GIGA REFACTOR
This commit is contained in:
@@ -22,9 +22,9 @@ public:
|
||||
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
|
||||
|
||||
@@ -28,25 +28,25 @@ private:
|
||||
public:
|
||||
TickCounter() {}
|
||||
|
||||
void reset() {
|
||||
void Reset() {
|
||||
m_TPS = SERVER_TPS;
|
||||
m_LastTPSTime = utils::getTime();
|
||||
m_LastTPSTime = utils::GetTime();
|
||||
m_TickCount = 0;
|
||||
}
|
||||
|
||||
bool update() { // return true when tps is updated
|
||||
bool Update() { // return true when tps is updated
|
||||
m_TickCount++;
|
||||
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_TickCount = 0;
|
||||
m_LastTPSTime = td::utils::getTime();
|
||||
m_LastTPSTime = td::utils::GetTime();
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
float getTPS() const { return m_TPS; }
|
||||
float GetTPS() const { return m_TPS; }
|
||||
};
|
||||
|
||||
class Server {
|
||||
@@ -63,36 +63,36 @@ public:
|
||||
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);
|
||||
|
||||
@@ -31,7 +31,7 @@ public:
|
||||
ServerConnexion(ServerConnexion&& move);
|
||||
virtual ~ServerConnexion();
|
||||
|
||||
void setServer(Server* server);
|
||||
void SetServer(Server* server);
|
||||
|
||||
virtual void HandlePacket(const protocol::PlayerLoginPacket* packet);
|
||||
virtual void HandlePacket(const protocol::KeepAlivePacket* packet);
|
||||
@@ -42,18 +42,18 @@ public:
|
||||
virtual void HandlePacket(const protocol::UpgradeTowerPacket* packet);
|
||||
virtual void HandlePacket(const protocol::RemoveTowerPacket* packet);
|
||||
|
||||
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);
|
||||
private:
|
||||
void registerHandlers();
|
||||
void checkKeepAlive();
|
||||
void sendKeepAlive();
|
||||
void initConnection();
|
||||
void RegisterHandlers();
|
||||
void CheckKeepAlive();
|
||||
void SendKeepAlive();
|
||||
void InitConnection();
|
||||
};
|
||||
|
||||
} // namespace server
|
||||
|
||||
@@ -20,10 +20,10 @@ public:
|
||||
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
|
||||
|
||||
@@ -32,10 +32,10 @@ public:
|
||||
virtual void OnGameEnd();
|
||||
virtual void OnGameClose();
|
||||
private:
|
||||
void balanceTeams();
|
||||
void updateMobStates();
|
||||
void updateGoldMines();
|
||||
void updatePlayerStats();
|
||||
void BalanceTeams();
|
||||
void UpdateMobStates();
|
||||
void UpdateGoldMines();
|
||||
void UpdatePlayerStats();
|
||||
};
|
||||
|
||||
} // namespace game
|
||||
|
||||
@@ -18,8 +18,8 @@ public:
|
||||
|
||||
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);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user