121 Commits

Author SHA1 Message Date
026a841a04 change default game port
All checks were successful
Linux arm64 / Build (push) Successful in 4m49s
2024-04-13 17:29:47 +02:00
56e2f2f434 reset game state when kicked 2024-04-13 17:28:34 +02:00
a5debe81ac fix valgrind error 2024-04-13 17:22:58 +02:00
7157e45eac disconnect clients when server forcefully shuts down 2024-04-13 16:56:34 +02:00
8f51d468d2 fixing crash 2024-04-13 16:54:18 +02:00
8ed7044733 hide options on kick 2024-04-13 16:52:51 +02:00
b85115b364 add end game music 2024-04-13 16:42:19 +02:00
5cf539fb6f fix server handshake 2024-04-13 16:41:59 +02:00
34365714de freeze imgui and sdl version 2024-04-13 16:32:23 +02:00
391e4b8a33 arrange assets folder 2024-04-13 16:29:56 +02:00
231db48bab remove libs folder 2024-04-13 16:25:40 +02:00
21aa1b0241 refactor listeners 2024-04-13 16:25:25 +02:00
e04444125d refactor PacketFactory 2024-04-13 16:13:10 +02:00
33f1c53148 fix server handshake 2024-04-13 16:04:58 +02:00
af0ef9eeb5 refactor tcpsocket 2024-04-13 15:58:28 +02:00
43510ea568 fix main menu on kick
All checks were successful
Linux arm64 / Build (push) Successful in 5m4s
2024-04-12 11:15:08 +02:00
9c6c25b17a add default server config
All checks were successful
Linux arm64 / Build (push) Successful in 5m19s
2024-04-12 11:07:23 +02:00
d8a3cb2785 Piou Piou (#48)
Some checks failed
Linux arm64 / Build (push) Has been cancelled
Fix #8

Reviewed-on: #48
Co-authored-by: Persson-dev <sim16.prib@gmail.com>
Co-committed-by: Persson-dev <sim16.prib@gmail.com>
2024-04-12 11:06:54 +02:00
27a76519a3 Suppressions d'erreurs Valgrind (#47)
All checks were successful
Linux arm64 / Build (push) Successful in 5m6s
Reviewed-on: #47
Co-authored-by: Persson-dev <sim16.prib@gmail.com>
Co-committed-by: Persson-dev <sim16.prib@gmail.com>
2024-04-12 10:54:59 +02:00
85585e157f Meilleur panel admin (#45)
All checks were successful
Linux arm64 / Build (push) Successful in 5m6s
Fix #34

Co-authored-by: Morph01 <thibaut6969delastreet@gmail.com>
Reviewed-on: #45
Co-authored-by: Persson-dev <sim16.prib@gmail.com>
Co-committed-by: Persson-dev <sim16.prib@gmail.com>
2024-04-11 17:29:11 +02:00
c2c6f1f033 C'est important la doc (#43)
All checks were successful
Linux arm64 / Build (push) Successful in 4m59s
C'est très long

Co-authored-by: Morph01 <thibaut6969delastreet@gmail.com>
Reviewed-on: #43
Co-authored-by: Persson-dev <sim16.prib@gmail.com>
Co-committed-by: Persson-dev <sim16.prib@gmail.com>
2024-04-11 17:17:40 +02:00
07d09332dd Musique de fond (#44)
All checks were successful
Linux arm64 / Build (push) Successful in 5m30s
Fix #7

Reviewed-on: #44
Co-authored-by: Persson-dev <sim16.prib@gmail.com>
Co-committed-by: Persson-dev <sim16.prib@gmail.com>
2024-04-11 16:59:07 +02:00
747fa13d3a fix action cache (this time it's actually working)
All checks were successful
Linux arm64 / Build (push) Successful in 5m4s
2024-04-11 16:21:49 +02:00
32ca078002 revert non blocking connect
All checks were successful
Linux arm64 / Build (push) Successful in 23m26s
2024-04-11 11:53:30 +02:00
e1efc5065c use leaderboard agin
All checks were successful
Linux arm64 / Build (push) Successful in 23m50s
2024-04-09 20:03:10 +02:00
8795562b42 Fix win (#38)
Some checks failed
Linux arm64 / Build (push) Has been cancelled
Reviewed-on: #38
Co-authored-by: Persson-dev <sim16.prib@gmail.com>
Co-committed-by: Persson-dev <sim16.prib@gmail.com>
2024-04-09 19:47:46 +02:00
048812090b fix assimp version
All checks were successful
Linux arm64 / Build (push) Successful in 22m33s
2024-04-09 10:08:43 +02:00
ad71bbbdf7 network: add error status
All checks were successful
Linux arm64 / Build (push) Successful in 6m15s
2024-04-06 12:28:45 +02:00
0bb7d28da8 fix join game freeze 2024-04-06 12:24:52 +02:00
8e13bac9d1 fix: build with glew only on CI
All checks were successful
Linux arm64 / Build (push) Successful in 4m55s
2024-04-03 11:09:20 +02:00
76b3057271 fix Android warnings 2024-04-03 10:59:16 +02:00
df4b1641d5 remove unsed assets
All checks were successful
Linux arm64 / Build (push) Successful in 5m42s
2024-04-02 22:46:09 +02:00
7daf2bae0c don't move player when menu is opened
All checks were successful
Linux arm64 / Build (push) Successful in 5m53s
2024-04-02 22:30:58 +02:00
a7b235da38 Possibilité de changer la cadence de tir (#33)
Some checks failed
Linux arm64 / Build (push) Has been cancelled
ajout d'un changement pour la cadence de tir

Co-authored-by: Morph01 <145839520+Morph01@users.noreply.github.com>
Co-authored-by: Persson-dev <sim16.prib@gmail.com>
Reviewed-on: #33
Reviewed-by: Simon Pribylski <sim16.prib@gmail.com>
Co-authored-by: Morph01 <thibaut6969delastreet@gmail.com>
Co-committed-by: Morph01 <thibaut6969delastreet@gmail.com>
2024-04-02 22:25:47 +02:00
e27cc29eb0 Réglage de la gravité (#31)
All checks were successful
Linux arm64 / Build (push) Successful in 5m4s
Fix #6

Co-authored-by: Morph01 <145839520+Morph01@users.noreply.github.com>
Reviewed-on: #31
Co-authored-by: Persson-dev <sim16.prib@gmail.com>
Co-committed-by: Persson-dev <sim16.prib@gmail.com>
2024-03-30 19:38:17 +01:00
d59467dd23 Le laser sort de la main à la première personne (#30)
Some checks are pending
Linux arm64 / Build (push) Waiting to run
Fix #25

Reviewed-on: #30
Co-authored-by: Persson-dev <sim16.prib@gmail.com>
Co-committed-by: Persson-dev <sim16.prib@gmail.com>
2024-03-30 19:37:40 +01:00
0ed577bbc2 On sait quand on gagne (#29)
Some checks are pending
Linux arm64 / Build (push) Waiting to run
L'écran de fin est mis à jour correctement selon si la victoire nous appartient ou non.
Le cas d'égalité n'est cependant pas traité ! Seulement un joueur peut gagner à l'état actuel

Reviewed-on: #29
Co-authored-by: Persson-dev <sim16.prib@gmail.com>
Co-committed-by: Persson-dev <sim16.prib@gmail.com>
2024-03-30 19:37:08 +01:00
aa29b9d718 use Vec3 for PlayerController members
All checks were successful
Linux arm64 / Build (push) Successful in 4m39s
2024-03-30 11:53:07 +01:00
1cce7fcd35 remove unused variable
All checks were successful
Linux arm64 / Build (push) Successful in 4m38s
2024-03-30 09:55:07 +01:00
9e93c1a1de better trail effect
All checks were successful
Linux arm64 / Build (push) Successful in 4m43s
2024-03-29 09:11:19 +01:00
4119fe37cc fix run dir 2024-03-29 09:11:01 +01:00
0511511702 Update BlitzClient.lua
All checks were successful
Linux arm64 / Build (push) Successful in 4m41s
2024-03-28 22:35:54 +01:00
2484eb5377 Chemtrails (#28)
All checks were successful
Linux arm64 / Build (push) Successful in 4m37s
Co-authored-by: Morph01 <145839520+Morph01@users.noreply.github.com>
Reviewed-on: #28
Co-authored-by: Persson-dev <sim16.prib@gmail.com>
Co-committed-by: Persson-dev <sim16.prib@gmail.com>
2024-03-28 21:42:26 +01:00
61ae530238 fiiiiiiiiiiiiiiix
All checks were successful
Linux arm64 / Build (push) Successful in 5m4s
2024-03-28 21:35:41 +01:00
Morph01
7c90ecfbd3 Refactor ServerGui.cpp: Remove unused variables
Some checks failed
Linux arm64 / Build (push) Has been cancelled
2024-03-28 21:33:39 +01:00
6e47fa6996 Add admin window and server duration settings (#27)
Some checks failed
Linux arm64 / Build (push) Failing after 3m33s
Fix #11

Co-authored-by: Morph01 <145839520+Morph01@users.noreply.github.com>
Reviewed-on: #27
2024-03-28 21:17:24 +01:00
83649ddbab fix linux build
Some checks failed
Linux arm64 / Build (push) Has been cancelled
2024-03-28 18:42:40 +01:00
Morph01
83c4599aa3 add finish screen
Some checks failed
Linux arm64 / Build (push) Failing after 2m55s
2024-03-28 18:29:52 +01:00
0247ee3cc1 add delay timer
All checks were successful
Linux arm64 / Build (push) Successful in 4m38s
2024-03-28 17:48:59 +01:00
Morph01
58b401f257 Update types of texture variables
All checks were successful
Linux arm64 / Build (push) Successful in 4m56s
2024-03-28 16:40:41 +01:00
c5b07e2ae6 fix network test for windows
All checks were successful
Linux arm64 / Build (push) Successful in 5m19s
2024-03-28 16:30:51 +01:00
507946a0f4 fix operator- for Vector
All checks were successful
Linux arm64 / Build (push) Successful in 4m41s
2024-03-28 16:14:01 +01:00
f9b79b0d64 Ajout d'états de jeu (#26)
All checks were successful
Linux arm64 / Build (push) Successful in 4m42s
La partie est d'abord en mode "Attente de joueurs"
Lorsque 2 joueurs sont présents, la partie passe en mode "Préparation" et un décompte de 10s commence
La partie passe ensuite en mode "Jeu" pendant 3 min
Pour finir, la partie passe en mode "Fin" pendant 30s pour rebasculer en mode "Jeu" si le nombre de joueurs est toujours suffisant.

Reviewed-on: #26
Co-authored-by: Persson-dev <sim16.prib@gmail.com>
Co-committed-by: Persson-dev <sim16.prib@gmail.com>
2024-03-28 15:58:39 +01:00
Morph01
78d68446f2 Fix data type inconsistencies lets cook
All checks were successful
Linux arm64 / Build (push) Successful in 4m39s
2024-03-28 15:32:08 +01:00
255eafa35e fix return type
All checks were successful
Linux arm64 / Build (push) Successful in 4m44s
2024-03-26 20:25:15 +01:00
e254452a6c Meilleure interface (#15)
All checks were successful
Linux arm64 / Build (push) Successful in 4m55s
améliorer l'interface, déplacement de certains boutons etc.

Co-authored-by: Persson-dev <sim16.prib@gmail.com>
Co-authored-by: Morph01 <145839520+Morph01@users.noreply.github.com>
Co-authored-by: Simon Pribylski <sim16.prib@gmail.com>
Reviewed-on: #15
Co-authored-by: Morph01 <thibaut6969delastreet@gmail.com>
Co-committed-by: Morph01 <thibaut6969delastreet@gmail.com>
2024-03-26 12:52:07 +01:00
920c2e20b3 Merge pull request 'Merge new features' (#23) from dev into main
All checks were successful
Linux arm64 / Build (push) Successful in 4m46s
Reviewed-on: #23
2024-03-26 12:07:09 +01:00
1e1880376d fix merge
All checks were successful
Linux arm64 / Build (push) Successful in 4m52s
2024-03-26 11:47:47 +01:00
de22c89975 Squashed commit of the following:
commit 0adeba26e4
Author: = <=>
Date:   Tue Mar 26 11:35:37 2024 +0100

    minor fix

commit 011d8a573c
Author: = <=>
Date:   Tue Mar 26 11:33:56 2024 +0100

    fix stupid build error

commit 22406ad020
Author: = <=>
Date:   Tue Mar 26 11:25:35 2024 +0100

    yes

commit 4db55a372b
Author: = <=>
Date:   Tue Mar 26 11:13:22 2024 +0100

    csavgfdslgakdf;g

commit 20d176ccb5
Author: AquaEBM <AquaEBM@gmail.com>
Date:   Tue Mar 26 11:07:27 2024 +0100

    add range overlapping check utilities

commit 3863e7907f
Author: AquaEBM <AquaEBM@gmail.com>
Date:   Tue Mar 26 10:24:35 2024 +0100

    better edge case handling

commit 35b7d7bab0
Author: = <=>
Date:   Tue Mar 26 10:19:21 2024 +0100

    I am fucking retarded what the fuck is this stupid brain smoking

commit 6aca413b4f
Author: Persson-dev <sim16.prib@gmail.com>
Date:   Sun Mar 24 18:14:02 2024 +0100

    small refactor

commit ee322e3e7b
Author: AquaEBM@gmail.com <AquaEBM@gmail.com>
Date:   Sun Mar 24 17:40:39 2024 +0100

    improve tests, fix some bugs in Distance, (not working yet)

commit 864a15e4c8
Merge: 7efd821 c1ded40
Author: Persson-dev <sim16.prib@gmail.com>
Date:   Fri Mar 22 19:33:45 2024 +0100

    Squashed commit of the following:

    commit c1ded40cc4
    Author: Persson-dev <sim16.prib@gmail.com>
    Date:   Thu Mar 21 17:24:05 2024 +0100

        improve network test

    commit 285bf880ee
    Author: Persson-dev <sim16.prib@gmail.com>
    Date:   Thu Mar 21 17:14:43 2024 +0100

        fix warning

    commit 06ff76607d
    Author: Persson-dev <sim16.prib@gmail.com>
    Date:   Thu Mar 21 15:45:33 2024 +0100

        add bots

    commit 19229bbe8a
    Author: Persson-dev <sim16.prib@gmail.com>
    Date:   Thu Mar 21 14:55:57 2024 +0100

        fix warnings

    commit 2b0930a734
    Author: Morph01 <thibaut6969delastreet@gmail.com>
    Date:   Tue Mar 19 10:43:55 2024 +0100

        hud of blitz (#16)

        Résoudre partiellement #12

        Co-authored-by: Persson-dev <sim16.prib@gmail.com>
        Co-authored-by: Morph01 <145839520+Morph01@users.noreply.github.com>
        Co-authored-by: Simon Pribylski <sim16.prib@gmail.com>
        Reviewed-on: #16

    commit 84b6acad4c
    Author: Persson-dev <sim16.prib@gmail.com>
    Date:   Tue Mar 19 10:15:54 2024 +0100

        less spooky light

    commit 9f94d51fc4
    Author: Persson-dev <sim16.prib@gmail.com>
    Date:   Thu Mar 14 16:36:15 2024 +0100

        Ajout de tests d'intégration (#17)

        Le paquet fournissant OpenGL a été temporairement remplacé par glew

        Reviewed-on: #17
        Co-authored-by: Persson-dev <sim16.prib@gmail.com>
        Co-committed-by: Persson-dev <sim16.prib@gmail.com>

    commit 9951256881
    Author: Simon Pribylski <sim16.prib@gmail.com>
    Date:   Wed Mar 13 20:19:37 2024 +0100

        action: install libsdl via apt

    commit 4a02054648
    Author: Morph01 <145839520+Morph01@users.noreply.github.com>
    Date:   Wed Mar 13 13:53:20 2024 +0100

        compression tests

    commit 19c39312bf
    Author: Morph01 <145839520+Morph01@users.noreply.github.com>
    Date:   Wed Mar 13 13:51:57 2024 +0100

        setup action

    commit d5014b1e8a
    Author: Persson-dev <sim16.prib@gmail.com>
    Date:   Tue Mar 12 10:26:47 2024 +0100

        Revert "extend Vec3"

        This reverts commit dccfa9c936.

    commit dccfa9c936
    Author: = <=>
    Date:   Tue Mar 12 10:01:00 2024 +0100

        extend Vec3
    Merge branch 'main' into physics

commit 7efd8218ea
Author: Persson-dev <sim16.prib@gmail.com>
Date:   Fri Mar 22 19:28:46 2024 +0100

    moved functions in Maths.h

commit 08db7f84b9
Author: Persson-dev <sim16.prib@gmail.com>
Date:   Fri Mar 22 19:16:48 2024 +0100

    add missing include

commit 7119dea783
Author: Persson-dev <sim16.prib@gmail.com>
Date:   Fri Mar 22 19:15:01 2024 +0100

    merge 'main' branch

    commit c1ded40cc4
    Author: Persson-dev <sim16.prib@gmail.com>
    Date:   Thu Mar 21 17:24:05 2024 +0100

        improve network test

    commit 285bf880ee
    Author: Persson-dev <sim16.prib@gmail.com>
    Date:   Thu Mar 21 17:14:43 2024 +0100

        fix warning

    commit 06ff76607d
    Author: Persson-dev <sim16.prib@gmail.com>
    Date:   Thu Mar 21 15:45:33 2024 +0100

        add bots

    commit 19229bbe8a
    Author: Persson-dev <sim16.prib@gmail.com>
    Date:   Thu Mar 21 14:55:57 2024 +0100

        fix warnings

    commit 2b0930a734
    Author: Morph01 <thibaut6969delastreet@gmail.com>
    Date:   Tue Mar 19 10:43:55 2024 +0100

        hud of blitz (#16)

        Résoudre partiellement #12

        Co-authored-by: Persson-dev <sim16.prib@gmail.com>
        Co-authored-by: Morph01 <145839520+Morph01@users.noreply.github.com>
        Co-authored-by: Simon Pribylski <sim16.prib@gmail.com>
        Reviewed-on: #16

    commit 84b6acad4c
    Author: Persson-dev <sim16.prib@gmail.com>
    Date:   Tue Mar 19 10:15:54 2024 +0100

        less spooky light

    commit 9f94d51fc4
    Author: Persson-dev <sim16.prib@gmail.com>
    Date:   Thu Mar 14 16:36:15 2024 +0100

        Ajout de tests d'intégration (#17)

        Le paquet fournissant OpenGL a été temporairement remplacé par glew

        Reviewed-on: #17
        Co-authored-by: Persson-dev <sim16.prib@gmail.com>
        Co-committed-by: Persson-dev <sim16.prib@gmail.com>

    commit 9951256881
    Author: Simon Pribylski <sim16.prib@gmail.com>
    Date:   Wed Mar 13 20:19:37 2024 +0100

        action: install libsdl via apt

    commit 4a02054648
    Author: Morph01 <145839520+Morph01@users.noreply.github.com>
    Date:   Wed Mar 13 13:53:20 2024 +0100

        compression tests

    commit 19c39312bf
    Author: Morph01 <145839520+Morph01@users.noreply.github.com>
    Date:   Wed Mar 13 13:51:57 2024 +0100

        setup action

    commit d5014b1e8a
    Author: Persson-dev <sim16.prib@gmail.com>
    Date:   Tue Mar 12 10:26:47 2024 +0100

        Revert "extend Vec3"

        This reverts commit dccfa9c936.

    commit dccfa9c936
    Author: = <=>
    Date:   Tue Mar 12 10:01:00 2024 +0100

        extend Vec3

commit 6e998fc368
Author: AquaEBM@gmail.com <AquaEBM@gmail.com>
Date:   Fri Mar 22 16:41:52 2024 +0100

    change tests

commit 441131a2f5
Author: AquaEBM@gmail.com <AquaEBM@gmail.com>
Date:   Fri Mar 22 16:14:56 2024 +0100

    rename Intersects to distance

commit c875fa1dee
Author: Persson-dev <sim16.prib@gmail.com>
Date:   Fri Mar 22 15:50:32 2024 +0100

    more template

commit 5e4b318d67
Author: AquaEBM@gmail.com <AquaEBM@gmail.com>
Date:   Fri Mar 22 15:26:07 2024 +0100

    inline Reduce_<> functions

commit 076fa7badc
Author: AquaEBM@gmail.com <AquaEBM@gmail.com>
Date:   Fri Mar 22 15:18:39 2024 +0100

    fix compilation error

commit 1091abd034
Author: AquaEBM <AquaEBM@gmail.com>
Date:   Fri Mar 22 14:58:26 2024 +0100

    fix some compilation errors

commit dd9ea3ece8
Author: AquaEBM <AquaEBM@gmail.com>
Date:   Fri Mar 22 12:02:39 2024 +0100

    update intersects, document changes

commit 6226161e31
Author: AquaEBM <AquaEBM@gmail.com>
Date:   Fri Mar 22 09:22:06 2024 +0100

    fix compilation error, add min/max functions for Vec3d

commit 6b32e8878e
Author: AquaEBM <AquaEBM@gmail.com>
Date:   Fri Mar 22 09:18:34 2024 +0100

    fix min/max functions
2024-03-26 11:44:37 +01:00
7a388bcd62 Add crosshair (#20)
All checks were successful
Linux arm64 / Build (push) Successful in 4m30s
Reviewed-on: #20
Co-authored-by: Persson-dev <sim16.prib@gmail.com>
Co-committed-by: Persson-dev <sim16.prib@gmail.com>
2024-03-26 09:11:20 +01:00
d1bb086daf temp intersect
Some checks failed
Linux arm64 / Build (push) Failing after 4m42s
2024-03-26 09:00:47 +01:00
7f5aee9e16 fix merge 2024-03-26 09:00:30 +01:00
1bdf35a4e6 Merge branch 'death' into dev
Some checks failed
Linux arm64 / Build (push) Failing after 2m17s
2024-03-26 08:39:18 +01:00
2bef8801e8 Physique presque finie (#21)
Some checks failed
Linux arm64 / Build (push) Failing after 4m47s
Co-authored-by: = <=>
Co-authored-by: AquaEBM <AquaEBM@gmail.com>
Co-authored-by: AquaEBM@gmail.com <AquaEBM@gmail.com>
Reviewed-on: #21
Co-authored-by: Persson-dev <sim16.prib@gmail.com>
Co-committed-by: Persson-dev <sim16.prib@gmail.com>
2024-03-26 08:31:02 +01:00
c1ded40cc4 improve network test
Some checks failed
Linux arm64 / Build (push) Has been cancelled
2024-03-21 17:24:05 +01:00
285bf880ee fix warning
Some checks failed
Linux arm64 / Build (push) Has been cancelled
2024-03-21 17:20:36 +01:00
5492f52806 fix warning
Some checks failed
Linux arm64 / Build (push) Failing after 4m53s
2024-03-21 17:14:43 +01:00
2cbe3f1219 move player on death
Some checks failed
Linux arm64 / Build (push) Failing after 3m53s
2024-03-21 16:46:38 +01:00
fe68b98ba1 update health to client 2024-03-21 16:43:45 +01:00
860ec70829 Squashed commit of the following:
commit 06ff76607d
Author: Persson-dev <sim16.prib@gmail.com>
Date:   Thu Mar 21 15:45:33 2024 +0100

    add bots

commit 19229bbe8a
Author: Persson-dev <sim16.prib@gmail.com>
Date:   Thu Mar 21 14:55:57 2024 +0100

    fix warnings

commit 2b0930a734
Author: Morph01 <thibaut6969delastreet@gmail.com>
Date:   Tue Mar 19 10:43:55 2024 +0100

    hud of blitz (#16)

    Résoudre partiellement #12

    Co-authored-by: Persson-dev <sim16.prib@gmail.com>
    Co-authored-by: Morph01 <145839520+Morph01@users.noreply.github.com>
    Co-authored-by: Simon Pribylski <sim16.prib@gmail.com>
    Reviewed-on: #16

commit 84b6acad4c
Author: Persson-dev <sim16.prib@gmail.com>
Date:   Tue Mar 19 10:15:54 2024 +0100

    less spooky light

commit 9f94d51fc4
Author: Persson-dev <sim16.prib@gmail.com>
Date:   Thu Mar 14 16:36:15 2024 +0100

    Ajout de tests d'intégration (#17)

    Le paquet fournissant OpenGL a été temporairement remplacé par glew

    Reviewed-on: #17
    Co-authored-by: Persson-dev <sim16.prib@gmail.com>
    Co-committed-by: Persson-dev <sim16.prib@gmail.com>

commit 9951256881
Author: Simon Pribylski <sim16.prib@gmail.com>
Date:   Wed Mar 13 20:19:37 2024 +0100

    action: install libsdl via apt

commit 4a02054648
Author: Morph01 <145839520+Morph01@users.noreply.github.com>
Date:   Wed Mar 13 13:53:20 2024 +0100

    compression tests

commit 19c39312bf
Author: Morph01 <145839520+Morph01@users.noreply.github.com>
Date:   Wed Mar 13 13:51:57 2024 +0100

    setup action

commit d5014b1e8a
Author: Persson-dev <sim16.prib@gmail.com>
Date:   Tue Mar 12 10:26:47 2024 +0100

    Revert "extend Vec3"

    This reverts commit dccfa9c936.

commit dccfa9c936
Author: = <=>
Date:   Tue Mar 12 10:01:00 2024 +0100

    extend Vec3
2024-03-21 15:51:57 +01:00
06ff76607d add bots
Some checks failed
Linux arm64 / Build (push) Failing after 3m31s
2024-03-21 15:45:33 +01:00
19229bbe8a fix warnings
Some checks failed
Linux arm64 / Build (push) Failing after 11m53s
2024-03-21 14:55:57 +01:00
438bc4a968 remove unused variable
Some checks failed
Linux arm64 / Build (push) Failing after 4m32s
2024-03-21 14:39:18 +01:00
9aa546881a better shoot logging
Some checks failed
Linux arm64 / Build (push) Has been cancelled
2024-03-21 14:35:41 +01:00
4db03f2b83 working shoot
Some checks failed
Linux arm64 / Build (push) Has been cancelled
2024-03-21 14:32:03 +01:00
0119d36b5c should work
All checks were successful
Linux arm64 / Build (push) Successful in 5m5s
2024-03-19 13:01:17 +01:00
249d7534a4 Squashed commit of the following:
All checks were successful
Linux arm64 / Build (push) Successful in 4m20s
commit 2b0930a734
Author: Morph01 <thibaut6969delastreet@gmail.com>
Date:   Tue Mar 19 10:43:55 2024 +0100

    hud of blitz (#16)

    Résoudre partiellement #12

    Co-authored-by: Persson-dev <sim16.prib@gmail.com>
    Co-authored-by: Morph01 <145839520+Morph01@users.noreply.github.com>
    Co-authored-by: Simon Pribylski <sim16.prib@gmail.com>
    Reviewed-on: #16

commit 84b6acad4c
Author: Persson-dev <sim16.prib@gmail.com>
Date:   Tue Mar 19 10:15:54 2024 +0100

    less spooky light

commit 9f94d51fc4
Author: Persson-dev <sim16.prib@gmail.com>
Date:   Thu Mar 14 16:36:15 2024 +0100

    Ajout de tests d'intégration (#17)

    Le paquet fournissant OpenGL a été temporairement remplacé par glew

    Reviewed-on: #17
    Co-authored-by: Persson-dev <sim16.prib@gmail.com>
    Co-committed-by: Persson-dev <sim16.prib@gmail.com>

commit 9951256881
Author: Simon Pribylski <sim16.prib@gmail.com>
Date:   Wed Mar 13 20:19:37 2024 +0100

    action: install libsdl via apt

commit 4a02054648
Author: Morph01 <145839520+Morph01@users.noreply.github.com>
Date:   Wed Mar 13 13:53:20 2024 +0100

    compression tests

commit 19c39312bf
Author: Morph01 <145839520+Morph01@users.noreply.github.com>
Date:   Wed Mar 13 13:51:57 2024 +0100

    setup action

commit d5014b1e8a
Author: Persson-dev <sim16.prib@gmail.com>
Date:   Tue Mar 12 10:26:47 2024 +0100

    Revert "extend Vec3"

    This reverts commit dccfa9c936.

commit dccfa9c936
Author: = <=>
Date:   Tue Mar 12 10:01:00 2024 +0100

    extend Vec3
2024-03-19 12:16:23 +01:00
=
abe89d2089 remove debug prints 2024-03-19 12:10:32 +01:00
f070b28d8b revert c_cpp_properties 2024-03-19 12:03:12 +01:00
=
a7f734d22e fix Intersects, add tests 2024-03-19 11:56:29 +01:00
2b0930a734 hud of blitz (#16)
All checks were successful
Linux arm64 / Build (push) Successful in 4m33s
Résoudre partiellement #12

Co-authored-by: Persson-dev <sim16.prib@gmail.com>
Co-authored-by: Morph01 <145839520+Morph01@users.noreply.github.com>
Co-authored-by: Simon Pribylski <sim16.prib@gmail.com>
Reviewed-on: #16
2024-03-19 10:43:55 +01:00
=
abbc4419fa update intersects function 2024-03-19 10:36:43 +01:00
84b6acad4c less spooky light
All checks were successful
Linux arm64 / Build (push) Successful in 4m23s
2024-03-19 10:15:54 +01:00
9f94d51fc4 Ajout de tests d'intégration (#17)
All checks were successful
Linux arm64 / Build (push) Successful in 4m28s
Le paquet fournissant OpenGL a été temporairement remplacé par glew

Reviewed-on: #17
Co-authored-by: Persson-dev <sim16.prib@gmail.com>
Co-committed-by: Persson-dev <sim16.prib@gmail.com>
2024-03-14 16:36:15 +01:00
9951256881 action: install libsdl via apt
Some checks failed
Linux arm64 / Build (push) Failing after 54m19s
2024-03-13 20:19:37 +01:00
Morph01
4a02054648 compression tests
Some checks failed
Linux arm64 / Build (push) Failing after 57m27s
2024-03-13 13:53:20 +01:00
Morph01
19c39312bf setup action 2024-03-13 13:51:57 +01:00
86e47601d7 idk 2024-03-12 11:31:04 +01:00
d5014b1e8a Revert "extend Vec3"
This reverts commit dccfa9c936.
2024-03-12 10:26:47 +01:00
=
a3b6d2488f extend Vec3, implement AABB intersection 2024-03-12 10:25:27 +01:00
=
dccfa9c936 extend Vec3 2024-03-12 10:01:00 +01:00
e39fc8aa70 Star Wars (#14)
Reviewed-on: #14
2024-03-12 08:55:49 +01:00
d42f67724d fix error 2024-03-12 08:32:53 +01:00
71bc4dd249 add keybindings (#13)
Co-authored-by: Morph01 <thibaut6969delastreet@gmail.com>
Reviewed-on: #13
Co-authored-by: Persson-dev <sim16.prib@gmail.com>
Co-committed-by: Persson-dev <sim16.prib@gmail.com>
2024-03-09 18:37:54 +01:00
2cb5074140 better server logs 2024-03-09 11:01:30 +01:00
269ac16d28 more precise logging 2024-03-08 22:59:50 +01:00
b7926d7a98 pretty log 2024-03-08 22:57:38 +01:00
52da1cf19b explicit server in logs 2024-03-07 23:10:37 +01:00
2da89c8dab xmake: remove global include 2024-03-07 21:12:41 +01:00
88cb433ecf xmake: relative paths 2024-03-07 21:03:23 +01:00
d96b01074e split xmake targets 2024-03-07 20:50:14 +01:00
a1effa05cd remove github ci 2024-03-07 20:14:12 +01:00
7b58117f36 fix warnings 2024-03-07 20:13:05 +01:00
bf8a6458a0 valgrind full info 2024-03-05 12:30:09 +01:00
18ddede8c0 add shoot 2024-03-05 12:29:39 +01:00
d3467418c7 Merge branch 'main' of github.com:Persson-dev/Blitz 2024-03-05 09:01:15 +01:00
d98939cb31 remove useless add_requires 2024-03-05 08:39:24 +01:00
0d039caa0e Merge branch 'weirdshoot' 2024-03-05 08:38:34 +01:00
848f12e58b Vecxuc wrong type 2024-02-27 12:15:35 +01:00
ce249359c6 non copyable classes 2024-02-26 11:27:16 +01:00
9591836074 add valgrind test 2024-01-30 09:14:07 +01:00
7305051062 fix memory warnings 2024-01-30 08:53:26 +01:00
617e1fa95e branchless 2024-01-28 19:09:30 +01:00
73b4539e8d add gun animation 2024-01-28 18:30:16 +01:00
de3ff4326a CooldownTimer to template 2024-01-28 18:29:55 +01:00
51f046f44e fix compile error 2024-01-27 20:12:14 +01:00
3b5208aeba clamp horizonal movement vector norm to 1 (fix diagonal movement speed increase) 2024-01-27 20:10:10 +01:00
a40cd1cd61 change smoothing time const names 2024-01-27 19:11:04 +01:00
1ccf525dd6 fix wrong filter equation 2024-01-27 19:08:56 +01:00
b345d6eb49 fixed-alpha movement smoothing 2024-01-27 17:54:26 +01:00
a7dbf69a4a oooo? 2024-01-27 17:48:37 +01:00
192 changed files with 5562 additions and 67280 deletions

View File

@@ -0,0 +1,46 @@
name: Linux arm64
run-name: Build And Test
on: [push]
jobs:
Build:
runs-on: ubuntu-latest
steps:
- name: Install deps
run : |
apt update
apt install -y libsdl2-dev libassimp-dev libglew-dev
- name: Check out repository code
uses: actions/checkout@v3
- name: Prepare XMake
uses: xmake-io/github-action-setup-xmake@v1
with:
xmake-version: latest
actions-cache-folder: '.xmake-cache'
actions-cache-key: 'ubuntu'
- name: Calc deps hash
uses: seepine/hash-files@v1
id: get-hash
with:
patterns: |
**/xmake.lua
**/xmake/*.lua
- name: Packages cache
uses: actions/cache@v4
with:
path: ~/.xmake
key: ${{ runner.os }}-${{ steps.get-hash.outputs.hash }}
- name: XMake config
run: xmake f -p linux -y --root
- name: Build
run: xmake --root
- name: Test
run: xmake test --root

View File

@@ -1,32 +0,0 @@
name: macOS
on:
pull_request:
push:
branches: main
jobs:
build:
strategy:
fail-fast: false
runs-on: macos-latest
concurrency:
group: ${{ github.ref }}-${{ github.base_ref }}-${{ github.head_ref }}-macOS
cancel-in-progress: true
steps:
- uses: actions/checkout@v1
- uses: xmake-io/github-action-setup-xmake@v1
with:
xmake-version: branch@master
- name: Prepare XMake
run: xmake f -p macosx -y
- name: Build
run: xmake
- name: Test
run: xmake test

View File

@@ -1,42 +0,0 @@
name: Windows
on:
pull_request:
push:
branches: main
jobs:
build:
strategy:
fail-fast: false
matrix:
arch: [x64, x86]
vs_runtime: [MT, MD]
runs-on: windows-latest
concurrency:
group: ${{ github.ref }}-${{ github.base_ref }}-${{ github.head_ref }}-Windows-${{ matrix.arch }}-${{ matrix.vs_runtime }}
cancel-in-progress: true
steps:
- uses: actions/checkout@v1
- uses: xmake-io/github-action-setup-xmake@v1
with:
xmake-version: branch@master
- name: Configure Pagefile
uses: al-cheb/configure-pagefile-action@v1.2
with:
minimum-size: 8GB
maximum-size: 32GB
disk-root: "D:"
- name: Prepare XMake
run: xmake f -p windows -a ${{ matrix.arch }} --vs_runtime=${{ matrix.vs_runtime }} -y
- name: Build
run: xmake
- name: Test
run: xmake test

View File

@@ -1,11 +1,13 @@
{
"configurations": [
{
"name": "Blitz",
"cppStandard": "c++17",
"includePath": ["include"],
"compileCommands": ".vscode/compile_commands.json"
}
],
"version": 4
"configurations": [
{
"name": "Blitz",
"cppStandard": "c++17",
"includePath": [
"include"
],
"compileCommands": ".vscode/compile_commands.json"
}
],
"version": 4
}

7
.vscode/launch.json vendored
View File

@@ -2,6 +2,13 @@
// Xmake debug
"version": "0.2.0",
"configurations": [
{
"type": "xmake",
"request": "launch",
"name": "debug intersects test",
"target": "test_intersects",
"cwd": "",
},
{
"type": "xmake",
"request": "launch",

BIN
assets/models/cube.glb Normal file

Binary file not shown.

View File

@@ -1,40 +0,0 @@
# Blender 3.6.4
# www.blender.org
mtllib untitled.mtl
o Cube
v 1.000000 3.829521 -1.000000
v 1.000000 -1.000000 -1.000000
v 1.000000 3.829521 1.000000
v 1.000000 -1.000000 1.000000
v -1.000000 3.829521 -1.000000
v -1.000000 -1.000000 -1.000000
v -1.000000 3.829521 1.000000
v -1.000000 -1.000000 1.000000
vn -0.0000 1.0000 -0.0000
vn -0.0000 -0.0000 1.0000
vn -1.0000 -0.0000 -0.0000
vn -0.0000 -1.0000 -0.0000
vn 1.0000 -0.0000 -0.0000
vn -0.0000 -0.0000 -1.0000
vt 0.625000 0.500000
vt 0.875000 0.500000
vt 0.875000 0.750000
vt 0.625000 0.750000
vt 0.375000 0.750000
vt 0.625000 1.000000
vt 0.375000 1.000000
vt 0.375000 0.000000
vt 0.625000 0.000000
vt 0.625000 0.250000
vt 0.375000 0.250000
vt 0.125000 0.500000
vt 0.375000 0.500000
vt 0.125000 0.750000
s 0
usemtl Material
f 1/1/1 5/2/1 7/3/1 3/4/1
f 4/5/2 3/4/2 7/6/2 8/7/2
f 8/8/3 7/9/3 5/10/3 6/11/3
f 6/12/4 2/13/4 4/5/4 8/14/4
f 2/13/5 1/1/5 3/4/5 4/5/5
f 6/11/6 5/10/6 1/1/6 2/13/6

BIN
assets/sounds/jazz.wav Normal file

Binary file not shown.

BIN
assets/sounds/laser.wav Normal file

Binary file not shown.

BIN
assets/sounds/sessionD.wav Normal file

Binary file not shown.

View File

Before

Width:  |  Height:  |  Size: 298 KiB

After

Width:  |  Height:  |  Size: 298 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 218 KiB

BIN
assets/textures/jp.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 78 KiB

View File

@@ -1,37 +0,0 @@
# Blender 3.6.4
# www.blender.org
mtllib void_map.mtl
o Plane
v -30.0 0.000000 30.0
v 30.0 0.000000 30.0
v -30.0 0.000000 -30.0
v 30.0 0.000000 -30.0
v -30.0 0.000000 30.0
v -30.0 0.000000 -30.0
v -30.0 0.000000 30.0
v -30.0 0.000000 -30.0
v -30.0 15.0 30.0
v -30.0 15.0 -30.0
v -30.0 15.0 -30.0
v 30.0 15.0 -30.0
v 30.0 15.0 30.0
v 30.0 15.0 -30.0
v -30.0 15.0 30.0
v 30.0 15.0 30.0
vn -0.0000 1.0000 -0.0000
vn 1.0000 -0.0000 -0.0000
vn -0.0000 -0.0000 1.0000
vn -1.0000 -0.0000 -0.0000
vn -0.0000 -0.0000 -1.0000
vt 0.000000 0.000000
vt 1.000000 0.000000
vt 1.000000 1.000000
vt 0.000000 1.000000
s 0
f 1/1/1 2/2/1 4/3/1 3/4/1
f 1/1/1 3/4/1 6/4/1 5/1/1
f 5/1/1 6/4/1 8/4/1 7/1/1
f 7/1/2 8/4/2 10/4/2 9/1/2
f 3/4/3 4/3/3 12/3/3 11/4/3
f 4/3/4 2/2/4 13/2/4 14/3/4
f 2/2/5 1/1/5 15/1/5 16/2/5

View File

@@ -1,38 +0,0 @@
# Blender 3.6.4
# www.blender.org
mtllib void_map2.mtl
o Plane
v -31.562399 0.000000 31.562399
v 31.562399 0.000000 31.562399
v -31.562399 0.000000 -31.562399
v 31.562399 0.000000 -31.562399
v -31.562399 0.000000 31.562399
v -31.562399 0.000000 -31.562399
v -31.562399 0.000000 31.562399
v -31.562399 0.000000 -31.562399
v -31.562399 12.947957 31.562399
v -31.562399 12.947957 -31.562399
v -31.562399 12.885334 -31.562399
v 31.562399 12.885334 -31.562399
v 31.562399 12.806857 31.562399
v 31.562399 12.806857 -31.562399
v -31.562399 12.847334 31.562399
v 31.562399 12.847334 31.562399
vn -0.0000 1.0000 -0.0000
vn 1.0000 -0.0000 -0.0000
vn -0.0000 -0.0000 1.0000
vn -1.0000 -0.0000 -0.0000
vn -0.0000 -0.0000 -1.0000
vt 0.000000 0.000000
vt 1.000000 0.000000
vt 1.000000 1.000000
vt 0.000000 1.000000
s 0
usemtl carrelage
f 1/1/1 2/2/1 4/3/1 3/4/1
f 1/1/1 3/4/1 6/4/1 5/1/1
f 5/1/1 6/4/1 8/4/1 7/1/1
f 7/1/2 8/4/2 10/4/2 9/1/2
f 3/4/3 4/3/3 12/3/3 11/4/3
f 4/3/4 2/2/4 13/2/4 14/3/4
f 2/2/5 1/1/5 15/1/5 16/2/5

View File

@@ -7,6 +7,7 @@
#include <algorithm>
#include <cassert>
#include <cstdint>
#include <cstring>
#include <string>
#include <vector>
@@ -39,21 +40,31 @@ class DataBuffer {
DataBuffer& operator=(const DataBuffer& other);
DataBuffer& operator=(DataBuffer&& other);
/**
* \brief Append data to the buffer
*/
template <typename T>
void Append(const T& data) {
std::size_t size = sizeof(data);
std::size_t end_pos = m_Buffer.size();
m_Buffer.resize(m_Buffer.size() + size);
memcpy(&m_Buffer[end_pos], &data, size);
std::memcpy(&m_Buffer[end_pos], &data, size);
}
/**
* \brief Append data to the buffer
*/
template <typename T>
DataBuffer& operator<<(const T& data) {
Append(data);
return *this;
}
// don't use it for binary data !
/**
* \brief Append a string to the buffer
* \warning Don't use it for binary data !
* \param str The string to append
*/
DataBuffer& operator<<(const std::string& str) {
std::size_t strlen = str.length() + 1; // including null character
Resize(GetSize() + strlen);
@@ -61,16 +72,18 @@ class DataBuffer {
return *this;
}
DataBuffer& operator<<(DataBuffer& data) {
m_Buffer.insert(m_Buffer.end(), data.begin(), data.end());
return *this;
}
/**
* \brief Append data to the buffer from another const buffer
* \param data The buffer to append
*/
DataBuffer& operator<<(const DataBuffer& data) {
m_Buffer.insert(m_Buffer.end(), data.begin(), data.end());
return *this;
}
/**
* \brief Read some data from the buffer and assign to desired variable
*/
template <typename T>
DataBuffer& operator>>(T& data) {
assert(m_ReadOffset + sizeof(T) <= GetSize());
@@ -79,6 +92,10 @@ class DataBuffer {
return *this;
}
/**
* \brief Read some data from the buffer and assign to the new buffer
* \param data The buffer to assign
*/
DataBuffer& operator>>(DataBuffer& data) {
data.Resize(GetSize() - m_ReadOffset);
std::copy(m_Buffer.begin() + static_cast<difference_type>(m_ReadOffset), m_Buffer.end(), data.begin());
@@ -86,7 +103,11 @@ class DataBuffer {
return *this;
}
// Don't use it for binary data !
/**
* \brief Read a string from the buffer
* \param str The string to assign in the new buffer
* \warning Don't use it for binary data !
*/
DataBuffer& operator>>(std::string& str) {
std::size_t stringSize =
strlen(reinterpret_cast<const char*>(m_Buffer.data()) + m_ReadOffset) + 1; // including null character
@@ -97,30 +118,55 @@ class DataBuffer {
return *this;
}
/**
* \brief Write some data to the buffer
* \param buffer The buffer to write
* \param amount The amount of data to write
*/
void WriteSome(const char* buffer, std::size_t amount) {
std::size_t end_pos = m_Buffer.size();
m_Buffer.resize(m_Buffer.size() + amount);
memcpy(m_Buffer.data() + end_pos, buffer, amount);
std::memcpy(m_Buffer.data() + end_pos, buffer, amount);
}
/**
* \brief Write some data to the buffer
* \param buffer The buffer to write
* \param amount The amount of data to write
*/
void WriteSome(const std::uint8_t* buffer, std::size_t amount) {
std::size_t end_pos = m_Buffer.size();
m_Buffer.resize(m_Buffer.size() + amount);
memcpy(m_Buffer.data() + end_pos, buffer, amount);
std::memcpy(m_Buffer.data() + end_pos, buffer, amount);
}
/**
* \brief Read some data from the buffer
* \param buffer The buffer to Read
* \param amount The amount of data from the buffer
*/
void ReadSome(char* buffer, std::size_t amount) {
assert(m_ReadOffset + amount <= GetSize());
std::copy_n(m_Buffer.begin() + static_cast<difference_type>(m_ReadOffset), amount, buffer);
m_ReadOffset += amount;
}
/**
* \brief Read some data from the buffer
* \param buffer The buffer to Read
* \param amount The amount of data from the buffer
*/
void ReadSome(std::uint8_t* buffer, std::size_t amount) {
assert(m_ReadOffset + amount <= GetSize());
std::copy_n(m_Buffer.begin() + static_cast<difference_type>(m_ReadOffset), amount, buffer);
m_ReadOffset += amount;
}
/**
* \brief Read some data from the buffer
* \param buffer The buffer to Read
* \param amount The amount of data from the buffer
*/
void ReadSome(DataBuffer& buffer, std::size_t amount) {
assert(m_ReadOffset + amount <= GetSize());
buffer.Resize(amount);
@@ -128,60 +174,113 @@ class DataBuffer {
m_ReadOffset += amount;
}
/**
* \brief Resize the buffer
* \param size The new size of the buffer
*/
void Resize(std::size_t size) {
m_Buffer.resize(size);
}
/**
* \brief Reserve some space in the buffer
* \param amount The amount of space to reserve
*/
void Reserve(std::size_t amount) {
m_Buffer.reserve(amount);
}
void erase(iterator it) {
m_Buffer.erase(it);
}
/**
* \brief Clear the buffer
*/
void Clear() {
m_Buffer.clear();
m_ReadOffset = 0;
}
/**
* \brief When the buffer has been read entirely
*/
bool IsFinished() const {
return m_ReadOffset >= m_Buffer.size();
}
/**
* \brief Get the buffer data
*/
std::uint8_t* data() {
return m_Buffer.data();
}
/**
* \brief Get the buffer data
*/
const std::uint8_t* data() const {
return m_Buffer.data();
}
/**
* \brief Get the read offset
*/
std::size_t GetReadOffset() const {
return m_ReadOffset;
}
/**
* \brief Set the read offset
* \param pos The new read offset
*/
void SetReadOffset(std::size_t pos);
/**
* \brief Get the size of the buffer
*/
std::size_t GetSize() const;
/**
* \brief Get the remaining size of the buffer
*/
std::size_t GetRemaining() const;
iterator begin();
iterator end();
const_iterator begin() const;
const_iterator end() const;
/**
* \brief Read a file into the buffer
* \param fileName The name of the file to read
*/
bool ReadFile(const std::string& fileName);
bool WriteFile(const std::string& fileName);
// Don't forget to free the data !
/**
* \brief Write a file into the buffer
* \param fileName The name of the file to write to
*/
bool WriteFile(const std::string& fileName) const;
/**
* \brief Allocate the buffer on the heap
* \warning Don't forget to free the data !
*/
std::uint8_t* HeapAllocatedData() const {
std::uint8_t* newBuffer = new std::uint8_t[GetSize()];
std::memcpy(newBuffer, data(), GetSize());
return newBuffer;
}
/**
* \brief Operator == to compare two DataBuffer
*/
bool operator==(const DataBuffer& other) const {
return m_Buffer == other.m_Buffer;
}
iterator begin();
iterator end();
const_iterator begin() const;
const_iterator end() const;
};
/**
* \brief Operator << to write a DataBuffer to an ostream
*/
std::ostream& operator<<(std::ostream& os, const DataBuffer& buffer);
} // namespace blitz

View File

@@ -3,7 +3,7 @@
/**
* \file Defines.h
* \brief File containing constants and typedefs
*/
*/
#include <cstdint>
@@ -13,8 +13,20 @@ namespace game {
/**
* \typedef PlayerID
* \brief Represents the identifier of a Player
*/
*/
typedef std::uint8_t PlayerID;
/**
* \enum GameState
* \brief The states of the game
*/
enum GameState : std::uint8_t {
gsNone = 0, /**< Default state */
gsWaiting, /**< Waiting state if the number of players is less than 2 */
gsPreparing, /**< Preparing state until the game start */
gsGame, /**< Game state during the players can shoot and kill ... */
gsEnd, /**< End state of the game : show the winner of the game and the leaderboard*/
};
} // namespace game
} // namespace blitz

View File

@@ -0,0 +1,25 @@
#pragma once
/**
* \file NonCopyable.h
* \brief File containing the blitz::NonCopyable class
*/
namespace blitz {
/**
* \class NonCopyable
* \brief Class used to make a class non copyable
* \note Inherit from this class privately to make a class non copyable
*/
class NonCopyable {
public:
NonCopyable(const NonCopyable&) = delete;
NonCopyable& operator=(const NonCopyable&) = delete;
protected:
NonCopyable() {}
~NonCopyable() {}
};
} // namespace blitz

View File

@@ -1,5 +1,10 @@
#pragma once
/**
* \file VarInt.h
* \brief File containing the blitz::VarInt class
*/
#include <cstddef>
#include <cstdint>
@@ -7,21 +12,46 @@ namespace blitz {
class DataBuffer;
/**
* \class VarInt
* \brief Variable-length format such that smaller numbers use fewer bytes.
*/
class VarInt {
private:
std::uint64_t m_Value;
public:
VarInt() : m_Value(0) {}
/**
* \brief Construct a variable integer from a value
* \param value The value of the variable integer
*/
VarInt(std::uint64_t value) : m_Value(value) {}
/**
* \brief Get the value of the variable integer
*/
std::uint64_t GetValue() const {
return m_Value;
}
/**
* \brief Get the length of the serialized variable integer
*/
std::size_t GetSerializedLength() const;
/**
* \brief Serialize the variable integer
* \param out The buffer to write the serialized variable integer to
* \param var The variable integer to serialize
*/
friend DataBuffer& operator<<(DataBuffer& out, const VarInt& var);
/**
* \brief Deserialize the variable integer
* \param in The buffer to read the serialized variable integer from
* \param var The variable integer to deserialize
*/
friend DataBuffer& operator>>(DataBuffer& in, VarInt& var);
};

View File

@@ -1,35 +1,140 @@
#pragma once
/**
* \file Game.h
* \brief File containing the blitz::game::Game class
*/
#include "Player.h"
#include "blitz/game/Listeners.h"
#include "blitz/misc/ObjectNotifier.h"
#include "blitz/misc/Time.h"
#include <map>
namespace blitz {
namespace game {
/**
* \typedef PlayerMap
* \brief A map of players
*/
typedef std::map<PlayerID, Player> PlayerMap;
class Game {
private:
/**
* \brief The game configuration
* \struct GameConfig
*/
struct GameConfig {
/**
* \brief The gravity applied to players
*/
float Gravity;
/**
* \brief The firing rate of the shoot in RPM (round per minute)
*/
int FiringRate;
};
/**
* \class Game
* \brief Class representing a game
*/
class Game : public utils::ObjectNotifier<GameListener> {
protected:
PlayerMap m_Players;
GameState m_GameState;
utils::Timer m_GameTimer;
GameConfig m_Config;
public:
Game() {}
/** \brief Default constructor */
Game() : m_GameState(gsNone), m_Config({}) {}
/**
* \brief Update the game with a delta time
* \param delta The time elapsed since the last update in milliseconds
*/
virtual void Tick(std::uint64_t delta) = 0;
/**
* \brief Get a player by its identifier
* \param id The identifier of the player
* \return The player if found, nullptr otherwise
*/
Player* GetPlayerById(PlayerID id);
/**
* \brief Get a player by its identifier (const version)
* \param id The identifier of the player
* \return The player if found, nullptr otherwise
*/
const Player* GetPlayerById(PlayerID id) const;
/**
* \brief Get the players
* \return The map of players
*/
PlayerMap& GetPlayers() {
return m_Players;
}
/**
* \brief Get the players (const version)
* \return The map of players
*/
const PlayerMap& GetPlayers() const {
return m_Players;
}
void AddPlayer(PlayerID player, const std::string& name);
void RemovePlayer(PlayerID player);
/**
* \brief Get the game state
* \return The game state
*/
GameState GetGameState() const {
return m_GameState;
}
/**
* \brief Set the game state
* \return The game state
*/
virtual void UpdateGameState(GameState newGameState, std::uint64_t timeRemaining);
/**
* \brief Load the game configuration
* \param config The game configuration to load
*/
void LoadConfig(const GameConfig& config) {
m_Config = config;
}
/**
* \brief Get the game configuration
* \return The game configuration
*/
const game::GameConfig& GetGameConfig() const {
return m_Config;
}
/**
* \brief Add a player to the game
* \param player The identifier of the player
* \param name The name of the player
*/
virtual void AddPlayer(PlayerID player, const std::string& name);
/**
* \brief Remove a player from the game
* \param player The identifier of the player
*/
virtual void RemovePlayer(PlayerID player);
/**
* \brief Get the remaining time of the game
* \return The remaining time of the game in milliseconds
*/
std::uint64_t GetGameStateRemainingTime() const {
return m_GameTimer.GetTimeRemaining();
}
};

View File

@@ -0,0 +1,49 @@
#pragma once
/**
* \file LeaderBoard.h
* \brief File containing the blitz::game::LeaderBoard class
*/
#include "blitz/game/Player.h"
#include <vector>
namespace blitz {
namespace game {
/**
* \class LeaderBoard
* \brief The leaderboard of the game
*/
class LeaderBoard {
private:
std::vector<Player*> m_Players;
public:
/**
* \brief Add a player to the leaderboard
* \param player The player to add
*/
void AddPlayer(Player* player);
/**
* \brief Remove a player from the leaderboard
* \param player The player to remove
*/
void RemovePlayer(PlayerID player);
/**
* \brief Update the leaderboard
*/
void Update();
/**
* \brief Get the players in the leaderboard ordered by kills
* \return The players
*/
const std::vector<Player*>& GetPlayers() const {
return m_Players;
}
};
} // namespace game
} // namespace blitz

View File

@@ -0,0 +1,17 @@
#pragma once
#include "blitz/common/Defines.h"
namespace blitz {
namespace game {
class GameListener {
public:
virtual void OnPlayerJoin(game::PlayerID player) {}
virtual void OnPlayerLeave(game::PlayerID player) {}
virtual void OnGameStateUpdate(game::GameState newState) {}
};
} // namespace game
} // namespace blitz

View File

@@ -1,13 +1,45 @@
#pragma once
/**
* \file Player.h
* \brief File containing the blitz::game::Player class
*/
#include "blitz/common/Defines.h"
#include "blitz/common/Vector.h"
#include "blitz/maths/Vector.h"
#include <cstdint>
#include <string>
namespace blitz {
namespace game {
/**
* \struct PlayerStats
* \brief The statistics of a player
*/
struct PlayerStats {
/**
* \brief The number of deaths
*/
std::uint16_t m_Deaths;
/**
* \brief The number of kills
*/
std::uint16_t m_Kills;
/**
* \brief The number of shots
*/
std::uint32_t m_ShootCount;
/**
* \brief The number of successful shots
*/
std::uint32_t m_ShootSuccessCount;
};
/**
* \class Player
* \brief The player of the game
*/
class Player {
private:
PlayerID m_ID;
@@ -16,65 +48,175 @@ class Player {
Vec3f m_Velocity;
float m_Yaw;
float m_Pitch;
float m_HP;
bool m_IsBot;
PlayerStats m_Stats{};
public:
Player(PlayerID id) : m_ID(id), m_Yaw(0), m_Pitch(0) {}
/**
* \brief Default constructor
* \param id The ID of the player
*/
Player(PlayerID id) : m_ID(id), m_Yaw(0), m_Pitch(0), m_HP(100), m_IsBot(false) {}
/**
* \brief Get the ID of the player
* \return The ID of the player
*/
PlayerID GetID() const {
return m_ID;
}
/**
* \brief Get the name of the player
* \return The name of the player
*/
const std::string& GetName() const {
return m_Name;
}
/**
* \brief Set the name of the player
* \param name The name of the player
*/
void SetName(const std::string& name) {
m_Name = name;
}
/**
* \brief Get the position of the player
* \return The position of the player
*/
const Vec3f& GetPosition() const {
return m_Position;
}
/**
* \brief Set the position of the player
* \param newPos The new position of the player
*/
void SetPosition(const Vec3f& newPos) {
m_Position = newPos;
}
/**
* \brief Add a position to the player
* \param dPos The position to add
*/
void AddPosition(const Vec3f& dPos) {
m_Position += dPos;
}
/**
* \brief Get the velocity of the player
* \return The velocity of the player
*/
const Vec3f& GetVelocity() const {
return m_Velocity;
}
/**
* \brief Set the velocity of the player
* \param newVelocity The new velocity of the player
*/
void SetVelocity(const Vec3f& newVelocity) {
m_Velocity = newVelocity;
}
/**
* \brief Get the yaw of the player
* \return The yaw of the player in radians
*/
float GetYaw() const {
return m_Yaw;
}
/**
* \brief Set the yaw of the player
* \param yaw The yaw of the player in radians
*/
void SetYaw(float yaw) {
m_Yaw = yaw;
}
/**
* \brief Add a yaw to the player
* \param dYaw The yaw to add in radians
*/
void AddYaw(float dYaw) {
m_Yaw += dYaw;
}
/**
* \brief Get the pitch of the player
* \return The pitch of the player in radians
*/
float GetPitch() const {
return m_Pitch;
}
/**
* \brief Set the pitch of the player
* \param pitch The pitch of the player in radians
*/
void SetPitch(float pitch) {
m_Pitch = pitch;
}
/**
* \brief Add a pitch to the player
* \param dPitch The pitch to add in radians
*/
void AddPitch(float dPitch) {
m_Pitch += dPitch;
}
/**
* \brief Get the HP of the player
* \return The HP of the player
*/
float GetHP() const {
return m_HP;
}
/**
* \brief Set the HP of the player
* \param hp The HP of the player
*/
void SetHP(float hp) {
m_HP = hp;
}
/**
* \brief When the player is a bot
* \return True if the player is a bot
*/
bool IsBot() const {
return m_IsBot;
}
/**
* \brief Set the player as a bot
*/
void SetBot() {
m_IsBot = true;
}
/**
* \brief Get the statistics of the player (const version)
* \return The statistics of the player
*/
const PlayerStats& GetStats() const {
return m_Stats;
}
/**
* \brief Get the statistics of the player
* \return The statistics of the player
*/
PlayerStats& GetStats() {
return m_Stats;
}
};

365
include/blitz/maths/Maths.h Normal file
View File

@@ -0,0 +1,365 @@
#pragma once
/**
* \file Maths.h
* \brief File containing mathematical functions and constants
*/
#include "blitz/maths/Vector.h"
#include <cmath>
namespace blitz {
namespace maths {
static constexpr float PI = 3.141592653f;
/**
* \return the amount of overlap between the ranges [a1 ; b1] and [a2 ; b2]
*/
template <typename T>
T RangesOverlap(T& a1, T& b1, T& a2, T& b2) {
return std::min(std::max(a1, b1), std::max(a2, b2)) - std::max(std::min(a1, b1), std::min(a2, b2));
}
/**
* \return whether the ranges [a1 ; b1] and [a2 ; b2] overlap
*/
template <typename T>
bool RangesOverlapping(T& a1, T& b1, T& a2, T& b2) {
return RangesOverlap(a1, a2, b1, b2) >= 0;
}
//////////////////////////////////////////////////////////////////
// Vectors //
//////////////////////////////////////////////////////////////////
/**
* \brief Returns the length of the vector
* \return the length of the vector
*/
template <typename T>
T Length(const Vec3<T>& vect) {
return std::sqrt(vect.x * vect.x + vect.y * vect.y + vect.z * vect.z);
}
/**
* \brief Normalizes the vector
* \return the normalized vector
*/
template <typename T>
Vec3<T> Normalize(const Vec3<T>& vect) {
T length = Length(vect);
return {vect.x / length, vect.y / length, vect.z / length};
}
/**
* \brief Normalizes the vector
* \return the normalized vector
*/
template <typename T>
Vec4<T> Normalize(const Vec4<T>& vect) {
T length = std::sqrt(vect.x * vect.x + vect.y * vect.y + vect.z * vect.z + vect.w * vect.w);
return {vect.x / length, vect.y / length, vect.z / length, vect.w / length};
}
/**
* \brief Returns the dot product of the two vectors
* \return the dot product of the two vectors
*/
template <typename T>
T Dot(const Vec3<T>& vect, const Vec3<T>& other) {
return vect.x * other.x + vect.y * other.y + vect.z * other.z;
}
/**
* \brief Returns the cross product of the two vectors
* \return the cross product of the two vectors
*/
template <typename T>
Vec3<T> Cross(const Vec3<T>& vect, const Vec3<T>& other) {
return {
vect.y * other.z - vect.z * other.y,
vect.z * other.x - vect.x * other.z,
vect.x * other.y - vect.y * other.x,
};
}
/**
* \brief Returns the dot product of the two vectors
* \return the dot product of the two vectors
*/
template <typename T>
T Dot(const Vec4<T>& vect, const Vec4<T>& other) {
return vect.x * other.x + vect.y * other.y + vect.z * other.z + vect.w * other.w;
}
/**
* \brief Returns the distance between the two vectors
* \return the distance between the two vectors
*/
template <typename T>
T Distance(const Vec3<T>& vect, const Vec3<T>& other) {
return Length(vect - other);
}
/**
* \brief Returns the minimum of the three coordinates of the vector
* \return the minimum between the three coordinates of the vector
*/
template <typename T>
T ReduceMin(const Vec3<T>& vect) {
return std::min(std::min(vect.x, vect.y), vect.z);
}
/**
* \brief Returns the maximum of the three coordinates of the vector
* \return the maximum between the three coordinates of the vector
*/
template <typename T>
T ReduceMax(const Vec3<T>& vect) {
return std::max(std::max(vect.x, vect.y), vect.z);
}
/**
* \brief Returns the (signed) minimal coordinate of the vector
* \param v a vector
* \return the (signed) minimal coordinate of the vector
*/
template <>
inline float ReduceMin<float>(const Vec3f& v) {
return std::fminf(std::fminf(v.x, v.y), v.z);
}
/**
* \brief Returns the (signed) maximal coordinate of the vector
* \param v a vector
* \return the (signed) maximal coordinate of the vector
*/
template <>
inline float ReduceMax<float>(const Vec3f& v) {
return std::fmaxf(std::fmaxf(v.x, v.y), v.z);
}
/**
* \brief returns the (signed) minimal coordinate of the vector
* \param v a vector
* \return the (signed) minimal coordinate of the vector
*/
template <>
inline double ReduceMin<double>(const Vec3d& v) {
return std::fmin(std::fmin(v.x, v.y), v.z);
}
/**
* \brief returns the (signed) maximal coordinate of the vector
* \param v a vector
* \return the (signed) maximal coordinate of the vector
*/
template <>
inline double ReduceMax<double>(const Vec3d& v) {
return std::fmax(std::fmax(v.x, v.y), v.z);
}
/**
* \brief returns the coordinate-wise minimum of the given vectors, where a coordinate in the returned vector is NAN iff any of the two
* compared ones are NAN
* \tparam T
* \param self a vector
* \param other an other vector
* \return the coordinate-wise minimum of the given vectors, where a coordinate in the returned vector is NAN iff any of the two
* compared ones are NAN
*/
template <typename T>
constexpr Vec3<T> Min(const Vec3<T>& self, const Vec3<T>& other) {
return {
std::min(self.x, other.x),
std::min(self.y, other.y),
std::min(self.z, other.z),
};
}
/**
* \brief returns the coordinate-wise maximum of the given vectors,
* where a coordinate in the returned vector is NAN iff any of the two compared ones are NAN
* \tparam T
* \param self a vector
* \param other an other vector
* \return returns the coordinate-wise maximum of the given vectors,
* where a coordinate in the returned vector is NAN iff any of the two compared ones are NAN
*/
template <typename T>
constexpr Vec3<T> Max(const Vec3<T>& self, const Vec3<T>& other) {
return {
std::max(self.x, other.x),
std::max(self.y, other.y),
std::max(self.z, other.z),
};
}
//////////////////////////////////////////////////////////////////
// Matricies //
//////////////////////////////////////////////////////////////////
/**
* \brief Returns the dot product of the matrix and the vector
* \return the dot product of the matrix and the vector
*/
template <typename T>
Vec4<T> Dot(const Mat4<T>& mat, const Vec4<T>& vect) {
return {mat.x0 * vect.x + mat.x1 * vect.y + mat.x2 * vect.z + mat.x3 * vect.w,
mat.y0 * vect.x + mat.y1 * vect.y + mat.y2 * vect.z + mat.y3 * vect.w,
mat.z0 * vect.x + mat.z1 * vect.y + mat.z2 * vect.z + mat.z3 * vect.w,
mat.w0 * vect.x + mat.w1 * vect.y + mat.w2 * vect.z + mat.w3 * vect.w};
}
/**
* \brief Returns the dot product of the matrix and an other matrix
* \return the dot product of the matrix and the other matrix
*/
template <typename T>
Mat4<T> Dot(const Mat4<T>& mat, const Mat4<T>& other) {
Mat4<T> result{};
for (std::size_t i = 0; i < Mat4<T>::MATRIX_SIZE; i++) {
for (std::size_t j = 0; j < Mat4<T>::MATRIX_SIZE; j++) {
for (std::size_t k = 0; k < Mat4<T>::MATRIX_SIZE; k++) {
result.at(i, j) += mat.at(i, k) * other.at(k, j);
}
}
}
return result;
}
/**
* \brief Returns the identity matrix
* \return the identity matrix
*/
template <typename T>
Mat4<T> Identity() {
Mat4<T> result{};
result.x0 = static_cast<T>(1);
result.y1 = static_cast<T>(1);
result.z2 = static_cast<T>(1);
result.w3 = static_cast<T>(1);
return result;
}
/**
* \brief Returns the transposed matrix
* \return the transposed matrix
*/
template <typename T>
Mat4<T> Transpose(const Mat4<T>& mat) {
Mat4<T> result;
result.x1 = mat.y0;
result.x2 = mat.z0;
result.x3 = mat.w0;
result.y0 = mat.x1;
result.y2 = mat.z1;
result.y3 = mat.w1;
result.z0 = mat.x2;
result.z1 = mat.y2;
result.z3 = mat.w2;
result.w0 = mat.x3;
result.w1 = mat.y3;
result.w2 = mat.z3;
result.x0 = mat.x0;
result.y1 = mat.y1;
result.z2 = mat.z2;
result.w3 = mat.w3;
return result;
}
/**
* \brief Returns the perspective matrix
* \param fovY The field of view in the y direction
* \param aspectRatio The aspect ratio of the screen
* \param zNear The near clipping plane
* \param zFar The far clipping plane
* \return the perspective matrix
*/
Mat4f Perspective(float fovY, float aspectRatio, float zNear, float zFar);
/**
* \brief Returns the look matrix
* \param eyePos The position of the camera
* \param front The front vector of the camera
* \param up The up vector of the camera
* \return the look matrix
*/
Mat4f Look(const Vec3f& eyePos, const Vec3f& front, const Vec3f& up);
/**
* \brief Returns the inverse of the matrix
* \return the inverse of the matrix
*/
Mat4f Inverse(const Mat4f& mat);
/**
* \brief Returns the translation matrix
* \param translation The translation vector
* \return the translation matrix
*/
Mat4f Translate(const Vec3f& translation);
/**
* \brief Returns the scale matrix
* \param axisFactor The scaling factor for each axis
* \return the scale matrix
*/
Mat4f Scale(const Vec3f& axisFactor);
/**
* \brief Returns the rotation matrix around the x axis
* \param angle The angle of rotation
* \return the rotation matrix
*/
Mat4f RotateX(float angle);
/**
* \brief Returns the rotation matrix around the y axis
* \param angle The angle of rotation
* \return the rotation matrix
*/
Mat4f RotateY(float angle);
/**
* \brief Returns the rotation matrix around the z axis
* \param angle The angle of rotation
* \return the rotation matrix
*/
Mat4f RotateZ(float angle);
/**
* \brief Returns the rotation matrix
* \param angles The angles of rotation
* \return the rotation matrix
*/
Mat4f Rotate(const Vec3f& angles);
/**
* \brief Returns the rotation matrix
* \param angle The angle of rotation
* \param axis The axis of rotation
* \return the rotation matrix
*/
Mat4f Rotate(float angle, Vec3f axis);
/**
* \brief Returns the unit vector correspond to the yaw and pitch
* \param yaw Angle in radians
* \param pitch Angle in radians
*/
Vec3f GetDirectionVectorFromRotation(float yaw, float pitch);
} // namespace maths
} // namespace blitz

View File

@@ -0,0 +1,30 @@
#pragma once
#include "blitz/maths/Vector.h"
namespace blitz {
namespace maths {
struct Ray {
Vec3f origin;
Vec3f direction;
};
struct AABB {
Vec3f from;
Vec3f to;
};
inline AABB operator+(const AABB& aabb, const Vec3f& offset) {
AABB result = aabb;
result.from += offset;
result.to += offset;
return result;
}
float Distance(const Ray& ray, const AABB& aabb);
bool Intersects(const Ray& ray, const AABB& aabb);
} // namespace maths
} // namespace blitz

View File

@@ -1,5 +1,12 @@
#pragma once
/**
* \file Vector.h
* \brief File containing the Vector structs and 4x4 matrix
*/
#include <algorithm>
#include <cmath>
#include <cstddef>
namespace blitz {
@@ -23,10 +30,6 @@ struct Vec2 {
constexpr Vec2(T X = 0, T Y = 0) : x(X), y(Y) {}
};
template <typename T>
struct Vec3 {
union {
@@ -47,10 +50,6 @@ struct Vec3 {
constexpr Vec3(T X = 0, T Y = 0, T Z = 0) : x(X), y(Y), z(Z) {}
};
template <typename T>
struct Vec4 {
union {
@@ -77,23 +76,19 @@ struct Vec4 {
constexpr Vec4(T X = 0, T Y = 0, T Z = 0, T W = 0) : x(X), y(Y), z(Z), w(W) {}
};
using Vec2uc = Vec2<unsigned int>;
using Vec2uc = Vec2<unsigned char>;
using Vec2i = Vec2<int>;
using Vec2u = Vec2<unsigned int>;
using Vec2f = Vec2<float>;
using Vec2d = Vec2<double>;
using Vec3uc = Vec3<unsigned int>;
using Vec3uc = Vec3<unsigned char>;
using Vec3i = Vec3<int>;
using Vec3u = Vec3<unsigned int>;
using Vec3f = Vec3<float>;
using Vec3d = Vec3<double>;
using Vec4uc = Vec4<unsigned int>;
using Vec4uc = Vec4<unsigned char>;
using Vec4i = Vec4<int>;
using Vec4u = Vec4<unsigned int>;
using Vec4f = Vec4<float>;
@@ -130,7 +125,7 @@ constexpr Vec2<T> operator-(const Vec2<T>& vect) {
template <typename T>
constexpr Vec2<T> operator-(const Vec2<T>& vect, const Vec2<T>& other) {
return vect + (-other);
return {vect.x - other.x, vect.y - other.y};
}
template <typename T>
@@ -178,7 +173,7 @@ Vec3<T>& operator+=(Vec3<T>& vect, const Vec3<T>& other) {
template <typename T>
constexpr Vec3<T> operator-(const Vec3<T>& vect, const Vec3<T>& other) {
return vect + (-other);
return {vect.x - other.x, vect.y - other.y, vect.z - other.z};
}
template <typename T>
@@ -197,9 +192,44 @@ constexpr Vec3<T> operator*(T mult, const Vec3<T>& vect) {
return vect * mult;
}
template <typename T>
constexpr Vec3<T> operator*=(const Vec3<T>& vect, T mult) {
vect = vect * mult;
return vect;
}
template <typename T>
constexpr Vec3<T> operator*=(T mult, const Vec3<T>& vect) {
vect = vect * mult;
return vect;
}
template <typename T>
constexpr Vec3<T> operator*(const Vec3<T>& vect, const Vec3<T>& other) {
return {vect.x * other.x, vect.y * other.y, vect.z * other.z};
}
template <typename T>
Vec3<T>& operator*=(Vec3<T>& vect, const Vec3<T>& other) {
vect = vect * other;
return vect;
}
template <typename T>
constexpr Vec3<T> operator/(const Vec3<T>& vect, const Vec3<T>& other) {
return {vect.x / other.x, vect.y / other.y, vect.z / other.z};
}
template <typename T>
Vec3<T>& operator/=(Vec3<T>& vect, const Vec3<T>& other) {
vect = vect / other;
return vect;
}
template <typename T>
constexpr bool operator<(const Vec3<T>& vec3, const Vec3<T>& other) {
return vec3.x < other.x && vec3.y < other.y && vec3.z < other.z;
}
// Vec4
@@ -226,7 +256,7 @@ Vec4<T>& operator+=(Vec4<T>& vect, const Vec4<T>& other) {
template <typename T>
constexpr Vec4<T> operator-(const Vec4<T>& vect, const Vec4<T>& other) {
return vect + (-other);
return {vect.x - other.x, vect.y - other.y, vect.z - other.z, vect.w - other.w};
}
template <typename T>
@@ -245,10 +275,6 @@ constexpr Vec4<T> operator*(T mult, const Vec4<T>& vect) {
return vect * mult;
}
//////////////////////////////////////////////////////////////////
// Matrix //
//////////////////////////////////////////////////////////////////
@@ -279,26 +305,18 @@ struct Mat4 {
}
T at(std::size_t row, std::size_t column) const {
return operator[](row* MATRIX_SIZE + column);
return operator[](row * MATRIX_SIZE + column);
}
T& at(std::size_t row, std::size_t column) {
return operator[](row* MATRIX_SIZE + column);
return operator[](row * MATRIX_SIZE + column);
}
};
typedef Mat4<float> Mat4f;
typedef Mat4<int> Mat4i;
typedef Mat4<double> Mat4d;
template <typename T>
bool operator==(const Mat4<T>& mat, const Mat4<T>& other) {
return mat.x0 == other.x0 && mat.y0 == other.y0 && mat.z0 == other.z0 && mat.w0 == other.w0 && mat.x1 == other.x1 &&
@@ -306,5 +324,4 @@ bool operator==(const Mat4<T>& mat, const Mat4<T>& other) {
mat.z2 == other.z2 && mat.w2 == other.w2 && mat.x3 == other.x3 && mat.y3 == other.y3 && mat.z3 == other.z3 &&
mat.w3 == other.w3;
}
} // namespace blitz

View File

@@ -1,5 +0,0 @@
#pragma once
#define REMOVE_COPY(className) \
className(const className&) = delete; \
className& operator=(const className&) = delete

View File

@@ -1,63 +1,88 @@
#pragma once
/**
* \file Easing.h
* \brief File containing mathematical functions and constants
*/
namespace blitz {
namespace utils {
/* Sine functions */
/**
* \brief Sine functions
*/
float EaseInSine(float x);
float EaseOutSine(float x);
float EaseInOutSine(float x);
/* Cubic functions */
/**
* \brief Cubic functions
*/
float EaseInCubic(float x);
float EaseOutCubic(float x);
float EaseInOutCubic(float x);
/* Quint functions */
/**
* \brief Quint functions
*/
float EaseInQuint(float x);
float EaseOutQuint(float x);
float EaseInOutQuint(float x);
/* Circ functions */
/**
* \brief Circ functions
*/
float EaseInCirc(float x);
float EaseOutCirc(float x);
float EaseInOutCirc(float x);
/* Elastic functions */
/**
* \brief Elastic functions
*/
float EaseInElastic(float x);
float EaseOutElastic(float x);
float EaseInOutElastic(float x);
/* Quad functions */
/**
* \brief Quad functions
*/
float EaseInQuad(float x);
float EaseOutQuad(float x);
float EaseInOutQuad(float x);
/* Quart functions */
/**
* \brief Quart functions
*/
float EaseInQuart(float x);
float EaseOutQuart(float x);
float EaseInOutQuart(float x);
/* Expo functions */
/**
* \brief Expo functions
*/
float EaseInExpo(float x);
float EaseOutExpo(float x);
float EaseInOutExpo(float x);
/* Back functions */
/**
* \brief Back functions
*/
float EaseInBack(float x);
float EaseOutBack(float x);
float EaseInOutBack(float x);
/* Bounce functions */
/**
* \brief Bounce functions
*/
float EaseInBounce(float x);
float EaseOutBounce(float x);

View File

@@ -1,5 +1,10 @@
#pragma once
/**
* \file Format.h
* \brief This file contains the definition of the `Format` function.
*/
#include <memory>
#include <stdexcept>
#include <string>
@@ -7,6 +12,17 @@
namespace blitz {
namespace utils {
/**
* \brief Formats a string using a format string and variadic arguments.
*
* This function takes a format string and a variable number of arguments and returns a formatted string.
* The format string can contain placeholders that will be replaced by the corresponding arguments.
*
* \param format The format string.
* \param args The variadic arguments to be formatted.
* \return The formatted string.
* \throws std::runtime_error if an error occurs during formatting.
*/
template <typename... Args>
std::string Format(const std::string& format, Args... args) {
int size = snprintf(nullptr, 0, format.c_str(), args...) + 1; // Extra space for '\0'

View File

@@ -1,13 +1,32 @@
#pragma once
/**
* \file Log.h
* \brief File defining log functions
*/
#include <string>
namespace blitz {
namespace utils {
void LOG(const std::string& msg); // Normal
void LOGD(const std::string& msg); // Normal en mode debug
void LOGE(const std::string& err); // Normal erreur
/**
* \brief Logs a normal message.
* \param msg The message to be logged.
*/
void LOG(const std::string& msg);
/**
* \brief Logs a normal message in debug mode.
* \param msg The message to be logged.
*/
void LOGD(const std::string& msg);
/**
* \brief Logs an error message.
* \param err The error message to be logged.
*/
void LOGE(const std::string& err);
} // namespace utils
} // namespace blitz

View File

@@ -1,137 +0,0 @@
#pragma once
#include "blitz/common/Vector.h"
#include <cmath>
namespace blitz {
namespace maths {
static constexpr float PI = 3.141592653f;
//////////////////////////////////////////////////////////////////
// Vectors //
//////////////////////////////////////////////////////////////////
template <typename T>
T Length(const Vec3<T>& vect) {
return std::sqrt(vect.x * vect.x + vect.y * vect.y + vect.z * vect.z);
}
template <typename T>
Vec3<T> Normalize(const Vec3<T>& vect) {
T length = Length(vect);
return {vect.x / length, vect.y / length, vect.z / length};
}
template <typename T>
Vec4<T> Normalize(const Vec4<T>& vect) {
T length = std::sqrt(vect.x * vect.x + vect.y * vect.y + vect.z * vect.z + vect.w * vect.w);
return {vect.x / length, vect.y / length, vect.z / length, vect.w / length};
}
template <typename T>
T Dot(const Vec3<T>& vect, const Vec3<T>& other) {
return vect.x * other.x + vect.y * other.y + vect.z * other.z;
}
template <typename T>
Vec3<T> Cross(const Vec3<T>& vect, const Vec3<T>& other) {
return {
vect.y * other.z - vect.z * other.y,
vect.z * other.x - vect.x * other.z,
vect.x * other.y - vect.y * other.x,
};
}
template <typename T>
T Dot(const Vec4<T>& vect, const Vec4<T>& other) {
return vect.x * other.x + vect.y * other.y + vect.z * other.z + vect.w * other.w;
}
template <typename T>
T Distance(const Vec3<T>& vect, const Vec3<T>& other) {
return Length(vect - other);
}
//////////////////////////////////////////////////////////////////
// Matricies //
//////////////////////////////////////////////////////////////////
template <typename T>
Vec4<T> Dot(const Mat4<T>& mat, const Vec4<T>& vect) {
return {mat.x0 * vect.x + mat.x1 * vect.y + mat.x2 * vect.z + mat.x3 * vect.w,
mat.y0 * vect.x + mat.y1 * vect.y + mat.y2 * vect.z + mat.y3 * vect.w,
mat.z0 * vect.x + mat.z1 * vect.y + mat.z2 * vect.z + mat.z3 * vect.w,
mat.w0 * vect.x + mat.w1 * vect.y + mat.w2 * vect.z + mat.w3 * vect.w};
}
template <typename T>
Mat4<T> Dot(const Mat4<T>& mat, const Mat4<T>& other) {
Mat4<T> result{};
for (std::size_t i = 0; i < Mat4<T>::MATRIX_SIZE; i++) {
for (std::size_t j = 0; j < Mat4<T>::MATRIX_SIZE; j++) {
for (std::size_t k = 0; k < Mat4<T>::MATRIX_SIZE; k++) {
result.at(i, j) += mat.at(i, k) * other.at(k, j);
}
}
}
return result;
}
template <typename T>
Mat4<T> Identity() {
Mat4<T> result{};
result.x0 = static_cast<T>(1);
result.y1 = static_cast<T>(1);
result.z2 = static_cast<T>(1);
result.w3 = static_cast<T>(1);
return result;
}
template <typename T>
Mat4<T> Transpose(const Mat4<T>& mat) {
Mat4<T> result;
result.x1 = mat.y0;
result.x2 = mat.z0;
result.x3 = mat.w0;
result.y0 = mat.x1;
result.y2 = mat.z1;
result.y3 = mat.w1;
result.z0 = mat.x2;
result.z1 = mat.y2;
result.z3 = mat.w2;
result.w0 = mat.x3;
result.w1 = mat.y3;
result.w2 = mat.z3;
result.x0 = mat.x0;
result.y1 = mat.y1;
result.z2 = mat.z2;
result.w3 = mat.w3;
return result;
}
Mat4f Perspective(float fovY, float aspectRatio, float zNear, float zFar);
Mat4f Look(const Vec3f& eyePos, const Vec3f& front, const Vec3f& up);
Mat4f Inverse(const Mat4f& mat);
Mat4f Translate(const Vec3f& translation);
Mat4f RotateX(float angle);
Mat4f RotateY(float angle);
Mat4f RotateZ(float angle);
Mat4f Rotate(const Vec3f& angles);
Mat4f Rotate(float angle, Vec3f axis);
} // namespace maths
} // namespace blitz

View File

@@ -1,5 +1,10 @@
#pragma once
/**
* \file ObjectNotifier.h
* \brief File containing the blitz::ObjectNotifier class
*/
#include <algorithm>
#include <functional>
#include <vector>
@@ -7,16 +12,26 @@
namespace blitz {
namespace utils {
/**
* \class ObjectNotifier
* \brief Class used to notify listeners
*/
template <typename Listener>
class ObjectNotifier {
protected:
std::vector<Listener*> m_Listeners;
public:
/**
* \brief Binds a listener to notify later
*/
void BindListener(Listener* listener) {
m_Listeners.push_back(listener);
}
/**
* \brief Unbinds a listener (in case the listener is destroyed for example)
*/
void UnbindListener(Listener* listener) {
auto iter = std::find(m_Listeners.begin(), m_Listeners.end(), listener);
@@ -26,8 +41,11 @@ class ObjectNotifier {
m_Listeners.erase(iter);
}
/**
* \brief Notify listeners that were bound
*/
template <typename Func, typename... Args>
void NotifyListeners(Func function, Args... args) {
void NotifyListeners(Func function, Args... args) const {
for (Listener* listener : m_Listeners)
std::bind(function, listener, args...)();
}

View File

@@ -0,0 +1,36 @@
#pragma once
/**
* \file PrettyLog.h
* \brief File defining log functions with colors
*/
#include "blitz/maths/Vector.h"
#include <string>
namespace blitz {
namespace utils {
namespace TextColor {
const static Vec3uc AQUA = {0, 255, 255};
const static Vec3uc BLUE = {0, 0, 255};
const static Vec3uc GREEN = {0, 255, 0};
const static Vec3uc PURPLE = {255, 0, 255};
const static Vec3uc RED = {255, 0, 0};
const static Vec3uc WHITE = {255, 255, 255};
const static Vec3uc YELLOW = {255, 255, 0};
} // namespace TextColor
/**
* \brief Returns the color code for a given color.
*/
std::string GetTextColor(Vec3uc color);
/**
* \brief Returns the color code for the reset color.
*/
std::string GetTextColorReset();
} // namespace utils
} // namespace blitz

View File

@@ -1,10 +1,21 @@
#pragma once
/**
* \file Random.h
* \brief Defines functions for generating random numbers.
*/
#include <random>
namespace blitz {
namespace utils {
/**
* \brief Returns a random integer between min and max.
* \param min The minimum value.
* \param max The maximum value.
* \return A random integer between min and max.
*/
template <typename NumberType>
NumberType GetRandomInt(NumberType min, NumberType max) {
std::random_device randomDevice;
@@ -13,6 +24,12 @@ NumberType GetRandomInt(NumberType min, NumberType max) {
return distrib(generator);
}
/**
* \brief Returns a random real number between min and max.
* \param min The minimum value.
* \param max The maximum value.
* \return A random real number between min and max.
*/
template <typename NumberType>
NumberType GetRandomReal(NumberType min, NumberType max) {
std::random_device randomDevice;

View File

@@ -10,7 +10,16 @@
namespace blitz {
namespace utils {
/**
* \def BLITZ_TEST_SUCCESSFUL
* \brief Used in tests to indicate that a test was successful
*/
#define BLITZ_TEST_SUCCESSFUL 0
/**
* \def BLITZ_TEST_FAILED
* \brief Used in tests to indicate that a test failed
*/
#define BLITZ_TEST_FAILED 1
#ifndef __FUNCTION_NAME__
@@ -24,7 +33,8 @@ namespace utils {
/**
* \def blitz_test_assert
* \param ... The expression to evaluate
* \brief Evaluates the expression and exits the program if not valid
* \brief Evaluates the expression and exits the program if not valid.
* \note It works like a basic assert() but also in release mode
*/
#define blitz_test_assert(...) \
if (!static_cast<bool>(__VA_ARGS__)) { \
@@ -37,6 +47,7 @@ namespace utils {
* \def blitz_debug_assert
* \param ... The expression to execute
* \brief Assertion without checks in release mode
* \note The expression is always executed. However, in release, no checks are made !
*/
#ifdef NDEBUG
#define blitz_debug_assert(...) __VA_ARGS__

View File

@@ -1,10 +1,19 @@
#pragma once
/**
* \file TickCounter.h
* \brief File containing the blitz::utils::TickCounter class
*/
#include <cstdint>
namespace blitz {
namespace utils {
/**
* \class TickCounter
* \brief Class used to count ticks
*/
class TickCounter {
private:
float m_TPS;
@@ -14,19 +23,42 @@ class TickCounter {
int m_TargetTPS;
public:
/**
* \brief Constructor
* \param tps The target ticks per second
*/
TickCounter(int tps) : m_TargetTPS(tps) {}
/**
* \brief Reset the tick counter
*/
void Reset();
bool Update(); // return true when tps is updated
/**
* \brief Update the tick counter
* \return True if the tick counter has been updated
*/
bool Update();
/**
* \brief Get the ticks per second
* \return The ticks per second
*/
float GetTPS() const {
return m_TPS;
}
/**
* \brief Get the milliseconds per tick
* \return The milliseconds per tick
*/
float GetMSPT() const {
return m_MSPT;
}
/**
* \brief Set the ticks per second
* \param mspt The ticks per second
*/
void SetMSPT(float mspt) {
m_MSPT = mspt;
}

View File

@@ -1,16 +1,30 @@
#pragma once
/**
* \file Time.h
* \brief File containing the blitz::utils::AutoTimer, blitz::utils::Timer, blitz::utils::CooldownTimer and blitz::utils::DelayTimer
* classes
*/
#include <algorithm>
#include <cstdint>
#include <functional>
namespace blitz {
namespace utils {
/**
* \brief Get current time
* \return Time elapsed since epoch in milliseconds
*/
std::uint64_t GetTime();
typedef std::function<void()> TimerExecFunction;
// utililty class to call a function at regular period of time
/**
* \class AutoTimer
* \brief Calls a function at regular period of time
*/
class AutoTimer {
private:
std::uint64_t m_Interval;
@@ -20,79 +34,245 @@ class AutoTimer {
std::uint64_t m_InternalTime = 0;
public:
/**
* \brief Default constructor
*/
AutoTimer() : m_Interval(0), m_Function(nullptr) {}
/**
* \param interval Time between each function call in milliseconds
*/
AutoTimer(std::uint64_t interval) : m_Interval(interval), m_Function(nullptr) {}
/**
* \param interval Time between each function call in milliseconds
* \param callback The function to call peridocally
*/
AutoTimer(std::uint64_t interval, TimerExecFunction callback) : m_Interval(interval), m_Function(callback) {}
/**
* \brief Updates the timer
*/
void Update();
/**
* \brief Updates the timer with the desired time step
* \param delta The time step in milliseconds
*/
void Update(std::uint64_t delta);
/**
* \brief Resets the internal cooldown
*/
void Reset();
/**
* \brief Sets a new interval
* \param newInterval the new interval in milliseconds
*/
void SetInterval(std::uint64_t newInterval) {
m_Interval = newInterval;
}
/**
* \return The interval between each callback in milliseconds
*/
std::uint64_t GetInterval() const {
return m_Interval;
}
/**
* \brief Set a new callback function
* \param newCallback The function to call
*/
void SetCallbackFunction(TimerExecFunction newCallback) {
m_Function = newCallback;
}
/**
* \return The callback function
*/
TimerExecFunction GetCallbackFunction() const {
return m_Function;
}
};
// utililty class to trigger update at regular period of time
/**
* \class Timer
* \brief Utililty class to trigger update at regular period of time
*/
class Timer {
private:
std::uint64_t m_Interval; // in millis
std::uint64_t m_InternalTime = 0;
public:
/**
* \brief Default constructor
*/
Timer() : m_Interval(0) {}
/**
* \brief Construct a Timer with the desired interval
* \param interval The interval between each update in milliseconds
*/
Timer(std::uint64_t interval) : m_Interval(interval) {}
/**
* \brief Updates the timer
* \param delta The time step in milliseconds
* \return true every interval milliseconds
*/
bool Update(std::uint64_t delta);
/**
* \brief Resets the timer to its original state
*/
void Reset();
/**
* \return The time remaing before the next Update() call will return true (in milliseconds)
*/
std::uint64_t GetTimeRemaining() const {
return m_Interval - m_InternalTime;
}
/**
* \return The time elapsed since the previous Update() call returned true (in milliseconds)
*/
std::uint64_t GetTimeElapsed() const {
return m_InternalTime;
}
/**
* \brief Set a new value for the interval
* \param newInterval the new interval to set
*/
void SetInterval(std::uint64_t newInterval) {
m_Interval = newInterval;
}
/**
* \return The interval between each successful Update()
*/
std::uint64_t GetInterval() const {
return m_Interval;
}
};
// utililty class to trigger update at regular period of time with a cooldown
/**
* \class CooldownTimer
* \brief Class to trigger update at regular period of time with a cooldown
*/
template <typename T>
class CooldownTimer {
private:
std::uint64_t m_Cooldown; // in millis
std::uint64_t m_CooldownTime;
T m_Cooldown;
T m_CooldownTime;
public:
/**
* \brief Default constructor
*/
CooldownTimer() : m_Cooldown(0), m_CooldownTime(0) {}
CooldownTimer(std::uint64_t cooldown) : m_Cooldown(0), m_CooldownTime(cooldown) {}
bool Update(std::uint64_t delta);
/**
* \param cooldown The cooldown before Update() returns true again
*/
CooldownTimer(T cooldown) : m_Cooldown(0), m_CooldownTime(cooldown) {}
void ApplyCooldown();
/**
* \brief Update the timer
* \param delta the time step
*/
bool Update(T delta) {
if (m_Cooldown > 0) {
m_Cooldown = std::max<T>(static_cast<T>(0), static_cast<T>(m_Cooldown - delta));
}
return m_Cooldown == 0;
}
void Reset();
/**
* \brief Apply a cooldown for the timer
*/
void ApplyCooldown() {
m_Cooldown = m_CooldownTime;
}
void SetCooldown(std::uint64_t newCooldown) {
/**
* \brief Reset the cooldown. Update() will return true immediatly afterward.
*/
void Reset() {
m_Cooldown = 0;
}
/**
* \brief Change the timer cooldown
* \param newCooldown the new cooldown
*/
void SetCooldown(T newCooldown) {
m_CooldownTime = newCooldown;
}
std::uint64_t GetCooldown() const {
/**
* \return The cooldown of the timer
*/
T GetCooldown() const {
return m_CooldownTime;
}
};
/**
* \class DelayTimer
* \brief class to trigger an update after a period of time
*/
template <typename T>
class DelayTimer {
private:
T m_DelayTime;
T m_InternalTime;
public:
/**
* \brief Default constructor
*/
DelayTimer() : m_DelayTime(0), m_InternalTime(0) {}
/**
* \param delay The delay to set
*/
DelayTimer(T delay) : m_DelayTime(delay), m_InternalTime(delay) {}
/**
* \brief Returns true whether the delay has been passed.
*/
bool Update(T delta) {
m_InternalTime = std::max<T>(static_cast<T>(0), static_cast<T>(m_InternalTime - delta));
return m_InternalTime == 0;
}
/**
* \brief Resets the timer. Update() will immediatly return true
*/
void Reset() {
m_InternalTime = m_DelayTime;
}
/**
* \brief Changes the delay of the timer
* \param newDelay the new delay
*/
void SetDelay(T newDelay) {
m_DelayTime = newDelay;
}
/**
* \return the delay of the timer
*/
T GetDelay() const {
return m_DelayTime;
}
};
} // namespace utils
} // namespace blitz

View File

@@ -16,7 +16,7 @@ namespace network {
* \class Connexion
* \brief Represents a network connexion
*/
class Connexion : public protocol::PacketHandler {
class Connexion : public protocol::PacketHandler, private NonCopyable {
protected:
protocol::PacketDispatcher m_Dispatcher;
@@ -41,28 +41,28 @@ class Connexion : public protocol::PacketHandler {
/**
* \brief Default destructor
*/
*/
virtual ~Connexion();
/**
* \brief Reads socket and process a Packet, if any
*/
* \brief Reads socket and process a Packet, if any
*/
virtual bool UpdateSocket();
/**
* \brief Closes the connexion
*/
*/
void CloseConnection();
/**
* \brief Tries to connect the socket at the specified address and port
* \return Wether this action was succesfull
*/
virtual bool Connect(const std::string& address, std::uint16_t port);
* \return Whether this action was succesfull
*/
bool Connect(const std::string& address, std::uint16_t port);
/**
* \brief Returns the TCPSocket::Status of the internal socket
*/
*/
TCPSocket::Status GetSocketStatus() const {
return m_Socket.GetStatus();
}
@@ -70,13 +70,8 @@ class Connexion : public protocol::PacketHandler {
/**
* \brief Sends the protocol::Packet over the network to the remote
* \param packet The protocol::Packet to send
*/
*/
void SendPacket(const protocol::Packet* packet);
/**
* \brief Disables Connexion copy
*/
REMOVE_COPY(Connexion);
};
} // namespace network

View File

@@ -21,7 +21,7 @@ namespace network {
* \note This class is meant to be created only once in your program. \n
* The easiest thing to do is to create an instance of this class at the top of your **main.cpp**.
*/
class NetworkInitializer {
class NetworkInitializer : private NonCopyable {
public:
/**
* \brief Creates the networking context
@@ -31,8 +31,6 @@ class NetworkInitializer {
* \brief Destroys the networking context
*/
~NetworkInitializer();
REMOVE_COPY(NetworkInitializer);
};
} // namespace network

View File

@@ -14,7 +14,7 @@ namespace network {
* \class TCPListener
* \brief Cross platform abstraction of a TCP socket server
*/
class TCPListener {
class TCPListener : private NonCopyable {
private:
SocketHandle m_Handle;
std::uint16_t m_Port;
@@ -35,7 +35,7 @@ class TCPListener {
* \param port The port to listen to
* \param maxConnexions The maximum amount of connexion that can happen at the same time. \n
* Every other guests will be kicked if this amount is reached.
* \return Wether this action was succesfull
* \return Whether this action was succesfull
*/
bool Listen(std::uint16_t port, int maxConnexions);
@@ -79,11 +79,6 @@ class TCPListener {
int GetMaximumConnections() const {
return m_MaxConnections;
}
/**
* \brief Disables TCPListener copy
*/
REMOVE_COPY(TCPListener);
};
} // namespace network

View File

@@ -1,7 +1,7 @@
#pragma once
#include "blitz/common/DataBuffer.h"
#include "blitz/misc/ClassEntity.h"
#include "blitz/common/NonCopyable.h"
#ifdef _WIN32
#include <winsock2.h>
@@ -40,7 +40,7 @@ typedef int SocketHandle;
* \class TCPSocket
* \brief Cross platform abstraction of a TCP socket
*/
class TCPSocket {
class TCPSocket : private NonCopyable {
public:
/**
* \enum Status
@@ -153,11 +153,6 @@ class TCPSocket {
*/
std::size_t Receive(DataBuffer& buffer, std::size_t amount);
/**
* \brief Disable TCPSocket copy, as it disconnects when destroyed
*/
REMOVE_COPY(TCPSocket);
friend class TCPListener;
};

View File

@@ -1,5 +1,11 @@
#pragma once
/**
* \file PacketDispatcher.h
* \brief File containing the blitz::protocol::PacketDispatcher class
*/
#include "blitz/common/NonCopyable.h"
#include "blitz/protocol/Protocol.h"
#include <map>
@@ -9,22 +15,42 @@ namespace protocol {
class PacketHandler;
class PacketDispatcher {
/**
* \class PacketDispatcher
* \brief Class used to dispatch packets
*/
class PacketDispatcher : private NonCopyable {
private:
std::map<PacketType, std::vector<PacketHandler*>> m_Handlers;
public:
PacketDispatcher() = default;
PacketDispatcher(const PacketDispatcher& rhs) = delete;
PacketDispatcher& operator=(const PacketDispatcher& rhs) = delete;
PacketDispatcher(PacketDispatcher&& rhs) = delete;
PacketDispatcher& operator=(PacketDispatcher&& rhs) = delete;
/**
* \brief Constructor
*/
PacketDispatcher() {}
/**
* \brief Dispatch a packet
* \param packet The packet to dispatch
*/
void Dispatch(const Packet* packet);
/**
* \brief Register a packet handler
* \param type The packet type
* \param handler The packet handler
*/
void RegisterHandler(PacketType type, PacketHandler* handler);
/**
* \brief Unregister a packet handler
* \param type The packet type
* \param handler The packet handler
*/
void UnregisterHandler(PacketType type, PacketHandler* handler);
/**
* \brief Unregister a packet handler
* \param handler The packet handler
*/
void UnregisterHandler(PacketHandler* handler);
};

View File

@@ -1,13 +1,26 @@
#pragma once
/**
* \file PacketFactory.h
*/
#include "blitz/protocol/Protocol.h"
#include <memory>
namespace blitz {
namespace protocol {
typedef std::unique_ptr<Packet> PacketPtr;
namespace PacketFactory {
const Packet* CreatePacket(PacketType type, DataBuffer& buffer);
/**
* \brief Creates a packet from a buffer.
* \param buffer The buffer containing the packet data.
* \return The created packet.
*/
const PacketPtr CreatePacket(PacketType type, DataBuffer& buffer);
}
} // namespace PacketFactory
} // namespace protocol
} // namespace blitz

View File

@@ -1,5 +1,10 @@
#pragma once
/**
* \file PacketHandler.h
* \brief File containing the blitz::protocol::PacketHandler class
*/
#include "blitz/protocol/PacketsForward.h"
#include "blitz/protocol/Protocol.h"
@@ -8,14 +13,26 @@ namespace protocol {
class PacketDispatcher;
/**
* \class PacketHandler
* \brief Class used to handle packets
*/
class PacketHandler {
private:
PacketDispatcher* m_Dispatcher;
public:
/**
* \brief Constructor
* \param dispatcher The packet dispatcher
*/
PacketHandler(PacketDispatcher* dispatcher) : m_Dispatcher(dispatcher) {}
virtual ~PacketHandler() {}
/**
* \brief Get the packet dispatcher
* \return The packet dispatcher
*/
PacketDispatcher* GetDispatcher() {
return m_Dispatcher;
}
@@ -29,7 +46,12 @@ class PacketHandler {
virtual void HandlePacket(const PlayerListPacket* packet) {}
virtual void HandlePacket(const PlayerLoginPacket* packet) {}
virtual void HandlePacket(const PlayerPositionAndRotationPacket* packet) {}
virtual void HandlePacket(const PlayerShootPacket* packet) {}
virtual void HandlePacket(const PlayerStatsPacket* packet) {}
virtual void HandlePacket(const ServerConfigPacket* packet) {}
virtual void HandlePacket(const ServerTpsPacket* packet) {}
virtual void HandlePacket(const UpdateGameStatePacket* packet) {}
virtual void HandlePacket(const UpdateHealthPacket* packet) {}
};
} // namespace protocol

View File

@@ -7,4 +7,9 @@
#include "packets/PlayerListPacket.h"
#include "packets/PlayerLoginPacket.h"
#include "packets/PlayerPositionAndRotationPacket.h"
#include "packets/ServerTpsPacket.h"
#include "packets/PlayerShootPacket.h"
#include "packets/PlayerStatsPacket.h"
#include "packets/ServerConfigPacket.h"
#include "packets/ServerTpsPacket.h"
#include "packets/UpdateGameStatePacket.h"
#include "packets/UpdateHealthPacket.h"

View File

@@ -12,7 +12,12 @@ class PlayerLeavePacket;
class PlayerListPacket;
class PlayerLoginPacket;
class PlayerPositionAndRotationPacket;
class PlayerShootPacket;
class PlayerStatsPacket;
class ServerConfigPacket;
class ServerTpsPacket;
class UpdateGameStatePacket;
class UpdateHealthPacket;
} // namespace protocol
} // namespace blitz

View File

@@ -2,7 +2,7 @@
/**
* \file Protocol.h
* \brief File describing protocol
* \brief File containing the blitz::protocol::Protocol class
*/
#include "blitz/common/DataBuffer.h"
@@ -20,14 +20,18 @@ enum class PacketType : std::uint8_t {
// client --> server
PlayerLogin = 0, /**< Corresponds to PlayerLoginPacket */
UpdateHealth, /**< Corresponds to UpdateHealthPacket */
// client <-- server
ConnexionInfo, /**< Corresponds to ConnexionInfoPacket */
PlayerJoin, /**< Corresponds to PlayerJoinPacket */
PlayerLeave, /**< Corresponds to PlayerLeavePacket */
PlayerList, /**< Corresponds to PlayerListPacket */
ServerTps, /**< Corresponds to ServerTpsPacket */
ConnexionInfo, /**< Corresponds to ConnexionInfoPacket */
PlayerJoin, /**< Corresponds to PlayerJoinPacket */
PlayerLeave, /**< Corresponds to PlayerLeavePacket */
PlayerList, /**< Corresponds to PlayerListPacket */
PlayerStats, /**< Corresponds to PlayerStatsPacket */
ServerConfig, /**< Corresponds to ServerConfigPacket*/
ServerTps, /**< Corresponds to ServerTpsPacket */
UpdateGameState, /**< Corresponds to UpdateGameStatePacket */
// client <--> server
@@ -35,6 +39,7 @@ enum class PacketType : std::uint8_t {
Disconnect, /**< Corresponds to DisconnectPacket */
Chat, /**< Corresponds to ChatPacket */
PlayerPositionAndRotation, /**< Corresponds to PlayerPositionAndRotationPacket */
PlayerShoot, /**< Corresponds to PlayerShootPacket */
PACKET_COUNT
};

View File

@@ -1,26 +1,64 @@
#pragma once
#include "blitz/common/Vector.h"
/**
* \file ChatPacket.h
* \brief File containing the blitz::protocol::ChatPacket class
*/
#include "blitz/maths/Vector.h"
#include "blitz/protocol/Protocol.h"
#include <vector>
namespace blitz {
namespace protocol {
/**
* \struct ColoredPart
* \brief Represents a part of a chat message with a specific color.
*/
struct ColoredPart {
/**
* \brief The color of the part.
*/
Vec4f color;
/**
* \brief The text of the part.
*/
std::string text;
};
typedef std::vector<ColoredPart> ColoredText;
/**
* \class ChatPacket
* \brief Packet for sending chat messages.
* %Packet structure :
* | PacketType |
* |------------------------|
* | PacketType::Chat |
*
* | Field Name | Field Type | Notes |
* |--------------------|-------------------|-------------------------------|
* | m_Message | ColoredText | The message sent in the chat |
*/
class ChatPacket : public Packet {
private:
ColoredText m_Message;
public:
/**
* \brief Default constructor.
*/
ChatPacket() {}
/**
* \brief Constructor.
* \param msg The message to send.
*/
ChatPacket(const std::string& msg) : m_Message(ColorizeText(msg)) {}
/**
* \brief Constructor.
* \param msg The message to send.
*/
ChatPacket(const ColoredText& msg) : m_Message(msg) {}
virtual ~ChatPacket() {}
@@ -28,6 +66,10 @@ class ChatPacket : public Packet {
virtual void Deserialize(DataBuffer& data);
virtual void Dispatch(PacketHandler* handler) const;
/**
* \brief Get the message.
* \return The message.
*/
const ColoredText& GetMessage() const {
return m_Message;
}
@@ -36,8 +78,17 @@ class ChatPacket : public Packet {
return PacketType::Chat;
}
/**
* \brief Get the text color.
*/
static std::string GetTextColor(Vec3uc color);
/**
* \brief Colorize a text.
*/
static ColoredText ColorizeText(const std::string& text);
/**
* \brief Get the colored text string.
*/
static std::string GetColoredTextString(const ColoredText& text);
};

View File

@@ -1,16 +1,40 @@
#pragma once
/**
* \file ConnexionInfoPacket.h
* \brief File containing the blitz::protocol::ConnexionInfoPacket class
*/
#include "blitz/protocol/Protocol.h"
namespace blitz {
namespace protocol {
/**
* \class ConnexionInfoPacket
* \brief Packet for sending connection information.
* %Packet structure :
* | PacketType |
* |------------------------|
* | PacketType::ConnexionInfo |
*
* | Field Name | Field Type | Notes |
* |--------------------|-------------------|-------------------------------|
* | m_ConnectionID | std::uint8_t | The connection ID |
*/
class ConnexionInfoPacket : public Packet {
private:
std::uint8_t m_ConnectionID;
public:
/**
* \brief Default constructor.
*/
ConnexionInfoPacket() {}
/**
* \brief Constructor.
* \param connectionID The ID of the connection.
*/
ConnexionInfoPacket(std::uint8_t connectionID) : m_ConnectionID(connectionID) {}
virtual ~ConnexionInfoPacket() {}
@@ -18,6 +42,10 @@ class ConnexionInfoPacket : public Packet {
virtual void Deserialize(DataBuffer& data);
virtual void Dispatch(PacketHandler* handler) const;
/**
* \brief Get the connection ID.
* \return The connection ID.
*/
std::uint8_t GetConnectionID() const {
return m_ConnectionID;
}

View File

@@ -1,15 +1,39 @@
#pragma once
/**
* \file DisconnectPacket.h
* \brief File containing the blitz::protocol::DisconnectPacket class
*/
#include "blitz/protocol/Protocol.h"
namespace blitz {
namespace protocol {
/**
* \class DisconnectPacket
* \brief Packet for disconnecting from the server.
* %Packet structure :
* | PacketType |
* |------------------------|
* | PacketType::Disconnect |
*
* | Field Name | Field Type | Notes |
* |--------------------|-------------------|-------------------------------|
* | m_Reason | std::string | The reason for disconnection |
*/
class DisconnectPacket : public Packet {
private:
std::string m_Reason; // only when sent from server
public:
/**
* \brief Default constructor.
*/
DisconnectPacket() {}
/**
* \brief Constructor.
* \param reason The reason for disconnection.
*/
DisconnectPacket(std::string reason) : m_Reason(reason) {}
virtual ~DisconnectPacket() {}
@@ -17,6 +41,10 @@ class DisconnectPacket : public Packet {
virtual void Deserialize(DataBuffer& data);
virtual void Dispatch(PacketHandler* handler) const;
/**
* \brief Get the reason for disconnection.
* \return The reason for disconnection.
*/
const std::string& GetReason() const {
return m_Reason;
}

View File

@@ -13,14 +13,14 @@ namespace protocol {
/**
* \class KeepAlivePacket
* \brief %Packet sent to measure the health of a connexion. \n
* \brief Packet sent to measure the health of a connexion. \n
* The client must respond with the same alive ID. Else, the connexion will be closed. \n
* %Packet structure :
* %Packet structure :
* | PacketType |
* |------------------------|
* | PacketType::KeepAlive |
*
* | Field Name | Field Type | Notes |
*
* | Field Name | Field Type | Notes |
* |--------------------|---------------|---------------------------------------------------------------------------|
* | Keep Alive ID | VarInt | The server generates a random ID, the client must respond with the same |
*

View File

@@ -13,7 +13,7 @@ namespace protocol {
/**
* \class PlayerJoinPacket
* \brief %Packet sent when a new player joins the game \n
* \brief Packet sent when a new player joins the game
* %Packet structure :
* | PacketType |
* |------------------------|

View File

@@ -1,24 +1,53 @@
#pragma once
/**
* \file PlayerLeavePacket.h
* \brief File containing the blitz::protocol::PlayerLeavePacket class
*/
#include "blitz/common/Defines.h"
#include "blitz/protocol/Protocol.h"
namespace blitz {
namespace protocol {
/**
* \class PlayerLeavePacket
* \brief Packet for when a player leaves the game.
* %Packet structure :
* | PacketType |
* |------------------------|
* | PacketType::PlayerLeave|
*
* | Field Name | Field Type | Notes |
* |--------------------|-------------------|-------------------------------|
* | m_PlayerID | PlayerID |The ID of the player that left |
*/
class PlayerLeavePacket : public Packet {
private:
std::uint8_t m_PlayerID;
game::PlayerID m_PlayerID;
public:
/**
* \brief Default constructor.
*/
PlayerLeavePacket() {}
PlayerLeavePacket(std::uint8_t playerID) : m_PlayerID(playerID) {}
/**
* \brief Constructor.
* \param playerID The ID of the player that left.
*/
PlayerLeavePacket(game::PlayerID playerID) : m_PlayerID(playerID) {}
virtual ~PlayerLeavePacket() {}
virtual DataBuffer Serialize(bool packetID = true) const;
virtual void Deserialize(DataBuffer& data);
virtual void Dispatch(PacketHandler* handler) const;
std::uint8_t GetPlayerID() const {
/**
* \brief Get the ID of the player that left.
* \return The ID of the player that left.
*/
game::PlayerID GetPlayerID() const {
return m_PlayerID;
}

View File

@@ -1,5 +1,10 @@
#pragma once
/**
* \file PlayerListPacket.h
* \brief File containing the blitz::protocol::PlayerListPacket class
*/
#include <map>
#include "blitz/protocol/Protocol.h"
@@ -7,18 +12,34 @@
namespace blitz {
namespace protocol {
/**
* \struct PlayerInfo
* \brief Represents information about a player.
*/
struct PlayerInfo {
std::string name;
};
typedef std::map<std::uint8_t, PlayerInfo> PlayerList;
/**
* \class PlayerListPacket
* \brief Packet for sending the list of players.
* \todo PACKET STRUCTURE
*/
class PlayerListPacket : public Packet {
private:
PlayerList m_Players;
public:
/**
* \brief Default constructor.
*/
PlayerListPacket() {}
/**
* \brief Constructor.
* \param players The list of players.
*/
PlayerListPacket(const PlayerList& players) : m_Players(players) {}
virtual ~PlayerListPacket() {}
@@ -26,6 +47,11 @@ class PlayerListPacket : public Packet {
virtual void Deserialize(DataBuffer& data);
virtual void Dispatch(PacketHandler* handler) const;
/**
* \brief Get the list of players.
* \return The list of players.
*/
const PlayerList& GetPlayers() const {
return m_Players;
}

View File

@@ -1,16 +1,40 @@
#pragma once
/**
* \file PlayerLoginPacket.h
* \brief File containing the blitz::protocol::PlayerLoginPacket class
*/
#include "blitz/protocol/Protocol.h"
namespace blitz {
namespace protocol {
/**
* \class PlayerLoginPacket
* \brief Packet for when a player logs in.
* %Packet structure :
* | PacketType |
* |------------------------|
* | PacketType::PlayerLogin|
*
* | Field Name | Field Type | Notes |
* |--------------------|-------------------|----------------------------------|
* | Player Name | std::string | Name of the player that logged in|
*/
class PlayerLoginPacket : public Packet {
private:
std::string m_PlayerName;
public:
/**
* \brief Default constructor.
*/
PlayerLoginPacket() {}
/**
* \brief Constructor.
* \param playerName The name of the player that logged in.
*/
PlayerLoginPacket(std::string playerName) : m_PlayerName(playerName) {}
virtual ~PlayerLoginPacket() {}
@@ -18,13 +42,17 @@ class PlayerLoginPacket : public Packet {
virtual void Deserialize(DataBuffer& data);
virtual void Dispatch(PacketHandler* handler) const;
virtual PacketType GetType() const {
return PacketType::PlayerLogin;
}
/**
* \brief Get the name of the player that logged in.
* \return The name of the player that logged in.
*/
const std::string& GetPlayerName() const {
return m_PlayerName;
}
virtual PacketType GetType() const {
return PacketType::PlayerLogin;
}
};
} // namespace protocol

View File

@@ -1,12 +1,32 @@
#pragma once
/**
* \file PlayerPositionAndRotationPacket.h
* \brief File containing the blitz::protocol::PlayerPositionAndRotationPacket class
*/
#include "blitz/common/Defines.h"
#include "blitz/common/Vector.h"
#include "blitz/maths/Vector.h"
#include "blitz/protocol/Protocol.h"
namespace blitz {
namespace protocol {
/**
* \class PlayerPositionAndRotationPacket
* \brief Packet for sending a player's position and rotation.
* %Packet structure :
* | PacketType |
* |--------------------------------|
* | PacketType::PlayerPositionAndRotation |
*
* | Field Name | Field Type | Notes |
* |--------------------|-------------------|----------------------------------|
* | Player ID | PlayerID | Id of the player who moved |
* | Position | Vec3f | Position of the player |
* | Yaw | float | Yaw of the player |
* | Pitch | float | Pitch of the player |
*/
class PlayerPositionAndRotationPacket : public Packet {
private:
game::PlayerID m_Player; // only used when sent to client
@@ -14,28 +34,53 @@ class PlayerPositionAndRotationPacket : public Packet {
float m_Yaw, m_Pitch;
public:
/**
* \brief Default constructor.
*/
PlayerPositionAndRotationPacket() {}
/**
* \brief Constructor.
* \param position The position of the player.
* \param yaw The yaw of the player.
* \param pitch The pitch of the player.
* \param player The ID of the player.
*/
PlayerPositionAndRotationPacket(const Vec3f& position, float yaw, float pitch, game::PlayerID player = 0) :
m_Player(player), m_Position(position), m_Yaw(yaw), m_Pitch(pitch) {}
virtual ~PlayerPositionAndRotationPacket() {}
virtual DataBuffer Serialize(bool packetID = true) const;
virtual void Deserialize(DataBuffer& data);
virtual void Dispatch(PacketHandler* handler) const;
/**
* \brief Get the position of the player.
* \return The position of the player.
*/
const Vec3f& GetPosition() const {
return m_Position;
}
/**
* \brief Get the yaw of the player.
* \return The yaw of the player.
*/
float GetYaw() const {
return m_Yaw;
}
/**
* \brief Get the pitch of the player.
* \return The pitch of the player.
*/
float GetPitch() const {
return m_Pitch;
}
/**
* \brief Get the ID of the player.
* \return The ID of the player.
*/
game::PlayerID GetPlayer() const {
return m_Player;
}

View File

@@ -0,0 +1,93 @@
#pragma once
/**
* \file PlayerShootPacket.h
* \brief File containing the blitz::protocol::PlayerShootPacket class
*/
#include "blitz/game/Player.h"
#include "blitz/protocol/Protocol.h"
namespace blitz {
namespace protocol {
/**
* \class PlayerShootPacket
* \brief Packet for when a player shoots.
* %Packet structure :
* | PacketType |
* |------------------------|
* | PacketType::PlayerShoot|
*
* | Field Name | Field Type | Notes |
* |--------------------|-------------------|----------------------------------|
* | Player ID | PlayerID | The ID of the player that shot |
* | Position | Vec3f | Position of the player |
* | Yaw | float | Yaw of the player |
* | Pitch | float | Pitch of the player |
*/
class PlayerShootPacket : public Packet {
private:
game::PlayerID m_Player; // only used when sent to client
Vec3f m_Position;
float m_Yaw, m_Pitch;
public:
/**
* \brief Default constructor.
*/
PlayerShootPacket() {}
/**
* \brief Constructor.
* \param position The position of the player.
* \param yaw The yaw of the player.
* \param pitch The pitch of the player.
* \param player The ID of the player.
*/
PlayerShootPacket(Vec3f position, float yaw, float pitch, game::PlayerID player = 0) :
m_Player(player), m_Position(position), m_Yaw(yaw), m_Pitch(pitch) {}
virtual ~PlayerShootPacket() {}
virtual DataBuffer Serialize(bool packetID = true) const;
virtual void Deserialize(DataBuffer& data);
virtual void Dispatch(PacketHandler* handler) const;
/**
* \brief Get the position of the player.
* \return The position of the player.
*/
const Vec3f& GetPosition() const {
return m_Position;
}
/**
* \brief Get the yaw of the player.
* \return The yaw of the player.
*/
float GetYaw() const {
return m_Yaw;
}
/**
* \brief Get the pitch of the player.
* \return The pitch of the player.
*/
float GetPitch() const {
return m_Pitch;
}
/**
* \brief Get the ID of the player.
* \return The ID of the player.
*/
game::PlayerID GetPlayer() const {
return m_Player;
}
virtual PacketType GetType() const {
return PacketType::PlayerShoot;
}
};
} // namespace protocol
} // namespace blitz

View File

@@ -0,0 +1,72 @@
#pragma once
/**
* \file PlayerStatsPacket.h
* \brief File containing the blitz::protocol::PlayerStatsPacket class
*/
#include "blitz/common/Defines.h"
#include "blitz/game/Player.h"
#include "blitz/protocol/Protocol.h"
namespace blitz {
namespace protocol {
/**
* \class PlayerStatsPacket
* \brief Packet for sending player stats.
* %Packet structure :
* | PacketType |
* |------------------------|
* | PacketType::PlayerStats|
*
* | Field Name | Field Type | Notes |
* |--------------------|-------------------|-------------------------------|
* | Player ID | PlayerID | Id of the player |
* | Player Stats | PlayerStats | Stats of the player |
*/
class PlayerStatsPacket : public Packet {
private:
game::PlayerID m_PlayerID;
game::PlayerStats m_PlayerStats;
public:
/**
* \brief Default constructor.
*/
PlayerStatsPacket() {}
/**
* \brief Constructor.
* \param playerID The ID of the player.
* \param stats The stats of the player.
*/
PlayerStatsPacket(game::PlayerID playerID, const game::PlayerStats& stats) : m_PlayerID(playerID), m_PlayerStats(stats) {}
virtual ~PlayerStatsPacket() {}
virtual DataBuffer Serialize(bool packetID = true) const;
virtual void Deserialize(DataBuffer& data);
virtual void Dispatch(PacketHandler* handler) const;
/**
* \brief Getter of the player id
* \return The ID of the player
*/
game::PlayerID GetPlayerID() const {
return m_PlayerID;
}
/**
* \brief Getter of the player stats
* \return The stats of the player
*/
const game::PlayerStats& GetPlayerStats() const {
return m_PlayerStats;
}
virtual PacketType GetType() const {
return PacketType::PlayerStats;
}
};
} // namespace protocol
} // namespace blitz

View File

@@ -0,0 +1,60 @@
#pragma once
/**
* \file ServerConfigPacket.h
* \brief File containing the blitz::protocol::ServerConfigPacket class
*/
#include "blitz/game/Game.h"
#include "blitz/protocol/Protocol.h"
namespace blitz {
namespace protocol {
/**
* \class ServerConfigPacket
* \brief Packet for sending the server configuration.
* %Packet structure :
* | PacketType |
* |-------------------------|
* | PacketType::ServerConfig|
*
* | Field Name | Field Type | Notes |
* |--------------------|-------------------|-------------------------------|
* | Game Config | GameConfig | The game configuration |
*/
class ServerConfigPacket : public Packet {
private:
game::GameConfig m_GameConfig;
public:
/**
* \brief Default constructor.
*/
ServerConfigPacket() {}
/**
* \brief Constructor.
* \param GameConfig The game configuration.
*/
ServerConfigPacket(const game::GameConfig& GameConfig) : m_GameConfig(GameConfig) {}
virtual ~ServerConfigPacket() {}
virtual DataBuffer Serialize(bool packetID = true) const;
virtual void Deserialize(DataBuffer& data);
virtual void Dispatch(PacketHandler* handler) const;
/**
* \brief Getter of the game configuration
* \return The game configuration
*/
game::GameConfig GetGameConfig() const {
return m_GameConfig;
}
virtual PacketType GetType() const {
return PacketType::ServerConfig;
}
};
} // namespace protocol
} // namespace blitz

View File

@@ -1,17 +1,45 @@
#pragma once
/**
* \file ServerTpsPacket.h
* \brief File containing the blitz::protocol::ServerTpsPacket class
*/
#include "blitz/protocol/Protocol.h"
namespace blitz {
namespace protocol {
/**
* \class ServerTpsPacket
* \brief Packet for sending server TPS (Tick per second) and MSPT (Milliseconds per tick).
* %Packet structure :
* | PacketType |
* |------------------------|
* | PacketType::ServerTps |
*
* | Field Name | Field Type | Notes |
* |--------------------|-------------------|-------------------------------|
* | Tps | float | Server TPS |
* | Mspt | float | Server MSPT |
* | PacketSendTime | uint64_t | Time the packet was sent |
*/
class ServerTpsPacket : public Packet {
private:
float m_TPS;
float m_MSPT;
std::uint64_t m_PacketSendTime; // used to calculate ping
public:
/**
* \brief Default constructor.
*/
ServerTpsPacket() {}
/**
* \brief Constructor.
* \param tps The server TPS.
* \param mspt The server MSPT.
* \param sendTime The time the packet was sent.
*/
ServerTpsPacket(float tps, float mspt, std::uint64_t sendTime) : m_TPS(tps), m_MSPT(mspt), m_PacketSendTime(sendTime) {}
virtual ~ServerTpsPacket() {}
@@ -19,14 +47,27 @@ class ServerTpsPacket : public Packet {
virtual void Deserialize(DataBuffer& data);
virtual void Dispatch(PacketHandler* handler) const;
/**
* \brief Get the server TPS.
* \return The server TPS.
*/
float GetTPS() const {
return m_TPS;
}
/**
* \brief Get the server MSPT.
* \return The server MSPT.
*/
float GetMSPT() const {
return m_MSPT;
}
/**
* \brief Get the time the packet was sent.
* \return The time the packet was sent.
* \todo Calculate ping.
*/
std::uint64_t GetPacketSendTime() const {
return m_PacketSendTime;
}

View File

@@ -0,0 +1,72 @@
#pragma once
/**
* \file UpdateGameStatePacket.h
* \brief File containing the blitz::protocol::UpdateGameStatePacket class
*/
#include "blitz/game/Game.h"
#include "blitz/protocol/Protocol.h"
namespace blitz {
namespace protocol {
/**
* \class UpdateGameStatePacket
* \brief Packet for updating the game state.
* %Packet structure :
* | PacketType |
* |-----------------------------|
* | PacketType::UpdateGameState |
*
* | Field Name | Field Type | Notes |
* |--------------------|-------------------|----------------------------------------------|
* | Game State | GameState | The new game state |
* | Time Remaining | std::uint64_t | The time remaining in the current game state |
*/
class UpdateGameStatePacket : public Packet {
private:
game::GameState m_GameState;
std::uint64_t m_TimeRemaining;
public:
/**
* \brief Default constructor.
*/
UpdateGameStatePacket() {}
/**
* \brief Constructor.
* \param a_GameState The new game state.
* \param a_TimeRemaining The time remaining in the current game state.
*/
UpdateGameStatePacket(game::GameState a_GameState, std::uint64_t a_TimeRemaining = 0) :
m_GameState(a_GameState), m_TimeRemaining(a_TimeRemaining) {}
virtual ~UpdateGameStatePacket() {}
virtual DataBuffer Serialize(bool packetID = true) const;
virtual void Deserialize(DataBuffer& data);
virtual void Dispatch(PacketHandler* handler) const;
/**
* \brief Get the new game state.
* \return The new game state.
*/
game::GameState GetGameState() const {
return m_GameState;
}
/**
* \brief Get the time remaining in the current game state.
* \return The time remaining in the current game state.
*/
std::uint64_t GetTimeRemaining() const {
return m_TimeRemaining;
}
virtual PacketType GetType() const {
return PacketType::UpdateGameState;
}
};
} // namespace protocol
} // namespace blitz

View File

@@ -0,0 +1,59 @@
#pragma once
/**
* \file UpdateHealthPacket.h
* \brief File containing the blitz::protocol::UpdateHealthPacket class
*/
#include "blitz/protocol/Protocol.h"
namespace blitz {
namespace protocol {
/**
* \class UpdateHealthPacket
* \brief Packet for updating the health of a player.
* %Packet structure :
* | PacketType |
* |--------------------------|
* | PacketType::UpdateHealth |
*
* | Field Name | Field Type | Notes |
* |--------------------|-------------------|-------------------------------|
* | m_NewHealth | float | The new health value |
*/
class UpdateHealthPacket : public Packet {
private:
float m_NewHealth;
public:
/**
* \brief Default constructor.
*/
UpdateHealthPacket() {}
/**
* \brief Constructor.
* \param newHealth The new health value.
*/
UpdateHealthPacket(float newHealth) : m_NewHealth(newHealth) {}
virtual ~UpdateHealthPacket() {}
virtual DataBuffer Serialize(bool packetID = true) const;
virtual void Deserialize(DataBuffer& data);
virtual void Dispatch(PacketHandler* handler) const;
/**
* \brief Get the new health value.
* \return The new health value.
*/
float GetNewHealth() const {
return m_NewHealth;
}
virtual PacketType GetType() const {
return PacketType::UpdateHealth;
}
};
} // namespace protocol
} // namespace blitz

View File

@@ -5,6 +5,7 @@
#include "blitz/misc/Time.h"
#include "blitz/protocol/packets/ChatPacket.h"
#include "client/config/BlitzConfig.h"
#include "client/game/Listeners.h"
#include <cstdint>
#include <memory>
#include <string>
@@ -22,14 +23,10 @@ namespace server {
class Server;
} // namespace server
class GuiListener {
public:
virtual void OnTextChatReceived(const protocol::ColoredText& text) {}
virtual void OnSpectatorChange(const game::PlayerID player) {}
};
// Singleton
class Client : public utils::ObjectNotifier<GuiListener> {
class Client : public utils::ObjectNotifier<game::ClientListener>, public game::PlayerInputListener {
private:
std::unique_ptr<server::Server> m_Server;
std::unique_ptr<client::ClientConnexion> m_Connexion;
@@ -55,6 +52,8 @@ class Client : public utils::ObjectNotifier<GuiListener> {
void SendPlayerPosAndLook(const Vec3f& position, float yaw, float pitch);
virtual void OnLocalPlayerShoot(const Vec3f& position, float yaw, float pitch) override;
game::PlayerID GetPlayerID() const;
client::ClientGame* GetGame() {
@@ -65,6 +64,14 @@ class Client : public utils::ObjectNotifier<GuiListener> {
return &m_Config;
}
bool IsAdmin() const;
server::Server* GetServer() {
return m_Server.get();
}
void UpdateServerConfig();
private:
void Reset();

View File

@@ -24,7 +24,7 @@ class ClientConnexion : public network::Connexion {
virtual void HandlePacket(const protocol::ChatPacket* packet) override;
virtual void HandlePacket(const protocol::ConnexionInfoPacket* packet) override;
virtual bool Connect(const std::string& pseudo, const std::string& address, std::uint16_t port);
bool Connect(const std::string& pseudo, const std::string& address, std::uint16_t port);
game::PlayerID GetPlayerID() const {
return m_PlayerID;

View File

@@ -0,0 +1,25 @@
#pragma once
#include "blitz/common/DataBuffer.h"
#include "blitz/common/NonCopyable.h"
#include "blitz/maths/Vector.h"
#include "client/audio/AudioLoader.h"
namespace blitz {
namespace audio {
class AudioBuffer : private NonCopyable {
private:
unsigned int m_ID;
public:
AudioBuffer(AudioData&& audioData);
~AudioBuffer();
unsigned int GetID() const {
return m_ID;
}
};
} // namespace audio
} // namespace blitz

View File

@@ -0,0 +1,21 @@
#pragma once
#include "blitz/common/NonCopyable.h"
#include "blitz/maths/Vector.h"
namespace blitz {
namespace audio {
class AudioListener : private NonCopyable {
public:
AudioListener();
~AudioListener();
void SetGain(float a_Gain);
void SetPosition(const Vec3f& a_Position);
void SetVelocity(const Vec3f& a_Velocity);
void SetOrientation(const Vec3f& a_Orientation, const Vec3f& a_Up);
};
} // namespace audio
} // namespace blitz

View File

@@ -0,0 +1,24 @@
#pragma once
#include "blitz/common/DataBuffer.h"
namespace blitz {
namespace audio {
enum AudioFormat { afMono8 = 0, afMono16, afStereo8, afStereo16 };
struct AudioData {
DataBuffer m_Buffer;
AudioFormat m_Format;
std::uint32_t m_Frequency;
};
namespace AudioLoader {
// files should be 8 or 16 bits wav
AudioData LoadAudioFile(const std::string& filePath);
}; // namespace AudioLoader
} // namespace audio
} // namespace blitz

View File

@@ -0,0 +1,59 @@
#pragma once
#include "blitz/game/Listeners.h"
#include "client/audio/AudioListener.h"
#include "client/audio/AudioSource.h"
#include "client/game/Listeners.h"
#include <map>
namespace blitz {
class Client;
namespace game {
class Player;
} // namespace game
namespace audio {
struct PlayerSound {
AudioSourcePtr m_Laser;
};
class AudioManager : public game::ClientListener, public game::GameListener {
private:
Client* m_Client;
game::Player* m_Player;
AudioListener m_Listener;
AudioSourcePtr m_MenuMusic;
AudioSourcePtr m_EndMusic;
AudioBufferPtr m_LaserSound;
std::map<game::PlayerID, PlayerSound> m_PlayerSources;
public:
AudioManager(Client* client);
~AudioManager();
virtual void OnGameJoin() override;
virtual void OnGameLeave() override;
virtual void OnGameStateUpdate(game::GameState gameState) override;
virtual void OnClientPlayerJoin() override;
virtual void OnPlayerShoot(game::PlayerID player, const Vec3f& position, float yaw, float pitch) override;
virtual void OnPlayerJoin(game::PlayerID player) override;
virtual void OnPlayerLeave(game::PlayerID player) override;
void SetGlobalVolume(float volume);
void Update();
private:
void InitSounds();
AudioSourcePtr InitSourceFromFile(const std::string& fileName);
AudioSourcePtr InitSourceFromBuffer(const AudioBufferPtr& buffer);
AudioBufferPtr InitBufferFromFile(const std::string& fileName);
};
} // namespace audio
} // namespace blitz

View File

@@ -0,0 +1,43 @@
#pragma once
#include "blitz/common/NonCopyable.h"
#include "blitz/maths/Vector.h"
#include "client/audio/AudioBuffer.h"
#include <memory>
namespace blitz {
namespace audio {
typedef std::shared_ptr<AudioBuffer> AudioBufferPtr;
class AudioSource : NonCopyable {
private:
unsigned int m_ID;
AudioBufferPtr m_Buffer;
public:
enum SourceState { ssInitial = 0, ssPlaying, ssPaused, ssStopped };
AudioSource();
~AudioSource();
void SetGain(float a_Gain);
void SetPitch(float a_Pitch);
void SetPosition(const Vec3f& a_Position);
void SetDirection(const Vec3f& a_Direction);
void SetVelocity(const Vec3f& a_Velocity);
void SetLooping(bool a_Looping);
void SetRelative(bool a_Relative);
void SetBuffer(const AudioBufferPtr& a_Buffer);
SourceState GetSourceState() const;
void Play();
void Pause();
void Stop();
};
typedef std::unique_ptr<AudioSource> AudioSourcePtr;
} // namespace audio
} // namespace blitz

View File

@@ -1,40 +1,114 @@
#pragma once
/**
* \file BlitzConfig.h
* \brief File containing the blitz::BlitzConfig class
*/
#include "blitz/game/Game.h"
#include <array>
#include <string>
namespace blitz {
/**
* \enum KeyAction
* \brief Enum containing the key actions
*/
enum KeyAction {
kaAvancer = 0,
kaReculer,
kaDroite,
kaGauche,
kaFenetreAdmin,
kaMax,
};
typedef std::array<int, kaMax> Keybinds;
/**
* \class BlitzConfig
* \brief Class used to manage the Blitz configuration
*/
class BlitzConfig {
private:
std::array<char, 256> m_Pseudo;
std::array<char, 20> m_Pseudo;
game::GameConfig m_ServerConfig;
bool m_VSync;
bool m_DisplayFps;
Keybinds m_Keybinds{};
float m_MouseSpeed;
public:
/**
* \brief Default constructor
*/
BlitzConfig();
~BlitzConfig();
std::array<char, 256>& GetPseudo() {
std::array<char, 20>& GetPseudo() {
return m_Pseudo;
}
/**
* \brief Return whether VSync is enabled
*/
bool IsVSyncEnabled() const {
return m_VSync;
}
/**
* \brief Set whether VSync is enabled
*/
void SetVSync(bool vsync) {
m_VSync = vsync;
}
/**
* \brief Return whether the FPS display is enabled
*/
bool IsFPSDisplayEnabled() const {
return m_DisplayFps;
}
/**
* \brief Set whether the FPS display is enabled
*/
void SetFPSDisplay(bool display) {
m_DisplayFps = display;
}
/**
* \brief Get the keybinds
* \return The keybinds
*/
Keybinds& GetKeys() {
return m_Keybinds;
}
/**
* \brief Get the mouse speed
* \return The mouse speed
*/
float GetMouseSpeed() const {
return m_MouseSpeed;
}
/**
* \brief Set the mouse speed
*/
void SetMouseSpeed(float MouseSpeed) {
m_MouseSpeed = MouseSpeed;
}
/**
* \brief Get the server configuration
* \return The server configuration
*/
game::GameConfig& GetServerConfig() {
return m_ServerConfig;
}
private:
void LoadConfig();
void LoadDefaultConfig();

View File

@@ -1,5 +1,12 @@
#pragma once
/**
* \file Display.h
* \brief File containing the blitz::Display class
*/
#include "client/display/InputManager.h"
#include "client/display/PlayerController.h"
#include <memory>
#include <string>
@@ -13,7 +20,10 @@ namespace gui {
class BlitzGui;
} // namespace gui
/**
* \class Display
* \brief Class used to manage the display
*/
class Display {
private:
SDL_Window* m_Window;
@@ -28,24 +38,76 @@ class Display {
bool m_FullScreen;
Client* m_Client;
input::InputManager& m_InputManager;
std::unique_ptr<gui::BlitzGui> m_BlitzGui;
input::PlayerController m_PlayerController;
public:
Display(int width, int height, const std::string& windowName, Client* client);
/**
* \brief Constructor
* \param width The width of the window
* \param height The height of the window
* \param windowName The name of the window
* \param client The client
* \param inputManager The InputManager
*/
Display(int width, int height, const std::string& windowName, Client* client, input::InputManager& inputManager);
~Display();
/**
* \brief Return whether the display has been created
*/
bool Create();
/**
* \brief Poll the events
* \note This function should be called at the beginning of the main loop
*/
void PollEvents();
/**
* \brief Update the display
* \note Swap the buffers
*/
void Update();
/**
* \brief Render the display (ImGui)
*/
void Render();
/**
* \brief Destroy the display (Not your mother's display)
*/
void Destroy();
/**
* \brief Return whether the display should be closed
*/
bool IsCloseRequested();
/**
* \brief Return widht/height ratio
*/
float GetAspectRatio();
/**
* \brief Return the window width
*/
int GetWindowWidth();
/**
* \brief Return the window height
*/
int GetWindowHeight();
/**
* \brief Return the player controller
*/
input::PlayerController& GetPlayerController() {
return m_PlayerController;
}
private:
void InitImGui();
};

View File

@@ -1,19 +1,30 @@
#pragma once
#include "blitz/misc/ObjectNotifier.h"
#include <SDL2/SDL_events.h>
#include <functional>
namespace blitz {
namespace InputManager {
namespace input {
typedef std::function<void(int)> KeyDownCallback;
typedef std::function<void(int, int)> MouseMoveCallback;
class InputListener {
public:
virtual void OnKeyDown(int imguiKey) {}
virtual void OnMouseMove(int deltaX, int deltaY) {}
};
void BindKeyDownCallback(const KeyDownCallback&);
void BindMouseMoveCallback(const MouseMoveCallback&);
void ProcessEvent(SDL_Event& event);
void GrabMouse(bool grabInput);
bool MouseGrabbed();
class InputManager : public utils::ObjectNotifier<InputListener> {
private:
bool m_MouseInputGrabbed;
} // namespace InputManager
public:
InputManager() : m_MouseInputGrabbed(false) {}
virtual ~InputManager() {}
void ProcessEvent(SDL_Event& event) const;
void GrabMouse(bool grabInput);
bool MouseGrabbed() const;
};
} // namespace input
} // namespace blitz

View File

@@ -1,7 +1,20 @@
#pragma once
/**
* \file PlayerController.h
* \brief File containing the blitz::input::PlayerController class.
*/
#include "blitz/common/Smoothing.h"
#include "blitz/misc/ObjectNotifier.h"
#include "blitz/misc/Time.h"
#include "client/display/InputManager.h"
#include "client/game/Listeners.h"
namespace blitz {
class Client;
namespace game {
class Player;
@@ -10,43 +23,46 @@ class Player;
namespace input {
class PlayerController {
/**
* \brief Class that handles player input and sends it to the client.
* \details This class is responsible for handling player input and sending it to the server.
* It also handles the player's velocity and position.
*/
class PlayerController : public utils::ObjectNotifier<game::PlayerInputListener>, game::ClientListener, InputListener {
private:
game::Player* m_Player;
game::Player* m_Player;
Client* m_Client;
input::InputManager& m_InputManager;
utils::CooldownTimer<float> m_ShootTimer{1.0f};
EMASmoother m_DxSmoother;
/// maximum x-axis velocity
float m_MaxDx;
/// current (target) x-axis velocity
float m_Dx;
EMASmoother m_DySmoother;
/// maximum (target) y-axis velocity
float m_MaxDy;
/// current (target) y-axis velocity
float m_Dy;
/// current z-axis velocity
float m_Dz;
/// maximum z-axis velocity (velocity at initial keypress)
float m_MaxDz;
/// individual gravitational force
float m_G;
// current (target) velocity
Vec3f m_Velocity;
/// maximum x-axis velocity
Vec3f m_MaxVelocity;
/// this is reset when the player touches the ground
bool m_OnGround;
public:
PlayerController();
/**
* \brief Default constructor
*/
PlayerController(Client* client, input::InputManager& inputManager);
virtual ~PlayerController();
/**
* \brief Update things like player position and velocity.
*/
void Update(float delta);
void SetAttachedPlayer(game::Player* a_Player) {
m_Player = a_Player;
}
virtual void OnGameConfigUpdate() override;
virtual void OnClientPlayerJoin() override;
virtual void OnGameLeave() override;
game::Player* GetAttachedPlayer() {
return m_Player;
}
virtual void OnMouseMove(int, int) override;
private:
void MouseMotionEvent(int, int);
void UpdateShootTimer(int bpm);
void UpdatePosition(float delta);
};

View File

@@ -1,7 +1,9 @@
#pragma once
#include "blitz/game/Game.h"
#include "blitz/game/LeaderBoard.h"
#include "blitz/protocol/PacketHandler.h"
#include <vector>
namespace blitz {
@@ -12,6 +14,7 @@ namespace client {
class ClientGame : public game::Game, public protocol::PacketHandler {
private:
Client* m_Client;
game::LeaderBoard m_LeaderBoard;
public:
ClientGame(Client* client, protocol::PacketDispatcher* dispatcher);
@@ -23,6 +26,18 @@ class ClientGame : public game::Game, public protocol::PacketHandler {
virtual void HandlePacket(const protocol::PlayerLeavePacket* packet) override;
virtual void HandlePacket(const protocol::PlayerListPacket* packet) override;
virtual void HandlePacket(const protocol::PlayerPositionAndRotationPacket* packet) override;
virtual void HandlePacket(const protocol::PlayerShootPacket* packet) override;
virtual void HandlePacket(const protocol::UpdateHealthPacket* packet) override;
virtual void HandlePacket(const protocol::PlayerStatsPacket* packet) override;
virtual void HandlePacket(const protocol::UpdateGameStatePacket* packet) override;
virtual void HandlePacket(const protocol::ServerConfigPacket* packet) override;
virtual void AddPlayer(game::PlayerID player, const std::string& name) override;
virtual void RemovePlayer(game::PlayerID player) override;
const game::LeaderBoard& GetLeaderBoard() const {
return m_LeaderBoard;
}
private:
void RegisterHandlers();

View File

@@ -0,0 +1,37 @@
#pragma once
#include "blitz/common/Defines.h"
#include "blitz/maths/Vector.h"
#include <vector>
namespace blitz {
namespace protocol {
struct ColoredPart;
typedef std::vector<ColoredPart> ColoredText;
} // namespace protocol
namespace game {
class PlayerInputListener {
public:
virtual void OnLocalPlayerJump() {}
virtual void OnLocalPlayerShoot(const Vec3f& position, float yaw, float pitch) {}
};
class ClientListener {
public:
virtual void OnTextChatReceived(const protocol::ColoredText& text) {}
virtual void OnSpectatorChange(game::PlayerID player) {}
virtual void OnPlayerShoot(PlayerID player, const Vec3f& position, float yaw, float pitch) {}
virtual void OnClientPlayerJoin() {}
virtual void OnGameConfigUpdate() {}
virtual void OnGameJoin() {}
virtual void OnGameLeave() {}
};
} // namespace game
} // namespace blitz

View File

@@ -1,6 +1,7 @@
#pragma once
#include "GuiWidget.h"
#include "client/display/InputManager.h"
namespace blitz {
@@ -13,7 +14,7 @@ class BlitzGui : public GuiWidget {
enum SubMenu { Main = 0 };
public:
BlitzGui(Client* client);
BlitzGui(Client* client, input::InputManager& inputManager);
virtual void Render() override;

View File

@@ -1,6 +1,7 @@
#pragma once
#include "GuiWidget.h"
#include "client/display/InputManager.h"
namespace blitz {
@@ -9,8 +10,11 @@ class Client;
namespace gui {
class CreateGameMenu : public GuiWidget {
private:
input::InputManager& m_InputManager;
public:
CreateGameMenu(GuiWidget* parent, Client* client) : GuiWidget(parent, client) {}
CreateGameMenu(GuiWidget* parent, Client* client, input::InputManager& inputManager);
virtual void Render() override;
};

View File

@@ -0,0 +1,19 @@
#pragma once
#include "GuiWidget.h"
namespace blitz {
namespace gui {
class CrossHair : public GuiWidget {
private:
std::uint64_t m_CrossHairTexture;
public:
CrossHair(Client* client);
virtual void Render() override;
};
} // namespace gui
} // namespace blitz

View File

@@ -2,6 +2,7 @@
#include "GuiWidget.h"
#include "client/Client.h"
#include "client/display/InputManager.h"
#include <string>
#include <vector>
@@ -9,21 +10,27 @@ namespace blitz {
namespace gui {
class GameChatGui : public GuiWidget, GuiListener {
class GameChatGui : public GuiWidget, game::ClientListener {
private:
char InputBuf[256];
std::vector<protocol::ColoredText> m_Lines;
std::vector<protocol::ColoredText> m_TempLines;
bool m_FocusRequested = false;
int HistoryPos; // -1: new line, 0..History.Size-1 browsing history.
bool ScrollToBottom = false;
bool AutoScroll = true;
float m_ChatDisplay = 0;
input::InputManager& m_InputManager;
void Draw(const char* title, bool* p_open);
void DrawMini(const char* title, bool* p_open);
public:
GameChatGui(GuiWidget* parent, Client* client);
virtual void OnTextChatReceived(const protocol::ColoredText& text);
GameChatGui(GuiWidget* parent, Client* client, input::InputManager& inputManager);
virtual ~GameChatGui();
virtual void OnTextChatReceived(const protocol::ColoredText& text) override;
virtual void Render() override;
};

33
include/client/gui/Hud.h Normal file
View File

@@ -0,0 +1,33 @@
#pragma once
#include "GuiWidget.h"
#include "client/Client.h"
namespace blitz {
class Client;
namespace game {
class Player;
} // namespace game
namespace gui {
class Hud : public GuiWidget {
private:
std::uint64_t m_GunTexture;
std::uint64_t m_JPTexture;
utils::DelayTimer<float> m_Timer{5.0f};
public:
Hud(GuiWidget* parent, Client* client);
virtual void Render() override;
private:
std::string FormatString();
void Draw(const char* title, bool* p_open);
void DrawFinishScreen(bool win);
void RenderTime(float, float);
};
} // namespace gui
} // namespace blitz

View File

@@ -1,6 +1,7 @@
#pragma once
#include "GuiWidget.h"
#include "client/display/InputManager.h"
namespace blitz {
@@ -9,8 +10,11 @@ class Client;
namespace gui {
class JoinGameMenu : public GuiWidget {
private:
input::InputManager& m_InputManager;
public:
JoinGameMenu(GuiWidget* parent, Client* client) : GuiWidget(parent, client) {}
JoinGameMenu(GuiWidget* parent, Client* client, input::InputManager& inputManager);
virtual void Render() override;
};

View File

@@ -0,0 +1,22 @@
#pragma once
#include "GuiWidget.h"
#include "client/Client.h"
namespace blitz {
namespace gui {
class LeaderBoardGui : public GuiWidget {
private:
void Draw(const char* title, bool* p_open);
utils::DelayTimer<float> m_Timer{5.0f};
public:
LeaderBoardGui(GuiWidget* parent, Client* client);
~LeaderBoardGui();
virtual void Render() override;
};
} // namespace gui
} // namespace blitz

View File

@@ -1,19 +1,29 @@
#pragma once
#include "GuiWidget.h"
#include "client/game/Listeners.h"
namespace blitz {
class Client;
namespace input {
class InputManager;
} // namespace input
namespace gui {
class MainMenu : public GuiWidget {
class MainMenu : public GuiWidget, public game::ClientListener {
private:
enum SubMenu { CREATE_MENU = 0, JOIN_MENU, OPTION_MENU };
input::InputManager& m_InputManager;
public:
MainMenu(Client* client);
MainMenu(Client* client, input::InputManager& inputManager);
virtual ~MainMenu();
virtual void OnGameLeave() override;
virtual void Render() override;
};

View File

@@ -1,6 +1,11 @@
#pragma once
#include "GuiWidget.h"
#include "blitz/misc/Time.h"
#include "client/config/BlitzConfig.h"
#include "client/display/InputManager.h"
#include <array>
#include <string>
namespace blitz {
@@ -8,17 +13,28 @@ class Client;
namespace gui {
class OptionsMenu : public GuiWidget {
class OptionsMenu : public GuiWidget, public input::InputListener {
private:
bool m_ShowFPS;
bool m_VSync;
bool m_IsKeyPopupOpen;
bool m_KeyPopupShouldClose;
utils::Timer m_Timer{100};
KeyAction m_CurrentAction;
input::InputManager& m_InputManager;
public:
OptionsMenu(GuiWidget* parent, Client* client);
OptionsMenu(GuiWidget* parent, Client* client, input::InputManager& inputManager);
virtual ~OptionsMenu();
virtual void Render() override;
void OnKeyEvent(int key);
virtual void OnKeyDown(int key) override;
private:
std::string GetKeyActionCodeName(KeyAction);
void HotkeyBindingButton();
void HotkeyBindingPopUp();
};
} // namespace gui

View File

@@ -0,0 +1,20 @@
#pragma once
#include "GuiWidget.h"
#include "client/display/InputManager.h"
namespace blitz {
namespace gui {
class ServerGui : public GuiWidget {
private:
input::InputManager& m_InputManager;
public:
ServerGui(GuiWidget* parent, Client* client, input::InputManager& inputManager);
virtual void Render() override;
};
} // namespace gui
} // namespace blitz

View File

@@ -0,0 +1,44 @@
#pragma once
#include "blitz/maths/Vector.h"
#include "client/render/loader/ModelLoader.h"
#include <memory>
#include <vector>
namespace blitz {
namespace shader {
class BulletShader;
} // namespace shader
namespace render {
class Camera;
struct Trail {
Mat4f m_Transform;
float m_Decay;
};
class BulletRenderer {
private:
std::vector<Trail> m_Trails;
ModelLoader::Model m_BulletModel;
std::unique_ptr<shader::BulletShader> m_Shader;
const Camera& m_Camera;
public:
BulletRenderer(const Camera& cam);
~BulletRenderer();
void AddBullet(const Vec3f& origin, float yaw, float pitch, bool firstPersson);
void Update(float delta);
void Render();
void Clear();
};
} // namespace render
} // namespace blitz

View File

@@ -1,6 +1,5 @@
#pragma once
#include "blitz/common/Vector.h"
#include "blitz/game/Player.h"
#include <cstdint>
@@ -19,6 +18,8 @@ class Camera {
void Update(float delta);
static float GetPlayerEyeHeight();
void SetAttachedPlayer(game::Player* a_Player) {
m_Player = a_Player;
}

View File

@@ -2,6 +2,7 @@
#include "client/Client.h"
#include "client/display/PlayerController.h"
#include "client/render/BulletRenderer.h"
#include "client/render/Camera.h"
#include "client/render/loader/GLLoader.h"
#include "client/render/loader/ModelLoader.h"
@@ -19,7 +20,7 @@ class GunShader;
namespace render {
class MainRenderer : public GuiListener {
class MainRenderer : public game::ClientListener, public game::PlayerInputListener {
private:
Client* m_Client;
ModelLoader::Model m_PlayerModel;
@@ -28,15 +29,22 @@ class MainRenderer : public GuiListener {
std::unique_ptr<shader::EntityShader> m_EntityShader;
std::unique_ptr<shader::WorldShader> m_WorldShader;
std::unique_ptr<shader::GunShader> m_GunShader;
input::PlayerController m_PlayerController;
unsigned int m_Texture;
float m_ShootTime;
Camera m_Camera;
BulletRenderer m_BulletRenderer;
input::PlayerController& m_PlayerController;
public:
MainRenderer(Client* client);
MainRenderer(Client* client, input::PlayerController& playerController);
~MainRenderer();
virtual void OnSpectatorChange(const game::PlayerID player) override;
virtual void OnSpectatorChange(game::PlayerID player) override;
virtual void OnPlayerShoot(game::PlayerID player, const Vec3f& position, float yaw, float pitch) override;
virtual void OnLocalPlayerShoot(const Vec3f& position, float yaw, float pitch) override;
virtual void OnGameConfigUpdate() override;
virtual void OnGameLeave() override;
void Update();
void Render();

View File

@@ -0,0 +1,8 @@
#pragma once
#ifdef BLITZ_GL_LOADER_GLEW
#include <GL/glew.h>
#else
#include <glbinding/gl/gl.h>
using namespace gl;
#endif

View File

@@ -1,6 +1,6 @@
#pragma once
#include "blitz/misc/ClassEntity.h"
#include "blitz/common/NonCopyable.h"
#include <vector>
@@ -13,7 +13,7 @@ struct VertexAttribPointer {
unsigned int m_Offset;
};
class ElementBuffer {
class ElementBuffer : private NonCopyable {
private:
unsigned int m_ID = 0;
std::size_t m_TriangleCount;
@@ -33,11 +33,9 @@ class ElementBuffer {
std::size_t GetTriangleCount() const {
return m_TriangleCount;
}
REMOVE_COPY(ElementBuffer);
};
class VertexBuffer {
class VertexBuffer : private NonCopyable {
private:
unsigned int m_ID = 0, m_DataStride;
std::vector<VertexAttribPointer> m_VertexAttribs;
@@ -56,11 +54,9 @@ class VertexBuffer {
void Unbind() const;
void AddVertexAttribPointer(unsigned int index, unsigned int coordinateSize, unsigned int offset);
void BindVertexAttribs() const;
REMOVE_COPY(VertexBuffer);
};
class VertexArray {
class VertexArray : private NonCopyable {
private:
unsigned int m_ID = 0;
ElementBuffer m_ElementBuffer;
@@ -74,7 +70,7 @@ class VertexArray {
VertexArray(ElementBuffer&& indicies);
~VertexArray();
unsigned int GetVertexCount() const {
std::size_t GetVertexCount() const {
return m_ElementBuffer.GetTriangleCount();
}
@@ -82,8 +78,6 @@ class VertexArray {
void Bind() const;
void Unbind() const;
REMOVE_COPY(VertexArray);
private:
void BindElementArrayBuffer();
};

View File

@@ -0,0 +1,30 @@
#pragma once
#include "ShaderProgram.h"
namespace blitz {
namespace shader {
class BulletShader : public ShaderProgram {
private:
unsigned int m_LocationProjectionMatrix = 0;
unsigned int m_LocationViewMatrix = 0;
unsigned int m_LocationAlpha = 0;
unsigned int m_LocationTransform = 0;
protected:
virtual void GetAllUniformLocation() override;
public:
BulletShader();
bool LoadShader();
void SetProjectionMatrix(const Mat4f& proj) const;
void SetViewMatrix(const Mat4f& view) const;
void SetTransform(const Mat4f& trans) const;
void SetDecay(float decay) const;
};
} // namespace shader
} // namespace blitz

View File

@@ -1,8 +1,7 @@
#pragma once
#include "blitz/common/Vector.h"
#include <glbinding/SharedBitfield.h>
#include <glbinding/gl/enum.h>
#include "blitz/maths/Vector.h"
#include "client/render/OpenGL.h"
#include <string>
namespace blitz {
@@ -37,7 +36,7 @@ class ShaderProgram {
unsigned int m_VertexShaderID;
unsigned int m_FragmentShaderID;
int LoadShader(const std::string& source, gl::GLenum type);
int LoadShader(const std::string& source, GLenum type);
};
} // namespace shader

View File

@@ -1,5 +1,10 @@
#pragma once
/**
* \file Server.h
* \brief File containing the blitz::server::Server class
*/
#include <map>
#include <thread>
@@ -8,7 +13,15 @@
#include "server/ServerConnexion.h"
#include "server/game/ServerGame.h"
/**
* \def SERVER_TPS
* \brief The server ticks per second
*/
#define SERVER_TPS 20
/**
* \def SERVER_TICK
* \brief The server tick duration
*/
#define SERVER_TICK 1000 / SERVER_TPS
namespace blitz {
@@ -16,6 +29,10 @@ namespace server {
typedef std::map<std::uint8_t, std::unique_ptr<ServerConnexion>> ConnexionMap;
/**
* \class Server
* \brief Class used to manage the server
*/
class Server {
private:
network::TCPListener m_Listener;
@@ -27,46 +44,119 @@ class Server {
std::thread m_Thread;
bool m_ServerRunning;
game::PlayerID m_FreePlayerID;
public:
/**
* \brief Constructor
*/
Server();
virtual ~Server();
/**
* \brief Start the server
* \param port The port
* \param blocking If the server is blocking
* \return If the server has started
*/
bool Start(std::uint16_t port, bool blocking);
void Stop(); // force the server to stop
/**
* \brief Force the server to stop
*/
void Stop();
/**
* \brief Restart the server
*/
void Restart();
/**
* \brief Add a bot
*/
void AddBot();
/**
* \brief Forcefully remove a player from the game
* \param player the id of the player to remove
*/
void KickPlayer(game::PlayerID player);
/**
* \brief Remove a connexion
* \param connexionID The connexion ID
*/
void RemoveConnexion(std::uint8_t connexionID);
/**
* \brief Broadcast a packet to all connexions
* \param packet The packet
*/
void BroadcastPacket(const protocol::Packet* packet);
/**
* \brief Broadcast a chat message
* \param msg The message
*/
void BroadcastChatMessage(const std::string& msg);
/**
* \brief Get the milliseconds per tick
* \return The milliseconds per tick
*/
float GetMSPT() const {
return m_TickCounter.GetMSPT();
}
/**
* \brief Get the ticks per second
* \return The ticks per second
*/
float GetTPS() const {
return m_TickCounter.GetTPS();
}
/**
* \brief Return whether the server is running
*/
bool IsRunning() {
return m_ServerRunning;
}
/**
* \brief Get the connexions (const version)
* \return The connexions
*/
const ConnexionMap& GetConnexions() const {
return m_Connections;
}
/**
* \brief Get the connexions
* \return The connexions
*/
ConnexionMap& GetConnexions() {
return m_Connections;
}
/**
* \brief Get the game
* \return The game
*/
ServerGame& GetGame() {
return m_Game;
}
/**
* \brief Get the listening port
* \return The listening port
*/
std::uint16_t GetListeningPort();
/**
* \brief Get a new player ID
* \return The new player ID
*/
game::PlayerID GetNewPlayerID();
private:
void Accept();
void UpdateSockets();

View File

@@ -1,5 +1,10 @@
#pragma once
/**
* \file ServerConnexion.h
* \brief File containing the blitz::server::ServerConnexion class
*/
#include "blitz/network/Connexion.h"
namespace blitz {
@@ -15,13 +20,23 @@ namespace server {
class Server;
/**
* \struct KeepAlive
* \brief Structure containing the keep alive informations
* \var KeepAlive::KeepAliveID The keep alive ID
* \var KeepAlive::SendTime The time when the keep alive was sent
* \var KeepAlive::RecievedResponse If the keep alive has recieved a response
*/
struct KeepAlive {
std::uint64_t keepAliveID = 0;
std::uint64_t sendTime;
bool recievedResponse = false;
std::uint64_t KeepAliveID = 0;
std::uint64_t SendTime;
bool RecievedResponse = false;
};
/**
* \class ServerConnexion
* \brief Class used to manage the server connexion
*/
class ServerConnexion : public network::Connexion {
private:
Server* m_Server;
@@ -31,25 +46,40 @@ class ServerConnexion : public network::Connexion {
std::string m_ChatColor;
public:
/**
* \brief Constructor
* \param server The server
* \param socket The socket
* \param id The ID of the connexion
*/
ServerConnexion(Server* server, network::TCPSocket& socket, std::uint8_t id);
/**
* \brief Move constructor
*/
ServerConnexion(ServerConnexion&& move);
virtual ~ServerConnexion();
void Start();
/**
* \brief Start the connexion
*/
void Init();
/**
* \brief Get the ID of the connexion
* \return The ID of the connexion
*/
std::uint8_t GetID() const {
return m_ID;
}
virtual void HandlePacket(const protocol::PlayerLoginPacket* packet) override;
virtual void HandlePacket(const protocol::KeepAlivePacket* packet) override;
virtual void HandlePacket(const protocol::DisconnectPacket* packet) override;
virtual void HandlePacket(const protocol::ChatPacket* packet) override;
virtual void HandlePacket(const protocol::PlayerPositionAndRotationPacket* packet) override;
virtual void HandlePacket(const protocol::PlayerShootPacket* packet) override;
std::uint8_t GetID() const {
return m_ID;
}
virtual bool UpdateSocket();
REMOVE_COPY(ServerConnexion);
virtual bool UpdateSocket() override;
private:
void RegisterHandlers();
@@ -58,6 +88,8 @@ class ServerConnexion : public network::Connexion {
void InitConnection();
void InitPlayerChatColor();
void SendPlayers();
void SendGameState();
void SendServerConfig();
};
} // namespace server

View File

@@ -1,26 +1,103 @@
#pragma once
/**
* \file ServerGame.h
* \brief File containing the blitz::server::ServerGame class
*/
#include "blitz/game/Game.h"
#include "blitz/misc/Time.h"
namespace blitz {
namespace server {
/**
* \struct ServerDuration
* \brief Structure containing the server game durations
* \var ServerDuration::m_GameDuration The game duration
* \var ServerDuration::m_PrepDuration The preparation duration
* \var ServerDuration::m_EndDuration The end duration
*/
struct ServerDuration {
std::uint64_t m_GameDuration = 1000 * 3 * 60;
std::uint64_t m_PrepDuration = 1000 * 10;
std::uint64_t m_EndDuration = 1000 * 30;
};
class Server;
/**
* \class ServerGame
* \brief Class used to manage the server game
*/
class ServerGame : public game::Game {
private:
Server* m_Server;
utils::Timer m_PositionTimer;
ServerDuration m_ServerDuration;
public:
/**
* \brief Constructor
* \param server The server
*/
ServerGame(Server* server);
virtual ~ServerGame();
/**
* \brief Process a player shoot
* \param player The player
* \param position The position of the player
* \param yaw The yaw
* \param pitch The pitch
*/
void ProcessShoot(game::PlayerID player, Vec3f position, float yaw, float pitch);
/**
* \brief Process a player login
* \param player The player
* \param name The name of the player
*/
void AddPlayer(game::PlayerID player, const std::string& name) override;
/**
* \brief Remove a player from the game if he disconnected
*/
void RemovePlayer(game::PlayerID player) override;
/**
* \brief Update the game
* \param delta The delta time in milliseconds
*/
void Tick(std::uint64_t delta) override;
/**
* \brief Set the game state
* \param gameState The game state
* \param duration The duration in milliseconds
*/
virtual void UpdateGameState(game::GameState gameState, std::uint64_t duration) override;
/**
* \brief Get the server duration
* \return The server duration in milliseconds
*/
ServerDuration& GetServerDuration() {
return m_ServerDuration;
}
/**
* \brief Send the player positions
*/
void SendServerConfig();
private:
void SendPlayerPositions();
void DamagePlayer(game::Player& player, game::Player& shooter);
void UpdateHP(game::Player& player, float newHP);
void UpdatePlayerStats();
void StartGame(); // when at least 2 players joined
void CancelGame(); // when not enough players are left
void ResetPlayerStats();
void InitGameConfig();
};
} // namespace server

Some files were not shown because too many files have changed in this diff Show More