Compare commits
65 Commits
alpha-0.3.
...
sync
| Author | SHA1 | Date | |
|---|---|---|---|
| d2e42c33a0 | |||
| 8bddbce07a | |||
| add62fb24a | |||
| 68b389f938 | |||
| f3adb639c3 | |||
| 88a9020da7 | |||
| 0a814233a4 | |||
| 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 | |||
| 28b8659e16 | |||
| 0b9fc0520e | |||
| c54017c7be | |||
| bbfe341d23 | |||
| 14efe2cc39 | |||
| fcda12e321 | |||
| 1200a6e087 | |||
| 512fb23d0e | |||
| 5a547b6514 | |||
| ed45995645 | |||
| 0b6d826eba | |||
| 6d0c6be166 | |||
| 222b79b40a | |||
| 8f95b1a750 | |||
| 7d30017742 | |||
| 386ea5b6ad |
@@ -1,7 +1,11 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
|
#include <cstdint>
|
||||||
|
|
||||||
namespace td {
|
namespace td {
|
||||||
|
|
||||||
|
static constexpr float PI = 3.141592653f;
|
||||||
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
struct Vec2 {
|
struct Vec2 {
|
||||||
union {
|
union {
|
||||||
@@ -14,11 +18,14 @@ struct Vec2 {
|
|||||||
T g;
|
T g;
|
||||||
};
|
};
|
||||||
|
|
||||||
Vec2(T X = 0, T Y = 0) : x(X), y(Y) {}
|
constexpr Vec2(T X = 0, T Y = 0) : x(X), y(Y) {}
|
||||||
|
|
||||||
friend bool operator==(const Vec2& vec2, const Vec2& other) { return vec2.x == other.x && vec2.y == other.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>
|
template<typename T>
|
||||||
struct Vec3 {
|
struct Vec3 {
|
||||||
union {
|
union {
|
||||||
@@ -36,9 +43,45 @@ struct Vec3 {
|
|||||||
T b;
|
T b;
|
||||||
};
|
};
|
||||||
|
|
||||||
Vec3(T X = 0, T Y = 0, T Z = 0) : x(X), y(Y), z(Z) {}
|
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 Vec2i = Vec2<int>;
|
||||||
using Vec2u = Vec2<unsigned int>;
|
using Vec2u = Vec2<unsigned int>;
|
||||||
using Vec2f = Vec2<float>;
|
using Vec2f = Vec2<float>;
|
||||||
@@ -49,4 +92,57 @@ using Vec3u = Vec3<unsigned int>;
|
|||||||
using Vec3f = Vec3<float>;
|
using Vec3f = Vec3<float>;
|
||||||
using Vec3d = Vec3<double>;
|
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
|
} // namespace td
|
||||||
|
|||||||
@@ -36,6 +36,8 @@ protected:
|
|||||||
TeamList m_Teams = { Team{TeamColor::Red}, Team{TeamColor::Blue} };
|
TeamList m_Teams = { Team{TeamColor::Red}, Team{TeamColor::Blue} };
|
||||||
GameState m_GameState = GameState::Lobby;
|
GameState m_GameState = GameState::Lobby;
|
||||||
PlayerList m_Players;
|
PlayerList m_Players;
|
||||||
|
|
||||||
|
std::uint64_t m_GameStartTime = 0;
|
||||||
public:
|
public:
|
||||||
Game(World* world);
|
Game(World* world);
|
||||||
virtual ~Game();
|
virtual ~Game();
|
||||||
@@ -65,6 +67,8 @@ public:
|
|||||||
|
|
||||||
const TeamList& GetTeams() const { return m_Teams; }
|
const TeamList& GetTeams() const { return m_Teams; }
|
||||||
|
|
||||||
|
std::uint64_t GetGameStartTime() const { return m_GameStartTime; }
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace game
|
} // namespace game
|
||||||
|
|||||||
@@ -89,6 +89,7 @@ private:
|
|||||||
Direction m_Direction;
|
Direction m_Direction;
|
||||||
std::vector<EffectDuration> m_Effects;
|
std::vector<EffectDuration> m_Effects;
|
||||||
const Tower* m_LastDamage; // the last tower that damaged the mob
|
const Tower* m_LastDamage; // the last tower that damaged the mob
|
||||||
|
float m_HitCooldown;
|
||||||
|
|
||||||
utils::Timer m_EffectFireTimer;
|
utils::Timer m_EffectFireTimer;
|
||||||
utils::Timer m_EffectPoisonTimer;
|
utils::Timer m_EffectPoisonTimer;
|
||||||
@@ -99,7 +100,7 @@ private:
|
|||||||
|
|
||||||
public:
|
public:
|
||||||
Mob(MobID id, MobLevel level, PlayerID sender) : m_Sender(sender), m_Level(level),
|
Mob(MobID id, MobLevel level, PlayerID sender) : m_Sender(sender), m_Level(level),
|
||||||
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) {
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -123,8 +124,16 @@ public:
|
|||||||
const Tower* GetLastDamageTower() { return m_LastDamage; }
|
const Tower* GetLastDamageTower() { return m_LastDamage; }
|
||||||
bool HasReachedEnemyCastle() { return m_CastleTarget != nullptr; }
|
bool HasReachedEnemyCastle() { return m_CastleTarget != nullptr; }
|
||||||
|
|
||||||
void Damage(float dmg, const Tower* damager) { m_Health = std::max(0.0f, m_Health - dmg); m_LastDamage = damager; }
|
void Damage(float dmg, const Tower* damager) {
|
||||||
void Heal(float heal) { m_Health = std::min(static_cast<float>(GetStats()->GetMaxLife()), m_Health + heal); }
|
m_Health = std::max(0.0f, m_Health - dmg);
|
||||||
|
m_LastDamage = damager;
|
||||||
|
m_HitCooldown = 0.1;
|
||||||
|
}
|
||||||
|
|
||||||
|
void Heal(float heal) {
|
||||||
|
m_Health = std::min(static_cast<float>(GetStats()->GetMaxLife()), m_Health + heal);
|
||||||
|
}
|
||||||
|
|
||||||
void SetMobReachedCastle(TeamCastle* castle) { m_CastleTarget = castle; } // used when mob is in front of the castle
|
void SetMobReachedCastle(TeamCastle* castle) { m_CastleTarget = castle; } // used when mob is in front of the castle
|
||||||
|
|
||||||
bool IsImmuneTo(TowerType type);
|
bool IsImmuneTo(TowerType type);
|
||||||
@@ -133,6 +142,8 @@ public:
|
|||||||
void AddEffect(EffectType type, float durationSec, Tower* tower);
|
void AddEffect(EffectType type, float durationSec, Tower* tower);
|
||||||
bool HasEffect(EffectType type);
|
bool HasEffect(EffectType type);
|
||||||
|
|
||||||
|
bool HasTakenDamage() { return m_HitCooldown > 0; }
|
||||||
|
|
||||||
float GetTileX() { return GetCenterX() - static_cast<float>(static_cast<std::int32_t>(GetCenterX())); } // returns a float between 0 and 1 excluded
|
float GetTileX() { return GetCenterX() - static_cast<float>(static_cast<std::int32_t>(GetCenterX())); } // returns a float between 0 and 1 excluded
|
||||||
float GetTileY() { return GetCenterY() - static_cast<float>(static_cast<std::int32_t>(GetCenterY())); } // returns a float between 0 and 1 excluded
|
float GetTileY() { return GetCenterY() - static_cast<float>(static_cast<std::int32_t>(GetCenterY())); } // returns a float between 0 and 1 excluded
|
||||||
|
|
||||||
|
|||||||
@@ -136,7 +136,8 @@ private:
|
|||||||
bool m_IsBigTower;
|
bool m_IsBigTower;
|
||||||
public:
|
public:
|
||||||
TowerInfo(std::string&& name, std::string&& description, bool big) : m_Name(std::move(name)),
|
TowerInfo(std::string&& name, std::string&& description, bool big) : m_Name(std::move(name)),
|
||||||
m_Description(std::move(description)), m_IsBigTower(big) {}
|
m_Description(std::move(description)), m_IsBigTower(big) {
|
||||||
|
}
|
||||||
|
|
||||||
const std::string& GetName() const { return m_Name; }
|
const std::string& GetName() const { return m_Name; }
|
||||||
const std::string& GetDescription() const { return m_Description; }
|
const std::string& GetDescription() const { return m_Description; }
|
||||||
|
|||||||
@@ -58,10 +58,6 @@ enum class TileType : std::uint8_t {
|
|||||||
Ice,*/
|
Ice,*/
|
||||||
};
|
};
|
||||||
|
|
||||||
struct Color {
|
|
||||||
std::uint8_t r, g, b;
|
|
||||||
};
|
|
||||||
|
|
||||||
static constexpr Color BLACK{ 0, 0, 0 };
|
static constexpr Color BLACK{ 0, 0, 0 };
|
||||||
static constexpr Color WHITE{ 255, 255, 255 };
|
static constexpr Color WHITE{ 255, 255, 255 };
|
||||||
|
|
||||||
|
|||||||
@@ -7,6 +7,7 @@
|
|||||||
#include "game/Player.h"
|
#include "game/Player.h"
|
||||||
|
|
||||||
#include "protocol/Protocol.h"
|
#include "protocol/Protocol.h"
|
||||||
|
#include "protocol/packets/SendMobsPacket.h"
|
||||||
|
|
||||||
#include "render/Renderer.h"
|
#include "render/Renderer.h"
|
||||||
|
|
||||||
|
|||||||
@@ -12,6 +12,7 @@ private:
|
|||||||
std::uint8_t m_ConnectionID;
|
std::uint8_t m_ConnectionID;
|
||||||
std::string m_DisconnectReason;
|
std::string m_DisconnectReason;
|
||||||
float m_ServerTPS;
|
float m_ServerTPS;
|
||||||
|
float m_ServerMSPT;
|
||||||
int m_Ping = 0;
|
int m_Ping = 0;
|
||||||
public:
|
public:
|
||||||
ClientConnexion();
|
ClientConnexion();
|
||||||
@@ -25,6 +26,7 @@ public:
|
|||||||
|
|
||||||
const std::string& GetDisconnectReason() const { return m_DisconnectReason; }
|
const std::string& GetDisconnectReason() const { return m_DisconnectReason; }
|
||||||
float GetServerTPS() const { return m_ServerTPS; }
|
float GetServerTPS() const { return m_ServerTPS; }
|
||||||
|
float GetServerMSPT() const { return m_ServerMSPT; }
|
||||||
int GetServerPing() const { return m_Ping; }
|
int GetServerPing() const { return m_Ping; }
|
||||||
|
|
||||||
REMOVE_COPY(ClientConnexion);
|
REMOVE_COPY(ClientConnexion);
|
||||||
|
|||||||
@@ -18,7 +18,7 @@ class ClientGame : public protocol::PacketHandler, public game::Game {
|
|||||||
private:
|
private:
|
||||||
Client* m_Client;
|
Client* m_Client;
|
||||||
std::uint8_t m_ConnexionID;
|
std::uint8_t m_ConnexionID;
|
||||||
std::uint32_t m_LobbyTime = 0;
|
std::uint64_t m_LobbyStartTime = 0;
|
||||||
game::Player* m_Player = nullptr;
|
game::Player* m_Player = nullptr;
|
||||||
render::Renderer* m_Renderer;
|
render::Renderer* m_Renderer;
|
||||||
client::WorldClient m_WorldClient;
|
client::WorldClient m_WorldClient;
|
||||||
@@ -31,7 +31,7 @@ public:
|
|||||||
|
|
||||||
void RenderWorld();
|
void RenderWorld();
|
||||||
|
|
||||||
std::uint32_t GetLobbyTime() const { return m_LobbyTime; }
|
std::uint64_t GetLobbyStartTime() const { return m_LobbyStartTime; }
|
||||||
const game::Player* GetPlayer() const { return m_Player; }
|
const game::Player* GetPlayer() const { return m_Player; }
|
||||||
const WorldClient& GetWorld() const { return m_WorldClient; }
|
const WorldClient& GetWorld() const { return m_WorldClient; }
|
||||||
Client* GetClient() const { return m_Client; }
|
Client* GetClient() const { return m_Client; }
|
||||||
|
|||||||
@@ -13,7 +13,7 @@ class Lobby {
|
|||||||
private:
|
private:
|
||||||
Server* m_Server;
|
Server* m_Server;
|
||||||
bool m_GameStarted = false;
|
bool m_GameStarted = false;
|
||||||
std::uint64_t m_StartTimerTime = 0;
|
std::uint64_t m_StartTime = 0;
|
||||||
std::vector<std::uint8_t> m_Players;
|
std::vector<std::uint8_t> m_Players;
|
||||||
utils::AutoTimer m_Timer;
|
utils::AutoTimer m_Timer;
|
||||||
public:
|
public:
|
||||||
|
|||||||
@@ -22,6 +22,7 @@ typedef std::map<std::uint8_t, ServerConnexion> ConnexionMap;
|
|||||||
class TickCounter {
|
class TickCounter {
|
||||||
private:
|
private:
|
||||||
float m_TPS;
|
float m_TPS;
|
||||||
|
float m_MSPT;
|
||||||
std::uint64_t m_LastTPSTime;
|
std::uint64_t m_LastTPSTime;
|
||||||
std::uint8_t m_TickCount;
|
std::uint8_t m_TickCount;
|
||||||
public:
|
public:
|
||||||
@@ -46,6 +47,9 @@ public:
|
|||||||
}
|
}
|
||||||
|
|
||||||
float GetTPS() const { return m_TPS; }
|
float GetTPS() const { return m_TPS; }
|
||||||
|
float GetMSPT() const { return m_MSPT; }
|
||||||
|
|
||||||
|
void SetMSPT(float mspt) { m_MSPT = mspt; }
|
||||||
};
|
};
|
||||||
|
|
||||||
class Server {
|
class Server {
|
||||||
|
|||||||
@@ -11,8 +11,7 @@ namespace server {
|
|||||||
|
|
||||||
class Server;
|
class Server;
|
||||||
|
|
||||||
struct KeepAlive
|
struct KeepAlive {
|
||||||
{
|
|
||||||
std::uint64_t keepAliveID = 0;
|
std::uint64_t keepAliveID = 0;
|
||||||
std::uint64_t sendTime;
|
std::uint64_t sendTime;
|
||||||
bool recievedResponse = false;
|
bool recievedResponse = false;
|
||||||
|
|||||||
@@ -14,7 +14,7 @@ std::string format(const std::string& format, Args... args){
|
|||||||
throw std::runtime_error("Error during formatting.");
|
throw std::runtime_error("Error during formatting.");
|
||||||
}
|
}
|
||||||
std::unique_ptr<char[]> buf(new char[size]);
|
std::unique_ptr<char[]> buf(new char[size]);
|
||||||
snprintf(buf.get(), size, format.c_str(), args...);
|
snprintf(buf.get(), static_cast<std::size_t>(size), format.c_str(), args...);
|
||||||
return std::string(buf.get(), buf.get() + size - 1); // We don't want the '\0' inside
|
return std::string(buf.get(), buf.get() + size - 1); // We don't want the '\0' inside
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
177
include/misc/Maths.h
Normal file
177
include/misc/Maths.h
Normal file
@@ -0,0 +1,177 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include "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,6 +1,7 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include "protocol/Protocol.h"
|
#include "protocol/Protocol.h"
|
||||||
|
#include "protocol/PacketsForward.h"
|
||||||
|
|
||||||
namespace td {
|
namespace td {
|
||||||
namespace protocol {
|
namespace protocol {
|
||||||
|
|||||||
27
include/protocol/Packets.h
Normal file
27
include/protocol/Packets.h
Normal file
@@ -0,0 +1,27 @@
|
|||||||
|
#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/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"
|
||||||
34
include/protocol/PacketsForward.h
Normal file
34
include/protocol/PacketsForward.h
Normal file
@@ -0,0 +1,34 @@
|
|||||||
|
#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;
|
||||||
|
|
||||||
|
} // namespace protocol
|
||||||
|
} // namespace td
|
||||||
@@ -1,8 +1,6 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include "misc/DataBuffer.h"
|
#include "misc/DataBuffer.h"
|
||||||
#include "game/World.h"
|
|
||||||
#include "game/BaseGame.h"
|
|
||||||
|
|
||||||
#include <memory>
|
#include <memory>
|
||||||
|
|
||||||
@@ -47,26 +45,6 @@ enum class PacketType : std::uint8_t {
|
|||||||
PACKET_COUNT
|
PACKET_COUNT
|
||||||
};
|
};
|
||||||
|
|
||||||
struct WorldHeader {
|
|
||||||
game::TowerTileColorPalette m_TowerPlacePalette;
|
|
||||||
game::Color m_WalkablePalette;
|
|
||||||
std::vector<game::Color> m_DecorationPalette;
|
|
||||||
game::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 {
|
class Packet {
|
||||||
public:
|
public:
|
||||||
Packet() {}
|
Packet() {}
|
||||||
@@ -76,558 +54,37 @@ public:
|
|||||||
virtual void Deserialize(DataBuffer& data) = 0;
|
virtual void Deserialize(DataBuffer& data) = 0;
|
||||||
virtual void Dispatch(PacketHandler* handler) const = 0;
|
virtual void Dispatch(PacketHandler* handler) const = 0;
|
||||||
|
|
||||||
void WritePacketID(DataBuffer& data, bool packetID) const;
|
virtual void WritePacketID(DataBuffer& data, bool packetID) const;
|
||||||
|
|
||||||
virtual PacketType GetType() const = 0;
|
virtual PacketType GetType() const = 0;
|
||||||
std::uint8_t GetID() const { return static_cast<std::uint8_t>(GetType()); }
|
std::uint8_t GetID() const { return static_cast<std::uint8_t>(GetType()); }
|
||||||
|
|
||||||
|
virtual bool IsTimed() const { return false; }
|
||||||
|
};
|
||||||
|
|
||||||
|
class DelayedPacket : public Packet {
|
||||||
|
protected:
|
||||||
|
std::uint64_t m_PacketTime = 69;
|
||||||
|
|
||||||
|
public:
|
||||||
|
DelayedPacket() {}
|
||||||
|
virtual ~DelayedPacket() {}
|
||||||
|
|
||||||
|
virtual DataBuffer Serialize(bool packetID = true) const = 0;
|
||||||
|
virtual void Deserialize(DataBuffer& data) = 0;
|
||||||
|
virtual void Dispatch(PacketHandler* handler) const = 0;
|
||||||
|
|
||||||
|
virtual void WritePacketID(DataBuffer& data, bool packetID) const override;
|
||||||
|
|
||||||
|
virtual PacketType GetType() const = 0;
|
||||||
|
|
||||||
|
virtual bool IsTimed() const override { return true; }
|
||||||
|
|
||||||
|
void SetPacketTime(std::uint64_t packetTime) { m_PacketTime = packetTime; }
|
||||||
};
|
};
|
||||||
|
|
||||||
typedef std::unique_ptr<Packet> PacketPtr;
|
typedef std::unique_ptr<Packet> PacketPtr;
|
||||||
|
typedef std::unique_ptr<DelayedPacket> DelayedPacketPtr;
|
||||||
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 game::Color& GetWalkableTileColor() const { return m_Header.m_WalkablePalette; }
|
|
||||||
const std::vector<game::Color>& GetDecorationPalette() const { return m_Header.m_DecorationPalette; }
|
|
||||||
const game::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;
|
|
||||||
std::uint64_t m_PacketSendTime; // used to calculate ping
|
|
||||||
public:
|
|
||||||
ServerTpsPacket() {}
|
|
||||||
ServerTpsPacket(float tps, std::uint64_t sendTime) : m_TPS(tps), 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; }
|
|
||||||
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 protocol
|
||||||
} // namespace td
|
} // namespace td
|
||||||
26
include/protocol/packets/ConnectionInfoPacket.h
Normal file
26
include/protocol/packets/ConnectionInfoPacket.h
Normal file
@@ -0,0 +1,26 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include "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/protocol/packets/DisconnectPacket.h
Normal file
26
include/protocol/packets/DisconnectPacket.h
Normal file
@@ -0,0 +1,26 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include "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/protocol/packets/KeepAlivePacket.h
Normal file
26
include/protocol/packets/KeepAlivePacket.h
Normal file
@@ -0,0 +1,26 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include "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/protocol/packets/PlaceTowerPacket.h
Normal file
32
include/protocol/packets/PlaceTowerPacket.h
Normal file
@@ -0,0 +1,32 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include "protocol/Protocol.h"
|
||||||
|
#include "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/protocol/packets/PlayerBuyItemPacket.h
Normal file
38
include/protocol/packets/PlayerBuyItemPacket.h
Normal file
@@ -0,0 +1,38 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include "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/protocol/packets/PlayerBuyMobUpgradePacket.h
Normal file
31
include/protocol/packets/PlayerBuyMobUpgradePacket.h
Normal file
@@ -0,0 +1,31 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include "protocol/Protocol.h"
|
||||||
|
#include "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/protocol/packets/PlayerJoinPacket.h
Normal file
28
include/protocol/packets/PlayerJoinPacket.h
Normal file
@@ -0,0 +1,28 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include "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/protocol/packets/PlayerLeavePacket.h
Normal file
26
include/protocol/packets/PlayerLeavePacket.h
Normal file
@@ -0,0 +1,26 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include "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/protocol/packets/PlayerListPacket.h
Normal file
32
include/protocol/packets/PlayerListPacket.h
Normal file
@@ -0,0 +1,32 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include "protocol/Protocol.h"
|
||||||
|
#include "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/protocol/packets/PlayerLoginPacket.h
Normal file
26
include/protocol/packets/PlayerLoginPacket.h
Normal file
@@ -0,0 +1,26 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include "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/protocol/packets/RemoveTowerPacket.h
Normal file
27
include/protocol/packets/RemoveTowerPacket.h
Normal file
@@ -0,0 +1,27 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include "protocol/Protocol.h"
|
||||||
|
#include "game/BaseGame.h"
|
||||||
|
|
||||||
|
namespace td {
|
||||||
|
namespace protocol {
|
||||||
|
|
||||||
|
class RemoveTowerPacket : public DelayedPacket {
|
||||||
|
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/protocol/packets/SelectTeamPacket.h
Normal file
27
include/protocol/packets/SelectTeamPacket.h
Normal file
@@ -0,0 +1,27 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include "protocol/Protocol.h"
|
||||||
|
#include "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/protocol/packets/SendMobsPacket.h
Normal file
33
include/protocol/packets/SendMobsPacket.h
Normal file
@@ -0,0 +1,33 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include "protocol/Protocol.h"
|
||||||
|
#include "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/protocol/packets/ServerTpsPacket.h
Normal file
30
include/protocol/packets/ServerTpsPacket.h
Normal file
@@ -0,0 +1,30 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include "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/protocol/packets/SpawnMobPacket.h
Normal file
41
include/protocol/packets/SpawnMobPacket.h
Normal file
@@ -0,0 +1,41 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include "protocol/Protocol.h"
|
||||||
|
#include "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/protocol/packets/UpdateCastleLifePacket.h
Normal file
29
include/protocol/packets/UpdateCastleLifePacket.h
Normal file
@@ -0,0 +1,29 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include "protocol/Protocol.h"
|
||||||
|
#include "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
|
||||||
26
include/protocol/packets/UpdateExpPacket.h
Normal file
26
include/protocol/packets/UpdateExpPacket.h
Normal file
@@ -0,0 +1,26 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include "protocol/Protocol.h"
|
||||||
|
|
||||||
|
namespace td {
|
||||||
|
namespace protocol {
|
||||||
|
|
||||||
|
class UpdateExpPacket : public Packet {
|
||||||
|
private:
|
||||||
|
std::uint32_t m_NewAmount;
|
||||||
|
public:
|
||||||
|
UpdateExpPacket() {}
|
||||||
|
UpdateExpPacket(std::uint32_t newAmount) : m_NewAmount(newAmount) {}
|
||||||
|
virtual ~UpdateExpPacket() {}
|
||||||
|
|
||||||
|
std::uint32_t GetExp() const { return m_NewAmount; }
|
||||||
|
|
||||||
|
virtual DataBuffer Serialize(bool packetID = true) const;
|
||||||
|
virtual void Deserialize(DataBuffer& data);
|
||||||
|
virtual void Dispatch(PacketHandler* handler) const;
|
||||||
|
|
||||||
|
virtual PacketType GetType() const { return PacketType::UpdateEXP; }
|
||||||
|
};
|
||||||
|
|
||||||
|
} // namespace protocol
|
||||||
|
} // namespace td
|
||||||
27
include/protocol/packets/UpdateGameStatePacket.h
Normal file
27
include/protocol/packets/UpdateGameStatePacket.h
Normal file
@@ -0,0 +1,27 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include "protocol/Protocol.h"
|
||||||
|
#include "game/BaseGame.h"
|
||||||
|
|
||||||
|
namespace td {
|
||||||
|
namespace protocol {
|
||||||
|
|
||||||
|
class UpdateGameStatePacket : public Packet {
|
||||||
|
private:
|
||||||
|
game::GameState m_GameState;
|
||||||
|
public:
|
||||||
|
UpdateGameStatePacket() {}
|
||||||
|
UpdateGameStatePacket(game::GameState gameState) : m_GameState(gameState) {}
|
||||||
|
virtual ~UpdateGameStatePacket() {}
|
||||||
|
|
||||||
|
virtual DataBuffer Serialize(bool packetID = true) const;
|
||||||
|
virtual void Deserialize(DataBuffer& data);
|
||||||
|
virtual void Dispatch(PacketHandler* handler) const;
|
||||||
|
|
||||||
|
game::GameState GetGameState() const { return m_GameState; }
|
||||||
|
|
||||||
|
virtual PacketType GetType() const { return PacketType::UpdateGameState; }
|
||||||
|
};
|
||||||
|
|
||||||
|
} // namespace protocol
|
||||||
|
} // namespace td
|
||||||
26
include/protocol/packets/UpdateLobbyTimePacket.h
Normal file
26
include/protocol/packets/UpdateLobbyTimePacket.h
Normal file
@@ -0,0 +1,26 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include "protocol/Protocol.h"
|
||||||
|
|
||||||
|
namespace td {
|
||||||
|
namespace protocol {
|
||||||
|
|
||||||
|
class UpdateLobbyTimePacket : public Packet {
|
||||||
|
private:
|
||||||
|
std::uint64_t m_StartTime; // unix millis
|
||||||
|
public:
|
||||||
|
UpdateLobbyTimePacket() {}
|
||||||
|
UpdateLobbyTimePacket(std::uint64_t startTime) : m_StartTime(startTime) {}
|
||||||
|
virtual ~UpdateLobbyTimePacket() {}
|
||||||
|
|
||||||
|
virtual DataBuffer Serialize(bool packetID = true) const;
|
||||||
|
virtual void Deserialize(DataBuffer& data);
|
||||||
|
virtual void Dispatch(PacketHandler* handler) const;
|
||||||
|
|
||||||
|
std::uint64_t GetStartTime() const { return m_StartTime; }
|
||||||
|
|
||||||
|
virtual PacketType GetType() const { return PacketType::UpdateLobbyTime; }
|
||||||
|
};
|
||||||
|
|
||||||
|
} // namespace protocol
|
||||||
|
} // namespace td
|
||||||
47
include/protocol/packets/UpdateMobStatesPacket.h
Normal file
47
include/protocol/packets/UpdateMobStatesPacket.h
Normal file
@@ -0,0 +1,47 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include "protocol/Protocol.h"
|
||||||
|
#include "game/BaseGame.h"
|
||||||
|
|
||||||
|
namespace td {
|
||||||
|
namespace protocol {
|
||||||
|
|
||||||
|
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 DelayedPacket {
|
||||||
|
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; }
|
||||||
|
};
|
||||||
|
|
||||||
|
} // namespace protocol
|
||||||
|
} // namespace td
|
||||||
26
include/protocol/packets/UpdateMoneyPacket.h
Normal file
26
include/protocol/packets/UpdateMoneyPacket.h
Normal file
@@ -0,0 +1,26 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include "protocol/Protocol.h"
|
||||||
|
|
||||||
|
namespace td {
|
||||||
|
namespace protocol {
|
||||||
|
|
||||||
|
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; }
|
||||||
|
};
|
||||||
|
|
||||||
|
} // namespace protocol
|
||||||
|
} // namespace td
|
||||||
29
include/protocol/packets/UpdatePlayerTeamPacket.h
Normal file
29
include/protocol/packets/UpdatePlayerTeamPacket.h
Normal file
@@ -0,0 +1,29 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include "protocol/Protocol.h"
|
||||||
|
#include "game/BaseGame.h"
|
||||||
|
|
||||||
|
namespace td {
|
||||||
|
namespace protocol {
|
||||||
|
|
||||||
|
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; }
|
||||||
|
};
|
||||||
|
|
||||||
|
} // namespace protocol
|
||||||
|
} // namespace td
|
||||||
29
include/protocol/packets/UpgradeTowerPacket.h
Normal file
29
include/protocol/packets/UpgradeTowerPacket.h
Normal file
@@ -0,0 +1,29 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include "protocol/Protocol.h"
|
||||||
|
#include "game/BaseGame.h"
|
||||||
|
|
||||||
|
namespace td {
|
||||||
|
namespace protocol {
|
||||||
|
|
||||||
|
class UpgradeTowerPacket : public DelayedPacket {
|
||||||
|
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; }
|
||||||
|
};
|
||||||
|
|
||||||
|
} // namespace protocol
|
||||||
|
} // namespace td
|
||||||
36
include/protocol/packets/WorldAddTowerPacket.h
Normal file
36
include/protocol/packets/WorldAddTowerPacket.h
Normal file
@@ -0,0 +1,36 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include "protocol/Protocol.h"
|
||||||
|
#include "game/BaseGame.h"
|
||||||
|
|
||||||
|
namespace td {
|
||||||
|
namespace protocol {
|
||||||
|
|
||||||
|
class WorldAddTowerPacket : public DelayedPacket {
|
||||||
|
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; }
|
||||||
|
};
|
||||||
|
|
||||||
|
} // namespace protocol
|
||||||
|
} // namespace td
|
||||||
60
include/protocol/packets/WorldBeginDataPacket.h
Normal file
60
include/protocol/packets/WorldBeginDataPacket.h
Normal file
@@ -0,0 +1,60 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include "protocol/Protocol.h"
|
||||||
|
#include "game/BaseGame.h"
|
||||||
|
|
||||||
|
namespace td {
|
||||||
|
namespace protocol {
|
||||||
|
|
||||||
|
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;
|
||||||
|
};
|
||||||
|
|
||||||
|
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; }
|
||||||
|
};
|
||||||
|
|
||||||
|
} // namespace protocol
|
||||||
|
} // namespace td
|
||||||
36
include/protocol/packets/WorldDataPacket.h
Normal file
36
include/protocol/packets/WorldDataPacket.h
Normal file
@@ -0,0 +1,36 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include "protocol/Protocol.h"
|
||||||
|
#include "game/BaseGame.h"
|
||||||
|
|
||||||
|
namespace td {
|
||||||
|
namespace protocol {
|
||||||
|
|
||||||
|
struct WorldData {
|
||||||
|
std::unordered_map<game::ChunkCoord, game::ChunkPtr> m_Chunks;
|
||||||
|
};
|
||||||
|
|
||||||
|
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; }
|
||||||
|
};
|
||||||
|
|
||||||
|
} // namespace protocol
|
||||||
|
} // namespace td
|
||||||
@@ -9,23 +9,39 @@
|
|||||||
namespace td {
|
namespace td {
|
||||||
namespace render {
|
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 {
|
class Renderer {
|
||||||
public:
|
public:
|
||||||
static constexpr float m_AnimationSpeed = 2.0f;
|
static constexpr float m_AnimationSpeed = 2.0f;
|
||||||
|
static constexpr float m_MouseSensitivity = 200.0f;
|
||||||
|
|
||||||
struct Model {
|
struct Model {
|
||||||
GL::VertexArray* vao;
|
GL::VertexArray* vao;
|
||||||
Vec2f positon;
|
Vec3f positon;
|
||||||
|
Vec3f color = { 1, 1, 1 };
|
||||||
};
|
};
|
||||||
private:
|
private:
|
||||||
std::unique_ptr<shader::WorldShader> m_WorldShader;
|
std::unique_ptr<shader::WorldShader> m_WorldShader;
|
||||||
std::unique_ptr<shader::EntityShader> m_EntityShader;
|
std::unique_ptr<shader::EntityShader> m_EntityShader;
|
||||||
|
|
||||||
|
Vec2i m_WindowSize;
|
||||||
|
|
||||||
Vec3f m_BackgroundColor;
|
Vec3f m_BackgroundColor;
|
||||||
|
|
||||||
bool m_IsometricView = true;
|
Camera m_Camera {};
|
||||||
float m_IsometricShade = m_IsometricView;
|
|
||||||
Vec2f m_CamPos{};
|
|
||||||
public:
|
public:
|
||||||
Renderer();
|
Renderer();
|
||||||
~Renderer();
|
~Renderer();
|
||||||
@@ -38,18 +54,17 @@ public:
|
|||||||
void RenderVAO(const GL::VertexArray& vao);
|
void RenderVAO(const GL::VertexArray& vao);
|
||||||
void RenderModel(const Model& model);
|
void RenderModel(const Model& model);
|
||||||
|
|
||||||
void SetZoom(float zoom);
|
void AddZoom(float zoom);
|
||||||
void SetCamMovement(const Vec2f& mov);
|
void SetCamAngularMovement(const Vec2f& mov);
|
||||||
void SetCamPos(const Vec2f& newPos);
|
void SetCamMovement(const Vec2f& lastCursorPos, const Vec2f& currentCursorPos);
|
||||||
void SetIsometricView(bool isometric); // false = 2D true = Isometric
|
void SetCamLook(const Vec2f& worldPos);
|
||||||
|
|
||||||
void SetBackgroundColor(const Vec3f& color) { m_BackgroundColor = color; }
|
void SetBackgroundColor(const Vec3f& color) { m_BackgroundColor = color; }
|
||||||
|
|
||||||
Vec2f GetCursorWorldPos(const Vec2f& cursorPos, float aspectRatio, float zoom, float windowWidth, float windowHeight);
|
Vec2f GetCursorWorldPos(const Vec2f& cursorPos, float windowWidth, float windowHeight);
|
||||||
private:
|
private:
|
||||||
void UpdateIsometricView();
|
|
||||||
void UpdateIsometricFade();
|
|
||||||
void InitShaders();
|
void InitShaders();
|
||||||
|
void SetCamPos(const Vec3f& newPos);
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace render
|
} // namespace render
|
||||||
|
|||||||
@@ -6,11 +6,10 @@
|
|||||||
#include "render/VertexCache.h"
|
#include "render/VertexCache.h"
|
||||||
|
|
||||||
#include "render/gui/TowerPlacePopup.h"
|
#include "render/gui/TowerPlacePopup.h"
|
||||||
|
#include "render/gui/TowerUpgradePopup.h"
|
||||||
#include "render/gui/MobTooltip.h"
|
#include "render/gui/MobTooltip.h"
|
||||||
#include "render/gui/CastleTooltip.h"
|
#include "render/gui/CastleTooltip.h"
|
||||||
|
|
||||||
#include "render/gui/imgui/imgui.h"
|
|
||||||
|
|
||||||
namespace td {
|
namespace td {
|
||||||
|
|
||||||
namespace client {
|
namespace client {
|
||||||
@@ -19,7 +18,6 @@ class ClientGame;
|
|||||||
|
|
||||||
} // namespace client
|
} // namespace client
|
||||||
|
|
||||||
|
|
||||||
namespace render {
|
namespace render {
|
||||||
|
|
||||||
class WorldRenderer : public game::WorldListener {
|
class WorldRenderer : public game::WorldListener {
|
||||||
@@ -38,6 +36,7 @@ private:
|
|||||||
VertexCache m_TowersCache;
|
VertexCache m_TowersCache;
|
||||||
|
|
||||||
std::unique_ptr<gui::TowerPlacePopup> m_TowerPlacePopup;
|
std::unique_ptr<gui::TowerPlacePopup> m_TowerPlacePopup;
|
||||||
|
std::unique_ptr<gui::TowerUpgradePopup> m_TowerUpgradePopup;
|
||||||
std::unique_ptr<gui::MobTooltip> m_MobTooltip;
|
std::unique_ptr<gui::MobTooltip> m_MobTooltip;
|
||||||
std::unique_ptr<gui::CastleTooltip> m_CastleTooltip;
|
std::unique_ptr<gui::CastleTooltip> m_CastleTooltip;
|
||||||
public:
|
public:
|
||||||
@@ -46,14 +45,12 @@ public:
|
|||||||
|
|
||||||
void LoadModels();
|
void LoadModels();
|
||||||
|
|
||||||
static ImVec4 GetImGuiTeamColor(game::TeamColor color);
|
|
||||||
|
|
||||||
void Update();
|
void Update();
|
||||||
void Render();
|
void Render();
|
||||||
|
|
||||||
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
|
||||||
@@ -67,7 +64,6 @@ private:
|
|||||||
void RenderMobs() const;
|
void RenderMobs() const;
|
||||||
void RenderTileSelect() const;
|
void RenderTileSelect() const;
|
||||||
void RenderPopups();
|
void RenderPopups();
|
||||||
void RenderTowerUpgradePopup();
|
|
||||||
void RenderMobTooltip() const;
|
void RenderMobTooltip() const;
|
||||||
void RenderCastleTooltip() const;
|
void RenderCastleTooltip() const;
|
||||||
void DetectClick();
|
void DetectClick();
|
||||||
|
|||||||
13
include/render/gui/ImGuiTeamColor.h
Normal file
13
include/render/gui/ImGuiTeamColor.h
Normal file
@@ -0,0 +1,13 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include "render/gui/imgui/imgui.h"
|
||||||
|
#include "game/Team.h"
|
||||||
|
|
||||||
|
namespace td {
|
||||||
|
namespace render {
|
||||||
|
|
||||||
|
ImVec4 GetImGuiTeamColor(game::TeamColor color);
|
||||||
|
|
||||||
|
} // namespace render
|
||||||
|
} // namespace td
|
||||||
|
|
||||||
9
include/render/gui/LifeProgress.h
Normal file
9
include/render/gui/LifeProgress.h
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
namespace td {
|
||||||
|
namespace gui {
|
||||||
|
|
||||||
|
extern void RenderLifeProgress(float progress);
|
||||||
|
|
||||||
|
} // namespace gui
|
||||||
|
} // namespace td
|
||||||
@@ -12,11 +12,15 @@ class SummonMenu : public GuiWidget {
|
|||||||
private:
|
private:
|
||||||
bool m_MenuOpened;
|
bool m_MenuOpened;
|
||||||
int m_ImageWidth = 100;
|
int m_ImageWidth = 100;
|
||||||
|
float m_Cooldown;
|
||||||
|
float m_LastCooldown;
|
||||||
static constexpr int m_MobTypeCount = static_cast<std::size_t>(td::game::MobType::MOB_COUNT);
|
static constexpr int m_MobTypeCount = static_cast<std::size_t>(td::game::MobType::MOB_COUNT);
|
||||||
std::array<int, static_cast<std::size_t>(m_MobTypeCount)> m_Values;
|
std::array<int, static_cast<std::size_t>(m_MobTypeCount)> m_Values;
|
||||||
public:
|
public:
|
||||||
SummonMenu(client::Client* client);
|
SummonMenu(client::Client* client);
|
||||||
|
|
||||||
|
void SetCooldown(float cooldown);
|
||||||
|
|
||||||
virtual void Render();
|
virtual void Render();
|
||||||
private:
|
private:
|
||||||
void SetSummonMax(int valueIndex);
|
void SetSummonMax(int valueIndex);
|
||||||
|
|||||||
32
include/render/gui/TowerUpgradePopup.h
Normal file
32
include/render/gui/TowerUpgradePopup.h
Normal file
@@ -0,0 +1,32 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include "GuiWidget.h"
|
||||||
|
|
||||||
|
#include "Defines.h"
|
||||||
|
|
||||||
|
namespace td {
|
||||||
|
namespace gui {
|
||||||
|
|
||||||
|
class TowerUpgradePopup : public GuiWidget {
|
||||||
|
private:
|
||||||
|
Vec2f m_ClickWorldPos;
|
||||||
|
bool m_ShouldBeClosed;
|
||||||
|
bool m_Opened;
|
||||||
|
public:
|
||||||
|
TowerUpgradePopup(client::Client* client);
|
||||||
|
|
||||||
|
virtual void Render();
|
||||||
|
|
||||||
|
void SetClickPos(const Vec2f& worldPos);
|
||||||
|
|
||||||
|
bool IsPopupOpened();
|
||||||
|
private:
|
||||||
|
static constexpr float m_TowerPopupTileWidth = 200.0f;
|
||||||
|
static constexpr float m_TowerPopupTileHeight = 200.0f;
|
||||||
|
|
||||||
|
static constexpr float m_PlaceTowerButtonWidth = 150.0f;
|
||||||
|
static constexpr float m_PlaceTowerButtonHeight = 35.0f;
|
||||||
|
};
|
||||||
|
|
||||||
|
} // namespace gui
|
||||||
|
} // namespace td
|
||||||
@@ -2,21 +2,28 @@
|
|||||||
|
|
||||||
#include "GuiWidget.h"
|
#include "GuiWidget.h"
|
||||||
|
|
||||||
#include "updater/Updater.h"
|
|
||||||
|
|
||||||
#include <future>
|
#include <future>
|
||||||
|
#include <memory>
|
||||||
|
|
||||||
namespace td {
|
namespace td {
|
||||||
|
|
||||||
|
namespace utils {
|
||||||
|
|
||||||
|
class Updater;
|
||||||
|
|
||||||
|
} // namespace utils
|
||||||
|
|
||||||
namespace gui {
|
namespace gui {
|
||||||
|
|
||||||
class UpdateMenu : public GuiWidget {
|
class UpdateMenu : public GuiWidget {
|
||||||
private:
|
private:
|
||||||
bool m_Opened;
|
bool m_Opened;
|
||||||
std::string m_Error;
|
std::string m_Error;
|
||||||
utils::Updater m_Updater;
|
std::unique_ptr<utils::Updater> m_Updater;
|
||||||
std::shared_future<bool> m_UpdateAvailable;
|
std::shared_future<bool> m_UpdateAvailable;
|
||||||
public:
|
public:
|
||||||
UpdateMenu(client::Client* client);
|
UpdateMenu(client::Client* client);
|
||||||
|
virtual ~UpdateMenu();
|
||||||
|
|
||||||
virtual void Render();
|
virtual void Render();
|
||||||
private:
|
private:
|
||||||
|
|||||||
@@ -6,24 +6,22 @@ namespace td {
|
|||||||
namespace shader {
|
namespace shader {
|
||||||
|
|
||||||
class EntityShader : public ShaderProgram {
|
class EntityShader : public ShaderProgram {
|
||||||
|
|
||||||
private:
|
private:
|
||||||
unsigned int m_LocationCam = 0;
|
unsigned int m_LocationProjectionMatrix = 0;
|
||||||
unsigned int m_LocationZoom = 0;
|
unsigned int m_LocationViewMatrix = 0;
|
||||||
unsigned int m_LocationAspectRatio = 0;
|
unsigned int m_LocationPosition = 0;
|
||||||
unsigned int m_LocationTranslation = 0;
|
unsigned int m_LocationColorEffect = 0;
|
||||||
unsigned int m_LocationViewtype = 0;
|
|
||||||
protected:
|
protected:
|
||||||
virtual void GetAllUniformLocation();
|
virtual void GetAllUniformLocation();
|
||||||
public:
|
public:
|
||||||
EntityShader();
|
EntityShader();
|
||||||
|
|
||||||
void LoadShader();
|
void LoadShader();
|
||||||
void SetCamPos(const Vec2f& camPos);
|
|
||||||
void SetZoom(float zoom);
|
void SetColorEffect(const Vec3f& color);
|
||||||
void SetAspectRatio(float aspectRatio);
|
void SetProjectionMatrix(const Mat4f& proj) const;
|
||||||
void SetModelPos(const Vec2f& modelPos);
|
void SetViewMatrix(const Mat4f& view) const;
|
||||||
void SetIsometricView(float isometric);
|
void SetModelPos(const Vec3f& pos) const;
|
||||||
};
|
};
|
||||||
|
|
||||||
} // 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
|
||||||
|
|||||||
@@ -203,6 +203,7 @@ bool Mob::IsTouchingCastle(const TeamCastle& enemyCastle) const {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void Mob::Tick(std::uint64_t delta, World* world) {
|
void Mob::Tick(std::uint64_t delta, World* world) {
|
||||||
|
m_HitCooldown = std::max(0.0f, m_HitCooldown - static_cast<float>(delta / 1000.0f));
|
||||||
UpdateEffects(delta, world);
|
UpdateEffects(delta, world);
|
||||||
Move(delta, world);
|
Move(delta, world);
|
||||||
AttackCastle(delta, world);
|
AttackCastle(delta, world);
|
||||||
|
|||||||
@@ -201,119 +201,5 @@ std::string GetTowerName(TowerType type) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
} // namespace TowerFactory
|
} // namespace TowerFactory
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
void ArcherTower::Tick(std::uint64_t delta, World* world) {
|
|
||||||
if (m_Timer.Update(delta)) {
|
|
||||||
std::uint8_t arrowsShot = 0;
|
|
||||||
bool explosiveArrows = GetLevel().GetPath() == TowerPath::Bottom;
|
|
||||||
std::uint8_t arrows = explosiveArrows ? 2 : GetLevel().GetLevel();
|
|
||||||
for (MobPtr mob : world->GetMobList()) {
|
|
||||||
if (IsMobInRange(mob)) {
|
|
||||||
world->GetWorldNotifier().NotifyListeners(&WorldListener::OnArcherTowerShot, mob, this);
|
|
||||||
m_Timer.ApplyCooldown();
|
|
||||||
arrowsShot++;
|
|
||||||
if (arrowsShot >= arrows)
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void IceTower::Tick(std::uint64_t delta, World* world) {
|
|
||||||
if (m_Timer.Update(delta)) {
|
|
||||||
float damage = GetStats()->GetDamage();
|
|
||||||
for (MobPtr mob : world->GetMobList()) {
|
|
||||||
if (IsMobInRange(mob)) {
|
|
||||||
mob->AddEffect(EffectType::Slowness, 1, this); // slowness for 1s every second
|
|
||||||
if (damage > 0)
|
|
||||||
world->GetMobNotifier().NotifyListeners(&MobListener::OnMobDamage, mob.get(), damage, this);
|
|
||||||
m_Timer.ApplyCooldown();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void MageTower::Tick(std::uint64_t delta, World* world) {
|
|
||||||
if (m_Timer.Update(delta)) {
|
|
||||||
for (MobPtr mob : world->GetMobList()) {
|
|
||||||
if (IsMobInRange(mob)) {
|
|
||||||
mob->AddEffect(EffectType::Fire, GetLevel().GetLevel() * 3, this);
|
|
||||||
m_Timer.ApplyCooldown();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void PoisonTower::Tick(std::uint64_t delta, World* world) {
|
|
||||||
if (m_Timer.Update(delta)) {
|
|
||||||
for (MobPtr mob : world->GetMobList()) {
|
|
||||||
if (IsMobInRange(mob)) {
|
|
||||||
if (GetLevel().GetPath() == TowerPath::Bottom) {
|
|
||||||
world->GetMobNotifier().NotifyListeners(&MobListener::OnMobDamage, mob.get(), GetStats()->GetDamage(), this);
|
|
||||||
} else {
|
|
||||||
float durationSec;
|
|
||||||
switch (GetLevel().GetLevel()) {
|
|
||||||
case 1:
|
|
||||||
durationSec = 5;
|
|
||||||
break;
|
|
||||||
|
|
||||||
case 2:
|
|
||||||
durationSec = 15;
|
|
||||||
break;
|
|
||||||
|
|
||||||
case 3:
|
|
||||||
durationSec = 30;
|
|
||||||
break;
|
|
||||||
|
|
||||||
case 4:
|
|
||||||
durationSec = 1e10; // about 3 million hours. It should be enough
|
|
||||||
break;
|
|
||||||
|
|
||||||
default:
|
|
||||||
durationSec = 0; // how did we get there ?
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
mob->AddEffect(EffectType::Poison, durationSec, this);
|
|
||||||
}
|
|
||||||
m_Timer.ApplyCooldown();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void QuakeTower::Tick(std::uint64_t delta, World* world) {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
void ZeusTower::Tick(std::uint64_t delta, World* world) {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
void ArtilleryTower::Tick(std::uint64_t delta, World* world) {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
void SorcererTower::Tick(std::uint64_t delta, World* world) {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
void LeachTower::Tick(std::uint64_t delta, World* world) {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
void TurretTower::Tick(std::uint64_t delta, World* world) {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
void NecromancerTower::Tick(std::uint64_t delta, World* world) {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
} // namespace game
|
} // namespace game
|
||||||
} // namespace td
|
} // namespace td
|
||||||
|
|||||||
@@ -1,6 +1,8 @@
|
|||||||
#include "game/World.h"
|
#include "game/World.h"
|
||||||
#include "protocol/PacketDispatcher.h"
|
#include "protocol/PacketDispatcher.h"
|
||||||
#include "protocol/Protocol.h"
|
#include "protocol/Protocol.h"
|
||||||
|
#include "protocol/packets/WorldBeginDataPacket.h"
|
||||||
|
#include "protocol/packets/WorldDataPacket.h"
|
||||||
#include "game/BaseGame.h"
|
#include "game/BaseGame.h"
|
||||||
#include "misc/Random.h"
|
#include "misc/Random.h"
|
||||||
#include "misc/Compression.h"
|
#include "misc/Compression.h"
|
||||||
|
|||||||
@@ -1,6 +1,12 @@
|
|||||||
#include "game/client/Client.h"
|
#include "game/client/Client.h"
|
||||||
#include "misc/Format.h"
|
#include "misc/Format.h"
|
||||||
|
|
||||||
|
#include "protocol/packets/DisconnectPacket.h"
|
||||||
|
#include "protocol/packets/PlaceTowerPacket.h"
|
||||||
|
#include "protocol/packets/RemoveTowerPacket.h"
|
||||||
|
#include "protocol/packets/SelectTeamPacket.h"
|
||||||
|
#include "protocol/packets/UpgradeTowerPacket.h"
|
||||||
|
|
||||||
namespace td {
|
namespace td {
|
||||||
namespace client {
|
namespace client {
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,12 @@
|
|||||||
#include "game/client/ClientConnexion.h"
|
#include "game/client/ClientConnexion.h"
|
||||||
#include "render/WorldRenderer.h"
|
#include "render/WorldRenderer.h"
|
||||||
|
|
||||||
|
#include "protocol/packets/ConnectionInfoPacket.h"
|
||||||
|
#include "protocol/packets/DisconnectPacket.h"
|
||||||
|
#include "protocol/packets/KeepAlivePacket.h"
|
||||||
|
#include "protocol/packets/PlayerLoginPacket.h"
|
||||||
|
#include "protocol/packets/ServerTpsPacket.h"
|
||||||
|
|
||||||
namespace td {
|
namespace td {
|
||||||
namespace client {
|
namespace client {
|
||||||
|
|
||||||
@@ -27,11 +33,12 @@ void ClientConnexion::HandlePacket(const protocol::ConnexionInfoPacket* packet)
|
|||||||
|
|
||||||
void ClientConnexion::HandlePacket(const protocol::ServerTpsPacket* packet) {
|
void ClientConnexion::HandlePacket(const protocol::ServerTpsPacket* packet) {
|
||||||
m_ServerTPS = packet->GetTPS();
|
m_ServerTPS = packet->GetTPS();
|
||||||
|
m_ServerMSPT = packet->GetMSPT();
|
||||||
m_Ping = utils::GetTime() - packet->GetPacketSendTime();
|
m_Ping = utils::GetTime() - packet->GetPacketSendTime();
|
||||||
}
|
}
|
||||||
|
|
||||||
void ClientConnexion::Login() {
|
void ClientConnexion::Login() {
|
||||||
td::protocol::PlayerLoginPacket loginPacket("Persson" + std::to_string(m_ConnectionID));
|
td::protocol::PlayerLoginPacket loginPacket("Persson" + std::to_string(static_cast<unsigned int>(m_ConnectionID)));
|
||||||
SendPacket(&loginPacket);
|
SendPacket(&loginPacket);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -2,6 +2,18 @@
|
|||||||
#include "protocol/PacketDispatcher.h"
|
#include "protocol/PacketDispatcher.h"
|
||||||
#include "game/client/Client.h"
|
#include "game/client/Client.h"
|
||||||
|
|
||||||
|
#include "protocol/packets/ConnectionInfoPacket.h"
|
||||||
|
#include "protocol/packets/PlayerJoinPacket.h"
|
||||||
|
#include "protocol/packets/PlayerListPacket.h"
|
||||||
|
#include "protocol/packets/PlayerLeavePacket.h"
|
||||||
|
#include "protocol/packets/UpdatePlayerTeamPacket.h"
|
||||||
|
#include "protocol/packets/UpdateLobbyTimePacket.h"
|
||||||
|
#include "protocol/packets/UpdateGameStatePacket.h"
|
||||||
|
#include "protocol/packets/UpdateMoneyPacket.h"
|
||||||
|
#include "protocol/packets/UpdateExpPacket.h"
|
||||||
|
#include "protocol/packets/DisconnectPacket.h"
|
||||||
|
#include "protocol/packets/WorldDataPacket.h"
|
||||||
|
|
||||||
namespace td {
|
namespace td {
|
||||||
namespace client {
|
namespace client {
|
||||||
|
|
||||||
@@ -28,9 +40,6 @@ ClientGame::~ClientGame() {
|
|||||||
void ClientGame::Tick(std::uint64_t delta) {
|
void ClientGame::Tick(std::uint64_t delta) {
|
||||||
game::Game::Tick(delta);
|
game::Game::Tick(delta);
|
||||||
m_WorldRenderer.Update();
|
m_WorldRenderer.Update();
|
||||||
if (m_GameState == game::GameState::Lobby && m_LobbyTime > 0) {
|
|
||||||
m_LobbyTime -= delta;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void ClientGame::HandlePacket(const protocol::PlayerJoinPacket* packet) {
|
void ClientGame::HandlePacket(const protocol::PlayerJoinPacket* packet) {
|
||||||
@@ -43,7 +52,7 @@ void ClientGame::HandlePacket(const protocol::PlayerJoinPacket* packet) {
|
|||||||
void ClientGame::HandlePacket(const protocol::PlayerLeavePacket* packet) {
|
void ClientGame::HandlePacket(const protocol::PlayerLeavePacket* packet) {
|
||||||
game::Player* player = &m_Players[packet->GetPlayerID()];
|
game::Player* player = &m_Players[packet->GetPlayerID()];
|
||||||
if (player->GetTeamColor() != game::TeamColor::None) {
|
if (player->GetTeamColor() != game::TeamColor::None) {
|
||||||
m_Teams[(std::size_t)player->GetTeamColor()].RemovePlayer(player);
|
m_Teams[static_cast<std::size_t>(player->GetTeamColor())].RemovePlayer(player);
|
||||||
}
|
}
|
||||||
m_Players.erase(player->GetID());
|
m_Players.erase(player->GetID());
|
||||||
}
|
}
|
||||||
@@ -57,7 +66,7 @@ void ClientGame::HandlePacket(const protocol::PlayerListPacket* packet) {
|
|||||||
player.SetTeamColor(playerInfo.team);
|
player.SetTeamColor(playerInfo.team);
|
||||||
m_Players.insert({ playerID, player });
|
m_Players.insert({ playerID, player });
|
||||||
if (player.GetTeamColor() != game::TeamColor::None) {
|
if (player.GetTeamColor() != game::TeamColor::None) {
|
||||||
m_Teams[(std::size_t)player.GetTeamColor()].AddPlayer(&m_Players[playerID]);
|
m_Teams[static_cast<std::size_t>(player.GetTeamColor())].AddPlayer(&m_Players[playerID]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
m_Player = &m_Players[m_ConnexionID];
|
m_Player = &m_Players[m_ConnexionID];
|
||||||
@@ -85,7 +94,8 @@ void ClientGame::HandlePacket(const protocol::ConnexionInfoPacket* packet) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void ClientGame::HandlePacket(const protocol::UpdateLobbyTimePacket* packet) {
|
void ClientGame::HandlePacket(const protocol::UpdateLobbyTimePacket* packet) {
|
||||||
m_LobbyTime = packet->GetRemainingTime();
|
m_GameStartTime = packet->GetStartTime();
|
||||||
|
m_LobbyStartTime = utils::GetTime();
|
||||||
}
|
}
|
||||||
|
|
||||||
void ClientGame::HandlePacket(const protocol::UpdateMoneyPacket* packet) {
|
void ClientGame::HandlePacket(const protocol::UpdateMoneyPacket* packet) {
|
||||||
|
|||||||
@@ -3,6 +3,15 @@
|
|||||||
#include "game/client/ClientGame.h"
|
#include "game/client/ClientGame.h"
|
||||||
#include "render/WorldRenderer.h"
|
#include "render/WorldRenderer.h"
|
||||||
|
|
||||||
|
#include "protocol/packets/WorldAddTowerPacket.h"
|
||||||
|
#include "protocol/packets/WorldBeginDataPacket.h"
|
||||||
|
#include "protocol/packets/WorldDataPacket.h"
|
||||||
|
#include "protocol/packets/SpawnMobPacket.h"
|
||||||
|
#include "protocol/packets/UpgradeTowerPacket.h"
|
||||||
|
#include "protocol/packets/RemoveTowerPacket.h"
|
||||||
|
#include "protocol/packets/UpdateCastleLifePacket.h"
|
||||||
|
#include "protocol/packets/UpdateMobStatesPacket.h"
|
||||||
|
|
||||||
namespace td {
|
namespace td {
|
||||||
namespace client {
|
namespace client {
|
||||||
|
|
||||||
@@ -20,7 +29,7 @@ WorldClient::WorldClient(ClientGame* game) : game::World(game), protocol::Packet
|
|||||||
void WorldClient::HandlePacket(const protocol::WorldBeginDataPacket* packet) {
|
void WorldClient::HandlePacket(const protocol::WorldBeginDataPacket* packet) {
|
||||||
LoadMap(packet);
|
LoadMap(packet);
|
||||||
if (m_Game->GetGameState() == game::GameState::Game) {
|
if (m_Game->GetGameState() == game::GameState::Game) {
|
||||||
const game::Color& backgroundColor = GetBackgroundColor();
|
const Color& backgroundColor = GetBackgroundColor();
|
||||||
m_Game->GetRenderer()->SetBackgroundColor({ static_cast<float>(backgroundColor.r / 255.0f), static_cast<float>(backgroundColor.g / 255.0f),
|
m_Game->GetRenderer()->SetBackgroundColor({ static_cast<float>(backgroundColor.r / 255.0f), static_cast<float>(backgroundColor.g / 255.0f),
|
||||||
static_cast<float>(backgroundColor.b / 255.0f) });
|
static_cast<float>(backgroundColor.b / 255.0f) });
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,8 @@
|
|||||||
#include "game/server/Lobby.h"
|
#include "game/server/Lobby.h"
|
||||||
#include "game/server/Server.h"
|
#include "game/server/Server.h"
|
||||||
|
|
||||||
|
#include "protocol/packets/UpdateLobbyTimePacket.h"
|
||||||
|
|
||||||
#include "misc/Time.h"
|
#include "misc/Time.h"
|
||||||
|
|
||||||
#ifdef NDEBUG
|
#ifdef NDEBUG
|
||||||
@@ -31,33 +33,39 @@ Lobby::Lobby(Server* server) : m_Server(server), m_Timer(1000, std::bind(&Lobby:
|
|||||||
}
|
}
|
||||||
|
|
||||||
void Lobby::Tick() {
|
void Lobby::Tick() {
|
||||||
if (m_GameStarted || m_StartTimerTime == 0)
|
if (m_GameStarted || m_StartTime == 0)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if (utils::GetTime() - m_StartTimerTime >= LobbyWaitingTime) {
|
if (utils::GetTime() >= m_StartTime) {
|
||||||
m_Server->GetGame().NotifyListeners(&game::GameListener::OnGameBegin);
|
m_Server->GetGame().NotifyListeners(&game::GameListener::OnGameBegin);
|
||||||
m_GameStarted = true;
|
m_GameStarted = true;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
m_Timer.Update();
|
//m_Timer.Update();
|
||||||
}
|
}
|
||||||
|
|
||||||
void Lobby::SendTimeRemaining() {
|
void Lobby::SendTimeRemaining() {
|
||||||
protocol::UpdateLobbyTimePacket packet(LobbyWaitingTime - (utils::GetTime() - m_StartTimerTime)); // converting second to millis
|
protocol::UpdateLobbyTimePacket packet(m_StartTime);
|
||||||
m_Server->BroadcastPacket(&packet);
|
m_Server->BroadcastPacket(&packet);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Lobby::OnPlayerJoin(std::uint8_t playerID) {
|
void Lobby::OnPlayerJoin(std::uint8_t playerID) {
|
||||||
if (m_GameStarted)
|
if (m_GameStarted)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
utils::LOG("(Server) Player Joined Lobby !");
|
utils::LOG("(Server) Player Joined Lobby !");
|
||||||
m_Players.push_back(playerID);
|
m_Players.push_back(playerID);
|
||||||
|
|
||||||
if (m_Players.size() == MIN_PLAYER_WAITING) { // start timer if a second player join the match
|
if (m_Players.size() == MIN_PLAYER_WAITING) { // start timer if a second player join the match
|
||||||
m_StartTimerTime = utils::GetTime();
|
m_StartTime = utils::GetTime() + static_cast<std::uint64_t>(LobbyWaitingTime);
|
||||||
m_Timer.Reset();
|
m_Timer.Reset();
|
||||||
SendTimeRemaining();
|
SendTimeRemaining();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// notify player that just arrived
|
||||||
|
protocol::UpdateLobbyTimePacket packet(m_StartTime);
|
||||||
|
m_Server->GetConnexions().at(playerID).SendPacket(&packet);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Lobby::OnPlayerLeave(std::uint8_t playerID) {
|
void Lobby::OnPlayerLeave(std::uint8_t playerID) {
|
||||||
@@ -71,9 +79,8 @@ void Lobby::OnPlayerLeave(std::uint8_t playerID) {
|
|||||||
m_Players.erase(it);
|
m_Players.erase(it);
|
||||||
|
|
||||||
if (m_Players.size() == 1) {
|
if (m_Players.size() == 1) {
|
||||||
protocol::UpdateLobbyTimePacket packet(0);
|
m_StartTime = 0; // reset timer if there is only one player left
|
||||||
m_Server->BroadcastPacket(&packet);
|
SendTimeRemaining();
|
||||||
m_StartTimerTime = 0; // reset timer if there is only one player left
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,10 @@
|
|||||||
#include "game/server/Server.h"
|
#include "game/server/Server.h"
|
||||||
#include "protocol/PacketFactory.h"
|
#include "protocol/PacketFactory.h"
|
||||||
|
|
||||||
|
#include "protocol/packets/DisconnectPacket.h"
|
||||||
|
#include "protocol/packets/ServerTpsPacket.h"
|
||||||
|
#include "protocol/packets/PlayerLeavePacket.h"
|
||||||
|
|
||||||
#include "misc/Format.h"
|
#include "misc/Format.h"
|
||||||
|
|
||||||
namespace td {
|
namespace td {
|
||||||
@@ -26,6 +30,7 @@ void Server::StartThread() {
|
|||||||
if (delta >= SERVER_TICK) {
|
if (delta >= SERVER_TICK) {
|
||||||
Tick(delta);
|
Tick(delta);
|
||||||
lastTime = td::utils::GetTime();
|
lastTime = td::utils::GetTime();
|
||||||
|
m_TickCounter.SetMSPT(lastTime - time);
|
||||||
std::uint64_t sleepTime = SERVER_TICK - (delta - SERVER_TICK);
|
std::uint64_t sleepTime = SERVER_TICK - (delta - SERVER_TICK);
|
||||||
std::this_thread::sleep_for(std::chrono::milliseconds(sleepTime));
|
std::this_thread::sleep_for(std::chrono::milliseconds(sleepTime));
|
||||||
}
|
}
|
||||||
@@ -85,7 +90,7 @@ void Server::Tick(std::uint64_t delta) {
|
|||||||
m_Lobby.Tick();
|
m_Lobby.Tick();
|
||||||
m_Game.Tick(delta);
|
m_Game.Tick(delta);
|
||||||
if (m_TickCounter.Update()) {
|
if (m_TickCounter.Update()) {
|
||||||
protocol::ServerTpsPacket packet(m_TickCounter.GetTPS(), utils::GetTime());
|
protocol::ServerTpsPacket packet(m_TickCounter.GetTPS(), m_TickCounter.GetMSPT(), utils::GetTime());
|
||||||
BroadcastPacket(&packet);
|
BroadcastPacket(&packet);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -140,6 +145,10 @@ void Server::OnPlayerJoin(std::uint8_t id) {
|
|||||||
void Server::OnPlayerLeave(std::uint8_t id) {
|
void Server::OnPlayerLeave(std::uint8_t id) {
|
||||||
protocol::PlayerLeavePacket packet(id);
|
protocol::PlayerLeavePacket packet(id);
|
||||||
BroadcastPacket(&packet);
|
BroadcastPacket(&packet);
|
||||||
|
|
||||||
|
if (GetPlayers().empty()) {
|
||||||
|
Close();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace server
|
} // namespace server
|
||||||
|
|||||||
@@ -3,6 +3,23 @@
|
|||||||
#include "protocol/PacketFactory.h"
|
#include "protocol/PacketFactory.h"
|
||||||
#include "game/server/Server.h"
|
#include "game/server/Server.h"
|
||||||
|
|
||||||
|
#include "protocol/packets/ConnectionInfoPacket.h"
|
||||||
|
#include "protocol/packets/DisconnectPacket.h"
|
||||||
|
#include "protocol/packets/KeepAlivePacket.h"
|
||||||
|
#include "protocol/packets/PlaceTowerPacket.h"
|
||||||
|
#include "protocol/packets/PlayerLoginPacket.h"
|
||||||
|
#include "protocol/packets/PlayerJoinPacket.h"
|
||||||
|
#include "protocol/packets/PlayerListPacket.h"
|
||||||
|
#include "protocol/packets/RemoveTowerPacket.h"
|
||||||
|
#include "protocol/packets/SelectTeamPacket.h"
|
||||||
|
#include "protocol/packets/SendMobsPacket.h"
|
||||||
|
#include "protocol/packets/UpdatePlayerTeamPacket.h"
|
||||||
|
#include "protocol/packets/UpdateGameStatePacket.h"
|
||||||
|
#include "protocol/packets/UpgradeTowerPacket.h"
|
||||||
|
#include "protocol/packets/WorldBeginDataPacket.h"
|
||||||
|
#include "protocol/packets/WorldDataPacket.h"
|
||||||
|
#include "protocol/packets/WorldAddTowerPacket.h"
|
||||||
|
|
||||||
#include "misc/Time.h"
|
#include "misc/Time.h"
|
||||||
#include "misc/Random.h"
|
#include "misc/Random.h"
|
||||||
|
|
||||||
@@ -10,6 +27,8 @@
|
|||||||
|
|
||||||
#define KEEP_ALIVE_TIMEOUT 10 * 1000 // 10s
|
#define KEEP_ALIVE_TIMEOUT 10 * 1000 // 10s
|
||||||
|
|
||||||
|
#define SAFE_CHECK(expr) if(expr) return
|
||||||
|
|
||||||
namespace td {
|
namespace td {
|
||||||
namespace server {
|
namespace server {
|
||||||
|
|
||||||
@@ -97,8 +116,8 @@ void ServerConnexion::HandlePacket(const protocol::PlayerLoginPacket* packet) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void ServerConnexion::HandlePacket(const protocol::SelectTeamPacket* packet) {
|
void ServerConnexion::HandlePacket(const protocol::SelectTeamPacket* packet) {
|
||||||
if (m_Server->GetGame().GetGameState() != game::GameState::Lobby)
|
SAFE_CHECK(m_Server->GetGame().GetGameState() != game::GameState::Lobby);
|
||||||
return;
|
|
||||||
if (static_cast<std::int8_t>(packet->GetSelectedTeam()) >= -1 || static_cast<std::int8_t>(packet->GetSelectedTeam()) <= 1) {
|
if (static_cast<std::int8_t>(packet->GetSelectedTeam()) >= -1 || static_cast<std::int8_t>(packet->GetSelectedTeam()) <= 1) {
|
||||||
if (m_Player->GetTeamColor() == game::TeamColor::None) { // join a team
|
if (m_Player->GetTeamColor() == game::TeamColor::None) { // join a team
|
||||||
m_Server->GetGame().GetTeam(packet->GetSelectedTeam()).AddPlayer(m_Player);
|
m_Server->GetGame().GetTeam(packet->GetSelectedTeam()).AddPlayer(m_Player);
|
||||||
@@ -138,13 +157,13 @@ void ServerConnexion::InitConnection() {
|
|||||||
protocol::ConnexionInfoPacket conPacket(m_ID);
|
protocol::ConnexionInfoPacket conPacket(m_ID);
|
||||||
SendPacket(&conPacket);
|
SendPacket(&conPacket);
|
||||||
|
|
||||||
if (m_Server->GetGame().GetGameState() == game::GameState::Game) {
|
SAFE_CHECK(m_Server->GetGame().GetGameState() != game::GameState::Game);
|
||||||
|
|
||||||
protocol::WorldBeginDataPacket headerDataPacket(m_Server->GetGame().GetWorld());
|
protocol::WorldBeginDataPacket headerDataPacket(m_Server->GetGame().GetWorld());
|
||||||
protocol::WorldBeginDataPacket dataPacket(m_Server->GetGame().GetWorld());
|
protocol::WorldBeginDataPacket dataPacket(m_Server->GetGame().GetWorld());
|
||||||
SendPacket(&headerDataPacket);
|
SendPacket(&headerDataPacket);
|
||||||
SendPacket(&dataPacket);
|
SendPacket(&dataPacket);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
void ServerConnexion::HandlePacket(const protocol::PlaceTowerPacket* packet) {
|
void ServerConnexion::HandlePacket(const protocol::PlaceTowerPacket* packet) {
|
||||||
game::TowerType towerType = packet->GetTowerType();
|
game::TowerType towerType = packet->GetTowerType();
|
||||||
@@ -153,12 +172,10 @@ void ServerConnexion::HandlePacket(const protocol::PlaceTowerPacket* packet) {
|
|||||||
|
|
||||||
Vec2f towerPos = { static_cast<float>(packet->GetTowerX()), static_cast<float>(packet->GetTowerY()) };
|
Vec2f towerPos = { static_cast<float>(packet->GetTowerX()), static_cast<float>(packet->GetTowerY()) };
|
||||||
|
|
||||||
if (!world->CanPlaceLittleTower(towerPos, m_ID))
|
SAFE_CHECK(!world->CanPlaceLittleTower(towerPos, m_ID));
|
||||||
return;
|
|
||||||
|
|
||||||
if (towerInfo.IsBigTower())
|
if (towerInfo.IsBigTower())
|
||||||
if (!world->CanPlaceBigTower(towerPos, m_ID))
|
SAFE_CHECK(!world->CanPlaceBigTower(towerPos, m_ID));
|
||||||
return;
|
|
||||||
|
|
||||||
game::TowerPtr tower = world->PlaceTowerAt(towerType, packet->GetTowerX(), packet->GetTowerY(), m_ID);
|
game::TowerPtr tower = world->PlaceTowerAt(towerType, packet->GetTowerX(), packet->GetTowerY(), m_ID);
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,15 @@
|
|||||||
#include "game/server/ServerGame.h"
|
#include "game/server/ServerGame.h"
|
||||||
#include "game/server/Server.h"
|
#include "game/server/Server.h"
|
||||||
|
|
||||||
|
#include "protocol/packets/DisconnectPacket.h"
|
||||||
|
#include "protocol/packets/UpdatePlayerTeamPacket.h"
|
||||||
|
#include "protocol/packets/UpdateGameStatePacket.h"
|
||||||
|
#include "protocol/packets/UpdateMoneyPacket.h"
|
||||||
|
#include "protocol/packets/UpdateExpPacket.h"
|
||||||
|
#include "protocol/packets/UpdateMobStatesPacket.h"
|
||||||
|
#include "protocol/packets/WorldDataPacket.h"
|
||||||
|
#include "protocol/packets/WorldBeginDataPacket.h"
|
||||||
|
|
||||||
namespace td {
|
namespace td {
|
||||||
namespace server {
|
namespace server {
|
||||||
|
|
||||||
|
|||||||
@@ -2,6 +2,9 @@
|
|||||||
#include "game/server/Server.h"
|
#include "game/server/Server.h"
|
||||||
#include "misc/Random.h"
|
#include "misc/Random.h"
|
||||||
|
|
||||||
|
#include "protocol/packets/SpawnMobPacket.h"
|
||||||
|
#include "protocol/packets/UpdateCastleLifePacket.h"
|
||||||
|
|
||||||
#define MOB_SPAWN_PRECISION 100.0f
|
#define MOB_SPAWN_PRECISION 100.0f
|
||||||
|
|
||||||
namespace td {
|
namespace td {
|
||||||
|
|||||||
25
src/game/towers/ArcherTower.cpp
Normal file
25
src/game/towers/ArcherTower.cpp
Normal file
@@ -0,0 +1,25 @@
|
|||||||
|
#include "game/Towers.h"
|
||||||
|
#include "game/World.h"
|
||||||
|
|
||||||
|
namespace td {
|
||||||
|
namespace game {
|
||||||
|
|
||||||
|
void ArcherTower::Tick(std::uint64_t delta, World* world) {
|
||||||
|
if (m_Timer.Update(delta)) {
|
||||||
|
std::uint8_t arrowsShot = 0;
|
||||||
|
bool explosiveArrows = GetLevel().GetPath() == TowerPath::Bottom;
|
||||||
|
std::uint8_t arrows = explosiveArrows ? 2 : GetLevel().GetLevel();
|
||||||
|
for (MobPtr mob : world->GetMobList()) {
|
||||||
|
if (IsMobInRange(mob)) {
|
||||||
|
world->GetWorldNotifier().NotifyListeners(&WorldListener::OnArcherTowerShot, mob, this);
|
||||||
|
m_Timer.ApplyCooldown();
|
||||||
|
arrowsShot++;
|
||||||
|
if (arrowsShot >= arrows)
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
} // namespace game
|
||||||
|
} // namespace td
|
||||||
12
src/game/towers/ArtilleryTower.cpp
Normal file
12
src/game/towers/ArtilleryTower.cpp
Normal file
@@ -0,0 +1,12 @@
|
|||||||
|
#include "game/Towers.h"
|
||||||
|
#include "game/World.h"
|
||||||
|
|
||||||
|
namespace td {
|
||||||
|
namespace game {
|
||||||
|
|
||||||
|
void ArtilleryTower::Tick(std::uint64_t delta, World* world) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
} // namespace game
|
||||||
|
} // namespace td
|
||||||
22
src/game/towers/IceTower.cpp
Normal file
22
src/game/towers/IceTower.cpp
Normal file
@@ -0,0 +1,22 @@
|
|||||||
|
#include "game/Towers.h"
|
||||||
|
#include "game/World.h"
|
||||||
|
|
||||||
|
namespace td {
|
||||||
|
namespace game {
|
||||||
|
|
||||||
|
void IceTower::Tick(std::uint64_t delta, World* world) {
|
||||||
|
if (m_Timer.Update(delta)) {
|
||||||
|
float damage = GetStats()->GetDamage();
|
||||||
|
for (MobPtr mob : world->GetMobList()) {
|
||||||
|
if (IsMobInRange(mob)) {
|
||||||
|
mob->AddEffect(EffectType::Slowness, 1, this); // slowness for 1s every second
|
||||||
|
if (damage > 0)
|
||||||
|
world->GetMobNotifier().NotifyListeners(&MobListener::OnMobDamage, mob.get(), damage, this);
|
||||||
|
m_Timer.ApplyCooldown();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
} // namespace game
|
||||||
|
} // namespace td
|
||||||
12
src/game/towers/LeachTower.cpp
Normal file
12
src/game/towers/LeachTower.cpp
Normal file
@@ -0,0 +1,12 @@
|
|||||||
|
#include "game/Towers.h"
|
||||||
|
#include "game/World.h"
|
||||||
|
|
||||||
|
namespace td {
|
||||||
|
namespace game {
|
||||||
|
|
||||||
|
void LeachTower::Tick(std::uint64_t delta, World* world) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
} // namespace game
|
||||||
|
} // namespace td
|
||||||
19
src/game/towers/MageTower.cpp
Normal file
19
src/game/towers/MageTower.cpp
Normal file
@@ -0,0 +1,19 @@
|
|||||||
|
#include "game/Towers.h"
|
||||||
|
#include "game/World.h"
|
||||||
|
|
||||||
|
namespace td {
|
||||||
|
namespace game {
|
||||||
|
|
||||||
|
void MageTower::Tick(std::uint64_t delta, World* world) {
|
||||||
|
if (m_Timer.Update(delta)) {
|
||||||
|
for (MobPtr mob : world->GetMobList()) {
|
||||||
|
if (IsMobInRange(mob)) {
|
||||||
|
mob->AddEffect(EffectType::Fire, GetLevel().GetLevel() * 3, this);
|
||||||
|
m_Timer.ApplyCooldown();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
} // namespace game
|
||||||
|
} // namespace td
|
||||||
12
src/game/towers/Necromancer.cpp
Normal file
12
src/game/towers/Necromancer.cpp
Normal file
@@ -0,0 +1,12 @@
|
|||||||
|
#include "game/Towers.h"
|
||||||
|
#include "game/World.h"
|
||||||
|
|
||||||
|
namespace td {
|
||||||
|
namespace game {
|
||||||
|
|
||||||
|
void NecromancerTower::Tick(std::uint64_t delta, World* world) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
} // namespace game
|
||||||
|
} // namespace td
|
||||||
45
src/game/towers/PoisonTower.cpp
Normal file
45
src/game/towers/PoisonTower.cpp
Normal file
@@ -0,0 +1,45 @@
|
|||||||
|
#include "game/Towers.h"
|
||||||
|
#include "game/World.h"
|
||||||
|
|
||||||
|
namespace td {
|
||||||
|
namespace game {
|
||||||
|
|
||||||
|
void PoisonTower::Tick(std::uint64_t delta, World* world) {
|
||||||
|
if (m_Timer.Update(delta)) {
|
||||||
|
for (MobPtr mob : world->GetMobList()) {
|
||||||
|
if (IsMobInRange(mob)) {
|
||||||
|
if (GetLevel().GetPath() == TowerPath::Bottom) {
|
||||||
|
world->GetMobNotifier().NotifyListeners(&MobListener::OnMobDamage, mob.get(), GetStats()->GetDamage(), this);
|
||||||
|
} else {
|
||||||
|
float durationSec;
|
||||||
|
switch (GetLevel().GetLevel()) {
|
||||||
|
case 1:
|
||||||
|
durationSec = 5;
|
||||||
|
break;
|
||||||
|
|
||||||
|
case 2:
|
||||||
|
durationSec = 15;
|
||||||
|
break;
|
||||||
|
|
||||||
|
case 3:
|
||||||
|
durationSec = 30;
|
||||||
|
break;
|
||||||
|
|
||||||
|
case 4:
|
||||||
|
durationSec = 1e10; // about 3 million hours. It should be enough
|
||||||
|
break;
|
||||||
|
|
||||||
|
default:
|
||||||
|
durationSec = 0; // how did we get there ?
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
mob->AddEffect(EffectType::Poison, durationSec, this);
|
||||||
|
}
|
||||||
|
m_Timer.ApplyCooldown();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
} // namespace game
|
||||||
|
} // namespace td
|
||||||
12
src/game/towers/QuakeTower.cpp
Normal file
12
src/game/towers/QuakeTower.cpp
Normal file
@@ -0,0 +1,12 @@
|
|||||||
|
#include "game/Towers.h"
|
||||||
|
#include "game/World.h"
|
||||||
|
|
||||||
|
namespace td {
|
||||||
|
namespace game {
|
||||||
|
|
||||||
|
void QuakeTower::Tick(std::uint64_t delta, World* world) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
} // namespace game
|
||||||
|
} // namespace td
|
||||||
12
src/game/towers/SorcererTower.cpp
Normal file
12
src/game/towers/SorcererTower.cpp
Normal file
@@ -0,0 +1,12 @@
|
|||||||
|
#include "game/Towers.h"
|
||||||
|
#include "game/World.h"
|
||||||
|
|
||||||
|
namespace td {
|
||||||
|
namespace game {
|
||||||
|
|
||||||
|
void SorcererTower::Tick(std::uint64_t delta, World* world) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
} // namespace game
|
||||||
|
} // namespace td
|
||||||
12
src/game/towers/TurretTower.cpp
Normal file
12
src/game/towers/TurretTower.cpp
Normal file
@@ -0,0 +1,12 @@
|
|||||||
|
#include "game/Towers.h"
|
||||||
|
#include "game/World.h"
|
||||||
|
|
||||||
|
namespace td {
|
||||||
|
namespace game {
|
||||||
|
|
||||||
|
void TurretTower::Tick(std::uint64_t delta, World* world) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
} // namespace game
|
||||||
|
} // namespace td
|
||||||
12
src/game/towers/ZeusTower.cpp
Normal file
12
src/game/towers/ZeusTower.cpp
Normal file
@@ -0,0 +1,12 @@
|
|||||||
|
#include "game/Towers.h"
|
||||||
|
#include "game/World.h"
|
||||||
|
|
||||||
|
namespace td {
|
||||||
|
namespace game {
|
||||||
|
|
||||||
|
void ZeusTower::Tick(std::uint64_t delta, World* world) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
} // namespace game
|
||||||
|
} // namespace td
|
||||||
90
src/misc/Maths.cpp
Normal file
90
src/misc/Maths.cpp
Normal file
@@ -0,0 +1,90 @@
|
|||||||
|
#include "misc/Maths.h"
|
||||||
|
|
||||||
|
#include <cassert>
|
||||||
|
|
||||||
|
namespace td {
|
||||||
|
namespace maths {
|
||||||
|
|
||||||
|
Mat4f Perspective(float fovY, float aspectRatio, float zNear, float zFar) {
|
||||||
|
const float tanHalfFovy = std::tan(fovY / 2.0f);
|
||||||
|
|
||||||
|
Mat4f result{};
|
||||||
|
result.x0 = 1.0f / (aspectRatio * tanHalfFovy);
|
||||||
|
result.y1 = 1.0f / (tanHalfFovy);
|
||||||
|
result.z2 = -(zFar + zNear) / (zFar - zNear);
|
||||||
|
result.z3 = -1.0f;
|
||||||
|
result.w2 = -(2.0f * zFar * zNear) / (zFar - zNear);
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
Mat4f Look(const Vec3f& eye, const Vec3f& front, const Vec3f& up) {
|
||||||
|
const Vec3f f = Normalize(front);
|
||||||
|
const Vec3f s = Normalize(Cross(f, up));
|
||||||
|
const Vec3f u = Cross(s, f);
|
||||||
|
|
||||||
|
Mat4f result = Identity<float>();
|
||||||
|
result.x0 = s.x;
|
||||||
|
result.y0 = s.y;
|
||||||
|
result.z0 = s.z;
|
||||||
|
result.x1 = u.x;
|
||||||
|
result.y1 = u.y;
|
||||||
|
result.z1 = u.z;
|
||||||
|
result.x2 = -f.x;
|
||||||
|
result.y2 = -f.y;
|
||||||
|
result.z2 = -f.z;
|
||||||
|
result.w0 = -Dot(s, eye);
|
||||||
|
result.w1 = -Dot(u, eye);
|
||||||
|
result.w2 = Dot(f, eye);
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
Mat4f Inverse(const Mat4f& mat) {
|
||||||
|
float s0 = mat.at(0, 0) * mat.at(1, 1) - mat.at(1, 0) * mat.at(0, 1);
|
||||||
|
float s1 = mat.at(0, 0) * mat.at(1, 2) - mat.at(1, 0) * mat.at(0, 2);
|
||||||
|
float s2 = mat.at(0, 0) * mat.at(1, 3) - mat.at(1, 0) * mat.at(0, 3);
|
||||||
|
float s3 = mat.at(0, 1) * mat.at(1, 2) - mat.at(1, 1) * mat.at(0, 2);
|
||||||
|
float s4 = mat.at(0, 1) * mat.at(1, 3) - mat.at(1, 1) * mat.at(0, 3);
|
||||||
|
float s5 = mat.at(0, 2) * mat.at(1, 3) - mat.at(1, 2) * mat.at(0, 3);
|
||||||
|
|
||||||
|
float c5 = mat.at(2, 2) * mat.at(3, 3) - mat.at(3, 2) * mat.at(2, 3);
|
||||||
|
float c4 = mat.at(2, 1) * mat.at(3, 3) - mat.at(3, 1) * mat.at(2, 3);
|
||||||
|
float c3 = mat.at(2, 1) * mat.at(3, 2) - mat.at(3, 1) * mat.at(2, 2);
|
||||||
|
float c2 = mat.at(2, 0) * mat.at(3, 3) - mat.at(3, 0) * mat.at(2, 3);
|
||||||
|
float c1 = mat.at(2, 0) * mat.at(3, 2) - mat.at(3, 0) * mat.at(2, 2);
|
||||||
|
float c0 = mat.at(2, 0) * mat.at(3, 1) - mat.at(3, 0) * mat.at(2, 1);
|
||||||
|
|
||||||
|
float det = s0 * c5 - s1 * c4 + s2 * c3 + s3 * c2 - s4 * c1 + s5 * c0;
|
||||||
|
|
||||||
|
assert(det != 0 && "Determinant equals 0 !");
|
||||||
|
|
||||||
|
float invdet = 1.0 / det;
|
||||||
|
|
||||||
|
Mat4f result;
|
||||||
|
|
||||||
|
result.at(0, 0) = ( mat.at(1, 1) * c5 - mat.at(1, 2) * c4 + mat.at(1, 3) * c3) * invdet;
|
||||||
|
result.at(0, 1) = (-mat.at(0, 1) * c5 + mat.at(0, 2) * c4 - mat.at(0, 3) * c3) * invdet;
|
||||||
|
result.at(0, 2) = ( mat.at(3, 1) * s5 - mat.at(3, 2) * s4 + mat.at(3, 3) * s3) * invdet;
|
||||||
|
result.at(0, 3) = (-mat.at(2, 1) * s5 + mat.at(2, 2) * s4 - mat.at(2, 3) * s3) * invdet;
|
||||||
|
|
||||||
|
result.at(1, 0) = (-mat.at(1, 0) * c5 + mat.at(1, 2) * c2 - mat.at(1, 3) * c1) * invdet;
|
||||||
|
result.at(1, 1) = ( mat.at(0, 0) * c5 - mat.at(0, 2) * c2 + mat.at(0, 3) * c1) * invdet;
|
||||||
|
result.at(1, 2) = (-mat.at(3, 0) * s5 + mat.at(3, 2) * s2 - mat.at(3, 3) * s1) * invdet;
|
||||||
|
result.at(1, 3) = ( mat.at(2, 0) * s5 - mat.at(2, 2) * s2 + mat.at(2, 3) * s1) * invdet;
|
||||||
|
|
||||||
|
result.at(2, 0) = ( mat.at(1, 0) * c4 - mat.at(1, 1) * c2 + mat.at(1, 3) * c0) * invdet;
|
||||||
|
result.at(2, 1) = (-mat.at(0, 0) * c4 + mat.at(0, 1) * c2 - mat.at(0, 3) * c0) * invdet;
|
||||||
|
result.at(2, 2) = ( mat.at(3, 0) * s4 - mat.at(3, 1) * s2 + mat.at(3, 3) * s0) * invdet;
|
||||||
|
result.at(2, 3) = (-mat.at(2, 0) * s4 + mat.at(2, 1) * s2 - mat.at(2, 3) * s0) * invdet;
|
||||||
|
|
||||||
|
result.at(3, 0) = (-mat.at(1, 0) * c3 + mat.at(1, 1) * c1 - mat.at(1, 2) * c0) * invdet;
|
||||||
|
result.at(3, 1) = ( mat.at(0, 0) * c3 - mat.at(0, 1) * c1 + mat.at(0, 2) * c0) * invdet;
|
||||||
|
result.at(3, 2) = (-mat.at(3, 0) * s3 + mat.at(3, 1) * s1 - mat.at(3, 2) * s0) * invdet;
|
||||||
|
result.at(3, 3) = ( mat.at(2, 0) * s3 - mat.at(2, 1) * s1 + mat.at(2, 2) * s0) * invdet;
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
} // namespace maths
|
||||||
|
} // namespace td
|
||||||
@@ -16,8 +16,7 @@ Socket::Socket(Type type)
|
|||||||
: m_Blocking(false),
|
: m_Blocking(false),
|
||||||
m_Type(type),
|
m_Type(type),
|
||||||
m_Status(Disconnected),
|
m_Status(Disconnected),
|
||||||
m_Handle(static_cast<SocketHandle>(INVALID_SOCKET))
|
m_Handle(static_cast<SocketHandle>(INVALID_SOCKET)) {
|
||||||
{
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -12,8 +12,7 @@ namespace td {
|
|||||||
namespace network {
|
namespace network {
|
||||||
|
|
||||||
UDPSocket::UDPSocket()
|
UDPSocket::UDPSocket()
|
||||||
: Socket(Socket::UDP), m_Port(0)
|
: Socket(Socket::UDP), m_Port(0) {
|
||||||
{
|
|
||||||
m_Handle = ::socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP);
|
m_Handle = ::socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
#include "protocol/PacketFactory.h"
|
#include "protocol/PacketFactory.h"
|
||||||
|
#include "protocol/Packets.h"
|
||||||
#include <map>
|
#include <map>
|
||||||
#include <functional>
|
#include <functional>
|
||||||
|
|
||||||
@@ -38,7 +39,27 @@ static std::map<PacketType, PacketCreator> packets = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
PacketPtr CreatePacket(PacketType type, DataBuffer& buffer) {
|
PacketPtr CreatePacket(PacketType type, DataBuffer& buffer) {
|
||||||
PacketPtr packet = packets[type]();
|
|
||||||
|
std::uint8_t packetTypeInt = static_cast<std::uint8_t>(type);
|
||||||
|
|
||||||
|
PacketPtr packet;
|
||||||
|
|
||||||
|
// we have a timed packet
|
||||||
|
if (packetTypeInt >> 7) {
|
||||||
|
std::uint64_t packetTime = 0;
|
||||||
|
buffer >> packetTime;
|
||||||
|
packetTypeInt &= 0x7F;
|
||||||
|
type = protocol::PacketType(packetTypeInt);
|
||||||
|
|
||||||
|
packet = packets[type]();
|
||||||
|
|
||||||
|
DelayedPacket* delayedPacket = reinterpret_cast<DelayedPacket*>(packet.get());
|
||||||
|
delayedPacket->SetPacketTime(packetTime);
|
||||||
|
|
||||||
|
} else {
|
||||||
|
packet = packets[type]();
|
||||||
|
}
|
||||||
|
|
||||||
packet->Deserialize(buffer);
|
packet->Deserialize(buffer);
|
||||||
return packet;
|
return packet;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,599 +1,49 @@
|
|||||||
#include "protocol/PacketHandler.h"
|
#include "protocol/PacketHandler.h"
|
||||||
|
#include "protocol/Packets.h"
|
||||||
|
|
||||||
#include <cmath>
|
#define REGISTER_DISPATCH(className) void className::Dispatch(PacketHandler* handler) const { \
|
||||||
|
|
||||||
#define REGISTER_DISPATCH_CLASS(className) void className::Dispatch(PacketHandler* handler) const { \
|
|
||||||
handler->HandlePacket(this);\
|
handler->HandlePacket(this);\
|
||||||
}
|
}
|
||||||
|
|
||||||
namespace td {
|
namespace td {
|
||||||
namespace protocol {
|
namespace protocol {
|
||||||
|
|
||||||
const int BITS_IN_BYTE = 8;
|
|
||||||
const int BITS_IN_LONG = BITS_IN_BYTE * sizeof(std::uint64_t);
|
|
||||||
|
|
||||||
static unsigned int countBits(unsigned int number) {
|
|
||||||
// log function in base 2
|
|
||||||
// take only integer part
|
|
||||||
return static_cast<unsigned int>(std::log2(number) + 1);
|
|
||||||
}
|
|
||||||
|
|
||||||
void Packet::WritePacketID(DataBuffer& data, bool packetID) const {
|
void Packet::WritePacketID(DataBuffer& data, bool packetID) const {
|
||||||
if (packetID)
|
if (packetID)
|
||||||
data << GetID();
|
data << GetID();
|
||||||
}
|
}
|
||||||
|
|
||||||
static DataBuffer& operator<<(DataBuffer& buffer, game::TilePtr tile) {
|
void DelayedPacket::WritePacketID(DataBuffer& data, bool packetID) const {
|
||||||
buffer << tile->GetType();
|
if (packetID)
|
||||||
|
data << static_cast<std::uint8_t>(GetID() | static_cast<std::uint8_t>(0x80)) << m_PacketTime;
|
||||||
switch (tile->GetType()) {
|
}
|
||||||
|
|
||||||
case game::TileType::Tower: {
|
REGISTER_DISPATCH(PlayerLoginPacket)
|
||||||
const game::TowerTile* towerTile = dynamic_cast<const game::TowerTile*>(tile.get());
|
REGISTER_DISPATCH(WorldBeginDataPacket)
|
||||||
buffer << towerTile->color_palette_ref << towerTile->team_owner;
|
REGISTER_DISPATCH(WorldDataPacket)
|
||||||
break;
|
REGISTER_DISPATCH(KeepAlivePacket)
|
||||||
}
|
REGISTER_DISPATCH(UpdateExpPacket)
|
||||||
|
REGISTER_DISPATCH(UpdateMoneyPacket)
|
||||||
case game::TileType::Walk: {
|
REGISTER_DISPATCH(UpdateLobbyTimePacket)
|
||||||
const game::WalkableTile* walkTile = dynamic_cast<const game::WalkableTile*>(tile.get());
|
REGISTER_DISPATCH(UpdateGameStatePacket)
|
||||||
buffer << walkTile->direction;
|
REGISTER_DISPATCH(PlayerListPacket)
|
||||||
break;
|
REGISTER_DISPATCH(PlayerJoinPacket)
|
||||||
}
|
REGISTER_DISPATCH(PlayerLeavePacket)
|
||||||
|
REGISTER_DISPATCH(ConnexionInfoPacket)
|
||||||
case game::TileType::Decoration: {
|
REGISTER_DISPATCH(SelectTeamPacket)
|
||||||
const game::DecorationTile* decoTile = dynamic_cast<const game::DecorationTile*>(tile.get());
|
REGISTER_DISPATCH(UpdatePlayerTeamPacket)
|
||||||
buffer << decoTile->color_palette_ref;
|
REGISTER_DISPATCH(DisconnectPacket)
|
||||||
break;
|
REGISTER_DISPATCH(ServerTpsPacket)
|
||||||
}
|
REGISTER_DISPATCH(SpawnMobPacket)
|
||||||
|
REGISTER_DISPATCH(PlaceTowerPacket)
|
||||||
default:
|
REGISTER_DISPATCH(WorldAddTowerPacket)
|
||||||
break;
|
REGISTER_DISPATCH(RemoveTowerPacket)
|
||||||
}
|
REGISTER_DISPATCH(SendMobsPacket)
|
||||||
|
REGISTER_DISPATCH(UpgradeTowerPacket)
|
||||||
return buffer;
|
REGISTER_DISPATCH(UpdateCastleLifePacket)
|
||||||
}
|
REGISTER_DISPATCH(UpdateMobStatesPacket)
|
||||||
|
REGISTER_DISPATCH(PlayerBuyItemPacket)
|
||||||
static DataBuffer& operator>>(DataBuffer& buffer, game::TilePtr& tile) {
|
REGISTER_DISPATCH(PlayerBuyMobUpgradePacket)
|
||||||
game::TileType tileType;
|
|
||||||
buffer >> tileType;
|
|
||||||
switch (tileType) {
|
|
||||||
case game::TileType::Tower: {
|
|
||||||
auto tilePtr = std::make_shared<game::TowerTile>();
|
|
||||||
buffer >> tilePtr->color_palette_ref >> tilePtr->team_owner;
|
|
||||||
tile = tilePtr;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
case game::TileType::Walk: {
|
|
||||||
auto tilePtr = std::make_shared<game::WalkableTile>();
|
|
||||||
buffer >> tilePtr->direction;
|
|
||||||
tile = tilePtr;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
case game::TileType::Decoration: {
|
|
||||||
auto tilePtr = std::make_shared<game::DecorationTile>();
|
|
||||||
buffer >> tilePtr->color_palette_ref;
|
|
||||||
tile = tilePtr;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
default:
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
return buffer;
|
|
||||||
}
|
|
||||||
|
|
||||||
DataBuffer PlayerLoginPacket::Serialize(bool packetID) const {
|
|
||||||
DataBuffer data;
|
|
||||||
|
|
||||||
WritePacketID(data, packetID);
|
|
||||||
data << m_PlayerName;
|
|
||||||
return data;
|
|
||||||
}
|
|
||||||
|
|
||||||
void PlayerLoginPacket::Deserialize(DataBuffer& data) {
|
|
||||||
data >> m_PlayerName;
|
|
||||||
}
|
|
||||||
|
|
||||||
DataBuffer WorldBeginDataPacket::Serialize(bool packetID) const {
|
|
||||||
DataBuffer data;
|
|
||||||
const game::TowerTileColorPalette& towerTilePalette = m_Header.m_World->GetTowerTileColorPalette();
|
|
||||||
const std::vector<game::Color>& decoTilePalette = m_Header.m_World->GetDecorationPalette();
|
|
||||||
|
|
||||||
WritePacketID(data, packetID);
|
|
||||||
|
|
||||||
data << towerTilePalette << m_Header.m_World->GetWalkableTileColor()
|
|
||||||
<< static_cast<std::uint16_t>(decoTilePalette.size());
|
|
||||||
|
|
||||||
// deco color palette
|
|
||||||
std::size_t bufferSize = data.GetSize();
|
|
||||||
data.Resize(bufferSize + decoTilePalette.size() * sizeof(game::Color));
|
|
||||||
|
|
||||||
memcpy(reinterpret_cast<std::uint8_t*>(data.data()) + bufferSize, decoTilePalette.data(), decoTilePalette.size() * sizeof(game::Color));
|
|
||||||
|
|
||||||
data << m_Header.m_World->GetBackgroundColor();
|
|
||||||
|
|
||||||
const game::Spawn& redSpawn = m_Header.m_World->GetRedTeam().GetSpawn(), blueSpawn = m_Header.m_World->GetBlueTeam().GetSpawn();
|
|
||||||
const game::TeamCastle& redCastle = m_Header.m_World->GetRedTeam().GetCastle(), blueCastle = m_Header.m_World->GetBlueTeam().GetCastle();
|
|
||||||
|
|
||||||
data << redSpawn << static_cast<utils::shape::Rectangle>(redCastle);
|
|
||||||
data << blueSpawn << static_cast<utils::shape::Rectangle>(blueCastle);
|
|
||||||
|
|
||||||
// tile palette
|
|
||||||
data << static_cast<std::uint64_t>(m_Header.m_World->GetTilePalette().size());
|
|
||||||
|
|
||||||
for (game::TilePtr tile : m_Header.m_World->GetTilePalette()) {
|
|
||||||
data << tile;
|
|
||||||
}
|
|
||||||
|
|
||||||
data << m_Header.m_World->GetSpawnColors();
|
|
||||||
|
|
||||||
return data;
|
|
||||||
}
|
|
||||||
|
|
||||||
void WorldBeginDataPacket::Deserialize(DataBuffer& data) {
|
|
||||||
data >> m_Header.m_TowerPlacePalette >> m_Header.m_WalkablePalette;
|
|
||||||
|
|
||||||
std::uint16_t decoPaletteSize;
|
|
||||||
data >> decoPaletteSize;
|
|
||||||
|
|
||||||
std::size_t decoPalletteSizeByte = decoPaletteSize * sizeof(game::Color);
|
|
||||||
|
|
||||||
m_Header.m_DecorationPalette.resize(decoPaletteSize);
|
|
||||||
|
|
||||||
memcpy(reinterpret_cast<std::uint8_t*>(m_Header.m_DecorationPalette.data()), data.data() + data.GetReadOffset(), decoPalletteSizeByte);
|
|
||||||
|
|
||||||
data.SetReadOffset(data.GetReadOffset() + decoPalletteSizeByte);
|
|
||||||
|
|
||||||
data >> m_Header.m_Background;
|
|
||||||
|
|
||||||
utils::shape::Rectangle redCastle, blueCastle;
|
|
||||||
|
|
||||||
data >> m_Header.m_RedSpawn >> redCastle;
|
|
||||||
data >> m_Header.m_BlueSpawn >> blueCastle;
|
|
||||||
|
|
||||||
m_Header.m_RedCastle.SetShape(redCastle);
|
|
||||||
m_Header.m_BlueCastle.SetShape(blueCastle);
|
|
||||||
|
|
||||||
std::uint64_t tilePaletteSize;
|
|
||||||
data >> tilePaletteSize;
|
|
||||||
|
|
||||||
m_Header.m_TilePalette.reserve(tilePaletteSize);
|
|
||||||
|
|
||||||
for (std::uint64_t tileNumber = 0; tileNumber < tilePaletteSize; tileNumber++) {
|
|
||||||
game::TilePtr tile;
|
|
||||||
data >> tile;
|
|
||||||
m_Header.m_TilePalette.push_back(tile);
|
|
||||||
}
|
|
||||||
|
|
||||||
data >> m_Header.m_SpawnColorPalette;
|
|
||||||
}
|
|
||||||
|
|
||||||
typedef std::vector<uint64_t> ChunkPackedData;
|
|
||||||
|
|
||||||
DataBuffer WorldDataPacket::Serialize(bool packetID) const {
|
|
||||||
DataBuffer data;
|
|
||||||
|
|
||||||
WritePacketID(data, packetID);
|
|
||||||
|
|
||||||
data << m_World->GetChunks().size();
|
|
||||||
for (const auto& pair : m_World->GetChunks()) {
|
|
||||||
game::ChunkCoord coords = pair.first;
|
|
||||||
game::ChunkPtr chunk = pair.second;
|
|
||||||
|
|
||||||
data << coords.x << coords.y << static_cast<std::uint64_t>(chunk->palette.size());
|
|
||||||
|
|
||||||
std::size_t bufferSize = data.GetSize();
|
|
||||||
data.Resize(data.GetSize() + chunk->palette.size() * sizeof(game::ChunkPalette::value_type));
|
|
||||||
memcpy(reinterpret_cast<std::uint8_t*>(data.data()) + bufferSize, chunk->palette.data(), chunk->palette.size() * sizeof(game::ChunkPalette::value_type));
|
|
||||||
|
|
||||||
std::uint8_t bitsPerTile = countBits(chunk->palette.size());
|
|
||||||
|
|
||||||
game::Chunk::ChunkData::value_type individualValueMask = ((1 << bitsPerTile) - 1);
|
|
||||||
|
|
||||||
ChunkPackedData chunkData(game::Chunk::ChunkSize / (BITS_IN_BYTE * sizeof(ChunkPackedData::value_type) / bitsPerTile), 0);
|
|
||||||
|
|
||||||
for (unsigned int tileNumber = 0; tileNumber < game::Chunk::ChunkSize; tileNumber++) {
|
|
||||||
std::size_t startLong = static_cast<std::size_t>((tileNumber * bitsPerTile) / BITS_IN_LONG);
|
|
||||||
std::size_t startOffset = static_cast<std::size_t>((tileNumber * bitsPerTile) % BITS_IN_LONG);
|
|
||||||
std::size_t endLong = static_cast<std::size_t>(((tileNumber + 1) * bitsPerTile - 1) / BITS_IN_LONG);
|
|
||||||
|
|
||||||
std::uint64_t value = static_cast<std::uint64_t>(chunk->tiles[tileNumber]);
|
|
||||||
|
|
||||||
value &= individualValueMask;
|
|
||||||
|
|
||||||
chunkData[startLong] |= (value << startOffset);
|
|
||||||
|
|
||||||
if (startLong != endLong) {
|
|
||||||
chunkData[endLong] = (value >> (BITS_IN_LONG - startOffset));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
bufferSize = data.GetSize();
|
|
||||||
data.Resize(data.GetSize() + chunkData.size() * sizeof(ChunkPackedData::value_type));
|
|
||||||
memcpy(reinterpret_cast<std::uint8_t*>(data.data()) + bufferSize, chunkData.data(), chunkData.size() * sizeof(ChunkPackedData::value_type));
|
|
||||||
}
|
|
||||||
return data;
|
|
||||||
}
|
|
||||||
|
|
||||||
void WorldDataPacket::Deserialize(DataBuffer& data) {
|
|
||||||
std::uint64_t chunkCount;
|
|
||||||
data >> chunkCount;
|
|
||||||
|
|
||||||
for (std::uint64_t chunkNumber = 0; chunkNumber < chunkCount; chunkNumber++) {
|
|
||||||
game::ChunkPtr chunk = std::make_shared<game::Chunk>();
|
|
||||||
|
|
||||||
decltype(game::ChunkCoord::x) chunkX, chunkY;
|
|
||||||
data >> chunkX >> chunkY;
|
|
||||||
|
|
||||||
std::uint64_t chunkPaletteSize;
|
|
||||||
data >> chunkPaletteSize;
|
|
||||||
|
|
||||||
game::ChunkPalette chunkPalette(chunkPaletteSize);
|
|
||||||
|
|
||||||
memcpy(reinterpret_cast<void*>(chunkPalette.data()), data.data() + data.GetReadOffset(), chunkPaletteSize * sizeof(game::ChunkPalette::value_type));
|
|
||||||
data.SetReadOffset(data.GetReadOffset() + chunkPaletteSize * sizeof(game::ChunkPalette::value_type));
|
|
||||||
|
|
||||||
chunk->palette = chunkPalette;
|
|
||||||
|
|
||||||
std::uint8_t bitsPerTile = countBits(chunkPaletteSize);
|
|
||||||
|
|
||||||
// A bitmask that contains bitsPerTile set bits
|
|
||||||
game::Chunk::ChunkData::value_type individualValueMask = ((1 << bitsPerTile) - 1);
|
|
||||||
|
|
||||||
ChunkPackedData chunkData(game::Chunk::ChunkSize / (BITS_IN_BYTE * sizeof(ChunkPackedData::value_type) / bitsPerTile), 0);
|
|
||||||
|
|
||||||
memcpy(reinterpret_cast<void*>(chunkData.data()), data.data() + data.GetReadOffset(), chunkData.size() * sizeof(ChunkPackedData::value_type));
|
|
||||||
data.SetReadOffset(data.GetReadOffset() + chunkData.size() * sizeof(ChunkPackedData::value_type));
|
|
||||||
|
|
||||||
for (unsigned int tileNumber = 0; tileNumber < game::Chunk::ChunkSize; tileNumber++) {
|
|
||||||
std::size_t startLong = (tileNumber * bitsPerTile) / BITS_IN_LONG;
|
|
||||||
std::size_t startOffset = (tileNumber * bitsPerTile) % BITS_IN_LONG;
|
|
||||||
std::size_t endLong = ((tileNumber + 1) * bitsPerTile - 1) / BITS_IN_LONG;
|
|
||||||
|
|
||||||
game::Chunk::ChunkData::value_type value;
|
|
||||||
if (startLong == endLong) {
|
|
||||||
value = (chunkData[startLong] >> startOffset);
|
|
||||||
} else {
|
|
||||||
int endOffset = BITS_IN_LONG - startOffset;
|
|
||||||
value = (chunkData[startLong] >> startOffset | chunkData[endLong] << endOffset);
|
|
||||||
}
|
|
||||||
value &= individualValueMask;
|
|
||||||
|
|
||||||
chunk->tiles[tileNumber] = value;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
m_WorldData.m_Chunks.insert({ {chunkX, chunkY}, chunk });
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
DataBuffer KeepAlivePacket::Serialize(bool packetID) const {
|
|
||||||
DataBuffer data;
|
|
||||||
|
|
||||||
WritePacketID(data, packetID);
|
|
||||||
data << m_AliveID;
|
|
||||||
return data;
|
|
||||||
}
|
|
||||||
|
|
||||||
void KeepAlivePacket::Deserialize(DataBuffer& data) {
|
|
||||||
data >> m_AliveID;
|
|
||||||
}
|
|
||||||
|
|
||||||
DataBuffer UpdateMoneyPacket::Serialize(bool packetID) const {
|
|
||||||
DataBuffer data;
|
|
||||||
|
|
||||||
WritePacketID(data, packetID);
|
|
||||||
data << m_NewAmount;
|
|
||||||
return data;
|
|
||||||
}
|
|
||||||
|
|
||||||
void UpdateMoneyPacket::Deserialize(DataBuffer& data) {
|
|
||||||
data >> m_NewAmount;
|
|
||||||
}
|
|
||||||
|
|
||||||
DataBuffer UpdateExpPacket::Serialize(bool packetID) const {
|
|
||||||
DataBuffer data;
|
|
||||||
|
|
||||||
WritePacketID(data, packetID);
|
|
||||||
data << m_NewAmount;
|
|
||||||
return data;
|
|
||||||
}
|
|
||||||
|
|
||||||
void UpdateExpPacket::Deserialize(DataBuffer& data) {
|
|
||||||
data >> m_NewAmount;
|
|
||||||
}
|
|
||||||
|
|
||||||
DataBuffer UpdateLobbyTimePacket::Serialize(bool packetID) const {
|
|
||||||
DataBuffer data;
|
|
||||||
|
|
||||||
WritePacketID(data, packetID);
|
|
||||||
data << m_RemainingTime;
|
|
||||||
return data;
|
|
||||||
}
|
|
||||||
|
|
||||||
void UpdateLobbyTimePacket::Deserialize(DataBuffer& data) {
|
|
||||||
data >> m_RemainingTime;
|
|
||||||
}
|
|
||||||
|
|
||||||
DataBuffer UpdateGameStatePacket::Serialize(bool packetID) const {
|
|
||||||
DataBuffer data;
|
|
||||||
|
|
||||||
WritePacketID(data, packetID);
|
|
||||||
data << m_GameState;
|
|
||||||
return data;
|
|
||||||
}
|
|
||||||
|
|
||||||
void UpdateGameStatePacket::Deserialize(DataBuffer& data) {
|
|
||||||
data >> m_GameState;
|
|
||||||
}
|
|
||||||
|
|
||||||
DataBuffer PlayerListPacket::Serialize(bool packetID) const {
|
|
||||||
DataBuffer data;
|
|
||||||
|
|
||||||
WritePacketID(data, packetID);
|
|
||||||
data << static_cast<std::uint8_t>(m_Players.size());
|
|
||||||
for (auto [playerID, playerInfo] : m_Players) {
|
|
||||||
data << playerID << playerInfo.name << playerInfo.team;
|
|
||||||
}
|
|
||||||
return data;
|
|
||||||
}
|
|
||||||
|
|
||||||
void PlayerListPacket::Deserialize(DataBuffer& data) {
|
|
||||||
std::uint8_t playerCount;
|
|
||||||
data >> playerCount;
|
|
||||||
|
|
||||||
for (int i = 0; i < playerCount; i++) {
|
|
||||||
std::uint8_t playerID;
|
|
||||||
PlayerInfo playerInfo;
|
|
||||||
data >> playerID >> playerInfo.name >> playerInfo.team;
|
|
||||||
m_Players.insert({ playerID, playerInfo });
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
DataBuffer PlayerJoinPacket::Serialize(bool packetID) const {
|
|
||||||
DataBuffer data;
|
|
||||||
|
|
||||||
WritePacketID(data, packetID);
|
|
||||||
data << m_PlayerID << m_PlayerName;
|
|
||||||
return data;
|
|
||||||
}
|
|
||||||
|
|
||||||
void PlayerJoinPacket::Deserialize(DataBuffer& data) {
|
|
||||||
data >> m_PlayerID >> m_PlayerName;
|
|
||||||
}
|
|
||||||
|
|
||||||
DataBuffer PlayerLeavePacket::Serialize(bool packetID) const {
|
|
||||||
DataBuffer data;
|
|
||||||
|
|
||||||
WritePacketID(data, packetID);
|
|
||||||
data << m_PlayerID;
|
|
||||||
return data;
|
|
||||||
}
|
|
||||||
|
|
||||||
void PlayerLeavePacket::Deserialize(DataBuffer& data) {
|
|
||||||
data >> m_PlayerID;
|
|
||||||
}
|
|
||||||
|
|
||||||
DataBuffer ConnexionInfoPacket::Serialize(bool packetID) const {
|
|
||||||
DataBuffer data;
|
|
||||||
|
|
||||||
WritePacketID(data, packetID);
|
|
||||||
data << m_ConnectionID;
|
|
||||||
return data;
|
|
||||||
}
|
|
||||||
|
|
||||||
void ConnexionInfoPacket::Deserialize(DataBuffer& data) {
|
|
||||||
data >> m_ConnectionID;
|
|
||||||
}
|
|
||||||
|
|
||||||
DataBuffer SelectTeamPacket::Serialize(bool packetID) const {
|
|
||||||
DataBuffer data;
|
|
||||||
|
|
||||||
WritePacketID(data, packetID);
|
|
||||||
data << m_SelectedTeam;
|
|
||||||
return data;
|
|
||||||
}
|
|
||||||
|
|
||||||
void SelectTeamPacket::Deserialize(DataBuffer& data) {
|
|
||||||
data >> m_SelectedTeam;
|
|
||||||
}
|
|
||||||
|
|
||||||
DataBuffer UpdatePlayerTeamPacket::Serialize(bool packetID) const {
|
|
||||||
DataBuffer data;
|
|
||||||
|
|
||||||
WritePacketID(data, packetID);
|
|
||||||
data << m_PlayerID << m_SelectedTeam;
|
|
||||||
return data;
|
|
||||||
}
|
|
||||||
|
|
||||||
void UpdatePlayerTeamPacket::Deserialize(DataBuffer& data) {
|
|
||||||
data >> m_PlayerID >> m_SelectedTeam;
|
|
||||||
}
|
|
||||||
|
|
||||||
DataBuffer DisconnectPacket::Serialize(bool packetID) const {
|
|
||||||
DataBuffer data;
|
|
||||||
|
|
||||||
WritePacketID(data, packetID);
|
|
||||||
data << m_Reason;
|
|
||||||
return data;
|
|
||||||
}
|
|
||||||
|
|
||||||
void DisconnectPacket::Deserialize(DataBuffer& data) {
|
|
||||||
data >> m_Reason;
|
|
||||||
}
|
|
||||||
|
|
||||||
DataBuffer ServerTpsPacket::Serialize(bool packetID) const {
|
|
||||||
DataBuffer data;
|
|
||||||
|
|
||||||
WritePacketID(data, packetID);
|
|
||||||
data << m_TPS << m_PacketSendTime;
|
|
||||||
return data;
|
|
||||||
}
|
|
||||||
|
|
||||||
void ServerTpsPacket::Deserialize(DataBuffer& data) {
|
|
||||||
data >> m_TPS >> m_PacketSendTime;
|
|
||||||
}
|
|
||||||
|
|
||||||
DataBuffer SpawnMobPacket::Serialize(bool packetID) const {
|
|
||||||
DataBuffer data;
|
|
||||||
|
|
||||||
WritePacketID(data, packetID);
|
|
||||||
data << m_MobID << m_MobType << m_MobLevel << m_MobDirection
|
|
||||||
<< m_Sender << m_MobX << m_MobY;
|
|
||||||
return data;
|
|
||||||
}
|
|
||||||
|
|
||||||
void SpawnMobPacket::Deserialize(DataBuffer& data) {
|
|
||||||
data >> m_MobID >> m_MobType >> m_MobLevel >> m_MobDirection
|
|
||||||
>> m_Sender >> m_MobX >> m_MobY;
|
|
||||||
}
|
|
||||||
|
|
||||||
DataBuffer PlaceTowerPacket::Serialize(bool packetID) const {
|
|
||||||
DataBuffer data;
|
|
||||||
|
|
||||||
WritePacketID(data, packetID);
|
|
||||||
data << m_TowerX << m_TowerY << m_TowerType;
|
|
||||||
return data;
|
|
||||||
}
|
|
||||||
|
|
||||||
void PlaceTowerPacket::Deserialize(DataBuffer& data) {
|
|
||||||
data >> m_TowerX >> m_TowerY >> m_TowerType;
|
|
||||||
}
|
|
||||||
|
|
||||||
DataBuffer WorldAddTowerPacket::Serialize(bool packetID) const {
|
|
||||||
DataBuffer data;
|
|
||||||
|
|
||||||
WritePacketID(data, packetID);
|
|
||||||
data << m_TowerID << m_TowerX << m_TowerY << m_TowerType << m_Builder;
|
|
||||||
return data;
|
|
||||||
}
|
|
||||||
|
|
||||||
void WorldAddTowerPacket::Deserialize(DataBuffer& data) {
|
|
||||||
data >> m_TowerID >> m_TowerX >> m_TowerY >> m_TowerType >> m_Builder;
|
|
||||||
}
|
|
||||||
|
|
||||||
DataBuffer RemoveTowerPacket::Serialize(bool packetID) const {
|
|
||||||
DataBuffer data;
|
|
||||||
|
|
||||||
WritePacketID(data, packetID);
|
|
||||||
data << m_TowerID;
|
|
||||||
return data;
|
|
||||||
}
|
|
||||||
|
|
||||||
void RemoveTowerPacket::Deserialize(DataBuffer& data) {
|
|
||||||
data >> m_TowerID;
|
|
||||||
}
|
|
||||||
|
|
||||||
DataBuffer SendMobsPacket::Serialize(bool packetID) const {
|
|
||||||
DataBuffer data;
|
|
||||||
|
|
||||||
WritePacketID(data, packetID);
|
|
||||||
data << static_cast<std::uint8_t>(m_MobSends.size());
|
|
||||||
|
|
||||||
data.WriteSome(reinterpret_cast<const std::uint8_t*>(m_MobSends.data()), m_MobSends.size() * sizeof(m_MobSends));
|
|
||||||
|
|
||||||
return data;
|
|
||||||
}
|
|
||||||
|
|
||||||
void SendMobsPacket::Deserialize(DataBuffer& data) {
|
|
||||||
std::uint8_t mobSendCount;
|
|
||||||
data >> mobSendCount;
|
|
||||||
|
|
||||||
m_MobSends.resize(mobSendCount);
|
|
||||||
data.ReadSome(reinterpret_cast<std::uint8_t*>(m_MobSends.data()), mobSendCount * sizeof(MobSend));
|
|
||||||
}
|
|
||||||
|
|
||||||
DataBuffer UpgradeTowerPacket::Serialize(bool packetID) const {
|
|
||||||
DataBuffer data;
|
|
||||||
|
|
||||||
WritePacketID(data, packetID);
|
|
||||||
data << m_TowerID << m_TowerLevel;
|
|
||||||
return data;
|
|
||||||
}
|
|
||||||
|
|
||||||
void UpgradeTowerPacket::Deserialize(DataBuffer& data) {
|
|
||||||
data >> m_TowerID >> m_TowerLevel;
|
|
||||||
}
|
|
||||||
|
|
||||||
DataBuffer UpdateCastleLifePacket::Serialize(bool packetID) const {
|
|
||||||
DataBuffer data;
|
|
||||||
|
|
||||||
WritePacketID(data, packetID);
|
|
||||||
data << m_CastleLife << m_Team;
|
|
||||||
return data;
|
|
||||||
}
|
|
||||||
|
|
||||||
void UpdateCastleLifePacket::Deserialize(DataBuffer& data) {
|
|
||||||
data >> m_CastleLife >> m_Team;
|
|
||||||
}
|
|
||||||
|
|
||||||
DataBuffer UpdateMobStatesPacket::Serialize(bool packetID) const {
|
|
||||||
DataBuffer data;
|
|
||||||
|
|
||||||
WritePacketID(data, packetID);
|
|
||||||
data << static_cast<std::uint64_t>(m_MobStates.size());
|
|
||||||
|
|
||||||
data.WriteSome(reinterpret_cast<const std::uint8_t*>(m_MobStates.data()), m_MobStates.size() * sizeof(MobState));
|
|
||||||
return data;
|
|
||||||
}
|
|
||||||
|
|
||||||
void UpdateMobStatesPacket::Deserialize(DataBuffer& data) {
|
|
||||||
std::uint64_t mobCount;
|
|
||||||
data >> mobCount;
|
|
||||||
m_MobStates.resize(mobCount);
|
|
||||||
|
|
||||||
data.ReadSome(reinterpret_cast<std::uint8_t*>(m_MobStates.data()), mobCount * sizeof(MobState));
|
|
||||||
}
|
|
||||||
|
|
||||||
DataBuffer PlayerBuyItemPacket::Serialize(bool packetID) const {
|
|
||||||
DataBuffer data;
|
|
||||||
|
|
||||||
WritePacketID(data, packetID);
|
|
||||||
data << m_ItemType << m_Count;
|
|
||||||
return data;
|
|
||||||
}
|
|
||||||
|
|
||||||
void PlayerBuyItemPacket::Deserialize(DataBuffer& data) {
|
|
||||||
data >> m_ItemType >> m_Count;
|
|
||||||
}
|
|
||||||
|
|
||||||
DataBuffer PlayerBuyMobUpgradePacket::Serialize(bool packetID) const {
|
|
||||||
DataBuffer data;
|
|
||||||
|
|
||||||
WritePacketID(data, packetID);
|
|
||||||
data << m_MobType << m_MobLevel;
|
|
||||||
return data;
|
|
||||||
}
|
|
||||||
|
|
||||||
void PlayerBuyMobUpgradePacket::Deserialize(DataBuffer& data) {
|
|
||||||
data >> m_MobType >> m_MobLevel;
|
|
||||||
}
|
|
||||||
|
|
||||||
REGISTER_DISPATCH_CLASS(PlayerLoginPacket)
|
|
||||||
REGISTER_DISPATCH_CLASS(WorldBeginDataPacket)
|
|
||||||
REGISTER_DISPATCH_CLASS(WorldDataPacket)
|
|
||||||
REGISTER_DISPATCH_CLASS(KeepAlivePacket)
|
|
||||||
REGISTER_DISPATCH_CLASS(UpdateExpPacket)
|
|
||||||
REGISTER_DISPATCH_CLASS(UpdateMoneyPacket)
|
|
||||||
REGISTER_DISPATCH_CLASS(UpdateLobbyTimePacket)
|
|
||||||
REGISTER_DISPATCH_CLASS(UpdateGameStatePacket)
|
|
||||||
REGISTER_DISPATCH_CLASS(PlayerListPacket)
|
|
||||||
REGISTER_DISPATCH_CLASS(PlayerJoinPacket)
|
|
||||||
REGISTER_DISPATCH_CLASS(PlayerLeavePacket)
|
|
||||||
REGISTER_DISPATCH_CLASS(ConnexionInfoPacket)
|
|
||||||
REGISTER_DISPATCH_CLASS(SelectTeamPacket)
|
|
||||||
REGISTER_DISPATCH_CLASS(UpdatePlayerTeamPacket)
|
|
||||||
REGISTER_DISPATCH_CLASS(DisconnectPacket)
|
|
||||||
REGISTER_DISPATCH_CLASS(ServerTpsPacket)
|
|
||||||
REGISTER_DISPATCH_CLASS(SpawnMobPacket)
|
|
||||||
REGISTER_DISPATCH_CLASS(PlaceTowerPacket)
|
|
||||||
REGISTER_DISPATCH_CLASS(WorldAddTowerPacket)
|
|
||||||
REGISTER_DISPATCH_CLASS(RemoveTowerPacket)
|
|
||||||
REGISTER_DISPATCH_CLASS(SendMobsPacket)
|
|
||||||
REGISTER_DISPATCH_CLASS(UpgradeTowerPacket)
|
|
||||||
REGISTER_DISPATCH_CLASS(UpdateCastleLifePacket)
|
|
||||||
REGISTER_DISPATCH_CLASS(UpdateMobStatesPacket)
|
|
||||||
REGISTER_DISPATCH_CLASS(PlayerBuyItemPacket)
|
|
||||||
REGISTER_DISPATCH_CLASS(PlayerBuyMobUpgradePacket)
|
|
||||||
|
|
||||||
} // namespace protocol
|
} // namespace protocol
|
||||||
} // namespace td
|
} // namespace td
|
||||||
19
src/protocol/packets/ConnectionInfoPacket.cpp
Normal file
19
src/protocol/packets/ConnectionInfoPacket.cpp
Normal file
@@ -0,0 +1,19 @@
|
|||||||
|
#include "protocol/packets/ConnectionInfoPacket.h"
|
||||||
|
|
||||||
|
namespace td {
|
||||||
|
namespace protocol {
|
||||||
|
|
||||||
|
DataBuffer ConnexionInfoPacket::Serialize(bool packetID) const {
|
||||||
|
DataBuffer data;
|
||||||
|
|
||||||
|
WritePacketID(data, packetID);
|
||||||
|
data << m_ConnectionID;
|
||||||
|
return data;
|
||||||
|
}
|
||||||
|
|
||||||
|
void ConnexionInfoPacket::Deserialize(DataBuffer& data) {
|
||||||
|
data >> m_ConnectionID;
|
||||||
|
}
|
||||||
|
|
||||||
|
} // namespace protocol
|
||||||
|
} // namespace td
|
||||||
19
src/protocol/packets/DisconnectPacket.cpp
Normal file
19
src/protocol/packets/DisconnectPacket.cpp
Normal file
@@ -0,0 +1,19 @@
|
|||||||
|
#include "protocol/packets/DisconnectPacket.h"
|
||||||
|
|
||||||
|
namespace td {
|
||||||
|
namespace protocol {
|
||||||
|
|
||||||
|
DataBuffer DisconnectPacket::Serialize(bool packetID) const {
|
||||||
|
DataBuffer data;
|
||||||
|
|
||||||
|
WritePacketID(data, packetID);
|
||||||
|
data << m_Reason;
|
||||||
|
return data;
|
||||||
|
}
|
||||||
|
|
||||||
|
void DisconnectPacket::Deserialize(DataBuffer& data) {
|
||||||
|
data >> m_Reason;
|
||||||
|
}
|
||||||
|
|
||||||
|
} // namespace protocol
|
||||||
|
} // namespace td
|
||||||
19
src/protocol/packets/KeepAlivePacket.cpp
Normal file
19
src/protocol/packets/KeepAlivePacket.cpp
Normal file
@@ -0,0 +1,19 @@
|
|||||||
|
#include "protocol/packets/KeepAlivePacket.h"
|
||||||
|
|
||||||
|
namespace td {
|
||||||
|
namespace protocol {
|
||||||
|
|
||||||
|
DataBuffer KeepAlivePacket::Serialize(bool packetID) const {
|
||||||
|
DataBuffer data;
|
||||||
|
|
||||||
|
WritePacketID(data, packetID);
|
||||||
|
data << m_AliveID;
|
||||||
|
return data;
|
||||||
|
}
|
||||||
|
|
||||||
|
void KeepAlivePacket::Deserialize(DataBuffer& data) {
|
||||||
|
data >> m_AliveID;
|
||||||
|
}
|
||||||
|
|
||||||
|
} // namespace protocol
|
||||||
|
} // namespace td
|
||||||
19
src/protocol/packets/PlaceTowerPacket.cpp
Normal file
19
src/protocol/packets/PlaceTowerPacket.cpp
Normal file
@@ -0,0 +1,19 @@
|
|||||||
|
#include "protocol/packets/PlaceTowerPacket.h"
|
||||||
|
|
||||||
|
namespace td {
|
||||||
|
namespace protocol {
|
||||||
|
|
||||||
|
DataBuffer PlaceTowerPacket::Serialize(bool packetID) const {
|
||||||
|
DataBuffer data;
|
||||||
|
|
||||||
|
WritePacketID(data, packetID);
|
||||||
|
data << m_TowerX << m_TowerY << m_TowerType;
|
||||||
|
return data;
|
||||||
|
}
|
||||||
|
|
||||||
|
void PlaceTowerPacket::Deserialize(DataBuffer& data) {
|
||||||
|
data >> m_TowerX >> m_TowerY >> m_TowerType;
|
||||||
|
}
|
||||||
|
|
||||||
|
} // namespace protocol
|
||||||
|
} // namespace td
|
||||||
19
src/protocol/packets/PlayerBuyItemPacket.cpp
Normal file
19
src/protocol/packets/PlayerBuyItemPacket.cpp
Normal file
@@ -0,0 +1,19 @@
|
|||||||
|
#include "protocol/packets/PlayerBuyItemPacket.h"
|
||||||
|
|
||||||
|
namespace td {
|
||||||
|
namespace protocol {
|
||||||
|
|
||||||
|
DataBuffer PlayerBuyItemPacket::Serialize(bool packetID) const {
|
||||||
|
DataBuffer data;
|
||||||
|
|
||||||
|
WritePacketID(data, packetID);
|
||||||
|
data << m_ItemType << m_Count;
|
||||||
|
return data;
|
||||||
|
}
|
||||||
|
|
||||||
|
void PlayerBuyItemPacket::Deserialize(DataBuffer& data) {
|
||||||
|
data >> m_ItemType >> m_Count;
|
||||||
|
}
|
||||||
|
|
||||||
|
} // namespace protocol
|
||||||
|
} // namespace td
|
||||||
19
src/protocol/packets/PlayerBuyMobUpgradePacket.cpp
Normal file
19
src/protocol/packets/PlayerBuyMobUpgradePacket.cpp
Normal file
@@ -0,0 +1,19 @@
|
|||||||
|
#include "protocol/packets/PlayerBuyMobUpgradePacket.h"
|
||||||
|
|
||||||
|
namespace td {
|
||||||
|
namespace protocol {
|
||||||
|
|
||||||
|
DataBuffer PlayerBuyMobUpgradePacket::Serialize(bool packetID) const {
|
||||||
|
DataBuffer data;
|
||||||
|
|
||||||
|
WritePacketID(data, packetID);
|
||||||
|
data << m_MobType << m_MobLevel;
|
||||||
|
return data;
|
||||||
|
}
|
||||||
|
|
||||||
|
void PlayerBuyMobUpgradePacket::Deserialize(DataBuffer& data) {
|
||||||
|
data >> m_MobType >> m_MobLevel;
|
||||||
|
}
|
||||||
|
|
||||||
|
} // namespace protocol
|
||||||
|
} // namespace td
|
||||||
19
src/protocol/packets/PlayerJoinPacket.cpp
Normal file
19
src/protocol/packets/PlayerJoinPacket.cpp
Normal file
@@ -0,0 +1,19 @@
|
|||||||
|
#include "protocol/packets/PlayerJoinPacket.h"
|
||||||
|
|
||||||
|
namespace td {
|
||||||
|
namespace protocol {
|
||||||
|
|
||||||
|
DataBuffer PlayerJoinPacket::Serialize(bool packetID) const {
|
||||||
|
DataBuffer data;
|
||||||
|
|
||||||
|
WritePacketID(data, packetID);
|
||||||
|
data << m_PlayerID << m_PlayerName;
|
||||||
|
return data;
|
||||||
|
}
|
||||||
|
|
||||||
|
void PlayerJoinPacket::Deserialize(DataBuffer& data) {
|
||||||
|
data >> m_PlayerID >> m_PlayerName;
|
||||||
|
}
|
||||||
|
|
||||||
|
} // namespace protocol
|
||||||
|
} // namespace td
|
||||||
20
src/protocol/packets/PlayerLeavePacket.cpp
Normal file
20
src/protocol/packets/PlayerLeavePacket.cpp
Normal file
@@ -0,0 +1,20 @@
|
|||||||
|
#include "protocol/packets/PlayerLeavePacket.h"
|
||||||
|
|
||||||
|
namespace td {
|
||||||
|
namespace protocol {
|
||||||
|
|
||||||
|
DataBuffer PlayerLeavePacket::Serialize(bool packetID) const {
|
||||||
|
DataBuffer data;
|
||||||
|
|
||||||
|
WritePacketID(data, packetID);
|
||||||
|
data << m_PlayerID;
|
||||||
|
return data;
|
||||||
|
}
|
||||||
|
|
||||||
|
void PlayerLeavePacket::Deserialize(DataBuffer& data) {
|
||||||
|
data >> m_PlayerID;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
} // namespace protocol
|
||||||
|
} // namespace td
|
||||||
30
src/protocol/packets/PlayerListPacket.cpp
Normal file
30
src/protocol/packets/PlayerListPacket.cpp
Normal file
@@ -0,0 +1,30 @@
|
|||||||
|
#include "protocol/packets/PlayerListPacket.h"
|
||||||
|
|
||||||
|
namespace td {
|
||||||
|
namespace protocol {
|
||||||
|
|
||||||
|
DataBuffer PlayerListPacket::Serialize(bool packetID) const {
|
||||||
|
DataBuffer data;
|
||||||
|
|
||||||
|
WritePacketID(data, packetID);
|
||||||
|
data << static_cast<std::uint8_t>(m_Players.size());
|
||||||
|
for (auto [playerID, playerInfo] : m_Players) {
|
||||||
|
data << playerID << playerInfo.name << playerInfo.team;
|
||||||
|
}
|
||||||
|
return data;
|
||||||
|
}
|
||||||
|
|
||||||
|
void PlayerListPacket::Deserialize(DataBuffer& data) {
|
||||||
|
std::uint8_t playerCount;
|
||||||
|
data >> playerCount;
|
||||||
|
|
||||||
|
for (int i = 0; i < playerCount; i++) {
|
||||||
|
std::uint8_t playerID;
|
||||||
|
PlayerInfo playerInfo;
|
||||||
|
data >> playerID >> playerInfo.name >> playerInfo.team;
|
||||||
|
m_Players.insert({ playerID, playerInfo });
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
} // namespace protocol
|
||||||
|
} // namespace td
|
||||||
19
src/protocol/packets/PlayerLoginPacket.cpp
Normal file
19
src/protocol/packets/PlayerLoginPacket.cpp
Normal file
@@ -0,0 +1,19 @@
|
|||||||
|
#include "protocol/packets/PlayerLoginPacket.h"
|
||||||
|
|
||||||
|
namespace td {
|
||||||
|
namespace protocol {
|
||||||
|
|
||||||
|
DataBuffer PlayerLoginPacket::Serialize(bool packetID) const {
|
||||||
|
DataBuffer data;
|
||||||
|
|
||||||
|
WritePacketID(data, packetID);
|
||||||
|
data << m_PlayerName;
|
||||||
|
return data;
|
||||||
|
}
|
||||||
|
|
||||||
|
void PlayerLoginPacket::Deserialize(DataBuffer& data) {
|
||||||
|
data >> m_PlayerName;
|
||||||
|
}
|
||||||
|
|
||||||
|
} // namespace protocol
|
||||||
|
} // namespace td
|
||||||
19
src/protocol/packets/RemoveTowerPacket.cpp
Normal file
19
src/protocol/packets/RemoveTowerPacket.cpp
Normal file
@@ -0,0 +1,19 @@
|
|||||||
|
#include "protocol/packets/RemoveTowerPacket.h"
|
||||||
|
|
||||||
|
namespace td {
|
||||||
|
namespace protocol {
|
||||||
|
|
||||||
|
DataBuffer RemoveTowerPacket::Serialize(bool packetID) const {
|
||||||
|
DataBuffer data;
|
||||||
|
|
||||||
|
WritePacketID(data, packetID);
|
||||||
|
data << m_TowerID;
|
||||||
|
return data;
|
||||||
|
}
|
||||||
|
|
||||||
|
void RemoveTowerPacket::Deserialize(DataBuffer& data) {
|
||||||
|
data >> m_TowerID;
|
||||||
|
}
|
||||||
|
|
||||||
|
} // namespace protocol
|
||||||
|
} // namespace td
|
||||||
19
src/protocol/packets/SelectTeamPacket.cpp
Normal file
19
src/protocol/packets/SelectTeamPacket.cpp
Normal file
@@ -0,0 +1,19 @@
|
|||||||
|
#include "protocol/packets/SelectTeamPacket.h"
|
||||||
|
|
||||||
|
namespace td {
|
||||||
|
namespace protocol {
|
||||||
|
|
||||||
|
DataBuffer SelectTeamPacket::Serialize(bool packetID) const {
|
||||||
|
DataBuffer data;
|
||||||
|
|
||||||
|
WritePacketID(data, packetID);
|
||||||
|
data << m_SelectedTeam;
|
||||||
|
return data;
|
||||||
|
}
|
||||||
|
|
||||||
|
void SelectTeamPacket::Deserialize(DataBuffer& data) {
|
||||||
|
data >> m_SelectedTeam;
|
||||||
|
}
|
||||||
|
|
||||||
|
} // namespace protocol
|
||||||
|
} // namespace td
|
||||||
26
src/protocol/packets/SendMobsPacket.cpp
Normal file
26
src/protocol/packets/SendMobsPacket.cpp
Normal file
@@ -0,0 +1,26 @@
|
|||||||
|
#include "protocol/packets/SendMobsPacket.h"
|
||||||
|
|
||||||
|
namespace td {
|
||||||
|
namespace protocol {
|
||||||
|
|
||||||
|
DataBuffer SendMobsPacket::Serialize(bool packetID) const {
|
||||||
|
DataBuffer data;
|
||||||
|
|
||||||
|
WritePacketID(data, packetID);
|
||||||
|
data << static_cast<std::uint8_t>(m_MobSends.size());
|
||||||
|
|
||||||
|
data.WriteSome(reinterpret_cast<const std::uint8_t*>(m_MobSends.data()), m_MobSends.size() * sizeof(m_MobSends));
|
||||||
|
|
||||||
|
return data;
|
||||||
|
}
|
||||||
|
|
||||||
|
void SendMobsPacket::Deserialize(DataBuffer& data) {
|
||||||
|
std::uint8_t mobSendCount;
|
||||||
|
data >> mobSendCount;
|
||||||
|
|
||||||
|
m_MobSends.resize(mobSendCount);
|
||||||
|
data.ReadSome(reinterpret_cast<std::uint8_t*>(m_MobSends.data()), mobSendCount * sizeof(MobSend));
|
||||||
|
}
|
||||||
|
|
||||||
|
} // namespace protocol
|
||||||
|
} // namespace td
|
||||||
19
src/protocol/packets/ServerTpsPacket.cpp
Normal file
19
src/protocol/packets/ServerTpsPacket.cpp
Normal file
@@ -0,0 +1,19 @@
|
|||||||
|
#include "protocol/packets/ServerTpsPacket.h"
|
||||||
|
|
||||||
|
namespace td {
|
||||||
|
namespace protocol {
|
||||||
|
|
||||||
|
DataBuffer ServerTpsPacket::Serialize(bool packetID) const {
|
||||||
|
DataBuffer data;
|
||||||
|
|
||||||
|
WritePacketID(data, packetID);
|
||||||
|
data << m_TPS << m_MSPT << m_PacketSendTime;
|
||||||
|
return data;
|
||||||
|
}
|
||||||
|
|
||||||
|
void ServerTpsPacket::Deserialize(DataBuffer& data) {
|
||||||
|
data >> m_TPS >> m_MSPT >> m_PacketSendTime;
|
||||||
|
}
|
||||||
|
|
||||||
|
} // namespace protocol
|
||||||
|
} // namespace td
|
||||||
21
src/protocol/packets/SpawnMobPacket.cpp
Normal file
21
src/protocol/packets/SpawnMobPacket.cpp
Normal file
@@ -0,0 +1,21 @@
|
|||||||
|
#include "protocol/packets/SpawnMobPacket.h"
|
||||||
|
|
||||||
|
namespace td {
|
||||||
|
namespace protocol {
|
||||||
|
|
||||||
|
DataBuffer SpawnMobPacket::Serialize(bool packetID) const {
|
||||||
|
DataBuffer data;
|
||||||
|
|
||||||
|
WritePacketID(data, packetID);
|
||||||
|
data << m_MobID << m_MobType << m_MobLevel << m_MobDirection
|
||||||
|
<< m_Sender << m_MobX << m_MobY;
|
||||||
|
return data;
|
||||||
|
}
|
||||||
|
|
||||||
|
void SpawnMobPacket::Deserialize(DataBuffer& data) {
|
||||||
|
data >> m_MobID >> m_MobType >> m_MobLevel >> m_MobDirection
|
||||||
|
>> m_Sender >> m_MobX >> m_MobY;
|
||||||
|
}
|
||||||
|
|
||||||
|
} // namespace protocol
|
||||||
|
} // namespace td
|
||||||
19
src/protocol/packets/UpdateCastleLifePacket.cpp
Normal file
19
src/protocol/packets/UpdateCastleLifePacket.cpp
Normal file
@@ -0,0 +1,19 @@
|
|||||||
|
#include "protocol/packets/UpdateCastleLifePacket.h"
|
||||||
|
|
||||||
|
namespace td {
|
||||||
|
namespace protocol {
|
||||||
|
|
||||||
|
DataBuffer UpdateCastleLifePacket::Serialize(bool packetID) const {
|
||||||
|
DataBuffer data;
|
||||||
|
|
||||||
|
WritePacketID(data, packetID);
|
||||||
|
data << m_CastleLife << m_Team;
|
||||||
|
return data;
|
||||||
|
}
|
||||||
|
|
||||||
|
void UpdateCastleLifePacket::Deserialize(DataBuffer& data) {
|
||||||
|
data >> m_CastleLife >> m_Team;
|
||||||
|
}
|
||||||
|
|
||||||
|
} // namespace protocol
|
||||||
|
} // namespace td
|
||||||
19
src/protocol/packets/UpdateExpPacket.cpp
Normal file
19
src/protocol/packets/UpdateExpPacket.cpp
Normal file
@@ -0,0 +1,19 @@
|
|||||||
|
#include "protocol/packets/UpdateExpPacket.h"
|
||||||
|
|
||||||
|
namespace td {
|
||||||
|
namespace protocol {
|
||||||
|
|
||||||
|
DataBuffer UpdateExpPacket::Serialize(bool packetID) const {
|
||||||
|
DataBuffer data;
|
||||||
|
|
||||||
|
WritePacketID(data, packetID);
|
||||||
|
data << m_NewAmount;
|
||||||
|
return data;
|
||||||
|
}
|
||||||
|
|
||||||
|
void UpdateExpPacket::Deserialize(DataBuffer& data) {
|
||||||
|
data >> m_NewAmount;
|
||||||
|
}
|
||||||
|
|
||||||
|
} // namespace protocol
|
||||||
|
} // namespace td
|
||||||
19
src/protocol/packets/UpdateGameStatePacket.cpp
Normal file
19
src/protocol/packets/UpdateGameStatePacket.cpp
Normal file
@@ -0,0 +1,19 @@
|
|||||||
|
#include "protocol/packets/UpdateGameStatePacket.h"
|
||||||
|
|
||||||
|
namespace td {
|
||||||
|
namespace protocol {
|
||||||
|
|
||||||
|
DataBuffer UpdateGameStatePacket::Serialize(bool packetID) const {
|
||||||
|
DataBuffer data;
|
||||||
|
|
||||||
|
WritePacketID(data, packetID);
|
||||||
|
data << m_GameState;
|
||||||
|
return data;
|
||||||
|
}
|
||||||
|
|
||||||
|
void UpdateGameStatePacket::Deserialize(DataBuffer& data) {
|
||||||
|
data >> m_GameState;
|
||||||
|
}
|
||||||
|
|
||||||
|
} // namespace protocol
|
||||||
|
} // namespace td
|
||||||
19
src/protocol/packets/UpdateLobbyTimePacket.cpp
Normal file
19
src/protocol/packets/UpdateLobbyTimePacket.cpp
Normal file
@@ -0,0 +1,19 @@
|
|||||||
|
#include "protocol/packets/UpdateLobbyTimePacket.h"
|
||||||
|
|
||||||
|
namespace td {
|
||||||
|
namespace protocol {
|
||||||
|
|
||||||
|
DataBuffer UpdateLobbyTimePacket::Serialize(bool packetID) const {
|
||||||
|
DataBuffer data;
|
||||||
|
|
||||||
|
WritePacketID(data, packetID);
|
||||||
|
data << m_StartTime;
|
||||||
|
return data;
|
||||||
|
}
|
||||||
|
|
||||||
|
void UpdateLobbyTimePacket::Deserialize(DataBuffer& data) {
|
||||||
|
data >> m_StartTime;
|
||||||
|
}
|
||||||
|
|
||||||
|
} // 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