Compare commits
87 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
8d184d1160
|
|||
| 7ddf47a81a | |||
| 7a1db0305d | |||
| 700a2b0c18 | |||
| 398439886b | |||
| 7c4ed3910f | |||
| 90c834cc49 | |||
| d23761dc10 | |||
| 3d8fd2e519 | |||
| 4bd32e8d0b | |||
| 09bba12814 | |||
| bb76e9493f | |||
|
|
808ef7b3f6 | ||
|
|
23938a0cb5 | ||
|
|
5631efcf9e | ||
|
|
8e7b446003 | ||
|
|
51ec035490 | ||
| 1f94ae2586 | |||
| 7b8c13612c | |||
| a36716d8e4 | |||
| debf9e974c | |||
| 380ecf3a27 | |||
| b3157be641 | |||
| 1e3b672897 | |||
| d1aa5cd8aa | |||
| dbe91b52fd | |||
| 7ab8c79fdf | |||
| 8f2a22762a | |||
| f0c3325141 | |||
| 1d00e0098a | |||
| ee5a27ac54 | |||
| 49a5a09537 | |||
| f9f80fc4fb | |||
| 4997715672 | |||
| 3fe480d121 | |||
| c46226c1ae | |||
| 8630421734 | |||
| 60b81003c0 | |||
| 7986e55846 | |||
| 0c0fd155ed | |||
| 7f650f282c | |||
| 118a04cd01 | |||
| d529c79150 | |||
| ddbba997e5 | |||
| 50c17e8ed1 | |||
| b4836847f5 | |||
| f941862637 | |||
| 36f37b6548 | |||
| 1dde1dbf1e | |||
| f5012f770c | |||
| e7b9a57723 | |||
| 02b4aa3c91 | |||
| f184982bc1 | |||
| 1cdc738839 | |||
| 368bc450ce | |||
| 148b5f397a | |||
| f62322752d | |||
| fb9e125f16 | |||
| b70e8f7790 | |||
| 39bdd0a11e | |||
| c95c8b7fde | |||
| e984ed9085 | |||
| 92035d7b9e | |||
| 48841fa4e9 | |||
| 83ab8c70f0 | |||
| ccdcdac7c6 | |||
| a2b5424888 | |||
| a4fb56b549 | |||
| 22e62df04d | |||
| faf544f997 | |||
| b72f4a7673 | |||
| 19c03010cb | |||
| 41f8c152eb | |||
| 051c9d8744 | |||
| 193e4db651 | |||
| cb5f5a4cf8 | |||
| bc7e5914ce | |||
| 0365902971 | |||
| f2fcc348d7 | |||
| 95c92ec6c9 | |||
| 721f15b601 | |||
| 3970103b01 | |||
| 4e866c1032 | |||
| ca268781fd | |||
| a2d8984199 | |||
| e7f9ca2b6c | |||
| deb0075aac |
46
.gitea/workflows/linux.yaml
Normal file
46
.gitea/workflows/linux.yaml
Normal file
@@ -0,0 +1,46 @@
|
|||||||
|
name: Linux arm64
|
||||||
|
run-name: Build And Test
|
||||||
|
|
||||||
|
on: [push]
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
Build:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
- name: Install deps
|
||||||
|
run : |
|
||||||
|
apt update
|
||||||
|
apt install -y libsdl2-dev 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: '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
|
||||||
|
key: ${{ runner.os }}-${{ steps.get-hash.outputs.hash }}
|
||||||
|
|
||||||
|
- name: XMake config
|
||||||
|
run: xmake f -p linux -y --root
|
||||||
|
|
||||||
|
- name: Build
|
||||||
|
run: xmake --root
|
||||||
|
|
||||||
|
- name: Test
|
||||||
|
run: xmake test --root
|
||||||
18
README.md
Normal file
18
README.md
Normal file
@@ -0,0 +1,18 @@
|
|||||||
|
# TowerDefense
|
||||||
|
|
||||||
|
Unmaintained multiplayer tower defense game prototype
|
||||||
|
(OpenGL + TCP)
|
||||||
|
|
||||||
|
## Screenshots 🖼
|
||||||
|
|
||||||
|
[[screenshots/game.png]]
|
||||||
|
|
||||||
|
## Build ⚙️
|
||||||
|
```
|
||||||
|
xmake
|
||||||
|
```
|
||||||
|
|
||||||
|
## Run 🏃
|
||||||
|
```
|
||||||
|
xmake run
|
||||||
|
```
|
||||||
@@ -1,63 +0,0 @@
|
|||||||
#pragma once
|
|
||||||
|
|
||||||
namespace td {
|
|
||||||
|
|
||||||
template<typename T>
|
|
||||||
struct Vec2 {
|
|
||||||
union {
|
|
||||||
T x;
|
|
||||||
T r;
|
|
||||||
};
|
|
||||||
|
|
||||||
union {
|
|
||||||
T y;
|
|
||||||
T g;
|
|
||||||
};
|
|
||||||
|
|
||||||
constexpr Vec2(T X = 0, T Y = 0) : x(X), y(Y) {}
|
|
||||||
|
|
||||||
};
|
|
||||||
|
|
||||||
template<typename T>
|
|
||||||
inline bool operator==(const Vec2<T>& vec2, const Vec2<T>& other) {
|
|
||||||
return vec2.x == other.x && vec2.y == other.y;
|
|
||||||
}
|
|
||||||
|
|
||||||
template<typename T>
|
|
||||||
struct Vec3 {
|
|
||||||
union {
|
|
||||||
T x;
|
|
||||||
T r;
|
|
||||||
};
|
|
||||||
|
|
||||||
union {
|
|
||||||
T y;
|
|
||||||
T g;
|
|
||||||
};
|
|
||||||
|
|
||||||
union {
|
|
||||||
T z;
|
|
||||||
T b;
|
|
||||||
};
|
|
||||||
|
|
||||||
constexpr Vec3(T X = 0, T Y = 0, T Z = 0) : x(X), y(Y), z(Z) {}
|
|
||||||
};
|
|
||||||
|
|
||||||
template<typename T>
|
|
||||||
inline bool operator==(const Vec3<T>& vec3, const Vec3<T>& other) {
|
|
||||||
return vec3.x == other.x && vec3.y == other.y && vec3.z == other.z;
|
|
||||||
}
|
|
||||||
|
|
||||||
using Vec2i = Vec2<int>;
|
|
||||||
using Vec2u = Vec2<unsigned int>;
|
|
||||||
using Vec2f = Vec2<float>;
|
|
||||||
using Vec2d = Vec2<double>;
|
|
||||||
|
|
||||||
using Vec3i = Vec3<int>;
|
|
||||||
using Vec3u = Vec3<unsigned int>;
|
|
||||||
using Vec3f = Vec3<float>;
|
|
||||||
using Vec3d = Vec3<double>;
|
|
||||||
|
|
||||||
using Color = Vec3<unsigned char>;
|
|
||||||
|
|
||||||
} // namespace td
|
|
||||||
@@ -1,16 +1,17 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include "ClientConnexion.h"
|
#include "client/ClientConnexion.h"
|
||||||
#include "ClientGame.h"
|
#include "client/game/ClientGame.h"
|
||||||
|
|
||||||
#include "game/Team.h"
|
#include "td/game/Team.h"
|
||||||
#include "game/Player.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 td {
|
||||||
namespace client {
|
namespace client {
|
||||||
@@ -1,8 +1,8 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include "protocol/PacketHandler.h"
|
#include "td/protocol/PacketHandler.h"
|
||||||
#include "network/TCPSocket.h"
|
#include "td/network/TCPSocket.h"
|
||||||
#include "game/Connexion.h"
|
#include "td/network/Connexion.h"
|
||||||
|
|
||||||
namespace td {
|
namespace td {
|
||||||
namespace client {
|
namespace client {
|
||||||
@@ -1,13 +1,13 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include "game/BaseGame.h"
|
#include "td/game/BaseGame.h"
|
||||||
|
|
||||||
#include "protocol/PacketHandler.h"
|
#include "td/protocol/PacketHandler.h"
|
||||||
|
|
||||||
#include "WorldClient.h"
|
#include "WorldClient.h"
|
||||||
|
|
||||||
#include "render/WorldRenderer.h"
|
#include "client/render/WorldRenderer.h"
|
||||||
#include "render/Renderer.h"
|
#include "client/render/Renderer.h"
|
||||||
|
|
||||||
namespace td {
|
namespace td {
|
||||||
namespace client {
|
namespace client {
|
||||||
@@ -39,8 +39,6 @@ public:
|
|||||||
render::Renderer* GetRenderer() const { return m_Renderer; }
|
render::Renderer* GetRenderer() const { return m_Renderer; }
|
||||||
WorldClient& GetWorldClient() { return m_WorldClient; }
|
WorldClient& GetWorldClient() { return m_WorldClient; }
|
||||||
|
|
||||||
void SetGameState(game::GameState gameState) override;
|
|
||||||
|
|
||||||
virtual void HandlePacket(const protocol::ConnexionInfoPacket* packet) override;
|
virtual void HandlePacket(const protocol::ConnexionInfoPacket* packet) override;
|
||||||
virtual void HandlePacket(const protocol::PlayerJoinPacket* packet) override;
|
virtual void HandlePacket(const protocol::PlayerJoinPacket* packet) override;
|
||||||
virtual void HandlePacket(const protocol::PlayerLeavePacket* packet) override;
|
virtual void HandlePacket(const protocol::PlayerLeavePacket* packet) override;
|
||||||
@@ -1,7 +1,7 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include "game/World.h"
|
#include "td/game/World.h"
|
||||||
#include "protocol/PacketHandler.h"
|
#include "td/protocol/PacketHandler.h"
|
||||||
|
|
||||||
namespace td {
|
namespace td {
|
||||||
namespace client {
|
namespace client {
|
||||||
@@ -13,12 +13,14 @@ private:
|
|||||||
ClientGame* m_Game;
|
ClientGame* m_Game;
|
||||||
public:
|
public:
|
||||||
WorldClient(ClientGame* game);
|
WorldClient(ClientGame* game);
|
||||||
|
virtual ~WorldClient();
|
||||||
|
|
||||||
virtual void HandlePacket(const protocol::WorldBeginDataPacket* packet) override;
|
virtual void HandlePacket(const protocol::WorldBeginDataPacket* packet) override;
|
||||||
virtual void HandlePacket(const protocol::WorldDataPacket* packet) override;
|
virtual void HandlePacket(const protocol::WorldDataPacket* packet) override;
|
||||||
virtual void HandlePacket(const protocol::SpawnMobPacket* packet) override;
|
virtual void HandlePacket(const protocol::SpawnMobPacket* packet) override;
|
||||||
virtual void HandlePacket(const protocol::UpgradeTowerPacket* packet) override;
|
virtual void HandlePacket(const protocol::UpgradeTowerPacket* packet) override;
|
||||||
virtual void HandlePacket(const protocol::WorldAddTowerPacket* 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::RemoveTowerPacket* packet) override;
|
||||||
virtual void HandlePacket(const protocol::UpdateMobStatesPacket* packet) override;
|
virtual void HandlePacket(const protocol::UpdateMobStatesPacket* packet) override;
|
||||||
virtual void HandlePacket(const protocol::UpdateCastleLifePacket* packet) override;
|
virtual void HandlePacket(const protocol::UpdateCastleLifePacket* packet) override;
|
||||||
72
include/client/render/Renderer.h
Normal file
72
include/client/render/Renderer.h
Normal file
@@ -0,0 +1,72 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include "td/Defines.h"
|
||||||
|
#include <memory>
|
||||||
|
#include "loader/GLLoader.h"
|
||||||
|
#include "client/render/shaders/WorldShader.h"
|
||||||
|
#include "client/render/shaders/EntityShader.h"
|
||||||
|
|
||||||
|
namespace td {
|
||||||
|
namespace render {
|
||||||
|
|
||||||
|
struct Camera {
|
||||||
|
Mat4f viewMatrix;
|
||||||
|
Mat4f projectionMatrix;
|
||||||
|
Mat4f InvViewMatrix;
|
||||||
|
Mat4f InvProjectionMatrix;
|
||||||
|
|
||||||
|
float CamDistance = 25.0f;
|
||||||
|
Vec3f CamPos {0, CamDistance, 0};
|
||||||
|
Vec2f CamLook {};
|
||||||
|
|
||||||
|
float m_Yaw = -PI / 2.0f;
|
||||||
|
float m_Pitch = -PI / 2.0f + 0.0000001f;
|
||||||
|
};
|
||||||
|
|
||||||
|
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;
|
||||||
|
|
||||||
|
Vec2i m_WindowSize;
|
||||||
|
|
||||||
|
Vec3f m_BackgroundColor;
|
||||||
|
|
||||||
|
Camera m_Camera {};
|
||||||
|
public:
|
||||||
|
Renderer();
|
||||||
|
~Renderer();
|
||||||
|
|
||||||
|
bool Init();
|
||||||
|
|
||||||
|
void Prepare();
|
||||||
|
void Resize(const int width, const int height);
|
||||||
|
|
||||||
|
void RenderVAO(const GL::VertexArray& vao);
|
||||||
|
void RenderModel(const Model& 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; }
|
||||||
|
|
||||||
|
Vec2f GetCursorWorldPos(const Vec2f& cursorPos, float windowWidth, float windowHeight);
|
||||||
|
private:
|
||||||
|
void InitShaders();
|
||||||
|
void SetCamPos(const Vec3f& newPos);
|
||||||
|
};
|
||||||
|
|
||||||
|
} // namespace render
|
||||||
|
} // namespace td
|
||||||
@@ -2,7 +2,7 @@
|
|||||||
#include <cstdint>
|
#include <cstdint>
|
||||||
#include <memory>
|
#include <memory>
|
||||||
|
|
||||||
#include "render/loader/GLLoader.h"
|
#include "client/render/loader/GLLoader.h"
|
||||||
|
|
||||||
|
|
||||||
namespace td {
|
namespace td {
|
||||||
@@ -1,16 +1,14 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include "game/World.h"
|
#include "td/game/World.h"
|
||||||
|
|
||||||
#include "render/Renderer.h"
|
#include "client/render/Renderer.h"
|
||||||
#include "render/VertexCache.h"
|
#include "client/render/VertexCache.h"
|
||||||
|
|
||||||
#include "render/gui/TowerPlacePopup.h"
|
#include "client/render/gui/TowerPlacePopup.h"
|
||||||
#include "render/gui/TowerUpgradePopup.h"
|
#include "client/render/gui/TowerUpgradePopup.h"
|
||||||
#include "render/gui/MobTooltip.h"
|
#include "client/render/gui/MobTooltip.h"
|
||||||
#include "render/gui/CastleTooltip.h"
|
#include "client/render/gui/CastleTooltip.h"
|
||||||
|
|
||||||
#include "render/gui/imgui/imgui.h"
|
|
||||||
|
|
||||||
namespace td {
|
namespace td {
|
||||||
|
|
||||||
@@ -20,7 +18,6 @@ class ClientGame;
|
|||||||
|
|
||||||
} // namespace client
|
} // namespace client
|
||||||
|
|
||||||
|
|
||||||
namespace render {
|
namespace render {
|
||||||
|
|
||||||
class WorldRenderer : public game::WorldListener {
|
class WorldRenderer : public game::WorldListener {
|
||||||
@@ -48,14 +45,13 @@ public:
|
|||||||
|
|
||||||
void LoadModels();
|
void LoadModels();
|
||||||
|
|
||||||
static ImVec4 GetImGuiTeamColor(game::TeamColor color);
|
|
||||||
|
|
||||||
void Update();
|
void Update();
|
||||||
void Render();
|
void Render();
|
||||||
|
|
||||||
|
void ResetCam();
|
||||||
void SetCamPos(float camX, float camY);
|
void SetCamPos(float camX, float camY);
|
||||||
|
|
||||||
void MoveCam(float relativeX, float relativeY, float aspectRatio);
|
void MoveCam(float relativeX, float relativeY);
|
||||||
void ChangeZoom(float zoom);
|
void ChangeZoom(float zoom);
|
||||||
|
|
||||||
// WorldListener
|
// WorldListener
|
||||||
@@ -1,16 +1,19 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include "SummonMenu.h"
|
#include "SummonMenu.h"
|
||||||
|
#include "td/game/BaseGame.h"
|
||||||
|
|
||||||
namespace td {
|
namespace td {
|
||||||
namespace gui {
|
namespace gui {
|
||||||
|
|
||||||
class GameMenu : public GuiWidget {
|
class GameMenu : public GuiWidget, public game::GameListener {
|
||||||
private:
|
private:
|
||||||
std::unique_ptr<SummonMenu> m_SummonMenu;
|
std::unique_ptr<SummonMenu> m_SummonMenu;
|
||||||
public:
|
public:
|
||||||
GameMenu(client::Client* client);
|
GameMenu(client::Client* client);
|
||||||
|
|
||||||
|
virtual void OnGameBegin();
|
||||||
|
|
||||||
virtual void Render();
|
virtual void Render();
|
||||||
private:
|
private:
|
||||||
void ShowTPS();
|
void ShowTPS();
|
||||||
@@ -18,6 +21,8 @@ private:
|
|||||||
void ShowPlayers();
|
void ShowPlayers();
|
||||||
void ShowLobbyProgress();
|
void ShowLobbyProgress();
|
||||||
void ShowTeamSelection();
|
void ShowTeamSelection();
|
||||||
|
|
||||||
|
void DisconnectButton();
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace gui
|
} // namespace gui
|
||||||
13
include/client/render/gui/ImGuiTeamColor.h
Normal file
13
include/client/render/gui/ImGuiTeamColor.h
Normal 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
|
||||||
|
|
||||||
@@ -4,13 +4,15 @@
|
|||||||
|
|
||||||
#include "imgui/imgui_filebrowser.h"
|
#include "imgui/imgui_filebrowser.h"
|
||||||
|
|
||||||
#include "game/server/Server.h"
|
#include "server/Server.h"
|
||||||
|
|
||||||
#include <memory>
|
#include <memory>
|
||||||
|
|
||||||
namespace td {
|
namespace td {
|
||||||
namespace gui {
|
namespace gui {
|
||||||
|
|
||||||
|
class ServerGui;
|
||||||
|
|
||||||
class MainMenu : public GuiWidget {
|
class MainMenu : public GuiWidget {
|
||||||
private:
|
private:
|
||||||
bool m_TriedToConnect = false;
|
bool m_TriedToConnect = false;
|
||||||
@@ -22,6 +24,7 @@ private:
|
|||||||
imgui_addons::ImGuiFileBrowser m_FileDialog;
|
imgui_addons::ImGuiFileBrowser m_FileDialog;
|
||||||
|
|
||||||
std::unique_ptr<server::Server> m_Server;
|
std::unique_ptr<server::Server> m_Server;
|
||||||
|
std::unique_ptr<ServerGui> m_ServerGui;
|
||||||
public:
|
public:
|
||||||
MainMenu(client::Client* client);
|
MainMenu(client::Client* client);
|
||||||
~MainMenu();
|
~MainMenu();
|
||||||
19
include/client/render/gui/ServerGui.h
Normal file
19
include/client/render/gui/ServerGui.h
Normal 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
|
||||||
@@ -3,7 +3,7 @@
|
|||||||
#include "GuiWidget.h"
|
#include "GuiWidget.h"
|
||||||
|
|
||||||
#include <array>
|
#include <array>
|
||||||
#include "game/Mobs.h"
|
#include "td/game/Mobs.h"
|
||||||
|
|
||||||
namespace td {
|
namespace td {
|
||||||
namespace gui {
|
namespace gui {
|
||||||
@@ -9,7 +9,7 @@
|
|||||||
|
|
||||||
#include <memory>
|
#include <memory>
|
||||||
|
|
||||||
#include "render/gui/GuiManager.h"
|
#include "client/render/gui/GuiManager.h"
|
||||||
|
|
||||||
struct SDL_Window;
|
struct SDL_Window;
|
||||||
typedef void* SDL_GLContext;
|
typedef void* SDL_GLContext;
|
||||||
@@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
#include "GuiWidget.h"
|
#include "GuiWidget.h"
|
||||||
|
|
||||||
#include "Defines.h"
|
#include "td/Defines.h"
|
||||||
|
|
||||||
namespace td {
|
namespace td {
|
||||||
namespace gui {
|
namespace gui {
|
||||||
@@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
#include "GuiWidget.h"
|
#include "GuiWidget.h"
|
||||||
|
|
||||||
#include "Defines.h"
|
#include "td/Defines.h"
|
||||||
|
|
||||||
namespace td {
|
namespace td {
|
||||||
namespace gui {
|
namespace gui {
|
||||||
@@ -107,7 +107,7 @@ namespace ImGui
|
|||||||
}
|
}
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "render/GL.h"
|
#include "client/render/GL.h"
|
||||||
|
|
||||||
#if defined(__ANDROID__)
|
#if defined(__ANDROID__)
|
||||||
#define IMGUI_IMPL_OPENGL_LOADER_ES3
|
#define IMGUI_IMPL_OPENGL_LOADER_ES3
|
||||||
@@ -1,7 +1,7 @@
|
|||||||
#ifndef IMGUIFILEBROWSER_H
|
#ifndef IMGUIFILEBROWSER_H
|
||||||
#define IMGUIFILEBROWSER_H
|
#define IMGUIFILEBROWSER_H
|
||||||
|
|
||||||
#include "render/gui/imgui/imgui.h"
|
#include "client/render/gui/imgui/imgui.h"
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
@@ -1,6 +1,6 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include "game/World.h"
|
#include "td/game/World.h"
|
||||||
#include "GLLoader.h"
|
#include "GLLoader.h"
|
||||||
|
|
||||||
namespace td {
|
namespace td {
|
||||||
28
include/client/render/shaders/EntityShader.h
Normal file
28
include/client/render/shaders/EntityShader.h
Normal file
@@ -0,0 +1,28 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include "ShaderProgram.h"
|
||||||
|
|
||||||
|
namespace td {
|
||||||
|
namespace shader {
|
||||||
|
|
||||||
|
class EntityShader : public ShaderProgram {
|
||||||
|
private:
|
||||||
|
unsigned int m_LocationProjectionMatrix = 0;
|
||||||
|
unsigned int m_LocationViewMatrix = 0;
|
||||||
|
unsigned int m_LocationPosition = 0;
|
||||||
|
unsigned int m_LocationColorEffect = 0;
|
||||||
|
protected:
|
||||||
|
virtual void GetAllUniformLocation();
|
||||||
|
public:
|
||||||
|
EntityShader();
|
||||||
|
|
||||||
|
void LoadShader();
|
||||||
|
|
||||||
|
void SetColorEffect(const Vec3f& color);
|
||||||
|
void SetProjectionMatrix(const Mat4f& proj) const;
|
||||||
|
void SetViewMatrix(const Mat4f& view) const;
|
||||||
|
void SetModelPos(const Vec3f& pos) const;
|
||||||
|
};
|
||||||
|
|
||||||
|
} // namespace shader
|
||||||
|
} // namespace td
|
||||||
@@ -1,8 +1,8 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <string>
|
#include <string>
|
||||||
#include "Defines.h"
|
#include "td/Defines.h"
|
||||||
#include "render/GL.h"
|
#include "client/render/GL.h"
|
||||||
|
|
||||||
namespace td {
|
namespace td {
|
||||||
namespace shader {
|
namespace shader {
|
||||||
@@ -27,6 +27,7 @@ protected:
|
|||||||
void LoadVector(unsigned int location, const Vec2f& vector) const;
|
void LoadVector(unsigned int location, const Vec2f& vector) const;
|
||||||
void LoadVector(unsigned int location, const Vec3f& vector) const;
|
void LoadVector(unsigned int location, const Vec3f& vector) const;
|
||||||
void LoadBoolean(unsigned int location, bool value) const;
|
void LoadBoolean(unsigned int location, bool value) const;
|
||||||
|
void LoadMat4(unsigned int location, const Mat4f& mat) const;
|
||||||
void CleanUp() const;
|
void CleanUp() const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
@@ -7,16 +7,15 @@ namespace shader {
|
|||||||
|
|
||||||
class WorldShader : public ShaderProgram {
|
class WorldShader : public ShaderProgram {
|
||||||
private:
|
private:
|
||||||
unsigned int m_LocationCam = 0, m_LocationZoom = 0, m_LocationAspectRatio = 0, m_LocationViewtype = 0;
|
unsigned int m_LocationProjection = 0, m_LocationView = 0;
|
||||||
protected:
|
protected:
|
||||||
void GetAllUniformLocation();
|
void GetAllUniformLocation();
|
||||||
public:
|
public:
|
||||||
WorldShader();
|
WorldShader();
|
||||||
void LoadShader();
|
void LoadShader();
|
||||||
void SetCamPos(const Vec2f& camPos);
|
|
||||||
void SetZoom(float zoom);
|
void SetProjectionMatrix(const Mat4f& proj) const;
|
||||||
void SetAspectRatio(float aspectRatio);
|
void SetViewMatrix(const Mat4f& view) const;
|
||||||
void SetIsometricView(float isometric);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace shader
|
} // namespace shader
|
||||||
@@ -1,8 +1,8 @@
|
|||||||
#pragma once
|
#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 td {
|
||||||
namespace utils {
|
namespace utils {
|
||||||
@@ -1,15 +0,0 @@
|
|||||||
#pragma once
|
|
||||||
|
|
||||||
#include <string>
|
|
||||||
|
|
||||||
namespace td {
|
|
||||||
namespace utils {
|
|
||||||
|
|
||||||
void InitDiscordRPC();
|
|
||||||
void UpdateDiscordRPC();
|
|
||||||
void ShutdownDiscordRPC();
|
|
||||||
|
|
||||||
void UpdateDiscordPresence(const std::string& state, const std::string& details, bool resetTimer = false);
|
|
||||||
|
|
||||||
} // namespace utils
|
|
||||||
} // namespace td
|
|
||||||
@@ -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
|
|
||||||
@@ -1,57 +0,0 @@
|
|||||||
#pragma once
|
|
||||||
|
|
||||||
#include "Defines.h"
|
|
||||||
#include <memory>
|
|
||||||
#include "loader/GLLoader.h"
|
|
||||||
#include "render/shaders/WorldShader.h"
|
|
||||||
#include "render/shaders/EntityShader.h"
|
|
||||||
|
|
||||||
namespace td {
|
|
||||||
namespace render {
|
|
||||||
|
|
||||||
class Renderer {
|
|
||||||
public:
|
|
||||||
static constexpr float m_AnimationSpeed = 2.0f;
|
|
||||||
|
|
||||||
struct Model {
|
|
||||||
GL::VertexArray* vao;
|
|
||||||
Vec2f positon;
|
|
||||||
Vec3f color = { 1, 1, 1 };
|
|
||||||
};
|
|
||||||
private:
|
|
||||||
std::unique_ptr<shader::WorldShader> m_WorldShader;
|
|
||||||
std::unique_ptr<shader::EntityShader> m_EntityShader;
|
|
||||||
|
|
||||||
Vec3f m_BackgroundColor;
|
|
||||||
|
|
||||||
bool m_IsometricView = true;
|
|
||||||
float m_IsometricShade = m_IsometricView;
|
|
||||||
Vec2f m_CamPos{};
|
|
||||||
public:
|
|
||||||
Renderer();
|
|
||||||
~Renderer();
|
|
||||||
|
|
||||||
bool Init();
|
|
||||||
|
|
||||||
void Prepare();
|
|
||||||
void Resize(const int width, const int height);
|
|
||||||
|
|
||||||
void RenderVAO(const GL::VertexArray& vao);
|
|
||||||
void RenderModel(const Model& model);
|
|
||||||
|
|
||||||
void SetZoom(float zoom);
|
|
||||||
void SetCamMovement(const Vec2f& mov);
|
|
||||||
void SetCamPos(const Vec2f& newPos);
|
|
||||||
void SetIsometricView(bool isometric); // false = 2D true = Isometric
|
|
||||||
|
|
||||||
void SetBackgroundColor(const Vec3f& color) { m_BackgroundColor = color; }
|
|
||||||
|
|
||||||
Vec2f GetCursorWorldPos(const Vec2f& cursorPos, float aspectRatio, float zoom, float windowWidth, float windowHeight);
|
|
||||||
private:
|
|
||||||
void UpdateIsometricView();
|
|
||||||
void UpdateIsometricFade();
|
|
||||||
void InitShaders();
|
|
||||||
};
|
|
||||||
|
|
||||||
} // namespace render
|
|
||||||
} // namespace td
|
|
||||||
@@ -1,32 +0,0 @@
|
|||||||
#pragma once
|
|
||||||
|
|
||||||
#include "ShaderProgram.h"
|
|
||||||
|
|
||||||
namespace td {
|
|
||||||
namespace shader {
|
|
||||||
|
|
||||||
class EntityShader : public ShaderProgram {
|
|
||||||
|
|
||||||
private:
|
|
||||||
unsigned int m_LocationCam = 0;
|
|
||||||
unsigned int m_LocationZoom = 0;
|
|
||||||
unsigned int m_LocationAspectRatio = 0;
|
|
||||||
unsigned int m_LocationTranslation = 0;
|
|
||||||
unsigned int m_LocationViewtype = 0;
|
|
||||||
unsigned int m_LocationColorEffect = 0;
|
|
||||||
protected:
|
|
||||||
virtual void GetAllUniformLocation();
|
|
||||||
public:
|
|
||||||
EntityShader();
|
|
||||||
|
|
||||||
void LoadShader();
|
|
||||||
void SetCamPos(const Vec2f& camPos);
|
|
||||||
void SetZoom(float zoom);
|
|
||||||
void SetAspectRatio(float aspectRatio);
|
|
||||||
void SetModelPos(const Vec2f& modelPos);
|
|
||||||
void SetIsometricView(float isometric);
|
|
||||||
void SetColorEffect(const Vec3f& color);
|
|
||||||
};
|
|
||||||
|
|
||||||
} // namespace shader
|
|
||||||
} // namespace td
|
|
||||||
@@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
#include "misc/Time.h"
|
#include "td/misc/Time.h"
|
||||||
|
|
||||||
namespace td {
|
namespace td {
|
||||||
namespace server {
|
namespace server {
|
||||||
@@ -12,7 +12,7 @@ class Server;
|
|||||||
class Lobby {
|
class Lobby {
|
||||||
private:
|
private:
|
||||||
Server* m_Server;
|
Server* m_Server;
|
||||||
bool m_GameStarted = false;
|
bool m_LobbyOpened = false;
|
||||||
std::uint64_t m_StartTimerTime = 0;
|
std::uint64_t m_StartTimerTime = 0;
|
||||||
std::vector<std::uint8_t> m_Players;
|
std::vector<std::uint8_t> m_Players;
|
||||||
utils::AutoTimer m_Timer;
|
utils::AutoTimer m_Timer;
|
||||||
@@ -22,6 +22,8 @@ public:
|
|||||||
void OnPlayerJoin(std::uint8_t playerID);
|
void OnPlayerJoin(std::uint8_t playerID);
|
||||||
void OnPlayerLeave(std::uint8_t playerID);
|
void OnPlayerLeave(std::uint8_t playerID);
|
||||||
|
|
||||||
|
void OpenLobby();
|
||||||
|
|
||||||
void SendTimeRemaining();
|
void SendTimeRemaining();
|
||||||
|
|
||||||
void Tick();
|
void Tick();
|
||||||
@@ -3,13 +3,13 @@
|
|||||||
#include <map>
|
#include <map>
|
||||||
#include <thread>
|
#include <thread>
|
||||||
|
|
||||||
#include "network/TCPListener.h"
|
#include "td/network/TCPListener.h"
|
||||||
#include "protocol/Protocol.h"
|
#include "td/protocol/Protocol.h"
|
||||||
#include "protocol/PacketDispatcher.h"
|
#include "td/protocol/PacketDispatcher.h"
|
||||||
#include "protocol/PacketHandler.h"
|
#include "td/protocol/PacketHandler.h"
|
||||||
#include "ServerGame.h"
|
#include "server/game/ServerGame.h"
|
||||||
#include "ServerConnexion.h"
|
#include "server/ServerConnexion.h"
|
||||||
#include "Lobby.h"
|
#include "server/Lobby.h"
|
||||||
|
|
||||||
#define SERVER_TPS 20
|
#define SERVER_TPS 20
|
||||||
#define SERVER_TICK 1000 / SERVER_TPS
|
#define SERVER_TICK 1000 / SERVER_TPS
|
||||||
@@ -63,17 +63,23 @@ private:
|
|||||||
std::thread m_Thread;
|
std::thread m_Thread;
|
||||||
bool m_ServerRunning;
|
bool m_ServerRunning;
|
||||||
public:
|
public:
|
||||||
Server(const std::string& worldFilePath);
|
Server();
|
||||||
virtual ~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 Stop(); // force the server to stop
|
||||||
void Close(); // at the end of a game
|
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 RemoveConnexion(std::uint8_t connexionID);
|
||||||
|
|
||||||
void BroadcastPacket(const protocol::Packet* packet);
|
void BroadcastPacket(const protocol::Packet* packet);
|
||||||
|
|
||||||
|
float GetMSPT() const { return m_TickCounter.GetMSPT(); }
|
||||||
float GetTPS() const { return m_TickCounter.GetTPS(); }
|
float GetTPS() const { return m_TickCounter.GetTPS(); }
|
||||||
|
|
||||||
bool IsRunning() { return m_ServerRunning; }
|
bool IsRunning() { return m_ServerRunning; }
|
||||||
@@ -95,6 +101,7 @@ private:
|
|||||||
void Clean();
|
void Clean();
|
||||||
void StartThread();
|
void StartThread();
|
||||||
void StopThread();
|
void StopThread();
|
||||||
|
void ServerLoop();
|
||||||
void Tick(std::uint64_t delta);
|
void Tick(std::uint64_t delta);
|
||||||
|
|
||||||
void OnPlayerJoin(std::uint8_t id);
|
void OnPlayerJoin(std::uint8_t id);
|
||||||
@@ -1,10 +1,10 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include "network/TCPSocket.h"
|
#include "td/network/TCPSocket.h"
|
||||||
#include "protocol/PacketHandler.h"
|
#include "td/protocol/PacketHandler.h"
|
||||||
#include "protocol/PacketDispatcher.h"
|
#include "td/protocol/PacketDispatcher.h"
|
||||||
#include "game/Player.h"
|
#include "td/game/Player.h"
|
||||||
#include "game/Connexion.h"
|
#include "td/network/Connexion.h"
|
||||||
|
|
||||||
namespace td {
|
namespace td {
|
||||||
namespace server {
|
namespace server {
|
||||||
@@ -1,7 +1,7 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include "game/BaseGame.h"
|
#include "td/game/BaseGame.h"
|
||||||
#include "misc/Time.h"
|
#include "td/misc/Time.h"
|
||||||
#include "ServerWorld.h"
|
#include "ServerWorld.h"
|
||||||
|
|
||||||
namespace td {
|
namespace td {
|
||||||
@@ -23,6 +23,8 @@ public:
|
|||||||
ServerWorld* GetServerWorld() { return &m_ServerWorld; }
|
ServerWorld* GetServerWorld() { return &m_ServerWorld; }
|
||||||
|
|
||||||
virtual void Tick(std::uint64_t delta);
|
virtual void Tick(std::uint64_t delta);
|
||||||
|
virtual void Reset() override;
|
||||||
|
|
||||||
void StartGame();
|
void StartGame();
|
||||||
|
|
||||||
// GameListener
|
// GameListener
|
||||||
@@ -31,6 +33,9 @@ public:
|
|||||||
virtual void OnGameBegin() override;
|
virtual void OnGameBegin() override;
|
||||||
virtual void OnGameEnd() override;
|
virtual void OnGameEnd() override;
|
||||||
virtual void OnGameClose() override;
|
virtual void OnGameClose() override;
|
||||||
|
|
||||||
|
virtual void OnPlayerJoin(game::PlayerID id) override;
|
||||||
|
virtual void OnPlayerLeave(game::PlayerID id) override;
|
||||||
private:
|
private:
|
||||||
void BalanceTeams();
|
void BalanceTeams();
|
||||||
void InitPlayerStats();
|
void InitPlayerStats();
|
||||||
@@ -1,6 +1,6 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include "game/World.h"
|
#include "td/game/World.h"
|
||||||
|
|
||||||
namespace td {
|
namespace td {
|
||||||
namespace server {
|
namespace server {
|
||||||
151
include/td/Defines.h
Normal file
151
include/td/Defines.h
Normal file
@@ -0,0 +1,151 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <cstdint>
|
||||||
|
|
||||||
|
#define SAFE_CHECK(expr) if(!(expr)) return
|
||||||
|
|
||||||
|
|
||||||
|
namespace td {
|
||||||
|
|
||||||
|
static constexpr float PI = 3.141592653f;
|
||||||
|
|
||||||
|
template<typename T>
|
||||||
|
struct Vec2 {
|
||||||
|
union {
|
||||||
|
T x;
|
||||||
|
T r;
|
||||||
|
};
|
||||||
|
|
||||||
|
union {
|
||||||
|
T y;
|
||||||
|
T g;
|
||||||
|
};
|
||||||
|
|
||||||
|
constexpr Vec2(T X = 0, T Y = 0) : x(X), y(Y) {}
|
||||||
|
};
|
||||||
|
|
||||||
|
template<typename T>
|
||||||
|
inline bool operator==(const Vec2<T>& vec2, const Vec2<T>& other) {
|
||||||
|
return vec2.x == other.x && vec2.y == other.y;
|
||||||
|
}
|
||||||
|
|
||||||
|
template<typename T>
|
||||||
|
struct Vec3 {
|
||||||
|
union {
|
||||||
|
T x;
|
||||||
|
T r;
|
||||||
|
};
|
||||||
|
|
||||||
|
union {
|
||||||
|
T y;
|
||||||
|
T g;
|
||||||
|
};
|
||||||
|
|
||||||
|
union {
|
||||||
|
T z;
|
||||||
|
T b;
|
||||||
|
};
|
||||||
|
|
||||||
|
constexpr Vec3(T X = 0, T Y = 0, T Z = 0) : x(X), y(Y), z(Z) {}
|
||||||
|
};
|
||||||
|
|
||||||
|
template<typename T>
|
||||||
|
inline bool operator==(const Vec3<T>& vec3, const Vec3<T>& other) {
|
||||||
|
return vec3.x == other.x && vec3.y == other.y && vec3.z == other.z;
|
||||||
|
}
|
||||||
|
|
||||||
|
template<typename T>
|
||||||
|
struct Vec4 {
|
||||||
|
union {
|
||||||
|
T x;
|
||||||
|
T r;
|
||||||
|
};
|
||||||
|
|
||||||
|
union {
|
||||||
|
T y;
|
||||||
|
T g;
|
||||||
|
};
|
||||||
|
|
||||||
|
union {
|
||||||
|
T z;
|
||||||
|
T b;
|
||||||
|
};
|
||||||
|
|
||||||
|
union {
|
||||||
|
T w;
|
||||||
|
T a;
|
||||||
|
};
|
||||||
|
|
||||||
|
constexpr Vec4(Vec3<T> vec, T W = 1) : x(vec.x), y(vec.y), z(vec.z), w(W) {}
|
||||||
|
constexpr Vec4(T X = 0, T Y = 0, T Z = 0, T W = 0) : x(X), y(Y), z(Z), w(W) {}
|
||||||
|
};
|
||||||
|
|
||||||
|
template<typename T>
|
||||||
|
inline bool operator==(const Vec4<T>& vec4, const Vec4<T>& other) {
|
||||||
|
return vec4.x == other.x && vec4.y == other.y && vec4.z == other.z && vec4.w = other.w;
|
||||||
|
}
|
||||||
|
|
||||||
|
using Vec2i = Vec2<int>;
|
||||||
|
using Vec2u = Vec2<unsigned int>;
|
||||||
|
using Vec2f = Vec2<float>;
|
||||||
|
using Vec2d = Vec2<double>;
|
||||||
|
|
||||||
|
using Vec3i = Vec3<int>;
|
||||||
|
using Vec3u = Vec3<unsigned int>;
|
||||||
|
using Vec3f = Vec3<float>;
|
||||||
|
using Vec3d = Vec3<double>;
|
||||||
|
|
||||||
|
using Vec4i = Vec4<int>;
|
||||||
|
using Vec4u = Vec4<unsigned int>;
|
||||||
|
using Vec4f = Vec4<float>;
|
||||||
|
using Vec4d = Vec4<double>;
|
||||||
|
|
||||||
|
using Color = Vec3<unsigned char>;
|
||||||
|
|
||||||
|
template<typename T>
|
||||||
|
struct Mat4 {
|
||||||
|
static const std::size_t MATRIX_SIZE = 4;
|
||||||
|
|
||||||
|
T x0, x1, x2, x3;
|
||||||
|
T y0, y1, y2, y3;
|
||||||
|
T z0, z1, z2, z3;
|
||||||
|
T w0, w1, w2, w3;
|
||||||
|
|
||||||
|
T operator[] (std::size_t offset) const {
|
||||||
|
return reinterpret_cast<const T*>(this)[offset];
|
||||||
|
}
|
||||||
|
|
||||||
|
T& operator[] (std::size_t offset) {
|
||||||
|
return reinterpret_cast<T*>(this)[offset];
|
||||||
|
}
|
||||||
|
|
||||||
|
T* data() {
|
||||||
|
return reinterpret_cast<T*>(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
const T* data() const{
|
||||||
|
return reinterpret_cast<const T*>(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
T at(std::size_t row, std::size_t column) const {
|
||||||
|
return operator[](row * MATRIX_SIZE + column);
|
||||||
|
}
|
||||||
|
|
||||||
|
T& at(std::size_t row, std::size_t column) {
|
||||||
|
return operator[](row * MATRIX_SIZE + column);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
typedef Mat4<float> Mat4f;
|
||||||
|
typedef Mat4<int> Mat4i;
|
||||||
|
typedef Mat4<double> Mat4d;
|
||||||
|
|
||||||
|
template<typename T>
|
||||||
|
inline 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 && mat.y1 == other.y1 && mat.z1 == other.z1 && mat.w1 == other.w1 &&
|
||||||
|
mat.x2 == other.x2 && mat.y2 == other.y2 && 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 td
|
||||||
@@ -1,8 +1,8 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include "game/Team.h"
|
#include "td/game/Team.h"
|
||||||
#include "game/World.h"
|
#include "td/game/World.h"
|
||||||
#include "game/Player.h"
|
#include "td/game/Player.h"
|
||||||
|
|
||||||
namespace td {
|
namespace td {
|
||||||
namespace game {
|
namespace game {
|
||||||
@@ -42,6 +42,8 @@ public:
|
|||||||
|
|
||||||
virtual void Tick(std::uint64_t delta);
|
virtual void Tick(std::uint64_t delta);
|
||||||
|
|
||||||
|
virtual void Reset();
|
||||||
|
|
||||||
Team& GetRedTeam() { return m_Teams[static_cast<std::uint8_t>(TeamColor::Red)]; }
|
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)]; }
|
const Team& GetRedTeam() const { return m_Teams[static_cast<std::uint8_t>(TeamColor::Red)]; }
|
||||||
|
|
||||||
@@ -52,7 +54,7 @@ public:
|
|||||||
const Team& GetTeam(TeamColor team) const { return m_Teams[static_cast<std::uint8_t>(team)]; }
|
const Team& GetTeam(TeamColor team) const { return m_Teams[static_cast<std::uint8_t>(team)]; }
|
||||||
|
|
||||||
GameState GetGameState() const { return m_GameState; }
|
GameState GetGameState() const { return m_GameState; }
|
||||||
virtual void SetGameState(GameState gameState) { m_GameState = gameState; };
|
void SetGameState(GameState gameState) { m_GameState = gameState; };
|
||||||
|
|
||||||
const World* GetWorld() const { return m_World; }
|
const World* GetWorld() const { return m_World; }
|
||||||
World* GetWorld() { return m_World; }
|
World* GetWorld() { return m_World; }
|
||||||
@@ -65,6 +67,8 @@ public:
|
|||||||
|
|
||||||
const TeamList& GetTeams() const { return m_Teams; }
|
const TeamList& GetTeams() const { return m_Teams; }
|
||||||
|
|
||||||
|
void RemovePlayer(PlayerID pId);
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace game
|
} // namespace game
|
||||||
@@ -1,11 +1,11 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include "Defines.h"
|
#include "td/Defines.h"
|
||||||
#include "Towers.h"
|
#include "Towers.h"
|
||||||
#include "Types.h"
|
#include "Types.h"
|
||||||
#include "Team.h"
|
#include "Team.h"
|
||||||
|
|
||||||
#include "misc/ObjectNotifier.h"
|
#include "td/misc/ObjectNotifier.h"
|
||||||
|
|
||||||
#include <vector>
|
#include <vector>
|
||||||
#include <memory>
|
#include <memory>
|
||||||
@@ -99,7 +99,7 @@ private:
|
|||||||
utils::CooldownTimer m_AttackTimer;
|
utils::CooldownTimer m_AttackTimer;
|
||||||
|
|
||||||
public:
|
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_HitCooldown(0), m_EffectFireTimer(1000), m_EffectPoisonTimer(1000),
|
||||||
m_EffectHealTimer(1000), m_CastleTarget(nullptr), m_AttackTimer(1000) {
|
m_EffectHealTimer(1000), m_CastleTarget(nullptr), m_AttackTimer(1000) {
|
||||||
|
|
||||||
@@ -2,8 +2,8 @@
|
|||||||
|
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
#include "game/Team.h"
|
#include "td/game/Team.h"
|
||||||
#include "game/PlayerUpgrades.h"
|
#include "td/game/PlayerUpgrades.h"
|
||||||
|
|
||||||
namespace td {
|
namespace td {
|
||||||
namespace game {
|
namespace game {
|
||||||
@@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
#include "Types.h"
|
#include "Types.h"
|
||||||
|
|
||||||
#include "misc/Shapes.h"
|
#include "td/misc/Shapes.h"
|
||||||
|
|
||||||
#include <vector>
|
#include <vector>
|
||||||
#include <memory>
|
#include <memory>
|
||||||
@@ -74,6 +74,7 @@ public:
|
|||||||
|
|
||||||
void AddPlayer(Player* newPlayer);
|
void AddPlayer(Player* newPlayer);
|
||||||
void RemovePlayer(const Player* player);
|
void RemovePlayer(const Player* player);
|
||||||
|
void ClearPlayers();
|
||||||
|
|
||||||
TeamColor GetColor() const;
|
TeamColor GetColor() const;
|
||||||
|
|
||||||
@@ -3,10 +3,10 @@
|
|||||||
#include <string>
|
#include <string>
|
||||||
#include <memory>
|
#include <memory>
|
||||||
|
|
||||||
#include "misc/Time.h"
|
#include "td/misc/Time.h"
|
||||||
#include "misc/Shapes.h"
|
#include "td/misc/Shapes.h"
|
||||||
|
|
||||||
#include "game/Types.h"
|
#include "td/game/Types.h"
|
||||||
|
|
||||||
namespace td {
|
namespace td {
|
||||||
namespace game {
|
namespace game {
|
||||||
@@ -3,7 +3,7 @@
|
|||||||
#include <cstdint>
|
#include <cstdint>
|
||||||
|
|
||||||
// include Log for every files
|
// include Log for every files
|
||||||
#include "misc/Log.h"
|
#include "td/misc/Log.h"
|
||||||
|
|
||||||
namespace td {
|
namespace td {
|
||||||
namespace game {
|
namespace game {
|
||||||
@@ -171,7 +171,10 @@ public:
|
|||||||
|
|
||||||
void Tick(std::uint64_t delta);
|
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);
|
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 PlaceTowerAt(TowerID id, TowerType type, std::int32_t x, std::int32_t y, PlayerID builder);
|
||||||
TowerPtr RemoveTower(TowerID id);
|
TowerPtr RemoveTower(TowerID id);
|
||||||
@@ -217,7 +220,9 @@ public:
|
|||||||
|
|
||||||
const TeamList& GetTeams() const;
|
const TeamList& GetTeams() const;
|
||||||
|
|
||||||
|
TowerList& GetTowers() { return m_Towers; }
|
||||||
const TowerList& GetTowers() const { return m_Towers; }
|
const TowerList& GetTowers() const { return m_Towers; }
|
||||||
|
|
||||||
TowerPtr GetTowerById(TowerID tower);
|
TowerPtr GetTowerById(TowerID tower);
|
||||||
|
|
||||||
const Player* GetPlayerById(PlayerID id) const;
|
const Player* GetPlayerById(PlayerID id) const;
|
||||||
@@ -5,6 +5,7 @@
|
|||||||
#include <cstring>
|
#include <cstring>
|
||||||
#include <cassert>
|
#include <cassert>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
#include <cstdint>
|
||||||
|
|
||||||
namespace td {
|
namespace td {
|
||||||
|
|
||||||
177
include/td/misc/Maths.h
Normal file
177
include/td/misc/Maths.h
Normal file
@@ -0,0 +1,177 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include "td/Defines.h"
|
||||||
|
#include <cmath>
|
||||||
|
|
||||||
|
namespace td {
|
||||||
|
|
||||||
|
//////////////////////////////////////////////////////////////////
|
||||||
|
// Operators //
|
||||||
|
//////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
template<typename T>
|
||||||
|
Vec2<T> operator+(const Vec2<T>& vect, const Vec2<T>& other) {
|
||||||
|
return {vect.x + other.x, vect.y + other.y};
|
||||||
|
}
|
||||||
|
|
||||||
|
template<typename T>
|
||||||
|
Vec2<T> operator- (const Vec2<T>& vect) {
|
||||||
|
return { -vect.x, -vect.y };
|
||||||
|
}
|
||||||
|
|
||||||
|
template<typename T>
|
||||||
|
Vec2<T> operator- (const Vec2<T>& vect, const Vec2<T>& other) {
|
||||||
|
return vect + (-other);
|
||||||
|
}
|
||||||
|
|
||||||
|
template<typename T>
|
||||||
|
Vec3<T> operator- (const Vec3<T>& vect) {
|
||||||
|
return { -vect.x, -vect.y, -vect.z };
|
||||||
|
}
|
||||||
|
|
||||||
|
template<typename T>
|
||||||
|
Vec3<T> operator+ (const Vec3<T>& vect, const Vec3<T>& other) {
|
||||||
|
return { vect.x + other.x, vect.y + other.y, vect.z + other.y };
|
||||||
|
}
|
||||||
|
|
||||||
|
template<typename T>
|
||||||
|
Vec3<T> operator- (const Vec3<T>& vect, const Vec3<T>& other) {
|
||||||
|
return vect + (-other);
|
||||||
|
}
|
||||||
|
|
||||||
|
template<typename T>
|
||||||
|
Vec4<T> operator- (const Vec4<T>& vect) {
|
||||||
|
return { -vect.x, -vect.y, -vect.z, -vect.w };
|
||||||
|
}
|
||||||
|
|
||||||
|
template<typename T>
|
||||||
|
Vec4<T> operator+ (const Vec4<T>& vect, const Vec4<T>& other) {
|
||||||
|
return { vect.x + other.x, vect.y + other.y, vect.z + other.y, vect.w + other.w };
|
||||||
|
}
|
||||||
|
|
||||||
|
template<typename T>
|
||||||
|
Vec4<T> operator- (const Vec4<T>& vect, const Vec4<T>& other) {
|
||||||
|
return vect + (-other);
|
||||||
|
}
|
||||||
|
|
||||||
|
//////////////////////////////////////////////////////////////////
|
||||||
|
// Vectors //
|
||||||
|
//////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
namespace maths {
|
||||||
|
|
||||||
|
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& eye, const Vec3f& center, const Vec3f& up);
|
||||||
|
|
||||||
|
Mat4f Inverse(const Mat4f& mat);
|
||||||
|
|
||||||
|
} // namespace maths
|
||||||
|
} // namespace td
|
||||||
@@ -1,9 +1,9 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include "network/TCPSocket.h"
|
#include "td/network/TCPSocket.h"
|
||||||
#include "protocol/PacketHandler.h"
|
#include "td/protocol/PacketHandler.h"
|
||||||
#include "protocol/PacketDispatcher.h"
|
#include "td/protocol/PacketDispatcher.h"
|
||||||
#include "game/Player.h"
|
#include "td/game/Player.h"
|
||||||
|
|
||||||
namespace td {
|
namespace td {
|
||||||
namespace protocol {
|
namespace protocol {
|
||||||
@@ -4,6 +4,7 @@
|
|||||||
#include <string>
|
#include <string>
|
||||||
#include <iosfwd>
|
#include <iosfwd>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
#include <cstdint>
|
||||||
|
|
||||||
namespace td {
|
namespace td {
|
||||||
namespace network {
|
namespace network {
|
||||||
@@ -12,10 +12,10 @@
|
|||||||
#include <fcntl.h>
|
#include <fcntl.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include "network/Socket.h"
|
#include "td/network/Socket.h"
|
||||||
#include "network/IPAddress.h"
|
#include "td/network/IPAddress.h"
|
||||||
#include "network/UDPSocket.h"
|
#include "td/network/UDPSocket.h"
|
||||||
#include "network/TCPSocket.h"
|
#include "td/network/TCPSocket.h"
|
||||||
|
|
||||||
namespace td {
|
namespace td {
|
||||||
namespace network {
|
namespace network {
|
||||||
@@ -5,7 +5,7 @@
|
|||||||
#include <vector>
|
#include <vector>
|
||||||
#include <memory>
|
#include <memory>
|
||||||
|
|
||||||
#include "misc/DataBuffer.h"
|
#include "td/misc/DataBuffer.h"
|
||||||
|
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
#include <ws2tcpip.h>
|
#include <ws2tcpip.h>
|
||||||
@@ -1,8 +1,8 @@
|
|||||||
#ifndef NETWORK_TCP_SOCKET_H_
|
#ifndef NETWORK_TCP_SOCKET_H_
|
||||||
#define NETWORK_TCP_SOCKET_H_
|
#define NETWORK_TCP_SOCKET_H_
|
||||||
|
|
||||||
#include "network/IPAddress.h"
|
#include "td/network/IPAddress.h"
|
||||||
#include "network/Socket.h"
|
#include "td/network/Socket.h"
|
||||||
|
|
||||||
#include <cstdint>
|
#include <cstdint>
|
||||||
|
|
||||||
@@ -1,8 +1,8 @@
|
|||||||
#ifndef NETWORK_UDP_SOCKET_H_
|
#ifndef NETWORK_UDP_SOCKET_H_
|
||||||
#define NETWORK_UDP_SOCKET_H_
|
#define NETWORK_UDP_SOCKET_H_
|
||||||
|
|
||||||
#include "network/IPAddress.h"
|
#include "td/network/IPAddress.h"
|
||||||
#include "network/Socket.h"
|
#include "td/network/Socket.h"
|
||||||
|
|
||||||
#include <cstdint>
|
#include <cstdint>
|
||||||
|
|
||||||
@@ -1,6 +1,6 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include "protocol/Protocol.h"
|
#include "td/protocol/Protocol.h"
|
||||||
|
|
||||||
#include <map>
|
#include <map>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
@@ -1,6 +1,6 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include "protocol/Protocol.h"
|
#include "td/protocol/Protocol.h"
|
||||||
|
|
||||||
namespace td {
|
namespace td {
|
||||||
namespace protocol {
|
namespace protocol {
|
||||||
@@ -1,6 +1,7 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include "protocol/Protocol.h"
|
#include "td/protocol/Protocol.h"
|
||||||
|
#include "td/protocol/PacketsForward.h"
|
||||||
|
|
||||||
namespace td {
|
namespace td {
|
||||||
namespace protocol {
|
namespace protocol {
|
||||||
@@ -26,6 +27,7 @@ public:
|
|||||||
virtual void HandlePacket(const PlayerLeavePacket* packet) {}
|
virtual void HandlePacket(const PlayerLeavePacket* packet) {}
|
||||||
virtual void HandlePacket(const PlayerListPacket* packet) {}
|
virtual void HandlePacket(const PlayerListPacket* packet) {}
|
||||||
virtual void HandlePacket(const PlayerLoginPacket* packet) {}
|
virtual void HandlePacket(const PlayerLoginPacket* packet) {}
|
||||||
|
virtual void HandlePacket(const RemoveMobPacket* packet) {}
|
||||||
virtual void HandlePacket(const RemoveTowerPacket* packet) {}
|
virtual void HandlePacket(const RemoveTowerPacket* packet) {}
|
||||||
virtual void HandlePacket(const SelectTeamPacket* packet) {}
|
virtual void HandlePacket(const SelectTeamPacket* packet) {}
|
||||||
virtual void HandlePacket(const SendMobsPacket* packet) {}
|
virtual void HandlePacket(const SendMobsPacket* packet) {}
|
||||||
28
include/td/protocol/Packets.h
Normal file
28
include/td/protocol/Packets.h
Normal 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"
|
||||||
35
include/td/protocol/PacketsForward.h
Normal file
35
include/td/protocol/PacketsForward.h
Normal 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
|
||||||
67
include/td/protocol/Protocol.h
Normal file
67
include/td/protocol/Protocol.h
Normal 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
|
||||||
26
include/td/protocol/packets/ConnectionInfoPacket.h
Normal file
26
include/td/protocol/packets/ConnectionInfoPacket.h
Normal 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
|
||||||
26
include/td/protocol/packets/DisconnectPacket.h
Normal file
26
include/td/protocol/packets/DisconnectPacket.h
Normal 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
|
||||||
26
include/td/protocol/packets/KeepAlivePacket.h
Normal file
26
include/td/protocol/packets/KeepAlivePacket.h
Normal 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
|
||||||
32
include/td/protocol/packets/PlaceTowerPacket.h
Normal file
32
include/td/protocol/packets/PlaceTowerPacket.h
Normal 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
|
||||||
38
include/td/protocol/packets/PlayerBuyItemPacket.h
Normal file
38
include/td/protocol/packets/PlayerBuyItemPacket.h
Normal 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
|
||||||
31
include/td/protocol/packets/PlayerBuyMobUpgradePacket.h
Normal file
31
include/td/protocol/packets/PlayerBuyMobUpgradePacket.h
Normal 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
|
||||||
28
include/td/protocol/packets/PlayerJoinPacket.h
Normal file
28
include/td/protocol/packets/PlayerJoinPacket.h
Normal 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
|
||||||
26
include/td/protocol/packets/PlayerLeavePacket.h
Normal file
26
include/td/protocol/packets/PlayerLeavePacket.h
Normal 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
|
||||||
32
include/td/protocol/packets/PlayerListPacket.h
Normal file
32
include/td/protocol/packets/PlayerListPacket.h
Normal 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
|
||||||
26
include/td/protocol/packets/PlayerLoginPacket.h
Normal file
26
include/td/protocol/packets/PlayerLoginPacket.h
Normal 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
|
||||||
27
include/td/protocol/packets/RemoveMobPacket.h
Normal file
27
include/td/protocol/packets/RemoveMobPacket.h
Normal 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
|
||||||
27
include/td/protocol/packets/RemoveTowerPacket.h
Normal file
27
include/td/protocol/packets/RemoveTowerPacket.h
Normal 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
|
||||||
27
include/td/protocol/packets/SelectTeamPacket.h
Normal file
27
include/td/protocol/packets/SelectTeamPacket.h
Normal 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
|
||||||
33
include/td/protocol/packets/SendMobsPacket.h
Normal file
33
include/td/protocol/packets/SendMobsPacket.h
Normal 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
|
||||||
30
include/td/protocol/packets/ServerTpsPacket.h
Normal file
30
include/td/protocol/packets/ServerTpsPacket.h
Normal 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
|
||||||
41
include/td/protocol/packets/SpawnMobPacket.h
Normal file
41
include/td/protocol/packets/SpawnMobPacket.h
Normal 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
|
||||||
29
include/td/protocol/packets/UpdateCastleLifePacket.h
Normal file
29
include/td/protocol/packets/UpdateCastleLifePacket.h
Normal 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
|
||||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user