43 Commits
3D ... license

Author SHA1 Message Date
0efbd480ac Add LICENSE.txt
All checks were successful
Linux arm64 / Build (push) Successful in 11m20s
2024-05-23 17:25:13 +02:00
7c4ed3910f action: xmake latest
All checks were successful
Linux arm64 / Build (push) Successful in 1m4s
2024-02-24 13:06:56 +01:00
90c834cc49 Squashed commit of the following:
All checks were successful
Linux arm64 / Build (push) Successful in 6m2s
commit a8cbebc8d11d3621924b189a58a4f150d30324e9
Author: Simon Pribylski <sim16.prib@gmail.com>
Date:   Sat Feb 10 14:00:26 2024 +0100

    jsp

commit a00ae1f6d9db33efef5e276bfc7101a1d24cf7d8
Author: Simon Pribylski <sim16.prib@gmail.com>
Date:   Sat Feb 10 13:17:03 2024 +0100

    lol

commit d3dcaf3659251bb8fb0d4984ea188601a058757b
Author: Simon Pribylski <sim16.prib@gmail.com>
Date:   Sat Feb 10 13:02:12 2024 +0100

    zsdf

commit 8ce343ff361ba0618d09d488404ff15c7d19de66
Author: Simon Pribylski <sim16.prib@gmail.com>
Date:   Sat Feb 10 12:55:39 2024 +0100

    caca

commit 9f2a818ee57c751cb1283f12cfcc2c3617a3bd63
Author: Simon Pribylski <sim16.prib@gmail.com>
Date:   Sat Feb 10 12:38:20 2024 +0100

    remove run name

commit b618dc176980ef18ae9a04f43a8abef311ca4329
Author: Simon Pribylski <sim16.prib@gmail.com>
Date:   Sat Feb 10 12:20:35 2024 +0100

    change action name

commit 3092a403fdb2ded81d6f7558f621d0f8ac5dc1f5
Author: Simon Pribylski <sim16.prib@gmail.com>
Date:   Sat Feb 10 12:06:03 2024 +0100

    fix action typo

commit 0cd675ef6c42758bef182307cce55d74aa2959fe
Author: Simon Pribylski <sim16.prib@gmail.com>
Date:   Sat Feb 10 11:56:16 2024 +0100

    add action cache name

    Signed-off-by: Simon Pribylski <sim16.prib@gmail.com>

commit 4a6e6754f0a82a35fa4d6793321c7d27cb3e9f37
Author: Simon Pribylski <sim16.prib@gmail.com>
Date:   Sat Feb 10 11:28:48 2024 +0100

    remove ssl ignore

    Signed-off-by: Simon Pribylski <sim16.prib@gmail.com>

commit 1808ca96ec84390915ace0678bc824d92cc3d1b3
Author: Simon Pribylski <sim16.prib@gmail.com>
Date:   Mon Jan 1 13:29:10 2024 +0100

    change action name

commit 5a966bbe77463a93ab210cd4b6a122ab1d440486
Author: Simon Pribylski <sim16.prib@gmail.com>
Date:   Mon Jan 1 13:22:16 2024 +0100

    cpp standard global

commit 673d1457162dda9018712d0a19ac5b3954ad265f
Author: Simon Pribylski <sim16.prib@gmail.com>
Date:   Mon Jan 1 13:21:36 2024 +0100

    add glew dep

commit b64eb6dd3ef535183dd0620beeeaa99deb323c97
Author: Simon Pribylski <sim16.prib@gmail.com>
Date:   Mon Jan 1 13:16:23 2024 +0100

    confirm

commit 1bf8065179b74f3dd194e05739a064097bdc2ebd
Author: Simon Pribylski <sim16.prib@gmail.com>
Date:   Mon Jan 1 13:15:37 2024 +0100

    remove sudo

commit 2dc4ee69ebba3821916963a96621d6f8b59d4808
Author: Simon Pribylski <sim16.prib@gmail.com>
Date:   Mon Jan 1 13:09:55 2024 +0100

    install apt

commit 69574b9c5a5074c2fdf87dfc8c068d9c64f7704c
Author: Simon Pribylski <sim16.prib@gmail.com>
Date:   Mon Jan 1 10:31:11 2024 +0100

    add xmake cache

commit 4d7d04c6722ca8e94d10569f25ae582265866948
Author: Simon Pribylski <sim16.prib@gmail.com>
Date:   Mon Jan 1 01:21:45 2024 +0100

    aaaaaaaaaaaaaaaaaa

commit aa7dac26cd9900c676e4662fadb7832700a3363a
Author: Simon Pribylski <sim16.prib@gmail.com>
Date:   Mon Jan 1 01:13:08 2024 +0100

    fiiiiiiiiiiiiiix xmake root

commit 3604b44d04f492254911a0508e8555aca61b4d26
Author: Simon Pribylski <sim16.prib@gmail.com>
Date:   Mon Jan 1 01:05:43 2024 +0100

    fix xmake root

commit cfcb8d4df46c6febeca47dff2f0447048b8f68ad
Author: Simon Pribylski <sim16.prib@gmail.com>
Date:   Mon Jan 1 01:03:56 2024 +0100

    run xmake as root

commit dbef2d27138ccce1124cc1979867baf15e897a7f
Author: Simon Pribylski <sim16.prib@gmail.com>
Date:   Mon Jan 1 00:54:54 2024 +0100

    xmake action

commit 42196398ced1e7f38c0234d82dc7cd65ef7aeb6d
Author: Simon Pribylski <sim16.prib@gmail.com>
Date:   Mon Jan 1 00:53:29 2024 +0100

    xmake

commit 51256d8c15066120c2df3a72063856a0a47f8b59
Author: Simon Pribylski <sim16.prib@gmail.com>
Date:   Mon Jan 1 00:47:35 2024 +0100

    Fix Linux.yaml

    add cert

commit 9c024fa8eb92765aff3fb195ce7c8c10a1b49d0b
Author: Simon Pribylski <sim16.prib@gmail.com>
Date:   Sun Dec 31 22:34:54 2023 +0100

    Add Linux actions
2024-02-10 16:02:51 +01:00
d23761dc10 Squashed commit of the following:
Some checks failed
Linux arm / Build (push) Has been cancelled
commit 1808ca96ec84390915ace0678bc824d92cc3d1b3
Author: Simon Pribylski <sim16.prib@gmail.com>
Date:   Mon Jan 1 13:29:10 2024 +0100

    change action name

commit 5a966bbe77463a93ab210cd4b6a122ab1d440486
Author: Simon Pribylski <sim16.prib@gmail.com>
Date:   Mon Jan 1 13:22:16 2024 +0100

    cpp standard global

commit 673d1457162dda9018712d0a19ac5b3954ad265f
Author: Simon Pribylski <sim16.prib@gmail.com>
Date:   Mon Jan 1 13:21:36 2024 +0100

    add glew dep

commit b64eb6dd3ef535183dd0620beeeaa99deb323c97
Author: Simon Pribylski <sim16.prib@gmail.com>
Date:   Mon Jan 1 13:16:23 2024 +0100

    confirm

commit 1bf8065179b74f3dd194e05739a064097bdc2ebd
Author: Simon Pribylski <sim16.prib@gmail.com>
Date:   Mon Jan 1 13:15:37 2024 +0100

    remove sudo

commit 2dc4ee69ebba3821916963a96621d6f8b59d4808
Author: Simon Pribylski <sim16.prib@gmail.com>
Date:   Mon Jan 1 13:09:55 2024 +0100

    install apt

commit 69574b9c5a5074c2fdf87dfc8c068d9c64f7704c
Author: Simon Pribylski <sim16.prib@gmail.com>
Date:   Mon Jan 1 10:31:11 2024 +0100

    add xmake cache

commit 4d7d04c6722ca8e94d10569f25ae582265866948
Author: Simon Pribylski <sim16.prib@gmail.com>
Date:   Mon Jan 1 01:21:45 2024 +0100

    aaaaaaaaaaaaaaaaaa

commit aa7dac26cd9900c676e4662fadb7832700a3363a
Author: Simon Pribylski <sim16.prib@gmail.com>
Date:   Mon Jan 1 01:13:08 2024 +0100

    fiiiiiiiiiiiiiix xmake root

commit 3604b44d04f492254911a0508e8555aca61b4d26
Author: Simon Pribylski <sim16.prib@gmail.com>
Date:   Mon Jan 1 01:05:43 2024 +0100

    fix xmake root

commit cfcb8d4df46c6febeca47dff2f0447048b8f68ad
Author: Simon Pribylski <sim16.prib@gmail.com>
Date:   Mon Jan 1 01:03:56 2024 +0100

    run xmake as root

commit dbef2d27138ccce1124cc1979867baf15e897a7f
Author: Simon Pribylski <sim16.prib@gmail.com>
Date:   Mon Jan 1 00:54:54 2024 +0100

    xmake action

commit 42196398ced1e7f38c0234d82dc7cd65ef7aeb6d
Author: Simon Pribylski <sim16.prib@gmail.com>
Date:   Mon Jan 1 00:53:29 2024 +0100

    xmake

commit 51256d8c15066120c2df3a72063856a0a47f8b59
Author: Simon Pribylski <sim16.prib@gmail.com>
Date:   Mon Jan 1 00:47:35 2024 +0100

    Fix Linux.yaml

    add cert

commit 9c024fa8eb92765aff3fb195ce7c8c10a1b49d0b
Author: Simon Pribylski <sim16.prib@gmail.com>
Date:   Sun Dec 31 22:34:54 2023 +0100

    Add Linux actions
2024-02-10 15:49:25 +01:00
3d8fd2e519 refactor xmake.lua 2023-09-03 11:02:22 +02:00
4bd32e8d0b chore: bump version to alpha-0.4.0 2023-09-02 20:29:51 +02:00
09bba12814 prevent player from joining mid game 2023-09-02 20:27:26 +02:00
bb76e9493f sync player when joining mid game 2023-08-26 11:49:52 +02:00
Simon Pribylski
808ef7b3f6 moved player leave packet 2023-08-26 11:27:05 +02:00
Simon Pribylski
23938a0cb5 fix mob id 2023-08-26 11:21:28 +02:00
Simon Pribylski
5631efcf9e remove mobs on player leave 2023-08-26 10:46:20 +02:00
Simon Pribylski
8e7b446003 add RemoveMobPacket 2023-08-26 10:35:26 +02:00
Simon Pribylski
51ec035490 remove towers on player leave 2023-08-26 10:25:52 +02:00
1f94ae2586 use of SAFE_CHECK 2023-08-15 19:33:09 +02:00
7b8c13612c fix login crash 2023-08-15 19:32:44 +02:00
a36716d8e4 fix player login 2023-08-15 19:20:13 +02:00
debf9e974c useless cam functions 2023-08-15 19:19:54 +02:00
380ecf3a27 fixed server world upload 2023-08-15 13:47:56 +02:00
b3157be641 change lib name 2023-08-15 13:06:31 +02:00
1e3b672897 remove player from team when leaving 2023-08-15 13:01:50 +02:00
d1aa5cd8aa balance team on player join 2023-08-14 18:54:36 +02:00
dbe91b52fd send team update after restart 2023-08-14 18:41:51 +02:00
7ab8c79fdf changed player join/leave message 2023-08-14 18:34:07 +02:00
8f2a22762a fixing button crash 2023-08-14 18:33:41 +02:00
f0c3325141 name randomizer 2023-08-14 18:33:24 +02:00
1d00e0098a fix player sync 2023-08-14 18:18:43 +02:00
ee5a27ac54 show integrated server stats 2023-08-14 18:10:05 +02:00
49a5a09537 add restart command 2023-08-14 17:46:49 +02:00
f9f80fc4fb summon debug 2023-08-14 15:00:05 +02:00
4997715672 players stat reset after game end 2023-08-14 14:59:37 +02:00
3fe480d121 connection removal safety 2023-08-14 14:59:15 +02:00
c46226c1ae disconnect queue 2023-08-14 14:58:26 +02:00
8630421734 set summon menu cooldown 2023-08-14 14:29:41 +02:00
60b81003c0 Don't disconnect when game is over 2023-08-14 14:25:10 +02:00
7986e55846 fix persistent players 2023-08-14 13:59:30 +02:00
0c0fd155ed add client disconnect button 2023-08-14 13:46:10 +02:00
7f650f282c back to lobby state when server ends 2023-08-14 13:35:17 +02:00
118a04cd01 xmake.lua : add lib target 2023-08-14 13:31:52 +02:00
d529c79150 server console input 2023-08-13 13:44:05 +02:00
ddbba997e5 Working server 2023-08-13 12:38:32 +02:00
50c17e8ed1 restructure project 2023-08-13 11:59:13 +02:00
b4836847f5 fix WorldBeginDataPacket 2023-08-12 11:00:30 +02:00
f941862637 Packets Refactor
commit 497a601c424e8e728ef0a8e61f049982f2d4af16
Author: Persson-dev <sim16.prib@gmail.com>
Date:   Sat Aug 12 10:32:52 2023 +0200

    fix warning

commit 1bfd019a1ea00dcdb6323d1f285e2cdd3ebb4020
Author: Persson-dev <sim16.prib@gmail.com>
Date:   Tue Jul 25 19:05:13 2023 +0200

    refactor: update cast

commit 5bbc23a7d37e53eb74a885685f18e714f9448fd9
Author: Persson-dev <sim16.prib@gmail.com>
Date:   Tue Jul 25 19:04:15 2023 +0200

    moved GetImguiTeamColor

commit fd0e2d2470ea5cca3553acf280aa371de5c06f4c
Author: Persson-dev <sim16.prib@gmail.com>
Date:   Tue Jul 25 19:03:37 2023 +0200

    packets forward declaration

commit 06eb9b99a96731f4b9a2167c00ed0bcd03702e3b
Author: Persson-dev <sim16.prib@gmail.com>
Date:   Tue Jul 25 18:30:55 2023 +0200

    remove Protocol.h includes

commit 165f63d2e8b468f3e38992baddc221270010f801
Author: Persson-dev <sim16.prib@gmail.com>
Date:   Tue Jul 25 18:30:30 2023 +0200

    split packets into separate source files

commit f247f146c6c1e804a44b86f65cf3059859c07c6c
Author: Persson-dev <sim16.prib@gmail.com>
Date:   Tue Jul 25 17:45:24 2023 +0200

    split packets into separate headers
2023-08-12 10:41:39 +02:00
243 changed files with 2998 additions and 7015 deletions

View File

@@ -0,0 +1,32 @@
name: Linux arm64
run-name: Build And Test
on: [push]
jobs:
Build:
runs-on: ubuntu-latest
steps:
- name: Install deps
run : |
apt update
apt install -y libsdl2-dev libglew-dev
- name: Check out repository code
uses: actions/checkout@v3
- name: Prepare Xmake
uses: xmake-io/github-action-setup-xmake@v1
with:
xmake-version: latest
actions-cache-folder: '.xmake-cache'
actions-cache-key: 'ubuntu'
- name: XMake config
run: xmake f -p linux -y --root
- name: Build
run: xmake --root
- name: Test
run: xmake test --root

21
LICENSE.txt Normal file
View File

@@ -0,0 +1,21 @@
MIT License
Copyright (c) 2024 Simon Pribylski
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

View File

@@ -1,16 +1,17 @@
#pragma once
#include "ClientConnexion.h"
#include "ClientGame.h"
#include "client/ClientConnexion.h"
#include "client/game/ClientGame.h"
#include "game/Team.h"
#include "game/Player.h"
#include "td/game/Team.h"
#include "td/game/Player.h"
#include "protocol/Protocol.h"
#include "td/protocol/Protocol.h"
#include "td/protocol/packets/SendMobsPacket.h"
#include "render/Renderer.h"
#include "client/render/Renderer.h"
#include "network/Network.h"
#include "td/network/Network.h"
namespace td {
namespace client {

View File

@@ -1,8 +1,8 @@
#pragma once
#include "protocol/PacketHandler.h"
#include "network/TCPSocket.h"
#include "game/Connexion.h"
#include "td/protocol/PacketHandler.h"
#include "td/network/TCPSocket.h"
#include "td/network/Connexion.h"
namespace td {
namespace client {

View File

@@ -1,13 +1,13 @@
#pragma once
#include "game/BaseGame.h"
#include "td/game/BaseGame.h"
#include "protocol/PacketHandler.h"
#include "td/protocol/PacketHandler.h"
#include "WorldClient.h"
#include "render/WorldRenderer.h"
#include "render/Renderer.h"
#include "client/render/WorldRenderer.h"
#include "client/render/Renderer.h"
namespace td {
namespace client {

View File

@@ -1,7 +1,7 @@
#pragma once
#include "game/World.h"
#include "protocol/PacketHandler.h"
#include "td/game/World.h"
#include "td/protocol/PacketHandler.h"
namespace td {
namespace client {
@@ -13,12 +13,14 @@ private:
ClientGame* m_Game;
public:
WorldClient(ClientGame* game);
virtual ~WorldClient();
virtual void HandlePacket(const protocol::WorldBeginDataPacket* packet) override;
virtual void HandlePacket(const protocol::WorldDataPacket* packet) override;
virtual void HandlePacket(const protocol::SpawnMobPacket* packet) override;
virtual void HandlePacket(const protocol::UpgradeTowerPacket* packet) override;
virtual void HandlePacket(const protocol::WorldAddTowerPacket* packet) override;
virtual void HandlePacket(const protocol::RemoveMobPacket* packet) override;
virtual void HandlePacket(const protocol::RemoveTowerPacket* packet) override;
virtual void HandlePacket(const protocol::UpdateMobStatesPacket* packet) override;
virtual void HandlePacket(const protocol::UpdateCastleLifePacket* packet) override;

View File

@@ -1,10 +1,10 @@
#pragma once
#include "Defines.h"
#include "td/Defines.h"
#include <memory>
#include "loader/GLLoader.h"
#include "render/shaders/WorldShader.h"
#include "render/shaders/EntityShader.h"
#include "client/render/shaders/WorldShader.h"
#include "client/render/shaders/EntityShader.h"
namespace td {
namespace render {
@@ -23,41 +23,16 @@ struct Camera {
float m_Pitch = -PI / 2.0f + 0.0000001f;
};
struct Model {
std::unique_ptr<GL::VertexArray> vao;
Vec3f positon;
Vec3f color = { 1, 1, 1 };
};
class TexturedModel {
private:
std::unique_ptr<GL::VertexArray> m_Vao;
std::unique_ptr<GL::Texture> m_Texture;
Vec3f m_Positon;
Vec3f m_Color = { 1, 1, 1 };
public:
REMOVE_COPY(TexturedModel);
TexturedModel(GL::VertexArray&& vao, GL::Texture&& texture);
TexturedModel(TexturedModel&& other);
~TexturedModel() {}
const GL::VertexArray& GetVao() const { return *m_Vao; }
const GL::Texture& GetTexture() const { return *m_Texture; }
Vec3f GetPosition() const { return m_Positon; }
Vec3f GetColor() const { return m_Color; }
void SetPosition(Vec3f newPos) { m_Positon = newPos; }
void SetColor(Vec3f newColor) { m_Color = newColor; }
};
class Renderer {
public:
static constexpr float m_AnimationSpeed = 2.0f;
static constexpr float m_MouseSensitivity = 200.0f;
struct Model {
GL::VertexArray* vao;
Vec3f positon;
Vec3f color = { 1, 1, 1 };
};
private:
std::unique_ptr<shader::WorldShader> m_WorldShader;
std::unique_ptr<shader::EntityShader> m_EntityShader;
@@ -78,12 +53,12 @@ public:
void RenderVAO(const GL::VertexArray& vao);
void RenderModel(const Model& model);
void RenderModel(const TexturedModel& model);
void AddZoom(float zoom);
void SetCamAngularMovement(const Vec2f& mov);
void SetCamMovement(const Vec2f& lastCursorPos, const Vec2f& currentCursorPos);
void SetCamLook(const Vec2f& worldPos);
void ResetCamLook();
void SetBackgroundColor(const Vec3f& color) { m_BackgroundColor = color; }

View File

@@ -2,7 +2,7 @@
#include <cstdint>
#include <memory>
#include "render/loader/GLLoader.h"
#include "client/render/loader/GLLoader.h"
namespace td {

View File

@@ -1,16 +1,14 @@
#pragma once
#include "game/World.h"
#include "td/game/World.h"
#include "render/Renderer.h"
#include "render/VertexCache.h"
#include "client/render/Renderer.h"
#include "client/render/VertexCache.h"
#include "render/gui/TowerPlacePopup.h"
#include "render/gui/TowerUpgradePopup.h"
#include "render/gui/MobTooltip.h"
#include "render/gui/CastleTooltip.h"
#include "render/gui/imgui/imgui.h"
#include "client/render/gui/TowerPlacePopup.h"
#include "client/render/gui/TowerUpgradePopup.h"
#include "client/render/gui/MobTooltip.h"
#include "client/render/gui/CastleTooltip.h"
namespace td {
@@ -20,7 +18,6 @@ class ClientGame;
} // namespace client
namespace render {
class WorldRenderer : public game::WorldListener {
@@ -28,9 +25,7 @@ private:
client::ClientGame* m_Client;
Renderer* m_Renderer;
game::World* m_World;
std::unique_ptr<GL::VertexArray> m_WorldVao;
std::unique_ptr<Model> m_SelectTileModel;
std::vector<TexturedModel> m_MobModels;
std::unique_ptr<GL::VertexArray> m_WorldVao, m_MobVao, m_SelectTileVao;
Vec2f m_CamPos;
Vec2f m_CursorPos;
Vec2f m_HoldCursorPos;
@@ -50,11 +45,10 @@ public:
void LoadModels();
static ImVec4 GetImGuiTeamColor(game::TeamColor color);
void Update();
void Render();
void ResetCam();
void SetCamPos(float camX, float camY);
void MoveCam(float relativeX, float relativeY);
@@ -68,7 +62,7 @@ private:
void Click();
void RenderWorld() const;
void RenderTowers() const;
void RenderMobs();
void RenderMobs() const;
void RenderTileSelect() const;
void RenderPopups();
void RenderMobTooltip() const;

View File

@@ -1,16 +1,19 @@
#pragma once
#include "SummonMenu.h"
#include "td/game/BaseGame.h"
namespace td {
namespace gui {
class GameMenu : public GuiWidget {
class GameMenu : public GuiWidget, public game::GameListener {
private:
std::unique_ptr<SummonMenu> m_SummonMenu;
public:
GameMenu(client::Client* client);
virtual void OnGameBegin();
virtual void Render();
private:
void ShowTPS();
@@ -18,6 +21,8 @@ private:
void ShowPlayers();
void ShowLobbyProgress();
void ShowTeamSelection();
void DisconnectButton();
};
} // namespace gui

View File

@@ -0,0 +1,13 @@
#pragma once
#include "client/render/gui/imgui/imgui.h"
#include "td/game/Team.h"
namespace td {
namespace render {
ImVec4 GetImGuiTeamColor(game::TeamColor color);
} // namespace render
} // namespace td

View File

@@ -4,13 +4,15 @@
#include "imgui/imgui_filebrowser.h"
#include "game/server/Server.h"
#include "server/Server.h"
#include <memory>
namespace td {
namespace gui {
class ServerGui;
class MainMenu : public GuiWidget {
private:
bool m_TriedToConnect = false;
@@ -22,6 +24,7 @@ private:
imgui_addons::ImGuiFileBrowser m_FileDialog;
std::unique_ptr<server::Server> m_Server;
std::unique_ptr<ServerGui> m_ServerGui;
public:
MainMenu(client::Client* client);
~MainMenu();

View File

@@ -0,0 +1,19 @@
#pragma once
#include "GuiWidget.h"
#include "server/Server.h"
namespace td {
namespace gui {
class ServerGui : public GuiWidget {
private:
server::Server* m_Server;
public:
ServerGui(client::Client* client, server::Server* server);
virtual void Render();
};
} // namespace gui
} // namespace td

View File

@@ -3,7 +3,7 @@
#include "GuiWidget.h"
#include <array>
#include "game/Mobs.h"
#include "td/game/Mobs.h"
namespace td {
namespace gui {

View File

@@ -9,7 +9,7 @@
#include <memory>
#include "render/gui/GuiManager.h"
#include "client/render/gui/GuiManager.h"
struct SDL_Window;
typedef void* SDL_GLContext;

View File

@@ -2,7 +2,7 @@
#include "GuiWidget.h"
#include "Defines.h"
#include "td/Defines.h"
namespace td {
namespace gui {

View File

@@ -2,7 +2,7 @@
#include "GuiWidget.h"
#include "Defines.h"
#include "td/Defines.h"
namespace td {
namespace gui {

View File

@@ -107,7 +107,7 @@ namespace ImGui
}
*/
#include "render/GL.h"
#include "client/render/GL.h"
#if defined(__ANDROID__)
#define IMGUI_IMPL_OPENGL_LOADER_ES3

View File

@@ -1,7 +1,7 @@
#ifndef IMGUIFILEBROWSER_H
#define IMGUIFILEBROWSER_H
#include "render/gui/imgui/imgui.h"
#include "client/render/gui/imgui/imgui.h"
#include <string>
#include <vector>

View File

@@ -70,24 +70,5 @@ public:
void Unbind() const;
};
class Texture {
private:
unsigned int m_ID;
public:
REMOVE_COPY(Texture);
Texture(Texture&& other) {
m_ID = other.m_ID;
other.m_ID = 0;
}
Texture(const char* textureData, int width, int height, int comp);
~Texture();
unsigned int GetTextureID() const { return m_ID; }
void Bind() const;
static void Unbind();
};
}

View File

@@ -8,12 +8,9 @@
#ifndef RENDER_LOADER_TEXTURELOADER_H_
#define RENDER_LOADER_TEXTURELOADER_H_
#include "render/loader/GLLoader.h"
#include <string>
namespace TextureLoader {
GL::Texture LoadTexture(const std::string& fileName);
unsigned int LoadGLTexture(const char* fileName);
}

View File

@@ -1,6 +1,6 @@
#pragma once
#include "game/World.h"
#include "td/game/World.h"
#include "GLLoader.h"
namespace td {

View File

@@ -1,8 +1,8 @@
#pragma once
#include <string>
#include "Defines.h"
#include "render/GL.h"
#include "td/Defines.h"
#include "client/render/GL.h"
namespace td {
namespace shader {

View File

@@ -1,8 +1,8 @@
#pragma once
#include "misc/DataBuffer.h"
#include "td/misc/DataBuffer.h"
#define TD_VERSION "alpha-0.3.0"
#define TD_VERSION "alpha-0.4.0"
namespace td {
namespace utils {

View File

@@ -1,639 +0,0 @@
#pragma once
#include "misc/DataBuffer.h"
#include "game/World.h"
#include "game/BaseGame.h"
#include <memory>
namespace td {
namespace protocol {
class PacketHandler;
enum class PacketType : std::uint8_t {
// client --> server
PlayerLogin = 0,
SelectTeam,
SpawnMob,
SendMobs,
PlaceTower,
// client <-- server
PlayerJoin,
PlayerLeave,
WorldBeginData,
WorldData,
UpdateMoney,
UpdateEXP,
UpdateLobbyTime,
UpdateGameState,
PlayerList,
ConnectionInfo,
UpdatePlayerTeam,
ServerTps,
WorldAddTower,
UpdateMobStates,
UpdateCastleLife,
// client <--> server
KeepAlive,
Disconnect,
UpgradeTower,
RemoveTower,
PlayerBuyItem,
PlayerBuyMobUpgrade,
PACKET_COUNT
};
struct WorldHeader {
game::TowerTileColorPalette m_TowerPlacePalette;
Color m_WalkablePalette;
std::vector<Color> m_DecorationPalette;
Color m_Background;
game::SpawnColorPalette m_SpawnColorPalette;
game::TilePalette m_TilePalette;
game::Spawn m_RedSpawn, m_BlueSpawn;
game::TeamCastle m_RedCastle, m_BlueCastle;
const game::World* m_World;
};
struct WorldData {
std::unordered_map<game::ChunkCoord, game::ChunkPtr> m_Chunks;
};
class Packet {
public:
Packet() {}
virtual ~Packet() {}
virtual DataBuffer Serialize(bool packetID = true) const = 0;
virtual void Deserialize(DataBuffer& data) = 0;
virtual void Dispatch(PacketHandler* handler) const = 0;
void WritePacketID(DataBuffer& data, bool packetID) const;
virtual PacketType GetType() const = 0;
std::uint8_t GetID() const { return static_cast<std::uint8_t>(GetType()); }
};
typedef std::unique_ptr<Packet> PacketPtr;
class KeepAlivePacket : public Packet {
private:
std::uint64_t 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;
std::uint64_t GetAliveID() const { return m_AliveID; }
virtual PacketType GetType() const { return PacketType::KeepAlive; }
};
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; }
const std::string& GetPlayerName() const { return m_PlayerName; }
};
class WorldBeginDataPacket : public Packet {
private:
WorldHeader m_Header;
public:
WorldBeginDataPacket() {}
WorldBeginDataPacket(const game::World* world) {
m_Header.m_World = world;
}
virtual ~WorldBeginDataPacket() {}
virtual DataBuffer Serialize(bool packetID = true) const;
virtual void Deserialize(DataBuffer& data);
virtual void Dispatch(PacketHandler* handler) const;
virtual PacketType GetType() const { return PacketType::WorldBeginData; }
const game::TowerTileColorPalette& GetTowerTilePalette() const { return m_Header.m_TowerPlacePalette; }
const Color& GetWalkableTileColor() const { return m_Header.m_WalkablePalette; }
const std::vector<Color>& GetDecorationPalette() const { return m_Header.m_DecorationPalette; }
const Color& GetBackgroundColor() const { return m_Header.m_Background; }
const game::Spawn& GetRedSpawn() const { return m_Header.m_RedSpawn; }
const game::Spawn& GetBlueSpawn() const { return m_Header.m_BlueSpawn; }
const game::SpawnColorPalette& GetSpawnPalette() const { return m_Header.m_SpawnColorPalette; }
const game::TeamCastle& GetRedCastle() const { return m_Header.m_RedCastle; }
const game::TeamCastle& GetBlueCastle() const { return m_Header.m_BlueCastle; }
const game::TilePalette GetTilePalette() const { return m_Header.m_TilePalette; }
void setWorldHeader(const WorldHeader& header) { m_Header = header; }
};
class WorldDataPacket : public Packet {
private:
WorldData m_WorldData;
const game::World* m_World;
public:
WorldDataPacket() {}
WorldDataPacket(const game::World* world) : m_World(world) {}
virtual ~WorldDataPacket() {}
virtual DataBuffer Serialize(bool packetID = true) const;
virtual void Deserialize(DataBuffer& data);
virtual void Dispatch(PacketHandler* handler) const;
virtual PacketType GetType() const { return PacketType::WorldData; }
const std::unordered_map<game::ChunkCoord, game::ChunkPtr>& GetChunks() const { return m_WorldData.m_Chunks; }
DataBuffer SerializeCustom() const; // allow serialisation with invalid World member
void SetWorldData(const WorldData& worldData) { m_WorldData = worldData; }
};
class UpdateMoneyPacket : public Packet {
private:
std::uint32_t m_NewAmount;
public:
UpdateMoneyPacket() {}
UpdateMoneyPacket(std::uint32_t newAmount) : m_NewAmount(newAmount) {}
virtual ~UpdateMoneyPacket() {}
std::uint32_t GetGold() const { return m_NewAmount; }
virtual DataBuffer Serialize(bool packetID = true) const;
virtual void Deserialize(DataBuffer& data);
virtual void Dispatch(PacketHandler* handler) const;
virtual PacketType GetType() const { return PacketType::UpdateMoney; }
};
class UpdateExpPacket : public Packet {
private:
std::uint32_t m_NewAmount;
public:
UpdateExpPacket() {}
UpdateExpPacket(std::uint32_t newAmount) : m_NewAmount(newAmount) {}
virtual ~UpdateExpPacket() {}
std::uint32_t GetExp() const { return m_NewAmount; }
virtual DataBuffer Serialize(bool packetID = true) const;
virtual void Deserialize(DataBuffer& data);
virtual void Dispatch(PacketHandler* handler) const;
virtual PacketType GetType() const { return PacketType::UpdateEXP; }
};
class UpdateLobbyTimePacket : public Packet {
private:
std::uint32_t m_RemainingTime;
public:
UpdateLobbyTimePacket() {}
UpdateLobbyTimePacket(std::uint32_t remainingTime) : m_RemainingTime(remainingTime) {}
virtual ~UpdateLobbyTimePacket() {}
virtual DataBuffer Serialize(bool packetID = true) const;
virtual void Deserialize(DataBuffer& data);
virtual void Dispatch(PacketHandler* handler) const;
std::uint32_t GetRemainingTime() const { return m_RemainingTime; }
virtual PacketType GetType() const { return PacketType::UpdateLobbyTime; }
};
class UpdateGameStatePacket : public Packet {
private:
game::GameState m_GameState;
public:
UpdateGameStatePacket() {}
UpdateGameStatePacket(game::GameState gameState) : m_GameState(gameState) {}
virtual ~UpdateGameStatePacket() {}
virtual DataBuffer Serialize(bool packetID = true) const;
virtual void Deserialize(DataBuffer& data);
virtual void Dispatch(PacketHandler* handler) const;
game::GameState GetGameState() const { return m_GameState; }
virtual PacketType GetType() const { return PacketType::UpdateGameState; }
};
struct PlayerInfo {
std::string name;
game::TeamColor team;
};
class PlayerListPacket : public Packet {
private:
std::map<std::uint8_t, PlayerInfo> m_Players;
public:
PlayerListPacket() {}
PlayerListPacket(std::map<std::uint8_t, PlayerInfo> 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 std::map<std::uint8_t, PlayerInfo>& GetPlayers() const { return m_Players; }
virtual PacketType GetType() const { return PacketType::PlayerList; }
};
class PlayerJoinPacket : public Packet {
private:
std::uint8_t m_PlayerID;
std::string m_PlayerName;
public:
PlayerJoinPacket() {}
PlayerJoinPacket(std::uint8_t 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;
std::uint8_t GetPlayerID() const { return m_PlayerID; }
const std::string& GetPlayerName() const { return m_PlayerName; }
virtual PacketType GetType() const { return PacketType::PlayerJoin; }
};
class PlayerLeavePacket : public Packet {
private:
std::uint8_t 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; }
};
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;
std::uint8_t GetConnectionID() const { return m_ConnectionID; }
virtual PacketType GetType() const { return PacketType::ConnectionInfo; }
};
class SelectTeamPacket : public Packet {
private:
game::TeamColor m_SelectedTeam;
public:
SelectTeamPacket() {}
SelectTeamPacket(game::TeamColor selectedTeam) : m_SelectedTeam(selectedTeam) {}
virtual ~SelectTeamPacket() {}
virtual DataBuffer Serialize(bool packetID = true) const;
virtual void Deserialize(DataBuffer& data);
virtual void Dispatch(PacketHandler* handler) const;
game::TeamColor GetSelectedTeam() const { return m_SelectedTeam; }
virtual PacketType GetType() const { return PacketType::SelectTeam; }
};
class UpdatePlayerTeamPacket : public Packet {
private:
std::uint8_t m_PlayerID;
game::TeamColor m_SelectedTeam;
public:
UpdatePlayerTeamPacket() {}
UpdatePlayerTeamPacket(std::uint8_t playerID, game::TeamColor selectedTeam) : m_PlayerID(playerID), m_SelectedTeam(selectedTeam) {}
virtual ~UpdatePlayerTeamPacket() {}
virtual DataBuffer Serialize(bool packetID = true) const;
virtual void Deserialize(DataBuffer& data);
virtual void Dispatch(PacketHandler* handler) const;
game::TeamColor GetSelectedTeam() const { return m_SelectedTeam; }
std::uint8_t GetPlayerID() const { return m_PlayerID; }
virtual PacketType GetType() const { return PacketType::UpdatePlayerTeam; }
};
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;
const std::string& GetReason() const { return m_Reason; }
virtual PacketType GetType() const { return PacketType::Disconnect; }
};
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;
float GetTPS() const { return m_TPS; }
float GetMSPT() const { return m_MSPT; }
std::uint64_t GetPacketSendTime() const { return m_PacketSendTime; }
virtual PacketType GetType() const { return PacketType::ServerTps; }
};
struct MobSend { // represents a mob send
game::MobType mobType : 4;
game::MobLevel mobLevel : 4;
std::uint8_t mobCount; // the max is 12
};
class SendMobsPacket : public Packet {
private:
std::vector<MobSend> m_MobSends;
public:
SendMobsPacket() {}
SendMobsPacket(const std::vector<MobSend>& mobSends) : m_MobSends(mobSends) {}
virtual ~SendMobsPacket() {}
virtual DataBuffer Serialize(bool packetID = true) const;
virtual void Deserialize(DataBuffer& data);
virtual void Dispatch(PacketHandler* handler) const;
const std::vector<MobSend>& GetMobSends() const { return m_MobSends; }
virtual PacketType GetType() const { return PacketType::SendMobs; }
};
class SpawnMobPacket : public Packet {
private:
game::MobID m_MobID;
game::MobType m_MobType;
game::MobLevel m_MobLevel;
game::Direction m_MobDirection;
game::PlayerID m_Sender;
float m_MobX, m_MobY;
public:
SpawnMobPacket() {}
SpawnMobPacket(game::MobID id, game::MobType type, std::uint8_t level, game::PlayerID sender,
float x, float y, game::Direction dir) : m_MobID(id), m_MobType(type), m_MobLevel(level),
m_MobDirection(dir), m_Sender(sender), m_MobX(x), m_MobY(y) {
}
virtual ~SpawnMobPacket() {}
virtual DataBuffer Serialize(bool packetID = true) const;
virtual void Deserialize(DataBuffer& data);
virtual void Dispatch(PacketHandler* handler) const;
game::MobID GetMobID() const { return m_MobID; }
game::MobType GetMobType() const { return m_MobType; }
game::MobLevel GetMobLevel() const { return m_MobLevel; }
game::Direction GetMobDirection() const { return m_MobDirection; }
game::PlayerID GetSender() const { return m_Sender; }
float GetMobX() const { return m_MobX; }
float GetMobY() const { return m_MobY; }
virtual PacketType GetType() const { return PacketType::SpawnMob; }
};
class PlaceTowerPacket : public Packet {
private:
std::int32_t m_TowerX, m_TowerY;
game::TowerType m_TowerType;
public:
PlaceTowerPacket() {}
PlaceTowerPacket(std::int32_t x, std::int32_t y, game::TowerType type) :
m_TowerX(x), m_TowerY(y), m_TowerType(type) {
}
virtual ~PlaceTowerPacket() {}
virtual DataBuffer Serialize(bool packetID = true) const;
virtual void Deserialize(DataBuffer& data);
virtual void Dispatch(PacketHandler* handler) const;
std::int32_t GetTowerX() const { return m_TowerX; }
std::int32_t GetTowerY() const { return m_TowerY; }
game::TowerType GetTowerType() const { return m_TowerType; }
virtual PacketType GetType() const { return PacketType::PlaceTower; }
};
class WorldAddTowerPacket : public Packet {
private:
game::TowerID m_TowerID;
std::int32_t m_TowerX, m_TowerY;
game::TowerType m_TowerType;
game::PlayerID m_Builder;
public:
WorldAddTowerPacket() {}
WorldAddTowerPacket(game::TowerID id, std::int32_t x, std::int32_t y, game::TowerType type, game::PlayerID player) :
m_TowerID(id), m_TowerX(x), m_TowerY(y), m_TowerType(type), m_Builder(player) {
}
virtual ~WorldAddTowerPacket() {}
virtual DataBuffer Serialize(bool packetID = true) const;
virtual void Deserialize(DataBuffer& data);
virtual void Dispatch(PacketHandler* handler) const;
game::TowerID GetTowerID() const { return m_TowerID; }
std::int32_t GetTowerX() const { return m_TowerX; }
std::int32_t GetTowerY() const { return m_TowerY; }
game::TowerType GetTowerType() const { return m_TowerType; }
game::PlayerID GetBuilder() const { return m_Builder; }
virtual PacketType GetType() const { return PacketType::WorldAddTower; }
};
class RemoveTowerPacket : public Packet {
private:
game::TowerID m_TowerID;
public:
RemoveTowerPacket() {}
RemoveTowerPacket(game::TowerID id) : m_TowerID(id) {}
virtual ~RemoveTowerPacket() {}
virtual DataBuffer Serialize(bool packetID = true) const;
virtual void Deserialize(DataBuffer& data);
virtual void Dispatch(PacketHandler* handler) const;
game::TowerID GetTowerID() const { return m_TowerID; }
virtual PacketType GetType() const { return PacketType::RemoveTower; }
};
class UpgradeTowerPacket : public Packet {
private:
game::TowerID m_TowerID;
game::TowerLevel m_TowerLevel;
public:
UpgradeTowerPacket() {}
UpgradeTowerPacket(game::TowerID tower, game::TowerLevel level) : m_TowerID(tower), m_TowerLevel(level) {}
virtual ~UpgradeTowerPacket() {}
virtual DataBuffer Serialize(bool packetID = true) const;
virtual void Deserialize(DataBuffer& data);
virtual void Dispatch(PacketHandler* handler) const;
game::TowerID GetTowerID() const { return m_TowerID; }
game::TowerLevel GetTowerLevel() const { return m_TowerLevel; }
virtual PacketType GetType() const { return PacketType::UpgradeTower; }
};
class MobState {
using Point = utils::shape::Point;
private:
game::MobID m_MobID;
Point m_MobPosition;
float m_MobLife;
game::Direction m_MobDirection;
public:
MobState() {}
MobState(game::MobID id, const Point& position, float life, game::Direction direction) :
m_MobID(id), m_MobPosition(position), m_MobLife(life), m_MobDirection(direction) {
}
game::MobID GetMobId() const { return m_MobID; }
Point GetMobPosition() const { return m_MobPosition; }
float GetMobLife() const { return m_MobLife; }
game::Direction GetMobDirection() const { return m_MobDirection; }
};
class UpdateMobStatesPacket : public Packet {
private:
std::vector<MobState> m_MobStates;
public:
UpdateMobStatesPacket() {}
virtual ~UpdateMobStatesPacket() {}
virtual DataBuffer Serialize(bool packetID = true) const;
virtual void Deserialize(DataBuffer& data);
virtual void Dispatch(PacketHandler* handler) const;
void addMobState(MobState mobState) { m_MobStates.push_back(mobState); }
const std::vector<MobState>& GetMobStates() const { return m_MobStates; }
virtual PacketType GetType() const { return PacketType::UpdateMobStates; }
};
class UpdateCastleLifePacket : public Packet {
private:
std::uint16_t m_CastleLife;
game::TeamColor m_Team;
public:
UpdateCastleLifePacket() {}
UpdateCastleLifePacket(std::uint16_t life, game::TeamColor team) : m_CastleLife(life), m_Team(team) {}
virtual ~UpdateCastleLifePacket() {}
virtual DataBuffer Serialize(bool packetID = true) const;
virtual void Deserialize(DataBuffer& data);
virtual void Dispatch(PacketHandler* handler) const;
std::uint16_t GetCastleLife() const { return m_CastleLife; }
game::TeamColor GetTeamColor() const { return m_Team; }
virtual PacketType GetType() const { return PacketType::UpdateCastleLife; }
};
enum class ItemType : std::uint8_t {
// Upgrades
ClickerUpgrade,
GoldPerSecUpgrade,
// Items
};
/** Packet used by the client to buy items or upgrades
Packet used by the server to confirm transaction */
class PlayerBuyItemPacket : public Packet {
private:
ItemType m_ItemType;
std::uint8_t m_Count;
public:
PlayerBuyItemPacket() {}
PlayerBuyItemPacket(ItemType itemType, std::uint8_t count) : m_ItemType(itemType), m_Count(count) {}
virtual ~PlayerBuyItemPacket() {}
virtual DataBuffer Serialize(bool packetID = true) const;
virtual void Deserialize(DataBuffer& data);
virtual void Dispatch(PacketHandler* handler) const;
ItemType GetItemType() const { return m_ItemType; }
std::uint8_t GetCount() const { return m_Count; }
virtual PacketType GetType() const { return PacketType::PlayerBuyItem; }
};
/** Packet used by the client to buy mob upgrades
Packet used by the server to confirm transaction */
class PlayerBuyMobUpgradePacket : public Packet {
private:
game::MobType m_MobType;
std::uint8_t m_MobLevel;
public:
PlayerBuyMobUpgradePacket() {}
PlayerBuyMobUpgradePacket(game::MobType mobType, std::uint8_t level) : m_MobType(mobType), m_MobLevel(level) {}
virtual ~PlayerBuyMobUpgradePacket() {}
virtual DataBuffer Serialize(bool packetID = true) const;
virtual void Deserialize(DataBuffer& data);
virtual void Dispatch(PacketHandler* handler) const;
game::MobType GetMobType() const { return m_MobType; }
std::uint8_t GetLevel() const { return m_MobLevel; }
virtual PacketType GetType() const { return PacketType::PlayerBuyMobUpgrade; }
};
} // namespace protocol
} // namespace td

View File

@@ -1,17 +0,0 @@
#pragma once
#include "GLLoader.h"
#include "render/Renderer.h"
#include "game/Mobs.h"
namespace td {
namespace render {
namespace MobLoader {
TexturedModel LoadMobModel(game::MobType mobType);
} // namespace MobLoader
} // namespace render
} // namespace td

View File

@@ -2,7 +2,7 @@
#include <vector>
#include "misc/Time.h"
#include "td/misc/Time.h"
namespace td {
namespace server {
@@ -12,7 +12,7 @@ class Server;
class Lobby {
private:
Server* m_Server;
bool m_GameStarted = false;
bool m_LobbyOpened = false;
std::uint64_t m_StartTimerTime = 0;
std::vector<std::uint8_t> m_Players;
utils::AutoTimer m_Timer;
@@ -22,6 +22,8 @@ public:
void OnPlayerJoin(std::uint8_t playerID);
void OnPlayerLeave(std::uint8_t playerID);
void OpenLobby();
void SendTimeRemaining();
void Tick();

View File

@@ -3,13 +3,13 @@
#include <map>
#include <thread>
#include "network/TCPListener.h"
#include "protocol/Protocol.h"
#include "protocol/PacketDispatcher.h"
#include "protocol/PacketHandler.h"
#include "ServerGame.h"
#include "ServerConnexion.h"
#include "Lobby.h"
#include "td/network/TCPListener.h"
#include "td/protocol/Protocol.h"
#include "td/protocol/PacketDispatcher.h"
#include "td/protocol/PacketHandler.h"
#include "server/game/ServerGame.h"
#include "server/ServerConnexion.h"
#include "server/Lobby.h"
#define SERVER_TPS 20
#define SERVER_TICK 1000 / SERVER_TPS
@@ -63,17 +63,23 @@ private:
std::thread m_Thread;
bool m_ServerRunning;
public:
Server(const std::string& worldFilePath);
Server();
virtual ~Server();
bool Start(std::uint16_t port);
bool Start(std::uint16_t port, bool blocking);
void Stop(); // force the server to stop
void Close(); // at the end of a game
void Restart(); // go back to lobby state
bool LoadMap(const std::string& worldFilePath);
bool IsMapLoaded();
void RemoveConnexion(std::uint8_t connexionID);
void BroadcastPacket(const protocol::Packet* packet);
float GetMSPT() const { return m_TickCounter.GetMSPT(); }
float GetTPS() const { return m_TickCounter.GetTPS(); }
bool IsRunning() { return m_ServerRunning; }
@@ -95,6 +101,7 @@ private:
void Clean();
void StartThread();
void StopThread();
void ServerLoop();
void Tick(std::uint64_t delta);
void OnPlayerJoin(std::uint8_t id);

View File

@@ -1,10 +1,10 @@
#pragma once
#include "network/TCPSocket.h"
#include "protocol/PacketHandler.h"
#include "protocol/PacketDispatcher.h"
#include "game/Player.h"
#include "game/Connexion.h"
#include "td/network/TCPSocket.h"
#include "td/protocol/PacketHandler.h"
#include "td/protocol/PacketDispatcher.h"
#include "td/game/Player.h"
#include "td/network/Connexion.h"
namespace td {
namespace server {

View File

@@ -1,7 +1,7 @@
#pragma once
#include "game/BaseGame.h"
#include "misc/Time.h"
#include "td/game/BaseGame.h"
#include "td/misc/Time.h"
#include "ServerWorld.h"
namespace td {
@@ -23,6 +23,8 @@ public:
ServerWorld* GetServerWorld() { return &m_ServerWorld; }
virtual void Tick(std::uint64_t delta);
virtual void Reset() override;
void StartGame();
// GameListener
@@ -31,6 +33,9 @@ public:
virtual void OnGameBegin() override;
virtual void OnGameEnd() override;
virtual void OnGameClose() override;
virtual void OnPlayerJoin(game::PlayerID id) override;
virtual void OnPlayerLeave(game::PlayerID id) override;
private:
void BalanceTeams();
void InitPlayerStats();

View File

@@ -1,6 +1,6 @@
#pragma once
#include "game/World.h"
#include "td/game/World.h"
namespace td {
namespace server {

View File

@@ -2,6 +2,9 @@
#include <cstdint>
#define SAFE_CHECK(expr) if(!(expr)) return
namespace td {
static constexpr float PI = 3.141592653f;

View File

@@ -1,8 +1,8 @@
#pragma once
#include "game/Team.h"
#include "game/World.h"
#include "game/Player.h"
#include "td/game/Team.h"
#include "td/game/World.h"
#include "td/game/Player.h"
namespace td {
namespace game {
@@ -42,6 +42,8 @@ public:
virtual void Tick(std::uint64_t delta);
virtual void Reset();
Team& GetRedTeam() { return m_Teams[static_cast<std::uint8_t>(TeamColor::Red)]; }
const Team& GetRedTeam() const { return m_Teams[static_cast<std::uint8_t>(TeamColor::Red)]; }
@@ -65,6 +67,8 @@ public:
const TeamList& GetTeams() const { return m_Teams; }
void RemovePlayer(PlayerID pId);
};
} // namespace game

View File

@@ -1,11 +1,11 @@
#pragma once
#include "Defines.h"
#include "td/Defines.h"
#include "Towers.h"
#include "Types.h"
#include "Team.h"
#include "misc/ObjectNotifier.h"
#include "td/misc/ObjectNotifier.h"
#include <vector>
#include <memory>
@@ -99,7 +99,7 @@ private:
utils::CooldownTimer m_AttackTimer;
public:
Mob(MobID id, MobLevel level, PlayerID sender) : m_Sender(sender), m_Level(level),
Mob(MobID id, MobLevel level, PlayerID sender) : m_ID(id), m_Sender(sender), m_Level(level),
m_HitCooldown(0), m_EffectFireTimer(1000), m_EffectPoisonTimer(1000),
m_EffectHealTimer(1000), m_CastleTarget(nullptr), m_AttackTimer(1000) {

View File

@@ -2,8 +2,8 @@
#include <string>
#include "game/Team.h"
#include "game/PlayerUpgrades.h"
#include "td/game/Team.h"
#include "td/game/PlayerUpgrades.h"
namespace td {
namespace game {

View File

@@ -2,7 +2,7 @@
#include "Types.h"
#include "misc/Shapes.h"
#include "td/misc/Shapes.h"
#include <vector>
#include <memory>
@@ -74,6 +74,7 @@ public:
void AddPlayer(Player* newPlayer);
void RemovePlayer(const Player* player);
void ClearPlayers();
TeamColor GetColor() const;

View File

@@ -3,10 +3,10 @@
#include <string>
#include <memory>
#include "misc/Time.h"
#include "misc/Shapes.h"
#include "td/misc/Time.h"
#include "td/misc/Shapes.h"
#include "game/Types.h"
#include "td/game/Types.h"
namespace td {
namespace game {

View File

@@ -3,7 +3,7 @@
#include <cstdint>
// include Log for every files
#include "misc/Log.h"
#include "td/misc/Log.h"
namespace td {
namespace game {

View File

@@ -171,7 +171,10 @@ public:
void Tick(std::uint64_t delta);
void Reset(); // clear mobs and towers
void SpawnMobAt(MobID id, MobType type, std::uint8_t level, PlayerID sender, float x, float y, Direction dir);
MobPtr RemoveMob(MobID id);
TowerPtr PlaceTowerAt(TowerID id, TowerType type, std::int32_t x, std::int32_t y, PlayerID builder);
TowerPtr RemoveTower(TowerID id);
@@ -217,7 +220,9 @@ public:
const TeamList& GetTeams() const;
TowerList& GetTowers() { return m_Towers; }
const TowerList& GetTowers() const { return m_Towers; }
TowerPtr GetTowerById(TowerID tower);
const Player* GetPlayerById(PlayerID id) const;

View File

@@ -1,6 +1,6 @@
#pragma once
#include "Defines.h"
#include "td/Defines.h"
#include <cmath>
namespace td {

View File

@@ -1,9 +1,9 @@
#pragma once
#include "network/TCPSocket.h"
#include "protocol/PacketHandler.h"
#include "protocol/PacketDispatcher.h"
#include "game/Player.h"
#include "td/network/TCPSocket.h"
#include "td/protocol/PacketHandler.h"
#include "td/protocol/PacketDispatcher.h"
#include "td/game/Player.h"
namespace td {
namespace protocol {

View File

@@ -12,10 +12,10 @@
#include <fcntl.h>
#endif
#include "network/Socket.h"
#include "network/IPAddress.h"
#include "network/UDPSocket.h"
#include "network/TCPSocket.h"
#include "td/network/Socket.h"
#include "td/network/IPAddress.h"
#include "td/network/UDPSocket.h"
#include "td/network/TCPSocket.h"
namespace td {
namespace network {

View File

@@ -5,7 +5,7 @@
#include <vector>
#include <memory>
#include "misc/DataBuffer.h"
#include "td/misc/DataBuffer.h"
#ifdef _WIN32
#include <ws2tcpip.h>

View File

@@ -1,8 +1,8 @@
#ifndef NETWORK_TCP_SOCKET_H_
#define NETWORK_TCP_SOCKET_H_
#include "network/IPAddress.h"
#include "network/Socket.h"
#include "td/network/IPAddress.h"
#include "td/network/Socket.h"
#include <cstdint>

View File

@@ -1,8 +1,8 @@
#ifndef NETWORK_UDP_SOCKET_H_
#define NETWORK_UDP_SOCKET_H_
#include "network/IPAddress.h"
#include "network/Socket.h"
#include "td/network/IPAddress.h"
#include "td/network/Socket.h"
#include <cstdint>

View File

@@ -1,6 +1,6 @@
#pragma once
#include "protocol/Protocol.h"
#include "td/protocol/Protocol.h"
#include <map>
#include <vector>

View File

@@ -1,6 +1,6 @@
#pragma once
#include "protocol/Protocol.h"
#include "td/protocol/Protocol.h"
namespace td {
namespace protocol {

View File

@@ -1,6 +1,7 @@
#pragma once
#include "protocol/Protocol.h"
#include "td/protocol/Protocol.h"
#include "td/protocol/PacketsForward.h"
namespace td {
namespace protocol {
@@ -26,6 +27,7 @@ public:
virtual void HandlePacket(const PlayerLeavePacket* packet) {}
virtual void HandlePacket(const PlayerListPacket* packet) {}
virtual void HandlePacket(const PlayerLoginPacket* packet) {}
virtual void HandlePacket(const RemoveMobPacket* packet) {}
virtual void HandlePacket(const RemoveTowerPacket* packet) {}
virtual void HandlePacket(const SelectTeamPacket* packet) {}
virtual void HandlePacket(const SendMobsPacket* packet) {}

View File

@@ -0,0 +1,28 @@
#include "packets/ConnectionInfoPacket.h"
#include "packets/DisconnectPacket.h"
#include "packets/KeepAlivePacket.h"
#include "packets/PlaceTowerPacket.h"
#include "packets/PlayerBuyItemPacket.h"
#include "packets/PlayerBuyMobUpgradePacket.h"
#include "packets/PlayerJoinPacket.h"
#include "packets/PlayerLeavePacket.h"
#include "packets/PlayerListPacket.h"
#include "packets/PlayerLoginPacket.h"
#include "packets/RemoveMobPacket.h"
#include "packets/RemoveTowerPacket.h"
#include "packets/SelectTeamPacket.h"
#include "packets/SendMobsPacket.h"
#include "packets/ServerTpsPacket.h"
#include "packets/SpawnMobPacket.h"
#include "packets/UpdateCastleLifePacket.h"
#include "packets/UpdateExpPacket.h"
#include "packets/UpdateGameStatePacket.h"
#include "packets/UpdateLobbyTimePacket.h"
#include "packets/UpdateMobStatesPacket.h"
#include "packets/UpdateMoneyPacket.h"
#include "packets/UpdatePlayerTeamPacket.h"
#include "packets/UpgradeTowerPacket.h"
#include "packets/WorldAddTowerPacket.h"
#include "packets/WorldAddTowerPacket.h"
#include "packets/WorldBeginDataPacket.h"
#include "packets/WorldDataPacket.h"

View File

@@ -0,0 +1,35 @@
#pragma once
namespace td {
namespace protocol {
class PlayerLoginPacket;
class WorldBeginDataPacket;
class WorldDataPacket;
class KeepAlivePacket;
class UpdateExpPacket;
class UpdateMoneyPacket;
class UpdateLobbyTimePacket;
class UpdateGameStatePacket;
class PlayerListPacket;
class PlayerJoinPacket;
class PlayerLeavePacket;
class ConnexionInfoPacket;
class SelectTeamPacket;
class UpdatePlayerTeamPacket;
class DisconnectPacket;
class ServerTpsPacket;
class SpawnMobPacket;
class PlaceTowerPacket;
class WorldAddTowerPacket;
class RemoveTowerPacket;
class SendMobsPacket;
class UpgradeTowerPacket;
class UpdateCastleLifePacket;
class UpdateMobStatesPacket;
class PlayerBuyItemPacket;
class PlayerBuyMobUpgradePacket;
class RemoveMobPacket;
} // namespace protocol
} // namespace td

View File

@@ -0,0 +1,67 @@
#pragma once
#include "td/misc/DataBuffer.h"
#include <memory>
namespace td {
namespace protocol {
class PacketHandler;
enum class PacketType : std::uint8_t {
// client --> server
PlayerLogin = 0,
SelectTeam,
SendMobs,
PlaceTower,
// client <-- server
PlayerJoin,
PlayerLeave,
WorldBeginData,
WorldData,
UpdateMoney,
UpdateEXP,
UpdateLobbyTime,
UpdateGameState,
PlayerList,
ConnectionInfo,
UpdatePlayerTeam,
ServerTps,
WorldAddTower,
UpdateMobStates,
UpdateCastleLife,
SpawnMob,
RemoveMob,
// client <--> server
KeepAlive,
Disconnect,
UpgradeTower,
RemoveTower,
PlayerBuyItem,
PlayerBuyMobUpgrade,
PACKET_COUNT
};
class Packet {
public:
Packet() {}
virtual ~Packet() {}
virtual DataBuffer Serialize(bool packetID = true) const = 0;
virtual void Deserialize(DataBuffer& data) = 0;
virtual void Dispatch(PacketHandler* handler) const = 0;
void WritePacketID(DataBuffer& data, bool packetID) const;
virtual PacketType GetType() const = 0;
std::uint8_t GetID() const { return static_cast<std::uint8_t>(GetType()); }
};
typedef std::unique_ptr<Packet> PacketPtr;
} // namespace protocol
} // namespace td

View File

@@ -0,0 +1,26 @@
#pragma once
#include "td/protocol/Protocol.h"
namespace td {
namespace protocol {
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;
std::uint8_t GetConnectionID() const { return m_ConnectionID; }
virtual PacketType GetType() const { return PacketType::ConnectionInfo; }
};
} // namespace protocol
} // namespace td

View File

@@ -0,0 +1,26 @@
#pragma once
#include "td/protocol/Protocol.h"
namespace td {
namespace protocol {
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;
const std::string& GetReason() const { return m_Reason; }
virtual PacketType GetType() const { return PacketType::Disconnect; }
};
} // namespace protocol
} // namespace td

View File

@@ -0,0 +1,26 @@
#pragma once
#include "td/protocol/Protocol.h"
namespace td {
namespace protocol {
class KeepAlivePacket : public Packet {
private:
std::uint64_t 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;
std::uint64_t GetAliveID() const { return m_AliveID; }
virtual PacketType GetType() const { return PacketType::KeepAlive; }
};
} // namespace protocol
} // namespace td

View File

@@ -0,0 +1,32 @@
#pragma once
#include "td/protocol/Protocol.h"
#include "td/game/BaseGame.h"
namespace td {
namespace protocol {
class PlaceTowerPacket : public Packet {
private:
std::int32_t m_TowerX, m_TowerY;
game::TowerType m_TowerType;
public:
PlaceTowerPacket() {}
PlaceTowerPacket(std::int32_t x, std::int32_t y, game::TowerType type) :
m_TowerX(x), m_TowerY(y), m_TowerType(type) {
}
virtual ~PlaceTowerPacket() {}
virtual DataBuffer Serialize(bool packetID = true) const;
virtual void Deserialize(DataBuffer& data);
virtual void Dispatch(PacketHandler* handler) const;
std::int32_t GetTowerX() const { return m_TowerX; }
std::int32_t GetTowerY() const { return m_TowerY; }
game::TowerType GetTowerType() const { return m_TowerType; }
virtual PacketType GetType() const { return PacketType::PlaceTower; }
};
} // namespace protocol
} // namespace td

View File

@@ -0,0 +1,38 @@
#pragma once
#include "td/protocol/Protocol.h"
namespace td {
namespace protocol {
enum class ItemType : std::uint8_t {
// Upgrades
ClickerUpgrade,
GoldPerSecUpgrade,
// Items
};
/** Packet used by the client to buy items or upgrades
Packet used by the server to confirm transaction */
class PlayerBuyItemPacket : public Packet {
private:
ItemType m_ItemType;
std::uint8_t m_Count;
public:
PlayerBuyItemPacket() {}
PlayerBuyItemPacket(ItemType itemType, std::uint8_t count) : m_ItemType(itemType), m_Count(count) {}
virtual ~PlayerBuyItemPacket() {}
virtual DataBuffer Serialize(bool packetID = true) const;
virtual void Deserialize(DataBuffer& data);
virtual void Dispatch(PacketHandler* handler) const;
ItemType GetItemType() const { return m_ItemType; }
std::uint8_t GetCount() const { return m_Count; }
virtual PacketType GetType() const { return PacketType::PlayerBuyItem; }
};
} // namespace protocol
} // namespace td

View File

@@ -0,0 +1,31 @@
#pragma once
#include "td/protocol/Protocol.h"
#include "td/game/BaseGame.h"
namespace td {
namespace protocol {
/** Packet used by the client to buy mob upgrades
Packet used by the server to confirm transaction */
class PlayerBuyMobUpgradePacket : public Packet {
private:
game::MobType m_MobType;
std::uint8_t m_MobLevel;
public:
PlayerBuyMobUpgradePacket() {}
PlayerBuyMobUpgradePacket(game::MobType mobType, std::uint8_t level) : m_MobType(mobType), m_MobLevel(level) {}
virtual ~PlayerBuyMobUpgradePacket() {}
virtual DataBuffer Serialize(bool packetID = true) const;
virtual void Deserialize(DataBuffer& data);
virtual void Dispatch(PacketHandler* handler) const;
game::MobType GetMobType() const { return m_MobType; }
std::uint8_t GetLevel() const { return m_MobLevel; }
virtual PacketType GetType() const { return PacketType::PlayerBuyMobUpgrade; }
};
} // namespace protocol
} // namespace td

View File

@@ -0,0 +1,28 @@
#pragma once
#include "td/protocol/Protocol.h"
namespace td {
namespace protocol {
class PlayerJoinPacket : public Packet {
private:
std::uint8_t m_PlayerID;
std::string m_PlayerName;
public:
PlayerJoinPacket() {}
PlayerJoinPacket(std::uint8_t 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;
std::uint8_t GetPlayerID() const { return m_PlayerID; }
const std::string& GetPlayerName() const { return m_PlayerName; }
virtual PacketType GetType() const { return PacketType::PlayerJoin; }
};
} // namespace protocol
} // namespace td

View File

@@ -0,0 +1,26 @@
#pragma once
#include "td/protocol/Protocol.h"
namespace td {
namespace protocol {
class PlayerLeavePacket : public Packet {
private:
std::uint8_t 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; }
};
} // namespace protocol
} // namespace td

View File

@@ -0,0 +1,32 @@
#pragma once
#include "td/protocol/Protocol.h"
#include "td/game/BaseGame.h"
namespace td {
namespace protocol {
struct PlayerInfo {
std::string name;
game::TeamColor team;
};
class PlayerListPacket : public Packet {
private:
std::map<std::uint8_t, PlayerInfo> m_Players;
public:
PlayerListPacket() {}
PlayerListPacket(std::map<std::uint8_t, PlayerInfo> 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 std::map<std::uint8_t, PlayerInfo>& GetPlayers() const { return m_Players; }
virtual PacketType GetType() const { return PacketType::PlayerList; }
};
} // namespace protocol
} // namespace td

View File

@@ -0,0 +1,26 @@
#pragma once
#include "td/protocol/Protocol.h"
namespace td {
namespace protocol {
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; }
const std::string& GetPlayerName() const { return m_PlayerName; }
};
} // namespace protocol
} // namespace td

View File

@@ -0,0 +1,27 @@
#pragma once
#include "td/protocol/Protocol.h"
#include "td/game/BaseGame.h"
namespace td {
namespace protocol {
class RemoveMobPacket : public Packet {
private:
game::MobID m_MobID;
public:
RemoveMobPacket() {}
RemoveMobPacket(game::MobID id) : m_MobID(id) {}
virtual ~RemoveMobPacket() {}
virtual DataBuffer Serialize(bool packetID = true) const;
virtual void Deserialize(DataBuffer& data);
virtual void Dispatch(PacketHandler* handler) const;
game::MobID GetMobID() const { return m_MobID; }
virtual PacketType GetType() const { return PacketType::RemoveMob; }
};
} // namespace protocol
} // namespace td

View File

@@ -0,0 +1,27 @@
#pragma once
#include "td/protocol/Protocol.h"
#include "td/game/BaseGame.h"
namespace td {
namespace protocol {
class RemoveTowerPacket : public Packet {
private:
game::TowerID m_TowerID;
public:
RemoveTowerPacket() {}
RemoveTowerPacket(game::TowerID id) : m_TowerID(id) {}
virtual ~RemoveTowerPacket() {}
virtual DataBuffer Serialize(bool packetID = true) const;
virtual void Deserialize(DataBuffer& data);
virtual void Dispatch(PacketHandler* handler) const;
game::TowerID GetTowerID() const { return m_TowerID; }
virtual PacketType GetType() const { return PacketType::RemoveTower; }
};
} // namespace protocol
} // namespace td

View File

@@ -0,0 +1,27 @@
#pragma once
#include "td/protocol/Protocol.h"
#include "td/game/BaseGame.h"
namespace td {
namespace protocol {
class SelectTeamPacket : public Packet {
private:
game::TeamColor m_SelectedTeam;
public:
SelectTeamPacket() {}
SelectTeamPacket(game::TeamColor selectedTeam) : m_SelectedTeam(selectedTeam) {}
virtual ~SelectTeamPacket() {}
virtual DataBuffer Serialize(bool packetID = true) const;
virtual void Deserialize(DataBuffer& data);
virtual void Dispatch(PacketHandler* handler) const;
game::TeamColor GetSelectedTeam() const { return m_SelectedTeam; }
virtual PacketType GetType() const { return PacketType::SelectTeam; }
};
} // namespace protocol
} // namespace td

View File

@@ -0,0 +1,33 @@
#pragma once
#include "td/protocol/Protocol.h"
#include "td/game/BaseGame.h"
namespace td {
namespace protocol {
struct MobSend { // represents a mob send
game::MobType mobType : 4;
game::MobLevel mobLevel : 4;
std::uint8_t mobCount; // the max is 12
};
class SendMobsPacket : public Packet {
private:
std::vector<MobSend> m_MobSends;
public:
SendMobsPacket() {}
SendMobsPacket(const std::vector<MobSend>& mobSends) : m_MobSends(mobSends) {}
virtual ~SendMobsPacket() {}
virtual DataBuffer Serialize(bool packetID = true) const;
virtual void Deserialize(DataBuffer& data);
virtual void Dispatch(PacketHandler* handler) const;
const std::vector<MobSend>& GetMobSends() const { return m_MobSends; }
virtual PacketType GetType() const { return PacketType::SendMobs; }
};
} // namespace protocol
} // namespace td

View File

@@ -0,0 +1,30 @@
#pragma once
#include "td/protocol/Protocol.h"
namespace td {
namespace protocol {
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;
float GetTPS() const { return m_TPS; }
float GetMSPT() const { return m_MSPT; }
std::uint64_t GetPacketSendTime() const { return m_PacketSendTime; }
virtual PacketType GetType() const { return PacketType::ServerTps; }
};
} // namespace protocol
} // namespace td

View File

@@ -0,0 +1,41 @@
#pragma once
#include "td/protocol/Protocol.h"
#include "td/game/BaseGame.h"
namespace td {
namespace protocol {
class SpawnMobPacket : public Packet {
private:
game::MobID m_MobID;
game::MobType m_MobType;
game::MobLevel m_MobLevel;
game::Direction m_MobDirection;
game::PlayerID m_Sender;
float m_MobX, m_MobY;
public:
SpawnMobPacket() {}
SpawnMobPacket(game::MobID id, game::MobType type, std::uint8_t level, game::PlayerID sender,
float x, float y, game::Direction dir) : m_MobID(id), m_MobType(type), m_MobLevel(level),
m_MobDirection(dir), m_Sender(sender), m_MobX(x), m_MobY(y) {
}
virtual ~SpawnMobPacket() {}
virtual DataBuffer Serialize(bool packetID = true) const;
virtual void Deserialize(DataBuffer& data);
virtual void Dispatch(PacketHandler* handler) const;
game::MobID GetMobID() const { return m_MobID; }
game::MobType GetMobType() const { return m_MobType; }
game::MobLevel GetMobLevel() const { return m_MobLevel; }
game::Direction GetMobDirection() const { return m_MobDirection; }
game::PlayerID GetSender() const { return m_Sender; }
float GetMobX() const { return m_MobX; }
float GetMobY() const { return m_MobY; }
virtual PacketType GetType() const { return PacketType::SpawnMob; }
};
} // namespace protocol
} // namespace td

View File

@@ -0,0 +1,29 @@
#pragma once
#include "td/protocol/Protocol.h"
#include "td/game/BaseGame.h"
namespace td {
namespace protocol {
class UpdateCastleLifePacket : public Packet {
private:
std::uint16_t m_CastleLife;
game::TeamColor m_Team;
public:
UpdateCastleLifePacket() {}
UpdateCastleLifePacket(std::uint16_t life, game::TeamColor team) : m_CastleLife(life), m_Team(team) {}
virtual ~UpdateCastleLifePacket() {}
virtual DataBuffer Serialize(bool packetID = true) const;
virtual void Deserialize(DataBuffer& data);
virtual void Dispatch(PacketHandler* handler) const;
std::uint16_t GetCastleLife() const { return m_CastleLife; }
game::TeamColor GetTeamColor() const { return m_Team; }
virtual PacketType GetType() const { return PacketType::UpdateCastleLife; }
};
} // namespace protocol
} // namespace td

View File

@@ -0,0 +1,26 @@
#pragma once
#include "td/protocol/Protocol.h"
namespace td {
namespace protocol {
class UpdateExpPacket : public Packet {
private:
std::uint32_t m_NewAmount;
public:
UpdateExpPacket() {}
UpdateExpPacket(std::uint32_t newAmount) : m_NewAmount(newAmount) {}
virtual ~UpdateExpPacket() {}
std::uint32_t GetExp() const { return m_NewAmount; }
virtual DataBuffer Serialize(bool packetID = true) const;
virtual void Deserialize(DataBuffer& data);
virtual void Dispatch(PacketHandler* handler) const;
virtual PacketType GetType() const { return PacketType::UpdateEXP; }
};
} // namespace protocol
} // namespace td

View File

@@ -0,0 +1,27 @@
#pragma once
#include "td/protocol/Protocol.h"
#include "td/game/BaseGame.h"
namespace td {
namespace protocol {
class UpdateGameStatePacket : public Packet {
private:
game::GameState m_GameState;
public:
UpdateGameStatePacket() {}
UpdateGameStatePacket(game::GameState gameState) : m_GameState(gameState) {}
virtual ~UpdateGameStatePacket() {}
virtual DataBuffer Serialize(bool packetID = true) const;
virtual void Deserialize(DataBuffer& data);
virtual void Dispatch(PacketHandler* handler) const;
game::GameState GetGameState() const { return m_GameState; }
virtual PacketType GetType() const { return PacketType::UpdateGameState; }
};
} // namespace protocol
} // namespace td

View File

@@ -0,0 +1,26 @@
#pragma once
#include "td/protocol/Protocol.h"
namespace td {
namespace protocol {
class UpdateLobbyTimePacket : public Packet {
private:
std::uint32_t m_RemainingTime;
public:
UpdateLobbyTimePacket() {}
UpdateLobbyTimePacket(std::uint32_t remainingTime) : m_RemainingTime(remainingTime) {}
virtual ~UpdateLobbyTimePacket() {}
virtual DataBuffer Serialize(bool packetID = true) const;
virtual void Deserialize(DataBuffer& data);
virtual void Dispatch(PacketHandler* handler) const;
std::uint32_t GetRemainingTime() const { return m_RemainingTime; }
virtual PacketType GetType() const { return PacketType::UpdateLobbyTime; }
};
} // namespace protocol
} // namespace td

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