1 Commits

Author SHA1 Message Date
f092a3b70a rotate gun on jump 2024-01-27 18:35:33 +01:00
210 changed files with 69088 additions and 6744 deletions

View File

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

32
.github/workflows/macos.yml vendored Normal file
View File

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

42
.github/workflows/windows.yml vendored Normal file
View File

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

View File

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

7
.vscode/launch.json vendored
View File

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

View File

@@ -86,25 +86,3 @@ 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)

BIN
assets/base_deambu.glb Normal file

Binary file not shown.

View File

Before

Width:  |  Height:  |  Size: 298 KiB

After

Width:  |  Height:  |  Size: 298 KiB

Binary file not shown.

View File

@@ -1,797 +0,0 @@
# 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

Binary file not shown.

40
assets/player.obj Normal file
View File

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

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Before

Width:  |  Height:  |  Size: 6.1 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 218 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 78 KiB

37
assets/void_map.obj Normal file
View File

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

38
assets/void_map2.obj Normal file
View File

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

View File

@@ -1,9 +1,187 @@
#pragma once
#include <sp/common/DataBuffer.h>
/**
* \file DataBuffer.h
* \brief File containing the blitz::DataBuffer class
*/
#include <algorithm>
#include <cassert>
#include <cstring>
#include <string>
#include <vector>
namespace blitz {
using DataBuffer = sp::DataBuffer;
/**
* \class DataBuffer
* \brief Class used to manipulate memory
*/
class DataBuffer {
private:
typedef std::vector<std::uint8_t> Data;
Data m_Buffer;
std::size_t m_ReadOffset;
public:
typedef Data::iterator iterator;
typedef Data::const_iterator const_iterator;
typedef Data::reference reference;
typedef Data::const_reference const_reference;
typedef Data::difference_type difference_type;
DataBuffer();
DataBuffer(const DataBuffer& other);
DataBuffer(const DataBuffer& other, difference_type offset);
DataBuffer(DataBuffer&& other);
DataBuffer(const std::string& str);
DataBuffer& operator=(const DataBuffer& other);
DataBuffer& operator=(DataBuffer&& other);
template <typename T>
void Append(const T& data) {
std::size_t size = sizeof(data);
std::size_t end_pos = m_Buffer.size();
m_Buffer.resize(m_Buffer.size() + size);
memcpy(&m_Buffer[end_pos], &data, size);
}
template <typename T>
DataBuffer& operator<<(const T& data) {
Append(data);
return *this;
}
// don't use it for binary data !
DataBuffer& operator<<(const std::string& str) {
std::size_t strlen = str.length() + 1; // including null character
Resize(GetSize() + strlen);
std::memcpy(m_Buffer.data() + GetSize() - strlen, str.data(), strlen);
return *this;
}
DataBuffer& operator<<(DataBuffer& data) {
m_Buffer.insert(m_Buffer.end(), data.begin(), data.end());
return *this;
}
DataBuffer& operator<<(const DataBuffer& data) {
m_Buffer.insert(m_Buffer.end(), data.begin(), data.end());
return *this;
}
template <typename T>
DataBuffer& operator>>(T& data) {
assert(m_ReadOffset + sizeof(T) <= GetSize());
data = *(reinterpret_cast<T*>(&m_Buffer[m_ReadOffset]));
m_ReadOffset += sizeof(T);
return *this;
}
DataBuffer& operator>>(DataBuffer& data) {
data.Resize(GetSize() - m_ReadOffset);
std::copy(m_Buffer.begin() + static_cast<difference_type>(m_ReadOffset), m_Buffer.end(), data.begin());
m_ReadOffset = m_Buffer.size();
return *this;
}
// Don't use it for binary data !
DataBuffer& operator>>(std::string& str) {
std::size_t stringSize =
strlen(reinterpret_cast<const char*>(m_Buffer.data()) + m_ReadOffset) + 1; // including null character
str.resize(stringSize);
std::copy(m_Buffer.begin() + static_cast<difference_type>(m_ReadOffset),
m_Buffer.begin() + static_cast<difference_type>(m_ReadOffset + stringSize), str.begin());
m_ReadOffset += stringSize;
return *this;
}
void WriteSome(const char* buffer, std::size_t amount) {
std::size_t end_pos = m_Buffer.size();
m_Buffer.resize(m_Buffer.size() + amount);
memcpy(m_Buffer.data() + end_pos, buffer, amount);
}
void WriteSome(const std::uint8_t* buffer, std::size_t amount) {
std::size_t end_pos = m_Buffer.size();
m_Buffer.resize(m_Buffer.size() + amount);
memcpy(m_Buffer.data() + end_pos, buffer, amount);
}
void ReadSome(char* buffer, std::size_t amount) {
assert(m_ReadOffset + amount <= GetSize());
std::copy_n(m_Buffer.begin() + static_cast<difference_type>(m_ReadOffset), amount, buffer);
m_ReadOffset += amount;
}
void ReadSome(std::uint8_t* buffer, std::size_t amount) {
assert(m_ReadOffset + amount <= GetSize());
std::copy_n(m_Buffer.begin() + static_cast<difference_type>(m_ReadOffset), amount, buffer);
m_ReadOffset += amount;
}
void ReadSome(DataBuffer& buffer, std::size_t amount) {
assert(m_ReadOffset + amount <= GetSize());
buffer.Resize(amount);
std::copy_n(m_Buffer.begin() + static_cast<difference_type>(m_ReadOffset), amount, buffer.begin());
m_ReadOffset += amount;
}
void Resize(std::size_t size) {
m_Buffer.resize(size);
}
void Reserve(std::size_t amount) {
m_Buffer.reserve(amount);
}
void erase(iterator it) {
m_Buffer.erase(it);
}
void Clear() {
m_Buffer.clear();
m_ReadOffset = 0;
}
bool IsFinished() const {
return m_ReadOffset >= m_Buffer.size();
}
std::uint8_t* data() {
return m_Buffer.data();
}
const std::uint8_t* data() const {
return m_Buffer.data();
}
std::size_t GetReadOffset() const {
return m_ReadOffset;
}
void SetReadOffset(std::size_t pos);
std::size_t GetSize() const;
std::size_t GetRemaining() const;
iterator begin();
iterator end();
const_iterator begin() const;
const_iterator end() const;
bool ReadFile(const std::string& fileName);
bool WriteFile(const std::string& fileName);
// Don't forget to free the data !
std::uint8_t* HeapAllocatedData() const {
std::uint8_t* newBuffer = new std::uint8_t[GetSize()];
std::memcpy(newBuffer, data(), GetSize());
return newBuffer;
}
};
std::ostream& operator<<(std::ostream& os, const DataBuffer& buffer);
} // namespace blitz

View File

@@ -3,10 +3,9 @@
/**
* \file Defines.h
* \brief File containing constants and typedefs
*/
*/
#include <cstdint>
#include <sp/protocol/MessagePrinter.h>
namespace blitz {
namespace game {
@@ -14,27 +13,8 @@ namespace game {
/**
* \typedef PlayerID
* \brief Represents the identifier of a Player
*/
*/
typedef std::uint8_t PlayerID;
/**
* \enum GameState
* \brief The states of the game
*/
enum GameState : std::uint8_t {
gsNone = 0, /**< Default state */
gsWaiting, /**< Waiting state if the number of players is less than 2 */
gsPreparing, /**< Preparing state until the game start */
gsGame, /**< Game state during the players can shoot and kill ... */
gsEnd, /**< End state of the game : show the winner of the game and the leaderboard*/
};
} // namespace game
} // namespace blitz
namespace sp {
template <>
inline std::string PrintData(const blitz::game::GameState& a_State) {
return PrintData(static_cast<unsigned>(a_State));
}
} // namespace sp

View File

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

View File

@@ -0,0 +1,28 @@
#pragma once
#include <cstddef>
#include <cstdint>
namespace blitz {
class DataBuffer;
class VarInt {
private:
std::uint64_t m_Value;
public:
VarInt() : m_Value(0) {}
VarInt(std::uint64_t value) : m_Value(value) {}
std::uint64_t GetValue() const {
return m_Value;
}
std::size_t GetSerializedLength() const;
friend DataBuffer& operator<<(DataBuffer& out, const VarInt& var);
friend DataBuffer& operator>>(DataBuffer& in, VarInt& var);
};
} // namespace blitz

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

137
include/blitz/misc/Maths.h Normal file
View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@@ -8,59 +8,75 @@
#include "TCPSocket.h"
#include "blitz/protocol/PacketDispatcher.h"
#include "blitz/protocol/PacketHandler.h"
#include "blitz/protocol/PacketFactory.h"
namespace blitz {
namespace network {
using TCPStream = sp::io::Stream<sp::io::TcpTag, protocol::PacketDispatcher, protocol::PacketFactory, sp::option::ZlibCompress>;
/**
* \class Connexion
* \brief Represents a network connexion
*/
class Connexion : public protocol::PacketHandler, public TCPStream {
class Connexion : public protocol::PacketHandler {
protected:
protocol::PacketDispatcher m_Dispatcher;
private:
TCPSocket m_Socket;
public:
/**
/**
* \brief Constructs with an empty socket
*/
Connexion() {}
Connexion(protocol::PacketDispatcher* dispatcher);
/**
* \brief Constructs with an already connected socket
*/
Connexion(TCPSocket&& socket);
Connexion(protocol::PacketDispatcher* dispatcher, TCPSocket& socket);
/**
* \brief Move constructor
*/
Connexion(Connexion&& move);
/**
* \brief Default destructor
*/
virtual ~Connexion();
/**
* \brief Reads socket and process a Packet, if any
*/
virtual bool UpdateSocket();
/**
* \brief Closes the connexion
*/
*/
void CloseConnection();
/**
* \brief Returns the TCPSocket::Status of the internal socket
*/
TCPSocket::Status GetSocketStatus() const {
return m_Interface.GetStatus();
}
virtual bool UpdateSocket();
* \brief Tries to connect the socket at the specified address and port
* \return Wether this action was succesfull
*/
virtual bool Connect(const std::string& address, std::uint16_t port);
/**
* \brief Tries to connect the socket at the specified address and port
* \return Whether this action was succesfull
*/
bool Connect(const std::string& address, std::uint16_t port);
* \brief Returns the TCPSocket::Status of the internal socket
*/
TCPSocket::Status GetSocketStatus() const {
return m_Socket.GetStatus();
}
/**
* \brief Sends the protocol::Packet over the network to the remote
* \param packet The protocol::Packet to send
*/
void SendPacket(const protocol::Packet& packet);
*/
void SendPacket(const protocol::Packet* packet);
/**
* \brief Disables Connexion copy
*/
REMOVE_COPY(Connexion);
};
} // namespace network

View File

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

View File

@@ -10,7 +10,81 @@
namespace blitz {
namespace network {
using TCPListener = sp::io::TcpListener;
/**
* \class TCPListener
* \brief Cross platform abstraction of a TCP socket server
*/
class TCPListener {
private:
SocketHandle m_Handle;
std::uint16_t m_Port;
int m_MaxConnections;
public:
/**
* \brief Default constructor
*/
TCPListener();
/**
* \brief Default destructor
*/
~TCPListener();
/**
* \brief Starts listening for guests to connect
* \param port The port to listen to
* \param maxConnexions The maximum amount of connexion that can happen at the same time. \n
* Every other guests will be kicked if this amount is reached.
* \return Wether this action was succesfull
*/
bool Listen(std::uint16_t port, int maxConnexions);
/**
* \brief Tries to accept an incoming request to connect
* \param newSocket the empty socket to put the result to
* \return true if a new connexion was accepted
*/
bool Accept(TCPSocket& newSocket);
/**
* \brief Destroys the socket
*/
void Destroy();
/**
* \brief Closes transmissions
* \return true if this action was succesfull
*/
bool Close();
/**
* \brief Allows to set the socket in non blocking/blocking mode
* \param block If set to true, every call to Read will wait until the socket receives something
* \return true if the operation was successful
*/
bool SetBlocking(bool blocking);
/**
* \brief Getter of the m_Port member
* \return The port which the socket listen to
*/
std::uint16_t GetListeningPort() const {
return m_Port;
}
/**
* \brief Getter of the m_MaxConnections member
* \return The maximum amount of connexions that can happen at the same time.
*/
int GetMaximumConnections() const {
return m_MaxConnections;
}
/**
* \brief Disables TCPListener copy
*/
REMOVE_COPY(TCPListener);
};
} // namespace network
} // namespace blitz

View File

@@ -1,6 +1,26 @@
#pragma once
#include <sp/extensions/Tcp.h>
#include "blitz/common/DataBuffer.h"
#include "blitz/misc/ClassEntity.h"
#ifdef _WIN32
#include <winsock2.h>
#include <ws2tcpip.h>
#else
#include <arpa/inet.h>
#include <netdb.h>
#include <netinet/in.h>
#include <sys/ioctl.h>
#include <sys/socket.h>
#include <sys/types.h>
#include <unistd.h>
#define closesocket close
#endif
#ifndef INVALID_SOCKET
#define INVALID_SOCKET -1
#endif
/**
* \file TCPSocket.h
@@ -10,7 +30,143 @@
namespace blitz {
namespace network {
using TCPSocket = sp::io::TcpSocket;
/**
* \typedef SocketHandle
* \brief Represents a native socket
*/
typedef int SocketHandle;
/**
* \class TCPSocket
* \brief Cross platform abstraction of a TCP socket
*/
class TCPSocket {
public:
/**
* \enum Status
* \brief Describes the state of a socket
*/
enum class Status {
/** The socket is connected */
Connected,
/** The socket is not connected */
Disconnected,
/** Something bad happened */
Error,
};
private:
bool m_Blocking;
Status m_Status;
SocketHandle m_Handle;
std::uint16_t m_Port;
sockaddr m_RemoteAddr;
public:
/**
* \brief Default constructor
*/
TCPSocket();
/**
* \brief Default destructor
*/
virtual ~TCPSocket();
/**
* \brief Move constructor
*/
TCPSocket(TCPSocket&&);
/**
* \brief Sets the TCPSocket::Status of the socket
* \param status The TCPSocket::Status to apply
*/
void SetStatus(Status status);
/**
* \brief Allows to set the socket in non blocking/blocking mode
* \param block If set to true, every call to Read will wait until the socket receives something
* \return true if the operation was successful
*/
bool SetBlocking(bool block);
/**
* \brief Checks if the socket is in blocking mode
* \return Whether the socket is in blocking mode
*/
bool IsBlocking() const;
/**
* \brief Getter of the m_Status member
* \return The TCPSocket::Status of this socket
*/
Status GetStatus() const;
/**
* \brief Tries to connect to the host at the given port
* \param host The host to connect to. Can be a hostname or an ip address.
* \param port The port to connect to.
* \return Whether this action was successfull
*/
bool Connect(const std::string& host, std::uint16_t port);
/**
* \brief Disconnects the socket from the remote
* \note Does nothing if the socket is not connected. \n
* This function is also called by the destructor.
*/
void Disconnect();
/**
* \brief Sends some data
* \param buffer The data to send
* \note Simply returns 0 if the socket is not connected
* \return The amount of data sent. It should be the size of the buffer in theory.
*/
std::size_t Send(DataBuffer& buffer);
/**
* \brief Sends some data
* \param data The data to send
* \param size The amount of data to send
* \note Simply returns 0 if the socket is not connected
* \return The amount of data sent. It should be equal to the size param in theory
*/
std::size_t Send(const std::uint8_t* data, std::size_t size);
/**
* \brief Reads some data
* \param amount The amount of data to read
* \return The buffer containing the data that have been received
* \note If no data is available, an empty DataBuffer is returned
*/
DataBuffer Receive(std::size_t amount);
/**
* \brief Reads some data
* \param buffer The buffer to write into
* \param amount The amount of data to read
* \return The amount of data read
* \note If no data is available, 0 is returned
*/
std::size_t Receive(DataBuffer& buffer, std::size_t amount);
/**
* \brief Disable TCPSocket copy, as it disconnects when destroyed
*/
REMOVE_COPY(TCPSocket);
friend class TCPListener;
};
/**
* \brief Compress the data and send it to the socket
* \param data The data to send
* \param socket The socket to send to
*/
void SendPacket(const DataBuffer& data, network::TCPSocket& socket);
} // namespace network
} // namespace blitz

View File

@@ -1,74 +0,0 @@
#pragma once
#include "blitz/common/DataBuffer.h"
#include "blitz/maths/Vector.h"
#include <string>
#include <vector>
namespace blitz {
namespace protocol {
/**
* \struct ColoredPart
* \brief Represents a part of a chat message with a specific color.
*/
struct ColoredPart {
/**
* \brief The color of the part.
*/
Vec4f m_Color;
/**
* \brief The text of the part.
*/
std::string m_Text;
};
using ColoredText = std::vector<ColoredPart>;
const static Vec3uc AQUA = {0, 255, 255};
const static Vec3uc BLUE = {0, 0, 255};
const static Vec3uc GREEN = {0, 255, 0};
const static Vec3uc PURPLE = {255, 0, 255};
const static Vec3uc RED = {255, 0, 0};
const static Vec3uc WHITE = {255, 255, 255};
const static Vec3uc YELLOW = {255, 255, 0};
/**
* \brief Get the text color.
*/
std::string GetTextColor(Vec3uc color);
/**
* \brief Colorize a text.
*/
ColoredText ColorizeText(const std::string& text);
/**
* \brief Get the colored text string.
*/
std::string GetColoredTextString(const ColoredText& text);
/**
* \brief Serialize the colored part
* \param out The buffer to write the serialized colored part to
* \param var The colored part to serialize
*/
DataBuffer& operator<<(DataBuffer& out, const ColoredPart& var);
/**
* \brief Deserialize the colored part
* \param in The buffer to read the serialized colored part from
* \param var The colored part to deserialize
*/
DataBuffer& operator>>(DataBuffer& in, ColoredPart& var);
} // namespace protocol
} // namespace blitz
namespace sp {
template <>
inline std::string PrintData(const blitz::protocol::ColoredPart& a_Part) {
return "{m_Color=" + PrintData(a_Part.m_Color) + ", m_Text=" + PrintData(a_Part.m_Text) + "}";
}
} // namespace sp

View File

@@ -1,21 +1,32 @@
#pragma once
/**
* \file PacketDispatcher.h
* \brief File containing the blitz::protocol::PacketDispatcher class
*/
#include "blitz/protocol/Protocol.h"
#include "blitz/protocol/Packets.h"
#include <sp/default/DefaultPacketDispatcher.h>
#include <map>
namespace blitz {
namespace protocol {
/**
* \class PacketDispatcher
* \brief Class used to dispatch packets
*/
using PacketDispatcher = sp::PacketDispatcher;
class PacketHandler;
class PacketDispatcher {
private:
std::map<PacketType, std::vector<PacketHandler*>> m_Handlers;
public:
PacketDispatcher() = default;
PacketDispatcher(const PacketDispatcher& rhs) = delete;
PacketDispatcher& operator=(const PacketDispatcher& rhs) = delete;
PacketDispatcher(PacketDispatcher&& rhs) = delete;
PacketDispatcher& operator=(PacketDispatcher&& rhs) = delete;
void Dispatch(const Packet* packet);
void RegisterHandler(PacketType type, PacketHandler* handler);
void UnregisterHandler(PacketType type, PacketHandler* handler);
void UnregisterHandler(PacketHandler* handler);
};
} // namespace protocol
} // namespace blitz

View File

@@ -1,16 +1,13 @@
#pragma once
/**
* \file PacketFactory.h
*/
#include "blitz/protocol/Packets.h"
#include "blitz/protocol/Protocol.h"
namespace blitz {
namespace protocol {
namespace PacketFactory {
using PacketPtr = std::unique_ptr<Packet>;
using PacketFactory = sp::PacketFactory;
const Packet* CreatePacket(PacketType type, DataBuffer& buffer);
}
} // namespace protocol
} // namespace blitz

View File

@@ -1,16 +1,36 @@
#pragma once
/**
* \file PacketHandler.h
* \brief File containing the blitz::protocol::PacketHandler class
*/
#include "blitz/protocol/Packets.h"
#include "blitz/protocol/PacketsForward.h"
#include "blitz/protocol/Protocol.h"
namespace blitz {
namespace protocol {
using PacketHandler = sp::PacketHandler;
class PacketDispatcher;
class PacketHandler {
private:
PacketDispatcher* m_Dispatcher;
public:
PacketHandler(PacketDispatcher* dispatcher) : m_Dispatcher(dispatcher) {}
virtual ~PacketHandler() {}
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 ServerTpsPacket* packet) {}
};
} // namespace protocol
} // namespace blitz

View File

@@ -1,78 +1,10 @@
#pragma once
namespace blitz {
namespace protocol {
/**
* \enum PacketType
* \brief Map the packets name to their ID
*/
enum PacketType {
Chat = 0, /**< Corresponds to ChatPacket */
ConnexionInfo, /**< Corresponds to ConnexionInfoPacket */
Disconnect, /**< Corresponds to DisconnectPacket */
KeepAlive, /**< Corresponds to KeepAlivePacket */
PlayerDeath, /**< Corresponds to PlayerDeathPacket */
PlayerJoin, /**< Corresponds to PlayerJoinPacket */
PlayerLeave, /**< Corresponds to PlayerLeavePacket */
PlayerList, /**< Corresponds to PlayerListPacket */
PlayerLogin, /**< Corresponds to PlayerLoginPacket */
PlayerPositionAndRotation, /**< Corresponds to PlayerPositionAndRotationPacket */
PlayerShoot, /**< Corresponds to PlayerShootPacket */
PlayerStats, /**< Corresponds to PlayerStatsPacket */
ServerConfig, /**< Corresponds to ServerConfigPacket*/
ServerTps, /**< Corresponds to ServerTpsPacket */
UpdateGameState, /**< Corresponds to UpdateGameStatePacket */
UpdateHealth, /**< Corresponds to UpdateHealthPacket */
};
} // namespace protocol
} // namespace blitz
#include "packets/ChatPacket.h"
#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"
#include "packets/PlayerLoginPacket.h"
#include "packets/PlayerPositionAndRotationPacket.h"
#include "packets/PlayerShootPacket.h"
#include "packets/PlayerStatsPacket.h"
#include "packets/ServerConfigPacket.h"
#include "packets/ServerTpsPacket.h"
#include "packets/UpdateGameStatePacket.h"
#include "packets/UpdateHealthPacket.h"
// they must be in the same order as in the enum !
using AllPackets = std::tuple<
blitz::protocol::ChatPacket,
blitz::protocol::ConnexionInfoPacket,
blitz::protocol::DisconnectPacket,
blitz::protocol::KeepAlivePacket,
blitz::protocol::PlayerDeathPacket,
blitz::protocol::PlayerJoinPacket,
blitz::protocol::PlayerLeavePacket,
blitz::protocol::PlayerListPacket,
blitz::protocol::PlayerLoginPacket,
blitz::protocol::PlayerPositionAndRotationPacket,
blitz::protocol::PlayerShootPacket,
blitz::protocol::PlayerStatsPacket,
blitz::protocol::ServerConfigPacket,
blitz::protocol::ServerTpsPacket,
blitz::protocol::UpdateGameStatePacket,
blitz::protocol::UpdateHealthPacket
>;
#include <sp/default/DefaultPacketFactory.h>
#include <sp/default/DefaultPacketHandler.h>
namespace blitz {
namespace protocol {
using Packet = sp::PacketMessage;
} // namespace protocol
} // namespace blitz
#include "packets/ServerTpsPacket.h"

View File

@@ -7,18 +7,12 @@ class ChatPacket;
class ConnexionInfoPacket;
class DisconnectPacket;
class KeepAlivePacket;
class PlayerDeathPacket;
class PlayerJoinPacket;
class PlayerLeavePacket;
class PlayerListPacket;
class PlayerLoginPacket;
class PlayerPositionAndRotationPacket;
class PlayerShootPacket;
class PlayerStatsPacket;
class ServerConfigPacket;
class ServerTpsPacket;
class UpdateGameStatePacket;
class UpdateHealthPacket;
} // namespace protocol
} // namespace blitz

View File

@@ -0,0 +1,98 @@
#pragma once
/**
* \file Protocol.h
* \brief File describing protocol
*/
#include "blitz/common/DataBuffer.h"
namespace blitz {
namespace protocol {
class PacketHandler;
/**
* \enum PacketType
* \brief Map the packets name to their ID
*/
enum class PacketType : std::uint8_t {
// client --> server
PlayerLogin = 0, /**< Corresponds to PlayerLoginPacket */
// client <-- server
ConnexionInfo, /**< Corresponds to ConnexionInfoPacket */
PlayerJoin, /**< Corresponds to PlayerJoinPacket */
PlayerLeave, /**< Corresponds to PlayerLeavePacket */
PlayerList, /**< Corresponds to PlayerListPacket */
ServerTps, /**< Corresponds to ServerTpsPacket */
// client <--> server
KeepAlive, /**< Corresponds to KeepAlivePacket */
Disconnect, /**< Corresponds to DisconnectPacket */
Chat, /**< Corresponds to ChatPacket */
PlayerPositionAndRotation, /**< Corresponds to PlayerPositionAndRotationPacket */
PACKET_COUNT
};
/**
* \class Packet
* \brief Represents a network packet <br/>
* %Packet data structure :
*| Field Name | Field Type | Notes |
*|---------------------|---------------|-------------------------------|
*| Length | Long | Length of whole Packet |
*| Uncompressed Length | VarInt | Length of Packet ID + Data |
*| Packet ID | Byte | Represents the #PacketType |
*| Data | Byte Array | Depends on the packet ID |
*/
class Packet {
public:
Packet() {}
virtual ~Packet() {}
/**
* \brief Serialize the Packet into a DataBuffer to be sent over the network
* \param packetID Set to false if you don't want to write the Packet ID for some reason
* \returns A DataBuffer filled with the serialized Packet
*/
virtual DataBuffer Serialize(bool packetID = true) const = 0;
/**
* \brief Deserialize the DataBuffer into a Packet to be read by the client/server
* \param data The DataBuffer containing the data from the network
*/
virtual void Deserialize(DataBuffer& data) = 0;
/**
* \brief Dispatches the Packet
* \param handler The class to dispatch the Packet to
*/
virtual void Dispatch(PacketHandler* handler) const = 0;
/**
* \brief Writes the Packet ID into a buffer
* \param data The DataBuffer to write to
* \param packetID If set to false, this function does nothing
*/
void WritePacketID(DataBuffer& data, bool packetID) const;
/**
* \returns The type of the Packet
*/
virtual PacketType GetType() const = 0;
/**
* \returns The Packet ID corresponding to the PacketType of this Packet
*/
std::uint8_t GetID() const {
return static_cast<std::uint8_t>(GetType());
}
};
} // namespace protocol
} // namespace blitz

View File

@@ -1,54 +1,53 @@
#pragma once
/**
* \file ChatPacket.h
* \brief File containing the blitz::protocol::ChatPacket class
*/
#include "blitz/protocol/Color.h"
#include <sp/default/DefaultPacket.h>
#include <sp/protocol/Field.h>
#include <sp/protocol/MessageBase.h>
#include "blitz/common/Vector.h"
#include "blitz/protocol/Protocol.h"
#include <vector>
namespace blitz {
namespace protocol {
enum class ChatFieldsE {
m_Message = 0,
struct ColoredPart {
Vec4f color;
std::string text;
};
using ChatFields = std::tuple<
ColoredText //<- m_Message
>;
/**
* \class ChatPacket
* \brief Packet for sending chat messages.
* %Packet structure :
* | PacketType |
* |------------------------|
* | PacketType::Chat |
*
* | Field Name | Field Type | Notes |
* |--------------------|-------------------|-------------------------------|
* | m_Message | ColoredText | The message sent in the chat |
*/
DeclarePacket(Chat){
public:
PacketConstructor(Chat)
typedef std::vector<ColoredPart> ColoredText;
ChatPacket(const std::string& msg) : ChatPacket(ColorizeText(msg)) {}
class ChatPacket : public Packet {
private:
ColoredText m_Message;
public:
ChatPacket() {}
ChatPacket(const std::string& msg) : m_Message(ColorizeText(msg)) {}
ChatPacket(const ColoredText& msg) : m_Message(msg) {}
virtual ~ChatPacket() {}
virtual DataBuffer Serialize(bool packetID = true) const;
virtual void Deserialize(DataBuffer& data);
virtual void Dispatch(PacketHandler* handler) const;
/**
* \brief Get the message.
* \return The message.
*/
const ColoredText& GetMessage() const {
return GetField<ChatFieldsE, ChatFieldsE::m_Message>();
return m_Message;
}
virtual PacketType GetType() const {
return PacketType::Chat;
}
static std::string GetTextColor(Vec3uc color);
static ColoredText ColorizeText(const std::string& text);
static std::string GetColoredTextString(const ColoredText& text);
};
const static Vec3uc AQUA = {0, 255, 255};
const static Vec3uc BLUE = {0, 0, 255};
const static Vec3uc GREEN = {0, 255, 0};
const static Vec3uc PURPLE = {255, 0, 255};
const static Vec3uc RED = {255, 0, 0};
const static Vec3uc WHITE = {255, 255, 255};
const static Vec3uc YELLOW = {255, 255, 0};
} // namespace protocol
} // namespace blitz

View File

@@ -1,47 +1,29 @@
#pragma once
/**
* \file ConnexionInfoPacket.h
* \brief File containing the blitz::protocol::ConnexionInfoPacket class
*/
#include <sp/default/DefaultPacket.h>
#include <sp/protocol/Field.h>
#include <sp/protocol/MessageBase.h>
#include "blitz/protocol/Protocol.h"
namespace blitz {
namespace protocol {
enum class ConnexionInfoFieldsE {
m_ConnectionID = 0,
};
using ConnexionInfoFields = std::tuple<
std::uint8_t //<- m_ConnectionID
>;
class ConnexionInfoPacket : public Packet {
private:
std::uint8_t m_ConnectionID;
public:
ConnexionInfoPacket() {}
ConnexionInfoPacket(std::uint8_t connectionID) : m_ConnectionID(connectionID) {}
virtual ~ConnexionInfoPacket() {}
virtual DataBuffer Serialize(bool packetID = true) const;
virtual void Deserialize(DataBuffer& data);
virtual void Dispatch(PacketHandler* handler) const;
/**
* \class ConnexionInfoPacket
* \brief Packet for sending connection information.
* %Packet structure :
* | PacketType |
* |------------------------|
* | PacketType::ConnexionInfo |
*
* | Field Name | Field Type | Notes |
* |--------------------|-------------------|-------------------------------|
* | m_ConnectionID | std::uint8_t | The connection ID |
*/
DeclarePacket(ConnexionInfo){
public:
PacketConstructor(ConnexionInfo)
/**
* \brief Get the connection ID.
* \return The connection ID.
*/
std::uint8_t GetConnectionID() const {
return GetField<ConnexionInfoFieldsE, ConnexionInfoFieldsE::m_ConnectionID>();
return m_ConnectionID;
}
virtual PacketType GetType() const {
return PacketType::ConnexionInfo;
}
};

View File

@@ -1,47 +1,28 @@
#pragma once
/**
* \file DisconnectPacket.h
* \brief File containing the blitz::protocol::DisconnectPacket class
*/
#include <sp/default/DefaultPacket.h>
#include <sp/protocol/Field.h>
#include <sp/protocol/MessageBase.h>
#include "blitz/protocol/Protocol.h"
namespace blitz {
namespace protocol {
enum class DisconnectFieldsE {
m_Reason = 0,
};
using DisconnectFields = std::tuple<
std::string //<- m_Reason
>;
/**
* \class DisconnectPacket
* \brief Packet for disconnecting from the server.
* %Packet structure :
* | PacketType |
* |------------------------|
* | PacketType::Disconnect |
*
* | Field Name | Field Type | Notes |
* |--------------------|-------------------|-------------------------------|
* | m_Reason | std::string | The reason for disconnection |
*/
DeclarePacket(Disconnect){
public:
PacketConstructor(Disconnect)
class DisconnectPacket : public Packet {
private:
std::string m_Reason; // only when sent from server
public:
DisconnectPacket() {}
DisconnectPacket(std::string reason) : m_Reason(reason) {}
virtual ~DisconnectPacket() {}
virtual DataBuffer Serialize(bool packetID = true) const;
virtual void Deserialize(DataBuffer& data);
virtual void Dispatch(PacketHandler* handler) const;
/**
* \brief Get the reason for disconnection.
* \return The reason for disconnection.
*/
const std::string& GetReason() const {
return GetField<DisconnectFieldsE, DisconnectFieldsE::m_Reason>();
return m_Reason;
}
virtual PacketType GetType() const {
return PacketType::Disconnect;
}
};

View File

@@ -5,47 +5,51 @@
* \brief File containing the blitz::protocol::KeepAlivePacket class
*/
#include <sp/default/DefaultPacket.h>
#include <sp/protocol/Field.h>
#include <sp/protocol/MessageBase.h>
#include "blitz/common/VarInt.h"
#include "blitz/protocol/Protocol.h"
namespace blitz {
namespace protocol {
enum class KeepAliveFieldsE {
KeepAliveId = 0,
};
using KeepAliveFields = std::tuple<
sp::VarInt //<- KeepAliveId
>;
/**
* \class KeepAlivePacket
* \brief Packet sent to measure the health of a connexion. \n
* \brief %Packet sent to measure the health of a connexion. \n
* The client must respond with the same alive ID. Else, the connexion will be closed. \n
* %Packet structure :
* %Packet structure :
* | PacketType |
* |------------------------|
* | PacketType::KeepAlive |
*
* | Field Name | Field Type | Notes |
*
* | Field Name | Field Type | Notes |
* |--------------------|---------------|---------------------------------------------------------------------------|
* | Keep Alive ID | VarInt | The server generates a random ID, the client must respond with the same |
*
*/
DeclarePacket(KeepAlive){
public:
PacketConstructor(KeepAlive)
class KeepAlivePacket : public Packet {
private:
VarInt m_AliveID;
public:
KeepAlivePacket() {}
KeepAlivePacket(std::uint64_t aliveID) : m_AliveID(aliveID) {}
virtual ~KeepAlivePacket() {}
virtual DataBuffer Serialize(bool packetID = true) const;
virtual void Deserialize(DataBuffer& data);
virtual void Dispatch(PacketHandler* handler) const;
/**
* \brief Getter of the alive ID
* \return The alive ID
*/
std::uint64_t GetAliveId() const {
return GetField<KeepAliveFieldsE, KeepAliveFieldsE::KeepAliveId>().GetValue();
std::uint64_t GetAliveID() const {
return m_AliveID.GetValue();
}
virtual PacketType GetType() const {
return PacketType::KeepAlive;
}
};
} // namespace protocol
} // namespace blitz
} // namespace protocol
} // namespace blitz

View File

@@ -1,50 +0,0 @@
#pragma once
/**
* \file PlayerDeathPacket.h
* \brief File containing the blitz::protocol::PlayerDeathPacket class
*/
#include "blitz/common/Defines.h"
#include <sp/default/DefaultPacket.h>
#include <sp/protocol/Field.h>
#include <sp/protocol/MessageBase.h>
namespace blitz {
namespace protocol {
enum class PlayerDeathFieldsE {
m_PlayerID = 0,
};
using PlayerDeathFields = std::tuple<
game::PlayerID //<- m_PlayerID
>;
/**
* \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 |
*/
DeclarePacket(PlayerDeath){
public:
PacketConstructor(PlayerDeath)
/**
* \brief Get the ID of the player that died.
* \return The ID of the player that died.
*/
game::PlayerID GetPlayerID() const {
return GetField<PlayerDeathFieldsE, PlayerDeathFieldsE::m_PlayerID>();
}
};
} // namespace protocol
} // namespace blitz

View File

@@ -6,26 +6,14 @@
*/
#include "blitz/common/Defines.h"
#include <sp/default/DefaultPacket.h>
#include <sp/protocol/Field.h>
#include <sp/protocol/MessageBase.h>
#include "blitz/protocol/Protocol.h"
namespace blitz {
namespace protocol {
enum class PlayerJoinFieldsE {
m_PlayerID = 0,
m_PlayerName,
};
using PlayerJoinFields = std::tuple<
game::PlayerID, //<- m_PlayerID
std::string //<- m_PlayerName
>;
/**
* \class PlayerJoinPacket
* \brief Packet sent when a new player joins the game
* \brief %Packet sent when a new player joins the game \n
* %Packet structure :
* | PacketType |
* |------------------------|
@@ -37,16 +25,26 @@ using PlayerJoinFields = std::tuple<
* | Player Name | std::string | Name of the player who joined |
*
*/
DeclarePacket(PlayerJoin){
public:
PacketConstructor(PlayerJoin)
class PlayerJoinPacket : public Packet {
private:
game::PlayerID m_PlayerID;
std::string m_PlayerName;
public:
PlayerJoinPacket() {}
PlayerJoinPacket(game::PlayerID playerID, const std::string& playerName) : m_PlayerID(playerID), m_PlayerName(playerName) {}
virtual ~PlayerJoinPacket() {}
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 died.
* \return The ID of the player that died.
*/
* \brief Getter of the player id
* \return The ID of the player
*/
game::PlayerID GetPlayerID() const {
return GetField<PlayerJoinFieldsE, PlayerJoinFieldsE::m_PlayerID>();
return m_PlayerID;
}
/**
@@ -54,7 +52,11 @@ DeclarePacket(PlayerJoin){
* \return The name of the player
*/
const std::string& GetPlayerName() const {
return GetField<PlayerJoinFieldsE, PlayerJoinFieldsE::m_PlayerName>();
return m_PlayerName;
}
virtual PacketType GetType() const {
return PacketType::PlayerJoin;
}
};

View File

@@ -1,49 +1,29 @@
#pragma once
/**
* \file PlayerLeavePacket.h
* \brief File containing the blitz::protocol::PlayerLeavePacket class
*/
#include "blitz/common/Defines.h"
#include <sp/default/DefaultPacket.h>
#include <sp/protocol/Field.h>
#include <sp/protocol/MessageBase.h>
#include "blitz/protocol/Protocol.h"
namespace blitz {
namespace protocol {
enum class PlayerLeaveFieldsE {
m_PlayerID = 0,
};
using PlayerLeaveFields = std::tuple<
game::PlayerID //<- m_PlayerID
>;
class PlayerLeavePacket : public Packet {
private:
std::uint8_t m_PlayerID;
/**
* \class PlayerLeavePacket
* \brief Packet for when a player leaves the game.
* %Packet structure :
* | PacketType |
* |------------------------|
* | PacketType::PlayerLeave|
*
* | Field Name | Field Type | Notes |
* |--------------------|-------------------|-------------------------------|
* | m_PlayerID | PlayerID |The ID of the player that left |
*/
DeclarePacket(PlayerLeave){
public:
PacketConstructor(PlayerLeave)
/**
* \brief Get the ID of the player that left.
* \return The ID of the player that left.
*/
game::PlayerID GetPlayerID() const {
return GetField<PlayerLeaveFieldsE, PlayerLeaveFieldsE::m_PlayerID>();
public:
PlayerLeavePacket() {}
PlayerLeavePacket(std::uint8_t playerID) : m_PlayerID(playerID) {}
virtual ~PlayerLeavePacket() {}
virtual DataBuffer Serialize(bool packetID = true) const;
virtual void Deserialize(DataBuffer& data);
virtual void Dispatch(PacketHandler* handler) const;
std::uint8_t GetPlayerID() const {
return m_PlayerID;
}
virtual PacketType GetType() const {
return PacketType::PlayerLeave;
}
};

View File

@@ -1,57 +1,39 @@
#pragma once
/**
* \file PlayerListPacket.h
* \brief File containing the blitz::protocol::PlayerListPacket class
*/
#include <map>
#include <sp/default/DefaultPacket.h>
#include <sp/protocol/Field.h>
#include <sp/protocol/MessageBase.h>
#include <sp/protocol/MessagePrinter.h>
#include "blitz/protocol/Protocol.h"
namespace blitz {
namespace protocol {
/**
* \struct PlayerInfo
* \brief Represents information about a player.
*/
struct PlayerInfo {
std::string m_Name;
std::string name;
};
using PlayerMap = std::map<std::uint8_t, PlayerInfo>;
typedef std::map<std::uint8_t, PlayerInfo> PlayerList;
enum class PlayerListFieldsE {
m_PlayerList = 0,
};
using PlayerListFields = std::tuple<
PlayerMap //<- m_PlayerList
>;
class PlayerListPacket : public Packet {
private:
PlayerList m_Players;
DeclarePacket(PlayerList){
public:
PacketConstructor(PlayerList)
/**
* \brief Get the list of players.
* \return The list of players.
*/
const PlayerMap& GetPlayers() const {
return GetField<PlayerListFieldsE, PlayerListFieldsE::m_PlayerList>();
public:
PlayerListPacket() {}
PlayerListPacket(const PlayerList& players) : m_Players(players) {}
virtual ~PlayerListPacket() {}
virtual DataBuffer Serialize(bool packetID = true) const;
virtual void Deserialize(DataBuffer& data);
virtual void Dispatch(PacketHandler* handler) const;
const PlayerList& GetPlayers() const {
return m_Players;
}
virtual PacketType GetType() const {
return PacketType::PlayerList;
}
};
} // namespace protocol
} // namespace blitz
namespace sp {
template <>
inline std::string PrintData(const blitz::protocol::PlayerInfo& a_Config) {
return "{m_Name=" + PrintData(a_Config.m_Name) + "}";
}
} // namespace sp

View File

@@ -1,47 +1,29 @@
#pragma once
/**
* \file PlayerLoginPacket.h
* \brief File containing the blitz::protocol::PlayerLoginPacket class
*/
#include <sp/default/DefaultPacket.h>
#include <sp/protocol/Field.h>
#include <sp/protocol/MessageBase.h>
#include "blitz/protocol/Protocol.h"
namespace blitz {
namespace protocol {
enum class PlayerLoginFieldsE {
m_PlayerName = 0,
};
using PlayerLoginFields = std::tuple<
std::string //<- m_PlayerName
>;
class PlayerLoginPacket : public Packet {
private:
std::string m_PlayerName;
public:
PlayerLoginPacket() {}
PlayerLoginPacket(std::string playerName) : m_PlayerName(playerName) {}
virtual ~PlayerLoginPacket() {}
virtual DataBuffer Serialize(bool packetID = true) const;
virtual void Deserialize(DataBuffer& data);
virtual void Dispatch(PacketHandler* handler) const;
virtual PacketType GetType() const {
return PacketType::PlayerLogin;
}
/**
* \class PlayerLoginPacket
* \brief Packet for when a player logs in.
* %Packet structure :
* | PacketType |
* |------------------------|
* | PacketType::PlayerLogin|
*
* | Field Name | Field Type | Notes |
* |--------------------|-------------------|----------------------------------|
* | Player Name | std::string | Name of the player that logged in|
*/
DeclarePacket(PlayerLogin){
public:
PacketConstructor(PlayerLogin)
/**
* \brief Get the name of the player that logged in.
* \return The name of the player that logged in.
*/
const std::string& GetPlayerName() const {
return GetField<PlayerLoginFieldsE, PlayerLoginFieldsE::m_PlayerName>();
return m_PlayerName;
}
};

View File

@@ -1,82 +1,47 @@
#pragma once
/**
* \file PlayerPositionAndRotationPacket.h
* \brief File containing the blitz::protocol::PlayerPositionAndRotationPacket class
*/
#include "blitz/common/Defines.h"
#include "blitz/maths/Vector.h"
#include <sp/default/DefaultPacket.h>
#include <sp/protocol/Field.h>
#include <sp/protocol/MessageBase.h>
#include "blitz/common/Vector.h"
#include "blitz/protocol/Protocol.h"
namespace blitz {
namespace protocol {
enum class PlayerPositionAndRotationFieldsE {
m_PlayerID = 0,
m_Position,
m_Yaw,
m_Pitch,
};
using PlayerPositionAndRotationFields = std::tuple<
game::PlayerID, //<- m_PlayerID
Vec3f, //<- m_Position
float, //<- m_Yaw
float //<- m_Pitch
>;
class PlayerPositionAndRotationPacket : public Packet {
private:
game::PlayerID m_Player; // only used when sent to client
Vec3f m_Position;
float m_Yaw, m_Pitch;
public:
PlayerPositionAndRotationPacket() {}
PlayerPositionAndRotationPacket(const Vec3f& position, float yaw, float pitch, game::PlayerID player = 0) :
m_Player(player), m_Position(position), m_Yaw(yaw), m_Pitch(pitch) {}
virtual ~PlayerPositionAndRotationPacket() {}
virtual DataBuffer Serialize(bool packetID = true) const;
virtual void Deserialize(DataBuffer& data);
virtual void Dispatch(PacketHandler* handler) const;
/**
* \class PlayerPositionAndRotationPacket
* \brief Packet for sending a player's position and rotation.
* %Packet structure :
* | PacketType |
* |--------------------------------|
* | PacketType::PlayerPositionAndRotation |
*
* | Field Name | Field Type | Notes |
* |--------------------|-------------------|----------------------------------|
* | Player ID | PlayerID | Id of the player who moved |
* | Position | Vec3f | Position of the player |
* | Yaw | float | Yaw of the player |
* | Pitch | float | Pitch of the player |
*/
DeclarePacket(PlayerPositionAndRotation){
public:
PacketConstructor(PlayerPositionAndRotation)
/**
* \brief Get the position of the player.
* \return The position of the player.
*/
const Vec3f& GetPosition() const {
return GetField<PlayerPositionAndRotationFieldsE, PlayerPositionAndRotationFieldsE::m_Position>();
return m_Position;
}
/**
* \brief Get the yaw of the player.
* \return The yaw of the player.
*/
float GetYaw() const {
return GetField<PlayerPositionAndRotationFieldsE, PlayerPositionAndRotationFieldsE::m_Yaw>();
return m_Yaw;
}
/**
* \brief Get the pitch of the player.
* \return The pitch of the player.
*/
float GetPitch() const {
return GetField<PlayerPositionAndRotationFieldsE, PlayerPositionAndRotationFieldsE::m_Pitch>();
return m_Pitch;
}
/**
* \brief Get the ID of the player.
* \return The ID of the player.
*/
game::PlayerID GetPlayer() const {
return GetField<PlayerPositionAndRotationFieldsE, PlayerPositionAndRotationFieldsE::m_PlayerID>();
return m_Player;
}
virtual PacketType GetType() const {
return PacketType::PlayerPositionAndRotation;
}
};

View File

@@ -1,83 +0,0 @@
#pragma once
/**
* \file PlayerShootPacket.h
* \brief File containing the blitz::protocol::PlayerShootPacket class
*/
#include "blitz/game/Player.h"
#include <sp/default/DefaultPacket.h>
#include <sp/protocol/Field.h>
#include <sp/protocol/MessageBase.h>
namespace blitz {
namespace protocol {
enum class PlayerShootFieldsE {
m_PlayerID = 0,
m_Position,
m_Yaw,
m_Pitch,
};
using PlayerShootFields = std::tuple<
game::PlayerID, //<- m_PlayerID
Vec3f, //<- m_Position
float, //<- m_Yaw
float //<- m_Pitch
>;
/**
* \class PlayerShootPacket
* \brief Packet for when a player shoots.
* %Packet structure :
* | PacketType |
* |------------------------|
* | PacketType::PlayerShoot|
*
* | Field Name | Field Type | Notes |
* |--------------------|-------------------|----------------------------------|
* | Player ID | PlayerID | The ID of the player that shot |
* | Position | Vec3f | Position of the player |
* | Yaw | float | Yaw of the player |
* | Pitch | float | Pitch of the player |
*/
DeclarePacket(PlayerShoot){
public:
PacketConstructor(PlayerShoot)
/**
* \brief Get the position of the player.
* \return The position of the player.
*/
const Vec3f& GetPosition() const {
return GetField<PlayerShootFieldsE, PlayerShootFieldsE::m_Position>();
}
/**
* \brief Get the yaw of the player.
* \return The yaw of the player.
*/
float GetYaw() const {
return GetField<PlayerShootFieldsE, PlayerShootFieldsE::m_Yaw>();
}
/**
* \brief Get the pitch of the player.
* \return The pitch of the player.
*/
float GetPitch() const {
return GetField<PlayerShootFieldsE, PlayerShootFieldsE::m_Pitch>();
}
/**
* \brief Get the ID of the player.
* \return The ID of the player.
*/
game::PlayerID GetPlayer() const {
return GetField<PlayerShootFieldsE, PlayerShootFieldsE::m_PlayerID>();
}
};
} // namespace protocol
} // namespace blitz

View File

@@ -1,62 +0,0 @@
#pragma once
/**
* \file PlayerStatsPacket.h
* \brief File containing the blitz::protocol::PlayerStatsPacket class
*/
#include "blitz/common/Defines.h"
#include "blitz/game/Player.h"
#include <sp/default/DefaultPacket.h>
#include <sp/protocol/Field.h>
#include <sp/protocol/MessageBase.h>
namespace blitz {
namespace protocol {
enum class PlayerStatsFieldsE {
m_PlayerID = 0,
m_PlayerStats,
};
using PlayerStatsFields = std::tuple<
game::PlayerID, //<- m_PlayerID
game::PlayerStats //<- m_PlayerStats
>;
/**
* \class PlayerStatsPacket
* \brief Packet for sending player stats.
* %Packet structure :
* | PacketType |
* |------------------------|
* | PacketType::PlayerStats|
*
* | Field Name | Field Type | Notes |
* |--------------------|-------------------|-------------------------------|
* | Player ID | PlayerID | Id of the player |
* | Player Stats | PlayerStats | Stats of the player |
*/
DeclarePacket(PlayerStats){
public:
PacketConstructor(PlayerStats)
/**
* \brief Getter of the player id
* \return The ID of the player
*/
game::PlayerID GetPlayerID() const {
return GetField<PlayerStatsFieldsE, PlayerStatsFieldsE::m_PlayerID>();
}
/**
* \brief Getter of the player stats
* \return The stats of the player
*/
const game::PlayerStats& GetPlayerStats() const {
return GetField<PlayerStatsFieldsE, PlayerStatsFieldsE::m_PlayerStats>();
}
};
} // namespace protocol
} // namespace blitz

View File

@@ -1,50 +0,0 @@
#pragma once
/**
* \file ServerConfigPacket.h
* \brief File containing the blitz::protocol::ServerConfigPacket class
*/
#include "blitz/game/Game.h"
#include <sp/default/DefaultPacket.h>
#include <sp/protocol/Field.h>
#include <sp/protocol/MessageBase.h>
namespace blitz {
namespace protocol {
enum class ServerConfigFieldsE {
m_GameConfig = 0,
};
using ServerConfigFields = std::tuple<
game::GameConfig //<- m_GameConfig
>;
/**
* \class ServerConfigPacket
* \brief Packet for sending the server configuration.
* %Packet structure :
* | PacketType |
* |-------------------------|
* | PacketType::ServerConfig|
*
* | Field Name | Field Type | Notes |
* |--------------------|-------------------|-------------------------------|
* | Game Config | GameConfig | The game configuration |
*/
DeclarePacket(ServerConfig){
public:
PacketConstructor(ServerConfig)
/**
* \brief Getter of the game configuration
* \return The game configuration
*/
game::GameConfig GetGameConfig() const {
return GetField<ServerConfigFieldsE, ServerConfigFieldsE::m_GameConfig>();
}
};
} // namespace protocol
} // namespace blitz

View File

@@ -1,70 +1,38 @@
#pragma once
/**
* \file ServerTpsPacket.h
* \brief File containing the blitz::protocol::ServerTpsPacket class
*/
#include <sp/default/DefaultPacket.h>
#include <sp/protocol/Field.h>
#include <sp/protocol/MessageBase.h>
#include "blitz/protocol/Protocol.h"
namespace blitz {
namespace protocol {
enum class ServerTpsFieldsE {
m_TPS = 0,
m_MSPT,
m_PacketSendTime,
};
using ServerTpsFields = std::tuple<
float, //<- m_TPS
float, //<- m_MSPT
std::uint64_t //<- m_PacketSendTime
>;
class ServerTpsPacket : public Packet {
private:
float m_TPS;
float m_MSPT;
std::uint64_t m_PacketSendTime; // used to calculate ping
public:
ServerTpsPacket() {}
ServerTpsPacket(float tps, float mspt, std::uint64_t sendTime) : m_TPS(tps), m_MSPT(mspt), m_PacketSendTime(sendTime) {}
virtual ~ServerTpsPacket() {}
virtual DataBuffer Serialize(bool packetID = true) const;
virtual void Deserialize(DataBuffer& data);
virtual void Dispatch(PacketHandler* handler) const;
/**
* \class ServerTpsPacket
* \brief Packet for sending server TPS (Tick per second) and MSPT (Milliseconds per tick).
* %Packet structure :
* | PacketType |
* |------------------------|
* | PacketType::ServerTps |
*
* | Field Name | Field Type | Notes |
* |--------------------|-------------------|-------------------------------|
* | Tps | float | Server TPS |
* | Mspt | float | Server MSPT |
* | PacketSendTime | uint64_t | Time the packet was sent |
*/
DeclarePacket(ServerTps){
public:
PacketConstructor(ServerTps)
/**
* \brief Get the server TPS.
* \return The server TPS.
*/
float GetTPS() const {
return GetField<ServerTpsFieldsE, ServerTpsFieldsE::m_TPS>();
return m_TPS;
}
/**
* \brief Get the server MSPT.
* \return The server MSPT.
*/
float GetMSPT() const {
return GetField<ServerTpsFieldsE, ServerTpsFieldsE::m_MSPT>();
return m_MSPT;
}
/**
* \brief Get the time the packet was sent.
* \return The time the packet was sent.
* \todo Calculate ping.
*/
std::uint64_t GetPacketSendTime() const {
return GetField<ServerTpsFieldsE, ServerTpsFieldsE::m_PacketSendTime>();
return m_PacketSendTime;
}
virtual PacketType GetType() const {
return PacketType::ServerTps;
}
};

View File

@@ -1,61 +0,0 @@
#pragma once
/**
* \file UpdateGameStatePacket.h
* \brief File containing the blitz::protocol::UpdateGameStatePacket class
*/
#include "blitz/game/Game.h"
#include <sp/default/DefaultPacket.h>
#include <sp/protocol/Field.h>
#include <sp/protocol/MessageBase.h>
namespace blitz {
namespace protocol {
enum class UpdateGameStateFieldsE {
m_GameState = 0,
m_TimeRemaining,
};
using UpdateGameStateFields = std::tuple<
game::GameState, //<- m_GameState
std::uint64_t //<- m_TimeRemaining
>;
/**
* \class UpdateGameStatePacket
* \brief Packet for updating the game state.
* %Packet structure :
* | PacketType |
* |-----------------------------|
* | PacketType::UpdateGameState |
*
* | Field Name | Field Type | Notes |
* |--------------------|-------------------|----------------------------------------------|
* | Game State | GameState | The new game state |
* | Time Remaining | std::uint64_t | The time remaining in the current game state |
*/
DeclarePacket(UpdateGameState){
public:
PacketConstructor(UpdateGameState)
/**
* \brief Get the new game state.
* \return The new game state.
*/
game::GameState GetGameState() const {
return GetField<UpdateGameStateFieldsE, UpdateGameStateFieldsE::m_GameState>();
}
/**
* \brief Get the time remaining in the current game state.
* \return The time remaining in the current game state.
*/
std::uint64_t GetTimeRemaining() const {
return GetField<UpdateGameStateFieldsE, UpdateGameStateFieldsE::m_TimeRemaining>();
}
};
} // namespace protocol
} // namespace blitz

View File

@@ -1,49 +0,0 @@
#pragma once
/**
* \file UpdateHealthPacket.h
* \brief File containing the blitz::protocol::UpdateHealthPacket class
*/
#include <sp/default/DefaultPacket.h>
#include <sp/protocol/Field.h>
#include <sp/protocol/MessageBase.h>
namespace blitz {
namespace protocol {
enum class UpdateHealthFieldsE {
m_NewHealth = 0,
};
using UpdateHealthFields = std::tuple<
float //<- m_NewHealth
>;
/**
* \class UpdateHealthPacket
* \brief Packet for updating the health of a player.
* %Packet structure :
* | PacketType |
* |--------------------------|
* | PacketType::UpdateHealth |
*
* | Field Name | Field Type | Notes |
* |--------------------|-------------------|-------------------------------|
* | m_NewHealth | float | The new health value |
*/
DeclarePacket(UpdateHealth){
public:
PacketConstructor(UpdateHealth)
/**
* \brief Get the ID of the player that left.
* \return The ID of the player that left.
*/
game::PlayerID GetNewHealth() const {
return GetField<UpdateHealthFieldsE, UpdateHealthFieldsE::m_NewHealth>();
}
};
} // namespace protocol
} // namespace blitz

View File

@@ -3,7 +3,7 @@
#include "blitz/common/Defines.h"
#include "blitz/misc/ObjectNotifier.h"
#include "blitz/misc/Time.h"
#include "client/Listeners.h"
#include "blitz/protocol/packets/ChatPacket.h"
#include "client/config/BlitzConfig.h"
#include <cstdint>
#include <memory>
@@ -13,17 +13,23 @@ namespace blitz {
static const int PlayerUpdatePosRate = 50;
namespace client {
class ClientConnexion;
class ClientGame;
} // namespace client
namespace server {
class Server;
} // namespace server
namespace client {
class ClientConnexion;
class ClientGame;
class GuiListener {
public:
virtual void OnTextChatReceived(const protocol::ColoredText& text) {}
virtual void OnSpectatorChange(const game::PlayerID player) {}
};
// Singleton
class Client : public utils::ObjectNotifier<client::ClientListener>, public client::PlayerInputListener {
class Client : public utils::ObjectNotifier<GuiListener> {
private:
std::unique_ptr<server::Server> m_Server;
std::unique_ptr<client::ClientConnexion> m_Connexion;
@@ -49,8 +55,6 @@ class Client : public utils::ObjectNotifier<client::ClientListener>, public clie
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() {
@@ -61,19 +65,10 @@ class Client : public utils::ObjectNotifier<client::ClientListener>, public clie
return &m_Config;
}
bool IsAdmin() const;
server::Server* GetServer() {
return m_Server.get();
}
void UpdateServerConfig();
private:
void Reset();
void UpdatePosition(std::uint64_t delta);
};
} // namespace client
} // namespace blitz

View File

@@ -4,10 +4,11 @@
#include "blitz/network/Connexion.h"
namespace blitz {
namespace client {
class Client;
namespace client {
class ClientConnexion : public network::Connexion {
private:
Client* m_Client;
@@ -18,12 +19,12 @@ class ClientConnexion : public network::Connexion {
ClientConnexion(Client* client);
virtual ~ClientConnexion();
virtual void Handle(const protocol::DisconnectPacket& packet) override;
virtual void Handle(const protocol::KeepAlivePacket& packet) override;
virtual void Handle(const protocol::ChatPacket& packet) override;
virtual void Handle(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);
virtual bool Connect(const std::string& pseudo, const std::string& address, std::uint16_t port);
game::PlayerID GetPlayerID() const {
return m_PlayerID;

View File

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

View File

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

View File

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

View File

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

View File

@@ -1,66 +0,0 @@
#pragma once
#include "blitz/game/Listeners.h"
#include "client/Listeners.h"
#include "client/audio/AudioListener.h"
#include "client/audio/AudioSource.h"
#include <map>
namespace blitz {
namespace client {
class Client;
} // namespace client
namespace game {
class Player;
} // namespace game
namespace audio {
struct PlayerSound {
AudioSourcePtr m_Laser;
AudioSourcePtr m_FootStep;
AudioSourcePtr m_Death;
};
class AudioManager : public client::ClientListener, public game::GameListener {
private:
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* 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;
void SetGlobalVolume(float volume);
void Update();
private:
void InitSounds();
AudioSourcePtr InitSourceFromFile(const std::string& fileName);
AudioSourcePtr InitSourceFromBuffer(const AudioBufferPtr& buffer);
AudioBufferPtr InitBufferFromFile(const std::string& fileName);
};
} // namespace audio
} // namespace blitz

View File

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

View File

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

View File

@@ -0,0 +1,53 @@
#pragma once
#include <memory>
#include <string>
class SDL_Window;
namespace blitz {
class Client;
namespace gui {
class BlitzGui;
} // namespace gui
class Display {
private:
SDL_Window* m_Window;
void* m_GL_Context;
int m_WindowWidth;
int m_WindowHeight;
float m_AspectRatio;
std::string m_WindowName;
bool m_ShouldClose;
bool m_FullScreen;
Client* m_Client;
std::unique_ptr<gui::BlitzGui> m_BlitzGui;
public:
Display(int width, int height, const std::string& windowName, Client* client);
~Display();
bool Create();
void PollEvents();
void Update();
void Render();
void Destroy();
bool IsCloseRequested();
float GetAspectRatio();
int GetWindowWidth();
int GetWindowHeight();
private:
void InitImGui();
};
} // namespace blitz

View File

@@ -0,0 +1,19 @@
#pragma once
#include <SDL2/SDL_events.h>
#include <functional>
namespace blitz {
namespace InputManager {
typedef std::function<void(int)> KeyDownCallback;
typedef std::function<void(int, int)> MouseMoveCallback;
void BindKeyDownCallback(const KeyDownCallback&);
void BindMouseMoveCallback(const MouseMoveCallback&);
void ProcessEvent(SDL_Event& event);
void GrabMouse(bool grabInput);
bool MouseGrabbed();
} // namespace InputManager
} // namespace blitz

View File

@@ -0,0 +1,54 @@
#pragma once
#include "blitz/common/Smoothing.h"
namespace blitz {
namespace game {
class Player;
} // namespace game
namespace input {
class PlayerController {
private:
game::Player* m_Player;
EMASmoother m_DxSmoother;
/// maximum x-axis velocity
float m_MaxDx;
/// current (target) x-axis velocity
float m_Dx;
EMASmoother m_DySmoother;
/// maximum (target) y-axis velocity
float m_MaxDy;
/// current (target) y-axis velocity
float m_Dy;
/// current z-axis velocity
float m_Dz;
/// maximum z-axis velocity (velocity at initial keypress)
float m_MaxDz;
/// individual gravitational force
float m_G;
/// this is reset when the player touches the ground
bool m_OnGround;
public:
PlayerController();
void Update(float delta);
void SetAttachedPlayer(game::Player* a_Player) {
m_Player = a_Player;
}
game::Player* GetAttachedPlayer() {
return m_Player;
}
private:
void MouseMotionEvent(int, int);
void UpdatePosition(float delta);
};
} // namespace input
} // namespace blitz

View File

@@ -1,52 +1,31 @@
#pragma once
#include "blitz/game/Game.h"
#include "blitz/game/LeaderBoard.h"
#include "blitz/protocol/PacketHandler.h"
#include "blitz/protocol/PacketDispatcher.h"
#include <vector>
namespace blitz {
namespace client {
class Client;
namespace client {
class ClientGame : public game::Game, public protocol::PacketHandler {
private:
Client* m_Client;
game::LeaderBoard m_LeaderBoard;
protocol::PacketDispatcher& m_Dispatcher;
public:
ClientGame(Client* client, protocol::PacketDispatcher& dispatcher);
ClientGame(Client* client, protocol::PacketDispatcher* dispatcher);
virtual ~ClientGame();
void Tick(std::uint64_t delta) override;
virtual void Handle(const protocol::PlayerDeathPacket& packet) override;
virtual void Handle(const protocol::PlayerJoinPacket& packet) override;
virtual void Handle(const protocol::PlayerLeavePacket& packet) override;
virtual void Handle(const protocol::PlayerListPacket& packet) override;
virtual void Handle(const protocol::PlayerPositionAndRotationPacket& packet) override;
virtual void Handle(const protocol::PlayerShootPacket& packet) override;
virtual void Handle(const protocol::UpdateHealthPacket& packet) override;
virtual void Handle(const protocol::PlayerStatsPacket& packet) override;
virtual void Handle(const protocol::UpdateGameStatePacket& packet) override;
virtual void Handle(const protocol::ServerConfigPacket& packet) override;
virtual void AddPlayer(game::PlayerID player, const std::string& name) override;
virtual void RemovePlayer(game::PlayerID player) override;
const game::LeaderBoard& GetLeaderBoard() const {
return m_LeaderBoard;
}
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;
private:
void RegisterHandlers();
protocol::PacketDispatcher& GetDispatcher() {
return m_Dispatcher;
}
};
} // namespace client

View File

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

View File

@@ -1,6 +1,6 @@
#pragma once
#include "blitz/protocol/Color.h"
#include "blitz/protocol/packets/ChatPacket.h"
#include <string>
namespace blitz {

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@@ -1,40 +0,0 @@
#pragma once
#include "GuiWidget.h"
#include "client/Client.h"
namespace blitz {
namespace client {
class Client;
} // namespace client
namespace game {
class Player;
} // namespace game
namespace gui {
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* 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);
void DrawFinishScreen(bool win);
void RenderTime(float, float);
};
} // namespace gui
} // namespace blitz

View File

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

View File

@@ -1,30 +0,0 @@
#pragma once
#include "GuiWidget.h"
#include "client/Client.h"
namespace blitz {
namespace client {
class Client;
} // namespace client
namespace gui {
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* client);
~LeaderBoardGui();
virtual void OnGameStateUpdate(game::GameState gameState) override;
virtual void OnGameJoin() override;
virtual void OnGameLeave() override;
virtual void Render() override;
};
} // namespace gui
} // namespace blitz

View File

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

View File

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

View File

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

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