refactor: add game listener

This commit is contained in:
2021-12-13 19:45:01 +01:00
parent 61166023df
commit 2148c0050c
6 changed files with 46 additions and 16 deletions

View File

@@ -5,7 +5,7 @@ namespace td {
namespace server {
ServerGame::ServerGame(server::Server* server) : game::Game(&m_ServerWorld), m_Server(server), m_ServerWorld(server, this) {
bindListener(this);
}
void ServerGame::tick(std::uint64_t delta) {
@@ -70,5 +70,24 @@ void ServerGame::balanceTeams() {
}
}
void ServerGame::OnGameStateUpdate(game::GameState newState) {
setGameState(newState);
protocol::UpdateGameStatePacket packet(newState);
m_Server->broadcastPacket(&packet);
}
void ServerGame::OnGameEnd() {
notifyListeners(&game::GameListener::OnGameStateUpdate, game::GameState::EndGame);
}
void ServerGame::OnGameClose() {
notifyListeners(&game::GameListener::OnGameStateUpdate, game::GameState::Closed);
}
void ServerGame::OnGameBegin() {
notifyListeners(&game::GameListener::OnGameStateUpdate, game::GameState::Game);
startGame();
}
} // namespace game
} // namespace td