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

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