begin client-server

This commit is contained in:
2025-08-06 20:10:56 +02:00
parent 89213e9a97
commit c813c49707
26 changed files with 264 additions and 188 deletions

View File

@@ -1,25 +1,36 @@
#include <server/state/GameState.h>
#include <server/state/GameStateHandler.h>
#include <iostream>
namespace td {
namespace server {
void GameState::HandlePacket(PlayerID a_Id, const protocol::PacketBase& a_Packet) {
GameState::GameState(const std::shared_ptr<game::World>& a_World) : m_World(a_World), m_Simulation(*m_World, STEP_TIME), m_Time(0) {}
void GameState::Init() {
std::cout << "Switched to Game state !\n";
BroadcastPacket(m_Simulation.MakePacket());
}
void GameState::HandlePacket(PlayerID a_Id, const protocol::PacketBase& a_Packet) {
GameStateHandler handler(*this, a_Id);
a_Packet.Dispatch(handler);
}
void GameState::Update(float a_Delta) {
static const float stepTimeSecond = static_cast<float>(STEP_TIME) / 1000.0f;
m_Time += a_Delta;
if (m_Time > stepTimeSecond) {
m_Time = std::fmod(m_Time, stepTimeSecond);
auto lockStepPacket = m_Simulation.Update();
BroadcastPacket(lockStepPacket);
}
}
void GameState::OnPlayerJoin(PlayerID a_Id) {
void GameState::OnPlayerJoin(PlayerID a_Id) {}
}
void GameState::OnPlayerLeave(PlayerID a_Id) {
std::cout << "Game leave !" << std::endl;
}
void GameState::OnPlayerLeave(PlayerID a_Id) {}
} // namespace server
} // namespace td