Compare commits
119 Commits
alpha-0.2.
...
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 | |||
| 8949c37891 | |||
| 019174128c | |||
| 4e8b095e31 | |||
| 0e0368cada | |||
|
|
6e0923ac75 | ||
|
|
bba9ef8219 | ||
| fd2288ac3c | |||
| 660952aed3 | |||
| 243b153309 | |||
| 73fa10d8d6 | |||
| 0b8a7d8db7 | |||
| e2ec9d6a3b | |||
| eb5b3c8ce2 | |||
| ddbba7399d | |||
| 9ce1f4a1a8 | |||
| ea4349af4c | |||
| d6fbb58da8 | |||
| 66376eaeda | |||
| 85eb9bbc32 | |||
| bbb84c0061 | |||
| 2f1161959b | |||
| f506307653 | |||
| 40f0d50991 | |||
| 663ad60ee3 | |||
| 3fbb6acac7 | |||
| 377e98f583 | |||
| ef9712629f | |||
| ed481de03e | |||
| 7d667d9c5e | |||
| 16006adc6e | |||
| 19062b5c77 | |||
| d3c6ff3988 | |||
| 31a0027bfc | |||
| d4b1805998 | |||
| b84f1fd302 | |||
| 98f73f467d | |||
| dc8a4ce947 | |||
| 113a831f39 | |||
| f906aa1bf0 | |||
| 1bbf607b22 | |||
| d5b42caf39 | |||
| d3edc0cb6c | |||
| 87e4e65843 | |||
| 7509cc1bf2 | |||
| 6df59b1487 | |||
| 553b2f6aad | |||
| 916fa0e7c0 | |||
| bc271bc01e | |||
| 97a33e5517 | |||
| bdebabb79e | |||
| 387cff36ad | |||
| 790237a1b5 | |||
| 840d5edbe4 | |||
| 36a9e1921c |
148
include/Defines.h
Normal file
148
include/Defines.h
Normal file
@@ -0,0 +1,148 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <cstdint>
|
||||||
|
|
||||||
|
namespace td {
|
||||||
|
|
||||||
|
static constexpr float PI = 3.141592653f;
|
||||||
|
|
||||||
|
template<typename T>
|
||||||
|
struct Vec2 {
|
||||||
|
union {
|
||||||
|
T x;
|
||||||
|
T r;
|
||||||
|
};
|
||||||
|
|
||||||
|
union {
|
||||||
|
T y;
|
||||||
|
T g;
|
||||||
|
};
|
||||||
|
|
||||||
|
constexpr Vec2(T X = 0, T Y = 0) : x(X), y(Y) {}
|
||||||
|
};
|
||||||
|
|
||||||
|
template<typename T>
|
||||||
|
inline bool operator==(const Vec2<T>& vec2, const Vec2<T>& other) {
|
||||||
|
return vec2.x == other.x && vec2.y == other.y;
|
||||||
|
}
|
||||||
|
|
||||||
|
template<typename T>
|
||||||
|
struct Vec3 {
|
||||||
|
union {
|
||||||
|
T x;
|
||||||
|
T r;
|
||||||
|
};
|
||||||
|
|
||||||
|
union {
|
||||||
|
T y;
|
||||||
|
T g;
|
||||||
|
};
|
||||||
|
|
||||||
|
union {
|
||||||
|
T z;
|
||||||
|
T b;
|
||||||
|
};
|
||||||
|
|
||||||
|
constexpr Vec3(T X = 0, T Y = 0, T Z = 0) : x(X), y(Y), z(Z) {}
|
||||||
|
};
|
||||||
|
|
||||||
|
template<typename T>
|
||||||
|
inline bool operator==(const Vec3<T>& vec3, const Vec3<T>& other) {
|
||||||
|
return vec3.x == other.x && vec3.y == other.y && vec3.z == other.z;
|
||||||
|
}
|
||||||
|
|
||||||
|
template<typename T>
|
||||||
|
struct Vec4 {
|
||||||
|
union {
|
||||||
|
T x;
|
||||||
|
T r;
|
||||||
|
};
|
||||||
|
|
||||||
|
union {
|
||||||
|
T y;
|
||||||
|
T g;
|
||||||
|
};
|
||||||
|
|
||||||
|
union {
|
||||||
|
T z;
|
||||||
|
T b;
|
||||||
|
};
|
||||||
|
|
||||||
|
union {
|
||||||
|
T w;
|
||||||
|
T a;
|
||||||
|
};
|
||||||
|
|
||||||
|
constexpr Vec4(Vec3<T> vec, T W = 1) : x(vec.x), y(vec.y), z(vec.z), w(W) {}
|
||||||
|
constexpr Vec4(T X = 0, T Y = 0, T Z = 0, T W = 0) : x(X), y(Y), z(Z), w(W) {}
|
||||||
|
};
|
||||||
|
|
||||||
|
template<typename T>
|
||||||
|
inline bool operator==(const Vec4<T>& vec4, const Vec4<T>& other) {
|
||||||
|
return vec4.x == other.x && vec4.y == other.y && vec4.z == other.z && vec4.w = other.w;
|
||||||
|
}
|
||||||
|
|
||||||
|
using Vec2i = Vec2<int>;
|
||||||
|
using Vec2u = Vec2<unsigned int>;
|
||||||
|
using Vec2f = Vec2<float>;
|
||||||
|
using Vec2d = Vec2<double>;
|
||||||
|
|
||||||
|
using Vec3i = Vec3<int>;
|
||||||
|
using Vec3u = Vec3<unsigned int>;
|
||||||
|
using Vec3f = Vec3<float>;
|
||||||
|
using Vec3d = Vec3<double>;
|
||||||
|
|
||||||
|
using Vec4i = Vec4<int>;
|
||||||
|
using Vec4u = Vec4<unsigned int>;
|
||||||
|
using Vec4f = Vec4<float>;
|
||||||
|
using Vec4d = Vec4<double>;
|
||||||
|
|
||||||
|
using Color = Vec3<unsigned char>;
|
||||||
|
|
||||||
|
template<typename T>
|
||||||
|
struct Mat4 {
|
||||||
|
static const std::size_t MATRIX_SIZE = 4;
|
||||||
|
|
||||||
|
T x0, x1, x2, x3;
|
||||||
|
T y0, y1, y2, y3;
|
||||||
|
T z0, z1, z2, z3;
|
||||||
|
T w0, w1, w2, w3;
|
||||||
|
|
||||||
|
T operator[] (std::size_t offset) const {
|
||||||
|
return reinterpret_cast<const T*>(this)[offset];
|
||||||
|
}
|
||||||
|
|
||||||
|
T& operator[] (std::size_t offset) {
|
||||||
|
return reinterpret_cast<T*>(this)[offset];
|
||||||
|
}
|
||||||
|
|
||||||
|
T* data() {
|
||||||
|
return reinterpret_cast<T*>(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
const T* data() const{
|
||||||
|
return reinterpret_cast<const T*>(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
T at(std::size_t row, std::size_t column) const {
|
||||||
|
return operator[](row * MATRIX_SIZE + column);
|
||||||
|
}
|
||||||
|
|
||||||
|
T& at(std::size_t row, std::size_t column) {
|
||||||
|
return operator[](row * MATRIX_SIZE + column);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
typedef Mat4<float> Mat4f;
|
||||||
|
typedef Mat4<int> Mat4i;
|
||||||
|
typedef Mat4<double> Mat4d;
|
||||||
|
|
||||||
|
template<typename T>
|
||||||
|
inline bool operator==(const Mat4<T>& mat, const Mat4<T>& other) {
|
||||||
|
return mat.x0 == other.x0 && mat.y0 == other.y0 && mat.z0 == other.z0 && mat.w0 == other.w0 &&
|
||||||
|
mat.x1 == other.x1 && mat.y1 == other.y1 && mat.z1 == other.z1 && mat.w1 == other.w1 &&
|
||||||
|
mat.x2 == other.x2 && mat.y2 == other.y2 && mat.z2 == other.z2 && mat.w2 == other.w2 &&
|
||||||
|
mat.x3 == other.x3 && mat.y3 == other.y3 && mat.z3 == other.z3 && mat.w3 == other.w3;
|
||||||
|
}
|
||||||
|
|
||||||
|
} // namespace td
|
||||||
@@ -36,34 +36,38 @@ 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();
|
||||||
|
|
||||||
virtual void tick(std::uint64_t delta);
|
virtual void Tick(std::uint64_t delta);
|
||||||
|
|
||||||
Team& getRedTeam() { return m_Teams[(std::uint8_t)TeamColor::Red]; }
|
Team& GetRedTeam() { return m_Teams[static_cast<std::uint8_t>(TeamColor::Red)]; }
|
||||||
const Team& getRedTeam() const { return m_Teams[(std::uint8_t)TeamColor::Red]; }
|
const Team& GetRedTeam() const { return m_Teams[static_cast<std::uint8_t>(TeamColor::Red)]; }
|
||||||
|
|
||||||
Team& getBlueTeam() { return m_Teams[(std::uint8_t)TeamColor::Blue]; }
|
Team& GetBlueTeam() { return m_Teams[static_cast<std::uint8_t>(TeamColor::Blue)]; }
|
||||||
const Team& getBlueTeam() const { return m_Teams[(std::uint8_t)TeamColor::Blue]; }
|
const Team& GetBlueTeam() const { return m_Teams[static_cast<std::uint8_t>(TeamColor::Red)]; }
|
||||||
|
|
||||||
Team& getTeam(TeamColor team) { return m_Teams[(std::uint8_t)team]; }
|
Team& GetTeam(TeamColor team) { return m_Teams[static_cast<std::uint8_t>(team)]; }
|
||||||
const Team& getTeam(TeamColor team) const { return m_Teams[(std::uint8_t)team]; }
|
const Team& GetTeam(TeamColor team) const { return m_Teams[static_cast<std::uint8_t>(team)]; }
|
||||||
|
|
||||||
GameState getGameState() const { return m_GameState; }
|
GameState GetGameState() const { return m_GameState; }
|
||||||
void setGameState(GameState gameState) { m_GameState = gameState; };
|
void SetGameState(GameState gameState) { m_GameState = gameState; };
|
||||||
|
|
||||||
const World* getWorld() const { return m_World; }
|
const World* GetWorld() const { return m_World; }
|
||||||
World* getWorld() { return m_World; }
|
World* GetWorld() { return m_World; }
|
||||||
|
|
||||||
const PlayerList& getPlayers() const { return m_Players; }
|
const PlayerList& GetPlayers() const { return m_Players; }
|
||||||
PlayerList& getPlayers() { return m_Players; }
|
PlayerList& GetPlayers() { return m_Players; }
|
||||||
|
|
||||||
const Player* getPlayerById(PlayerID id) const;
|
const Player* GetPlayerById(PlayerID id) const;
|
||||||
Player* getPlayerById(PlayerID id);
|
Player* GetPlayerById(PlayerID id);
|
||||||
|
|
||||||
const TeamList& getTeams() const { return m_Teams; }
|
const TeamList& GetTeams() const { return m_Teams; }
|
||||||
|
|
||||||
|
std::uint64_t GetGameStartTime() const { return m_GameStartTime; }
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -20,14 +20,14 @@ public:
|
|||||||
Connexion(protocol::PacketDispatcher* dispatcher, network::TCPSocket& socket);
|
Connexion(protocol::PacketDispatcher* dispatcher, network::TCPSocket& socket);
|
||||||
virtual ~Connexion();
|
virtual ~Connexion();
|
||||||
|
|
||||||
virtual bool updateSocket();
|
virtual bool UpdateSocket();
|
||||||
void closeConnection();
|
void CloseConnection();
|
||||||
|
|
||||||
bool connect(const std::string& address, std::uint16_t port);
|
bool Connect(const std::string& address, std::uint16_t port);
|
||||||
|
|
||||||
network::Socket::Status getSocketStatus() const { return m_Socket.GetStatus(); }
|
network::Socket::Status GetSocketStatus() const { return m_Socket.GetStatus(); }
|
||||||
|
|
||||||
void sendPacket(const protocol::Packet* packet);
|
void SendPacket(const protocol::Packet* packet);
|
||||||
|
|
||||||
REMOVE_COPY(Connexion);
|
REMOVE_COPY(Connexion);
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -10,12 +10,12 @@
|
|||||||
|
|
||||||
namespace GameManager {
|
namespace GameManager {
|
||||||
|
|
||||||
void render();
|
void Render();
|
||||||
void init();
|
void Init();
|
||||||
void destroy();
|
void Destroy();
|
||||||
void tick();
|
void Tick();
|
||||||
|
|
||||||
void startServer();
|
void StartServer();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
|
#include "Defines.h"
|
||||||
#include "Towers.h"
|
#include "Towers.h"
|
||||||
#include "Types.h"
|
#include "Types.h"
|
||||||
#include "Team.h"
|
#include "Team.h"
|
||||||
@@ -9,8 +10,6 @@
|
|||||||
#include <vector>
|
#include <vector>
|
||||||
#include <memory>
|
#include <memory>
|
||||||
|
|
||||||
#include <glm/glm.hpp>
|
|
||||||
|
|
||||||
namespace td {
|
namespace td {
|
||||||
namespace game {
|
namespace game {
|
||||||
|
|
||||||
@@ -48,26 +47,26 @@ class MobStats {
|
|||||||
private:
|
private:
|
||||||
float m_Damage;
|
float m_Damage;
|
||||||
float m_Speed;
|
float m_Speed;
|
||||||
glm::vec2 m_Size;
|
Vec2f m_Size;
|
||||||
std::uint16_t m_MoneyCost;
|
std::uint16_t m_MoneyCost;
|
||||||
std::uint16_t m_ExpCost;
|
std::uint16_t m_ExpCost;
|
||||||
std::uint16_t m_MaxLife;
|
std::uint16_t m_MaxLife;
|
||||||
std::uint16_t m_ExpReward;
|
std::uint16_t m_ExpReward;
|
||||||
public:
|
public:
|
||||||
MobStats(float damage, float speed, glm::vec2 size, std::uint16_t moneyCost,
|
MobStats(float damage, float speed, Vec2f size, std::uint16_t moneyCost,
|
||||||
std::uint16_t expCost, std::uint16_t expReward,
|
std::uint16_t expCost, std::uint16_t expReward,
|
||||||
std::uint16_t maxLife) : m_Damage(damage), m_Speed(speed),
|
std::uint16_t maxLife) : m_Damage(damage), m_Speed(speed),
|
||||||
m_Size(size), m_MoneyCost(moneyCost), m_ExpCost(expCost),
|
m_Size(size), m_MoneyCost(moneyCost), m_ExpCost(expCost),
|
||||||
m_MaxLife(maxLife), m_ExpReward(expReward) {
|
m_MaxLife(maxLife), m_ExpReward(expReward) {
|
||||||
}
|
}
|
||||||
|
|
||||||
float getDamage() const { return m_Damage; }
|
float GetDamage() const { return m_Damage; }
|
||||||
float getMovementSpeed() const { return m_Speed; }
|
float GetMovementSpeed() const { return m_Speed; }
|
||||||
const glm::vec2& getSize() const { return m_Size; }
|
const Vec2f& GetSize() const { return m_Size; }
|
||||||
std::uint16_t getMoneyCost() const { return m_MoneyCost; }
|
std::uint16_t GetMoneyCost() const { return m_MoneyCost; }
|
||||||
std::uint16_t getExpCost() const { return m_ExpCost; }
|
std::uint16_t GetExpCost() const { return m_ExpCost; }
|
||||||
std::uint16_t getExpReward() const { return m_ExpReward; }
|
std::uint16_t GetExpReward() const { return m_ExpReward; }
|
||||||
std::uint16_t getMaxLife() const { return m_MaxLife; }
|
std::uint16_t GetMaxLife() const { return m_MaxLife; }
|
||||||
};
|
};
|
||||||
|
|
||||||
struct EffectDuration {
|
struct EffectDuration {
|
||||||
@@ -76,9 +75,9 @@ struct EffectDuration {
|
|||||||
Tower* tower; // the tower that gived the effect
|
Tower* tower; // the tower that gived the effect
|
||||||
};
|
};
|
||||||
|
|
||||||
const MobStats* getMobStats(MobType type, std::uint8_t level);
|
const MobStats* GetMobStats(MobType type, std::uint8_t level);
|
||||||
const TowerImmunities& getMobTowerImmunities(MobType type, std::uint8_t level);
|
const TowerImmunities& GetMobTowerImmunities(MobType type, std::uint8_t level);
|
||||||
const EffectImmunities& getMobEffectImmunities(MobType type, std::uint8_t level);
|
const EffectImmunities& GetMobEffectImmunities(MobType type, std::uint8_t level);
|
||||||
|
|
||||||
class Mob : public utils::shape::Rectangle {
|
class Mob : public utils::shape::Rectangle {
|
||||||
protected:
|
protected:
|
||||||
@@ -90,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;
|
||||||
@@ -100,136 +100,148 @@ 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) {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual MobType getType() const = 0;
|
virtual MobType GetType() const = 0;
|
||||||
|
|
||||||
virtual void tick(std::uint64_t delta, World* world);
|
virtual void Tick(std::uint64_t delta, World* world);
|
||||||
|
|
||||||
virtual bool OnDeath(World* world) { return true; }
|
virtual bool OnDeath(World* world) { return true; }
|
||||||
|
|
||||||
MobID getMobID() const { return m_ID; }
|
MobID GetMobID() const { return m_ID; }
|
||||||
const TowerImmunities& getTowerImmunities() const { return getMobTowerImmunities(getType(), m_Level); }
|
const TowerImmunities& GetTowerImmunities() const { return GetMobTowerImmunities(GetType(), m_Level); }
|
||||||
const EffectImmunities& getEffectImmunities() const { return getMobEffectImmunities(getType(), m_Level); }
|
const EffectImmunities& GetEffectImmunities() const { return GetMobEffectImmunities(GetType(), m_Level); }
|
||||||
PlayerID getSender() const { return m_Sender; }
|
PlayerID GetSender() const { return m_Sender; }
|
||||||
MobLevel getLevel() const { return m_Level; }
|
MobLevel GetLevel() const { return m_Level; }
|
||||||
const MobStats* getStats() const { return getMobStats(getType(), m_Level); }
|
const MobStats* GetStats() const { return GetMobStats(GetType(), m_Level); }
|
||||||
void setHealth(float newHealth) { m_Health = newHealth; }
|
void SetHealth(float newHealth) { m_Health = newHealth; }
|
||||||
float getHealth() const { return m_Health; }
|
float GetHealth() const { return m_Health; }
|
||||||
bool isDead() const { return m_Health <= 0; }
|
bool IsDead() const { return m_Health <= 0; }
|
||||||
bool isAlive() const { return m_Health > 0; }
|
bool IsAlive() const { return m_Health > 0; }
|
||||||
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);
|
||||||
void setMobReachedCastle(TeamCastle* castle) { m_CastleTarget = castle; } // used when mob is in front of the castle
|
m_LastDamage = damager;
|
||||||
|
m_HitCooldown = 0.1;
|
||||||
|
}
|
||||||
|
|
||||||
bool isImmuneTo(TowerType type);
|
void Heal(float heal) {
|
||||||
|
m_Health = std::min(static_cast<float>(GetStats()->GetMaxLife()), m_Health + heal);
|
||||||
|
}
|
||||||
|
|
||||||
bool isImmuneTo(EffectType type);
|
void SetMobReachedCastle(TeamCastle* castle) { m_CastleTarget = castle; } // used when mob is in front of the castle
|
||||||
void addEffect(EffectType type, float durationSec, Tower* tower);
|
|
||||||
bool hasEffect(EffectType type);
|
|
||||||
|
|
||||||
float getTileX() { return getCenterX() - static_cast<float>(static_cast<std::int32_t>(getCenterX())); } // returns a float between 0 and 1 excluded
|
bool IsImmuneTo(TowerType type);
|
||||||
float getTileY() { return getCenterY() - static_cast<float>(static_cast<std::int32_t>(getCenterY())); } // returns a float between 0 and 1 excluded
|
|
||||||
|
|
||||||
Direction getDirection() const { return m_Direction; }
|
bool IsImmuneTo(EffectType type);
|
||||||
void setDirection(Direction dir) { m_Direction = dir; }
|
void AddEffect(EffectType type, float durationSec, Tower* tower);
|
||||||
|
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 GetTileY() { return GetCenterY() - static_cast<float>(static_cast<std::int32_t>(GetCenterY())); } // returns a float between 0 and 1 excluded
|
||||||
|
|
||||||
|
Direction GetDirection() const { return m_Direction; }
|
||||||
|
void SetDirection(Direction dir) { m_Direction = dir; }
|
||||||
protected:
|
protected:
|
||||||
void initMob() {
|
void InitMob() {
|
||||||
m_Health = static_cast<float>(getStats()->getMaxLife());
|
m_Health = static_cast<float>(GetStats()->GetMaxLife());
|
||||||
setSize(getStats()->getSize().x, getStats()->getSize().y);
|
SetSize(GetStats()->GetSize().x, GetStats()->GetSize().y);
|
||||||
}
|
}
|
||||||
private:
|
private:
|
||||||
void updateEffects(std::uint64_t delta, World* world);
|
void UpdateEffects(std::uint64_t delta, World* world);
|
||||||
void attackCastle(std::uint64_t delta, World* world);
|
void AttackCastle(std::uint64_t delta, World* world);
|
||||||
void move(std::uint64_t delta, World* world);
|
void Move(std::uint64_t delta, World* world);
|
||||||
void walk(std::uint64_t delta, World* world);
|
void Walk(std::uint64_t delta, World* world);
|
||||||
void moveBack(const TeamCastle& castle, World* world);
|
void MoveBack(const TeamCastle& castle, World* world);
|
||||||
void changeDirection(const WalkableTile& tile, World* world);
|
void ChangeDirection(const WalkableTile& tile, World* world);
|
||||||
bool isTouchingCastle(const TeamCastle& castle) const;
|
bool IsTouchingCastle(const TeamCastle& castle) const;
|
||||||
EffectDuration& getEffect(EffectType type);
|
EffectDuration& GetEffect(EffectType type);
|
||||||
};
|
};
|
||||||
|
|
||||||
typedef std::shared_ptr<Mob> MobPtr;
|
typedef std::shared_ptr<Mob> MobPtr;
|
||||||
|
|
||||||
class Zombie : public Mob {
|
class Zombie : public Mob {
|
||||||
public:
|
public:
|
||||||
Zombie(MobID id, std::uint8_t level, PlayerID sender) : Mob(id, level, sender) { initMob(); }
|
Zombie(MobID id, std::uint8_t level, PlayerID sender) : Mob(id, level, sender) { InitMob(); }
|
||||||
|
|
||||||
virtual MobType getType() const { return MobType::Zombie; }
|
virtual MobType GetType() const { return MobType::Zombie; }
|
||||||
};
|
};
|
||||||
|
|
||||||
class Spider : public Mob {
|
class Spider : public Mob {
|
||||||
public:
|
public:
|
||||||
Spider(MobID id, std::uint8_t level, PlayerID sender) : Mob(id, level, sender) { initMob(); }
|
Spider(MobID id, std::uint8_t level, PlayerID sender) : Mob(id, level, sender) { InitMob(); }
|
||||||
|
|
||||||
virtual MobType getType() const { return MobType::Spider; }
|
virtual MobType GetType() const { return MobType::Spider; }
|
||||||
};
|
};
|
||||||
|
|
||||||
class Skeleton : public Mob {
|
class Skeleton : public Mob {
|
||||||
public:
|
public:
|
||||||
Skeleton(MobID id, std::uint8_t level, PlayerID sender) : Mob(id, level, sender) { initMob(); }
|
Skeleton(MobID id, std::uint8_t level, PlayerID sender) : Mob(id, level, sender) { InitMob(); }
|
||||||
|
|
||||||
virtual MobType getType() const { return MobType::Skeleton; }
|
virtual MobType GetType() const { return MobType::Skeleton; }
|
||||||
};
|
};
|
||||||
|
|
||||||
class PigMan : public Mob {
|
class PigMan : public Mob {
|
||||||
public:
|
public:
|
||||||
PigMan(MobID id, std::uint8_t level, PlayerID sender) : Mob(id, level, sender) { initMob(); }
|
PigMan(MobID id, std::uint8_t level, PlayerID sender) : Mob(id, level, sender) { InitMob(); }
|
||||||
|
|
||||||
virtual MobType getType() const { return MobType::Pigman; }
|
virtual MobType GetType() const { return MobType::Pigman; }
|
||||||
};
|
};
|
||||||
|
|
||||||
class Creeper : public Mob {
|
class Creeper : public Mob {
|
||||||
public:
|
public:
|
||||||
Creeper(MobID id, std::uint8_t level, PlayerID sender) : Mob(id, level, sender) { initMob(); }
|
Creeper(MobID id, std::uint8_t level, PlayerID sender) : Mob(id, level, sender) { InitMob(); }
|
||||||
|
|
||||||
virtual MobType getType() const { return MobType::Creeper; }
|
virtual MobType GetType() const { return MobType::Creeper; }
|
||||||
};
|
};
|
||||||
|
|
||||||
class Silverfish : public Mob {
|
class Silverfish : public Mob {
|
||||||
public:
|
public:
|
||||||
Silverfish(MobID id, std::uint8_t level, PlayerID sender) : Mob(id, level, sender) { initMob(); }
|
Silverfish(MobID id, std::uint8_t level, PlayerID sender) : Mob(id, level, sender) { InitMob(); }
|
||||||
|
|
||||||
virtual MobType getType() const { return MobType::Silverfish; }
|
virtual MobType GetType() const { return MobType::Silverfish; }
|
||||||
};
|
};
|
||||||
|
|
||||||
class Blaze : public Mob {
|
class Blaze : public Mob {
|
||||||
public:
|
public:
|
||||||
Blaze(MobID id, std::uint8_t level, PlayerID sender) : Mob(id, level, sender) { initMob(); }
|
Blaze(MobID id, std::uint8_t level, PlayerID sender) : Mob(id, level, sender) { InitMob(); }
|
||||||
|
|
||||||
virtual MobType getType() const { return MobType::Blaze; }
|
virtual MobType GetType() const { return MobType::Blaze; }
|
||||||
};
|
};
|
||||||
|
|
||||||
class Witch : public Mob {
|
class Witch : public Mob {
|
||||||
public:
|
public:
|
||||||
Witch(MobID id, std::uint8_t level, PlayerID sender) : Mob(id, level, sender) { initMob(); }
|
Witch(MobID id, std::uint8_t level, PlayerID sender) : Mob(id, level, sender) { InitMob(); }
|
||||||
|
|
||||||
virtual MobType getType() const { return MobType::Witch; }
|
virtual MobType GetType() const { return MobType::Witch; }
|
||||||
};
|
};
|
||||||
|
|
||||||
class Slime : public Mob {
|
class Slime : public Mob {
|
||||||
public:
|
public:
|
||||||
Slime(MobID id, std::uint8_t level, PlayerID sender) : Mob(id, level, sender) { initMob(); }
|
Slime(MobID id, std::uint8_t level, PlayerID sender) : Mob(id, level, sender) { InitMob(); }
|
||||||
|
|
||||||
virtual MobType getType() const { return MobType::Slime; }
|
virtual MobType GetType() const { return MobType::Slime; }
|
||||||
};
|
};
|
||||||
|
|
||||||
class Giant : public Mob {
|
class Giant : public Mob {
|
||||||
public:
|
public:
|
||||||
Giant(MobID id, std::uint8_t level, PlayerID sender) : Mob(id, level, sender) { initMob(); }
|
Giant(MobID id, std::uint8_t level, PlayerID sender) : Mob(id, level, sender) { InitMob(); }
|
||||||
|
|
||||||
virtual MobType getType() const { return MobType::Giant; }
|
virtual MobType GetType() const { return MobType::Giant; }
|
||||||
};
|
};
|
||||||
|
|
||||||
namespace MobFactory {
|
namespace MobFactory {
|
||||||
MobPtr createMob(MobID id, MobType type, std::uint8_t level, PlayerID sender);
|
|
||||||
std::string getMobName(MobType type);
|
MobPtr CreateMob(MobID id, MobType type, std::uint8_t level, PlayerID sender);
|
||||||
|
std::string GetMobName(MobType type);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
class MobListener {
|
class MobListener {
|
||||||
|
|||||||
@@ -1,56 +1,50 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <cstdint>
|
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
#include "game/Team.h"
|
#include "game/Team.h"
|
||||||
|
#include "game/PlayerUpgrades.h"
|
||||||
|
|
||||||
namespace td {
|
namespace td {
|
||||||
namespace game {
|
namespace game {
|
||||||
|
|
||||||
class Player {
|
class Player {
|
||||||
private:
|
private:
|
||||||
game::TeamColor m_TeamColor;
|
TeamColor m_TeamColor;
|
||||||
|
PlayerUpgrades m_Upgrades;
|
||||||
|
|
||||||
std::uint32_t m_Gold;
|
std::uint32_t m_Gold;
|
||||||
std::uint32_t m_Exp;
|
std::uint32_t m_Exp;
|
||||||
std::string m_Name;
|
std::string m_Name;
|
||||||
std::uint8_t m_ID;
|
PlayerID m_ID;
|
||||||
|
|
||||||
std::uint8_t m_GoldPerSecond;
|
|
||||||
|
|
||||||
bool m_GoldChanged;
|
|
||||||
bool m_ExpChanged;
|
|
||||||
public:
|
public:
|
||||||
Player(std::uint8_t id = 0) : m_TeamColor(game::TeamColor::None), m_Gold(0), m_Exp(0), m_ID(id), m_GoldPerSecond(5),
|
|
||||||
m_GoldChanged(false), m_ExpChanged(false) {}
|
|
||||||
|
|
||||||
const std::string& getName() const { return m_Name; }
|
Player(std::uint8_t id = 0) : m_TeamColor(TeamColor::None), m_Gold(0), m_Exp(0), m_ID(id) {}
|
||||||
void setName(const std::string& name) { m_Name = name; }
|
|
||||||
|
|
||||||
game::TeamColor getTeamColor() const { return m_TeamColor; }
|
const std::string& GetName() const { return m_Name; }
|
||||||
void setTeamColor(game::TeamColor teamColor) { m_TeamColor = teamColor; }
|
void SetName(const std::string& name) { m_Name = name; }
|
||||||
|
|
||||||
std::uint8_t getGoldPerSecond() const { return m_GoldPerSecond; }
|
TeamColor GetTeamColor() const { return m_TeamColor; }
|
||||||
void setGoldPerSecond(std::uint8_t goldPerSecond) { m_GoldPerSecond = goldPerSecond; }
|
void SetTeamColor(TeamColor teamColor) { m_TeamColor = teamColor; }
|
||||||
|
|
||||||
std::uint32_t getGold() const { return m_Gold; }
|
std::uint32_t GetGold() const { return m_Gold; }
|
||||||
void setGold(std::uint32_t gold) { m_GoldChanged = true; m_Gold = gold; }
|
void SetGold(std::uint32_t gold) { m_Gold = gold; }
|
||||||
void addGold(std::uint32_t gold) { m_GoldChanged = true; m_Gold += gold; }
|
void AddGold(std::uint32_t gold) { m_Gold += gold; }
|
||||||
void removeGold(std::uint32_t gold) { m_GoldChanged = true; m_Gold -= gold; }
|
void RemoveGold(std::uint32_t gold) { m_Gold -= gold; }
|
||||||
|
|
||||||
std::uint32_t getExp() const { return m_Exp; }
|
std::uint32_t GetExp() const { return m_Exp; }
|
||||||
void setExp(std::uint32_t exp) { m_ExpChanged = true; m_Exp = exp; }
|
void SetExp(std::uint32_t exp) { m_Exp = exp; }
|
||||||
void addExp(std::uint32_t exp) { m_ExpChanged = true; m_Exp += exp; }
|
void AddExp(std::uint32_t exp) { m_Exp += exp; }
|
||||||
void removeExp(std::uint32_t exp) { m_ExpChanged = true; m_Exp -= exp; }
|
void RemoveExp(std::uint32_t exp) { m_Exp -= exp; }
|
||||||
|
|
||||||
bool hasGoldChanged() const { return m_GoldChanged; }
|
const PlayerUpgrades& getUpgrades() const { return m_Upgrades; }
|
||||||
bool hasExpChanged() const { return m_ExpChanged; }
|
PlayerUpgrades& getUpgrades() { return m_Upgrades; }
|
||||||
|
|
||||||
void updateGold() { m_GoldChanged = false; }
|
bool HasEnoughGold(std::uint32_t gold) const { return m_Gold >= gold; }
|
||||||
void updateExp() { m_ExpChanged = false; }
|
bool HasEnoughExp(std::uint32_t exp) const { return m_Exp >= exp; }
|
||||||
|
|
||||||
std::uint8_t getID() const { return m_ID; }
|
PlayerID GetID() const { return m_ID; }
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace game
|
} // namespace game
|
||||||
|
|||||||
34
include/game/PlayerUpgrades.h
Normal file
34
include/game/PlayerUpgrades.h
Normal file
@@ -0,0 +1,34 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include "Mobs.h"
|
||||||
|
|
||||||
|
namespace td {
|
||||||
|
namespace game {
|
||||||
|
|
||||||
|
class PlayerUpgrades {
|
||||||
|
private:
|
||||||
|
std::uint8_t m_ClickerLevel;
|
||||||
|
std::uint8_t m_GoldPerSecond;
|
||||||
|
std::array<std::uint8_t, static_cast<std::size_t>(MobType::MOB_COUNT)> m_MobsUpgradeLevel;
|
||||||
|
public:
|
||||||
|
static const int MAX_MOB_LEVEL = 5;
|
||||||
|
static const int MAX_CLICKER_LEVEL = 3;
|
||||||
|
|
||||||
|
PlayerUpgrades() : m_ClickerLevel(1), m_GoldPerSecond(5) {}
|
||||||
|
|
||||||
|
std::uint8_t GetClickerLevel() const { return m_ClickerLevel; }
|
||||||
|
std::uint8_t GetMobUpgradeLevel(MobType mob) const { return m_MobsUpgradeLevel.at(static_cast<std::size_t>(mob)); }
|
||||||
|
std::uint8_t GetGoldPerSecond() const { return m_GoldPerSecond; }
|
||||||
|
|
||||||
|
|
||||||
|
void UpgradeMob(MobType mob) {
|
||||||
|
std::uint8_t& mobLevel = m_MobsUpgradeLevel.at(static_cast<std::size_t>(mob));
|
||||||
|
mobLevel = std::min(mobLevel + 1, MAX_MOB_LEVEL);
|
||||||
|
}
|
||||||
|
|
||||||
|
void UpgradeClicker() { m_ClickerLevel = std::min(m_ClickerLevel + 1, MAX_CLICKER_LEVEL); }
|
||||||
|
void SetGoldPerSecond(std::uint8_t goldPerSecond) { m_GoldPerSecond = goldPerSecond; }
|
||||||
|
};
|
||||||
|
|
||||||
|
} // namespace game
|
||||||
|
} // namespace td
|
||||||
@@ -24,13 +24,13 @@ private:
|
|||||||
Direction m_Direction;
|
Direction m_Direction;
|
||||||
public:
|
public:
|
||||||
Spawn() {
|
Spawn() {
|
||||||
setWidth(5);
|
SetWidth(5);
|
||||||
setHeight(5);
|
SetHeight(5);
|
||||||
}
|
}
|
||||||
|
|
||||||
Direction getDirection() const { return m_Direction; }
|
Direction GetDirection() const { return m_Direction; }
|
||||||
|
|
||||||
void setDirection(Direction direction) { m_Direction = direction; }
|
void SetDirection(Direction direction) { m_Direction = direction; }
|
||||||
};
|
};
|
||||||
|
|
||||||
class Team;
|
class Team;
|
||||||
@@ -43,23 +43,23 @@ public:
|
|||||||
static constexpr int CastleMaxLife = 1000;
|
static constexpr int CastleMaxLife = 1000;
|
||||||
|
|
||||||
TeamCastle(const Team* team) : m_Team(team), m_Life(CastleMaxLife) {
|
TeamCastle(const Team* team) : m_Team(team), m_Life(CastleMaxLife) {
|
||||||
setWidth(5);
|
SetWidth(5);
|
||||||
setHeight(5);
|
SetHeight(5);
|
||||||
}
|
}
|
||||||
|
|
||||||
TeamCastle() : TeamCastle(nullptr) {}
|
TeamCastle() : TeamCastle(nullptr) {}
|
||||||
|
|
||||||
float getLife() const { return m_Life; }
|
float GetLife() const { return m_Life; }
|
||||||
|
|
||||||
const Team* getTeam() const { return m_Team; }
|
const Team* GetTeam() const { return m_Team; }
|
||||||
void setTeam(const Team* team) { m_Team = team; }
|
void SetTeam(const Team* team) { m_Team = team; }
|
||||||
|
|
||||||
void setLife(float life) { m_Life = life; }
|
void SetLife(float life) { m_Life = life; }
|
||||||
void damage(float damage) { m_Life = std::max(0.0f, m_Life - damage); }
|
void Damage(float damage) { m_Life = std::max(0.0f, m_Life - damage); }
|
||||||
|
|
||||||
void setShape(utils::shape::Rectangle rect) {
|
void SetShape(utils::shape::Rectangle rect) {
|
||||||
setCenter(rect.getCenter());
|
SetCenter(rect.GetCenter());
|
||||||
setSize(rect.getSize());
|
SetSize(rect.GetSize());
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -72,18 +72,18 @@ private:
|
|||||||
public:
|
public:
|
||||||
Team(TeamColor color);
|
Team(TeamColor color);
|
||||||
|
|
||||||
void addPlayer(Player* newPlayer);
|
void AddPlayer(Player* newPlayer);
|
||||||
void removePlayer(const Player* player);
|
void RemovePlayer(const Player* player);
|
||||||
|
|
||||||
TeamColor getColor() const;
|
TeamColor GetColor() const;
|
||||||
|
|
||||||
const Spawn& getSpawn() const { return m_Spawn; }
|
const Spawn& GetSpawn() const { return m_Spawn; }
|
||||||
Spawn& getSpawn() { return m_Spawn; }
|
Spawn& GetSpawn() { return m_Spawn; }
|
||||||
|
|
||||||
const TeamCastle& getCastle() const { return m_TeamCastle; }
|
const TeamCastle& GetCastle() const { return m_TeamCastle; }
|
||||||
TeamCastle& getCastle() { return m_TeamCastle; }
|
TeamCastle& GetCastle() { return m_TeamCastle; }
|
||||||
|
|
||||||
std::uint8_t getPlayerCount() const;
|
std::uint8_t GetPlayerCount() const;
|
||||||
};
|
};
|
||||||
|
|
||||||
typedef std::array<Team, 2> TeamList;
|
typedef std::array<Team, 2> TeamList;
|
||||||
|
|||||||
@@ -1,6 +1,5 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <cstdint>
|
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <memory>
|
#include <memory>
|
||||||
|
|
||||||
@@ -55,9 +54,9 @@ public:
|
|||||||
m_Range(range) {
|
m_Range(range) {
|
||||||
}
|
}
|
||||||
|
|
||||||
float getDamageRate() const { return m_Rate; }
|
float GetDamageRate() const { return m_Rate; }
|
||||||
float getDamage() const { return m_Damage; }
|
float GetDamage() const { return m_Damage; }
|
||||||
std::uint8_t getRange() const { return m_Range; }
|
std::uint8_t GetRange() const { return m_Range; }
|
||||||
};
|
};
|
||||||
|
|
||||||
class TowerLevel {
|
class TowerLevel {
|
||||||
@@ -70,20 +69,20 @@ public:
|
|||||||
TowerLevel() : m_Level(1), m_Path(TowerPath::Base) {}
|
TowerLevel() : m_Level(1), m_Path(TowerPath::Base) {}
|
||||||
TowerLevel(std::uint8_t level, TowerPath path) : m_Level(level), m_Path(path) {}
|
TowerLevel(std::uint8_t level, TowerPath path) : m_Level(level), m_Path(path) {}
|
||||||
|
|
||||||
std::uint8_t getLevel() const { return m_Level; }
|
std::uint8_t GetLevel() const { return m_Level; }
|
||||||
TowerPath getPath() const { return m_Path; }
|
TowerPath GetPath() const { return m_Path; }
|
||||||
|
|
||||||
void setLevel(std::uint8_t level) { m_Level = level; }
|
void SetLevel(std::uint8_t level) { m_Level = level; }
|
||||||
void setPath(TowerPath path) { m_Path = path; }
|
void SetPath(TowerPath path) { m_Path = path; }
|
||||||
|
|
||||||
// operator to sort maps
|
// operator to sort maps
|
||||||
friend bool operator<(const TowerLevel& level, const TowerLevel& other) {
|
friend bool operator<(const TowerLevel& level, const TowerLevel& other) {
|
||||||
return level.getLevel() + static_cast<std::uint8_t>(level.getPath()) * 4 <
|
return level.GetLevel() + static_cast<std::uint8_t>(level.GetPath()) * 4 <
|
||||||
other.getLevel() + static_cast<std::uint8_t>(other.getPath()) * 4;
|
other.GetLevel() + static_cast<std::uint8_t>(other.GetPath()) * 4;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
const TowerStats* getTowerStats(TowerType type, TowerLevel level);
|
const TowerStats* GetTowerStats(TowerType type, TowerLevel level);
|
||||||
|
|
||||||
typedef std::uint16_t TowerID;
|
typedef std::uint16_t TowerID;
|
||||||
|
|
||||||
@@ -97,36 +96,36 @@ protected:
|
|||||||
utils::CooldownTimer m_Timer;
|
utils::CooldownTimer m_Timer;
|
||||||
public:
|
public:
|
||||||
Tower(TowerID id, TowerType type, std::int32_t x, std::int32_t y, PlayerID builder) : utils::shape::Circle(x + 0.5f, y + 0.5f, 0), m_ID(id), m_Type(type), m_Builder(builder),
|
Tower(TowerID id, TowerType type, std::int32_t x, std::int32_t y, PlayerID builder) : utils::shape::Circle(x + 0.5f, y + 0.5f, 0), m_ID(id), m_Type(type), m_Builder(builder),
|
||||||
m_Timer(getStats()->getDamageRate() * 1000) { // converting seconds to millis
|
m_Timer(GetStats()->GetDamageRate() * 1000) { // converting seconds to millis
|
||||||
setRadius(getStats()->getRange());
|
SetRadius(GetStats()->GetRange());
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual TowerType getType() const = 0;
|
virtual TowerType GetType() const = 0;
|
||||||
virtual TowerSize getSize() const = 0;
|
virtual TowerSize GetSize() const = 0;
|
||||||
virtual void tick(std::uint64_t delta, World* world) = 0;
|
virtual void Tick(std::uint64_t delta, World* world) = 0;
|
||||||
|
|
||||||
void upgrade(std::uint8_t level, TowerPath path) {
|
void Upgrade(std::uint8_t level, TowerPath path) {
|
||||||
m_Level.setLevel(level);
|
m_Level.SetLevel(level);
|
||||||
m_Level.setPath(path);
|
m_Level.SetPath(path);
|
||||||
m_Timer.setCooldown(getStats()->getDamageRate() * 1000); // converting seconds to millis
|
m_Timer.SetCooldown(GetStats()->GetDamageRate() * 1000); // converting seconds to millis
|
||||||
m_Timer.reset();
|
m_Timer.Reset();
|
||||||
setRadius(getStats()->getRange());
|
SetRadius(GetStats()->GetRange());
|
||||||
}
|
}
|
||||||
|
|
||||||
std::uint16_t getID() const { return m_ID; }
|
std::uint16_t GetID() const { return m_ID; }
|
||||||
const TowerLevel& getLevel() const { return m_Level; }
|
const TowerLevel& GetLevel() const { return m_Level; }
|
||||||
const TowerStats* getStats() const { return getTowerStats(m_Type, m_Level); }
|
const TowerStats* GetStats() const { return GetTowerStats(m_Type, m_Level); }
|
||||||
PlayerID getBuilder() const { return m_Builder; }
|
PlayerID GetBuilder() const { return m_Builder; }
|
||||||
|
|
||||||
bool isMobInRange(MobPtr mob);
|
bool IsMobInRange(MobPtr mob);
|
||||||
};
|
};
|
||||||
|
|
||||||
typedef std::shared_ptr<Tower> TowerPtr;
|
typedef std::shared_ptr<Tower> TowerPtr;
|
||||||
|
|
||||||
namespace TowerFactory {
|
namespace TowerFactory {
|
||||||
|
|
||||||
TowerPtr createTower(TowerType type, TowerID id, std::int32_t x, std::int32_t y, PlayerID builder);
|
TowerPtr CreateTower(TowerType type, TowerID id, std::int32_t x, std::int32_t y, PlayerID builder);
|
||||||
std::string getTowerName(TowerType type);
|
std::string GetTowerName(TowerType type);
|
||||||
|
|
||||||
} // namespace TowerFactory
|
} // namespace TowerFactory
|
||||||
|
|
||||||
@@ -137,15 +136,16 @@ 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; }
|
||||||
|
|
||||||
bool isBigTower() const { return m_IsBigTower; }
|
bool IsBigTower() const { return m_IsBigTower; }
|
||||||
};
|
};
|
||||||
|
|
||||||
const TowerInfo& getTowerInfo(TowerType type);
|
const TowerInfo& GetTowerInfo(TowerType type);
|
||||||
|
|
||||||
// ---------- Little Towers ----------
|
// ---------- Little Towers ----------
|
||||||
|
|
||||||
@@ -153,77 +153,77 @@ class LittleTower : public Tower {
|
|||||||
public:
|
public:
|
||||||
LittleTower(TowerID id, TowerType type, std::uint16_t x, std::uint16_t y, PlayerID builder) : Tower(id, type, x, y, builder) {}
|
LittleTower(TowerID id, TowerType type, std::uint16_t x, std::uint16_t y, PlayerID builder) : Tower(id, type, x, y, builder) {}
|
||||||
|
|
||||||
virtual TowerSize getSize() const { return TowerSize::Little; }
|
virtual TowerSize GetSize() const { return TowerSize::Little; }
|
||||||
|
|
||||||
virtual TowerType getType() const = 0;
|
virtual TowerType GetType() const = 0;
|
||||||
virtual void tick(std::uint64_t delta, World* world) = 0;
|
virtual void Tick(std::uint64_t delta, World* world) = 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
class ArcherTower : public LittleTower {
|
class ArcherTower : public LittleTower {
|
||||||
public:
|
public:
|
||||||
ArcherTower(TowerID id, std::uint16_t x, std::uint16_t y, PlayerID builder) : LittleTower(id, getType(), x, y, builder) {}
|
ArcherTower(TowerID id, std::uint16_t x, std::uint16_t y, PlayerID builder) : LittleTower(id, GetType(), x, y, builder) {}
|
||||||
|
|
||||||
constexpr static float ExplosionRadius = 1.5f;
|
constexpr static float ExplosionRadius = 1.5f;
|
||||||
constexpr static float FireDurationSec = 10.0f;
|
constexpr static float FireDurationSec = 10.0f;
|
||||||
|
|
||||||
virtual TowerType getType() const { return TowerType::Archer; }
|
virtual TowerType GetType() const { return TowerType::Archer; }
|
||||||
virtual void tick(std::uint64_t delta, World* world);
|
virtual void Tick(std::uint64_t delta, World* world);
|
||||||
};
|
};
|
||||||
|
|
||||||
class IceTower : public LittleTower {
|
class IceTower : public LittleTower {
|
||||||
public:
|
public:
|
||||||
IceTower(TowerID id, std::uint16_t x, std::uint16_t y, PlayerID builder) : LittleTower(id, getType(), x, y, builder) {}
|
IceTower(TowerID id, std::uint16_t x, std::uint16_t y, PlayerID builder) : LittleTower(id, GetType(), x, y, builder) {}
|
||||||
|
|
||||||
virtual TowerType getType() const { return TowerType::Ice; }
|
virtual TowerType GetType() const { return TowerType::Ice; }
|
||||||
virtual void tick(std::uint64_t delta, World* world);
|
virtual void Tick(std::uint64_t delta, World* world);
|
||||||
};
|
};
|
||||||
|
|
||||||
class MageTower : public LittleTower {
|
class MageTower : public LittleTower {
|
||||||
public:
|
public:
|
||||||
MageTower(TowerID id, std::uint16_t x, std::uint16_t y, PlayerID builder) : LittleTower(id, getType(), x, y, builder) {}
|
MageTower(TowerID id, std::uint16_t x, std::uint16_t y, PlayerID builder) : LittleTower(id, GetType(), x, y, builder) {}
|
||||||
|
|
||||||
virtual TowerType getType() const { return TowerType::Mage; }
|
virtual TowerType GetType() const { return TowerType::Mage; }
|
||||||
virtual void tick(std::uint64_t delta, World* world);
|
virtual void Tick(std::uint64_t delta, World* world);
|
||||||
};
|
};
|
||||||
|
|
||||||
class PoisonTower : public LittleTower {
|
class PoisonTower : public LittleTower {
|
||||||
public:
|
public:
|
||||||
PoisonTower(TowerID id, std::uint16_t x, std::uint16_t y, PlayerID builder) : LittleTower(id, getType(), x, y, builder) {}
|
PoisonTower(TowerID id, std::uint16_t x, std::uint16_t y, PlayerID builder) : LittleTower(id, GetType(), x, y, builder) {}
|
||||||
|
|
||||||
virtual TowerType getType() const { return TowerType::Poison; }
|
virtual TowerType GetType() const { return TowerType::Poison; }
|
||||||
virtual void tick(std::uint64_t delta, World* world);
|
virtual void Tick(std::uint64_t delta, World* world);
|
||||||
};
|
};
|
||||||
|
|
||||||
class QuakeTower : public LittleTower {
|
class QuakeTower : public LittleTower {
|
||||||
public:
|
public:
|
||||||
QuakeTower(TowerID id, std::uint16_t x, std::uint16_t y, PlayerID builder) : LittleTower(id, getType(), x, y, builder) {}
|
QuakeTower(TowerID id, std::uint16_t x, std::uint16_t y, PlayerID builder) : LittleTower(id, GetType(), x, y, builder) {}
|
||||||
|
|
||||||
virtual TowerType getType() const { return TowerType::Quake; }
|
virtual TowerType GetType() const { return TowerType::Quake; }
|
||||||
virtual void tick(std::uint64_t delta, World* world);
|
virtual void Tick(std::uint64_t delta, World* world);
|
||||||
};
|
};
|
||||||
|
|
||||||
class ArtilleryTower : public LittleTower {
|
class ArtilleryTower : public LittleTower {
|
||||||
public:
|
public:
|
||||||
ArtilleryTower(TowerID id, std::uint16_t x, std::uint16_t y, PlayerID builder) : LittleTower(id, getType(), x, y, builder) {}
|
ArtilleryTower(TowerID id, std::uint16_t x, std::uint16_t y, PlayerID builder) : LittleTower(id, GetType(), x, y, builder) {}
|
||||||
|
|
||||||
virtual TowerType getType() const { return TowerType::Artillery; }
|
virtual TowerType GetType() const { return TowerType::Artillery; }
|
||||||
virtual void tick(std::uint64_t delta, World* world);
|
virtual void Tick(std::uint64_t delta, World* world);
|
||||||
};
|
};
|
||||||
|
|
||||||
class SorcererTower : public LittleTower {
|
class SorcererTower : public LittleTower {
|
||||||
public:
|
public:
|
||||||
SorcererTower(TowerID id, std::uint16_t x, std::uint16_t y, PlayerID builder) : LittleTower(id, getType(), x, y, builder) {}
|
SorcererTower(TowerID id, std::uint16_t x, std::uint16_t y, PlayerID builder) : LittleTower(id, GetType(), x, y, builder) {}
|
||||||
|
|
||||||
virtual TowerType getType() const { return TowerType::Sorcerer; }
|
virtual TowerType GetType() const { return TowerType::Sorcerer; }
|
||||||
virtual void tick(std::uint64_t delta, World* world);
|
virtual void Tick(std::uint64_t delta, World* world);
|
||||||
};
|
};
|
||||||
|
|
||||||
class ZeusTower : public LittleTower {
|
class ZeusTower : public LittleTower {
|
||||||
public:
|
public:
|
||||||
ZeusTower(TowerID id, std::uint16_t x, std::uint16_t y, PlayerID builder) : LittleTower(id, getType(), x, y, builder) {}
|
ZeusTower(TowerID id, std::uint16_t x, std::uint16_t y, PlayerID builder) : LittleTower(id, GetType(), x, y, builder) {}
|
||||||
|
|
||||||
virtual TowerType getType() const { return TowerType::Zeus; }
|
virtual TowerType GetType() const { return TowerType::Zeus; }
|
||||||
virtual void tick(std::uint64_t delta, World* world);
|
virtual void Tick(std::uint64_t delta, World* world);
|
||||||
};
|
};
|
||||||
|
|
||||||
// ---------- Big Towers ----------
|
// ---------- Big Towers ----------
|
||||||
@@ -232,34 +232,34 @@ class BigTower : public Tower {
|
|||||||
public:
|
public:
|
||||||
BigTower(TowerID id, TowerType type, std::uint16_t x, std::uint16_t y, PlayerID builder) : Tower(id, type, x, y, builder) {}
|
BigTower(TowerID id, TowerType type, std::uint16_t x, std::uint16_t y, PlayerID builder) : Tower(id, type, x, y, builder) {}
|
||||||
|
|
||||||
virtual TowerSize getSize() const { return TowerSize::Big; }
|
virtual TowerSize GetSize() const { return TowerSize::Big; }
|
||||||
|
|
||||||
virtual TowerType getType() const = 0;
|
virtual TowerType GetType() const = 0;
|
||||||
virtual void tick(std::uint64_t delta, World* world) = 0;
|
virtual void Tick(std::uint64_t delta, World* world) = 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
class TurretTower : public BigTower {
|
class TurretTower : public BigTower {
|
||||||
public:
|
public:
|
||||||
TurretTower(TowerID id, std::uint16_t x, std::uint16_t y, PlayerID builder) : BigTower(id, getType(), x, y, builder) {}
|
TurretTower(TowerID id, std::uint16_t x, std::uint16_t y, PlayerID builder) : BigTower(id, GetType(), x, y, builder) {}
|
||||||
|
|
||||||
virtual TowerType getType() const { return TowerType::Turret; }
|
virtual TowerType GetType() const { return TowerType::Turret; }
|
||||||
virtual void tick(std::uint64_t delta, World* world);
|
virtual void Tick(std::uint64_t delta, World* world);
|
||||||
};
|
};
|
||||||
|
|
||||||
class NecromancerTower : public BigTower {
|
class NecromancerTower : public BigTower {
|
||||||
public:
|
public:
|
||||||
NecromancerTower(TowerID id, std::uint16_t x, std::uint16_t y, PlayerID builder) : BigTower(id, getType(), x, y, builder) {}
|
NecromancerTower(TowerID id, std::uint16_t x, std::uint16_t y, PlayerID builder) : BigTower(id, GetType(), x, y, builder) {}
|
||||||
|
|
||||||
virtual TowerType getType() const { return TowerType::Necromancer; }
|
virtual TowerType GetType() const { return TowerType::Necromancer; }
|
||||||
virtual void tick(std::uint64_t delta, World* world);
|
virtual void Tick(std::uint64_t delta, World* world);
|
||||||
};
|
};
|
||||||
|
|
||||||
class LeachTower : public BigTower {
|
class LeachTower : public BigTower {
|
||||||
public:
|
public:
|
||||||
LeachTower(TowerID id, std::uint16_t x, std::uint16_t y, PlayerID builder) : BigTower(id, getType(), x, y, builder) {}
|
LeachTower(TowerID id, std::uint16_t x, std::uint16_t y, PlayerID builder) : BigTower(id, GetType(), x, y, builder) {}
|
||||||
|
|
||||||
virtual TowerType getType() const { return TowerType::Leach; }
|
virtual TowerType GetType() const { return TowerType::Leach; }
|
||||||
virtual void tick(std::uint64_t delta, World* world);
|
virtual void Tick(std::uint64_t delta, World* world);
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace game
|
} // namespace game
|
||||||
|
|||||||
@@ -2,6 +2,9 @@
|
|||||||
|
|
||||||
#include <cstdint>
|
#include <cstdint>
|
||||||
|
|
||||||
|
// include Log for every files
|
||||||
|
#include "misc/Log.h"
|
||||||
|
|
||||||
namespace td {
|
namespace td {
|
||||||
namespace game {
|
namespace game {
|
||||||
|
|
||||||
|
|||||||
@@ -4,7 +4,6 @@
|
|||||||
#include <vector>
|
#include <vector>
|
||||||
#include <map>
|
#include <map>
|
||||||
#include <unordered_map>
|
#include <unordered_map>
|
||||||
#include <glm/glm.hpp>
|
|
||||||
#include <array>
|
#include <array>
|
||||||
|
|
||||||
#include "Mobs.h"
|
#include "Mobs.h"
|
||||||
@@ -12,23 +11,30 @@
|
|||||||
|
|
||||||
namespace td {
|
namespace td {
|
||||||
namespace game {
|
namespace game {
|
||||||
typedef std::pair<std::int16_t, std::int16_t> ChunkCoord;
|
|
||||||
|
struct ChunkCoord {
|
||||||
|
std::int16_t x, y;
|
||||||
|
|
||||||
|
friend bool operator==(const td::game::ChunkCoord& first, const td::game::ChunkCoord& other) {
|
||||||
|
return first.x == other.x && first.y == other.y;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
namespace std {
|
namespace std {
|
||||||
template <>
|
template <>
|
||||||
struct hash<td::game::ChunkCoord> {
|
struct hash<td::game::ChunkCoord> {
|
||||||
std::size_t operator()(const td::game::ChunkCoord& key) const {
|
std::size_t operator()(const td::game::ChunkCoord& key) const noexcept {
|
||||||
// Compute individual hash values for first,
|
return std::hash<std::int16_t>()(key.x << 16 | key.y);
|
||||||
// second and third and combine them using XOR
|
|
||||||
// and bit shifting:
|
|
||||||
return ((std::hash<std::int16_t>()(key.first) ^ (std::hash<std::int16_t>()(key.second) << 1)) >> 1);
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
namespace td {
|
namespace td {
|
||||||
|
|
||||||
namespace protocol {
|
namespace protocol {
|
||||||
|
|
||||||
class WorldBeginDataPacket;
|
class WorldBeginDataPacket;
|
||||||
@@ -52,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 };
|
||||||
|
|
||||||
@@ -64,26 +66,26 @@ static constexpr Color GREEN{ 0, 255, 0 };
|
|||||||
static constexpr Color BLUE{ 0, 0, 255 };
|
static constexpr Color BLUE{ 0, 0, 255 };
|
||||||
|
|
||||||
struct Tile {
|
struct Tile {
|
||||||
virtual TileType getType() const = 0;
|
virtual TileType GetType() const = 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct TowerTile : Tile {
|
struct TowerTile : Tile {
|
||||||
std::uint8_t color_palette_ref;
|
std::uint8_t color_palette_ref;
|
||||||
TeamColor team_owner;
|
TeamColor team_owner;
|
||||||
|
|
||||||
virtual TileType getType() const { return TileType::Tower; }
|
virtual TileType GetType() const { return TileType::Tower; }
|
||||||
};
|
};
|
||||||
|
|
||||||
struct WalkableTile : Tile {
|
struct WalkableTile : Tile {
|
||||||
Direction direction;
|
Direction direction;
|
||||||
|
|
||||||
virtual TileType getType() const { return TileType::Walk; }
|
virtual TileType GetType() const { return TileType::Walk; }
|
||||||
};
|
};
|
||||||
|
|
||||||
struct DecorationTile : Tile {
|
struct DecorationTile : Tile {
|
||||||
std::uint16_t color_palette_ref;
|
std::uint16_t color_palette_ref;
|
||||||
|
|
||||||
virtual TileType getType() const { return TileType::Decoration; }
|
virtual TileType GetType() const { return TileType::Decoration; }
|
||||||
};
|
};
|
||||||
|
|
||||||
typedef std::shared_ptr<Tile> TilePtr;
|
typedef std::shared_ptr<Tile> TilePtr;
|
||||||
@@ -91,17 +93,18 @@ typedef std::vector<std::uint16_t> ChunkPalette;
|
|||||||
|
|
||||||
typedef std::shared_ptr<WalkableTile> WalkableTilePtr;
|
typedef std::shared_ptr<WalkableTile> WalkableTilePtr;
|
||||||
|
|
||||||
typedef std::array<std::uint16_t, 32 * 32> ChunkData;
|
|
||||||
typedef std::uint32_t TileIndex;
|
typedef std::uint32_t TileIndex;
|
||||||
|
|
||||||
//32 x 32 area
|
//32 x 32 area
|
||||||
struct Chunk {
|
struct Chunk {
|
||||||
enum { ChunkWidth = 32, ChunkHeight = 32, ChunkSize = ChunkWidth * ChunkHeight };
|
enum { ChunkWidth = 32, ChunkHeight = 32, ChunkSize = ChunkWidth * ChunkHeight };
|
||||||
|
typedef std::array<std::uint16_t, ChunkSize> ChunkData;
|
||||||
|
|
||||||
// stores index of tile palette
|
// stores index of tile palette
|
||||||
ChunkData tiles{ 0 };
|
ChunkData tiles{ 0 };
|
||||||
ChunkPalette palette;
|
ChunkPalette palette;
|
||||||
|
|
||||||
TileIndex getTileIndex(std::uint16_t tileNumber) const {
|
TileIndex GetTileIndex(std::uint16_t tileNumber) const {
|
||||||
TileIndex chunkPaletteIndex = tiles.at(tileNumber);
|
TileIndex chunkPaletteIndex = tiles.at(tileNumber);
|
||||||
if (chunkPaletteIndex == 0) // index 0 means empty tile index 1 = first tile
|
if (chunkPaletteIndex == 0) // index 0 means empty tile index 1 = first tile
|
||||||
return 0;
|
return 0;
|
||||||
@@ -160,83 +163,82 @@ protected:
|
|||||||
public:
|
public:
|
||||||
World(Game* game);
|
World(Game* game);
|
||||||
|
|
||||||
bool loadMap(const protocol::WorldBeginDataPacket* worldHeader);
|
bool LoadMap(const protocol::WorldBeginDataPacket* worldHeader);
|
||||||
bool loadMap(const protocol::WorldDataPacket* worldData);
|
bool LoadMap(const protocol::WorldDataPacket* worldData);
|
||||||
|
|
||||||
bool loadMapFromFile(const std::string& fileName);
|
bool LoadMapFromFile(const std::string& fileName);
|
||||||
bool saveMap(const std::string& fileName) const;
|
bool SaveMap(const std::string& fileName) const;
|
||||||
|
|
||||||
void tick(std::uint64_t delta);
|
void Tick(std::uint64_t delta);
|
||||||
|
|
||||||
void spawnMobAt(MobID id, MobType type, std::uint8_t level, PlayerID sender, float x, float y, Direction dir);
|
void SpawnMobAt(MobID id, MobType type, std::uint8_t level, PlayerID sender, float x, float y, Direction dir);
|
||||||
|
|
||||||
TowerPtr placeTowerAt(TowerID id, TowerType type, std::int32_t x, std::int32_t y, PlayerID builder);
|
TowerPtr PlaceTowerAt(TowerID id, TowerType type, std::int32_t x, std::int32_t y, PlayerID builder);
|
||||||
TowerPtr removeTower(TowerID id);
|
TowerPtr RemoveTower(TowerID id);
|
||||||
|
|
||||||
TilePtr getTile(std::int32_t x, std::int32_t y) const;
|
TilePtr GetTile(std::int32_t x, std::int32_t y) const;
|
||||||
|
|
||||||
const TowerTileColorPalette& getTowerTileColorPalette() const { return m_TowerPlacePalette; }
|
const TowerTileColorPalette& GetTowerTileColorPalette() const { return m_TowerPlacePalette; }
|
||||||
const Color& getWalkableTileColor() const { return m_WalkablePalette; }
|
const Color& GetWalkableTileColor() const { return m_WalkablePalette; }
|
||||||
const std::vector<Color>& getDecorationPalette() const { return m_DecorationPalette; }
|
const std::vector<Color>& GetDecorationPalette() const { return m_DecorationPalette; }
|
||||||
const Color& getBackgroundColor() const { return m_Background; }
|
const Color& GetBackgroundColor() const { return m_Background; }
|
||||||
|
|
||||||
const TilePalette& getTilePalette() const { return m_TilePalette; }
|
const TilePalette& GetTilePalette() const { return m_TilePalette; }
|
||||||
|
|
||||||
TilePtr getTilePtr(TileIndex index) const {
|
TilePtr GetTilePtr(TileIndex index) const {
|
||||||
if (index == 0)
|
if (index == 0)
|
||||||
return nullptr;
|
return nullptr;
|
||||||
return m_TilePalette.at(index - 1);
|
return m_TilePalette.at(index - 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool CanPlaceLittleTower(const glm::vec2& worldPos, PlayerID player) const;
|
bool CanPlaceLittleTower(const Vec2f& worldPos, PlayerID player) const;
|
||||||
bool CanPlaceBigTower(const glm::vec2& worldPos, PlayerID player) const;
|
bool CanPlaceBigTower(const Vec2f& worldPos, PlayerID player) const;
|
||||||
|
|
||||||
TowerPtr getTower(const glm::vec2& position) const; // returns null if no tower is here
|
TowerPtr GetTower(const Vec2f& position) const; // returns null if no tower is here
|
||||||
|
|
||||||
const std::unordered_map<ChunkCoord, ChunkPtr>& getChunks() const { return m_Chunks; }
|
const std::unordered_map<ChunkCoord, ChunkPtr>& GetChunks() const { return m_Chunks; }
|
||||||
|
|
||||||
const Color& getSpawnColor(TeamColor color) const { return m_SpawnColorPalette[(std::size_t)color]; }
|
const Color& GetSpawnColor(TeamColor color) const { return m_SpawnColorPalette[static_cast<std::size_t>(color)]; }
|
||||||
const SpawnColorPalette& getSpawnColors() const { return m_SpawnColorPalette; }
|
const SpawnColorPalette& GetSpawnColors() const { return m_SpawnColorPalette; }
|
||||||
|
|
||||||
const MobList& getMobList() const { return m_Mobs; }
|
const MobList& GetMobList() const { return m_Mobs; }
|
||||||
MobList& getMobList() { return m_Mobs; }
|
MobList& GetMobList() { return m_Mobs; }
|
||||||
|
|
||||||
const Color* getTileColor(TilePtr tile) const;
|
const Color* GetTileColor(TilePtr tile) const;
|
||||||
|
|
||||||
Team& getRedTeam();
|
Team& GetRedTeam();
|
||||||
const Team& getRedTeam() const;
|
const Team& GetRedTeam() const;
|
||||||
|
|
||||||
Team& getBlueTeam();
|
Team& GetBlueTeam();
|
||||||
const Team& getBlueTeam() const;
|
const Team& GetBlueTeam() const;
|
||||||
|
|
||||||
Team& getTeam(TeamColor team);
|
Team& GetTeam(TeamColor team);
|
||||||
const Team& getTeam(TeamColor team) const;
|
const Team& GetTeam(TeamColor team) const;
|
||||||
|
|
||||||
const TeamList& getTeams() const;
|
const TeamList& GetTeams() const;
|
||||||
|
|
||||||
const TowerList& getTowers() const { return m_Towers; };
|
const TowerList& GetTowers() const { return m_Towers; }
|
||||||
TowerPtr getTowerById(TowerID tower);
|
TowerPtr GetTowerById(TowerID tower);
|
||||||
|
|
||||||
const Player* getPlayerById(PlayerID id) const;
|
const Player* GetPlayerById(PlayerID id) const;
|
||||||
|
|
||||||
WorldNotifier& getWorldNotifier() { return m_WorldNotifier; }
|
WorldNotifier& GetWorldNotifier() { return m_WorldNotifier; }
|
||||||
MobNotifier& getMobNotifier() { return m_MobNotifier; }
|
MobNotifier& GetMobNotifier() { return m_MobNotifier; }
|
||||||
|
|
||||||
// WorldListener
|
// WorldListener
|
||||||
|
|
||||||
virtual void OnArcherTowerShot(MobPtr target, ArcherTower* shooter);
|
virtual void OnArcherTowerShot(MobPtr target, ArcherTower* shooter) override;
|
||||||
|
virtual void OnArrowShot(MobPtr target, bool fire, Tower* shooter) override;
|
||||||
virtual void OnArrowShot(MobPtr target, bool fire, Tower* shooter);
|
virtual void OnExplosion(utils::shape::Circle explosion, float centerDamage, Tower* shooter) override;
|
||||||
virtual void OnExplosion(utils::shape::Circle explosion, float centerDamage, Tower* shooter);
|
|
||||||
|
|
||||||
// MobListener
|
// MobListener
|
||||||
|
|
||||||
virtual void OnMobDamage(Mob* target, float damage, Tower* source);
|
virtual void OnMobDamage(Mob* target, float damage, Tower* source) override;
|
||||||
virtual void OnMobCastleDamage(Mob* damager, TeamCastle* enemyCastle, float damage);
|
virtual void OnMobCastleDamage(Mob* damager, TeamCastle* enemyCastle, float damage) override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void tickMobs(std::uint64_t delta);
|
void TickMobs(std::uint64_t delta);
|
||||||
void cleanDeadMobs();
|
void CleanDeadMobs();
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace game
|
} // namespace game
|
||||||
|
|||||||
@@ -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"
|
||||||
|
|
||||||
@@ -24,29 +25,31 @@ private:
|
|||||||
public:
|
public:
|
||||||
Client(render::Renderer* renderer) : m_Renderer(renderer), m_Game(std::make_unique<ClientGame>(this)), m_Connected(false) {}
|
Client(render::Renderer* renderer) : m_Renderer(renderer), m_Game(std::make_unique<ClientGame>(this)), m_Connected(false) {}
|
||||||
|
|
||||||
const ClientGame& getGame() const { return *m_Game; }
|
const ClientGame& GetGame() const { return *m_Game; }
|
||||||
const ClientConnexion& getConnexion() const { return m_Connexion; }
|
const ClientConnexion& GetConnexion() const { return m_Connexion; }
|
||||||
render::Renderer* getRenderer() const { return m_Renderer; }
|
render::Renderer* GetRenderer() const { return m_Renderer; }
|
||||||
|
|
||||||
ClientGame& getGame() { return *m_Game; }
|
ClientGame& GetGame() { return *m_Game; }
|
||||||
ClientConnexion& getConnexion() { return m_Connexion; }
|
ClientConnexion& GetConnexion() { return m_Connexion; }
|
||||||
|
|
||||||
void tick(std::uint64_t delta);
|
const game::Player* GetPlayer() { return m_Game->GetPlayer(); }
|
||||||
|
|
||||||
void render();
|
void Tick(std::uint64_t delta);
|
||||||
|
|
||||||
bool connect(const network::IPAddresses& addresses, std::uint16_t port);
|
void Render();
|
||||||
void closeConnection();
|
|
||||||
|
|
||||||
bool isConnected() const { return m_Connexion.getSocketStatus() == network::Socket::Connected; }
|
bool Connect(const network::IPAddresses& addresses, std::uint16_t port);
|
||||||
|
void CloseConnection();
|
||||||
|
|
||||||
void selectTeam(game::TeamColor team);
|
bool IsConnected() const { return m_Connexion.GetSocketStatus() == network::Socket::Connected; }
|
||||||
void sendMobs(const std::vector<protocol::MobSend>& mobSends);
|
|
||||||
void placeTower(game::TowerType type, const glm::vec2& position);
|
void SelectTeam(game::TeamColor team);
|
||||||
void upgradeTower(game::TowerID tower, game::TowerLevel level);
|
void SendMobs(const std::vector<protocol::MobSend>& mobSends);
|
||||||
void removeTower(game::TowerID tower);
|
void PlaceTower(game::TowerType type, const Vec2f& position);
|
||||||
|
void UpgradeTower(game::TowerID tower, game::TowerLevel level);
|
||||||
|
void RemoveTower(game::TowerID tower);
|
||||||
private:
|
private:
|
||||||
void reset();
|
void Reset();
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace client
|
} // namespace client
|
||||||
|
|||||||
@@ -12,25 +12,27 @@ 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();
|
||||||
|
|
||||||
virtual bool updateSocket();
|
virtual bool UpdateSocket();
|
||||||
|
|
||||||
virtual void HandlePacket(const protocol::KeepAlivePacket* packet);
|
virtual void HandlePacket(const protocol::KeepAlivePacket* packet) override;
|
||||||
virtual void HandlePacket(const protocol::ConnexionInfoPacket* packet);
|
virtual void HandlePacket(const protocol::ConnexionInfoPacket* packet) override;
|
||||||
virtual void HandlePacket(const protocol::DisconnectPacket* packet);
|
virtual void HandlePacket(const protocol::DisconnectPacket* packet) override;
|
||||||
virtual void HandlePacket(const protocol::ServerTpsPacket* packet);
|
virtual void HandlePacket(const protocol::ServerTpsPacket* packet) override;
|
||||||
|
|
||||||
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; }
|
||||||
int getServerPing() const { return m_Ping; }
|
float GetServerMSPT() const { return m_ServerMSPT; }
|
||||||
|
int GetServerPing() const { return m_Ping; }
|
||||||
|
|
||||||
REMOVE_COPY(ClientConnexion);
|
REMOVE_COPY(ClientConnexion);
|
||||||
private:
|
private:
|
||||||
void registerHandlers();
|
void RegisterHandlers();
|
||||||
void login();
|
void Login();
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace client
|
} // namespace client
|
||||||
|
|||||||
@@ -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;
|
||||||
@@ -27,28 +27,29 @@ public:
|
|||||||
ClientGame(Client* client);
|
ClientGame(Client* client);
|
||||||
virtual ~ClientGame();
|
virtual ~ClientGame();
|
||||||
|
|
||||||
virtual void tick(std::uint64_t delta);
|
virtual void Tick(std::uint64_t delta);
|
||||||
|
|
||||||
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; }
|
||||||
|
|
||||||
render::Renderer* getRenderer() const { return m_Renderer; }
|
render::Renderer* GetRenderer() const { return m_Renderer; }
|
||||||
WorldClient& getWorldClient() { return m_WorldClient; }
|
WorldClient& GetWorldClient() { return m_WorldClient; }
|
||||||
|
|
||||||
virtual void HandlePacket(const protocol::ConnexionInfoPacket* packet);
|
virtual void HandlePacket(const protocol::ConnexionInfoPacket* packet) override;
|
||||||
virtual void HandlePacket(const protocol::PlayerJoinPacket* packet);
|
virtual void HandlePacket(const protocol::PlayerJoinPacket* packet) override;
|
||||||
virtual void HandlePacket(const protocol::PlayerLeavePacket* packet);
|
virtual void HandlePacket(const protocol::PlayerLeavePacket* packet) override;
|
||||||
virtual void HandlePacket(const protocol::PlayerListPacket* packet);
|
virtual void HandlePacket(const protocol::PlayerListPacket* packet) override;
|
||||||
virtual void HandlePacket(const protocol::UpdatePlayerTeamPacket* packet);
|
virtual void HandlePacket(const protocol::UpdatePlayerTeamPacket* packet) override;
|
||||||
virtual void HandlePacket(const protocol::UpdateGameStatePacket* packet);
|
virtual void HandlePacket(const protocol::UpdateGameStatePacket* packet) override;
|
||||||
virtual void HandlePacket(const protocol::UpdateLobbyTimePacket* packet);
|
virtual void HandlePacket(const protocol::UpdateLobbyTimePacket* packet) override;
|
||||||
virtual void HandlePacket(const protocol::UpdateMoneyPacket* packet);
|
virtual void HandlePacket(const protocol::UpdateMoneyPacket* packet) override;
|
||||||
virtual void HandlePacket(const protocol::DisconnectPacket* packet);
|
virtual void HandlePacket(const protocol::UpdateExpPacket* packet) override;
|
||||||
virtual void HandlePacket(const protocol::WorldDataPacket* packet);
|
virtual void HandlePacket(const protocol::DisconnectPacket* packet) override;
|
||||||
|
virtual void HandlePacket(const protocol::WorldDataPacket* packet) override;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -14,14 +14,14 @@ private:
|
|||||||
public:
|
public:
|
||||||
WorldClient(ClientGame* game);
|
WorldClient(ClientGame* game);
|
||||||
|
|
||||||
virtual void HandlePacket(const protocol::WorldBeginDataPacket* packet);
|
virtual void HandlePacket(const protocol::WorldBeginDataPacket* packet) override;
|
||||||
virtual void HandlePacket(const protocol::WorldDataPacket* packet);
|
virtual void HandlePacket(const protocol::WorldDataPacket* packet) override;
|
||||||
virtual void HandlePacket(const protocol::SpawnMobPacket* packet);
|
virtual void HandlePacket(const protocol::SpawnMobPacket* packet) override;
|
||||||
virtual void HandlePacket(const protocol::UpgradeTowerPacket* packet);
|
virtual void HandlePacket(const protocol::UpgradeTowerPacket* packet) override;
|
||||||
virtual void HandlePacket(const protocol::WorldAddTowerPacket* packet);
|
virtual void HandlePacket(const protocol::WorldAddTowerPacket* packet) override;
|
||||||
virtual void HandlePacket(const protocol::RemoveTowerPacket* packet);
|
virtual void HandlePacket(const protocol::RemoveTowerPacket* packet) override;
|
||||||
virtual void HandlePacket(const protocol::UpdateMobStatesPacket* packet);
|
virtual void HandlePacket(const protocol::UpdateMobStatesPacket* packet) override;
|
||||||
virtual void HandlePacket(const protocol::UpdateCastleLifePacket* packet);
|
virtual void HandlePacket(const protocol::UpdateCastleLifePacket* packet) override;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -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,9 +22,9 @@ public:
|
|||||||
void OnPlayerJoin(std::uint8_t playerID);
|
void OnPlayerJoin(std::uint8_t playerID);
|
||||||
void OnPlayerLeave(std::uint8_t playerID);
|
void OnPlayerLeave(std::uint8_t playerID);
|
||||||
|
|
||||||
void sendTimeRemaining();
|
void SendTimeRemaining();
|
||||||
|
|
||||||
void tick();
|
void Tick();
|
||||||
|
|
||||||
//static constexpr int LobbyWaitingTime = 2 * 60 * 1000; // in millis
|
//static constexpr int LobbyWaitingTime = 2 * 60 * 1000; // in millis
|
||||||
static constexpr int LobbyWaitingTime = 5 * 1000; // in millis
|
static constexpr int LobbyWaitingTime = 5 * 1000; // in millis
|
||||||
|
|||||||
@@ -1,6 +1,5 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <cstdint>
|
|
||||||
#include <map>
|
#include <map>
|
||||||
#include <thread>
|
#include <thread>
|
||||||
|
|
||||||
@@ -23,30 +22,34 @@ 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:
|
||||||
TickCounter() {}
|
TickCounter() {}
|
||||||
|
|
||||||
void reset() {
|
void Reset() {
|
||||||
m_TPS = SERVER_TPS;
|
m_TPS = SERVER_TPS;
|
||||||
m_LastTPSTime = utils::getTime();
|
m_LastTPSTime = utils::GetTime();
|
||||||
m_TickCount = 0;
|
m_TickCount = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool update() { // return true when tps is updated
|
bool Update() { // return true when tps is updated
|
||||||
m_TickCount++;
|
m_TickCount++;
|
||||||
if (m_TickCount >= SERVER_TPS) {
|
if (m_TickCount >= SERVER_TPS) {
|
||||||
std::uint64_t timeElapsedSinceLast20Ticks = td::utils::getTime() - m_LastTPSTime;
|
std::uint64_t timeElapsedSinceLast20Ticks = td::utils::GetTime() - m_LastTPSTime;
|
||||||
m_TPS = (float)SERVER_TPS / (float)(timeElapsedSinceLast20Ticks / 1000.0f);
|
m_TPS = static_cast<float>(SERVER_TPS) / static_cast<float>(timeElapsedSinceLast20Ticks / 1000.0f);
|
||||||
m_TickCount = 0;
|
m_TickCount = 0;
|
||||||
m_LastTPSTime = td::utils::getTime();
|
m_LastTPSTime = td::utils::GetTime();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
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 {
|
||||||
@@ -63,36 +66,36 @@ public:
|
|||||||
Server(const std::string& worldFilePath);
|
Server(const std::string& worldFilePath);
|
||||||
virtual ~Server();
|
virtual ~Server();
|
||||||
|
|
||||||
bool start(std::uint16_t port);
|
bool Start(std::uint16_t port);
|
||||||
void stop(); // force the server to stop
|
void Stop(); // force the server to stop
|
||||||
void close(); // at the end of a game
|
void Close(); // at the end of a game
|
||||||
|
|
||||||
void removeConnexion(std::uint8_t connexionID);
|
void RemoveConnexion(std::uint8_t connexionID);
|
||||||
|
|
||||||
void broadcastPacket(const protocol::Packet* packet);
|
void BroadcastPacket(const protocol::Packet* packet);
|
||||||
|
|
||||||
float getTPS() const { return m_TickCounter.getTPS(); }
|
float GetTPS() const { return m_TickCounter.GetTPS(); }
|
||||||
|
|
||||||
bool isRunning() { return m_ServerRunning; }
|
bool IsRunning() { return m_ServerRunning; }
|
||||||
|
|
||||||
const ServerGame& getGame() const { return m_Game; }
|
const ServerGame& GetGame() const { return m_Game; }
|
||||||
ServerGame& getGame() { return m_Game; }
|
ServerGame& GetGame() { return m_Game; }
|
||||||
|
|
||||||
const Lobby& getLobby() const { return m_Lobby; }
|
const Lobby& GetLobby() const { return m_Lobby; }
|
||||||
const ConnexionMap& getConnexions() const { return m_Connections; }
|
const ConnexionMap& GetConnexions() const { return m_Connections; }
|
||||||
ConnexionMap& getConnexions() { return m_Connections; }
|
ConnexionMap& GetConnexions() { return m_Connections; }
|
||||||
|
|
||||||
const game::PlayerList& getPlayers() const { return m_Game.getPlayers(); }
|
const game::PlayerList& GetPlayers() const { return m_Game.GetPlayers(); }
|
||||||
game::PlayerList& getPlayers() { return m_Game.getPlayers(); }
|
game::PlayerList& GetPlayers() { return m_Game.GetPlayers(); }
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void accept();
|
void Accept();
|
||||||
void updateSockets();
|
void UpdateSockets();
|
||||||
|
|
||||||
void clean();
|
void Clean();
|
||||||
void startThread();
|
void StartThread();
|
||||||
void stopThread();
|
void StopThread();
|
||||||
void tick(std::uint64_t delta);
|
void Tick(std::uint64_t delta);
|
||||||
|
|
||||||
void OnPlayerJoin(std::uint8_t id);
|
void OnPlayerJoin(std::uint8_t id);
|
||||||
void OnPlayerLeave(std::uint8_t id);
|
void OnPlayerLeave(std::uint8_t id);
|
||||||
|
|||||||
@@ -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;
|
||||||
@@ -31,29 +30,29 @@ public:
|
|||||||
ServerConnexion(ServerConnexion&& move);
|
ServerConnexion(ServerConnexion&& move);
|
||||||
virtual ~ServerConnexion();
|
virtual ~ServerConnexion();
|
||||||
|
|
||||||
void setServer(Server* server);
|
void SetServer(Server* server);
|
||||||
|
|
||||||
virtual void HandlePacket(const protocol::PlayerLoginPacket* packet);
|
virtual void HandlePacket(const protocol::PlayerLoginPacket* packet) override;
|
||||||
virtual void HandlePacket(const protocol::KeepAlivePacket* packet);
|
virtual void HandlePacket(const protocol::KeepAlivePacket* packet) override;
|
||||||
virtual void HandlePacket(const protocol::SelectTeamPacket* packet);
|
virtual void HandlePacket(const protocol::SelectTeamPacket* packet) override;
|
||||||
virtual void HandlePacket(const protocol::DisconnectPacket* packet);
|
virtual void HandlePacket(const protocol::DisconnectPacket* packet) override;
|
||||||
virtual void HandlePacket(const protocol::PlaceTowerPacket* packet);
|
virtual void HandlePacket(const protocol::PlaceTowerPacket* packet) override;
|
||||||
virtual void HandlePacket(const protocol::SendMobsPacket* packet);
|
virtual void HandlePacket(const protocol::SendMobsPacket* packet) override;
|
||||||
virtual void HandlePacket(const protocol::UpgradeTowerPacket* packet);
|
virtual void HandlePacket(const protocol::UpgradeTowerPacket* packet) override;
|
||||||
virtual void HandlePacket(const protocol::RemoveTowerPacket* packet);
|
virtual void HandlePacket(const protocol::RemoveTowerPacket* packet) override;
|
||||||
|
|
||||||
std::uint8_t getID() const { return m_ID; }
|
std::uint8_t GetID() const { return m_ID; }
|
||||||
const game::Player* getPlayer() const { return m_Player; }
|
const game::Player* GetPlayer() const { return m_Player; }
|
||||||
game::Player* getPlayer() { return m_Player; }
|
game::Player* GetPlayer() { return m_Player; }
|
||||||
|
|
||||||
virtual bool updateSocket();
|
virtual bool UpdateSocket();
|
||||||
|
|
||||||
REMOVE_COPY(ServerConnexion);
|
REMOVE_COPY(ServerConnexion);
|
||||||
private:
|
private:
|
||||||
void registerHandlers();
|
void RegisterHandlers();
|
||||||
void checkKeepAlive();
|
void CheckKeepAlive();
|
||||||
void sendKeepAlive();
|
void SendKeepAlive();
|
||||||
void initConnection();
|
void InitConnection();
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace server
|
} // namespace server
|
||||||
|
|||||||
@@ -20,22 +20,23 @@ public:
|
|||||||
ServerGame(Server* server);
|
ServerGame(Server* server);
|
||||||
~ServerGame() {}
|
~ServerGame() {}
|
||||||
|
|
||||||
ServerWorld* getServerWorld() { return &m_ServerWorld; }
|
ServerWorld* GetServerWorld() { return &m_ServerWorld; }
|
||||||
|
|
||||||
virtual void tick(std::uint64_t delta);
|
virtual void Tick(std::uint64_t delta);
|
||||||
void startGame();
|
void StartGame();
|
||||||
|
|
||||||
// GameListener
|
// GameListener
|
||||||
|
|
||||||
virtual void OnGameStateUpdate(game::GameState newState);
|
virtual void OnGameStateUpdate(game::GameState newState) override;
|
||||||
virtual void OnGameBegin();
|
virtual void OnGameBegin() override;
|
||||||
virtual void OnGameEnd();
|
virtual void OnGameEnd() override;
|
||||||
virtual void OnGameClose();
|
virtual void OnGameClose() override;
|
||||||
private:
|
private:
|
||||||
void balanceTeams();
|
void BalanceTeams();
|
||||||
void updateMobStates();
|
void InitPlayerStats();
|
||||||
void updateGoldMines();
|
void UpdateMobStates();
|
||||||
void updatePlayerStats();
|
void UpdateGoldMines();
|
||||||
|
void UpdatePlayerStats();
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace game
|
} // namespace game
|
||||||
|
|||||||
@@ -18,12 +18,11 @@ public:
|
|||||||
|
|
||||||
ServerWorld(Server* server, ServerGame* game);
|
ServerWorld(Server* server, ServerGame* game);
|
||||||
|
|
||||||
void spawnMobs(game::MobType type, std::uint8_t level, game::PlayerID sender, std::uint8_t count);
|
void SpawnMobs(game::MobType type, std::uint8_t level, game::PlayerID sender, std::uint8_t count);
|
||||||
game::TowerPtr placeTowerAt(game::TowerType type, std::int32_t x, std::int32_t y, game::PlayerID builder);
|
game::TowerPtr PlaceTowerAt(game::TowerType type, std::int32_t x, std::int32_t y, game::PlayerID builder);
|
||||||
|
|
||||||
virtual void OnMobDie(game::Mob* mob);
|
virtual void OnMobDie(game::Mob* mob) override;
|
||||||
|
virtual void OnMobCastleDamage(game::Mob* damager, game::TeamCastle* enemyCastle, float damage) override;
|
||||||
virtual void OnMobCastleDamage(game::Mob* damager, game::TeamCastle* enemyCastle, float damage);
|
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -6,6 +6,9 @@
|
|||||||
namespace td {
|
namespace td {
|
||||||
namespace utils {
|
namespace utils {
|
||||||
|
|
||||||
|
std::uint64_t Inflate(const std::string& source, std::string& dest);
|
||||||
|
std::uint64_t Deflate(const std::string& source, std::string& dest);
|
||||||
|
|
||||||
DataBuffer Compress(const DataBuffer& buffer);
|
DataBuffer Compress(const DataBuffer& buffer);
|
||||||
DataBuffer Decompress(DataBuffer& buffer);
|
DataBuffer Decompress(DataBuffer& buffer);
|
||||||
DataBuffer Decompress(DataBuffer& buffer, std::uint64_t packetLength);
|
DataBuffer Decompress(DataBuffer& buffer, std::uint64_t packetLength);
|
||||||
|
|||||||
@@ -1,5 +1,4 @@
|
|||||||
#ifndef MCLIB_COMMON_DATA_BUFFER_H_
|
#pragma once
|
||||||
#define MCLIB_COMMON_DATA_BUFFER_H_
|
|
||||||
|
|
||||||
#include <vector>
|
#include <vector>
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
@@ -13,7 +12,7 @@ class DataBuffer {
|
|||||||
private:
|
private:
|
||||||
typedef std::vector<std::uint8_t> Data;
|
typedef std::vector<std::uint8_t> Data;
|
||||||
Data m_Buffer;
|
Data m_Buffer;
|
||||||
std::size_t m_ReadOffset = 0;
|
std::size_t m_ReadOffset;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
typedef Data::iterator iterator;
|
typedef Data::iterator iterator;
|
||||||
@@ -23,7 +22,7 @@ public:
|
|||||||
|
|
||||||
DataBuffer();
|
DataBuffer();
|
||||||
DataBuffer(const DataBuffer& other);
|
DataBuffer(const DataBuffer& other);
|
||||||
DataBuffer(const DataBuffer& other, std::size_t offset);
|
DataBuffer(const DataBuffer& other, Data::difference_type offset);
|
||||||
DataBuffer(DataBuffer&& other);
|
DataBuffer(DataBuffer&& other);
|
||||||
DataBuffer(const std::string& str);
|
DataBuffer(const std::string& str);
|
||||||
|
|
||||||
@@ -64,7 +63,7 @@ public:
|
|||||||
template <typename T>
|
template <typename T>
|
||||||
DataBuffer& operator>>(T& data) {
|
DataBuffer& operator>>(T& data) {
|
||||||
assert(m_ReadOffset + sizeof(T) <= GetSize());
|
assert(m_ReadOffset + sizeof(T) <= GetSize());
|
||||||
data = *(T*)&m_Buffer[m_ReadOffset];
|
data = *(reinterpret_cast<T*>(&m_Buffer[m_ReadOffset]));
|
||||||
//std::reverse((std::uint8_t*)&data, (std::uint8_t*)&data + sizeof(T));
|
//std::reverse((std::uint8_t*)&data, (std::uint8_t*)&data + sizeof(T));
|
||||||
m_ReadOffset += sizeof(T);
|
m_ReadOffset += sizeof(T);
|
||||||
return *this;
|
return *this;
|
||||||
@@ -72,42 +71,55 @@ public:
|
|||||||
|
|
||||||
DataBuffer& operator>>(DataBuffer& data) {
|
DataBuffer& operator>>(DataBuffer& data) {
|
||||||
data.Resize(GetSize() - m_ReadOffset);
|
data.Resize(GetSize() - m_ReadOffset);
|
||||||
std::copy(m_Buffer.begin() + m_ReadOffset, m_Buffer.end(), data.begin());
|
std::copy(m_Buffer.begin() + static_cast<Data::difference_type>(m_ReadOffset), m_Buffer.end(), data.begin());
|
||||||
m_ReadOffset = m_Buffer.size();
|
m_ReadOffset = m_Buffer.size();
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
DataBuffer& operator>>(std::string& str) {
|
DataBuffer& operator>>(std::string& str) {
|
||||||
std::size_t stringSize = strlen((const char*)m_Buffer.data() + m_ReadOffset) + 1; // including null character
|
std::size_t stringSize = strlen(reinterpret_cast<const char*>(m_Buffer.data()) + m_ReadOffset) + 1; // including null character
|
||||||
str.resize(stringSize);
|
str.resize(stringSize);
|
||||||
std::copy(m_Buffer.begin() + m_ReadOffset, m_Buffer.begin() + m_ReadOffset + stringSize, str.begin());
|
std::copy(m_Buffer.begin() + static_cast<Data::difference_type>(m_ReadOffset),
|
||||||
|
m_Buffer.begin() + static_cast<Data::difference_type>(m_ReadOffset + stringSize), str.begin());
|
||||||
m_ReadOffset += stringSize;
|
m_ReadOffset += stringSize;
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void WriteSome(const char* buffer, std::size_t amount) {
|
||||||
|
std::size_t end_pos = m_Buffer.size();
|
||||||
|
m_Buffer.resize(m_Buffer.size() + amount);
|
||||||
|
memcpy(m_Buffer.data() + end_pos, buffer, amount);
|
||||||
|
}
|
||||||
|
|
||||||
|
void WriteSome(const std::uint8_t* buffer, std::size_t amount) {
|
||||||
|
std::size_t end_pos = m_Buffer.size();
|
||||||
|
m_Buffer.resize(m_Buffer.size() + amount);
|
||||||
|
memcpy(m_Buffer.data() + end_pos, buffer, amount);
|
||||||
|
}
|
||||||
|
|
||||||
void ReadSome(char* buffer, std::size_t amount) {
|
void ReadSome(char* buffer, std::size_t amount) {
|
||||||
assert(m_ReadOffset + amount <= GetSize());
|
assert(m_ReadOffset + amount <= GetSize());
|
||||||
std::copy_n(m_Buffer.begin() + m_ReadOffset, amount, buffer);
|
std::copy_n(m_Buffer.begin() + static_cast<Data::difference_type>(m_ReadOffset), amount, buffer);
|
||||||
m_ReadOffset += amount;
|
m_ReadOffset += amount;
|
||||||
}
|
}
|
||||||
|
|
||||||
void ReadSome(std::uint8_t* buffer, std::size_t amount) {
|
void ReadSome(std::uint8_t* buffer, std::size_t amount) {
|
||||||
assert(m_ReadOffset + amount <= GetSize());
|
assert(m_ReadOffset + amount <= GetSize());
|
||||||
std::copy_n(m_Buffer.begin() + m_ReadOffset, amount, buffer);
|
std::copy_n(m_Buffer.begin() + static_cast<Data::difference_type>(m_ReadOffset), amount, buffer);
|
||||||
m_ReadOffset += amount;
|
m_ReadOffset += amount;
|
||||||
}
|
}
|
||||||
|
|
||||||
void ReadSome(DataBuffer& buffer, std::size_t amount) {
|
void ReadSome(DataBuffer& buffer, std::size_t amount) {
|
||||||
assert(m_ReadOffset + amount <= GetSize());
|
assert(m_ReadOffset + amount <= GetSize());
|
||||||
buffer.Resize(amount);
|
buffer.Resize(amount);
|
||||||
std::copy_n(m_Buffer.begin() + m_ReadOffset, amount, buffer.begin());
|
std::copy_n(m_Buffer.begin() + static_cast<Data::difference_type>(m_ReadOffset), amount, buffer.begin());
|
||||||
m_ReadOffset += amount;
|
m_ReadOffset += amount;
|
||||||
}
|
}
|
||||||
|
|
||||||
void ReadSome(std::string& buffer, std::size_t amount) {
|
void ReadSome(std::string& buffer, std::size_t amount) {
|
||||||
assert(m_ReadOffset + amount <= GetSize());
|
assert(m_ReadOffset + amount <= GetSize());
|
||||||
buffer.resize(amount);
|
buffer.resize(amount);
|
||||||
std::copy_n(m_Buffer.begin() + m_ReadOffset, amount, buffer.begin());
|
std::copy_n(m_Buffer.begin() + static_cast<Data::difference_type>(m_ReadOffset), amount, buffer.begin());
|
||||||
m_ReadOffset += amount;
|
m_ReadOffset += amount;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -163,5 +175,3 @@ public:
|
|||||||
std::ostream& operator<<(std::ostream& os, const DataBuffer& buffer);
|
std::ostream& operator<<(std::ostream& os, const DataBuffer& buffer);
|
||||||
|
|
||||||
} // ns td
|
} // ns td
|
||||||
|
|
||||||
#endif
|
|
||||||
|
|||||||
@@ -7,63 +7,63 @@ constexpr float PI = 3.14159274101257324219;
|
|||||||
|
|
||||||
/* Sine functions */
|
/* Sine functions */
|
||||||
|
|
||||||
float easeInSine(float x);
|
float EaseInSine(float x);
|
||||||
float easeOutSine(float x);
|
float EaseOutSine(float x);
|
||||||
float easeInOutSine(float x);
|
float EaseInOutSine(float x);
|
||||||
|
|
||||||
/* Cubic functions */
|
/* Cubic functions */
|
||||||
|
|
||||||
float easeInCubic(float x);
|
float EaseInCubic(float x);
|
||||||
float easeOutCubic(float x);
|
float EaseOutCubic(float x);
|
||||||
float easeInOutCubic(float x);
|
float EaseInOutCubic(float x);
|
||||||
|
|
||||||
/* Quint functions */
|
/* Quint functions */
|
||||||
|
|
||||||
float easeInQuint(float x);
|
float EaseInQuint(float x);
|
||||||
float easeOutQuint(float x);
|
float EaseOutQuint(float x);
|
||||||
float easeInOutQuint(float x);
|
float EaseInOutQuint(float x);
|
||||||
|
|
||||||
/* Circ functions */
|
/* Circ functions */
|
||||||
|
|
||||||
float easeInCirc(float x);
|
float EaseInCirc(float x);
|
||||||
float easeOutCirc(float x);
|
float EaseOutCirc(float x);
|
||||||
float easeInOutCirc(float x);
|
float EaseInOutCirc(float x);
|
||||||
|
|
||||||
/* Elastic functions */
|
/* Elastic functions */
|
||||||
|
|
||||||
float easeInElastic(float x);
|
float EaseInElastic(float x);
|
||||||
float easeOutElastic(float x);
|
float EaseOutElastic(float x);
|
||||||
float easeInOutElastic(float x);
|
float EaseInOutElastic(float x);
|
||||||
|
|
||||||
/* Quad functions */
|
/* Quad functions */
|
||||||
|
|
||||||
float easeInQuad(float x);
|
float EaseInQuad(float x);
|
||||||
float easeOutQuad(float x);
|
float EaseOutQuad(float x);
|
||||||
float easeInOutQuad(float x);
|
float EaseInOutQuad(float x);
|
||||||
|
|
||||||
/* Quart functions */
|
/* Quart functions */
|
||||||
|
|
||||||
float easeInQuart(float x);
|
float EaseInQuart(float x);
|
||||||
float easeOutQuart(float x);
|
float EaseOutQuart(float x);
|
||||||
float easeInOutQuart(float x);
|
float EaseInOutQuart(float x);
|
||||||
|
|
||||||
/* Expo functions */
|
/* Expo functions */
|
||||||
|
|
||||||
float easeInExpo(float x);
|
float EaseInExpo(float x);
|
||||||
float easeOutExpo(float x);
|
float EaseOutExpo(float x);
|
||||||
float easeInOutExpo(float x);
|
float EaseInOutExpo(float x);
|
||||||
|
|
||||||
/* Back functions */
|
/* Back functions */
|
||||||
|
|
||||||
float easeInBack(float x);
|
float EaseInBack(float x);
|
||||||
float easeOutBack(float x);
|
float EaseOutBack(float x);
|
||||||
float easeInOutBack(float x);
|
float EaseInOutBack(float x);
|
||||||
|
|
||||||
/* Bounce functions */
|
/* Bounce functions */
|
||||||
|
|
||||||
float easeInBounce(float x);
|
float EaseInBounce(float x);
|
||||||
float easeOutBounce(float x);
|
float EaseOutBounce(float x);
|
||||||
float easeInOutBounce(float x);
|
float EaseInOutBounce(float x);
|
||||||
|
|
||||||
} // namespace utils
|
} // namespace utils
|
||||||
} // namespace td
|
} // namespace td
|
||||||
|
|||||||
23
include/misc/Format.h
Normal file
23
include/misc/Format.h
Normal file
@@ -0,0 +1,23 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <string>
|
||||||
|
#include <memory>
|
||||||
|
#include <stdexcept>
|
||||||
|
|
||||||
|
namespace td {
|
||||||
|
namespace utils {
|
||||||
|
|
||||||
|
template <typename... Args>
|
||||||
|
std::string format(const std::string& format, Args... args) {
|
||||||
|
int size = snprintf(nullptr, 0, format.c_str(), args...) + 1; // Extra space for '\0'
|
||||||
|
if (size <= 0) {
|
||||||
|
throw std::runtime_error("Error during formatting.");
|
||||||
|
}
|
||||||
|
std::unique_ptr<char[]> buf(new char[size]);
|
||||||
|
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
|
||||||
|
}
|
||||||
|
|
||||||
|
} // namespace utils
|
||||||
|
} // namespace td
|
||||||
|
|
||||||
13
include/misc/Log.h
Normal file
13
include/misc/Log.h
Normal file
@@ -0,0 +1,13 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <string>
|
||||||
|
|
||||||
|
namespace td {
|
||||||
|
namespace utils {
|
||||||
|
|
||||||
|
void LOG(const std::string& msg);
|
||||||
|
void LOGD(const std::string& msg);
|
||||||
|
void LOGE(const std::string& err);
|
||||||
|
|
||||||
|
} // namespace utils
|
||||||
|
} // namespace td
|
||||||
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
|
||||||
@@ -13,11 +13,11 @@ protected:
|
|||||||
std::vector<Listener*> m_Listeners;
|
std::vector<Listener*> m_Listeners;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
void bindListener(Listener* listener) {
|
void BindListener(Listener* listener) {
|
||||||
m_Listeners.push_back(listener);
|
m_Listeners.push_back(listener);
|
||||||
}
|
}
|
||||||
|
|
||||||
void unbindListener(Listener* listener) {
|
void UnbindListener(Listener* listener) {
|
||||||
auto iter = std::find(m_Listeners.begin(), m_Listeners.end(), listener);
|
auto iter = std::find(m_Listeners.begin(), m_Listeners.end(), listener);
|
||||||
|
|
||||||
if (iter == m_Listeners.end()) return;
|
if (iter == m_Listeners.end()) return;
|
||||||
@@ -26,7 +26,7 @@ public:
|
|||||||
}
|
}
|
||||||
|
|
||||||
template <typename Func, typename... Args>
|
template <typename Func, typename... Args>
|
||||||
void notifyListeners(Func function, Args... args) {
|
void NotifyListeners(Func function, Args... args) {
|
||||||
for (Listener* listener : m_Listeners)
|
for (Listener* listener : m_Listeners)
|
||||||
std::bind(function, listener, args...)();
|
std::bind(function, listener, args...)();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -18,7 +18,7 @@ enum class Architecture {
|
|||||||
Unknown,
|
Unknown,
|
||||||
};
|
};
|
||||||
|
|
||||||
inline Os getSystemOs() {
|
inline Os GetSystemOs() {
|
||||||
#if defined(_WIN32) || defined(_WIN64)
|
#if defined(_WIN32) || defined(_WIN64)
|
||||||
return Os::Windows;
|
return Os::Windows;
|
||||||
#elif defined(__ANDROID__)
|
#elif defined(__ANDROID__)
|
||||||
@@ -31,7 +31,7 @@ inline Os getSystemOs() {
|
|||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
inline Architecture getSystemArchitecture() {
|
inline Architecture GetSystemArchitecture() {
|
||||||
#if defined(_WIN64)
|
#if defined(_WIN64)
|
||||||
return Architecture::x86_64;
|
return Architecture::x86_64;
|
||||||
#elif defined(_WIN32)
|
#elif defined(_WIN32)
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ namespace td {
|
|||||||
namespace utils {
|
namespace utils {
|
||||||
|
|
||||||
template<typename NumberType>
|
template<typename NumberType>
|
||||||
NumberType getRandomInt(NumberType min, NumberType max) {
|
NumberType GetRandomInt(NumberType min, NumberType max) {
|
||||||
std::random_device randomDevice;
|
std::random_device randomDevice;
|
||||||
std::mt19937 generator(randomDevice());
|
std::mt19937 generator(randomDevice());
|
||||||
std::uniform_int_distribution<NumberType> distrib(min, max);
|
std::uniform_int_distribution<NumberType> distrib(min, max);
|
||||||
@@ -14,7 +14,7 @@ NumberType getRandomInt(NumberType min, NumberType max) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
template<typename NumberType>
|
template<typename NumberType>
|
||||||
NumberType getRandomReal(NumberType min, NumberType max) {
|
NumberType GetRandomReal(NumberType min, NumberType max) {
|
||||||
std::random_device randomDevice;
|
std::random_device randomDevice;
|
||||||
std::mt19937 generator(randomDevice());
|
std::mt19937 generator(randomDevice());
|
||||||
std::uniform_real_distribution<NumberType> distrib(min, max);
|
std::uniform_real_distribution<NumberType> distrib(min, max);
|
||||||
|
|||||||
@@ -13,14 +13,14 @@ public:
|
|||||||
Point() : m_X(0), m_Y(0) {}
|
Point() : m_X(0), m_Y(0) {}
|
||||||
Point(float x, float y) : m_X(x), m_Y(y) {}
|
Point(float x, float y) : m_X(x), m_Y(y) {}
|
||||||
|
|
||||||
float getX() const { return m_X; }
|
float GetX() const { return m_X; }
|
||||||
float getY() const { return m_Y; }
|
float GetY() const { return m_Y; }
|
||||||
|
|
||||||
void setX(float x) { m_X = x; }
|
void SetX(float x) { m_X = x; }
|
||||||
void setY(float y) { m_Y = y; }
|
void SetY(float y) { m_Y = y; }
|
||||||
|
|
||||||
float distance(const Point& point) const;
|
float Distance(const Point& point) const;
|
||||||
float distanceSquared(const Point& point) const;
|
float DistanceSquared(const Point& point) const;
|
||||||
};
|
};
|
||||||
|
|
||||||
class Circle;
|
class Circle;
|
||||||
@@ -32,34 +32,34 @@ private:
|
|||||||
public:
|
public:
|
||||||
Rectangle() {}
|
Rectangle() {}
|
||||||
|
|
||||||
const Point& getCenter() const { return m_Center; }
|
const Point& GetCenter() const { return m_Center; }
|
||||||
float getCenterX() const { return m_Center.getX(); }
|
float GetCenterX() const { return m_Center.GetX(); }
|
||||||
float getCenterY() const { return m_Center.getY(); }
|
float GetCenterY() const { return m_Center.GetY(); }
|
||||||
|
|
||||||
float getWidth() const { return m_Width; }
|
float GetWidth() const { return m_Width; }
|
||||||
float getHeight() const { return m_Height; }
|
float GetHeight() const { return m_Height; }
|
||||||
|
|
||||||
Point getTopLeft() const { return { m_Center.getX() - (m_Width / 2.0f), m_Center.getY() - (m_Height / 2.0f) }; }
|
Point GetTopLeft() const { return { m_Center.GetX() - (m_Width / 2.0f), m_Center.GetY() - (m_Height / 2.0f) }; }
|
||||||
Point getBottomRight() const { return { m_Center.getX() + (m_Width / 2.0f), m_Center.getY() + (m_Height / 2.0f) }; }
|
Point GetBottomRight() const { return { m_Center.GetX() + (m_Width / 2.0f), m_Center.GetY() + (m_Height / 2.0f) }; }
|
||||||
|
|
||||||
void setCenter(const Point& center) { m_Center = center; }
|
void SetCenter(const Point& center) { m_Center = center; }
|
||||||
void setCenterX(float x) { m_Center.setX(x); }
|
void SetCenterX(float x) { m_Center.SetX(x); }
|
||||||
void setCenterY(float y) { m_Center.setY(y); }
|
void SetCenterY(float y) { m_Center.SetY(y); }
|
||||||
|
|
||||||
void setSize(float width, float height) { setWidth(width); setHeight(height); }
|
void SetSize(float width, float height) { SetWidth(width); SetHeight(height); }
|
||||||
void setSize(Point size) { setSize(size.getX(), size.getY()); }
|
void SetSize(Point size) { SetSize(size.GetX(), size.GetY()); }
|
||||||
Point getSize() { return { m_Width, m_Height }; }
|
Point GetSize() { return { m_Width, m_Height }; }
|
||||||
|
|
||||||
void setWidth(float width) { m_Width = width; }
|
void SetWidth(float width) { m_Width = width; }
|
||||||
void setHeight(float height) { m_Height = height; }
|
void SetHeight(float height) { m_Height = height; }
|
||||||
|
|
||||||
bool collidesWith(const Point& point) const;
|
bool CollidesWith(const Point& point) const;
|
||||||
bool collidesWith(const Rectangle& rect) const;
|
bool CollidesWith(const Rectangle& rect) const;
|
||||||
bool collidesWith(const Circle& circle) const;
|
bool CollidesWith(const Circle& circle) const;
|
||||||
|
|
||||||
// distance from the closest side of the rectangle
|
// distance from the closest side of the rectangle
|
||||||
float distance(const Circle& circle) const;
|
float Distance(const Circle& circle) const;
|
||||||
float distanceSquared(const Circle& circle) const;
|
float DistanceSquared(const Circle& circle) const;
|
||||||
};
|
};
|
||||||
|
|
||||||
class Circle {
|
class Circle {
|
||||||
@@ -70,25 +70,25 @@ public:
|
|||||||
Circle(float x, float y, float radius) : m_Center(x, y), m_Radius(radius) {}
|
Circle(float x, float y, float radius) : m_Center(x, y), m_Radius(radius) {}
|
||||||
Circle() : m_Radius(0) {}
|
Circle() : m_Radius(0) {}
|
||||||
|
|
||||||
const Point& getCenter() const { return m_Center; }
|
const Point& GetCenter() const { return m_Center; }
|
||||||
float getCenterX() const { return m_Center.getX(); }
|
float GetCenterX() const { return m_Center.GetX(); }
|
||||||
float getCenterY() const { return m_Center.getY(); }
|
float GetCenterY() const { return m_Center.GetY(); }
|
||||||
|
|
||||||
float getRadius() const { return m_Radius; }
|
float GetRadius() const { return m_Radius; }
|
||||||
|
|
||||||
void setCenter(const Point& center) { m_Center = center; }
|
void SetCenter(const Point& center) { m_Center = center; }
|
||||||
void setCenterX(float x) { m_Center.setX(x); }
|
void SetCenterX(float x) { m_Center.SetX(x); }
|
||||||
void setCenterY(float y) { m_Center.setY(y); }
|
void SetCenterY(float y) { m_Center.SetY(y); }
|
||||||
|
|
||||||
void setRadius(float radius) { m_Radius = radius; }
|
void SetRadius(float radius) { m_Radius = radius; }
|
||||||
|
|
||||||
bool collidesWith(const Point& point) const;
|
bool CollidesWith(const Point& point) const;
|
||||||
bool collidesWith(const Rectangle& rect) const;
|
bool CollidesWith(const Rectangle& rect) const;
|
||||||
bool collidesWith(const Circle& circle) const;
|
bool CollidesWith(const Circle& circle) const;
|
||||||
|
|
||||||
// distance from the closest side of the rectangle
|
// distance from the closest side of the rectangle
|
||||||
float distance(const Rectangle& rect) const;
|
float Distance(const Rectangle& rect) const;
|
||||||
float distanceSquared(const Rectangle& rect) const;
|
float DistanceSquared(const Rectangle& rect) const;
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace shape
|
} // namespace shape
|
||||||
|
|||||||
@@ -6,7 +6,7 @@
|
|||||||
namespace td {
|
namespace td {
|
||||||
namespace utils {
|
namespace utils {
|
||||||
|
|
||||||
std::uint64_t getTime();
|
std::uint64_t GetTime();
|
||||||
|
|
||||||
|
|
||||||
typedef std::function<void()> TimerExecFunction;
|
typedef std::function<void()> TimerExecFunction;
|
||||||
@@ -17,23 +17,23 @@ private:
|
|||||||
std::uint64_t m_Interval;
|
std::uint64_t m_Interval;
|
||||||
TimerExecFunction m_Function;
|
TimerExecFunction m_Function;
|
||||||
|
|
||||||
std::uint64_t m_LastTime = getTime();
|
std::uint64_t m_LastTime = GetTime();
|
||||||
std::uint64_t m_InternalTime = 0;
|
std::uint64_t m_InternalTime = 0;
|
||||||
public:
|
public:
|
||||||
AutoTimer() : m_Interval(0), m_Function(nullptr) {}
|
AutoTimer() : m_Interval(0), m_Function(nullptr) {}
|
||||||
AutoTimer(std::uint64_t interval) : m_Interval(interval), m_Function(nullptr) {}
|
AutoTimer(std::uint64_t interval) : m_Interval(interval), m_Function(nullptr) {}
|
||||||
AutoTimer(std::uint64_t interval, TimerExecFunction callback) : m_Interval(interval), m_Function(callback) {}
|
AutoTimer(std::uint64_t interval, TimerExecFunction callback) : m_Interval(interval), m_Function(callback) {}
|
||||||
|
|
||||||
void update();
|
void Update();
|
||||||
void update(std::uint64_t delta);
|
void Update(std::uint64_t delta);
|
||||||
|
|
||||||
void reset();
|
void Reset();
|
||||||
|
|
||||||
void setInterval(std::uint64_t newInterval) { m_Interval = newInterval; }
|
void SetInterval(std::uint64_t newInterval) { m_Interval = newInterval; }
|
||||||
std::uint64_t getInterval() const { return m_Interval; }
|
std::uint64_t GetInterval() const { return m_Interval; }
|
||||||
|
|
||||||
void setCallbackFunction(TimerExecFunction newCallback) { m_Function = newCallback; }
|
void SetCallbackFunction(TimerExecFunction newCallback) { m_Function = newCallback; }
|
||||||
TimerExecFunction getCallbackFunction() const { return m_Function; }
|
TimerExecFunction GetCallbackFunction() const { return m_Function; }
|
||||||
};
|
};
|
||||||
|
|
||||||
// utililty class to call function at regular period of time
|
// utililty class to call function at regular period of time
|
||||||
@@ -45,12 +45,12 @@ public:
|
|||||||
Timer() : m_Interval(0) {}
|
Timer() : m_Interval(0) {}
|
||||||
Timer(std::uint64_t interval) : m_Interval(interval) {}
|
Timer(std::uint64_t interval) : m_Interval(interval) {}
|
||||||
|
|
||||||
bool update(std::uint64_t delta);
|
bool Update(std::uint64_t delta);
|
||||||
|
|
||||||
void reset();
|
void Reset();
|
||||||
|
|
||||||
void setInterval(std::uint64_t newInterval) { m_Interval = newInterval; }
|
void SetInterval(std::uint64_t newInterval) { m_Interval = newInterval; }
|
||||||
std::uint64_t getInterval() const { return m_Interval; }
|
std::uint64_t GetInterval() const { return m_Interval; }
|
||||||
};
|
};
|
||||||
|
|
||||||
// utililty class to call function at regular period of time with a cooldown (used for towers and mobs )
|
// utililty class to call function at regular period of time with a cooldown (used for towers and mobs )
|
||||||
@@ -62,14 +62,14 @@ public:
|
|||||||
CooldownTimer() : m_Cooldown(0), m_CooldownTime(0) {}
|
CooldownTimer() : m_Cooldown(0), m_CooldownTime(0) {}
|
||||||
CooldownTimer(std::uint64_t cooldown) : m_Cooldown(0), m_CooldownTime(cooldown) {}
|
CooldownTimer(std::uint64_t cooldown) : m_Cooldown(0), m_CooldownTime(cooldown) {}
|
||||||
|
|
||||||
bool update(std::uint64_t delta);
|
bool Update(std::uint64_t delta);
|
||||||
|
|
||||||
void applyCooldown();
|
void ApplyCooldown();
|
||||||
|
|
||||||
void reset();
|
void Reset();
|
||||||
|
|
||||||
void setCooldown(std::uint64_t newCooldown) { m_CooldownTime = newCooldown; }
|
void SetCooldown(std::uint64_t newCooldown) { m_CooldownTime = newCooldown; }
|
||||||
std::uint64_t getCooldown() const { return m_CooldownTime; }
|
std::uint64_t GetCooldown() const { return m_CooldownTime; }
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace utils
|
} // namespace utils
|
||||||
|
|||||||
@@ -13,17 +13,18 @@ public:
|
|||||||
TCPListener();
|
TCPListener();
|
||||||
~TCPListener();
|
~TCPListener();
|
||||||
|
|
||||||
bool listen(std::uint16_t port, int maxConnections);
|
bool Listen(std::uint16_t port, int maxConnections);
|
||||||
bool accept(TCPSocket& newSocket);
|
bool Accept(TCPSocket& newSocket);
|
||||||
|
|
||||||
void destroy();
|
void Destroy();
|
||||||
bool close();
|
bool Close();
|
||||||
bool setBlocking(bool blocking);
|
bool SetBlocking(bool blocking);
|
||||||
|
|
||||||
std::uint16_t getListeningPort() const {
|
std::uint16_t GetListeningPort() const {
|
||||||
return m_Port;
|
return m_Port;
|
||||||
}
|
}
|
||||||
int getMaximumConnections() const {
|
|
||||||
|
int GetMaximumConnections() const {
|
||||||
return m_MaxConnections;
|
return m_MaxConnections;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -15,7 +15,7 @@ class TCPSocket : public Socket {
|
|||||||
private:
|
private:
|
||||||
IPAddress m_RemoteIP;
|
IPAddress m_RemoteIP;
|
||||||
uint16_t m_Port;
|
uint16_t m_Port;
|
||||||
sockaddr_in m_RemoteAddr;
|
sockaddr m_RemoteAddr;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
TCPSocket();
|
TCPSocket();
|
||||||
|
|||||||
@@ -20,7 +20,9 @@ public:
|
|||||||
|
|
||||||
bool Connect(const IPAddress& address, std::uint16_t port);
|
bool Connect(const IPAddress& address, std::uint16_t port);
|
||||||
std::size_t Send(const std::uint8_t* data, std::size_t size);
|
std::size_t Send(const std::uint8_t* data, std::size_t size);
|
||||||
DataBuffer Receive(std::size_t amount);
|
|
||||||
|
virtual DataBuffer Receive(std::size_t amount);
|
||||||
|
virtual std::size_t Receive(DataBuffer& buffer, std::size_t amount);
|
||||||
};
|
};
|
||||||
|
|
||||||
} // ns network
|
} // ns network
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ namespace td {
|
|||||||
namespace protocol {
|
namespace protocol {
|
||||||
namespace PacketFactory {
|
namespace PacketFactory {
|
||||||
|
|
||||||
PacketPtr createPacket(PacketType type, DataBuffer& buffer);
|
PacketPtr CreatePacket(PacketType type, DataBuffer& buffer);
|
||||||
|
|
||||||
}
|
}
|
||||||
} // namespace protocol
|
} // namespace protocol
|
||||||
|
|||||||
@@ -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 {
|
||||||
@@ -16,30 +17,32 @@ public:
|
|||||||
|
|
||||||
PacketDispatcher* GetDispatcher() { return m_Dispatcher; }
|
PacketDispatcher* GetDispatcher() { return m_Dispatcher; }
|
||||||
|
|
||||||
virtual void HandlePacket(const PlayerLoginPacket* packet) {}
|
virtual void HandlePacket(const ConnexionInfoPacket* packet) {}
|
||||||
virtual void HandlePacket(const WorldBeginDataPacket* packet) {}
|
virtual void HandlePacket(const DisconnectPacket* packet) {}
|
||||||
virtual void HandlePacket(const WorldDataPacket* packet) {}
|
|
||||||
virtual void HandlePacket(const KeepAlivePacket* packet) {}
|
virtual void HandlePacket(const KeepAlivePacket* packet) {}
|
||||||
virtual void HandlePacket(const UpdateMoneyPacket* packet) {}
|
virtual void HandlePacket(const PlaceTowerPacket* packet) {}
|
||||||
virtual void HandlePacket(const UpdateExpPacket* packet) {}
|
virtual void HandlePacket(const PlayerBuyItemPacket* packet) {}
|
||||||
virtual void HandlePacket(const UpdateLobbyTimePacket* packet) {}
|
virtual void HandlePacket(const PlayerBuyMobUpgradePacket* packet) {}
|
||||||
virtual void HandlePacket(const UpdateGameStatePacket* packet) {}
|
|
||||||
virtual void HandlePacket(const PlayerListPacket* packet) {}
|
|
||||||
virtual void HandlePacket(const PlayerJoinPacket* packet) {}
|
virtual void HandlePacket(const PlayerJoinPacket* packet) {}
|
||||||
virtual void HandlePacket(const PlayerLeavePacket* packet) {}
|
virtual void HandlePacket(const PlayerLeavePacket* packet) {}
|
||||||
virtual void HandlePacket(const ConnexionInfoPacket* packet) {}
|
virtual void HandlePacket(const PlayerListPacket* packet) {}
|
||||||
|
virtual void HandlePacket(const PlayerLoginPacket* packet) {}
|
||||||
|
virtual void HandlePacket(const RemoveTowerPacket* packet) {}
|
||||||
virtual void HandlePacket(const SelectTeamPacket* packet) {}
|
virtual void HandlePacket(const SelectTeamPacket* packet) {}
|
||||||
virtual void HandlePacket(const UpdatePlayerTeamPacket* packet) {}
|
virtual void HandlePacket(const SendMobsPacket* packet) {}
|
||||||
virtual void HandlePacket(const DisconnectPacket* packet) {}
|
|
||||||
virtual void HandlePacket(const ServerTpsPacket* packet) {}
|
virtual void HandlePacket(const ServerTpsPacket* packet) {}
|
||||||
virtual void HandlePacket(const SpawnMobPacket* packet) {}
|
virtual void HandlePacket(const SpawnMobPacket* packet) {}
|
||||||
virtual void HandlePacket(const PlaceTowerPacket* packet) {}
|
|
||||||
virtual void HandlePacket(const WorldAddTowerPacket* packet) {}
|
|
||||||
virtual void HandlePacket(const RemoveTowerPacket* packet) {}
|
|
||||||
virtual void HandlePacket(const SendMobsPacket* packet) {}
|
|
||||||
virtual void HandlePacket(const UpgradeTowerPacket* packet) {}
|
|
||||||
virtual void HandlePacket(const UpdateMobStatesPacket* packet) {}
|
|
||||||
virtual void HandlePacket(const UpdateCastleLifePacket* packet) {}
|
virtual void HandlePacket(const UpdateCastleLifePacket* packet) {}
|
||||||
|
virtual void HandlePacket(const UpdateExpPacket* packet) {}
|
||||||
|
virtual void HandlePacket(const UpdateGameStatePacket* packet) {}
|
||||||
|
virtual void HandlePacket(const UpdateLobbyTimePacket* packet) {}
|
||||||
|
virtual void HandlePacket(const UpdateMobStatesPacket* packet) {}
|
||||||
|
virtual void HandlePacket(const UpdateMoneyPacket* packet) {}
|
||||||
|
virtual void HandlePacket(const UpdatePlayerTeamPacket* packet) {}
|
||||||
|
virtual void HandlePacket(const UpgradeTowerPacket* packet) {}
|
||||||
|
virtual void HandlePacket(const WorldAddTowerPacket* packet) {}
|
||||||
|
virtual void HandlePacket(const WorldBeginDataPacket* packet) {}
|
||||||
|
virtual void HandlePacket(const WorldDataPacket* packet) {}
|
||||||
};
|
};
|
||||||
|
|
||||||
} // 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>
|
||||||
|
|
||||||
@@ -41,26 +39,10 @@ enum class PacketType : std::uint8_t {
|
|||||||
Disconnect,
|
Disconnect,
|
||||||
UpgradeTower,
|
UpgradeTower,
|
||||||
RemoveTower,
|
RemoveTower,
|
||||||
};
|
PlayerBuyItem,
|
||||||
|
PlayerBuyMobUpgrade,
|
||||||
|
|
||||||
struct WorldHeader {
|
PACKET_COUNT
|
||||||
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 {
|
||||||
@@ -68,509 +50,41 @@ public:
|
|||||||
Packet() {}
|
Packet() {}
|
||||||
virtual ~Packet() {}
|
virtual ~Packet() {}
|
||||||
|
|
||||||
virtual DataBuffer Serialize() const = 0;
|
virtual DataBuffer Serialize(bool packetID = true) const = 0;
|
||||||
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;
|
||||||
|
|
||||||
virtual PacketType getType() const = 0;
|
virtual void WritePacketID(DataBuffer& data, bool packetID) const;
|
||||||
std::uint8_t getID() const { return (std::uint8_t)getType(); }
|
|
||||||
|
virtual PacketType GetType() const = 0;
|
||||||
|
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 {
|
} // namespace protocol
|
||||||
private:
|
} // namespace td
|
||||||
std::uint64_t m_AliveID;
|
|
||||||
public:
|
|
||||||
KeepAlivePacket() {}
|
|
||||||
KeepAlivePacket(std::uint64_t aliveID) : m_AliveID(aliveID) {}
|
|
||||||
virtual ~KeepAlivePacket() {}
|
|
||||||
|
|
||||||
virtual DataBuffer Serialize() 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() 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() 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; }
|
|
||||||
|
|
||||||
DataBuffer SerializeCustom() const; // allow serialisation with invalid World member
|
|
||||||
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() 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() 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() {}
|
|
||||||
|
|
||||||
virtual DataBuffer Serialize() 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() 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() 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() 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() 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() 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() 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() 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() 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() 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() 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;
|
|
||||||
game::MobLevel mobLevel;
|
|
||||||
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() 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() 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() 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() 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() 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() 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, 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() 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() 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; }
|
|
||||||
};
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
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
|
||||||
@@ -1,8 +1,62 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#ifdef __ANDROID__
|
#if !defined(TD_IMPL_OPENGL_ES2) \
|
||||||
#include <GLES3/gl3.h>
|
&& !defined(TD_IMPL_OPENGL_ES3) \
|
||||||
|
&& !defined(TD_IMPL_OPENGL_LOADER_GL3W) \
|
||||||
|
&& !defined(TD_IMPL_OPENGL_LOADER_GLEW) \
|
||||||
|
&& !defined(TD_IMPL_OPENGL_LOADER_GLAD) \
|
||||||
|
&& !defined(TD_IMPL_OPENGL_LOADER_GLBINDING2) \
|
||||||
|
&& !defined(TD_IMPL_OPENGL_LOADER_GLBINDING3) \
|
||||||
|
&& !defined(TD_IMPL_OPENGL_LOADER_CUSTOM) \
|
||||||
|
&& !defined(__ANDROID__)
|
||||||
|
|
||||||
|
#if defined(__has_include)
|
||||||
|
|
||||||
|
#if __has_include(<GL/glew.h>)
|
||||||
|
#define TD_IMPL_OPENGL_LOADER_GLEW
|
||||||
|
#elif __has_include(<glad/glad.h>)
|
||||||
|
#define TD_IMPL_OPENGL_LOADER_GLAD
|
||||||
|
#elif __has_include(<GL/gl3w.h>)
|
||||||
|
#define TD_IMPL_OPENGL_LOADER_GL3W
|
||||||
|
#elif __has_include(<glbinding/glbinding.h>)
|
||||||
|
#define TD_IMPL_OPENGL_LOADER_GLBINDING3
|
||||||
|
#elif __has_include(<glbinding/Binding.h>)
|
||||||
|
#define TD_IMPL_OPENGL_LOADER_GLBINDING2
|
||||||
#else
|
#else
|
||||||
#include "glbinding/gl/gl.h"
|
#error "Cannot detect OpenGL loader!"
|
||||||
using namespace gl;
|
#endif
|
||||||
|
|
||||||
|
#else
|
||||||
|
#error "Cannot detect loader with include detection !"
|
||||||
|
#endif
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
// Include correct files
|
||||||
|
|
||||||
|
#if defined(__ANDROID__)
|
||||||
|
#include <GLES3/gl3.h>
|
||||||
|
#elif defined(TD_IMPL_OPENGL_LOADER_GL3W)
|
||||||
|
#include <GL/gl3w.h> // Needs to be initialized with gl3wInit() in user's code
|
||||||
|
#elif defined(TD_IMPL_OPENGL_LOADER_GLEW)
|
||||||
|
#include <GL/glew.h> // Needs to be initialized with glewInit() in user's code.
|
||||||
|
#elif defined(TD_IMPL_OPENGL_LOADER_GLAD)
|
||||||
|
#include <glad/glad.h> // Needs to be initialized with gladLoadGL() in user's code.
|
||||||
|
#elif defined(TD_IMPL_OPENGL_LOADER_GLBINDING2)
|
||||||
|
#ifndef GLFW_INCLUDE_NONE
|
||||||
|
#define GLFW_INCLUDE_NONE // GLFW including OpenGL headers causes ambiguity or multiple definition errors.
|
||||||
|
#endif
|
||||||
|
#include <glbinding/Binding.h> // Needs to be initialized with glbinding::Binding::initialize() in user's code.
|
||||||
|
#include <glbinding/gl/gl.h>
|
||||||
|
using namespace gl;
|
||||||
|
#elif defined(TD_IMPL_OPENGL_LOADER_GLBINDING3)
|
||||||
|
#ifndef GLFW_INCLUDE_NONE
|
||||||
|
#define GLFW_INCLUDE_NONE // GLFW including OpenGL headers causes ambiguity or multiple definition errors.
|
||||||
|
#endif
|
||||||
|
#include <glbinding/glbinding.h>// Needs to be initialized with glbinding::initialize() in user's code.
|
||||||
|
#include <glbinding/gl/gl.h>
|
||||||
|
using namespace gl;
|
||||||
|
#else
|
||||||
|
#include TD_IMPL_OPENGL_LOADER_CUSTOM
|
||||||
#endif
|
#endif
|
||||||
@@ -1,14 +1,6 @@
|
|||||||
/*
|
#pragma once
|
||||||
* Renderer.h
|
|
||||||
*
|
|
||||||
* Created on: 4 nov. 2020
|
|
||||||
* Author: simon
|
|
||||||
*/
|
|
||||||
|
|
||||||
#ifndef RENDER_RENDERER_H_
|
#include "Defines.h"
|
||||||
#define RENDER_RENDERER_H_
|
|
||||||
|
|
||||||
#include <glm/glm.hpp>
|
|
||||||
#include <memory>
|
#include <memory>
|
||||||
#include "loader/GLLoader.h"
|
#include "loader/GLLoader.h"
|
||||||
#include "render/shaders/WorldShader.h"
|
#include "render/shaders/WorldShader.h"
|
||||||
@@ -17,50 +9,63 @@
|
|||||||
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;
|
||||||
glm::vec2 positon;
|
Vec3f positon;
|
||||||
|
Vec3f color = { 1, 1, 1 };
|
||||||
};
|
};
|
||||||
private:
|
private:
|
||||||
std::unique_ptr<WorldShader> m_WorldShader;
|
std::unique_ptr<shader::WorldShader> m_WorldShader;
|
||||||
std::unique_ptr<EntityShader> m_EntityShader;
|
std::unique_ptr<shader::EntityShader> m_EntityShader;
|
||||||
|
|
||||||
glm::vec3 m_BackgroundColor;
|
Vec2i m_WindowSize;
|
||||||
|
|
||||||
bool m_IsometricView = true;
|
Vec3f m_BackgroundColor;
|
||||||
float m_IsometricShade = m_IsometricView;
|
|
||||||
glm::vec2 m_CamPos{};
|
Camera m_Camera {};
|
||||||
public:
|
public:
|
||||||
Renderer();
|
Renderer();
|
||||||
~Renderer();
|
~Renderer();
|
||||||
|
|
||||||
bool init();
|
bool Init();
|
||||||
|
|
||||||
void prepare();
|
void Prepare();
|
||||||
void resize(const int width, const int height);
|
void Resize(const int width, const int height);
|
||||||
|
|
||||||
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 glm::vec2& mov);
|
void SetCamAngularMovement(const Vec2f& mov);
|
||||||
void setCamPos(const glm::vec2& 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 glm::vec3& color) { m_BackgroundColor = color; }
|
void SetBackgroundColor(const Vec3f& color) { m_BackgroundColor = color; }
|
||||||
|
|
||||||
glm::vec2 getCursorWorldPos(const glm::vec2& cursorPos, float aspectRatio, float zoom, float windowWidth, float windowHeight);
|
Vec2f GetCursorWorldPos(const Vec2f& cursorPos, float windowWidth, float windowHeight);
|
||||||
private:
|
private:
|
||||||
void updateIsometricView();
|
void InitShaders();
|
||||||
void updateIsometricFade();
|
void SetCamPos(const Vec3f& newPos);
|
||||||
void initShader();
|
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace render
|
} // namespace render
|
||||||
} // namespace td
|
} // namespace td
|
||||||
|
|
||||||
#endif /* RENDER_RENDERER_H_ */
|
|
||||||
|
|||||||
@@ -25,13 +25,13 @@ private:
|
|||||||
public:
|
public:
|
||||||
VertexCache() : m_VertexCount(0) {}
|
VertexCache() : m_VertexCount(0) {}
|
||||||
|
|
||||||
void addData(std::uint64_t index, std::vector<float> positions, std::vector<float> colors);
|
void AddData(std::uint64_t index, std::vector<float> positions, std::vector<float> colors);
|
||||||
void removeData(std::uint64_t index);
|
void RemoveData(std::uint64_t index);
|
||||||
void clear();
|
void Clear();
|
||||||
void updateVertexArray();
|
void UpdateVertexArray();
|
||||||
|
|
||||||
const GL::VertexArray& getVertexArray() const { return *m_VertexArray; }
|
const GL::VertexArray& GetVertexArray() const { return *m_VertexArray; }
|
||||||
bool isEmpty() const { return m_VertexArray == nullptr; }
|
bool IsEmpty() const { return m_VertexArray == nullptr; }
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace render
|
} // namespace render
|
||||||
|
|||||||
@@ -6,13 +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"
|
|
||||||
|
|
||||||
#include <glm/glm.hpp>
|
|
||||||
|
|
||||||
namespace td {
|
namespace td {
|
||||||
|
|
||||||
namespace client {
|
namespace client {
|
||||||
@@ -21,7 +18,6 @@ class ClientGame;
|
|||||||
|
|
||||||
} // namespace client
|
} // namespace client
|
||||||
|
|
||||||
|
|
||||||
namespace render {
|
namespace render {
|
||||||
|
|
||||||
class WorldRenderer : public game::WorldListener {
|
class WorldRenderer : public game::WorldListener {
|
||||||
@@ -30,57 +26,55 @@ private:
|
|||||||
Renderer* m_Renderer;
|
Renderer* m_Renderer;
|
||||||
game::World* m_World;
|
game::World* m_World;
|
||||||
std::unique_ptr<GL::VertexArray> m_WorldVao, m_MobVao, m_SelectTileVao;
|
std::unique_ptr<GL::VertexArray> m_WorldVao, m_MobVao, m_SelectTileVao;
|
||||||
glm::vec2 m_CamPos;
|
Vec2f m_CamPos;
|
||||||
glm::vec2 m_CursorPos;
|
Vec2f m_CursorPos;
|
||||||
glm::vec2 m_HoldCursorPos;
|
Vec2f m_HoldCursorPos;
|
||||||
glm::vec2 m_LastClicked;
|
Vec2f m_LastClicked;
|
||||||
float m_Zoom;
|
float m_Zoom;
|
||||||
float m_CamSensibility = 1;
|
float m_CamSensibility = 1;
|
||||||
bool m_PopupOpened = false;
|
bool m_PopupOpened = false;
|
||||||
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:
|
||||||
WorldRenderer(game::World* world, client::ClientGame* client);
|
WorldRenderer(game::World* world, client::ClientGame* client);
|
||||||
~WorldRenderer();
|
~WorldRenderer();
|
||||||
|
|
||||||
void loadModels();
|
void LoadModels();
|
||||||
|
|
||||||
static ImVec4 getImGuiTeamColor(game::TeamColor color);
|
void Update();
|
||||||
|
void Render();
|
||||||
|
|
||||||
void update();
|
void SetCamPos(float camX, float camY);
|
||||||
void render();
|
|
||||||
|
|
||||||
void setCamPos(float camX, float camY);
|
void MoveCam(float relativeX, float relativeY);
|
||||||
|
void ChangeZoom(float zoom);
|
||||||
void moveCam(float relativeX, float relativeY, float aspectRatio);
|
|
||||||
void changeZoom(float zoom);
|
|
||||||
|
|
||||||
// WorldListener
|
// WorldListener
|
||||||
|
|
||||||
virtual void OnTowerAdd(game::TowerPtr tower);
|
virtual void OnTowerAdd(game::TowerPtr tower);
|
||||||
virtual void OnTowerRemove(game::TowerPtr tower);
|
virtual void OnTowerRemove(game::TowerPtr tower);
|
||||||
private:
|
private:
|
||||||
void click();
|
void Click();
|
||||||
void renderWorld() const;
|
void RenderWorld() const;
|
||||||
void renderTowers() const;
|
void RenderTowers() const;
|
||||||
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();
|
void DetectMobHovering() const;
|
||||||
void detectMobHovering() const;
|
void DetectCastleHovering() const;
|
||||||
void detectCastleHovering() const;
|
void RenderTooltips() const;
|
||||||
void renderTooltips() const;
|
void RemoveTower();
|
||||||
void removeTower();
|
Vec2f GetCursorWorldPos() const;
|
||||||
glm::vec2 getCursorWorldPos() const;
|
Vec2f GetClickWorldPos() const;
|
||||||
glm::vec2 getClickWorldPos() const;
|
|
||||||
|
|
||||||
void updateCursorPos();
|
void UpdateCursorPos();
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace render
|
} // namespace render
|
||||||
|
|||||||
@@ -18,10 +18,10 @@ private:
|
|||||||
public:
|
public:
|
||||||
CastleTooltip(client::Client* client);
|
CastleTooltip(client::Client* client);
|
||||||
|
|
||||||
virtual void render();
|
virtual void Render();
|
||||||
|
|
||||||
void setCastle(const game::TeamCastle* castle) { m_Castle = castle; }
|
void SetCastle(const game::TeamCastle* castle) { m_Castle = castle; }
|
||||||
bool isShown() { return m_Castle != nullptr; }
|
bool IsShown() { return m_Castle != nullptr; }
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace gui
|
} // namespace gui
|
||||||
|
|||||||
@@ -13,7 +13,7 @@ private:
|
|||||||
public:
|
public:
|
||||||
FrameMenu(client::Client* client);
|
FrameMenu(client::Client* client);
|
||||||
|
|
||||||
virtual void render();
|
virtual void Render();
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace gui
|
} // namespace gui
|
||||||
|
|||||||
@@ -11,13 +11,13 @@ private:
|
|||||||
public:
|
public:
|
||||||
GameMenu(client::Client* client);
|
GameMenu(client::Client* client);
|
||||||
|
|
||||||
virtual void render();
|
virtual void Render();
|
||||||
private:
|
private:
|
||||||
void showTPS();
|
void ShowTPS();
|
||||||
void showStats();
|
void ShowStats();
|
||||||
void showPlayers();
|
void ShowPlayers();
|
||||||
void showLobbyProgress();
|
void ShowLobbyProgress();
|
||||||
void showTeamSelection();
|
void ShowTeamSelection();
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace gui
|
} // namespace gui
|
||||||
|
|||||||
@@ -14,13 +14,13 @@ private:
|
|||||||
public:
|
public:
|
||||||
GuiManager() {}
|
GuiManager() {}
|
||||||
|
|
||||||
void renderWidgets() {
|
void RenderWidgets() {
|
||||||
for (auto& widget : m_Widgets) {
|
for (auto& widget : m_Widgets) {
|
||||||
widget->render();
|
widget->Render();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void addWidget(std::unique_ptr<GuiWidget>&& widget) {
|
void AddWidget(std::unique_ptr<GuiWidget>&& widget) {
|
||||||
m_Widgets.push_back(std::move(widget));
|
m_Widgets.push_back(std::move(widget));
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -14,9 +14,9 @@ protected:
|
|||||||
public:
|
public:
|
||||||
GuiWidget(client::Client* client) : m_Client(client) {}
|
GuiWidget(client::Client* client) : m_Client(client) {}
|
||||||
|
|
||||||
client::Client* getClient() { return m_Client; }
|
client::Client* GetClient() { return m_Client; }
|
||||||
|
|
||||||
virtual void render() = 0;
|
virtual void Render() = 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace gui
|
} // namespace gui
|
||||||
|
|||||||
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
|
||||||
@@ -26,11 +26,11 @@ public:
|
|||||||
MainMenu(client::Client* client);
|
MainMenu(client::Client* client);
|
||||||
~MainMenu();
|
~MainMenu();
|
||||||
|
|
||||||
virtual void render();
|
virtual void Render();
|
||||||
|
|
||||||
const server::Server* getServer() const { return m_Server.get(); }
|
const server::Server* GetServer() const { return m_Server.get(); }
|
||||||
private:
|
private:
|
||||||
bool startServer();
|
bool StartServer();
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace gui
|
} // namespace gui
|
||||||
|
|||||||
@@ -18,10 +18,10 @@ private:
|
|||||||
public:
|
public:
|
||||||
MobTooltip(client::Client* client);
|
MobTooltip(client::Client* client);
|
||||||
|
|
||||||
virtual void render();
|
virtual void Render();
|
||||||
|
|
||||||
void setMob(const game::Mob* mob) { m_Mob = mob; }
|
void SetMob(const game::Mob* mob) { m_Mob = mob; }
|
||||||
bool isShown() { return m_Mob != nullptr; }
|
bool IsShown() { return m_Mob != nullptr; }
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace gui
|
} // namespace gui
|
||||||
|
|||||||
@@ -12,14 +12,18 @@ 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);
|
||||||
|
|
||||||
virtual void render();
|
void SetCooldown(float cooldown);
|
||||||
|
|
||||||
|
virtual void Render();
|
||||||
private:
|
private:
|
||||||
void setSummonMax(int valueIndex);
|
void SetSummonMax(int valueIndex);
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace gui
|
} // namespace gui
|
||||||
|
|||||||
@@ -37,12 +37,12 @@ public:
|
|||||||
TowerGui(SDL_Window* wndow, SDL_GLContext glContext, td::render::Renderer* renderer);
|
TowerGui(SDL_Window* wndow, SDL_GLContext glContext, td::render::Renderer* renderer);
|
||||||
~TowerGui();
|
~TowerGui();
|
||||||
|
|
||||||
void render();
|
void Render();
|
||||||
private:
|
private:
|
||||||
void initWidgets();
|
void InitWidgets();
|
||||||
void tick();
|
void Tick();
|
||||||
void beginFrame();
|
void BeginFrame();
|
||||||
void endFrame();
|
void EndFrame();
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace render
|
} // namespace render
|
||||||
|
|||||||
@@ -2,20 +2,20 @@
|
|||||||
|
|
||||||
#include "GuiWidget.h"
|
#include "GuiWidget.h"
|
||||||
|
|
||||||
#include <glm/glm.hpp>
|
#include "Defines.h"
|
||||||
|
|
||||||
namespace td {
|
namespace td {
|
||||||
namespace gui {
|
namespace gui {
|
||||||
|
|
||||||
class TowerPlacePopup : public GuiWidget {
|
class TowerPlacePopup : public GuiWidget {
|
||||||
private:
|
private:
|
||||||
glm::vec2 m_ClickWorldPos;
|
Vec2f m_ClickWorldPos;
|
||||||
public:
|
public:
|
||||||
TowerPlacePopup(client::Client* client);
|
TowerPlacePopup(client::Client* client);
|
||||||
|
|
||||||
virtual void render();
|
virtual void Render();
|
||||||
|
|
||||||
void setClickPos(const glm::vec2& worldPos);
|
void SetClickPos(const Vec2f& worldPos);
|
||||||
private:
|
private:
|
||||||
static constexpr float m_TowerPopupTileWidth = 200.0f;
|
static constexpr float m_TowerPopupTileWidth = 200.0f;
|
||||||
static constexpr float m_TowerPopupTileHeight = 200.0f;
|
static constexpr float m_TowerPopupTileHeight = 200.0f;
|
||||||
|
|||||||
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,27 +2,34 @@
|
|||||||
|
|
||||||
#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:
|
||||||
void checkUpdates();
|
void CheckUpdates();
|
||||||
bool isUpdateChecked();
|
bool IsUpdateChecked();
|
||||||
void renderErrorPopup();
|
void RenderErrorPopup();
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace gui
|
} // namespace gui
|
||||||
|
|||||||
@@ -107,8 +107,20 @@ namespace ImGui
|
|||||||
}
|
}
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifdef __ANDROID__
|
#include "render/GL.h"
|
||||||
#define IMGUI_IMPL_OPENGL_ES3
|
|
||||||
#else
|
#if defined(__ANDROID__)
|
||||||
|
#define IMGUI_IMPL_OPENGL_LOADER_ES3
|
||||||
|
#elif defined(TD_IMPL_OPENGL_LOADER_GL3W)
|
||||||
|
#define IMGUI_IMPL_OPENGL_LOADER_GL3W
|
||||||
|
#elif defined(TD_IMPL_OPENGL_LOADER_GLEW)
|
||||||
|
#define IMGUI_IMPL_OPENGL_LOADER_GLEW
|
||||||
|
#elif defined(TD_IMPL_OPENGL_LOADER_GLAD)
|
||||||
|
#define IMGUI_IMPL_OPENGL_LOADER_GLAD
|
||||||
|
#elif defined(TD_IMPL_OPENGL_LOADER_GLBINDING2)
|
||||||
#define IMGUI_IMPL_OPENGL_LOADER_GLBINDING2
|
#define IMGUI_IMPL_OPENGL_LOADER_GLBINDING2
|
||||||
|
#elif defined(TD_IMPL_OPENGL_LOADER_GLBINDING3)
|
||||||
|
#define IMGUI_IMPL_OPENGL_LOADER_GLBINDING3
|
||||||
|
#else
|
||||||
|
#define IMGUI_IMPL_OPENGL_LOADER_CUSTOM
|
||||||
#endif
|
#endif
|
||||||
@@ -17,8 +17,9 @@
|
|||||||
namespace GL {
|
namespace GL {
|
||||||
|
|
||||||
struct VertexAttribPointer {
|
struct VertexAttribPointer {
|
||||||
unsigned int m_Index, m_Size;
|
unsigned int m_Index;
|
||||||
int m_Offset;
|
unsigned int m_Size;
|
||||||
|
unsigned int m_Offset;
|
||||||
};
|
};
|
||||||
|
|
||||||
class VertexBuffer {
|
class VertexBuffer {
|
||||||
@@ -27,6 +28,7 @@ private:
|
|||||||
std::vector<VertexAttribPointer> m_VertexAttribs;
|
std::vector<VertexAttribPointer> m_VertexAttribs;
|
||||||
public:
|
public:
|
||||||
REMOVE_COPY(VertexBuffer);
|
REMOVE_COPY(VertexBuffer);
|
||||||
|
|
||||||
VertexBuffer(VertexBuffer&& other) {
|
VertexBuffer(VertexBuffer&& other) {
|
||||||
m_VertexAttribs = std::move(other.m_VertexAttribs);
|
m_VertexAttribs = std::move(other.m_VertexAttribs);
|
||||||
m_ID = other.m_ID;
|
m_ID = other.m_ID;
|
||||||
@@ -34,12 +36,14 @@ public:
|
|||||||
other.m_ID = 0;
|
other.m_ID = 0;
|
||||||
other.m_DataStride = 0;
|
other.m_DataStride = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
VertexBuffer(const std::vector<float>& data, unsigned int stride);
|
VertexBuffer(const std::vector<float>& data, unsigned int stride);
|
||||||
~VertexBuffer();
|
~VertexBuffer();
|
||||||
void bind() const;
|
|
||||||
void unbind() const;
|
void Bind() const;
|
||||||
void addVertexAttribPointer(unsigned int index, unsigned int coordinateSize, unsigned int offset);
|
void Unbind() const;
|
||||||
void bindVertexAttribs() const;
|
void AddVertexAttribPointer(unsigned int index, unsigned int coordinateSize, unsigned int offset);
|
||||||
|
void BindVertexAttribs() const;
|
||||||
};
|
};
|
||||||
|
|
||||||
class VertexArray {
|
class VertexArray {
|
||||||
@@ -48,6 +52,7 @@ private:
|
|||||||
std::vector<VertexBuffer> m_VertexBuffers; //use to destroy vbos when become unused
|
std::vector<VertexBuffer> m_VertexBuffers; //use to destroy vbos when become unused
|
||||||
public:
|
public:
|
||||||
REMOVE_COPY(VertexArray);
|
REMOVE_COPY(VertexArray);
|
||||||
|
|
||||||
VertexArray(VertexArray&& other) {
|
VertexArray(VertexArray&& other) {
|
||||||
m_ID = other.m_ID;
|
m_ID = other.m_ID;
|
||||||
m_VertexCount = other.m_VertexCount;
|
m_VertexCount = other.m_VertexCount;
|
||||||
@@ -55,12 +60,14 @@ public:
|
|||||||
other.m_VertexCount = 0;
|
other.m_VertexCount = 0;
|
||||||
other.m_ID = 0;
|
other.m_ID = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
VertexArray(unsigned int vertexCount);
|
VertexArray(unsigned int vertexCount);
|
||||||
~VertexArray();
|
~VertexArray();
|
||||||
unsigned int getVertexCount() const { return m_VertexCount; }
|
|
||||||
void bindVertexBuffer(VertexBuffer& vbo);
|
unsigned int GetVertexCount() const { return m_VertexCount; }
|
||||||
void bind() const;
|
void BindVertexBuffer(VertexBuffer& vbo);
|
||||||
void unbind() const;
|
void Bind() const;
|
||||||
|
void Unbind() const;
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -9,7 +9,9 @@
|
|||||||
#define RENDER_LOADER_TEXTURELOADER_H_
|
#define RENDER_LOADER_TEXTURELOADER_H_
|
||||||
|
|
||||||
namespace TextureLoader {
|
namespace TextureLoader {
|
||||||
const unsigned int loadGLTexture(const char* fileName);
|
|
||||||
|
unsigned int LoadGLTexture(const char* fileName);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -13,10 +13,10 @@ struct RenderData {
|
|||||||
std::vector<float> colors;
|
std::vector<float> colors;
|
||||||
};
|
};
|
||||||
|
|
||||||
GL::VertexArray loadMobModel();
|
GL::VertexArray LoadMobModel();
|
||||||
GL::VertexArray loadWorldModel(const td::game::World* world);
|
GL::VertexArray LoadWorldModel(const td::game::World* world);
|
||||||
GL::VertexArray loadTileSelectModel();
|
GL::VertexArray LoadTileSelectModel();
|
||||||
RenderData loadTowerModel(game::TowerPtr tower);
|
RenderData LoadTowerModel(game::TowerPtr tower);
|
||||||
|
|
||||||
} // namespace WorldLoader
|
} // namespace WorldLoader
|
||||||
|
|
||||||
|
|||||||
@@ -2,17 +2,27 @@
|
|||||||
|
|
||||||
#include "ShaderProgram.h"
|
#include "ShaderProgram.h"
|
||||||
|
|
||||||
|
namespace td {
|
||||||
|
namespace shader {
|
||||||
|
|
||||||
class EntityShader : public ShaderProgram {
|
class EntityShader : public ShaderProgram {
|
||||||
private:
|
private:
|
||||||
unsigned int location_cam = 0, location_zoom = 0, location_aspect_ratio = 0, location_translation = 0, location_viewtype = 0;
|
unsigned int m_LocationProjectionMatrix = 0;
|
||||||
|
unsigned int m_LocationViewMatrix = 0;
|
||||||
|
unsigned int m_LocationPosition = 0;
|
||||||
|
unsigned int m_LocationColorEffect = 0;
|
||||||
protected:
|
protected:
|
||||||
void getAllUniformLocation();
|
virtual void GetAllUniformLocation();
|
||||||
public:
|
public:
|
||||||
EntityShader();
|
EntityShader();
|
||||||
void loadShader();
|
|
||||||
void setCamPos(const glm::vec2& camPos);
|
void LoadShader();
|
||||||
void setZoom(float zoom);
|
|
||||||
void setAspectRatio(float aspectRatio);
|
void SetColorEffect(const Vec3f& color);
|
||||||
void setModelPos(const glm::vec2& modelPos);
|
void SetProjectionMatrix(const Mat4f& proj) const;
|
||||||
void setIsometricView(float isometric);
|
void SetViewMatrix(const Mat4f& view) const;
|
||||||
|
void SetModelPos(const Vec3f& pos) const;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
} // namespace shader
|
||||||
|
} // namespace td
|
||||||
|
|||||||
@@ -1,44 +1,43 @@
|
|||||||
/*
|
#pragma once
|
||||||
* ShaderProgram.h
|
|
||||||
*
|
|
||||||
* Created on: 31 janv. 2020
|
|
||||||
* Author: simon
|
|
||||||
*/
|
|
||||||
|
|
||||||
#ifndef RENDER_SHADERS_SHADERPROGRAM_H_
|
|
||||||
#define RENDER_SHADERS_SHADERPROGRAM_H_
|
|
||||||
|
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <glm/glm.hpp>
|
#include "Defines.h"
|
||||||
#include "render/GL.h"
|
#include "render/GL.h"
|
||||||
|
|
||||||
|
namespace td {
|
||||||
|
namespace shader {
|
||||||
|
|
||||||
class ShaderProgram {
|
class ShaderProgram {
|
||||||
public:
|
public:
|
||||||
ShaderProgram();
|
ShaderProgram();
|
||||||
virtual ~ShaderProgram();
|
virtual ~ShaderProgram();
|
||||||
void start() const;
|
|
||||||
void stop() const;
|
void Start() const;
|
||||||
void loadProgramFile(const std::string& vertexFile, const std::string& fragmentFile);
|
void Stop() const;
|
||||||
void loadProgram(const std::string& vertexSource, const std::string& fragmentSource);
|
|
||||||
|
void LoadProgramFile(const std::string& vertexFile, const std::string& fragmentFile);
|
||||||
|
void LoadProgram(const std::string& vertexSource, const std::string& fragmentSource);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
virtual void getAllUniformLocation() = 0;
|
virtual void GetAllUniformLocation() = 0;
|
||||||
int getUniformLocation(const std::string& uniformName)const;
|
int GetUniformLocation(const std::string& uniformName) const;
|
||||||
void loadFloat(const int location, const float value)const;
|
|
||||||
void loadInt(const int& location, const int& value)const;
|
void LoadFloat(unsigned int location, float value) const;
|
||||||
void loadVector(const int& location, const glm::vec2& vector)const;
|
void LoadInt(unsigned int location, int value) const;
|
||||||
void loadVector(const int& location, const glm::vec3& vector)const;
|
void LoadVector(unsigned int location, const Vec2f& vector) const;
|
||||||
void loadVector(const int& location, const glm::vec4& vector)const;
|
void LoadVector(unsigned int location, const Vec3f& vector) const;
|
||||||
void loadBoolean(const int& location, const bool& value)const;
|
void LoadBoolean(unsigned int location, bool value) const;
|
||||||
void loadMatrix(const int& location, const glm::mat4& matrix);
|
void LoadMat4(unsigned int location, const Mat4f& mat) const;
|
||||||
void cleanUp() const;
|
void CleanUp() const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
unsigned int programID;
|
unsigned int m_ProgramID;
|
||||||
unsigned int vertexShaderID;
|
unsigned int m_VertexShaderID;
|
||||||
unsigned int fragmentShaderID;
|
unsigned int m_FragmentShaderID;
|
||||||
int loadShaderFromFile(const std::string& file, GLenum type);
|
|
||||||
int loadShader(const std::string& source, GLenum type);
|
unsigned int LoadShaderFromFile(const std::string& file, GLenum type);
|
||||||
|
unsigned int LoadShader(const std::string& source, GLenum type);
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif /* RENDER_SHADERS_SHADERPROGRAM_H_ */
|
} // namespace shader
|
||||||
|
} // namespace td
|
||||||
@@ -1,27 +1,22 @@
|
|||||||
/*
|
#pragma once
|
||||||
* GameShader.h
|
|
||||||
*
|
|
||||||
* Created on: 4 nov. 2020
|
|
||||||
* Author: simon
|
|
||||||
*/
|
|
||||||
|
|
||||||
#ifndef RENDER_SHADERS_GAMESHADER_H_
|
|
||||||
#define RENDER_SHADERS_GAMESHADER_H_
|
|
||||||
|
|
||||||
#include "ShaderProgram.h"
|
#include "ShaderProgram.h"
|
||||||
|
|
||||||
|
namespace td {
|
||||||
|
namespace shader {
|
||||||
|
|
||||||
class WorldShader : public ShaderProgram {
|
class WorldShader : public ShaderProgram {
|
||||||
private:
|
private:
|
||||||
unsigned int location_cam = 0, location_zoom = 0, location_aspect_ratio = 0, location_viewtype = 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 glm::vec2& 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);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif /* RENDER_SHADERS_GAMESHADER_H_ */
|
} // namespace shader
|
||||||
|
} // namespace td
|
||||||
|
|||||||
@@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
#include "misc/DataBuffer.h"
|
#include "misc/DataBuffer.h"
|
||||||
|
|
||||||
#define TD_VERSION "alpha-0.2.0"
|
#define TD_VERSION "alpha-0.3.0"
|
||||||
|
|
||||||
namespace td {
|
namespace td {
|
||||||
namespace utils {
|
namespace utils {
|
||||||
@@ -18,26 +18,26 @@ private:
|
|||||||
public:
|
public:
|
||||||
Updater() : m_Progress(0), m_DownloadComplete(false), m_FileWrited(false), m_CancelDownload(false) {}
|
Updater() : m_Progress(0), m_DownloadComplete(false), m_FileWrited(false), m_CancelDownload(false) {}
|
||||||
|
|
||||||
bool checkUpdate();
|
bool CheckUpdate();
|
||||||
void downloadUpdate();
|
void DownloadUpdate();
|
||||||
void cancelDownload() { m_CancelDownload = true; m_Progress = 0.0f; m_DownloadComplete = false; }
|
void CancelDownload() { m_CancelDownload = true; m_Progress = 0.0f; m_DownloadComplete = false; }
|
||||||
bool writeFile();
|
bool WriteFile();
|
||||||
|
|
||||||
void clearCache() { m_FileBuffer.Clear(); }
|
void ClearCache() { m_FileBuffer.Clear(); }
|
||||||
|
|
||||||
float getDownloadProgress() { return m_Progress; }
|
float GetDownloadProgress() { return m_Progress; }
|
||||||
bool isDownloadComplete() { return m_DownloadComplete; }
|
bool IsDownloadComplete() { return m_DownloadComplete; }
|
||||||
bool isFileWrited() { return m_FileWrited; }
|
bool IsFileWrited() { return m_FileWrited; }
|
||||||
|
|
||||||
static std::string getLocalFilePath();
|
static std::string GetLocalFilePath();
|
||||||
static void removeOldFile();
|
static void RemoveOldFile();
|
||||||
|
|
||||||
static std::string getCurrentVersion() { return TD_VERSION; }
|
static std::string GetCurrentVersion() { return TD_VERSION; }
|
||||||
std::string getLastVersion() { return m_LastVersion; }
|
std::string GetLastVersion() { return m_LastVersion; }
|
||||||
|
|
||||||
bool canUpdate();
|
bool CanUpdate();
|
||||||
private:
|
private:
|
||||||
std::string getDownloadFileURL();
|
std::string GetDownloadFileURL();
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace utils
|
} // namespace utils
|
||||||
|
|||||||
@@ -11,19 +11,19 @@
|
|||||||
|
|
||||||
namespace Display {
|
namespace Display {
|
||||||
|
|
||||||
bool create();
|
bool Create();
|
||||||
void render();
|
void Render();
|
||||||
void update();
|
void Update();
|
||||||
void destroy();
|
void Destroy();
|
||||||
void pollEvents();
|
void PollEvents();
|
||||||
|
|
||||||
bool isCloseRequested();
|
bool IsCloseRequested();
|
||||||
|
|
||||||
bool isMouseDown(int button);
|
bool IsMouseDown(int button);
|
||||||
|
|
||||||
float getAspectRatio();
|
float GetAspectRatio();
|
||||||
int getWindowWidth();
|
int GetWindowWidth();
|
||||||
int getWindowHeight();
|
int GetWindowHeight();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -26,14 +26,14 @@ int main(int argc, const char* args[]) {
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
// remove the outdated binary
|
// remove the outdated binary
|
||||||
td::utils::Updater::removeOldFile();
|
td::utils::Updater::RemoveOldFile();
|
||||||
|
|
||||||
Display::create();
|
Display::Create();
|
||||||
while (!Display::isCloseRequested()) {
|
while (!Display::IsCloseRequested()) {
|
||||||
Display::pollEvents();
|
Display::PollEvents();
|
||||||
Display::render();
|
Display::Render();
|
||||||
Display::update();
|
Display::Update();
|
||||||
}
|
}
|
||||||
Display::destroy();
|
Display::Destroy();
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
@@ -11,13 +11,13 @@ Game::~Game() {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void Game::tick(std::uint64_t delta) {
|
void Game::Tick(std::uint64_t delta) {
|
||||||
if (m_GameState == GameState::Game) {
|
if (m_GameState == GameState::Game) {
|
||||||
m_World->tick(delta);
|
m_World->Tick(delta);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Player* Game::getPlayerById(PlayerID id) {
|
Player* Game::GetPlayerById(PlayerID id) {
|
||||||
auto it = m_Players.find(id);
|
auto it = m_Players.find(id);
|
||||||
|
|
||||||
if (it == m_Players.end()) return nullptr;
|
if (it == m_Players.end()) return nullptr;
|
||||||
@@ -25,7 +25,7 @@ Player* Game::getPlayerById(PlayerID id) {
|
|||||||
return &it->second;
|
return &it->second;
|
||||||
}
|
}
|
||||||
|
|
||||||
const Player* Game::getPlayerById(PlayerID id) const {
|
const Player* Game::GetPlayerById(PlayerID id) const {
|
||||||
auto it = m_Players.find(id);
|
auto it = m_Players.find(id);
|
||||||
|
|
||||||
if (it == m_Players.end()) return nullptr;
|
if (it == m_Players.end()) return nullptr;
|
||||||
|
|||||||
@@ -28,7 +28,7 @@ Connexion::Connexion(protocol::PacketDispatcher* dispatcher, network::TCPSocket&
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Connexion::updateSocket() {
|
bool Connexion::UpdateSocket() {
|
||||||
if (m_Socket.GetStatus() != network::Socket::Connected)
|
if (m_Socket.GetStatus() != network::Socket::Connected)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
@@ -47,13 +47,13 @@ bool Connexion::updateSocket() {
|
|||||||
protocol::PacketType packetType;
|
protocol::PacketType packetType;
|
||||||
decompressed >> packetType;
|
decompressed >> packetType;
|
||||||
|
|
||||||
PacketPtr packet = protocol::PacketFactory::createPacket(packetType, decompressed);
|
PacketPtr packet = protocol::PacketFactory::CreatePacket(packetType, decompressed);
|
||||||
GetDispatcher()->Dispatch(packet);
|
GetDispatcher()->Dispatch(packet);
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Connexion::connect(const std::string& address, std::uint16_t port) {
|
bool Connexion::Connect(const std::string& address, std::uint16_t port) {
|
||||||
if (!m_Socket.Connect(address, port)) {
|
if (!m_Socket.Connect(address, port)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@@ -61,11 +61,11 @@ bool Connexion::connect(const std::string& address, std::uint16_t port) {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Connexion::sendPacket(const protocol::Packet* packet) {
|
void Connexion::SendPacket(const protocol::Packet* packet) {
|
||||||
network::SendPacket(packet->Serialize(), m_Socket);
|
network::SendPacket(packet->Serialize(), m_Socket);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Connexion::closeConnection() {
|
void Connexion::CloseConnection() {
|
||||||
m_Socket.Disconnect();
|
m_Socket.Disconnect();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -8,136 +8,140 @@
|
|||||||
namespace td {
|
namespace td {
|
||||||
namespace game {
|
namespace game {
|
||||||
|
|
||||||
bool Mob::isImmuneTo(TowerType type) {
|
bool Mob::IsImmuneTo(TowerType type) {
|
||||||
return std::find(getTowerImmunities().begin(), getTowerImmunities().end(), type) != getTowerImmunities().end();
|
return std::find(GetTowerImmunities().begin(), GetTowerImmunities().end(), type) != GetTowerImmunities().end();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Mob::isImmuneTo(EffectType type) {
|
bool Mob::IsImmuneTo(EffectType type) {
|
||||||
return std::find(getEffectImmunities().begin(), getEffectImmunities().end(), type) != getEffectImmunities().end();
|
return std::find(GetEffectImmunities().begin(), GetEffectImmunities().end(), type) != GetEffectImmunities().end();
|
||||||
}
|
}
|
||||||
|
|
||||||
EffectDuration& Mob::getEffect(EffectType effectType) {
|
EffectDuration& Mob::GetEffect(EffectType effectType) {
|
||||||
return *std::find_if(m_Effects.begin(), m_Effects.end(), [&effectType](EffectDuration effect) { return effect.type == effectType;});
|
return *std::find_if(m_Effects.begin(), m_Effects.end(), [&effectType](EffectDuration effect) { return effect.type == effectType;});
|
||||||
}
|
}
|
||||||
|
|
||||||
void Mob::addEffect(EffectType effectType, float durationSec, Tower* tower) {
|
void Mob::AddEffect(EffectType effectType, float durationSec, Tower* tower) {
|
||||||
if (isImmuneTo(effectType))
|
if (IsImmuneTo(effectType))
|
||||||
return;
|
return;
|
||||||
if (hasEffect(effectType)) {
|
if (HasEffect(effectType)) {
|
||||||
EffectDuration& effect = getEffect(effectType);
|
EffectDuration& effect = GetEffect(effectType);
|
||||||
if (effect.duration < durationSec)
|
if (effect.duration < durationSec)
|
||||||
effect.duration = durationSec; // setting new duration if it's greater then the actual
|
effect.duration = durationSec; // Setting new duration if it's greater then the actual
|
||||||
} else {
|
} else {
|
||||||
m_Effects.push_back({ effectType, durationSec, tower });
|
m_Effects.push_back({ effectType, durationSec, tower });
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void Mob::attackCastle(std::uint64_t delta, World* world) {
|
void Mob::AttackCastle(std::uint64_t delta, World* world) {
|
||||||
if(!hasReachedEnemyCastle()) return;
|
if (!HasReachedEnemyCastle()) return;
|
||||||
|
|
||||||
if (m_AttackTimer.update(delta)) {
|
if (m_AttackTimer.Update(delta)) {
|
||||||
world->getMobNotifier().notifyListeners(&MobListener::OnMobCastleDamage, this, m_CastleTarget, getStats()->getDamage());
|
world->GetMobNotifier().NotifyListeners(&MobListener::OnMobCastleDamage, this, m_CastleTarget, GetStats()->GetDamage());
|
||||||
m_AttackTimer.applyCooldown();
|
m_AttackTimer.ApplyCooldown();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void Mob::walk(std::uint64_t delta, World* world) {
|
void Mob::Walk(std::uint64_t delta, World* world) {
|
||||||
float mobWalkSpeed = getStats()->getMovementSpeed();
|
float mobWalkSpeed = GetStats()->GetMovementSpeed();
|
||||||
|
|
||||||
float walkAmount = mobWalkSpeed * ((float)delta / 1000.0f);
|
float walkAmount = mobWalkSpeed * (static_cast<float>(delta) / 1000.0f);
|
||||||
|
|
||||||
if (hasEffect(EffectType::Slowness))
|
if (HasEffect(EffectType::Slowness))
|
||||||
walkAmount *= 0.70; // walk 30% slower
|
walkAmount *= 0.70; // walk 30% slower
|
||||||
|
|
||||||
switch (getDirection()) {
|
switch (GetDirection()) {
|
||||||
case Direction::NegativeX: {
|
case Direction::NegativeX: {
|
||||||
setCenterX(getCenterX() - walkAmount);
|
SetCenterX(GetCenterX() - walkAmount);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case Direction::PositiveX: {
|
case Direction::PositiveX: {
|
||||||
setCenterX(getCenterX() + walkAmount);
|
SetCenterX(GetCenterX() + walkAmount);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case Direction::NegativeY: {
|
case Direction::NegativeY: {
|
||||||
setCenterY(getCenterY() - walkAmount);
|
SetCenterY(GetCenterY() - walkAmount);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case Direction::PositiveY: {
|
case Direction::PositiveY: {
|
||||||
setCenterY(getCenterY() + walkAmount);
|
SetCenterY(GetCenterY() + walkAmount);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
void Mob::move(std::uint64_t delta, World* world) {
|
void Mob::Move(std::uint64_t delta, World* world) {
|
||||||
TilePtr tile = world->getTile(getCenter().getX(), getCenter().getY());
|
TilePtr tile = world->GetTile(GetCenter().GetX(), GetCenter().GetY());
|
||||||
|
|
||||||
if (tile != nullptr && tile->getType() == TileType::Walk) {
|
if (tile != nullptr && tile->GetType() == TileType::Walk) {
|
||||||
WalkableTilePtr walkTile = std::static_pointer_cast<WalkableTile>(tile);
|
WalkableTilePtr walkTile = std::static_pointer_cast<WalkableTile>(tile);
|
||||||
changeDirection(*walkTile, world);
|
ChangeDirection(*walkTile, world);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (hasReachedEnemyCastle()) return;
|
if (HasReachedEnemyCastle()) return;
|
||||||
|
|
||||||
walk(delta, world);
|
Walk(delta, world);
|
||||||
|
|
||||||
TeamColor mobTeam = world->getPlayerById(getSender())->getTeamColor();
|
TeamColor mobTeam = world->GetPlayerById(GetSender())->GetTeamColor();
|
||||||
|
|
||||||
TeamCastle* enemyCastle = nullptr;
|
TeamCastle* enemyCastle = nullptr;
|
||||||
|
|
||||||
if (mobTeam == TeamColor::Red) {
|
if (mobTeam == TeamColor::Red) {
|
||||||
enemyCastle = &world->getBlueTeam().getCastle();
|
enemyCastle = &world->GetBlueTeam().GetCastle();
|
||||||
} else if (mobTeam == TeamColor::Blue) {
|
} else if (mobTeam == TeamColor::Blue) {
|
||||||
enemyCastle = &world->getRedTeam().getCastle();
|
enemyCastle = &world->GetRedTeam().GetCastle();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isTouchingCastle(*enemyCastle)) {
|
if (IsTouchingCastle(*enemyCastle)) {
|
||||||
moveBack(*enemyCastle, world);
|
MoveBack(*enemyCastle, world);
|
||||||
setMobReachedCastle(enemyCastle);
|
SetMobReachedCastle(enemyCastle);
|
||||||
|
|
||||||
world->getMobNotifier().notifyListeners(&MobListener::OnMobTouchCastle, this, enemyCastle);
|
world->GetMobNotifier().NotifyListeners(&MobListener::OnMobTouchCastle, this, enemyCastle);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void Mob::moveBack(const TeamCastle& enemyCastle, World* world) {
|
void Mob::MoveBack(const TeamCastle& enemyCastle, World* world) {
|
||||||
switch (getDirection()) {
|
switch (GetDirection()) {
|
||||||
case Direction::NegativeX: {
|
case Direction::NegativeX: {
|
||||||
setCenterX(enemyCastle.getBottomRight().getX() + getWidth() / 2.0f);
|
SetCenterX(enemyCastle.GetBottomRight().GetX() + GetWidth() / 2.0f);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case Direction::PositiveX: {
|
case Direction::PositiveX: {
|
||||||
setCenterX(enemyCastle.getTopLeft().getX() - getWidth() / 2.0f);
|
SetCenterX(enemyCastle.GetTopLeft().GetX() - GetWidth() / 2.0f);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case Direction::NegativeY: {
|
case Direction::NegativeY: {
|
||||||
setCenterY(enemyCastle.getBottomRight().getY() + getHeight() / 2.0f);
|
SetCenterY(enemyCastle.GetBottomRight().GetY() + GetHeight() / 2.0f);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case Direction::PositiveY: {
|
case Direction::PositiveY: {
|
||||||
setCenterY(enemyCastle.getTopLeft().getY() - getHeight() / 2.0f);
|
SetCenterY(enemyCastle.GetTopLeft().GetY() - GetHeight() / 2.0f);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
void Mob::changeDirection(const WalkableTile& tile, World* world) {
|
void Mob::ChangeDirection(const WalkableTile& tile, World* world) {
|
||||||
if (getDirection() == tile.direction) return;
|
if (GetDirection() == tile.direction) return;
|
||||||
|
|
||||||
float tileX = static_cast<float>(static_cast<std::int32_t>(getCenterX()));
|
float tileX = static_cast<float>(static_cast<std::int32_t>(GetCenterX()));
|
||||||
float tileY = static_cast<float>(static_cast<std::int32_t>(getCenterY()));
|
float tileY = static_cast<float>(static_cast<std::int32_t>(GetCenterY()));
|
||||||
|
|
||||||
switch (getDirection()) {
|
switch (GetDirection()) {
|
||||||
|
|
||||||
case Direction::PositiveY: {
|
case Direction::PositiveY: {
|
||||||
if (tile.direction == Direction::NegativeX) {
|
if (tile.direction == Direction::NegativeX) {
|
||||||
if (getTileY() > getTileX()) {
|
if (GetTileY() > GetTileX()) {
|
||||||
setCenterY(tileY + getTileX());
|
SetCenterY(tileY + GetTileX());
|
||||||
setDirection(tile.direction);
|
SetDirection(tile.direction);
|
||||||
}
|
}
|
||||||
} else { // tile->direction = Direction::PositiveX
|
} else { // tile->direction = Direction::PositiveX
|
||||||
if (getTileY() > 1 - getTileX()) {
|
if (GetTileY() > 1 - GetTileX()) {
|
||||||
setCenterY(tileY + (1 - getTileX()));
|
SetCenterY(tileY + (1 - GetTileX()));
|
||||||
setDirection(tile.direction);
|
SetDirection(tile.direction);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
@@ -145,14 +149,14 @@ void Mob::changeDirection(const WalkableTile& tile, World* world) {
|
|||||||
|
|
||||||
case Direction::NegativeY: {
|
case Direction::NegativeY: {
|
||||||
if (tile.direction == Direction::PositiveX) {
|
if (tile.direction == Direction::PositiveX) {
|
||||||
if (getTileY() < getTileX()) {
|
if (GetTileY() < GetTileX()) {
|
||||||
setCenterY(tileY + getTileX());
|
SetCenterY(tileY + GetTileX());
|
||||||
setDirection(tile.direction);
|
SetDirection(tile.direction);
|
||||||
}
|
}
|
||||||
} else { // tile.direction = Direction::NegativeX
|
} else { // tile.direction = Direction::NegativeX
|
||||||
if (getTileY() < 1 - getTileX()) {
|
if (GetTileY() < 1 - GetTileX()) {
|
||||||
setCenterY(tileY + (1 - getTileX()));
|
SetCenterY(tileY + (1 - GetTileX()));
|
||||||
setDirection(tile.direction);
|
SetDirection(tile.direction);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
@@ -160,14 +164,14 @@ void Mob::changeDirection(const WalkableTile& tile, World* world) {
|
|||||||
|
|
||||||
case Direction::PositiveX: {
|
case Direction::PositiveX: {
|
||||||
if (tile.direction == Direction::NegativeY) {
|
if (tile.direction == Direction::NegativeY) {
|
||||||
if (getTileX() > getTileY()) {
|
if (GetTileX() > GetTileY()) {
|
||||||
setCenterX(tileX + getTileY());
|
SetCenterX(tileX + GetTileY());
|
||||||
setDirection(tile.direction);
|
SetDirection(tile.direction);
|
||||||
}
|
}
|
||||||
} else { // tile.direction = Direction::PositiveY
|
} else { // tile.direction = Direction::PositiveY
|
||||||
if (getTileX() > 1 - getTileY()) {
|
if (GetTileX() > 1 - GetTileY()) {
|
||||||
setCenterX(tileX + (1 - getTileY()));
|
SetCenterX(tileX + (1 - GetTileY()));
|
||||||
setDirection(tile.direction);
|
SetDirection(tile.direction);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
@@ -175,52 +179,56 @@ void Mob::changeDirection(const WalkableTile& tile, World* world) {
|
|||||||
|
|
||||||
case Direction::NegativeX: {
|
case Direction::NegativeX: {
|
||||||
if (tile.direction == Direction::PositiveY) {
|
if (tile.direction == Direction::PositiveY) {
|
||||||
if (getTileX() < getTileY()) {
|
if (GetTileX() < GetTileY()) {
|
||||||
setCenterX(tileX + getTileY());
|
SetCenterX(tileX + GetTileY());
|
||||||
setDirection(tile.direction);
|
SetDirection(tile.direction);
|
||||||
}
|
}
|
||||||
} else { // tile.direction = Direction::NegativeY
|
} else { // tile.direction = Direction::NegativeY
|
||||||
if (getTileX() < 1 - getTileY()) {
|
if (GetTileX() < 1 - GetTileY()) {
|
||||||
setCenterX(tileX + (1 - getTileY()));
|
SetCenterX(tileX + (1 - GetTileY()));
|
||||||
setDirection(tile.direction);
|
SetDirection(tile.direction);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Mob::isTouchingCastle(const TeamCastle& enemyCastle) const {
|
bool Mob::IsTouchingCastle(const TeamCastle& enemyCastle) const {
|
||||||
return enemyCastle.collidesWith(*this);
|
return enemyCastle.CollidesWith(*this);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Mob::tick(std::uint64_t delta, World* world) {
|
void Mob::Tick(std::uint64_t delta, World* world) {
|
||||||
updateEffects(delta, world);
|
m_HitCooldown = std::max(0.0f, m_HitCooldown - static_cast<float>(delta / 1000.0f));
|
||||||
move(delta, world);
|
UpdateEffects(delta, world);
|
||||||
attackCastle(delta, world);
|
Move(delta, world);
|
||||||
|
AttackCastle(delta, world);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Mob::updateEffects(std::uint64_t delta, World* world) {
|
void Mob::UpdateEffects(std::uint64_t delta, World* world) {
|
||||||
float deltaSec = (float)delta / 1000.0f;
|
float deltaSec = static_cast<float>(delta / 1000.0f);
|
||||||
for (std::size_t i = 0; i < m_Effects.size(); i++) {
|
for (std::size_t i = 0; i < m_Effects.size(); i++) {
|
||||||
EffectDuration& effect = m_Effects[i];
|
EffectDuration& effect = m_Effects[i];
|
||||||
effect.duration -= deltaSec;
|
effect.duration -= deltaSec;
|
||||||
if (effect.duration < 0) { // effect has gone
|
if (effect.duration < 0) { // effect has gone
|
||||||
m_Effects.erase(m_Effects.begin() + i);
|
m_Effects.erase(m_Effects.begin() + static_cast<int>(i));
|
||||||
switch (effect.type) {
|
switch (effect.type) {
|
||||||
case EffectType::Fire: {
|
case EffectType::Fire: {
|
||||||
m_EffectFireTimer.reset();
|
m_EffectFireTimer.Reset();
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
case EffectType::Poison: {
|
case EffectType::Poison: {
|
||||||
m_EffectPoisonTimer.reset();
|
m_EffectPoisonTimer.Reset();
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
case EffectType::Heal: {
|
case EffectType::Heal: {
|
||||||
m_EffectHealTimer.reset();
|
m_EffectHealTimer.Reset();
|
||||||
}
|
}
|
||||||
|
|
||||||
default:
|
default:
|
||||||
@@ -228,24 +236,24 @@ void Mob::updateEffects(std::uint64_t delta, World* world) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (hasEffect(EffectType::Fire)) {
|
if (HasEffect(EffectType::Fire)) {
|
||||||
if (m_EffectFireTimer.update(delta)) {
|
if (m_EffectFireTimer.Update(delta)) {
|
||||||
world->getMobNotifier().notifyListeners(&MobListener::OnMobDamage, this, 3.0f, getEffect(EffectType::Fire).tower);
|
world->GetMobNotifier().NotifyListeners(&MobListener::OnMobDamage, this, 3.0f, GetEffect(EffectType::Fire).tower);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (hasEffect(EffectType::Poison)) {
|
if (HasEffect(EffectType::Poison)) {
|
||||||
if (m_EffectPoisonTimer.update(delta)) {
|
if (m_EffectPoisonTimer.Update(delta)) {
|
||||||
world->getMobNotifier().notifyListeners(&MobListener::OnMobDamage, this, 1.0f, getEffect(EffectType::Poison).tower);
|
world->GetMobNotifier().NotifyListeners(&MobListener::OnMobDamage, this, 1.0f, GetEffect(EffectType::Poison).tower);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (hasEffect(EffectType::Heal)) {
|
if (HasEffect(EffectType::Heal)) {
|
||||||
if (m_EffectFireTimer.update(delta)) {
|
if (m_EffectFireTimer.Update(delta)) {
|
||||||
heal(10);
|
Heal(10);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Mob::hasEffect(EffectType type) {
|
bool Mob::HasEffect(EffectType type) {
|
||||||
return std::find_if(m_Effects.begin(), m_Effects.end(), [&type](EffectDuration effect) { return effect.type == type;}) != m_Effects.end();
|
return std::find_if(m_Effects.begin(), m_Effects.end(), [&type](EffectDuration effect) { return effect.type == type;}) != m_Effects.end();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -254,7 +262,7 @@ bool Mob::hasEffect(EffectType type) {
|
|||||||
|
|
||||||
typedef std::pair<MobType, std::uint8_t> MobKey;
|
typedef std::pair<MobType, std::uint8_t> MobKey;
|
||||||
|
|
||||||
const std::map<MobKey, MobStats> MobConstants = {
|
static const std::map<MobKey, MobStats> MobConstants = {
|
||||||
// damage speed size money_cost exp_cost exp_reward max_health
|
// damage speed size money_cost exp_cost exp_reward max_health
|
||||||
{{MobType::Zombie, 1},{MobStats{1, 1.6, {1, 1}, 15, 0, 7, 40}}},
|
{{MobType::Zombie, 1},{MobStats{1, 1.6, {1, 1}, 15, 0, 7, 40}}},
|
||||||
{{MobType::Zombie, 2},{MobStats{1, 1.6, {1, 1}, 18, 88, 9, 56}}},
|
{{MobType::Zombie, 2},{MobStats{1, 1.6, {1, 1}, 18, 88, 9, 56}}},
|
||||||
@@ -317,11 +325,11 @@ const std::map<MobKey, MobStats> MobConstants = {
|
|||||||
{{MobType::Giant, 5},{MobStats{50, 0.8, {1, 1}, 6407, 22000, 648, 31640}}},
|
{{MobType::Giant, 5},{MobStats{50, 0.8, {1, 1}, 6407, 22000, 648, 31640}}},
|
||||||
};
|
};
|
||||||
|
|
||||||
const MobStats* getMobStats(MobType type, std::uint8_t level) {
|
const MobStats* GetMobStats(MobType type, std::uint8_t level) {
|
||||||
return &MobConstants.at(MobKey{ type, level });
|
return &MobConstants.at(MobKey{ type, level });
|
||||||
}
|
}
|
||||||
|
|
||||||
const std::map<MobKey, TowerImmunities> MobsTowerImmunities = {
|
static const std::map<MobKey, TowerImmunities> MobsTowerImmunities = {
|
||||||
{{MobType::Zombie, 1},{}},
|
{{MobType::Zombie, 1},{}},
|
||||||
{{MobType::Zombie, 2},{}},
|
{{MobType::Zombie, 2},{}},
|
||||||
{{MobType::Zombie, 3},{}},
|
{{MobType::Zombie, 3},{}},
|
||||||
@@ -383,11 +391,11 @@ const std::map<MobKey, TowerImmunities> MobsTowerImmunities = {
|
|||||||
{{MobType::Giant, 5},{}},
|
{{MobType::Giant, 5},{}},
|
||||||
};
|
};
|
||||||
|
|
||||||
const TowerImmunities& getMobTowerImmunities(MobType type, std::uint8_t level) {
|
const TowerImmunities& GetMobTowerImmunities(MobType type, std::uint8_t level) {
|
||||||
return MobsTowerImmunities.at({ type, level });
|
return MobsTowerImmunities.at({ type, level });
|
||||||
}
|
}
|
||||||
|
|
||||||
const std::map<MobKey, EffectImmunities> MobsEffectImmunities = {
|
static const std::map<MobKey, EffectImmunities> MobsEffectImmunities = {
|
||||||
{{MobType::Zombie, 1},{}},
|
{{MobType::Zombie, 1},{}},
|
||||||
{{MobType::Zombie, 2},{}},
|
{{MobType::Zombie, 2},{}},
|
||||||
{{MobType::Zombie, 3},{}},
|
{{MobType::Zombie, 3},{}},
|
||||||
@@ -449,14 +457,14 @@ const std::map<MobKey, EffectImmunities> MobsEffectImmunities = {
|
|||||||
{{MobType::Giant, 5},{EffectType::Stun}},
|
{{MobType::Giant, 5},{EffectType::Stun}},
|
||||||
};
|
};
|
||||||
|
|
||||||
const EffectImmunities& getMobEffectImmunities(MobType type, std::uint8_t level) {
|
const EffectImmunities& GetMobEffectImmunities(MobType type, std::uint8_t level) {
|
||||||
return MobsEffectImmunities.at({ type, level });
|
return MobsEffectImmunities.at({ type, level });
|
||||||
}
|
}
|
||||||
|
|
||||||
MobPtr MobFactory::createMob(MobID id, MobType type, std::uint8_t level, PlayerID sender) {
|
MobPtr MobFactory::CreateMob(MobID mobId, MobType mobType, std::uint8_t mobLevel, PlayerID mobSender) {
|
||||||
using MobCreator = std::function<std::shared_ptr<Mob>(MobID, std::uint8_t, PlayerID)>;
|
using MobCreator = std::function<std::shared_ptr<Mob>(MobID, std::uint8_t, PlayerID)>;
|
||||||
|
|
||||||
static std::map<MobType, MobCreator> mobFactory = {
|
static const std::map<MobType, MobCreator> mobFactory = {
|
||||||
{MobType::Zombie, [](MobID id, std::uint8_t level, PlayerID sender) -> MobPtr {return std::make_shared<Zombie>(id, level, sender);} },
|
{MobType::Zombie, [](MobID id, std::uint8_t level, PlayerID sender) -> MobPtr {return std::make_shared<Zombie>(id, level, sender);} },
|
||||||
{MobType::Spider, [](MobID id, std::uint8_t level, PlayerID sender) -> MobPtr {return std::make_shared<Spider>(id, level, sender);} },
|
{MobType::Spider, [](MobID id, std::uint8_t level, PlayerID sender) -> MobPtr {return std::make_shared<Spider>(id, level, sender);} },
|
||||||
{MobType::Skeleton, [](MobID id, std::uint8_t level, PlayerID sender) -> MobPtr {return std::make_shared<Skeleton>(id, level, sender);} },
|
{MobType::Skeleton, [](MobID id, std::uint8_t level, PlayerID sender) -> MobPtr {return std::make_shared<Skeleton>(id, level, sender);} },
|
||||||
@@ -469,10 +477,10 @@ MobPtr MobFactory::createMob(MobID id, MobType type, std::uint8_t level, PlayerI
|
|||||||
{MobType::Giant, [](MobID id, std::uint8_t level, PlayerID sender) -> MobPtr {return std::make_shared<Giant>(id, level, sender);} },
|
{MobType::Giant, [](MobID id, std::uint8_t level, PlayerID sender) -> MobPtr {return std::make_shared<Giant>(id, level, sender);} },
|
||||||
};
|
};
|
||||||
|
|
||||||
return mobFactory[type](id, level, sender);
|
return mobFactory.at(mobType)(mobId, mobLevel, mobSender);
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string MobFactory::getMobName(MobType type) {
|
std::string MobFactory::GetMobName(MobType type) {
|
||||||
switch (type) {
|
switch (type) {
|
||||||
case MobType::Zombie:
|
case MobType::Zombie:
|
||||||
return "Zombie";
|
return "Zombie";
|
||||||
|
|||||||
@@ -7,19 +7,19 @@ namespace game {
|
|||||||
|
|
||||||
Team::Team(TeamColor color) : m_Color(color), m_TeamCastle(this) {}
|
Team::Team(TeamColor color) : m_Color(color), m_TeamCastle(this) {}
|
||||||
|
|
||||||
void Team::addPlayer(Player* newPlayer) {
|
void Team::AddPlayer(Player* newPlayer) {
|
||||||
m_Players.push_back(newPlayer);
|
m_Players.push_back(newPlayer);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Team::removePlayer(const Player* player) {
|
void Team::RemovePlayer(const Player* player) {
|
||||||
m_Players.erase(std::find(m_Players.begin(), m_Players.end(), player));
|
m_Players.erase(std::find(m_Players.begin(), m_Players.end(), player));
|
||||||
}
|
}
|
||||||
|
|
||||||
TeamColor Team::getColor() const {
|
TeamColor Team::GetColor() const {
|
||||||
return m_Color;
|
return m_Color;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::uint8_t Team::getPlayerCount() const {
|
std::uint8_t Team::GetPlayerCount() const {
|
||||||
return m_Players.size();
|
return m_Players.size();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -6,10 +6,10 @@
|
|||||||
namespace td {
|
namespace td {
|
||||||
namespace game {
|
namespace game {
|
||||||
|
|
||||||
bool Tower::isMobInRange(MobPtr mob) {
|
bool Tower::IsMobInRange(MobPtr mob) {
|
||||||
if (mob->isDead())
|
if (mob->IsDead())
|
||||||
return false;
|
return false;
|
||||||
return mob->collidesWith(*this);
|
return mob->CollidesWith(*this);
|
||||||
}
|
}
|
||||||
|
|
||||||
const std::map<std::pair<TowerType, TowerLevel>, TowerStats> TowerConstants = {
|
const std::map<std::pair<TowerType, TowerLevel>, TowerStats> TowerConstants = {
|
||||||
@@ -115,7 +115,7 @@ const std::map<std::pair<TowerType, TowerLevel>, TowerStats> TowerConstants = {
|
|||||||
{{TowerType::Necromancer, {3, TowerPath::Bottom}}, {0, 30, 0}},
|
{{TowerType::Necromancer, {3, TowerPath::Bottom}}, {0, 30, 0}},
|
||||||
};
|
};
|
||||||
|
|
||||||
const TowerStats* getTowerStats(TowerType type, TowerLevel level) {
|
const TowerStats* GetTowerStats(TowerType type, TowerLevel level) {
|
||||||
auto it = TowerConstants.find({ type, level });
|
auto it = TowerConstants.find({ type, level });
|
||||||
if (it == TowerConstants.end()) return nullptr;
|
if (it == TowerConstants.end()) return nullptr;
|
||||||
return &it->second;
|
return &it->second;
|
||||||
@@ -139,7 +139,7 @@ static const std::map<TowerType, TowerInfo> TowerInfoConstants = {
|
|||||||
{TowerType::Zeus, {"Zeus", "Strike lightning", false}},
|
{TowerType::Zeus, {"Zeus", "Strike lightning", false}},
|
||||||
};
|
};
|
||||||
|
|
||||||
const TowerInfo& getTowerInfo(TowerType type) {
|
const TowerInfo& GetTowerInfo(TowerType type) {
|
||||||
return TowerInfoConstants.at(type);
|
return TowerInfoConstants.at(type);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -165,11 +165,11 @@ static const std::map<TowerType, TowerCreator> towerFactory = {
|
|||||||
{TowerType::Turret, [](TowerID id, std::int32_t x, std::int32_t y, PlayerID builder) -> TowerPtr {return std::make_shared<TurretTower>(id, x, y , builder);} },
|
{TowerType::Turret, [](TowerID id, std::int32_t x, std::int32_t y, PlayerID builder) -> TowerPtr {return std::make_shared<TurretTower>(id, x, y , builder);} },
|
||||||
};
|
};
|
||||||
|
|
||||||
TowerPtr createTower(TowerType type, TowerID id, std::int32_t x, std::int32_t y, PlayerID builder) {
|
TowerPtr CreateTower(TowerType type, TowerID id, std::int32_t x, std::int32_t y, PlayerID builder) {
|
||||||
return towerFactory.at(type)(id, x, y, builder);
|
return towerFactory.at(type)(id, x, y, builder);
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string getTowerName(TowerType type) {
|
std::string GetTowerName(TowerType type) {
|
||||||
switch (type) {
|
switch (type) {
|
||||||
|
|
||||||
case TowerType::Archer:
|
case TowerType::Archer:
|
||||||
@@ -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,23 +1,24 @@
|
|||||||
#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/Format.h"
|
||||||
|
|
||||||
#include <cmath>
|
#include <cmath>
|
||||||
#include "misc/Compression.h"
|
|
||||||
|
|
||||||
#include <iostream>
|
|
||||||
|
|
||||||
namespace td {
|
namespace td {
|
||||||
namespace game {
|
namespace game {
|
||||||
|
|
||||||
World::World(Game* game) : m_Game(game) {
|
World::World(Game* game) : m_Game(game) {
|
||||||
getWorldNotifier().bindListener(this);
|
GetWorldNotifier().BindListener(this);
|
||||||
getMobNotifier().bindListener(this);
|
GetMobNotifier().BindListener(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
TilePtr World::getTile(std::int32_t x, std::int32_t y) const {
|
TilePtr World::GetTile(std::int32_t x, std::int32_t y) const {
|
||||||
std::int16_t chunkX = x / Chunk::ChunkWidth;
|
std::int16_t chunkX = x / Chunk::ChunkWidth;
|
||||||
std::int16_t chunkY = y / Chunk::ChunkHeight;
|
std::int16_t chunkY = y / Chunk::ChunkHeight;
|
||||||
|
|
||||||
@@ -30,107 +31,101 @@ TilePtr World::getTile(std::int32_t x, std::int32_t y) const {
|
|||||||
|
|
||||||
ChunkPtr chunk = chunkIt->second;
|
ChunkPtr chunk = chunkIt->second;
|
||||||
|
|
||||||
return getTilePtr(chunk->getTileIndex(subChunkY * Chunk::ChunkWidth + subChunkX));
|
return GetTilePtr(chunk->GetTileIndex(subChunkY * Chunk::ChunkWidth + subChunkX));
|
||||||
}
|
}
|
||||||
|
|
||||||
bool World::loadMap(const protocol::WorldBeginDataPacket* worldHeader) {
|
bool World::LoadMap(const protocol::WorldBeginDataPacket* worldHeader) {
|
||||||
m_TowerPlacePalette = worldHeader->getTowerTilePalette();
|
m_TowerPlacePalette = worldHeader->GetTowerTilePalette();
|
||||||
m_WalkablePalette = worldHeader->getWalkableTileColor();
|
m_WalkablePalette = worldHeader->GetWalkableTileColor();
|
||||||
m_DecorationPalette = worldHeader->getDecorationPalette();
|
m_DecorationPalette = worldHeader->GetDecorationPalette();
|
||||||
m_Background = worldHeader->getBackgroundColor();
|
m_Background = worldHeader->GetBackgroundColor();
|
||||||
|
|
||||||
getRedTeam().getSpawn() = worldHeader->getRedSpawn();
|
GetRedTeam().GetSpawn() = worldHeader->GetRedSpawn();
|
||||||
getBlueTeam().getSpawn() = worldHeader->getBlueSpawn();
|
GetBlueTeam().GetSpawn() = worldHeader->GetBlueSpawn();
|
||||||
|
|
||||||
m_SpawnColorPalette = worldHeader->getSpawnPalette();
|
m_SpawnColorPalette = worldHeader->GetSpawnPalette();
|
||||||
|
|
||||||
getRedTeam().getCastle() = worldHeader->getRedCastle();
|
GetRedTeam().GetCastle() = worldHeader->GetRedCastle();
|
||||||
getRedTeam().getCastle().setTeam(&getRedTeam());
|
GetRedTeam().GetCastle().SetTeam(&GetRedTeam());
|
||||||
|
|
||||||
getBlueTeam().getCastle() = worldHeader->getBlueCastle();
|
GetBlueTeam().GetCastle() = worldHeader->GetBlueCastle();
|
||||||
getBlueTeam().getCastle().setTeam(&getBlueTeam());
|
GetBlueTeam().GetCastle().SetTeam(&GetBlueTeam());
|
||||||
|
|
||||||
m_TilePalette = worldHeader->getTilePalette();
|
m_TilePalette = worldHeader->GetTilePalette();
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool World::loadMap(const protocol::WorldDataPacket* worldData) {
|
bool World::LoadMap(const protocol::WorldDataPacket* worldData) {
|
||||||
m_Chunks = worldData->getChunks();
|
m_Chunks = worldData->GetChunks();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool World::loadMapFromFile(const std::string& fileName) {
|
bool World::LoadMapFromFile(const std::string& fileName) {
|
||||||
DataBuffer buffer;
|
DataBuffer buffer;
|
||||||
if (!buffer.ReadFile(fileName)) {
|
if (!buffer.ReadFile(fileName)) {
|
||||||
std::cerr << "Failed to load map from file " << fileName << " !\n";
|
utils::LOGE(utils::format("Failed to load map from file %s", fileName.c_str()));
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::cout << "Read file : " << fileName << " (File size : " << buffer.GetSize() << ")" << std::endl;
|
utils::LOG(utils::format("Read file : %s (File size : %u)", fileName.c_str(), buffer.GetSize()));
|
||||||
|
|
||||||
DataBuffer mapHeaderPacketBuffer = utils::Decompress(buffer);
|
DataBuffer mapHeaderPacketBuffer = utils::Decompress(buffer);
|
||||||
DataBuffer mapDataPacketBuffer = utils::Decompress(buffer);
|
DataBuffer mapDataPacketBuffer = utils::Decompress(buffer);
|
||||||
|
|
||||||
protocol::PacketType packetType;
|
|
||||||
|
|
||||||
mapHeaderPacketBuffer >> packetType;
|
|
||||||
|
|
||||||
protocol::WorldBeginDataPacket headerPacket;
|
protocol::WorldBeginDataPacket headerPacket;
|
||||||
headerPacket.Deserialize(mapHeaderPacketBuffer);
|
headerPacket.Deserialize(mapHeaderPacketBuffer);
|
||||||
|
|
||||||
mapDataPacketBuffer >> packetType;
|
|
||||||
|
|
||||||
protocol::WorldDataPacket dataPacket;
|
protocol::WorldDataPacket dataPacket;
|
||||||
dataPacket.Deserialize(mapDataPacketBuffer);
|
dataPacket.Deserialize(mapDataPacketBuffer);
|
||||||
|
|
||||||
loadMap(&headerPacket);
|
LoadMap(&headerPacket);
|
||||||
loadMap(&dataPacket);
|
LoadMap(&dataPacket);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool World::saveMap(const std::string& fileName) const {
|
bool World::SaveMap(const std::string& fileName) const {
|
||||||
protocol::WorldBeginDataPacket headerPacket(this);
|
protocol::WorldBeginDataPacket headerPacket(this);
|
||||||
protocol::WorldDataPacket dataPacket(this);
|
protocol::WorldDataPacket dataPacket(this);
|
||||||
|
|
||||||
DataBuffer mapHeaderCompressed = utils::Compress(headerPacket.Serialize());
|
DataBuffer mapHeaderCompressed = utils::Compress(headerPacket.Serialize(false));
|
||||||
DataBuffer mapDataCompressed = utils::Compress(dataPacket.Serialize());
|
DataBuffer mapDataCompressed = utils::Compress(dataPacket.Serialize(false));
|
||||||
|
|
||||||
std::cout << "Header Packet Size : " << mapHeaderCompressed.GetSize() << std::endl;
|
utils::LOG(utils::format("Header Packet Size : %u", mapHeaderCompressed.GetSize()));
|
||||||
std::cout << "World Data Packet Size : " << mapDataCompressed.GetSize() << std::endl;
|
utils::LOG(utils::format("World Data Packet Size : %u", mapDataCompressed.GetSize()));
|
||||||
|
|
||||||
DataBuffer buffer = mapHeaderCompressed << mapDataCompressed;
|
DataBuffer buffer = mapHeaderCompressed << mapDataCompressed;
|
||||||
std::cout << "Total Size : " << buffer.GetSize() << std::endl;
|
utils::LOG(utils::format("Total Size : %u", buffer.GetSize()));
|
||||||
return buffer.WriteFile(fileName);
|
return buffer.WriteFile(fileName);
|
||||||
}
|
}
|
||||||
|
|
||||||
void World::tick(std::uint64_t delta) {
|
void World::Tick(std::uint64_t delta) {
|
||||||
if (m_Game->getGameState() != GameState::Game) return;
|
if (m_Game->GetGameState() != GameState::Game) return;
|
||||||
|
|
||||||
tickMobs(delta);
|
TickMobs(delta);
|
||||||
for (TowerPtr tower : m_Towers) {
|
for (TowerPtr tower : m_Towers) {
|
||||||
tower->tick(delta, this);
|
tower->Tick(delta, this);
|
||||||
}
|
}
|
||||||
cleanDeadMobs();
|
CleanDeadMobs();
|
||||||
}
|
}
|
||||||
|
|
||||||
void World::spawnMobAt(MobID id, MobType type, std::uint8_t level, PlayerID sender, float x, float y, Direction dir) {
|
void World::SpawnMobAt(MobID id, MobType type, std::uint8_t level, PlayerID sender, float x, float y, Direction dir) {
|
||||||
MobPtr mob = MobFactory::createMob(id, type, level, sender);
|
MobPtr mob = MobFactory::CreateMob(id, type, level, sender);
|
||||||
mob->setCenter({ x, y });
|
mob->SetCenter({ x, y });
|
||||||
mob->setDirection(dir);
|
mob->SetDirection(dir);
|
||||||
m_Mobs.push_back(mob);
|
m_Mobs.push_back(mob);
|
||||||
getMobNotifier().notifyListeners(&MobListener::OnMobSpawn, mob.get());
|
GetMobNotifier().NotifyListeners(&MobListener::OnMobSpawn, mob.get());
|
||||||
}
|
}
|
||||||
|
|
||||||
TowerPtr World::placeTowerAt(TowerID id, TowerType type, std::int32_t x, std::int32_t y, PlayerID builder) {
|
TowerPtr World::PlaceTowerAt(TowerID id, TowerType type, std::int32_t x, std::int32_t y, PlayerID builder) {
|
||||||
TowerPtr tower = TowerFactory::createTower(type, id, x, y, builder);
|
TowerPtr tower = TowerFactory::CreateTower(type, id, x, y, builder);
|
||||||
m_Towers.push_back(tower);
|
m_Towers.push_back(tower);
|
||||||
return tower;
|
return tower;
|
||||||
}
|
}
|
||||||
|
|
||||||
TowerPtr World::removeTower(TowerID towerId) {
|
TowerPtr World::RemoveTower(TowerID towerId) {
|
||||||
auto it = std::find_if(m_Towers.begin(), m_Towers.end(), [towerId](TowerPtr tower) { return tower->getID() == towerId;});
|
auto it = std::find_if(m_Towers.begin(), m_Towers.end(), [towerId](TowerPtr tower) { return tower->GetID() == towerId;});
|
||||||
if (it == m_Towers.end()) return nullptr;
|
if (it == m_Towers.end()) return nullptr;
|
||||||
|
|
||||||
TowerPtr tower = *it;
|
TowerPtr tower = *it;
|
||||||
@@ -140,49 +135,49 @@ TowerPtr World::removeTower(TowerID towerId) {
|
|||||||
return tower;
|
return tower;
|
||||||
}
|
}
|
||||||
|
|
||||||
void World::tickMobs(std::uint64_t delta) {
|
void World::TickMobs(std::uint64_t delta) {
|
||||||
for (MobPtr mob : m_Mobs) {
|
for (MobPtr mob : m_Mobs) {
|
||||||
mob->tick(delta, this);
|
mob->Tick(delta, this);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const Color* World::getTileColor(TilePtr tile) const {
|
const Color* World::GetTileColor(TilePtr tile) const {
|
||||||
switch (tile->getType()) {
|
switch (tile->GetType()) {
|
||||||
case TileType::Tower: {
|
case TileType::Tower: {
|
||||||
TowerTile* towerTile = (TowerTile*)tile.get();
|
TowerTile* towerTile = dynamic_cast<TowerTile*>(tile.get());
|
||||||
return &m_TowerPlacePalette[towerTile->color_palette_ref];
|
return &m_TowerPlacePalette[towerTile->color_palette_ref];
|
||||||
}
|
}
|
||||||
case TileType::Walk: {
|
case TileType::Walk: {
|
||||||
return &m_WalkablePalette;
|
return &m_WalkablePalette;
|
||||||
}
|
}
|
||||||
case TileType::Decoration: {
|
case TileType::Decoration: {
|
||||||
DecorationTile* towerTile = (DecorationTile*)tile.get();
|
DecorationTile* towerTile = dynamic_cast<DecorationTile*>(tile.get());
|
||||||
return &m_DecorationPalette[towerTile->color_palette_ref];
|
return &m_DecorationPalette[towerTile->color_palette_ref];
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case TileType::None: {
|
default: {
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool World::CanPlaceLittleTower(const glm::vec2& worldPos, PlayerID playerID) const {
|
bool World::CanPlaceLittleTower(const Vec2f& worldPos, PlayerID playerID) const {
|
||||||
TilePtr tile = getTile(worldPos.x, worldPos.y);
|
TilePtr tile = GetTile(worldPos.x, worldPos.y);
|
||||||
const Player& player = m_Game->getPlayers()[playerID];
|
const Player& player = m_Game->GetPlayers()[playerID];
|
||||||
|
|
||||||
if (tile == nullptr) {
|
if (tile == nullptr) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (tile->getType() == game::TileType::Tower) {
|
if (tile->GetType() == game::TileType::Tower) {
|
||||||
const TowerTile* towerTile = (const TowerTile*)tile.get();
|
const TowerTile* towerTile = dynamic_cast<TowerTile*>(tile.get());
|
||||||
if (towerTile->team_owner != player.getTeamColor())
|
if (towerTile->team_owner != player.GetTeamColor())
|
||||||
return false;
|
return false;
|
||||||
for (int x = -1; x < 2; x++) {
|
for (int x = -1; x < 2; x++) {
|
||||||
for (int y = -1; y < 2; y++) {
|
for (int y = -1; y < 2; y++) {
|
||||||
game::TilePtr adjacentTile = getTile(worldPos.x + x, worldPos.y + y);
|
game::TilePtr adjacentTile = GetTile(worldPos.x + x, worldPos.y + y);
|
||||||
if (adjacentTile == nullptr || adjacentTile->getType() != game::TileType::Tower || getTower({ worldPos.x + x, worldPos.y + y }) != nullptr) {
|
if (adjacentTile == nullptr || adjacentTile->GetType() != game::TileType::Tower || GetTower({ worldPos.x + x, worldPos.y + y }) != nullptr) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -193,24 +188,24 @@ bool World::CanPlaceLittleTower(const glm::vec2& worldPos, PlayerID playerID) co
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool World::CanPlaceBigTower(const glm::vec2& worldPos, PlayerID playerID) const {
|
bool World::CanPlaceBigTower(const Vec2f& worldPos, PlayerID playerID) const {
|
||||||
if (!CanPlaceLittleTower(worldPos, playerID)) return false;
|
if (!CanPlaceLittleTower(worldPos, playerID)) return false;
|
||||||
|
|
||||||
TilePtr tile = getTile(worldPos.x, worldPos.y);
|
TilePtr tile = GetTile(worldPos.x, worldPos.y);
|
||||||
const Player& player = m_Game->getPlayers()[playerID];
|
const Player& player = m_Game->GetPlayers()[playerID];
|
||||||
|
|
||||||
if (tile == nullptr) {
|
if (tile == nullptr) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (tile->getType() == game::TileType::Tower) {
|
if (tile->GetType() == game::TileType::Tower) {
|
||||||
const TowerTile* towerTile = (const TowerTile*)tile.get();
|
const TowerTile* towerTile = dynamic_cast<const TowerTile*>(tile.get());
|
||||||
if (towerTile->team_owner != player.getTeamColor())
|
if (towerTile->team_owner != player.GetTeamColor())
|
||||||
return false;
|
return false;
|
||||||
for (int x = -2; x < 3; x++) {
|
for (int x = -2; x < 3; x++) {
|
||||||
for (int y = -2; y < 3; y++) {
|
for (int y = -2; y < 3; y++) {
|
||||||
game::TilePtr adjacentTile = getTile(worldPos.x + x, worldPos.y + y);
|
game::TilePtr adjacentTile = GetTile(worldPos.x + x, worldPos.y + y);
|
||||||
if (adjacentTile == nullptr || adjacentTile->getType() != game::TileType::Tower || getTower({ worldPos.x + x, worldPos.y + y }) != nullptr) {
|
if (adjacentTile == nullptr || adjacentTile->GetType() != game::TileType::Tower || GetTower({ worldPos.x + x, worldPos.y + y }) != nullptr) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -221,26 +216,26 @@ bool World::CanPlaceBigTower(const glm::vec2& worldPos, PlayerID playerID) const
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
void World::cleanDeadMobs() {
|
void World::CleanDeadMobs() {
|
||||||
// safely remove mobs when unused
|
// safely remove mobs when unused
|
||||||
for (std::size_t i = 0; i < m_Mobs.size(); i++) {
|
for (std::size_t i = 0; i < m_Mobs.size(); i++) {
|
||||||
MobPtr mob = m_Mobs[i];
|
MobPtr mob = m_Mobs[i];
|
||||||
if (mob->isDead()) {
|
if (mob->IsDead()) {
|
||||||
m_Mobs.erase(m_Mobs.begin() + i);
|
m_Mobs.erase(m_Mobs.begin() + static_cast<int>(i));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
TowerPtr World::getTower(const glm::vec2& position) const {
|
TowerPtr World::GetTower(const Vec2f& position) const {
|
||||||
for (TowerPtr tower : m_Towers) {
|
for (TowerPtr tower : m_Towers) {
|
||||||
if (tower->getSize() == TowerSize::Big) {
|
if (tower->GetSize() == TowerSize::Big) {
|
||||||
if (tower->getCenterX() - 2.5f < position.x && tower->getCenterX() + 2.5f > position.x &&
|
if (tower->GetCenterX() - 2.5f < position.x && tower->GetCenterX() + 2.5f > position.x &&
|
||||||
tower->getCenterY() - 2.5f < position.y && tower->getCenterY() + 2.5f > position.y) {
|
tower->GetCenterY() - 2.5f < position.y && tower->GetCenterY() + 2.5f > position.y) {
|
||||||
return tower;
|
return tower;
|
||||||
}
|
}
|
||||||
} else { // little tower
|
} else { // little tower
|
||||||
if (tower->getCenterX() - 1.5f < position.x && tower->getCenterX() + 1.5f > position.x &&
|
if (tower->GetCenterX() - 1.5f < position.x && tower->GetCenterX() + 1.5f > position.x &&
|
||||||
tower->getCenterY() - 1.5f < position.y && tower->getCenterY() + 1.5f > position.y) {
|
tower->GetCenterY() - 1.5f < position.y && tower->GetCenterY() + 1.5f > position.y) {
|
||||||
return tower;
|
return tower;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -248,83 +243,83 @@ TowerPtr World::getTower(const glm::vec2& position) const {
|
|||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
TowerPtr World::getTowerById(TowerID towerID) {
|
TowerPtr World::GetTowerById(TowerID towerID) {
|
||||||
auto it = std::find_if(m_Towers.begin(), m_Towers.end(), [towerID](TowerPtr tower) { return tower->getID() == towerID;});
|
auto it = std::find_if(m_Towers.begin(), m_Towers.end(), [towerID](TowerPtr tower) { return tower->GetID() == towerID;});
|
||||||
if (it == m_Towers.end()) return nullptr;
|
if (it == m_Towers.end()) return nullptr;
|
||||||
return *it;
|
return *it;
|
||||||
}
|
}
|
||||||
|
|
||||||
void World::OnArcherTowerShot(MobPtr target, ArcherTower* shooter) {
|
void World::OnArcherTowerShot(MobPtr tarGet, ArcherTower* shooter) {
|
||||||
bool fireArrows = shooter->getLevel().getPath() == TowerPath::Bottom;
|
bool fireArrows = shooter->GetLevel().GetPath() == TowerPath::Bottom;
|
||||||
bool explosiveArrows = shooter->getLevel().getLevel() == 4 && fireArrows;
|
bool explosiveArrows = shooter->GetLevel().GetLevel() == 4 && fireArrows;
|
||||||
|
|
||||||
getWorldNotifier().notifyListeners(&WorldListener::OnArrowShot, target, fireArrows, shooter);
|
GetWorldNotifier().NotifyListeners(&WorldListener::OnArrowShot, tarGet, fireArrows, shooter);
|
||||||
if (explosiveArrows) {
|
if (explosiveArrows) {
|
||||||
getWorldNotifier().notifyListeners(&WorldListener::OnExplosion, utils::shape::Circle{ target->getCenterX(), target->getCenterY(), ArcherTower::ExplosionRadius }, shooter->getStats()->getDamage(), shooter);
|
GetWorldNotifier().NotifyListeners(&WorldListener::OnExplosion, utils::shape::Circle{ tarGet->GetCenterX(), tarGet->GetCenterY(), ArcherTower::ExplosionRadius }, shooter->GetStats()->GetDamage(), shooter);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void World::OnArrowShot(MobPtr target, bool fireArrow, Tower* shooter) {
|
void World::OnArrowShot(MobPtr tarGet, bool fireArrow, Tower* shooter) {
|
||||||
getMobNotifier().notifyListeners(&MobListener::OnMobDamage, target.get(), shooter->getStats()->getDamage(), shooter);
|
GetMobNotifier().NotifyListeners(&MobListener::OnMobDamage, tarGet.get(), shooter->GetStats()->GetDamage(), shooter);
|
||||||
if (fireArrow) {
|
if (fireArrow) {
|
||||||
target->addEffect(EffectType::Fire, ArcherTower::FireDurationSec, shooter);
|
tarGet->AddEffect(EffectType::Fire, ArcherTower::FireDurationSec, shooter);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void World::OnExplosion(utils::shape::Circle explosion, float centerDamage, Tower* shooter) {
|
void World::OnExplosion(utils::shape::Circle explosion, float centerDamage, Tower* shooter) {
|
||||||
for (MobPtr mob : m_Mobs) {
|
for (MobPtr mob : m_Mobs) {
|
||||||
if (mob->isAlive() && mob->collidesWith(explosion)) {
|
if (mob->IsAlive() && mob->CollidesWith(explosion)) {
|
||||||
// linear distance damage reduction
|
// linear distance damage reduction
|
||||||
float explosionDamage = mob->distance(explosion) / explosion.getRadius() * centerDamage;
|
float explosionDamage = mob->Distance(explosion) / explosion.GetRadius() * centerDamage;
|
||||||
getMobNotifier().notifyListeners(&MobListener::OnMobDamage, mob.get(), explosionDamage, shooter);
|
GetMobNotifier().NotifyListeners(&MobListener::OnMobDamage, mob.get(), explosionDamage, shooter);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void World::OnMobCastleDamage(Mob* damager, TeamCastle* enemyCastle, float damage) {
|
void World::OnMobCastleDamage(Mob* damager, TeamCastle* enemyCastle, float damage) {
|
||||||
enemyCastle->damage(damage);
|
enemyCastle->Damage(damage);
|
||||||
if (enemyCastle->getLife() <= 0) {
|
if (enemyCastle->GetLife() <= 0) {
|
||||||
m_Game->notifyListeners(&GameListener::OnGameEnd);
|
m_Game->NotifyListeners(&GameListener::OnGameEnd);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void World::OnMobDamage(Mob* target, float damage, Tower* source) {
|
void World::OnMobDamage(Mob* tarGet, float damage, Tower* source) {
|
||||||
target->damage(damage, source);
|
tarGet->Damage(damage, source);
|
||||||
if (target->isDead()) {
|
if (tarGet->IsDead()) {
|
||||||
getMobNotifier().notifyListeners(&MobListener::OnMobDie, target);
|
GetMobNotifier().NotifyListeners(&MobListener::OnMobDie, tarGet);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Team& World::getRedTeam() {
|
Team& World::GetRedTeam() {
|
||||||
return m_Game->getRedTeam();
|
return m_Game->GetRedTeam();
|
||||||
}
|
}
|
||||||
|
|
||||||
const Team& World::getRedTeam() const {
|
const Team& World::GetRedTeam() const {
|
||||||
return m_Game->getRedTeam();
|
return m_Game->GetRedTeam();
|
||||||
}
|
}
|
||||||
|
|
||||||
Team& World::getBlueTeam() {
|
Team& World::GetBlueTeam() {
|
||||||
return m_Game->getBlueTeam();
|
return m_Game->GetBlueTeam();
|
||||||
}
|
}
|
||||||
|
|
||||||
const Team& World::getBlueTeam() const {
|
const Team& World::GetBlueTeam() const {
|
||||||
return m_Game->getBlueTeam();
|
return m_Game->GetBlueTeam();
|
||||||
}
|
}
|
||||||
|
|
||||||
Team& World::getTeam(TeamColor team) {
|
Team& World::GetTeam(TeamColor team) {
|
||||||
return m_Game->getTeam(team);
|
return m_Game->GetTeam(team);
|
||||||
}
|
}
|
||||||
|
|
||||||
const Team& World::getTeam(TeamColor team) const {
|
const Team& World::GetTeam(TeamColor team) const {
|
||||||
return m_Game->getTeam(team);
|
return m_Game->GetTeam(team);
|
||||||
}
|
}
|
||||||
|
|
||||||
const Player* World::getPlayerById(PlayerID id) const {
|
const Player* World::GetPlayerById(PlayerID id) const {
|
||||||
return m_Game->getPlayerById(id);
|
return m_Game->GetPlayerById(id);
|
||||||
}
|
}
|
||||||
|
|
||||||
const TeamList& World::getTeams() const {
|
const TeamList& World::GetTeams() const {
|
||||||
return m_Game->getTeams();
|
return m_Game->GetTeams();
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace game
|
} // namespace game
|
||||||
|
|||||||
@@ -1,78 +1,83 @@
|
|||||||
#include "game/client/Client.h"
|
#include "game/client/Client.h"
|
||||||
|
#include "misc/Format.h"
|
||||||
|
|
||||||
#include <iostream>
|
#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 {
|
||||||
|
|
||||||
bool Client::connect(const network::IPAddresses& addresses, std::uint16_t port) {
|
bool Client::Connect(const network::IPAddresses& addresses, std::uint16_t port) {
|
||||||
for (const network::IPAddress& address : addresses) {
|
for (const network::IPAddress& address : addresses) {
|
||||||
if (address.IsValid() && m_Connexion.connect(address.ToString(), port)) {
|
if (address.IsValid() && m_Connexion.Connect(address.ToString(), port)) {
|
||||||
m_Connected = true;
|
m_Connected = true;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
std::cout << "Failed to connect !\n";
|
utils::LOGE("Failed to connect !");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Client::selectTeam(game::TeamColor team) {
|
void Client::SelectTeam(game::TeamColor team) {
|
||||||
if (!m_Connected)
|
if (!m_Connected)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
protocol::SelectTeamPacket packet(team);
|
protocol::SelectTeamPacket packet(team);
|
||||||
m_Connexion.sendPacket(&packet);
|
m_Connexion.SendPacket(&packet);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Client::closeConnection() {
|
void Client::CloseConnection() {
|
||||||
if (!m_Connected)
|
if (!m_Connected)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
m_Connected = false;
|
m_Connected = false;
|
||||||
|
|
||||||
protocol::DisconnectPacket packet;
|
protocol::DisconnectPacket packet;
|
||||||
m_Connexion.sendPacket(&packet);
|
m_Connexion.SendPacket(&packet);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Client::tick(std::uint64_t delta) {
|
void Client::Tick(std::uint64_t delta) {
|
||||||
if (!m_Connected)
|
if (!m_Connected)
|
||||||
return;
|
return;
|
||||||
m_Connected = m_Connexion.updateSocket();
|
m_Connected = m_Connexion.UpdateSocket();
|
||||||
if (!m_Connected) {
|
if (!m_Connected) {
|
||||||
std::cout << "Disconnected ! (Reason : " << m_Connexion.getDisconnectReason() << ")\n";
|
utils::LOG(utils::format("Disconnected ! (Reason : %s)", m_Connexion.GetDisconnectReason().c_str()));
|
||||||
reset();
|
Reset();
|
||||||
} else {
|
} else {
|
||||||
m_Game->tick(delta);
|
m_Game->Tick(delta);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void Client::render() {
|
void Client::Render() {
|
||||||
m_Game->renderWorld();
|
m_Game->RenderWorld();
|
||||||
}
|
}
|
||||||
|
|
||||||
void Client::reset() {
|
void Client::Reset() {
|
||||||
m_Game.reset(0);
|
m_Game.reset(0);
|
||||||
m_Game = std::make_unique<ClientGame>(this);
|
m_Game = std::make_unique<ClientGame>(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Client::sendMobs(const std::vector<protocol::MobSend>& mobSends) {
|
void Client::SendMobs(const std::vector<protocol::MobSend>& mobSends) {
|
||||||
protocol::SendMobsPacket packet(mobSends);
|
protocol::SendMobsPacket packet(mobSends);
|
||||||
m_Connexion.sendPacket(&packet);
|
m_Connexion.SendPacket(&packet);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Client::placeTower(game::TowerType type, const glm::vec2& position) {
|
void Client::PlaceTower(game::TowerType type, const Vec2f& position) {
|
||||||
protocol::PlaceTowerPacket packet(position.x, position.y, type);
|
protocol::PlaceTowerPacket packet(position.x, position.y, type);
|
||||||
m_Connexion.sendPacket(&packet);
|
m_Connexion.SendPacket(&packet);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Client::upgradeTower(game::TowerID tower, game::TowerLevel level) {
|
void Client::UpgradeTower(game::TowerID tower, game::TowerLevel level) {
|
||||||
protocol::UpgradeTowerPacket packet(tower, level);
|
protocol::UpgradeTowerPacket packet(tower, level);
|
||||||
m_Connexion.sendPacket(&packet);
|
m_Connexion.SendPacket(&packet);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Client::removeTower(game::TowerID tower) {
|
void Client::RemoveTower(game::TowerID tower) {
|
||||||
protocol::RemoveTowerPacket packet(tower);
|
protocol::RemoveTowerPacket packet(tower);
|
||||||
m_Connexion.sendPacket(&packet);
|
m_Connexion.SendPacket(&packet);
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace client
|
} // namespace client
|
||||||
|
|||||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user