GIGA REFACTOR

This commit is contained in:
2022-03-02 18:51:42 +01:00
parent 553b2f6aad
commit 6df59b1487
92 changed files with 1807 additions and 1785 deletions

View File

@@ -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);