#include #include #include namespace td { namespace server { GameState::GameState(Server& a_Server, const std::shared_ptr& a_World) : ServerState(a_Server), m_World(a_World), m_Simulation(*m_World, STEP_TIME), m_Time(0) { 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) { // TODO: don't make STEP_TIME constant static const float stepTimeSecond = static_cast(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); } } } // namespace server } // namespace td