refactor: format code
This commit is contained in:
@@ -9,7 +9,7 @@ namespace server {
|
||||
|
||||
class Server;
|
||||
|
||||
class Lobby{
|
||||
class Lobby {
|
||||
private:
|
||||
Server* m_Server;
|
||||
bool m_GameStarted = false;
|
||||
|
||||
@@ -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();
|
||||
|
||||
@@ -6,8 +6,8 @@
|
||||
#include "game/Player.h"
|
||||
#include "game/Connexion.h"
|
||||
|
||||
namespace td{
|
||||
namespace server{
|
||||
namespace td {
|
||||
namespace server {
|
||||
|
||||
class Server;
|
||||
|
||||
@@ -19,7 +19,7 @@ struct KeepAlive
|
||||
};
|
||||
|
||||
|
||||
class ServerConnexion : public protocol::Connexion{
|
||||
class ServerConnexion : public protocol::Connexion {
|
||||
private:
|
||||
Server* m_Server = nullptr;
|
||||
std::uint8_t m_ID;
|
||||
@@ -39,9 +39,9 @@ public:
|
||||
virtual void HandlePacket(protocol::DisconnectPacket* packet);
|
||||
virtual void HandlePacket(protocol::PlaceTowerPacket* 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();
|
||||
|
||||
|
||||
@@ -9,14 +9,14 @@ namespace server {
|
||||
|
||||
class Server;
|
||||
|
||||
class ServerGame : public game::Game{
|
||||
class ServerGame : public game::Game {
|
||||
private:
|
||||
Server* m_Server;
|
||||
ServerWorld m_ServerWorld;
|
||||
utils::Timer m_GoldMineTimer{1000, std::bind(&ServerGame::updateGoldMines, this)};
|
||||
utils::Timer m_GoldMineTimer{ 1000, std::bind(&ServerGame::updateGoldMines, this) };
|
||||
public:
|
||||
ServerGame(Server* server);
|
||||
~ServerGame(){}
|
||||
~ServerGame() {}
|
||||
|
||||
virtual void tick(std::uint64_t delta);
|
||||
void startGame();
|
||||
|
||||
@@ -8,7 +8,7 @@ namespace server {
|
||||
class Server;
|
||||
class ServerGame;
|
||||
|
||||
class ServerWorld : public game::World{
|
||||
class ServerWorld : public game::World {
|
||||
private:
|
||||
game::MobID m_CurrentMobID;
|
||||
Server* m_Server;
|
||||
|
||||
Reference in New Issue
Block a user