29 Commits

Author SHA1 Message Date
5840ae1922 add BaseClient class
All checks were successful
Linux arm64 / Build (push) Successful in 5m8s
2024-06-03 16:03:05 +02:00
21b5a473d5 add PacketDerived static check
All checks were successful
Linux arm64 / Build (push) Successful in 4m42s
2024-06-01 19:21:11 +02:00
29a66ca7d1 use of more reference
All checks were successful
Linux arm64 / Build (push) Successful in 42m42s
2024-06-01 15:59:48 +02:00
814c944b16 use of std remove 2024-06-01 15:54:01 +02:00
5efbb7c15b move AudioBufferPtr declaration 2024-06-01 15:05:03 +02:00
3af3a4d221 remove \ 2024-06-01 14:54:35 +02:00
ca073d1062 const array 2024-06-01 14:54:25 +02:00
c2e0845999 pass packet and handler by reference 2024-06-01 14:20:26 +02:00
8b346754f1 use of template for packets 2024-06-01 12:34:42 +02:00
e2f1850987 move VarInt.cpp
All checks were successful
Linux arm64 / Build (push) Successful in 4m47s
2024-04-15 17:02:47 +02:00
95e6967d0d fart sound on death
All checks were successful
Linux arm64 / Build (push) Successful in 4m29s
2024-04-15 16:53:44 +02:00
b2323d2761 Update MainRenderer.cpp to load GLB model for the world with better map
All checks were successful
Linux arm64 / Build (push) Successful in 4m36s
2024-04-15 16:40:58 +02:00
84ae607cd1 footsteps velocity
All checks were successful
Linux arm64 / Build (push) Successful in 4m27s
2024-04-15 16:05:28 +02:00
e254d677d0 add foosteps
All checks were successful
Linux arm64 / Build (push) Successful in 4m32s
2024-04-15 15:58:45 +02:00
f0023c1b22 Update display name in ClientMain.cpp to Blitz
All checks were successful
Linux arm64 / Build (push) Successful in 4m20s
2024-04-14 22:14:06 +02:00
71600e7a8b Map with thick walls for collisions and update MainRenderer.cpp 2024-04-14 22:13:39 +02:00
b917a8d1fa fix endgame gui timers
All checks were successful
Linux arm64 / Build (push) Successful in 4m42s
2024-04-14 19:55:51 +02:00
8880056b1c move Client to client namespace
All checks were successful
Linux arm64 / Build (push) Successful in 5m17s
2024-04-14 19:27:42 +02:00
9bb5c85f41 refactor ColoredPart 2024-04-14 19:15:28 +02:00
c6c811ca17 refactor PlayerInfo 2024-04-14 19:11:08 +02:00
40c551a4dc move KeyAction to input 2024-04-14 19:06:29 +02:00
a5bb2f74dd move VarInt to protocol 2024-04-14 19:01:59 +02:00
d9cc43a7a1 rename display to input 2024-04-14 18:58:12 +02:00
9a297026cd move EMASmoother to maths 2024-04-14 18:53:22 +02:00
2f141698ad better ObjectNotifier doc 2024-04-14 18:41:56 +02:00
af5f084234 moved client listeners 2024-04-14 18:40:45 +02:00
fd61870ebe include wiki in readme
All checks were successful
Linux arm64 / Build (push) Successful in 4m28s
2024-04-14 18:13:31 +02:00
5595213f3d Add valgrind testing to readme
All checks were successful
Linux arm64 / Build (push) Successful in 4m21s
2024-04-14 13:09:59 +02:00
8158dda315 fix mainmenu client when server crashes
All checks were successful
Linux arm64 / Build (push) Successful in 4m17s
2024-04-13 19:12:34 +02:00
95 changed files with 1612 additions and 490 deletions

View File

@@ -86,3 +86,25 @@ xmake project -k compile_commands
```
Alternatively, you can install the [XMake extension](https://marketplace.visualstudio.com/items?itemName=tboox.xmake-vscode) for VsCode.
# Valgrind 🔍
We can inspect the client binary to look for memory leak.
First, switch compilation mode to valgrind :
```
xmake f -m valgrind
```
Then build and run :
```
xmake
xmake run
```
# Wiki 📚
Available [here](https://git.ale-pri.com/Blitz/Blitz/wiki)

Binary file not shown.

View File

@@ -0,0 +1,797 @@
# Blender 4.0.2
# www.blender.org
mtllib base_deambu.mtl
o sol
v -50.000000 0.150000 18.150000
v 50.000000 0.150000 18.150000
v -50.000000 0.150000 -18.150000
v 50.000000 0.150000 -18.150000
v -50.000000 0.000000 18.150000
v 50.000000 0.000000 18.150000
v -50.000000 0.000000 -18.150000
v 50.000000 0.000000 -18.150000
vn -0.0000 1.0000 -0.0000
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 5/1/2 7/4/2 8/3/2 6/2/2
f 1/1/3 3/4/3 7/4/3 5/1/3
f 2/2/4 1/1/4 5/1/4 6/2/4
f 4/3/5 2/2/5 6/2/5 8/3/5
f 3/4/6 4/3/6 8/3/6 7/4/6
o mur_dc_partie_basse
v 40.400005 0.000003 -9.649998
v -32.133335 -0.000002 -9.650001
v 40.400005 2.500000 -9.649998
v -32.133335 2.500000 -9.650001
v 40.400005 2.500000 -9.079998
v -32.133335 2.500000 -9.080001
v 40.400005 2.650000 -9.079998
v -32.133335 2.650000 -9.080001
v 40.400005 2.650000 -7.729998
v -32.133335 2.650000 -7.730001
v 40.400005 2.750000 -7.729998
v -32.133335 2.750000 -7.730001
v 40.400005 2.750000 -7.669998
v -32.133335 2.750000 -7.670001
v 40.400005 4.250000 -7.669998
v -32.133335 4.250000 -7.670001
v 40.400005 4.250000 -7.669998
v -32.133335 4.250000 -7.670001
v 40.400005 4.250000 -7.969998
v -32.133335 4.250000 -7.970001
v 40.400005 6.000000 -7.969998
v -32.133335 6.000000 -7.970001
v 40.400005 2.500000 -9.649998
v -32.133335 2.500000 -9.650001
v 40.400005 6.000000 -9.649998
v 40.400005 6.000000 -9.079998
v 40.400005 4.250000 -9.079998
v 40.400005 4.250000 -7.729998
v 40.400005 4.250000 -7.729998
v 40.400005 4.250000 -7.669998
v 40.400005 4.250000 -9.085698
v 40.400005 6.000000 -9.085698
v -32.133335 6.000000 -9.650001
v -32.133335 6.000000 -9.080001
v -32.133335 4.250000 -9.080001
v -32.133335 4.250000 -7.730001
v -32.133335 4.250000 -7.730001
v -32.133335 4.250000 -7.670001
v -32.133335 4.250000 -9.085701
v -32.133335 6.000000 -9.085701
v -50.000000 5.999996 -9.650001
v -50.000000 -0.000004 -9.650001
v 40.400005 6.000003 -9.649997
v -40.666664 5.999997 -9.650001
v -40.666668 -0.000003 -9.650001
v -32.133335 -0.000002 -9.650000
v -32.133339 5.999998 -9.650000
v -40.666664 11.999997 -9.650001
v -40.666668 -0.000003 -9.650001
v -32.133335 -0.000002 -9.650000
v -32.133339 11.999998 -9.650000
v -40.666664 5.999997 -18.150002
v -40.666668 -0.000003 -18.150002
v -32.133335 -0.000002 -18.150000
v -32.133339 5.999998 -18.150000
v 40.400005 2.500000 -9.649997
v -32.133335 2.500000 -9.650000
v -50.000000 5.999996 -18.150002
v -50.000000 -0.000004 -18.150002
v 50.000000 6.000004 -18.149998
v 50.000000 0.000004 -18.149998
v 50.000000 5.761985 18.149998
v 50.000000 0.000004 18.149998
v -50.000000 5.761978 18.150002
v -50.000000 -0.000004 18.150002
v -50.000000 6.000000 18.150002
v -50.000000 0.000000 18.150002
v -50.000000 6.000000 -18.149998
v -50.000000 0.000000 -18.149998
v 50.000000 0.000000 18.150002
v 50.000000 6.000000 18.150002
v 50.000000 0.000000 -18.149998
v 50.000000 6.000000 -18.149998
v 47.300003 6.000003 1.649999
v 47.299999 0.000003 1.649999
v 32.900002 0.000002 1.650000
v 32.900005 6.000002 1.650000
v 29.699999 0.000002 1.649999
v 29.699999 6.000002 1.649999
v 32.900002 0.000002 1.650000
v 32.900005 12.000002 1.650000
v 29.699999 0.000002 1.649999
v 29.699999 12.000002 1.649999
v 15.300000 0.000001 1.650001
v 15.299998 6.000001 1.650001
v 12.099999 0.000001 1.650001
v 12.100004 6.000001 1.650001
v 15.300000 0.000001 1.650001
v 15.299998 12.000001 1.650001
v 12.099999 0.000001 1.650001
v 12.100005 12.000001 1.650001
v -2.300000 0.000000 1.650001
v -2.300000 6.000000 1.650001
v -5.500000 -0.000000 1.650002
v -5.500001 6.000000 1.650002
v -2.300000 0.000000 1.650001
v -2.300001 12.000000 1.650001
v -5.500000 -0.000000 1.650002
v -5.500001 12.000000 1.650002
v -19.899998 -0.000001 1.650002
v -19.900000 5.999999 1.650002
v -19.899998 -0.000001 1.650002
v -19.900000 11.999998 1.650002
v -22.600000 -0.000002 1.650002
v -22.600000 11.999998 1.650002
v 32.900002 0.000002 12.316666
v 32.900005 6.000002 12.316666
v 29.699997 0.000002 12.316666
v 29.699997 6.000002 12.316666
v 15.300002 0.000001 12.316668
v 15.300000 6.000001 12.316668
v 12.099999 0.000001 12.316668
v 12.100004 6.000001 12.316668
v -2.300000 0.000000 12.316668
v -2.300001 6.000000 12.316668
v -5.500000 -0.000000 12.316668
v -5.500001 6.000000 12.316668
v 15.300000 0.000002 12.316666
v 15.300000 6.000002 12.316666
v -2.300000 0.000001 12.316668
v -2.299995 6.000001 12.316668
v -19.900000 -0.000000 12.316668
v -19.900000 6.000000 12.316668
v 45.200001 6.000003 -9.649997
v 45.199997 0.000003 -9.649997
v 45.200001 6.000003 -18.183331
v 45.199997 0.000003 -18.183331
v 45.200001 6.000003 -8.633330
v 45.199997 0.000003 -8.633330
v 40.400002 6.000003 -9.649997
v 40.399994 0.000003 -9.649997
v 40.400002 6.000003 -18.183331
v 40.399994 0.000003 -18.183331
v 47.300003 6.000003 1.649999
v 47.299999 0.000003 1.649999
v 47.300003 6.000003 12.316666
v 47.299999 0.000003 12.316666
v 32.900005 6.000004 12.316666
v 32.900002 0.000003 12.316666
v -19.899998 -0.000001 1.650002
v -19.900000 5.999999 1.650002
v -19.900000 -0.000001 12.316669
v -19.900000 5.999999 12.316669
v -23.099998 -0.000001 1.650002
v -23.100000 5.999998 1.650002
v -23.100000 -0.000001 12.316668
v -23.100000 5.999998 12.316668
v -37.500000 -0.000001 12.316668
v -37.500000 5.999999 12.316668
v -37.500000 -0.000001 1.650001
v -37.500000 5.999999 1.650001
v -23.100000 -0.000001 1.650002
v -23.100000 5.999998 1.650002
v -19.899998 -0.000001 1.650002
v -19.900000 11.999998 1.650002
v -23.099998 -0.000001 1.650002
v -23.100000 11.999998 1.650002
v -37.500000 -0.000001 1.650001
v -37.500000 11.999998 1.650001
v -40.700001 -0.000001 1.650002
v -40.700001 11.999998 1.650002
v -40.700001 -0.000001 1.650002
v -40.700001 5.999999 1.650002
v -40.700001 -0.000001 18.150002
v -40.700001 5.999999 18.150002
v -40.700001 -0.000001 1.650002
v -40.700001 5.999999 1.650002
v -40.700001 -0.000001 0.050001
v -40.700001 5.999999 0.050001
v -40.700001 -0.000001 0.050001
v -40.700001 11.999998 0.050001
v -48.166668 -0.000001 0.050001
v -48.166668 11.999998 0.050001
v -48.166668 -0.000001 6.450001
v -48.166668 11.999998 6.450001
v -40.699997 -0.000001 6.450001
v -40.699997 11.999998 6.450001
v -40.700001 -0.000001 -6.349998
v -40.700001 5.999999 -6.349998
v -48.166668 -0.000001 -6.349998
v -48.166668 5.999999 -6.349998
v -48.166668 -0.000001 0.050002
v -48.166668 5.999999 0.050002
v -40.700001 -0.000001 0.050002
v -40.700001 5.999999 0.050002
v 50.000000 5.761985 18.149998
v -50.000000 5.761978 18.150002
v 50.000000 5.761985 18.149998
v -50.000000 5.761978 18.150002
v 50.000000 5.761985 18.149998
v -50.000000 5.761978 18.150002
v 50.000000 5.761985 18.149998
v -50.000000 5.761978 18.150002
v 49.999996 5.761985 -18.157017
v -50.000000 5.761978 -18.157013
v 40.400005 0.000003 -9.659998
v -32.133335 -0.000002 -9.660001
v 40.195881 2.524495 -9.658163
v -31.929211 2.524495 -9.658166
v 40.111332 2.534641 -9.085772
v -31.844660 2.534641 -9.085774
v 40.111332 2.684641 -9.085772
v -31.844660 2.684641 -9.085774
v 40.111332 2.684641 -7.735771
v -31.844660 2.684641 -7.735775
v 40.111332 2.784641 -7.735771
v -31.844660 2.784641 -7.735775
v 40.111332 2.784641 -7.675771
v -31.844660 2.784641 -7.675775
v 40.400005 4.250000 -7.679998
v -32.133335 4.250000 -7.680001
v 40.400005 4.207573 -7.677069
v -32.133335 4.207573 -7.677072
v 40.111332 4.215359 -7.975771
v -31.844660 4.215359 -7.975775
v 40.046452 6.000000 -7.977069
v -31.779781 6.000000 -7.977072
v 40.400005 2.500000 -9.659998
v -32.133335 2.500000 -9.660001
v 39.900005 6.000000 -9.649998
v 39.900005 6.000000 -9.079998
v 39.900005 4.250000 -9.079998
v 39.900005 4.250000 -7.729998
v 39.900005 4.250000 -7.729998
v 39.900005 4.250000 -7.669998
v 39.900005 4.250000 -9.085698
v 39.900005 6.000000 -9.085698
v -31.633335 6.000000 -9.650001
v -31.633335 6.000000 -9.080001
v -31.633335 4.250000 -9.080001
v -31.633335 4.250000 -7.730001
v -31.633335 4.250000 -7.730001
v -31.633335 4.250000 -7.670001
v -31.633335 4.250000 -9.085701
v -31.633335 6.000000 -9.085701
v -50.000000 5.999996 -9.660001
v -50.000000 -0.000004 -9.660001
v 40.400005 6.000003 -9.659997
v -41.020218 5.999997 -9.657071
v -41.020222 -0.000003 -9.657071
v -31.633335 -0.000002 -9.650000
v -31.779787 5.999998 -9.657071
v -40.351173 11.953449 -9.650001
v -40.351181 0.046545 -9.650001
v -31.863012 0.050473 -9.650000
v -31.863018 11.949522 -9.650000
v -41.166664 5.999997 -18.150002
v -41.166668 -0.000003 -18.150002
v -31.633335 -0.000002 -18.150000
v -31.633341 5.999998 -18.150000
v 40.400005 2.500000 -9.659997
v -31.686121 2.500000 -9.654472
v -50.000000 5.999996 -18.160000
v -50.000000 -0.000004 -18.160000
v 50.000000 6.000004 -18.159996
v 50.000000 0.000004 -18.159996
v 50.499897 5.761985 18.149799
v 50.000000 0.000004 18.159998
v -49.500099 5.761978 18.149803
v -49.999996 -0.000004 18.160002
v -50.500000 6.000000 18.150002
v -50.500000 0.000000 18.150002
v -50.500000 6.000000 -18.149998
v -50.500000 0.000000 -18.149998
v 50.500000 0.000000 18.150002
v 50.500000 6.000000 18.150002
v 50.500000 0.000000 -18.149998
v 50.500000 6.000000 -18.149998
v 47.300007 6.000004 1.659999
v 47.300003 0.000003 1.659999
v 33.253555 0.000002 1.657071
v 33.253559 6.000002 1.657071
v 29.346449 0.000002 1.657070
v 29.346449 6.000002 1.657070
v 32.871048 0.005282 1.640056
v 32.871052 11.994722 1.640056
v 29.673853 0.005284 1.640051
v 29.673853 11.994720 1.640051
v 15.653554 0.000001 1.657072
v 15.653553 6.000001 1.657072
v 11.746446 0.000001 1.657072
v 11.746451 6.000001 1.657072
v 15.286518 0.005288 1.640043
v 15.286516 11.994714 1.640043
v 12.089335 0.005289 1.640041
v 12.089341 11.994713 1.640041
v -1.946446 0.000000 1.657072
v -1.946447 6.000000 1.657072
v -5.853553 -0.000000 1.657073
v -5.853554 6.000000 1.657073
v -2.297972 0.005289 1.640039
v -2.297973 11.994711 1.640039
v -5.495152 0.005289 1.640041
v -5.495153 11.994711 1.640041
v -19.899998 -0.000001 1.660002
v -19.899998 5.999999 1.660002
v -19.882467 0.005284 1.640046
v -19.882469 11.994713 1.640046
v -22.580095 0.005283 1.640048
v -22.580095 11.994713 1.640048
v 33.400002 0.000002 12.316666
v 33.400005 6.000002 12.316666
v 29.346443 0.000002 12.309595
v 29.346443 6.000002 12.309595
v 15.800001 0.000001 12.316668
v 15.800000 6.000001 12.316668
v 11.746446 0.000001 12.309597
v 11.746451 6.000001 12.309597
v -1.800000 0.000000 12.316668
v -1.800001 6.000000 12.316668
v -5.853553 -0.000000 12.309597
v -5.853554 6.000000 12.309597
v 15.299997 0.000002 12.306665
v 15.299997 6.000002 12.306665
v -2.300000 0.000001 12.306667
v -2.299995 6.000001 12.306667
v -19.900000 -0.000000 12.306667
v -19.900000 6.000000 12.306667
v 44.700005 6.000003 -9.649997
v 44.699997 0.000003 -9.649997
v 44.700005 6.000003 -18.183331
v 44.699997 0.000003 -18.183331
v 44.700005 6.000003 -8.633330
v 44.699997 0.000003 -8.633330
v 39.900002 6.000003 -9.649997
v 39.899998 0.000003 -9.649997
v 39.900002 6.000003 -18.183331
v 39.899998 0.000003 -18.183331
v 46.800007 6.000003 1.649999
v 46.799999 0.000003 1.649999
v 46.946449 6.000004 12.309595
v 46.946445 0.000003 12.309595
v 32.900005 6.000004 12.306665
v 32.900002 0.000003 12.306665
v -19.400000 -0.000001 1.650002
v -19.400002 5.999999 1.650002
v -19.400000 -0.000001 12.316669
v -19.400002 5.999999 12.316669
v -23.599998 -0.000001 1.650002
v -23.600000 5.999998 1.650002
v -23.453554 -0.000001 12.309597
v -23.453554 5.999998 12.309597
v -37.146446 -0.000001 12.309597
v -37.146446 5.999999 12.309597
v -37.146446 -0.000001 1.657072
v -37.146446 5.999999 1.657072
v -23.100000 -0.000001 1.660002
v -23.100000 5.999998 1.660002
v -19.882467 0.005284 1.640046
v -19.882469 11.994713 1.640046
v -23.079653 0.005283 1.640049
v -23.079655 11.994713 1.640049
v -37.467014 0.005276 1.640061
v -37.467014 11.994720 1.640061
v -40.664215 0.005274 1.640066
v -40.664215 11.994723 1.640066
v -41.200001 -0.000001 1.650002
v -41.200001 5.999998 1.650002
v -41.200001 -0.000001 18.150002
v -41.200001 5.999998 18.150002
v -41.200001 -0.000001 1.650002
v -41.200001 5.999998 1.650002
v -41.200001 -0.000001 0.050001
v -41.200001 5.999998 0.050001
v -40.658409 0.006130 0.040089
v -40.658409 11.993867 0.040089
v -48.117512 0.006122 0.040102
v -48.117512 11.993876 0.040102
v -48.136864 0.003712 6.440039
v -48.136864 11.996285 6.440039
v -40.674801 0.003714 6.440033
v -40.674801 11.996284 6.440033
v -41.053551 -0.000001 -6.342928
v -41.053551 5.999998 -6.342928
v -47.813114 -0.000001 -6.342927
v -47.813114 5.999999 -6.342927
v -47.813114 -0.000001 0.042931
v -47.813114 5.999999 0.042931
v -40.700001 -0.000001 0.040002
v -40.700001 5.999999 0.040002
v 50.000000 5.761985 18.139997
v -50.000000 5.761978 18.140001
v 50.000000 5.761985 18.139997
v -50.000000 5.761978 18.140001
v 50.000000 5.761985 18.139997
v -50.000000 5.761978 18.140001
v 50.000000 5.804412 18.142927
v -50.000000 5.804404 18.142931
v 49.999996 5.821985 -18.157017
v -50.000000 5.821978 -18.157013
vn -0.0000 -0.0000 1.0000
vn -0.0000 -1.0000 -0.0000
vn -0.0000 1.0000 -0.0000
vn 1.0000 -0.0000 -0.0000
vn -1.0000 -0.0000 -0.0000
vn -0.0000 -0.0000 -1.0000
vn -0.0000 0.0007 -1.0000
vn -0.0000 0.9998 -0.0177
vn -0.0000 -0.0029 -1.0000
vn -0.0000 0.0689 0.9976
vn -0.0000 -0.9997 -0.0261
vn -0.0000 -0.0007 -1.0000
vn -0.0000 0.0747 -0.9972
vn -0.9947 -0.0725 -0.0730
vn -0.9910 -0.1338 -0.0000
vn -0.9898 -0.1427 -0.0000
vn -0.9871 -0.0181 0.1589
vn 0.9947 -0.0725 -0.0730
vn 0.9910 -0.1338 -0.0000
vn 0.9898 -0.1427 -0.0000
vn 0.9871 -0.0181 0.1589
vn 0.0003 -0.0000 -1.0000
vn 0.9999 0.0122 0.0081
vn -0.9999 -0.0000 0.0172
vn -0.0001 -0.0004 -1.0000
vn -0.0000 0.0018 1.0000
vn -0.0002 -0.0000 1.0000
vn 0.0002 -0.0000 1.0000
vn 0.9999 -0.0000 -0.0137
vn 0.0002 -0.0000 -1.0000
vn -0.9999 -0.0000 0.0137
vn -0.9997 -0.0000 -0.0229
vn -0.0004 -0.0000 -1.0000
vn -0.0000 -0.0689 0.9976
vn -0.0000 1.0000 0.0005
vn 0.0891 0.0040 -0.9960
vn -0.0891 0.0040 -0.9960
vn -0.0200 -0.0000 -0.9998
vn 0.0200 -0.0000 -0.9998
vn -0.0538 -0.0067 -0.9985
vn 0.0538 -0.0067 -0.9985
vn -0.2612 -0.9553 -0.1384
vn 0.2612 -0.9553 -0.1384
vn 0.1191 0.9929 -0.0000
vn -0.1191 0.9929 -0.0000
vn -0.0074 -0.0011 1.0000
vn 0.0117 0.0017 -0.9999
vn -0.0074 -0.0023 1.0000
vn 0.0074 0.0023 -1.0000
vn -0.0074 -0.0025 1.0000
vn 0.0074 0.0025 -1.0000
vn 0.0440 -0.9988 -0.0197
vn -0.0117 0.0017 -0.9999
vn 0.0074 -0.0011 1.0000
vn -0.0074 0.0023 -1.0000
vn 0.0074 -0.0023 1.0000
vn -0.0074 0.0025 -1.0000
vn 0.0074 -0.0025 1.0000
vn -0.0440 -0.9988 -0.0197
vn 0.0047 0.0009 1.0000
vn 0.0196 -0.0017 -0.9998
vn -0.0196 0.0017 0.9998
vn 1.0000 -0.0000 -0.0003
vn -1.0000 -0.0000 0.0003
vt 0.791666 0.178667
vt 1.000000 0.178667
vt 1.000000 0.904000
vt 0.791667 0.904000
vt 0.000000 0.000000
vt 1.000000 0.000000
vt 1.000000 0.093333
vt 0.000000 0.093333
vt 0.000000 0.178667
vt 0.000000 0.904000
vt 1.000000 1.000000
vt 0.000000 1.000000
vt 0.000000 0.027000
vt 1.000000 0.027000
vt 1.000000 0.171000
vt 0.000000 0.171000
vt 0.000000 0.203000
vt 1.000000 0.203000
vt 1.000000 0.347000
vt 0.000000 0.347000
vt 0.000000 0.379000
vt 1.000000 0.379000
vt 1.000000 0.523000
vt 0.000000 0.523000
vt 0.000000 0.555000
vt 1.000000 0.555000
vt 1.000000 0.699000
vt 0.000000 0.699000
vt 0.000000 0.952000
vt 1.000000 0.952000
s 0
f 12/5/7 10/6/7 9/7/7 11/8/7
f 12/5/8 11/8/8 13/8/8 14/5/8
f 14/5/7 13/8/7 15/8/7 16/5/7
f 16/5/8 15/8/8 17/8/8 18/5/8
f 18/5/7 17/8/7 19/8/7 20/5/7
f 20/5/8 19/8/8 21/8/8 22/5/8
f 22/5/7 21/8/7 23/8/7 24/5/7
f 24/5/7 23/8/7 25/8/7 26/5/7
f 26/5/9 25/8/9 27/8/9 28/5/9
f 28/5/7 27/8/7 29/8/7 30/5/7
f 11/8/7 12/5/7 32/5/7 31/8/7
f 13/8/10 11/8/10 33/8/10 34/8/10
f 17/8/10 15/8/10 35/8/10 36/8/10
f 21/8/10 19/8/10 37/8/10 38/8/10
f 29/8/10 27/8/10 39/8/10 40/8/10
f 12/5/11 14/5/11 42/5/11 41/5/11
f 16/5/11 18/5/11 44/5/11 43/5/11
f 20/5/11 22/5/11 46/5/11 45/5/11
f 28/5/11 30/5/11 48/5/11 47/5/11
f 49/9/7 50/10/7 53/11/7 52/12/7
f 54/6/11 65/5/11 55/13/11 63/13/11 62/6/11
f 52/12/10 53/11/10 61/11/10 60/12/10
f 55/13/7 65/5/7 64/8/7 51/14/7
f 66/9/7 67/10/7 69/15/7 68/16/7
f 70/9/12 71/10/12 73/15/12 72/16/12
f 74/9/10 75/10/10 77/15/10 76/16/10
f 78/9/11 79/10/11 81/15/11 80/16/11
f 82/17/12 83/18/12 84/19/12 85/20/12
f 87/21/12 86/22/12 92/23/12 93/24/12
f 95/25/12 94/26/12 100/27/12 101/28/12
f 103/29/12 102/30/12 108/31/12 109/32/12
f 102/30/10 103/29/10 125/29/10 124/30/10
f 101/28/11 100/27/11 122/27/11 123/28/11
f 94/26/10 95/25/10 121/25/10 120/26/10
f 93/24/11 92/23/11 118/23/11 119/24/11
f 86/22/10 87/21/10 117/21/10 116/22/10
f 85/20/11 84/19/11 114/19/11 115/20/11
f 124/30/7 125/29/7 131/29/7 130/30/7
f 120/26/7 121/25/7 129/25/7 128/26/7
f 116/22/7 117/21/7 127/21/7 126/22/7
f 132/33/10 133/34/10 135/34/10 134/33/10
f 133/34/10 132/33/10 136/33/10 137/34/10
f 138/33/10 139/34/10 141/34/10 140/33/10
f 143/18/10 142/17/10 144/17/10 145/18/10
f 145/18/7 144/17/7 146/17/7 147/18/7
f 149/32/11 148/31/11 150/31/11 151/32/11
f 152/31/10 153/32/10 155/32/10 154/31/10
f 154/31/7 155/32/7 157/32/7 156/31/7
f 156/31/11 157/32/11 159/32/11 158/31/11
f 158/31/12 159/32/12 161/32/12 160/31/12
f 171/32/10 173/32/10 172/31/10 170/31/10
f 174/31/10 176/31/10 177/32/10 175/32/10
f 177/32/10 176/31/10 186/31/10 187/32/10
f 187/32/12 186/31/12 188/31/12 189/32/12
f 189/32/11 188/31/11 190/31/11 191/32/11
f 191/32/7 190/31/7 192/31/7 193/32/7
f 70/9/7 72/16/7 195/16/7 194/9/7
f 194/9/7 195/16/7 197/16/7 196/9/7
f 196/9/7 197/16/7 199/16/7 198/9/7
f 198/9/7 199/16/7 201/16/7 200/9/7
f 200/9/8 201/16/8 203/16/8 202/9/8
f 207/5/13 206/8/13 204/7/13 205/6/13
f 207/5/14 209/5/14 208/8/14 206/8/14
f 209/5/12 211/5/12 210/8/12 208/8/12
f 211/5/9 213/5/9 212/8/9 210/8/9
f 213/5/12 215/5/12 214/8/12 212/8/12
f 215/5/9 217/5/9 216/8/9 214/8/9
f 217/5/15 219/5/15 218/8/15 216/8/15
f 219/5/16 221/5/16 220/8/16 218/8/16
f 221/5/17 223/5/17 222/8/17 220/8/17
f 223/5/18 225/5/18 224/8/18 222/8/18
f 206/8/19 226/8/19 227/5/19 207/5/19
f 208/8/20 229/8/20 228/8/20 206/8/20
f 212/8/21 231/8/21 230/8/21 210/8/21
f 216/8/22 233/8/22 232/8/22 214/8/22
f 224/8/23 235/8/23 234/8/23 222/8/23
f 207/5/24 236/5/24 237/5/24 209/5/24
f 211/5/25 238/5/25 239/5/25 213/5/25
f 215/5/26 240/5/26 241/5/26 217/5/26
f 223/5/27 242/5/27 243/5/27 225/5/27
f 244/9/28 247/12/28 248/11/28 245/10/28
f 249/6/29 257/6/29 258/13/29 250/13/29 260/5/29
f 247/12/30 255/12/30 256/11/30 248/11/30
f 250/13/31 246/14/31 259/8/31 260/5/31
f 261/9/12 263/16/12 264/15/12 262/10/12
f 265/9/32 267/16/32 268/15/32 266/10/32
f 269/9/11 271/16/11 272/15/11 270/10/11
f 273/9/10 275/16/10 276/15/10 274/10/10
f 277/17/33 280/20/33 279/19/33 278/18/33
f 282/21/7 288/24/7 287/23/7 281/22/7
f 290/25/7 296/28/7 295/27/7 289/26/7
f 298/29/34 304/32/34 303/31/34 297/30/34
f 297/30/11 319/30/11 320/29/11 298/29/11
f 296/28/35 318/28/35 317/27/35 295/27/35
f 289/26/11 315/26/11 316/25/11 290/25/11
f 288/24/35 314/24/35 313/23/35 287/23/35
f 281/22/11 311/22/11 312/21/11 282/21/11
f 280/20/35 310/20/35 309/19/35 279/19/35
f 319/30/36 325/30/36 326/29/36 320/29/36
f 315/26/36 323/26/36 324/25/36 316/25/36
f 311/22/36 321/22/36 322/21/36 312/21/36
f 327/33/11 329/33/11 330/34/11 328/34/11
f 328/34/11 332/34/11 331/33/11 327/33/11
f 333/33/11 335/33/11 336/34/11 334/34/11
f 338/18/37 340/18/37 339/17/37 337/17/37
f 340/18/36 342/18/36 341/17/36 339/17/36
f 344/32/10 346/32/10 345/31/10 343/31/10
f 347/31/37 349/31/37 350/32/37 348/32/37
f 349/31/12 351/31/12 352/32/12 350/32/12
f 351/31/10 353/31/10 354/32/10 352/32/10
f 353/31/33 355/31/33 356/32/33 354/32/33
f 366/32/11 365/31/11 367/31/11 368/32/11
f 369/31/11 370/32/11 372/32/11 371/31/11
f 372/32/38 382/32/38 381/31/38 371/31/38
f 382/32/7 384/32/7 383/31/7 381/31/7
f 384/32/10 386/32/10 385/31/10 383/31/10
f 386/32/39 388/32/39 387/31/39 385/31/39
f 265/9/9 389/9/9 390/16/9 267/16/9
f 389/9/7 391/9/7 392/16/7 390/16/7
f 391/9/7 393/9/7 394/16/7 392/16/7
f 393/9/40 395/9/40 396/16/40 394/16/40
f 395/9/41 397/9/41 398/16/41 396/16/41
f 9/7/8 10/6/8 205/6/8 204/7/8
f 11/8/42 9/7/42 204/7/42 206/8/42
f 10/6/43 12/5/43 207/5/43 205/6/43
f 14/5/44 16/5/44 211/5/44 209/5/44
f 15/8/45 13/8/45 208/8/45 210/8/45
f 18/5/44 20/5/44 215/5/44 213/5/44
f 19/8/45 17/8/45 212/8/45 214/8/45
f 22/5/46 24/5/46 219/5/46 217/5/46
f 23/8/47 21/8/47 216/8/47 218/8/47
f 24/5/10 26/5/10 221/5/10 219/5/10
f 25/8/11 23/8/11 218/8/11 220/8/11
f 26/5/48 28/5/48 223/5/48 221/5/48
f 27/8/49 25/8/49 220/8/49 222/8/49
f 30/5/9 29/8/9 224/8/9 225/5/9
f 31/8/8 32/5/8 227/5/8 226/8/8
f 11/8/50 31/8/50 226/8/50 206/8/50
f 32/5/51 12/5/51 207/5/51 227/5/51
f 34/8/9 33/8/9 228/8/9 229/8/9
f 13/8/52 34/8/52 229/8/52 208/8/52
f 33/8/53 11/8/53 206/8/53 228/8/53
f 36/8/9 35/8/9 230/8/9 231/8/9
f 17/8/54 36/8/54 231/8/54 212/8/54
f 35/8/55 15/8/55 210/8/55 230/8/55
f 38/8/9 37/8/9 232/8/9 233/8/9
f 21/8/56 38/8/56 233/8/56 216/8/56
f 37/8/57 19/8/57 214/8/57 232/8/57
f 40/8/12 39/8/12 234/8/12 235/8/12
f 29/8/9 40/8/9 235/8/9 224/8/9
f 39/8/58 27/8/58 222/8/58 234/8/58
f 41/5/9 42/5/9 237/5/9 236/5/9
f 12/5/59 41/5/59 236/5/59 207/5/59
f 42/5/60 14/5/60 209/5/60 237/5/60
f 43/5/9 44/5/9 239/5/9 238/5/9
f 16/5/61 43/5/61 238/5/61 211/5/61
f 44/5/62 18/5/62 213/5/62 239/5/62
f 45/5/9 46/5/9 241/5/9 240/5/9
f 20/5/63 45/5/63 240/5/63 215/5/63
f 46/5/64 22/5/64 217/5/64 241/5/64
f 47/5/12 48/5/12 243/5/12 242/5/12
f 28/5/65 47/5/65 242/5/65 223/5/65
f 48/5/9 30/5/9 225/5/9 243/5/9
f 49/9/9 52/12/9 247/12/9 244/9/9
f 50/10/11 49/9/11 244/9/11 245/10/11
f 51/14/10 64/8/10 259/8/10 246/14/10
f 53/11/8 50/10/8 245/10/8 248/11/8
f 55/13/9 51/14/9 246/14/9 250/13/9
f 60/12/12 61/11/12 256/11/12 255/12/12
f 62/6/12 63/13/12 258/13/12 257/6/12
f 54/6/8 62/6/8 257/6/8 249/6/8
f 63/13/9 55/13/9 250/13/9 258/13/9
f 52/12/9 60/12/9 255/12/9 247/12/9
f 61/11/8 53/11/8 248/11/8 256/11/8
f 65/5/66 54/6/66 249/6/66 260/5/66
f 64/8/8 65/5/8 260/5/8 259/8/8
f 66/9/9 68/16/9 263/16/9 261/9/9
f 67/10/11 66/9/11 261/9/11 262/10/11
f 69/15/8 67/10/8 262/10/8 264/15/8
f 68/16/10 69/15/10 264/15/10 263/16/10
f 71/10/67 70/9/67 265/9/67 266/10/67
f 73/15/8 71/10/8 266/10/8 268/15/8
f 72/16/68 73/15/68 268/15/68 267/16/68
f 74/9/9 76/16/9 271/16/9 269/9/9
f 75/10/7 74/9/7 269/9/7 270/10/7
f 77/15/8 75/10/8 270/10/8 272/15/8
f 76/16/12 77/15/12 272/15/12 271/16/12
f 78/9/8 80/16/8 275/16/8 273/9/8
f 79/10/7 78/9/7 273/9/7 274/10/7
f 81/15/9 79/10/9 274/10/9 276/15/9
f 80/16/12 81/15/12 276/15/12 275/16/12
f 82/17/9 85/20/9 280/20/9 277/17/9
f 83/18/69 82/17/69 277/17/69 278/18/69
f 84/19/8 83/18/8 278/18/8 279/19/8
f 87/21/9 93/24/9 288/24/9 282/21/9
f 92/23/8 86/22/8 281/22/8 287/23/8
f 95/25/9 101/28/9 296/28/9 290/25/9
f 100/27/8 94/26/8 289/26/8 295/27/8
f 103/29/9 109/32/9 304/32/9 298/29/9
f 108/31/8 102/30/8 297/30/8 303/31/8
f 109/32/70 108/31/70 303/31/70 304/32/70
f 115/20/7 114/19/7 309/19/7 310/20/7
f 119/24/7 118/23/7 313/23/7 314/24/7
f 123/28/7 122/27/7 317/27/7 318/28/7
f 102/30/8 124/30/8 319/30/8 297/30/8
f 125/29/9 103/29/9 298/29/9 320/29/9
f 101/28/9 123/28/9 318/28/9 296/28/9
f 122/27/8 100/27/8 295/27/8 317/27/8
f 94/26/8 120/26/8 315/26/8 289/26/8
f 121/25/9 95/25/9 290/25/9 316/25/9
f 93/24/9 119/24/9 314/24/9 288/24/9
f 118/23/8 92/23/8 287/23/8 313/23/8
f 86/22/8 116/22/8 311/22/8 281/22/8
f 117/21/9 87/21/9 282/21/9 312/21/9
f 85/20/9 115/20/9 310/20/9 280/20/9
f 114/19/8 84/19/8 279/19/8 309/19/8
f 126/22/70 127/21/70 322/21/70 321/22/70
f 128/26/11 129/25/11 324/25/11 323/26/11
f 130/30/70 131/29/70 326/29/70 325/30/70
f 124/30/8 130/30/8 325/30/8 319/30/8
f 131/29/9 125/29/9 320/29/9 326/29/9
f 120/26/8 128/26/8 323/26/8 315/26/8
f 129/25/9 121/25/9 316/25/9 324/25/9
f 116/22/8 126/22/8 321/22/8 311/22/8
f 127/21/9 117/21/9 312/21/9 322/21/9
f 134/33/12 135/34/12 330/34/12 329/33/12
f 132/33/9 134/33/9 329/33/9 327/33/9
f 135/34/8 133/34/8 328/34/8 330/34/8
f 137/34/7 136/33/7 331/33/7 332/34/7
f 133/34/8 137/34/8 332/34/8 328/34/8
f 136/33/9 132/33/9 327/33/9 331/33/9
f 139/34/7 138/33/7 333/33/7 334/34/7
f 140/33/12 141/34/12 336/34/12 335/33/12
f 138/33/9 140/33/9 335/33/9 333/33/9
f 141/34/8 139/34/8 334/34/8 336/34/8
f 142/17/12 143/18/12 338/18/12 337/17/12
f 143/18/8 145/18/8 340/18/8 338/18/8
f 144/17/9 142/17/9 337/17/9 339/17/9
f 147/18/11 146/17/11 341/17/11 342/18/11
f 145/18/8 147/18/8 342/18/8 340/18/8
f 146/17/9 144/17/9 339/17/9 341/17/9
f 148/31/12 149/32/12 344/32/12 343/31/12
f 151/32/7 150/31/7 345/31/7 346/32/7
f 149/32/9 151/32/9 346/32/9 344/32/9
f 150/31/8 148/31/8 343/31/8 345/31/8
f 153/32/12 152/31/12 347/31/12 348/32/12
f 152/31/8 154/31/8 349/31/8 347/31/8
f 155/32/9 153/32/9 348/32/9 350/32/9
f 154/31/8 156/31/8 351/31/8 349/31/8
f 157/32/9 155/32/9 350/32/9 352/32/9
f 156/31/8 158/31/8 353/31/8 351/31/8
f 159/32/9 157/32/9 352/32/9 354/32/9
f 160/31/10 161/32/10 356/32/10 355/31/10
f 158/31/8 160/31/8 355/31/8 353/31/8
f 161/32/9 159/32/9 354/32/9 356/32/9
f 171/32/12 170/31/12 365/31/12 366/32/12
f 172/31/7 173/32/7 368/32/7 367/31/7
f 173/32/9 171/32/9 366/32/9 368/32/9
f 170/31/8 172/31/8 367/31/8 365/31/8
f 174/31/7 175/32/7 370/32/7 369/31/7
f 176/31/8 174/31/8 369/31/8 371/31/8
f 175/32/9 177/32/9 372/32/9 370/32/9
f 177/32/9 187/32/9 382/32/9 372/32/9
f 186/31/8 176/31/8 371/31/8 381/31/8
f 187/32/9 189/32/9 384/32/9 382/32/9
f 188/31/8 186/31/8 381/31/8 383/31/8
f 189/32/9 191/32/9 386/32/9 384/32/9
f 190/31/8 188/31/8 383/31/8 385/31/8
f 193/32/10 192/31/10 387/31/10 388/32/10
f 191/32/9 193/32/9 388/32/9 386/32/9
f 192/31/8 190/31/8 385/31/8 387/31/8
f 70/9/8 194/9/8 389/9/8 265/9/8
f 195/16/9 72/16/9 267/16/9 390/16/9
f 194/9/7 196/9/7 391/9/7 389/9/7
f 197/16/7 195/16/7 390/16/7 392/16/7
f 196/9/7 198/9/7 393/9/7 391/9/7
f 199/16/7 197/16/7 392/16/7 394/16/7
f 198/9/11 200/9/11 395/9/11 393/9/11
f 201/16/10 199/16/10 394/16/10 396/16/10
f 202/9/12 203/16/12 398/16/12 397/9/12
f 200/9/10 202/9/10 397/9/10 395/9/10
f 203/16/11 201/16/11 396/16/11 398/16/11

BIN
assets/sounds/fart.wav Normal file

Binary file not shown.

BIN
assets/sounds/step.wav Normal file

Binary file not shown.

View File

@@ -9,6 +9,7 @@ class GameListener {
public:
virtual void OnPlayerJoin(game::PlayerID player) {}
virtual void OnPlayerLeave(game::PlayerID player) {}
virtual void OnPlayerDeath(game::PlayerID player) {}
virtual void OnGameStateUpdate(game::GameState newState) {}
};

View File

@@ -1,6 +1,7 @@
#pragma once
namespace blitz {
namespace maths {
class EMASmoother {
private:
@@ -16,4 +17,5 @@ class EMASmoother {
void SetSmoothingTime(float t);
};
} // namespace maths
} // namespace blitz

View File

@@ -33,16 +33,13 @@ class ObjectNotifier {
* \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);
if (iter == m_Listeners.end())
return;
m_Listeners.erase(iter);
m_Listeners.erase(std::remove(m_Listeners.begin(), m_Listeners.end(), listener), m_Listeners.end());
}
/**
* \brief Notify listeners that were bound
* \param function the function to call
* \param args the parameters of the function to call
*/
template <typename Func, typename... Args>
void NotifyListeners(Func function, Args... args) const {

View File

@@ -27,12 +27,12 @@ class Connexion : public protocol::PacketHandler, private NonCopyable {
/**
* \brief Constructs with an empty socket
*/
Connexion(protocol::PacketDispatcher* dispatcher);
Connexion(protocol::PacketDispatcher& dispatcher);
/**
* \brief Constructs with an already connected socket
*/
Connexion(protocol::PacketDispatcher* dispatcher, TCPSocket& socket);
Connexion(protocol::PacketDispatcher& dispatcher, TCPSocket& socket);
/**
* \brief Move constructor

View File

@@ -33,25 +33,25 @@ class PacketDispatcher : private NonCopyable {
* \brief Dispatch a packet
* \param packet The packet to dispatch
*/
void Dispatch(const Packet* packet);
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);
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);
void UnregisterHandler(PacketType type, PacketHandler& handler);
/**
* \brief Unregister a packet handler
* \param handler The packet handler
*/
void UnregisterHandler(PacketHandler* handler);
void UnregisterHandler(PacketHandler& handler);
};
} // namespace protocol

View File

@@ -19,39 +19,40 @@ class PacketDispatcher;
*/
class PacketHandler {
private:
PacketDispatcher* m_Dispatcher;
PacketDispatcher& m_Dispatcher;
public:
/**
* \brief Constructor
* \param dispatcher The packet dispatcher
*/
PacketHandler(PacketDispatcher* dispatcher) : m_Dispatcher(dispatcher) {}
PacketHandler(PacketDispatcher& dispatcher) : m_Dispatcher(dispatcher) {}
virtual ~PacketHandler() {}
/**
* \brief Get the packet dispatcher
* \return The packet dispatcher
*/
PacketDispatcher* GetDispatcher() {
PacketDispatcher& GetDispatcher() {
return m_Dispatcher;
}
virtual void HandlePacket(const ChatPacket* packet) {}
virtual void HandlePacket(const ConnexionInfoPacket* packet) {}
virtual void HandlePacket(const DisconnectPacket* packet) {}
virtual void HandlePacket(const KeepAlivePacket* packet) {}
virtual void HandlePacket(const PlayerJoinPacket* packet) {}
virtual void HandlePacket(const PlayerLeavePacket* packet) {}
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) {}
virtual void HandlePacket(const ChatPacket& packet) {}
virtual void HandlePacket(const ConnexionInfoPacket& packet) {}
virtual void HandlePacket(const DisconnectPacket& packet) {}
virtual void HandlePacket(const KeepAlivePacket& packet) {}
virtual void HandlePacket(const PlayerDeathPacket& packet) {}
virtual void HandlePacket(const PlayerJoinPacket& packet) {}
virtual void HandlePacket(const PlayerLeavePacket& packet) {}
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

@@ -2,6 +2,7 @@
#include "packets/ConnexionInfoPacket.h"
#include "packets/DisconnectPacket.h"
#include "packets/KeepAlivePacket.h"
#include "packets/PlayerDeathPacket.h"
#include "packets/PlayerJoinPacket.h"
#include "packets/PlayerLeavePacket.h"
#include "packets/PlayerListPacket.h"

View File

@@ -7,6 +7,7 @@ class ChatPacket;
class ConnexionInfoPacket;
class DisconnectPacket;
class KeepAlivePacket;
class PlayerDeathPacket;
class PlayerJoinPacket;
class PlayerLeavePacket;
class PlayerListPacket;

View File

@@ -25,6 +25,7 @@ enum class PacketType : std::uint8_t {
// client <-- server
ConnexionInfo, /**< Corresponds to ConnexionInfoPacket */
PlayerDeath, /**< Corresponds to PlayerDeathPacket */
PlayerJoin, /**< Corresponds to PlayerJoinPacket */
PlayerLeave, /**< Corresponds to PlayerLeavePacket */
PlayerList, /**< Corresponds to PlayerListPacket */
@@ -99,5 +100,22 @@ class Packet {
}
};
/**
* \class ConcretePacket
* \brief A concrete instance of a Packet
*/
template <typename PacketDerived>
class ConcretePacket : public Packet {
public:
ConcretePacket() {}
virtual ~ConcretePacket() {}
virtual DataBuffer Serialize(bool packetID = true) const = 0;
virtual void Deserialize(DataBuffer& data) = 0;
virtual void Dispatch(PacketHandler* handler) const;
virtual PacketType GetType() const = 0;
};
} // namespace protocol
} // namespace blitz

View File

@@ -12,6 +12,8 @@ namespace blitz {
class DataBuffer;
namespace protocol {
/**
* \class VarInt
* \brief Variable-length format such that smaller numbers use fewer bytes.
@@ -55,4 +57,5 @@ class VarInt {
friend DataBuffer& operator>>(DataBuffer& in, VarInt& var);
};
} // namespace protocol
} // namespace blitz

View File

@@ -20,11 +20,11 @@ struct ColoredPart {
/**
* \brief The color of the part.
*/
Vec4f color;
Vec4f m_Color;
/**
* \brief The text of the part.
*/
std::string text;
std::string m_Text;
};
typedef std::vector<ColoredPart> ColoredText;
@@ -41,7 +41,7 @@ typedef std::vector<ColoredPart> ColoredText;
* |--------------------|-------------------|-------------------------------|
* | m_Message | ColoredText | The message sent in the chat |
*/
class ChatPacket : public Packet {
class ChatPacket : public ConcretePacket<ChatPacket> {
private:
ColoredText m_Message;
@@ -64,7 +64,6 @@ class ChatPacket : public Packet {
virtual DataBuffer Serialize(bool packetID = true) const;
virtual void Deserialize(DataBuffer& data);
virtual void Dispatch(PacketHandler* handler) const;
/**
* \brief Get the message.

View File

@@ -22,7 +22,7 @@ namespace protocol {
* |--------------------|-------------------|-------------------------------|
* | m_ConnectionID | std::uint8_t | The connection ID |
*/
class ConnexionInfoPacket : public Packet {
class ConnexionInfoPacket : public ConcretePacket<ConnexionInfoPacket> {
private:
std::uint8_t m_ConnectionID;
@@ -40,7 +40,6 @@ class ConnexionInfoPacket : public Packet {
virtual DataBuffer Serialize(bool packetID = true) const;
virtual void Deserialize(DataBuffer& data);
virtual void Dispatch(PacketHandler* handler) const;
/**
* \brief Get the connection ID.

View File

@@ -22,7 +22,7 @@ namespace protocol {
* |--------------------|-------------------|-------------------------------|
* | m_Reason | std::string | The reason for disconnection |
*/
class DisconnectPacket : public Packet {
class DisconnectPacket : public ConcretePacket<DisconnectPacket> {
private:
std::string m_Reason; // only when sent from server
public:
@@ -39,7 +39,6 @@ class DisconnectPacket : public Packet {
virtual DataBuffer Serialize(bool packetID = true) const;
virtual void Deserialize(DataBuffer& data);
virtual void Dispatch(PacketHandler* handler) const;
/**
* \brief Get the reason for disconnection.

View File

@@ -5,7 +5,7 @@
* \brief File containing the blitz::protocol::KeepAlivePacket class
*/
#include "blitz/common/VarInt.h"
#include "blitz/protocol/VarInt.h"
#include "blitz/protocol/Protocol.h"
namespace blitz {
@@ -25,7 +25,7 @@ namespace protocol {
* | Keep Alive ID | VarInt | The server generates a random ID, the client must respond with the same |
*
*/
class KeepAlivePacket : public Packet {
class KeepAlivePacket : public ConcretePacket<KeepAlivePacket> {
private:
VarInt m_AliveID;
@@ -36,7 +36,6 @@ class KeepAlivePacket : public Packet {
virtual DataBuffer Serialize(bool packetID = true) const;
virtual void Deserialize(DataBuffer& data);
virtual void Dispatch(PacketHandler* handler) const;
/**
* \brief Getter of the alive ID

View File

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

View File

@@ -25,7 +25,7 @@ namespace protocol {
* | Player Name | std::string | Name of the player who joined |
*
*/
class PlayerJoinPacket : public Packet {
class PlayerJoinPacket : public ConcretePacket<PlayerJoinPacket> {
private:
game::PlayerID m_PlayerID;
std::string m_PlayerName;
@@ -37,7 +37,6 @@ class PlayerJoinPacket : public Packet {
virtual DataBuffer Serialize(bool packetID = true) const;
virtual void Deserialize(DataBuffer& data);
virtual void Dispatch(PacketHandler* handler) const;
/**
* \brief Getter of the player id

View File

@@ -23,7 +23,7 @@ namespace protocol {
* |--------------------|-------------------|-------------------------------|
* | m_PlayerID | PlayerID |The ID of the player that left |
*/
class PlayerLeavePacket : public Packet {
class PlayerLeavePacket : public ConcretePacket<PlayerLeavePacket> {
private:
game::PlayerID m_PlayerID;
@@ -41,7 +41,6 @@ class PlayerLeavePacket : public Packet {
virtual DataBuffer Serialize(bool packetID = true) const;
virtual void Deserialize(DataBuffer& data);
virtual void Dispatch(PacketHandler* handler) const;
/**
* \brief Get the ID of the player that left.

View File

@@ -17,7 +17,7 @@ namespace protocol {
* \brief Represents information about a player.
*/
struct PlayerInfo {
std::string name;
std::string m_Name;
};
typedef std::map<std::uint8_t, PlayerInfo> PlayerList;
@@ -27,7 +27,7 @@ typedef std::map<std::uint8_t, PlayerInfo> PlayerList;
* \brief Packet for sending the list of players.
* \todo PACKET STRUCTURE
*/
class PlayerListPacket : public Packet {
class PlayerListPacket : public ConcretePacket<PlayerListPacket> {
private:
PlayerList m_Players;
@@ -45,8 +45,6 @@ class PlayerListPacket : public Packet {
virtual DataBuffer Serialize(bool packetID = true) const;
virtual void Deserialize(DataBuffer& data);
virtual void Dispatch(PacketHandler* handler) const;
/**
* \brief Get the list of players.

View File

@@ -22,7 +22,7 @@ namespace protocol {
* |--------------------|-------------------|----------------------------------|
* | Player Name | std::string | Name of the player that logged in|
*/
class PlayerLoginPacket : public Packet {
class PlayerLoginPacket : public ConcretePacket<PlayerLoginPacket> {
private:
std::string m_PlayerName;
@@ -40,7 +40,6 @@ class PlayerLoginPacket : public Packet {
virtual DataBuffer Serialize(bool packetID = true) const;
virtual void Deserialize(DataBuffer& data);
virtual void Dispatch(PacketHandler* handler) const;
/**
* \brief Get the name of the player that logged in.

View File

@@ -27,7 +27,7 @@ namespace protocol {
* | Yaw | float | Yaw of the player |
* | Pitch | float | Pitch of the player |
*/
class PlayerPositionAndRotationPacket : public Packet {
class PlayerPositionAndRotationPacket : public ConcretePacket<PlayerPositionAndRotationPacket> {
private:
game::PlayerID m_Player; // only used when sent to client
Vec3f m_Position;
@@ -51,7 +51,6 @@ class PlayerPositionAndRotationPacket : public Packet {
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.

View File

@@ -26,7 +26,7 @@ namespace protocol {
* | Yaw | float | Yaw of the player |
* | Pitch | float | Pitch of the player |
*/
class PlayerShootPacket : public Packet {
class PlayerShootPacket : public ConcretePacket<PlayerShootPacket> {
private:
game::PlayerID m_Player; // only used when sent to client
Vec3f m_Position;
@@ -50,7 +50,6 @@ class PlayerShootPacket : public Packet {
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.

View File

@@ -25,7 +25,7 @@ namespace protocol {
* | Player ID | PlayerID | Id of the player |
* | Player Stats | PlayerStats | Stats of the player |
*/
class PlayerStatsPacket : public Packet {
class PlayerStatsPacket : public ConcretePacket<PlayerStatsPacket> {
private:
game::PlayerID m_PlayerID;
game::PlayerStats m_PlayerStats;
@@ -45,7 +45,6 @@ class PlayerStatsPacket : public Packet {
virtual DataBuffer Serialize(bool packetID = true) const;
virtual void Deserialize(DataBuffer& data);
virtual void Dispatch(PacketHandler* handler) const;
/**
* \brief Getter of the player id

View File

@@ -23,7 +23,7 @@ namespace protocol {
* |--------------------|-------------------|-------------------------------|
* | Game Config | GameConfig | The game configuration |
*/
class ServerConfigPacket : public Packet {
class ServerConfigPacket : public ConcretePacket<ServerConfigPacket> {
private:
game::GameConfig m_GameConfig;
@@ -41,7 +41,6 @@ class ServerConfigPacket : public Packet {
virtual DataBuffer Serialize(bool packetID = true) const;
virtual void Deserialize(DataBuffer& data);
virtual void Dispatch(PacketHandler* handler) const;
/**
* \brief Getter of the game configuration

View File

@@ -24,7 +24,7 @@ namespace protocol {
* | Mspt | float | Server MSPT |
* | PacketSendTime | uint64_t | Time the packet was sent |
*/
class ServerTpsPacket : public Packet {
class ServerTpsPacket : public ConcretePacket<ServerTpsPacket> {
private:
float m_TPS;
float m_MSPT;
@@ -45,7 +45,6 @@ class ServerTpsPacket : public Packet {
virtual DataBuffer Serialize(bool packetID = true) const;
virtual void Deserialize(DataBuffer& data);
virtual void Dispatch(PacketHandler* handler) const;
/**
* \brief Get the server TPS.

View File

@@ -24,7 +24,7 @@ namespace protocol {
* | Game State | GameState | The new game state |
* | Time Remaining | std::uint64_t | The time remaining in the current game state |
*/
class UpdateGameStatePacket : public Packet {
class UpdateGameStatePacket : public ConcretePacket<UpdateGameStatePacket> {
private:
game::GameState m_GameState;
std::uint64_t m_TimeRemaining;
@@ -45,7 +45,6 @@ class UpdateGameStatePacket : public Packet {
virtual DataBuffer Serialize(bool packetID = true) const;
virtual void Deserialize(DataBuffer& data);
virtual void Dispatch(PacketHandler* handler) const;
/**
* \brief Get the new game state.

View File

@@ -22,7 +22,7 @@ namespace protocol {
* |--------------------|-------------------|-------------------------------|
* | m_NewHealth | float | The new health value |
*/
class UpdateHealthPacket : public Packet {
class UpdateHealthPacket : public ConcretePacket<UpdateHealthPacket> {
private:
float m_NewHealth;
@@ -40,7 +40,6 @@ class UpdateHealthPacket : public Packet {
virtual DataBuffer Serialize(bool packetID = true) const;
virtual void Deserialize(DataBuffer& data);
virtual void Dispatch(PacketHandler* handler) const;
/**
* \brief Get the new health value.

View File

@@ -0,0 +1,81 @@
#pragma once
#include "blitz/misc/ObjectNotifier.h"
#include "blitz/misc/Time.h"
#include "blitz/protocol/packets/ChatPacket.h"
#include "client/Listeners.h"
#include <memory>
namespace blitz {
namespace game {
class Player;
} // namespace game
namespace client {
class ClientConnexion;
class ClientGame;
static const int PlayerUpdatePosRate = 50;
/**
* \class BaseClient
* \brief Minimal client which connects to a server
*/
class BaseClient : public utils::ObjectNotifier<ClientListener> {
private:
utils::Timer m_UpdatePosTimer{PlayerUpdatePosRate};
std::unique_ptr<ClientConnexion> m_Connexion;
std::unique_ptr<ClientGame> m_Game;
public:
BaseClient();
virtual ~BaseClient();
/**
* \brief Should be called every frame
*/
virtual void Update();
bool JoinGame(const std::string& pseudo, const std::string& address, std::uint16_t port);
void Disconnect();
void SendChatText(const std::string& text);
void SendPlayerPosAndLook(const Vec3f& position, float yaw, float pitch);
/**
* \brief Sends the protocol::Packet over the network to the remote
* \param packet The protocol::Packet to send
*/
void SendPacket(const protocol::Packet* packet);
bool IsConnected();
game::PlayerID GetPlayerID() const;
client::ClientGame* GetGame() {
return m_Game.get();
}
/**
* \brief Get a player by its identifier
* \param id The identifier of the player
* \return The player if found, nullptr otherwise
*/
game::Player* GetPlayerById(game::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 game::Player* GetPlayerById(game::PlayerID id) const;
private:
void UpdatePosition(std::uint64_t delta);
};
} // namespace client
} // namespace blitz

View File

@@ -1,64 +1,37 @@
#pragma once
#include "blitz/common/Defines.h"
#include "blitz/misc/ObjectNotifier.h"
#include "blitz/misc/Time.h"
#include "blitz/protocol/packets/ChatPacket.h"
#include "client/BaseClient.h"
#include "client/Listeners.h"
#include "client/config/BlitzConfig.h"
#include "client/game/Listeners.h"
#include <cstdint>
#include <memory>
#include <string>
namespace blitz {
static const int PlayerUpdatePosRate = 50;
namespace client {
class ClientConnexion;
class ClientGame;
} // namespace client
namespace server {
class Server;
} // namespace server
namespace client {
// Singleton
class Client : public utils::ObjectNotifier<game::ClientListener>, public game::PlayerInputListener {
class Client : public BaseClient, public PlayerInputListener, public ClientListener {
private:
std::unique_ptr<server::Server> m_Server;
std::unique_ptr<client::ClientConnexion> m_Connexion;
std::unique_ptr<client::ClientGame> m_Game;
utils::Timer m_UpdatePosTimer{PlayerUpdatePosRate};
BlitzConfig m_Config;
public:
Client();
virtual ~Client();
void Update();
virtual void Update() override;
bool IsConnected();
bool JoinGame(const std::string& pseudo, const std::string& address, std::uint16_t port);
bool CreateGame(std::uint16_t port, const std::string& pseudo);
void Disconnect();
void SendChatText(const std::string& text);
void ChatTextReceived(const protocol::ColoredText& text);
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() {
return m_Game.get();
}
virtual void OnGameLeave() override;
BlitzConfig* GetConfig() {
return &m_Config;
@@ -71,11 +44,7 @@ class Client : public utils::ObjectNotifier<game::ClientListener>, public game::
}
void UpdateServerConfig();
private:
void Reset();
void UpdatePosition(std::uint64_t delta);
};
} // namespace client
} // namespace blitz

View File

@@ -4,25 +4,24 @@
#include "blitz/network/Connexion.h"
namespace blitz {
class Client;
namespace client {
class BaseClient;
class ClientConnexion : public network::Connexion {
private:
Client* m_Client;
BaseClient& m_Client;
std::string m_PlayerName;
game::PlayerID m_PlayerID;
public:
ClientConnexion(Client* client);
ClientConnexion(BaseClient& client);
virtual ~ClientConnexion();
virtual void HandlePacket(const protocol::DisconnectPacket* packet) override;
virtual void HandlePacket(const protocol::KeepAlivePacket* packet) override;
virtual void HandlePacket(const protocol::ChatPacket* packet) override;
virtual void HandlePacket(const protocol::ConnexionInfoPacket* packet) override;
virtual void HandlePacket(const protocol::DisconnectPacket& packet) override;
virtual void HandlePacket(const protocol::KeepAlivePacket& packet) override;
virtual void HandlePacket(const protocol::ChatPacket& packet) override;
virtual void HandlePacket(const protocol::ConnexionInfoPacket& packet) override;
bool Connect(const std::string& pseudo, const std::string& address, std::uint16_t port);

View File

@@ -13,7 +13,7 @@ typedef std::vector<ColoredPart> ColoredText;
} // namespace protocol
namespace game {
namespace client {
class PlayerInputListener {
public:
@@ -25,7 +25,7 @@ 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 OnPlayerShoot(game::PlayerID player, const Vec3f& position, float yaw, float pitch) {}
virtual void OnClientPlayerJoin() {}
virtual void OnGameConfigUpdate() {}
virtual void OnGameJoin() {}

View File

@@ -1,5 +1,6 @@
#pragma once
#include <memory>
#include "blitz/common/DataBuffer.h"
#include "blitz/common/NonCopyable.h"
#include "blitz/maths/Vector.h"
@@ -21,5 +22,7 @@ class AudioBuffer : private NonCopyable {
}
};
typedef std::shared_ptr<AudioBuffer> AudioBufferPtr;
} // namespace audio
} // namespace blitz

View File

@@ -1,14 +1,16 @@
#pragma once
#include "blitz/game/Listeners.h"
#include "client/Listeners.h"
#include "client/audio/AudioListener.h"
#include "client/audio/AudioSource.h"
#include "client/game/Listeners.h"
#include <map>
namespace blitz {
namespace client {
class Client;
} // namespace client
namespace game {
class Player;
@@ -19,26 +21,31 @@ namespace audio {
struct PlayerSound {
AudioSourcePtr m_Laser;
AudioSourcePtr m_FootStep;
AudioSourcePtr m_Death;
};
class AudioManager : public game::ClientListener, public game::GameListener {
class AudioManager : public client::ClientListener, public game::GameListener {
private:
Client* m_Client;
client::Client* m_Client;
game::Player* m_Player;
AudioListener m_Listener;
AudioSourcePtr m_MenuMusic;
AudioSourcePtr m_EndMusic;
AudioBufferPtr m_DeathSound;
AudioBufferPtr m_LaserSound;
AudioBufferPtr m_FootStepSound;
std::map<game::PlayerID, PlayerSound> m_PlayerSources;
public:
AudioManager(Client* client);
AudioManager(client::Client* client);
~AudioManager();
virtual void OnGameJoin() override;
virtual void OnGameLeave() override;
virtual void OnGameStateUpdate(game::GameState gameState) override;
virtual void OnClientPlayerJoin() override;
virtual void OnPlayerDeath(game::PlayerID player) 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;

View File

@@ -3,13 +3,10 @@
#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;

View File

@@ -11,6 +11,8 @@
namespace blitz {
namespace input {
/**
* \enum KeyAction
* \brief Enum containing the key actions
@@ -24,7 +26,9 @@ enum KeyAction {
kaMax,
};
typedef std::array<int, kaMax> Keybinds;
} // namespace input
typedef std::array<int, input::kaMax> Keybinds;
/**
* \class BlitzConfig

View File

@@ -6,31 +6,31 @@
#include <vector>
namespace blitz {
class Client;
namespace client {
class BaseClient;
class ClientGame : public game::Game, public protocol::PacketHandler {
private:
Client* m_Client;
BaseClient& m_Client;
game::LeaderBoard m_LeaderBoard;
public:
ClientGame(Client* client, protocol::PacketDispatcher* dispatcher);
ClientGame(BaseClient& client, protocol::PacketDispatcher& dispatcher);
virtual ~ClientGame();
void Tick(std::uint64_t delta) override;
virtual void HandlePacket(const protocol::PlayerJoinPacket* packet) override;
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 HandlePacket(const protocol::PlayerDeathPacket& packet) override;
virtual void HandlePacket(const protocol::PlayerJoinPacket& packet) override;
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;

View File

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

View File

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

View File

@@ -3,6 +3,11 @@
#include "GuiWidget.h"
namespace blitz {
namespace client {
class Client;
} // namespace client
namespace gui {
class CrossHair : public GuiWidget {
@@ -10,7 +15,7 @@ class CrossHair : public GuiWidget {
std::uint64_t m_CrossHairTexture;
public:
CrossHair(Client* client);
CrossHair(client::Client* client);
virtual void Render() override;
};

View File

@@ -4,13 +4,15 @@
namespace blitz {
namespace client {
class Client;
} // namespace client
namespace gui {
class FPSMenu : public GuiWidget {
public:
FPSMenu(GuiWidget* parent, Client* client) : GuiWidget(parent, client) {}
FPSMenu(GuiWidget* parent, client::Client* client) : GuiWidget(parent, client) {}
virtual void Render() override;
};

View File

@@ -2,15 +2,19 @@
#include "GuiWidget.h"
#include "client/Client.h"
#include "client/display/InputManager.h"
#include "client/input/InputManager.h"
#include <string>
#include <vector>
namespace blitz {
namespace client {
class Client;
} // namespace client
namespace gui {
class GameChatGui : public GuiWidget, game::ClientListener {
class GameChatGui : public GuiWidget, client::ClientListener {
private:
char InputBuf[256];
std::vector<protocol::ColoredText> m_Lines;
@@ -27,7 +31,7 @@ class GameChatGui : public GuiWidget, game::ClientListener {
void DrawMini(const char* title, bool* p_open);
public:
GameChatGui(GuiWidget* parent, Client* client, input::InputManager& inputManager);
GameChatGui(GuiWidget* parent, client::Client* client, input::InputManager& inputManager);
virtual ~GameChatGui();
virtual void OnTextChatReceived(const protocol::ColoredText& text) override;

View File

@@ -7,19 +7,21 @@
namespace blitz {
namespace client {
class Client;
} // namespace client
namespace gui {
class GuiWidget {
protected:
bool m_Enabled;
Client* m_Client;
client::Client* m_Client;
GuiWidget* m_Parent;
std::vector<std::unique_ptr<GuiWidget>> m_SubWidgets;
public:
GuiWidget(GuiWidget* parent, Client* client) : m_Enabled(false), m_Client(client), m_Parent(parent) {}
GuiWidget(GuiWidget* parent, client::Client* client) : m_Enabled(false), m_Client(client), m_Parent(parent) {}
virtual ~GuiWidget() {}
void Enable() {

View File

@@ -5,23 +5,30 @@
namespace blitz {
namespace client {
class Client;
} // namespace client
namespace game {
class Player;
} // namespace game
namespace gui {
class Hud : public GuiWidget {
class Hud : public GuiWidget, public game::GameListener, public client::ClientListener {
private:
std::uint64_t m_GunTexture;
std::uint64_t m_JPTexture;
utils::DelayTimer<float> m_Timer{5.0f};
public:
Hud(GuiWidget* parent, Client* client);
Hud(GuiWidget* parent, client::Client* client);
virtual ~Hud();
virtual void Render() override;
virtual void OnGameStateUpdate(game::GameState gameState) override;
virtual void OnGameJoin() override;
virtual void OnGameLeave() override;
private:
std::string FormatString();
void Draw(const char* title, bool* p_open);

View File

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

View File

@@ -5,16 +5,24 @@
namespace blitz {
namespace client {
class Client;
} // namespace client
namespace gui {
class LeaderBoardGui : public GuiWidget {
class LeaderBoardGui : public GuiWidget, public game::GameListener, public client::ClientListener {
private:
void Draw(const char* title, bool* p_open);
utils::DelayTimer<float> m_Timer{5.0f};
public:
LeaderBoardGui(GuiWidget* parent, Client* client);
LeaderBoardGui(GuiWidget* parent, client::Client* client);
~LeaderBoardGui();
virtual void OnGameStateUpdate(game::GameState gameState) override;
virtual void OnGameJoin() override;
virtual void OnGameLeave() override;
virtual void Render() override;
};

View File

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

View File

@@ -3,13 +3,15 @@
#include "GuiWidget.h"
#include "blitz/misc/Time.h"
#include "client/config/BlitzConfig.h"
#include "client/display/InputManager.h"
#include "client/input/InputManager.h"
#include <array>
#include <string>
namespace blitz {
namespace client {
class Client;
} // namespace client
namespace gui {
@@ -20,11 +22,11 @@ class OptionsMenu : public GuiWidget, public input::InputListener {
bool m_IsKeyPopupOpen;
bool m_KeyPopupShouldClose;
utils::Timer m_Timer{100};
KeyAction m_CurrentAction;
input::KeyAction m_CurrentAction;
input::InputManager& m_InputManager;
public:
OptionsMenu(GuiWidget* parent, Client* client, input::InputManager& inputManager);
OptionsMenu(GuiWidget* parent, client::Client* client, input::InputManager& inputManager);
virtual ~OptionsMenu();
virtual void Render() override;
@@ -32,7 +34,7 @@ class OptionsMenu : public GuiWidget, public input::InputListener {
virtual void OnKeyDown(int key) override;
private:
std::string GetKeyActionCodeName(KeyAction);
std::string GetKeyActionCodeName(input::KeyAction);
void HotkeyBindingButton();
void HotkeyBindingPopUp();
};

View File

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

View File

@@ -5,8 +5,8 @@
* \brief File containing the blitz::Display class
*/
#include "client/display/InputManager.h"
#include "client/display/PlayerController.h"
#include "client/input/InputManager.h"
#include "client/input/PlayerController.h"
#include <memory>
#include <string>
@@ -14,12 +14,16 @@ class SDL_Window;
namespace blitz {
namespace client {
class Client;
} // namespace client
namespace gui {
class BlitzGui;
} // namespace gui
namespace input {
/**
* \class Display
* \brief Class used to manage the display
@@ -37,7 +41,7 @@ class Display {
bool m_ShouldClose;
bool m_FullScreen;
Client* m_Client;
client::Client* m_Client;
input::InputManager& m_InputManager;
std::unique_ptr<gui::BlitzGui> m_BlitzGui;
input::PlayerController m_PlayerController;
@@ -51,7 +55,7 @@ class Display {
* \param client The client
* \param inputManager The InputManager
*/
Display(int width, int height, const std::string& windowName, Client* client, input::InputManager& inputManager);
Display(int width, int height, const std::string& windowName, client::Client* client, input::InputManager& inputManager);
~Display();
/**
@@ -112,4 +116,5 @@ class Display {
void InitImGui();
};
} // namespace input
} // namespace blitz

View File

@@ -5,15 +5,17 @@
* \brief File containing the blitz::input::PlayerController class.
*/
#include "blitz/common/Smoothing.h"
#include "blitz/maths/Smoothing.h"
#include "blitz/misc/ObjectNotifier.h"
#include "blitz/misc/Time.h"
#include "client/display/InputManager.h"
#include "client/game/Listeners.h"
#include "client/input/InputManager.h"
#include "client/Listeners.h"
namespace blitz {
namespace client {
class Client;
} // namespace client
namespace game {
@@ -28,14 +30,14 @@ namespace input {
* \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 {
class PlayerController : public utils::ObjectNotifier<client::PlayerInputListener>, client::ClientListener, InputListener {
private:
game::Player* m_Player;
Client* m_Client;
client::Client* m_Client;
input::InputManager& m_InputManager;
utils::CooldownTimer<float> m_ShootTimer{1.0f};
EMASmoother m_DxSmoother;
EMASmoother m_DySmoother;
maths::EMASmoother m_DxSmoother;
maths::EMASmoother m_DySmoother;
// current (target) velocity
Vec3f m_Velocity;
/// maximum x-axis velocity
@@ -47,7 +49,7 @@ class PlayerController : public utils::ObjectNotifier<game::PlayerInputListener>
/**
* \brief Default constructor
*/
PlayerController(Client* client, input::InputManager& inputManager);
PlayerController(client::Client* client, input::InputManager& inputManager);
virtual ~PlayerController();
/**

View File

@@ -1,7 +1,6 @@
#pragma once
#include "client/Client.h"
#include "client/display/PlayerController.h"
#include "client/input/PlayerController.h"
#include "client/render/BulletRenderer.h"
#include "client/render/Camera.h"
#include "client/render/loader/GLLoader.h"
@@ -9,6 +8,10 @@
namespace blitz {
namespace client {
class Client;
} // namespace client
namespace shader {
class EntityShader;
@@ -20,9 +23,9 @@ class GunShader;
namespace render {
class MainRenderer : public game::ClientListener, public game::PlayerInputListener {
class MainRenderer : public client::ClientListener, public client::PlayerInputListener {
private:
Client* m_Client;
client::Client* m_Client;
ModelLoader::Model m_PlayerModel;
ModelLoader::Model m_WorldModel;
ModelLoader::Model m_GunModel;
@@ -36,7 +39,7 @@ class MainRenderer : public game::ClientListener, public game::PlayerInputListen
input::PlayerController& m_PlayerController;
public:
MainRenderer(Client* client, input::PlayerController& playerController);
MainRenderer(client::Client* client, input::PlayerController& playerController);
~MainRenderer();
virtual void OnSpectatorChange(game::PlayerID player) override;

View File

@@ -39,7 +39,7 @@ struct KeepAlive {
*/
class ServerConnexion : public network::Connexion {
private:
Server* m_Server;
Server& m_Server;
std::uint8_t m_ID;
KeepAlive m_KeepAlive;
game::Player* m_Player;
@@ -52,7 +52,7 @@ class ServerConnexion : public network::Connexion {
* \param socket The socket
* \param id The ID of the connexion
*/
ServerConnexion(Server* server, network::TCPSocket& socket, std::uint8_t id);
ServerConnexion(Server& server, network::TCPSocket& socket, std::uint8_t id);
/**
* \brief Move constructor
*/
@@ -72,12 +72,12 @@ class ServerConnexion : public network::Connexion {
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;
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;
virtual bool UpdateSocket() override;

View File

@@ -31,7 +31,7 @@ class Server;
*/
class ServerGame : public game::Game {
private:
Server* m_Server;
Server& m_Server;
utils::Timer m_PositionTimer;
ServerDuration m_ServerDuration;
@@ -40,7 +40,7 @@ class ServerGame : public game::Game {
* \brief Constructor
* \param server The server
*/
ServerGame(Server* server);
ServerGame(Server& server);
virtual ~ServerGame();
/**

View File

@@ -1,15 +1,15 @@
#include "blitz/network/Network.h"
#include "client/Client.h"
#include "client/audio/AudioManager.h"
#include "client/display/Display.h"
#include "client/display/InputManager.h"
#include "client/input/Display.h"
#include "client/input/InputManager.h"
#include "client/render/MainRenderer.h"
int main(int argc, char** argv) {
blitz::Client client;
blitz::client::Client client;
blitz::input::InputManager inputManager;
blitz::Display display(1920, 1080, "BlitzKrieg", &client, inputManager);
blitz::input::Display display(1920, 1080, "Blitz", &client, inputManager);
if (!display.Create())
return EXIT_FAILURE;

View File

@@ -9,9 +9,8 @@ void LeaderBoard::AddPlayer(Player* player) {
}
void LeaderBoard::RemovePlayer(PlayerID player) {
auto it = std::find_if(m_Players.begin(), m_Players.end(), [player](game::Player* p) { return p->GetID() == player; });
if (it != m_Players.end())
m_Players.erase(it);
m_Players.erase(std::remove_if(m_Players.begin(), m_Players.end(), [player](game::Player* p) { return p->GetID() == player; }),
m_Players.end());
}
void LeaderBoard::Update() {

View File

@@ -1,8 +1,9 @@
#include "blitz/common/Smoothing.h"
#include "blitz/maths/Smoothing.h"
#include <cassert>
#include <cmath>
namespace blitz {
namespace maths {
EMASmoother::EMASmoother() : Alpha(1.0f), Current(0.0f) {}
@@ -27,4 +28,5 @@ void EMASmoother::SetSmoothingTime(float t) {
SetAlpha(std::pow(1.0f - 0.999f, 1.0f / t));
};
} // namespace maths
} // namespace blitz

View File

@@ -1,6 +1,6 @@
#include "blitz/misc/Compression.h"
#include "blitz/common/VarInt.h"
#include "blitz/protocol/VarInt.h"
#include <cassert>
#include <zlib.h>
@@ -37,7 +37,7 @@ DataBuffer Compress(const DataBuffer& buffer) {
if (buffer.GetSize() < COMPRESSION_THRESHOLD) {
// Don't compress since it's a small packet
VarInt compressedDataLength = 0;
protocol::VarInt compressedDataLength = 0;
std::uint64_t packetLength = compressedDataLength.GetSerializedLength() + buffer.GetSize();
packet << packetLength;
@@ -48,7 +48,7 @@ DataBuffer Compress(const DataBuffer& buffer) {
DataBuffer compressedData = Deflate(buffer.data(), buffer.GetSize());
VarInt uncompressedDataLength = buffer.GetSize();
protocol::VarInt uncompressedDataLength = buffer.GetSize();
std::uint64_t packetLength = uncompressedDataLength.GetSerializedLength() + compressedData.GetSize();
packet << packetLength;
@@ -58,7 +58,7 @@ DataBuffer Compress(const DataBuffer& buffer) {
}
DataBuffer Decompress(DataBuffer& buffer, std::uint64_t packetLength) {
VarInt uncompressedLength;
protocol::VarInt uncompressedLength;
buffer >> uncompressedLength;
std::uint64_t compressedLength = packetLength - uncompressedLength.GetSerializedLength();

View File

@@ -10,11 +10,11 @@
namespace blitz {
namespace network {
Connexion::Connexion(Connexion&& move) : protocol::PacketHandler(&m_Dispatcher), m_Socket(std::move(move.m_Socket)) {}
Connexion::Connexion(Connexion&& move) : protocol::PacketHandler(m_Dispatcher), m_Socket(std::move(move.m_Socket)) {}
Connexion::Connexion(protocol::PacketDispatcher* dispatcher) : protocol::PacketHandler(dispatcher) {}
Connexion::Connexion(protocol::PacketDispatcher& dispatcher) : protocol::PacketHandler(dispatcher) {}
Connexion::Connexion(protocol::PacketDispatcher* dispatcher, TCPSocket& socket) :
Connexion::Connexion(protocol::PacketDispatcher& dispatcher, TCPSocket& socket) :
protocol::PacketHandler(dispatcher), m_Socket(std::move(socket)) {}
bool Connexion::UpdateSocket() {
@@ -39,7 +39,7 @@ bool Connexion::UpdateSocket() {
decompressed >> packetType;
const protocol::PacketPtr packet = protocol::PacketFactory::CreatePacket(packetType, decompressed);
GetDispatcher()->Dispatch(packet.get());
GetDispatcher().Dispatch(*packet.get());
}
return true;
}

View File

@@ -150,7 +150,7 @@ std::size_t TCPSocket::Receive(DataBuffer& buffer, std::size_t amount) {
Disconnect();
buffer.Clear();
m_Status = Status::Error;
SetStatus(Status::Error);
return 0;
}
buffer.Resize(static_cast<std::size_t>(recvAmount));

View File

@@ -3,36 +3,31 @@
namespace blitz {
namespace protocol {
void PacketDispatcher::RegisterHandler(PacketType type, PacketHandler* handler) {
auto found = std::find(m_Handlers[type].begin(), m_Handlers[type].end(), handler);
void PacketDispatcher::RegisterHandler(PacketType type, PacketHandler& handler) {
auto found = std::find(m_Handlers[type].begin(), m_Handlers[type].end(), &handler);
if (found == m_Handlers[type].end())
m_Handlers[type].push_back(handler);
m_Handlers[type].push_back(&handler);
}
void PacketDispatcher::UnregisterHandler(PacketType type, PacketHandler* handler) {
auto found = std::find(m_Handlers[type].begin(), m_Handlers[type].end(), handler);
if (found != m_Handlers[type].end())
m_Handlers[type].erase(found);
void PacketDispatcher::UnregisterHandler(PacketType type, PacketHandler& handler) {
m_Handlers[type].erase(std::remove(m_Handlers[type].begin(), m_Handlers[type].end(), &handler), m_Handlers[type].end());
}
void PacketDispatcher::UnregisterHandler(PacketHandler* handler) {
void PacketDispatcher::UnregisterHandler(PacketHandler& handler) {
for (auto& pair : m_Handlers) {
if (pair.second.empty())
continue;
PacketType type = pair.first;
m_Handlers[type].erase(std::remove(m_Handlers[type].begin(), m_Handlers[type].end(), handler), m_Handlers[type].end());
m_Handlers[type].erase(std::remove(m_Handlers[type].begin(), m_Handlers[type].end(), &handler), m_Handlers[type].end());
}
}
void PacketDispatcher::Dispatch(const Packet* packet) {
if (!packet)
return;
PacketType type = packet->GetType();
void PacketDispatcher::Dispatch(const Packet& packet) {
PacketType type = packet.GetType();
for (PacketHandler* handler : m_Handlers[type])
packet->Dispatch(handler);
packet.Dispatch(handler);
}
} // namespace protocol

View File

@@ -11,10 +11,11 @@ namespace PacketFactory {
typedef std::function<PacketPtr()> PacketCreator;
static std::array<PacketCreator, static_cast<std::size_t>(PacketType::PACKET_COUNT)> Packets = {
static const std::array<PacketCreator, static_cast<std::size_t>(PacketType::PACKET_COUNT)> Packets = {
[]() -> PacketPtr { return std::make_unique<PlayerLoginPacket>(); },
[]() -> PacketPtr { return std::make_unique<UpdateHealthPacket>(); },
[]() -> PacketPtr { return std::make_unique<ConnexionInfoPacket>(); },
[]() -> PacketPtr { return std::make_unique<PlayerDeathPacket>(); },
[]() -> PacketPtr { return std::make_unique<PlayerJoinPacket>(); },
[]() -> PacketPtr { return std::make_unique<PlayerLeavePacket>(); },
[]() -> PacketPtr { return std::make_unique<PlayerListPacket>(); },

View File

@@ -1,11 +1,6 @@
#include "blitz/protocol/PacketHandler.h"
#include "blitz/protocol/Packets.h"
#define REGISTER_DISPATCH_CLASS(className) \
void className::Dispatch(PacketHandler* handler) const { \
handler->HandlePacket(this); \
}
namespace blitz {
namespace protocol {
@@ -14,21 +9,28 @@ void Packet::WritePacketID(DataBuffer& data, bool packetID) const {
data << GetID();
}
REGISTER_DISPATCH_CLASS(PlayerLoginPacket)
REGISTER_DISPATCH_CLASS(KeepAlivePacket)
REGISTER_DISPATCH_CLASS(PlayerListPacket)
REGISTER_DISPATCH_CLASS(PlayerJoinPacket)
REGISTER_DISPATCH_CLASS(PlayerLeavePacket)
REGISTER_DISPATCH_CLASS(ConnexionInfoPacket)
REGISTER_DISPATCH_CLASS(DisconnectPacket)
REGISTER_DISPATCH_CLASS(ServerTpsPacket)
REGISTER_DISPATCH_CLASS(ChatPacket)
REGISTER_DISPATCH_CLASS(PlayerPositionAndRotationPacket)
REGISTER_DISPATCH_CLASS(PlayerShootPacket);
REGISTER_DISPATCH_CLASS(UpdateHealthPacket);
REGISTER_DISPATCH_CLASS(PlayerStatsPacket);
REGISTER_DISPATCH_CLASS(UpdateGameStatePacket);
REGISTER_DISPATCH_CLASS(ServerConfigPacket);
template <typename PacketDerived>
void ConcretePacket<PacketDerived>::Dispatch(PacketHandler* handler) const {
static_assert(std::is_base_of<ConcretePacket, PacketDerived>::value, "PacketDerived must be derived from the ConcretePacket class");
handler->HandlePacket(dynamic_cast<const PacketDerived&>(*this));
}
template class ConcretePacket<ChatPacket>;
template class ConcretePacket<ConnexionInfoPacket>;
template class ConcretePacket<DisconnectPacket>;
template class ConcretePacket<KeepAlivePacket>;
template class ConcretePacket<PlayerDeathPacket>;
template class ConcretePacket<PlayerJoinPacket>;
template class ConcretePacket<PlayerLeavePacket>;
template class ConcretePacket<PlayerListPacket>;
template class ConcretePacket<PlayerLoginPacket>;
template class ConcretePacket<PlayerPositionAndRotationPacket>;
template class ConcretePacket<PlayerShootPacket>;
template class ConcretePacket<PlayerStatsPacket>;
template class ConcretePacket<ServerConfigPacket>;
template class ConcretePacket<ServerTpsPacket>;
template class ConcretePacket<UpdateGameStatePacket>;
template class ConcretePacket<UpdateHealthPacket>;
} // namespace protocol
} // namespace blitz

View File

@@ -1,9 +1,10 @@
#include "blitz/common/VarInt.h"
#include "blitz/protocol/VarInt.h"
#include "blitz/common/DataBuffer.h"
#include <stdexcept>
namespace blitz {
namespace protocol {
static constexpr int SEGMENT_BITS = 0x7F;
static constexpr int CONTINUE_BIT = 0x80;
@@ -49,4 +50,5 @@ DataBuffer& operator>>(DataBuffer& in, VarInt& var) {
return in;
}
} // namespace protocol
} // namespace blitz

View File

@@ -1,6 +1,6 @@
#include "blitz/protocol/packets/ChatPacket.h"
#include "blitz/common/VarInt.h"
#include "blitz/protocol/VarInt.h"
#include "blitz/maths/Vector.h"
#include "blitz/misc/Log.h"
#include <map>
@@ -26,7 +26,7 @@ DataBuffer ChatPacket::Serialize(bool packetID) const {
data << VarInt{m_Message.size()};
for (const auto& part : m_Message) {
data << part.color << part.text;
data << part.m_Color << part.m_Text;
}
return data;
}
@@ -38,7 +38,7 @@ void ChatPacket::Deserialize(DataBuffer& data) {
m_Message.resize(partsNumber.GetValue());
for (std::size_t i = 0; i < partsNumber.GetValue(); ++i) {
data >> m_Message[i].color >> m_Message[i].text;
data >> m_Message[i].m_Color >> m_Message[i].m_Text;
}
}
@@ -139,10 +139,10 @@ std::string ChatPacket::GetColoredTextString(const ColoredText& text) {
std::string result;
for (auto& part : text) {
result += GetTextColor({static_cast<std::uint8_t>(part.color.x * 255), static_cast<std::uint8_t>(part.color.y * 255),
static_cast<std::uint8_t>(part.color.z * 255)})
result += GetTextColor({static_cast<std::uint8_t>(part.m_Color.x * 255), static_cast<std::uint8_t>(part.m_Color.y * 255),
static_cast<std::uint8_t>(part.m_Color.z * 255)})
.c_str();
result += part.text.c_str();
result += part.m_Text.c_str();
}
return result;

View File

@@ -1,6 +1,6 @@
#include "blitz/protocol/packets/KeepAlivePacket.h"
#include "blitz/common/VarInt.h"
#include "blitz/protocol/VarInt.h"
namespace blitz {
namespace protocol {

View File

@@ -0,0 +1,20 @@
#include "blitz/protocol/packets/PlayerDeathPacket.h"
namespace blitz {
namespace protocol {
DataBuffer PlayerDeathPacket::Serialize(bool packetID) const {
DataBuffer data;
WritePacketID(data, packetID);
data << m_PlayerID;
return data;
}
void PlayerDeathPacket::Deserialize(DataBuffer& data) {
data >> m_PlayerID;
}
} // namespace protocol
} // namespace blitz

View File

@@ -1,6 +1,6 @@
#include "blitz/protocol/packets/PlayerListPacket.h"
#include "blitz/common/VarInt.h"
#include "blitz/protocol/VarInt.h"
namespace blitz {
namespace protocol {
@@ -11,7 +11,7 @@ DataBuffer PlayerListPacket::Serialize(bool packetID) const {
WritePacketID(data, packetID);
data << VarInt(m_Players.size());
for (auto [playerID, playerInfo] : m_Players) {
data << playerID << playerInfo.name;
data << playerID << playerInfo.m_Name;
}
return data;
}
@@ -23,7 +23,7 @@ void PlayerListPacket::Deserialize(DataBuffer& data) {
for (std::size_t i = 0; i < playerCount.GetValue(); i++) {
std::uint8_t playerID;
PlayerInfo playerInfo;
data >> playerID >> playerInfo.name;
data >> playerID >> playerInfo.m_Name;
m_Players.insert({playerID, playerInfo});
}
}

91
src/client/BaseClient.cpp Normal file
View File

@@ -0,0 +1,91 @@
#include "client/BaseClient.h"
#include "blitz/misc/Log.h"
#include "blitz/protocol/packets/DisconnectPacket.h"
#include "blitz/protocol/packets/PlayerPositionAndRotationPacket.h"
#include "client/ClientConnexion.h"
#include "client/game/ClientGame.h"
namespace blitz {
namespace client {
BaseClient::BaseClient() :
m_Connexion(std::make_unique<ClientConnexion>(*this)), m_Game(std::make_unique<ClientGame>(*this, m_Connexion->GetDispatcher())) {}
BaseClient::~BaseClient() {
Disconnect();
}
void BaseClient::Update() {
if (m_Connexion->GetSocketStatus() == network::TCPSocket::Status::Disconnected)
return;
if (m_Connexion->UpdateSocket()) {
static std::uint64_t lastTime = utils::GetTime();
UpdatePosition(utils::GetTime() - lastTime);
m_Game->Tick(utils::GetTime() - lastTime);
lastTime = utils::GetTime();
} else {
Disconnect();
}
}
bool BaseClient::JoinGame(const std::string& pseudo, const std::string& address, std::uint16_t port) {
return m_Connexion->Connect(pseudo, address, port);
}
void BaseClient::Disconnect() {
if (m_Connexion->GetSocketStatus() == network::TCPSocket::Status::Disconnected)
return;
protocol::DisconnectPacket packet("Client wants to leave !");
m_Connexion->SendPacket(&packet);
utils::LOGD("[BaseClient] Disconnected !");
m_Connexion->CloseConnection();
// Clear previous game
m_Game.reset(nullptr);
m_Game = std::make_unique<client::ClientGame>(*this, m_Connexion->GetDispatcher());
NotifyListeners(&ClientListener::OnGameLeave);
}
void BaseClient::SendChatText(const std::string& text) {
protocol::ChatPacket packet(text);
m_Connexion->SendPacket(&packet);
}
void BaseClient::SendPlayerPosAndLook(const Vec3f& position, float yaw, float pitch) {
protocol::PlayerPositionAndRotationPacket packet(position, yaw, pitch);
m_Connexion->SendPacket(&packet);
}
game::PlayerID BaseClient::GetPlayerID() const {
return m_Connexion->GetPlayerID();
}
bool BaseClient::IsConnected() {
return m_Connexion->GetSocketStatus() == network::TCPSocket::Status::Connected;
}
void BaseClient::UpdatePosition(std::uint64_t delta) {
// send position every tick (50 ms)
if (m_UpdatePosTimer.Update(delta)) {
game::Player* player = m_Game->GetPlayerById(m_Connexion->GetPlayerID());
if (player)
SendPlayerPosAndLook(player->GetPosition(), player->GetYaw(), player->GetPitch());
}
}
void BaseClient::SendPacket(const protocol::Packet* packet) {
m_Connexion->SendPacket(packet);
}
} // namespace client
} // namespace blitz

View File

@@ -11,34 +11,18 @@
#include <cassert>
namespace blitz {
namespace client {
Client::Client() :
m_Server(std::make_unique<server::Server>()),
m_Connexion(std::make_unique<client::ClientConnexion>(this)),
m_Game(std::make_unique<client::ClientGame>(this, m_Connexion->GetDispatcher())) {}
Client::Client() : BaseClient(), m_Server(std::make_unique<server::Server>()) {
BindListener(this);
}
Client::~Client() {
Disconnect();
}
void Client::Update() {
if (m_Connexion->GetSocketStatus() != network::TCPSocket::Status::Connected)
return;
if (m_Connexion->UpdateSocket()) {
static std::uint64_t lastTime = utils::GetTime();
UpdatePosition(utils::GetTime() - lastTime);
m_Game->Tick(utils::GetTime() - lastTime);
lastTime = utils::GetTime();
} else {
Disconnect();
}
}
bool Client::JoinGame(const std::string& pseudo, const std::string& address, std::uint16_t port) {
return m_Connexion->Connect(pseudo, address, port);
BaseClient::Update();
}
void Client::UpdateServerConfig() {
@@ -61,77 +45,20 @@ bool Client::CreateGame(std::uint16_t port, const std::string& pseudo) {
return true;
}
void Client::Disconnect() {
if (m_Connexion->GetSocketStatus() != network::TCPSocket::Status::Connected)
return;
protocol::DisconnectPacket packet("Client wants to leave !");
m_Connexion->SendPacket(&packet);
utils::LOGD("[Client] Disconnected !");
if (m_Server) {
m_Server->Stop();
}
m_Connexion->CloseConnection();
NotifyListeners(&game::ClientListener::OnGameLeave);
Reset();
}
void Client::Reset() {
utils::LOGD("[Client] Reset !");
// Reset server
void Client::OnGameLeave() {
// Clear previous server
m_Server.reset(nullptr);
m_Server = std::make_unique<server::Server>();
// Reset game
m_Game.reset(nullptr);
m_Game = std::make_unique<client::ClientGame>(this, m_Connexion->GetDispatcher());
}
void Client::SendChatText(const std::string& text) {
protocol::ChatPacket packet(text);
m_Connexion->SendPacket(&packet);
}
void Client::ChatTextReceived(const protocol::ColoredText& text) {
NotifyListeners(&game::ClientListener::OnTextChatReceived, text);
}
void Client::SendPlayerPosAndLook(const Vec3f& position, float yaw, float pitch) {
protocol::PlayerPositionAndRotationPacket packet(position, yaw, pitch);
m_Connexion->SendPacket(&packet);
}
void Client::OnLocalPlayerShoot(const Vec3f& position, float yaw, float pitch) {
protocol::PlayerShootPacket packet(position, yaw, pitch);
m_Connexion->SendPacket(&packet);
}
game::PlayerID Client::GetPlayerID() const {
return m_Connexion->GetPlayerID();
}
bool Client::IsConnected() {
return m_Connexion->GetSocketStatus() == network::TCPSocket::Status::Connected;
SendPacket(&packet);
}
bool Client::IsAdmin() const {
return m_Server->IsRunning();
}
void Client::UpdatePosition(std::uint64_t delta) {
// send position every tick (50 ms)
if (m_UpdatePosTimer.Update(delta)) {
game::Player* player = m_Game->GetPlayerById(m_Connexion->GetPlayerID());
if (player)
SendPlayerPosAndLook(player->GetPosition(), player->GetYaw(), player->GetPitch());
}
}
} // namespace client
} // namespace blitz

View File

@@ -8,7 +8,7 @@
#include "blitz/protocol/packets/DisconnectPacket.h"
#include "blitz/protocol/packets/KeepAlivePacket.h"
#include "blitz/protocol/packets/PlayerLoginPacket.h"
#include "client/Client.h"
#include "client/BaseClient.h"
namespace blitz {
namespace client {
@@ -16,27 +16,27 @@ namespace client {
static std::string PrintColoredText(const protocol::ColoredText& coloredText) {
std::string text;
for (const auto& part : coloredText) {
text += utils::GetTextColor({static_cast<std::uint8_t>(part.color.r * 255), static_cast<std::uint8_t>(part.color.g * 255),
static_cast<std::uint8_t>(part.color.b * 255)}) +
part.text;
text += utils::GetTextColor({static_cast<std::uint8_t>(part.m_Color.r * 255), static_cast<std::uint8_t>(part.m_Color.g * 255),
static_cast<std::uint8_t>(part.m_Color.b * 255)}) +
part.m_Text;
}
text += utils::GetTextColorReset();
return text;
}
ClientConnexion::ClientConnexion(Client* client) : network::Connexion(&m_Dispatcher), m_Client(client) {
ClientConnexion::ClientConnexion(BaseClient& client) : network::Connexion(m_Dispatcher), m_Client(client) {
RegisterHandlers();
}
ClientConnexion::~ClientConnexion() {
GetDispatcher()->UnregisterHandler(this);
GetDispatcher().UnregisterHandler(*this);
}
void ClientConnexion::RegisterHandlers() {
GetDispatcher()->RegisterHandler(protocol::PacketType::KeepAlive, this);
GetDispatcher()->RegisterHandler(protocol::PacketType::Disconnect, this);
GetDispatcher()->RegisterHandler(protocol::PacketType::Chat, this);
GetDispatcher()->RegisterHandler(protocol::PacketType::ConnexionInfo, this);
GetDispatcher().RegisterHandler(protocol::PacketType::KeepAlive, *this);
GetDispatcher().RegisterHandler(protocol::PacketType::Disconnect, *this);
GetDispatcher().RegisterHandler(protocol::PacketType::Chat, *this);
GetDispatcher().RegisterHandler(protocol::PacketType::ConnexionInfo, *this);
}
bool ClientConnexion::Connect(const std::string& pseudo, const std::string& address, std::uint16_t port) {
@@ -47,24 +47,24 @@ bool ClientConnexion::Connect(const std::string& pseudo, const std::string& addr
return true;
}
void ClientConnexion::HandlePacket(const protocol::ChatPacket* packet) {
utils::LOG("[Chat] " + PrintColoredText(packet->GetMessage()));
m_Client->ChatTextReceived(packet->GetMessage());
void ClientConnexion::HandlePacket(const protocol::ChatPacket& packet) {
utils::LOG("[Chat] " + PrintColoredText(packet.GetMessage()));
m_Client.NotifyListeners(&ClientListener::OnTextChatReceived, packet.GetMessage());
}
void ClientConnexion::HandlePacket(const protocol::DisconnectPacket* packet) {
utils::LOG("[ClientConnexion] Disconnected ! Reason : " + packet->GetReason());
m_Client->NotifyListeners(&game::ClientListener::OnGameLeave);
m_Client->Disconnect();
void ClientConnexion::HandlePacket(const protocol::DisconnectPacket& packet) {
utils::LOG("[ClientConnexion] Disconnected ! Reason : " + packet.GetReason());
m_Client.NotifyListeners(&ClientListener::OnGameLeave);
m_Client.Disconnect();
}
void ClientConnexion::HandlePacket(const protocol::KeepAlivePacket* packet) {
protocol::KeepAlivePacket response(packet->GetAliveID());
void ClientConnexion::HandlePacket(const protocol::KeepAlivePacket& packet) {
protocol::KeepAlivePacket response(packet.GetAliveID());
SendPacket(&response);
}
void ClientConnexion::HandlePacket(const protocol::ConnexionInfoPacket* packet) {
m_PlayerID = packet->GetConnectionID();
void ClientConnexion::HandlePacket(const protocol::ConnexionInfoPacket& packet) {
m_PlayerID = packet.GetConnectionID();
utils::LOGD("[ClientConnexion] Logging in with pseudo " + m_PlayerName + " ...");
Login(m_PlayerName);
}

View File

@@ -9,7 +9,7 @@
namespace blitz {
namespace audio {
AudioManager::AudioManager(Client* client) : m_Client(client), m_Player(nullptr) {
AudioManager::AudioManager(client::Client* client) : m_Client(client), m_Player(nullptr) {
m_Listener.SetGain(1.0f);
InitSounds();
m_MenuMusic->Play();
@@ -27,6 +27,25 @@ void AudioManager::Update() {
m_Listener.SetPosition(m_Player->GetPosition());
m_Listener.SetOrientation(maths::GetDirectionVectorFromRotation(m_Player->GetYaw(), m_Player->GetPitch()), {0.0f, 1.0f, 0.0f});
m_Listener.SetVelocity(m_Player->GetVelocity());
for (const auto& [playerID, player] : m_Client->GetGame()->GetPlayers()) {
auto it = m_PlayerSources.find(playerID);
if (it == m_PlayerSources.end()) {
utils::LOGD("[AudioManager] No sound found for player " + std::to_string(playerID) + " !");
continue;
}
Vec3f horizontalVelocity = {player.GetVelocity().x, 0.0f, player.GetVelocity().z};
PlayerSound& playerSounds = it->second;
if (player.GetPosition().y <= 0.1f && maths::Length(horizontalVelocity) > 0.02f) {
playerSounds.m_FootStep->SetPosition(player.GetPosition());
playerSounds.m_FootStep->SetVelocity(player.GetVelocity());
if (playerSounds.m_FootStep->GetSourceState() != AudioSource::ssPlaying)
playerSounds.m_FootStep->Play();
}
}
}
AudioSourcePtr AudioManager::InitSourceFromFile(const std::string& fileName) {
@@ -56,6 +75,8 @@ void AudioManager::InitSounds() {
m_EndMusic = InitSourceFromFile("sounds/jazz.wav");
m_DeathSound = InitBufferFromFile("sounds/fart.wav");
m_FootStepSound = InitBufferFromFile("sounds/step.wav");
m_LaserSound = InitBufferFromFile("sounds/laser.wav");
}
@@ -64,6 +85,22 @@ void AudioManager::OnGameJoin() {
m_Client->GetGame()->BindListener(this);
}
void AudioManager::OnPlayerDeath(game::PlayerID playerID) {
auto it = m_PlayerSources.find(playerID);
if (it == m_PlayerSources.end()) {
utils::LOGD("[AudioManager] No sound found for player " + std::to_string(playerID) + " !");
return;
}
game::Player* player = m_Client->GetGame()->GetPlayerById(playerID);
assert(player);
PlayerSound& playerSounds = it->second;
playerSounds.m_Death->SetPosition(player->GetPosition());
playerSounds.m_Death->Play();
}
void AudioManager::OnGameLeave() {
m_MenuMusic->Play();
m_EndMusic->Stop();
@@ -73,7 +110,7 @@ void AudioManager::OnGameLeave() {
}
void AudioManager::OnGameStateUpdate(game::GameState gameState) {
if(gameState == game::gsEnd)
if (gameState == game::gsEnd)
m_EndMusic->Play();
}
@@ -82,7 +119,8 @@ void AudioManager::OnClientPlayerJoin() {
}
void AudioManager::OnPlayerJoin(game::PlayerID player) {
m_PlayerSources.insert({player, PlayerSound{InitSourceFromBuffer(m_LaserSound)}});
m_PlayerSources.insert({player,
PlayerSound{InitSourceFromBuffer(m_LaserSound), InitSourceFromBuffer(m_FootStepSound), InitSourceFromBuffer(m_DeathSound)}});
}
void AudioManager::OnPlayerLeave(game::PlayerID player) {

View File

@@ -3,6 +3,7 @@
#include "blitz/misc/Log.h"
#include "blitz/misc/Random.h"
#include "blitz/protocol/PacketDispatcher.h"
#include "blitz/protocol/packets/PlayerDeathPacket.h"
#include "blitz/protocol/packets/PlayerJoinPacket.h"
#include "blitz/protocol/packets/PlayerLeavePacket.h"
#include "blitz/protocol/packets/PlayerListPacket.h"
@@ -12,18 +13,18 @@
#include "blitz/protocol/packets/ServerConfigPacket.h"
#include "blitz/protocol/packets/UpdateGameStatePacket.h"
#include "blitz/protocol/packets/UpdateHealthPacket.h"
#include "client/Client.h"
#include "client/BaseClient.h"
namespace blitz {
namespace client {
ClientGame::ClientGame(Client* client, protocol::PacketDispatcher* dispatcher) :
ClientGame::ClientGame(BaseClient& client, protocol::PacketDispatcher& dispatcher) :
protocol::PacketHandler(dispatcher), m_Client(client) {
RegisterHandlers();
}
ClientGame::~ClientGame() {
GetDispatcher()->UnregisterHandler(this);
GetDispatcher().UnregisterHandler(*this);
}
void ClientGame::AddPlayer(game::PlayerID player, const std::string& name) {
@@ -36,91 +37,100 @@ void ClientGame::RemovePlayer(game::PlayerID player) {
}
void ClientGame::RegisterHandlers() {
GetDispatcher()->RegisterHandler(protocol::PacketType::PlayerJoin, this);
GetDispatcher()->RegisterHandler(protocol::PacketType::PlayerLeave, this);
GetDispatcher()->RegisterHandler(protocol::PacketType::PlayerList, this);
GetDispatcher()->RegisterHandler(protocol::PacketType::PlayerPositionAndRotation, this);
GetDispatcher()->RegisterHandler(protocol::PacketType::PlayerShoot, this);
GetDispatcher()->RegisterHandler(protocol::PacketType::PlayerStats, this);
GetDispatcher()->RegisterHandler(protocol::PacketType::UpdateGameState, this);
GetDispatcher()->RegisterHandler(protocol::PacketType::UpdateHealth, this);
GetDispatcher()->RegisterHandler(protocol::PacketType::ServerConfig, this);
GetDispatcher().RegisterHandler(protocol::PacketType::PlayerDeath, *this);
GetDispatcher().RegisterHandler(protocol::PacketType::PlayerJoin, *this);
GetDispatcher().RegisterHandler(protocol::PacketType::PlayerLeave, *this);
GetDispatcher().RegisterHandler(protocol::PacketType::PlayerList, *this);
GetDispatcher().RegisterHandler(protocol::PacketType::PlayerPositionAndRotation, *this);
GetDispatcher().RegisterHandler(protocol::PacketType::PlayerShoot, *this);
GetDispatcher().RegisterHandler(protocol::PacketType::PlayerStats, *this);
GetDispatcher().RegisterHandler(protocol::PacketType::UpdateGameState, *this);
GetDispatcher().RegisterHandler(protocol::PacketType::UpdateHealth, *this);
GetDispatcher().RegisterHandler(protocol::PacketType::ServerConfig, *this);
}
void ClientGame::HandlePacket(const protocol::PlayerJoinPacket* packet) {
void ClientGame::HandlePacket(const protocol::PlayerDeathPacket& packet) {
NotifyListeners(&game::GameListener::OnPlayerDeath, packet.GetPlayerID());
}
if (packet->GetPlayerID() == m_Client->GetPlayerID()) {
m_Client->NotifyListeners(&game::ClientListener::OnGameJoin);
void ClientGame::HandlePacket(const protocol::PlayerJoinPacket& packet) {
if (packet.GetPlayerID() == m_Client.GetPlayerID()) {
m_Client.NotifyListeners(&client::ClientListener::OnGameJoin);
}
AddPlayer(packet->GetPlayerID(), packet->GetPlayerName());
AddPlayer(packet.GetPlayerID(), packet.GetPlayerName());
// Initialize camera
if (packet->GetPlayerID() == m_Client->GetPlayerID()) {
m_Client->NotifyListeners(&game::ClientListener::OnSpectatorChange, packet->GetPlayerID());
m_Client->NotifyListeners(&game::ClientListener::OnClientPlayerJoin);
if (packet.GetPlayerID() == m_Client.GetPlayerID()) {
m_Client.NotifyListeners(&client::ClientListener::OnSpectatorChange, packet.GetPlayerID());
m_Client.NotifyListeners(&client::ClientListener::OnClientPlayerJoin);
}
}
void ClientGame::HandlePacket(const protocol::PlayerLeavePacket* packet) {
RemovePlayer(packet->GetPlayerID());
void ClientGame::HandlePacket(const protocol::PlayerLeavePacket& packet) {
RemovePlayer(packet.GetPlayerID());
}
void ClientGame::HandlePacket(const protocol::PlayerListPacket* packet) {
for (const auto& [playerID, playerInfo] : packet->GetPlayers()) {
AddPlayer(playerID, playerInfo.name);
void ClientGame::HandlePacket(const protocol::PlayerListPacket& packet) {
for (const auto& [playerID, playerInfo] : packet.GetPlayers()) {
AddPlayer(playerID, playerInfo.m_Name);
}
}
void ClientGame::HandlePacket(const protocol::PlayerStatsPacket* packet) {
game::Player* player = m_Client->GetGame()->GetPlayerById(packet->GetPlayerID());
void ClientGame::HandlePacket(const protocol::PlayerStatsPacket& packet) {
game::Player* player = m_Client.GetGame()->GetPlayerById(packet.GetPlayerID());
if (!player)
return;
player->GetStats() = packet->GetPlayerStats();
player->GetStats() = packet.GetPlayerStats();
m_LeaderBoard.Update();
}
void ClientGame::HandlePacket(const protocol::UpdateHealthPacket* packet) {
game::Player* player = m_Client->GetGame()->GetPlayerById(m_Client->GetPlayerID());
player->SetHP(packet->GetNewHealth());
void ClientGame::HandlePacket(const protocol::UpdateHealthPacket& packet) {
game::Player* player = m_Client.GetGame()->GetPlayerById(m_Client.GetPlayerID());
player->SetHP(packet.GetNewHealth());
// we are dead
if (player->GetHP() <= 0.0f) {
NotifyListeners(&game::GameListener::OnPlayerDeath, player->GetID());
player->SetPosition({utils::GetRandomReal(-10.0f, 10.0f), 0, utils::GetRandomReal(-10.0f, 10.0f)});
}
}
void ClientGame::HandlePacket(const protocol::UpdateGameStatePacket* packet) {
Game::UpdateGameState(packet->GetGameState(), packet->GetTimeRemaining());
void ClientGame::HandlePacket(const protocol::UpdateGameStatePacket& packet) {
Game::UpdateGameState(packet.GetGameState(), packet.GetTimeRemaining());
}
void ClientGame::HandlePacket(const protocol::ServerConfigPacket* packet) {
m_Config = packet->GetGameConfig();
m_Client->NotifyListeners(&game::ClientListener::OnGameConfigUpdate);
void ClientGame::HandlePacket(const protocol::ServerConfigPacket& packet) {
m_Config = packet.GetGameConfig();
m_Client.NotifyListeners(&client::ClientListener::OnGameConfigUpdate);
}
void ClientGame::HandlePacket(const protocol::PlayerShootPacket* packet) {
m_Client->NotifyListeners(
&game::ClientListener::OnPlayerShoot, packet->GetPlayer(), packet->GetPosition(), packet->GetYaw(), packet->GetPitch());
void ClientGame::HandlePacket(const protocol::PlayerShootPacket& packet) {
m_Client.NotifyListeners(
&client::ClientListener::OnPlayerShoot, packet.GetPlayer(), packet.GetPosition(), packet.GetYaw(), packet.GetPitch());
}
void ClientGame::HandlePacket(const protocol::PlayerPositionAndRotationPacket* packet) {
if (packet->GetPlayer() == m_Client->GetPlayerID())
void ClientGame::HandlePacket(const protocol::PlayerPositionAndRotationPacket& packet) {
if (packet.GetPlayer() == m_Client.GetPlayerID())
return;
game::Player* player = GetPlayerById(packet->GetPlayer());
game::Player* player = GetPlayerById(packet.GetPlayer());
if (!player)
return;
player->SetVelocity(packet->GetPosition() - player->GetPosition());
player->SetYaw(packet->GetYaw());
player->SetPitch(packet->GetPitch());
player->SetVelocity(packet.GetPosition() - player->GetPosition());
player->SetYaw(packet.GetYaw());
player->SetPitch(packet.GetPitch());
}
void ClientGame::Tick(std::uint64_t delta) {
for (auto& [playerId, player] : GetPlayers()) {
// already handled by PlayerController
if (playerId == m_Client.GetPlayerID())
continue;
player.SetPosition(player.GetPosition() + player.GetVelocity() * (static_cast<float>(delta) / 100.0f));
}
if (m_GameTimer.GetInterval() > 0) {

View File

@@ -11,7 +11,7 @@
namespace blitz {
namespace gui {
BlitzGui::BlitzGui(Client* client, input::InputManager& inputManager) : GuiWidget(nullptr, client) {
BlitzGui::BlitzGui(client::Client* client, input::InputManager& inputManager) : GuiWidget(nullptr, client) {
Enable();
AddWidget(std::make_unique<GameChatGui>(this, client, inputManager));
AddWidget(std::make_unique<MainMenu>(client, inputManager));

View File

@@ -12,7 +12,7 @@ void RenderColorfulText(const protocol::ColoredText& parts, float alpha) {
const bool need_backup = (g.CurrentWindow->DC.TextWrapPos < 0.0f); // Keep existing wrap position if one is already set
if (need_backup)
ImGui::PushTextWrapPos(0.0f);
ImGui::TextColored({part.color.r, part.color.g, part.color.b, alpha}, "%s", part.text.c_str());
ImGui::TextColored({part.m_Color.r, part.m_Color.g, part.m_Color.b, alpha}, "%s", part.m_Text.c_str());
if (need_backup)
ImGui::PopTextWrapPos();
ImGui::SameLine();

View File

@@ -10,7 +10,7 @@
namespace blitz {
namespace gui {
CreateGameMenu::CreateGameMenu(GuiWidget* parent, Client* client, input::InputManager& inputManager) :
CreateGameMenu::CreateGameMenu(GuiWidget* parent, client::Client* client, input::InputManager& inputManager) :
GuiWidget(parent, client), m_InputManager(inputManager) {}
void CreateGameMenu::Render() {

View File

@@ -7,7 +7,7 @@
namespace blitz {
namespace gui {
CrossHair::CrossHair(Client* client) : GuiWidget(nullptr, client) {
CrossHair::CrossHair(client::Client* client) : GuiWidget(nullptr, client) {
m_CrossHairTexture = TextureLoader::LoadGLTexture("textures/crosshair.png");
}

View File

@@ -3,7 +3,7 @@
#include "blitz/misc/Easing.h"
#include "blitz/misc/Format.h"
#include "blitz/misc/Log.h"
#include "client/display/InputManager.h"
#include "client/input/InputManager.h"
#include "client/gui/ColorFulText.h"
#include "client/gui/GuiWidget.h"
#include <client/Client.h>
@@ -15,7 +15,7 @@ namespace gui {
static const float ChatFadeTime = 2.0f;
GameChatGui::GameChatGui(GuiWidget* parent, Client* client, input::InputManager& inputManager) :
GameChatGui::GameChatGui(GuiWidget* parent, client::Client* client, input::InputManager& inputManager) :
GuiWidget(parent, client), m_InputManager(inputManager) {
m_Client->BindListener(this);
InputBuf[0] = '\0';

View File

@@ -10,9 +10,26 @@
namespace blitz {
namespace gui {
Hud::Hud(GuiWidget* parent, Client* client) : GuiWidget(parent, client) {
Hud::Hud(GuiWidget* parent, client::Client* client) : GuiWidget(parent, client) {
m_GunTexture = TextureLoader::LoadGLTexture("textures/fingergun.png");
m_JPTexture = TextureLoader::LoadGLTexture("textures/jp.png");
m_Client->BindListener(this);
}
Hud::~Hud() {
m_Client->UnbindListener(this);
}
void Hud::OnGameStateUpdate(game::GameState gameState) {
m_Timer.Reset();
}
void Hud::OnGameJoin() {
m_Client->GetGame()->BindListener(this);
}
void Hud::OnGameLeave() {
m_Client->GetGame()->UnbindListener(this);
}
void Hud::Draw(const char* title, bool* p_open) {
@@ -148,9 +165,11 @@ void Hud::Render() {
switch (m_Client->GetGame()->GetGameState()) {
case game::GameState::gsEnd: {
game::Player* firstPlayer = m_Client->GetGame()->GetLeaderBoard().GetPlayers().front();
if (!firstPlayer)
const auto& players = m_Client->GetGame()->GetLeaderBoard().GetPlayers();
if (players.empty())
return;
game::Player* firstPlayer = players.front();
DrawFinishScreen(firstPlayer->GetID() == m_Client->GetPlayerID());
break;
}

View File

@@ -3,14 +3,14 @@
#include "blitz/misc/Format.h"
#include "blitz/misc/Log.h"
#include "client/Client.h"
#include "client/display/InputManager.h"
#include "client/input/InputManager.h"
#include <imgui.h>
#include <string>
namespace blitz {
namespace gui {
JoinGameMenu::JoinGameMenu(GuiWidget* parent, Client* client, input::InputManager& inputManager) :
JoinGameMenu::JoinGameMenu(GuiWidget* parent, client::Client* client, input::InputManager& inputManager) :
GuiWidget(parent, client), m_InputManager(inputManager) {}
void JoinGameMenu::Render() {

View File

@@ -10,9 +10,20 @@
namespace blitz {
namespace gui {
LeaderBoardGui::LeaderBoardGui(GuiWidget* parent, Client* client) : GuiWidget(parent, client) {}
LeaderBoardGui::LeaderBoardGui(GuiWidget* parent, client::Client* client) : GuiWidget(parent, client) {
m_Client->BindListener(this);
}
LeaderBoardGui::~LeaderBoardGui() {}
void LeaderBoardGui::OnGameJoin() {
m_Client->GetGame()->BindListener(this);
}
void LeaderBoardGui::OnGameLeave() {
m_Client->GetGame()->UnbindListener(this);
}
LeaderBoardGui::~LeaderBoardGui() {
m_Client->UnbindListener(this);
}
void LeaderBoardGui::Draw(const char* title, bool* p_open) {
static float leaderboard_width = 800.0f;
@@ -62,6 +73,10 @@ void LeaderBoardGui::Draw(const char* title, bool* p_open) {
ImGui::End();
}
void LeaderBoardGui::OnGameStateUpdate(game::GameState gameState) {
m_Timer.Reset();
}
void LeaderBoardGui::Render() {
if (!m_Client->IsConnected())
return;
@@ -74,8 +89,6 @@ void LeaderBoardGui::Render() {
if (m_Timer.Update(ImGui::GetIO().DeltaTime)) {
Draw("Leaderboard", nullptr);
}
} else {
m_Timer.Reset();
}
}

View File

@@ -9,7 +9,7 @@
namespace blitz {
namespace gui {
MainMenu::MainMenu(Client* client, input::InputManager& inputManager) : GuiWidget(nullptr, client), m_InputManager(inputManager) {
MainMenu::MainMenu(client::Client* client, input::InputManager& inputManager) : GuiWidget(nullptr, client), m_InputManager(inputManager) {
Enable();
AddWidget(std::make_unique<CreateGameMenu>(this, client, inputManager));
AddWidget(std::make_unique<JoinGameMenu>(this, client, inputManager));

View File

@@ -3,15 +3,15 @@
#include "blitz/misc/Format.h"
#include "blitz/misc/Log.h"
#include "client/Client.h"
#include "client/display/InputManager.h"
#include "client/gui/FPSMenu.h"
#include "client/input/InputManager.h"
#include <SDL2/SDL.h>
#include <imgui.h>
namespace blitz {
namespace gui {
static std::string ActionNames[kaMax] = {
static std::string ActionNames[input::kaMax] = {
"Avancer",
"Reculer",
"Droite",
@@ -23,7 +23,7 @@ static std::string ActionNames[kaMax] = {
static std::string GetActionName(KeyAction action) {
static std::string GetActionName(input::KeyAction action) {
return ActionNames[action];
}
@@ -42,7 +42,7 @@ static std::string GetImGuiKeyName(int key) {
OptionsMenu::OptionsMenu(GuiWidget* parent, Client* client, input::InputManager& inputManager) :
OptionsMenu::OptionsMenu(GuiWidget* parent, client::Client* client, input::InputManager& inputManager) :
GuiWidget(parent, client), m_IsKeyPopupOpen(false), m_KeyPopupShouldClose(false), m_InputManager(inputManager) {
AddWidget(std::make_unique<FPSMenu>(this, client));
@@ -69,13 +69,13 @@ OptionsMenu::~OptionsMenu() {
void OptionsMenu::HotkeyBindingButton() {
for (std::size_t i = 0; i < m_Client->GetConfig()->GetKeys().size(); i++) {
if (ImGui::Button(utils::Format("%s##%i", GetKeyActionCodeName(KeyAction(i)).c_str(), i).c_str())) {
if (ImGui::Button(utils::Format("%s##%i", GetKeyActionCodeName(input::KeyAction(i)).c_str(), i).c_str())) {
m_IsKeyPopupOpen = true;
m_CurrentAction = KeyAction(i);
m_CurrentAction = input::KeyAction(i);
ImGui::OpenPopup("Changer de touche");
}
ImGui::SameLine();
ImGui::Text("%s", GetActionName(KeyAction(i)).c_str());
ImGui::Text("%s", GetActionName(input::KeyAction(i)).c_str());
}
}
@@ -135,7 +135,7 @@ void OptionsMenu::OnKeyDown(int key) {
std::string OptionsMenu::GetKeyActionCodeName(KeyAction act) {
std::string OptionsMenu::GetKeyActionCodeName(input::KeyAction act) {
return GetImGuiKeyName(static_cast<int>(m_Client->GetConfig()->GetKeys()[act]));
}

View File

@@ -1,8 +1,8 @@
#include "client/gui/ServerGui.h"
#include "client/Client.h"
#include "client/display/InputManager.h"
#include "client/game/ClientGame.h"
#include "client/input/InputManager.h"
#include "server/Server.h"
#include "server/game/ServerGame.h"
#include <imgui.h>
@@ -10,7 +10,7 @@
namespace blitz {
namespace gui {
ServerGui::ServerGui(GuiWidget* parent, Client* client, input::InputManager& inputManager) :
ServerGui::ServerGui(GuiWidget* parent, client::Client* client, input::InputManager& inputManager) :
GuiWidget(parent, client), m_InputManager(inputManager) {}
void ServerGui::Render() {
@@ -18,7 +18,7 @@ void ServerGui::Render() {
return;
Keybinds keys = m_Client->GetConfig()->GetKeys();
if (ImGui::IsKeyPressed(ImGuiKey(keys[kaFenetreAdmin])) && m_InputManager.MouseGrabbed()) {
if (ImGui::IsKeyPressed(ImGuiKey(keys[input::kaFenetreAdmin])) && m_InputManager.MouseGrabbed()) {
ImGui::OpenPopup("FENETRE D'ADMIN");
}

View File

@@ -1,6 +1,6 @@
#include "client/display/Display.h"
#include "client/input/Display.h"
#include "client/display/InputManager.h"
#include "client/input/InputManager.h"
#include "client/render/OpenGL.h"
#include <SDL2/SDL.h>
#include <backends/imgui_impl_opengl3.h>
@@ -19,8 +19,9 @@
#endif
namespace blitz {
namespace input {
Display::Display(int width, int height, const std::string& windowName, Client* client, input::InputManager& inputManager) :
Display::Display(int width, int height, const std::string& windowName, client::Client* client, input::InputManager& inputManager) :
m_WindowWidth(width),
m_WindowHeight(height),
m_AspectRatio(m_WindowHeight / static_cast<float>(m_WindowWidth)),
@@ -236,4 +237,5 @@ void Display::InitImGui() {
m_BlitzGui = std::make_unique<gui::BlitzGui>(m_Client, m_InputManager);
}
} // namespace input
} // namespace blitz

View File

@@ -1,4 +1,4 @@
#include "client/display/InputManager.h"
#include "client/input/InputManager.h"
#include "imgui.h"
#include <vector>

View File

@@ -1,12 +1,12 @@
#include "client/display/PlayerController.h"
#include "client/input/PlayerController.h"
#include "blitz/game/Player.h"
#include "blitz/maths/Maths.h"
#include "blitz/misc/Log.h"
#include "client/Client.h"
#include "client/config/BlitzConfig.h"
#include "client/display/InputManager.h"
#include "client/game/ClientGame.h"
#include "client/input/InputManager.h"
#include "imgui.h"
#include <algorithm>
#include <iostream>
@@ -20,7 +20,7 @@ static constexpr float DEFAULT_MAX_FB_SPEED = 10.;
static constexpr float DEFAULT_LR_SPEED_SMOOTHING_TIME = 1.0;
static constexpr float DEFAULT_FB_SPEED_SMOOTHING_TIME = 1.0;
PlayerController::PlayerController(Client* client, input::InputManager& inputManager) :
PlayerController::PlayerController(client::Client* client, input::InputManager& inputManager) :
m_Player(nullptr),
m_Client(client),
m_InputManager(inputManager),
@@ -87,13 +87,13 @@ void PlayerController::Update(float delta) {
if (ImGui::IsKeyDown(ImGuiKey::ImGuiKey_Space) && m_OnGround) {
m_Velocity.z = m_MaxVelocity.z;
NotifyListeners(&game::PlayerInputListener::OnLocalPlayerJump);
NotifyListeners(&client::PlayerInputListener::OnLocalPlayerJump);
}
bool canShoot = m_ShootTimer.Update(ImGui::GetIO().DeltaTime);
if (ImGui::IsMouseDown(ImGuiMouseButton_Left) && canShoot) {
NotifyListeners(
&game::PlayerInputListener::OnLocalPlayerShoot, m_Player->GetPosition(), m_Player->GetYaw(), m_Player->GetPitch());
&client::PlayerInputListener::OnLocalPlayerShoot, m_Player->GetPosition(), m_Player->GetYaw(), m_Player->GetPitch());
m_ShootTimer.ApplyCooldown();
}
} else {
@@ -132,6 +132,7 @@ void PlayerController::UpdatePosition(const float delta) {
}
m_Player->AddPosition({dx, dz, dy});
m_Player->SetVelocity({dx, dz, dy});
}
} // namespace input

View File

@@ -24,7 +24,7 @@ namespace render {
static const Vec4f SkyColor = {0.6f, 0.8f, 1.0f, 1.0f};
static const Vec4f MenuColor = {0.0f, 0.0f, 0.0f, 0.0f};
MainRenderer::MainRenderer(Client* client, input::PlayerController& playerController) :
MainRenderer::MainRenderer(client::Client* client, input::PlayerController& playerController) :
m_Client(client), m_ShootTime(0), m_BulletRenderer(m_Camera), m_PlayerController(playerController) {
LoadModels();

View File

@@ -14,7 +14,7 @@
namespace blitz {
namespace server {
Server::Server() : m_TickCounter(SERVER_TPS), m_Game(this), m_ServerRunning(false), m_FreePlayerID(0) {}
Server::Server() : m_TickCounter(SERVER_TPS), m_Game(*this), m_ServerRunning(false), m_FreePlayerID(0) {}
Server::~Server() {
Stop();
@@ -104,7 +104,7 @@ void Server::Accept() {
network::TCPSocket newSocket;
if (m_Listener.Accept(newSocket)) {
game::PlayerID newPlayerID = GetNewPlayerID();
auto con = std::make_unique<ServerConnexion>(this, newSocket, newPlayerID);
auto con = std::make_unique<ServerConnexion>(*this, newSocket, newPlayerID);
m_Connections.insert(ConnexionMap::value_type{newPlayerID, std::move(con)});
m_Connections[newPlayerID]->Init();
newPlayerID++;

View File

@@ -28,8 +28,8 @@ namespace blitz {
namespace server {
ServerConnexion::ServerConnexion(Server* server, network::TCPSocket& socket, std::uint8_t id) :
Connexion::Connexion(&m_Dispatcher, socket), m_Server(server), m_ID(id), m_Player(nullptr) {
ServerConnexion::ServerConnexion(Server& server, network::TCPSocket& socket, std::uint8_t id) :
Connexion::Connexion(m_Dispatcher, socket), m_Server(server), m_ID(id), m_Player(nullptr) {
RegisterHandlers();
}
@@ -39,18 +39,16 @@ ServerConnexion::ServerConnexion(ServerConnexion&& move) :
m_ID(move.m_ID),
m_KeepAlive(move.m_KeepAlive),
m_Player(move.m_Player) {
move.m_Server = nullptr;
RegisterHandlers();
}
void ServerConnexion::RegisterHandlers() {
GetDispatcher()->RegisterHandler(protocol::PacketType::Disconnect, this);
GetDispatcher()->RegisterHandler(protocol::PacketType::KeepAlive, this);
GetDispatcher()->RegisterHandler(protocol::PacketType::PlayerLogin, this);
GetDispatcher()->RegisterHandler(protocol::PacketType::Chat, this);
GetDispatcher()->RegisterHandler(protocol::PacketType::PlayerShoot, this);
GetDispatcher()->RegisterHandler(protocol::PacketType::PlayerPositionAndRotation, this);
GetDispatcher().RegisterHandler(protocol::PacketType::Disconnect, *this);
GetDispatcher().RegisterHandler(protocol::PacketType::KeepAlive, *this);
GetDispatcher().RegisterHandler(protocol::PacketType::PlayerLogin, *this);
GetDispatcher().RegisterHandler(protocol::PacketType::Chat, *this);
GetDispatcher().RegisterHandler(protocol::PacketType::PlayerShoot, *this);
GetDispatcher().RegisterHandler(protocol::PacketType::PlayerPositionAndRotation, *this);
}
bool ServerConnexion::UpdateSocket() {
@@ -93,10 +91,10 @@ void ServerConnexion::InitPlayerChatColor() {
m_ChatColor = protocol::ChatPacket::GetTextColor({red, green, blue});
}
void ServerConnexion::HandlePacket(const protocol::PlayerLoginPacket* packet) {
m_Server->GetGame().AddPlayer(m_ID, packet->GetPlayerName());
void ServerConnexion::HandlePacket(const protocol::PlayerLoginPacket& packet) {
m_Server.GetGame().AddPlayer(m_ID, packet.GetPlayerName());
m_Player = m_Server->GetGame().GetPlayerById(m_ID);
m_Player = m_Server.GetGame().GetPlayerById(m_ID);
SendPlayers();
SendGameState();
@@ -105,40 +103,40 @@ void ServerConnexion::HandlePacket(const protocol::PlayerLoginPacket* packet) {
InitPlayerChatColor();
}
void ServerConnexion::HandlePacket(const protocol::KeepAlivePacket* packet) {
if (packet->GetAliveID() != m_KeepAlive.KeepAliveID)
void ServerConnexion::HandlePacket(const protocol::KeepAlivePacket& packet) {
if (packet.GetAliveID() != m_KeepAlive.KeepAliveID)
return;
m_KeepAlive.RecievedResponse = true;
}
void ServerConnexion::HandlePacket(const protocol::DisconnectPacket* packet) {
void ServerConnexion::HandlePacket(const protocol::DisconnectPacket& packet) {
CloseConnection();
}
void ServerConnexion::HandlePacket(const protocol::ChatPacket* packet) {
void ServerConnexion::HandlePacket(const protocol::ChatPacket& packet) {
if (!m_Player)
return;
m_Server->BroadcastChatMessage(utils::Format("<%s%s%s> %s", m_ChatColor.c_str(), m_Player->GetName().c_str(),
m_Server.BroadcastChatMessage(utils::Format("<%s%s%s> %s", m_ChatColor.c_str(), m_Player->GetName().c_str(),
protocol::ChatPacket::GetTextColor(protocol::WHITE).c_str(),
protocol::ChatPacket::GetColoredTextString(packet->GetMessage()).c_str()));
protocol::ChatPacket::GetColoredTextString(packet.GetMessage()).c_str()));
}
void ServerConnexion::HandlePacket(const protocol::PlayerPositionAndRotationPacket* packet) {
void ServerConnexion::HandlePacket(const protocol::PlayerPositionAndRotationPacket& packet) {
if (!m_Player)
return;
m_Player->SetPosition(packet->GetPosition());
m_Player->SetYaw(packet->GetYaw());
m_Player->SetPitch(packet->GetPitch());
m_Player->SetPosition(packet.GetPosition());
m_Player->SetYaw(packet.GetYaw());
m_Player->SetPitch(packet.GetPitch());
}
void ServerConnexion::HandlePacket(const protocol::PlayerShootPacket* packet) {
protocol::PlayerShootPacket broadcastShoot(packet->GetPosition(), packet->GetYaw(), packet->GetPitch(), m_Player->GetID());
m_Server->BroadcastPacket(&broadcastShoot);
void ServerConnexion::HandlePacket(const protocol::PlayerShootPacket& packet) {
protocol::PlayerShootPacket broadcastShoot(packet.GetPosition(), packet.GetYaw(), packet.GetPitch(), m_Player->GetID());
m_Server.BroadcastPacket(&broadcastShoot);
m_Server->GetGame().ProcessShoot(m_Player->GetID(), packet->GetPosition(), packet->GetYaw(), packet->GetPitch());
m_Server.GetGame().ProcessShoot(m_Player->GetID(), packet.GetPosition(), packet.GetYaw(), packet.GetPitch());
}
void ServerConnexion::Init() {
@@ -147,14 +145,14 @@ void ServerConnexion::Init() {
}
void ServerConnexion::SendGameState() {
protocol::UpdateGameStatePacket packet(m_Server->GetGame().GetGameState(), m_Server->GetGame().GetGameStateRemainingTime());
protocol::UpdateGameStatePacket packet(m_Server.GetGame().GetGameState(), m_Server.GetGame().GetGameStateRemainingTime());
SendPacket(&packet);
}
void ServerConnexion::SendPlayers() {
protocol::PlayerList list;
for (const auto& [playerID, player] : m_Server->GetGame().GetPlayers()) {
for (const auto& [playerID, player] : m_Server.GetGame().GetPlayers()) {
if (playerID == m_ID)
continue;
list.insert({playerID, {player.GetName()}});
@@ -165,7 +163,7 @@ void ServerConnexion::SendPlayers() {
}
void ServerConnexion::SendServerConfig() {
protocol::ServerConfigPacket packet(m_Server->GetGame().GetGameConfig());
protocol::ServerConfigPacket packet(m_Server.GetGame().GetGameConfig());
SendPacket(&packet);
}
@@ -175,12 +173,9 @@ void ServerConnexion::InitConnection() {
}
ServerConnexion::~ServerConnexion() {
if (GetDispatcher() == nullptr)
return;
GetDispatcher().UnregisterHandler(*this);
GetDispatcher()->UnregisterHandler(this);
m_Server->GetGame().RemovePlayer(m_ID);
m_Server.GetGame().RemovePlayer(m_ID);
}
} // namespace server

View File

@@ -5,6 +5,7 @@
#include "blitz/misc/Log.h"
#include "blitz/misc/Random.h"
#include "blitz/protocol/packets/ChatPacket.h"
#include "blitz/protocol/packets/PlayerDeathPacket.h"
#include "blitz/protocol/packets/PlayerJoinPacket.h"
#include "blitz/protocol/packets/PlayerLeavePacket.h"
#include "blitz/protocol/packets/PlayerPositionAndRotationPacket.h"
@@ -18,7 +19,7 @@
namespace blitz {
namespace server {
ServerGame::ServerGame(Server* server) : m_Server(server), m_PositionTimer(SERVER_TPS) {
ServerGame::ServerGame(Server& server) : m_Server(server), m_PositionTimer(SERVER_TPS) {
CancelGame();
InitGameConfig();
}
@@ -27,7 +28,7 @@ ServerGame::~ServerGame() {}
void ServerGame::StartGame() {
UpdateGameState(game::gsPreparing, m_ServerDuration.m_PrepDuration);
m_Server->BroadcastChatMessage(protocol::ChatPacket::GetTextColor(protocol::AQUA) + "La partie commence dans 10s !");
m_Server.BroadcastChatMessage(protocol::ChatPacket::GetTextColor(protocol::AQUA) + "La partie commence dans 10s !");
}
void ServerGame::CancelGame() {
@@ -72,7 +73,7 @@ void ServerGame::Tick(std::uint64_t delta) {
void ServerGame::SendPlayerPositions() {
for (const auto& [playerID, player] : GetPlayers()) {
protocol::PlayerPositionAndRotationPacket packet(player.GetPosition(), player.GetYaw(), player.GetPitch(), playerID);
m_Server->BroadcastPacket(&packet);
m_Server.BroadcastPacket(&packet);
}
}
@@ -108,12 +109,12 @@ void ServerGame::AddPlayer(game::PlayerID player, const std::string& name) {
Game::AddPlayer(player, name);
protocol::PlayerJoinPacket joinPacket(player, name);
m_Server->BroadcastPacket(&joinPacket);
m_Server.BroadcastPacket(&joinPacket);
std::string joinMessage = utils::Format("%s a rejoint la partie !", name.c_str());
utils::LOG("[Server] " + joinMessage);
m_Server->BroadcastChatMessage(protocol::ChatPacket::GetTextColor(protocol::YELLOW) + joinMessage);
m_Server.BroadcastChatMessage(protocol::ChatPacket::GetTextColor(protocol::YELLOW) + joinMessage);
if (m_GameState == game::gsWaiting && m_Players.size() > 1) {
StartGame();
@@ -122,7 +123,7 @@ void ServerGame::AddPlayer(game::PlayerID player, const std::string& name) {
void ServerGame::RemovePlayer(game::PlayerID playerID) {
// we are closing the server, no need to broadcast any packets
if (!m_Server->IsRunning())
if (!m_Server.IsRunning())
return;
game::Player* player = GetPlayerById(playerID);
@@ -131,12 +132,12 @@ void ServerGame::RemovePlayer(game::PlayerID playerID) {
return;
protocol::PlayerLeavePacket packet(playerID);
m_Server->BroadcastPacket(&packet);
m_Server.BroadcastPacket(&packet);
std::string leaveMessage = utils::Format("%s a quitte la partie !", player->GetName().c_str());
utils::LOG("[Server] " + leaveMessage);
m_Server->BroadcastChatMessage(protocol::ChatPacket::GetTextColor(protocol::YELLOW) + leaveMessage);
m_Server.BroadcastChatMessage(protocol::ChatPacket::GetTextColor(protocol::YELLOW) + leaveMessage);
Game::RemovePlayer(playerID);
@@ -159,6 +160,11 @@ void ServerGame::DamagePlayer(game::Player& player, game::Player& shooter) {
player.SetPosition({utils::GetRandomReal(-10.0f, 10.0f), 0.0f, utils::GetRandomReal(-10.0f, 10.0f)});
UpdatePlayerStats();
NotifyListeners(&game::GameListener::OnPlayerDeath, player.GetID());
protocol::PlayerDeathPacket packet(player.GetID());
m_Server.BroadcastPacket(&packet);
}
}
@@ -170,15 +176,15 @@ void ServerGame::UpdateHP(game::Player& player, float newHP) {
protocol::UpdateHealthPacket packet(player.GetHP());
auto it = m_Server->GetConnexions().find(player.GetID());
if (it != m_Server->GetConnexions().end())
auto it = m_Server.GetConnexions().find(player.GetID());
if (it != m_Server.GetConnexions().end())
it->second->SendPacket(&packet);
}
void ServerGame::UpdatePlayerStats() {
for (auto& [playerId, player] : GetPlayers()) {
protocol::PlayerStatsPacket packet(playerId, player.GetStats());
m_Server->BroadcastPacket(&packet);
m_Server.BroadcastPacket(&packet);
}
}
@@ -197,12 +203,12 @@ void ServerGame::UpdateGameState(game::GameState gameState, std::uint64_t durati
}
protocol::UpdateGameStatePacket packet(gameState, duration);
m_Server->BroadcastPacket(&packet);
m_Server.BroadcastPacket(&packet);
}
void ServerGame::SendServerConfig() {
protocol::ServerConfigPacket packet(m_Config);
m_Server->BroadcastPacket(&packet);
m_Server.BroadcastPacket(&packet);
}