indent with tabs

This commit is contained in:
2023-01-02 13:05:43 +01:00
parent 8f95b1a750
commit 222b79b40a
100 changed files with 4783 additions and 4781 deletions

View File

@@ -11,23 +11,23 @@ class Server;
class Lobby {
private:
Server* m_Server;
bool m_GameStarted = false;
std::uint64_t m_StartTimerTime = 0;
std::vector<std::uint8_t> m_Players;
utils::AutoTimer m_Timer;
Server* m_Server;
bool m_GameStarted = false;
std::uint64_t m_StartTimerTime = 0;
std::vector<std::uint8_t> m_Players;
utils::AutoTimer m_Timer;
public:
Lobby(Server* server);
Lobby(Server* server);
void OnPlayerJoin(std::uint8_t playerID);
void OnPlayerLeave(std::uint8_t playerID);
void OnPlayerJoin(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 = 5 * 1000; // in millis
//static constexpr int LobbyWaitingTime = 2 * 60 * 1000; // in millis
static constexpr int LobbyWaitingTime = 5 * 1000; // in millis
};
} // namespace server

View File

@@ -21,80 +21,80 @@ typedef std::map<std::uint8_t, ServerConnexion> ConnexionMap;
class TickCounter {
private:
float m_TPS;
std::uint64_t m_LastTPSTime;
std::uint8_t m_TickCount;
float m_TPS;
std::uint64_t m_LastTPSTime;
std::uint8_t m_TickCount;
public:
TickCounter() {}
TickCounter() {}
void Reset() {
m_TPS = SERVER_TPS;
m_LastTPSTime = utils::GetTime();
m_TickCount = 0;
}
void Reset() {
m_TPS = SERVER_TPS;
m_LastTPSTime = utils::GetTime();
m_TickCount = 0;
}
bool Update() { // return true when tps is updated
m_TickCount++;
if (m_TickCount >= SERVER_TPS) {
std::uint64_t timeElapsedSinceLast20Ticks = td::utils::GetTime() - m_LastTPSTime;
m_TPS = static_cast<float>(SERVER_TPS) / static_cast<float>(timeElapsedSinceLast20Ticks / 1000.0f);
m_TickCount = 0;
m_LastTPSTime = td::utils::GetTime();
return true;
}
return false;
}
bool Update() { // return true when tps is updated
m_TickCount++;
if (m_TickCount >= SERVER_TPS) {
std::uint64_t timeElapsedSinceLast20Ticks = td::utils::GetTime() - m_LastTPSTime;
m_TPS = static_cast<float>(SERVER_TPS) / static_cast<float>(timeElapsedSinceLast20Ticks / 1000.0f);
m_TickCount = 0;
m_LastTPSTime = td::utils::GetTime();
return true;
}
return false;
}
float GetTPS() const { return m_TPS; }
float GetTPS() const { return m_TPS; }
};
class Server {
private:
network::TCPListener m_Listener;
ConnexionMap m_Connections;
ServerGame m_Game{ this };
Lobby m_Lobby{ this };
TickCounter m_TickCounter;
network::TCPListener m_Listener;
ConnexionMap m_Connections;
ServerGame m_Game{ this };
Lobby m_Lobby{ this };
TickCounter m_TickCounter;
std::thread m_Thread;
bool m_ServerRunning;
std::thread m_Thread;
bool m_ServerRunning;
public:
Server(const std::string& worldFilePath);
virtual ~Server();
Server(const std::string& worldFilePath);
virtual ~Server();
bool Start(std::uint16_t port);
void Stop(); // force the server to stop
void Close(); // at the end of a game
bool Start(std::uint16_t port);
void Stop(); // force the server to stop
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; }
ServerGame& GetGame() { return m_Game; }
const ServerGame& GetGame() const { return m_Game; }
ServerGame& GetGame() { return m_Game; }
const Lobby& GetLobby() const { return m_Lobby; }
const ConnexionMap& GetConnexions() const { return m_Connections; }
ConnexionMap& GetConnexions() { return m_Connections; }
const Lobby& GetLobby() const { return m_Lobby; }
const ConnexionMap& GetConnexions() const { return m_Connections; }
ConnexionMap& GetConnexions() { return m_Connections; }
const game::PlayerList& GetPlayers() const { return m_Game.GetPlayers(); }
game::PlayerList& GetPlayers() { return m_Game.GetPlayers(); }
const game::PlayerList& GetPlayers() const { return m_Game.GetPlayers(); }
game::PlayerList& GetPlayers() { return m_Game.GetPlayers(); }
private:
void Accept();
void UpdateSockets();
void Accept();
void UpdateSockets();
void Clean();
void StartThread();
void StopThread();
void Tick(std::uint64_t delta);
void Clean();
void StartThread();
void StopThread();
void Tick(std::uint64_t delta);
void OnPlayerJoin(std::uint8_t id);
void OnPlayerLeave(std::uint8_t id);
void OnPlayerJoin(std::uint8_t id);
void OnPlayerLeave(std::uint8_t id);
};
} // namespace server

View File

@@ -11,49 +11,48 @@ namespace server {
class Server;
struct KeepAlive
{
std::uint64_t keepAliveID = 0;
std::uint64_t sendTime;
bool recievedResponse = false;
struct KeepAlive {
std::uint64_t keepAliveID = 0;
std::uint64_t sendTime;
bool recievedResponse = false;
};
class ServerConnexion : public protocol::Connexion {
private:
Server* m_Server = nullptr;
std::uint8_t m_ID;
KeepAlive m_KeepAlive;
game::Player* m_Player;
Server* m_Server = nullptr;
std::uint8_t m_ID;
KeepAlive m_KeepAlive;
game::Player* m_Player;
public:
ServerConnexion();
ServerConnexion(network::TCPSocket& socket, std::uint8_t id);
ServerConnexion(ServerConnexion&& move);
virtual ~ServerConnexion();
ServerConnexion();
ServerConnexion(network::TCPSocket& socket, std::uint8_t id);
ServerConnexion(ServerConnexion&& move);
virtual ~ServerConnexion();
void SetServer(Server* server);
void SetServer(Server* server);
virtual void HandlePacket(const protocol::PlayerLoginPacket* packet) override;
virtual void HandlePacket(const protocol::KeepAlivePacket* packet) override;
virtual void HandlePacket(const protocol::SelectTeamPacket* packet) override;
virtual void HandlePacket(const protocol::DisconnectPacket* packet) override;
virtual void HandlePacket(const protocol::PlaceTowerPacket* packet) override;
virtual void HandlePacket(const protocol::SendMobsPacket* packet) override;
virtual void HandlePacket(const protocol::UpgradeTowerPacket* packet) override;
virtual void HandlePacket(const protocol::RemoveTowerPacket* packet) override;
virtual void HandlePacket(const protocol::PlayerLoginPacket* packet) override;
virtual void HandlePacket(const protocol::KeepAlivePacket* packet) override;
virtual void HandlePacket(const protocol::SelectTeamPacket* packet) override;
virtual void HandlePacket(const protocol::DisconnectPacket* packet) override;
virtual void HandlePacket(const protocol::PlaceTowerPacket* packet) override;
virtual void HandlePacket(const protocol::SendMobsPacket* packet) override;
virtual void HandlePacket(const protocol::UpgradeTowerPacket* packet) override;
virtual void HandlePacket(const protocol::RemoveTowerPacket* packet) override;
std::uint8_t GetID() const { return m_ID; }
const game::Player* GetPlayer() const { return m_Player; }
game::Player* GetPlayer() { return m_Player; }
std::uint8_t GetID() const { return m_ID; }
const game::Player* GetPlayer() const { return m_Player; }
game::Player* GetPlayer() { return m_Player; }
virtual bool UpdateSocket();
virtual bool UpdateSocket();
REMOVE_COPY(ServerConnexion);
REMOVE_COPY(ServerConnexion);
private:
void RegisterHandlers();
void CheckKeepAlive();
void SendKeepAlive();
void InitConnection();
void RegisterHandlers();
void CheckKeepAlive();
void SendKeepAlive();
void InitConnection();
};
} // namespace server

View File

@@ -11,32 +11,32 @@ class Server;
class ServerGame : public game::Game, public game::GameListener {
private:
Server* m_Server;
ServerWorld m_ServerWorld;
utils::AutoTimer m_GoldMineTimer;
utils::AutoTimer m_MobStatesTimer;
utils::CooldownTimer m_EndGameCooldown;
Server* m_Server;
ServerWorld m_ServerWorld;
utils::AutoTimer m_GoldMineTimer;
utils::AutoTimer m_MobStatesTimer;
utils::CooldownTimer m_EndGameCooldown;
public:
ServerGame(Server* server);
~ServerGame() {}
ServerGame(Server* server);
~ServerGame() {}
ServerWorld* GetServerWorld() { return &m_ServerWorld; }
ServerWorld* GetServerWorld() { return &m_ServerWorld; }
virtual void Tick(std::uint64_t delta);
void StartGame();
virtual void Tick(std::uint64_t delta);
void StartGame();
// GameListener
// GameListener
virtual void OnGameStateUpdate(game::GameState newState) override;
virtual void OnGameBegin() override;
virtual void OnGameEnd() override;
virtual void OnGameClose() override;
virtual void OnGameStateUpdate(game::GameState newState) override;
virtual void OnGameBegin() override;
virtual void OnGameEnd() override;
virtual void OnGameClose() override;
private:
void BalanceTeams();
void InitPlayerStats();
void UpdateMobStates();
void UpdateGoldMines();
void UpdatePlayerStats();
void BalanceTeams();
void InitPlayerStats();
void UpdateMobStates();
void UpdateGoldMines();
void UpdatePlayerStats();
};
} // namespace game

View File

@@ -10,19 +10,19 @@ class ServerGame;
class ServerWorld : public game::World {
private:
game::MobID m_CurrentMobID;
game::TowerID m_CurrentTowerID;
Server* m_Server;
game::MobID m_CurrentMobID;
game::TowerID m_CurrentTowerID;
Server* m_Server;
public:
static constexpr float MobSpawnBorder = 0.01f;
static constexpr float MobSpawnBorder = 0.01f;
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);
game::TowerPtr PlaceTowerAt(game::TowerType type, std::int32_t x, std::int32_t y, game::PlayerID builder);
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);
virtual void OnMobDie(game::Mob* mob) override;
virtual void OnMobCastleDamage(game::Mob* damager, game::TeamCastle* enemyCastle, float damage) override;
virtual void OnMobDie(game::Mob* mob) override;
virtual void OnMobCastleDamage(game::Mob* damager, game::TeamCastle* enemyCastle, float damage) override;
};