refactor: format code

This commit is contained in:
2021-09-19 17:33:16 +02:00
parent 52a143769e
commit 0856ca47ca
71 changed files with 1102 additions and 1110 deletions

View File

@@ -22,23 +22,23 @@ namespace server {
typedef std::map<std::uint8_t, ServerConnexion> ConnexionMap;
class TickCounter{
class TickCounter {
private:
float m_TPS;
std::uint64_t m_LastTPSTime;
std::uint8_t m_TickCount;
public:
TickCounter(){}
TickCounter() {}
void reset(){
void reset() {
m_TPS = SERVER_TPS;
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){
if (m_TickCount >= SERVER_TPS) {
std::uint64_t timeElapsedSinceLast20Ticks = td::utils::getTime() - m_LastTPSTime;
m_TPS = (float)SERVER_TPS / (float)(timeElapsedSinceLast20Ticks / 1000.0f);
m_TickCount = 0;
@@ -48,19 +48,19 @@ public:
return false;
}
float getTPS() const{ return m_TPS; }
float getTPS() const { return m_TPS; }
};
class Server{
class Server {
private:
network::TCPListener m_Listener;
ConnexionMap m_Connections;
ServerGame m_Game{this};
Lobby m_Lobby{this};
ServerGame m_Game{ this };
Lobby m_Lobby{ this };
TickCounter m_TickCounter;
public:
Server(const std::string& worldFilePath);
virtual ~Server(){}
virtual ~Server() {}
bool start(std::uint16_t port);
void tick(std::uint64_t delta);
@@ -72,17 +72,17 @@ public:
void broadcastPacket(protocol::Packet* packet);
float getTPS() const{ return m_TickCounter.getTPS(); }
float getTPS() const { return m_TickCounter.getTPS(); }
const ServerGame& getGame() const{ 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();