From 2225151f72020928b8fd4073475ef8b3da7de371 Mon Sep 17 00:00:00 2001 From: Persson-dev Date: Thu, 1 Jan 2026 22:17:01 +0100 Subject: [PATCH] add debug fastforward --- src/server/state/GameState.cpp | 4 ++-- src/td/display/state/DebugWorldState.cpp | 8 +++++++- src/td/simulation/ClientSimulation.cpp | 4 ++-- 3 files changed, 11 insertions(+), 5 deletions(-) diff --git a/src/server/state/GameState.cpp b/src/server/state/GameState.cpp index d46aba0..b702593 100644 --- a/src/server/state/GameState.cpp +++ b/src/server/state/GameState.cpp @@ -25,8 +25,8 @@ 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); + while (m_Time > stepTimeSecond) { + m_Time -= stepTimeSecond; auto lockStepPacket = m_Simulation.Update(); BroadcastPacket(lockStepPacket); } diff --git a/src/td/display/state/DebugWorldState.cpp b/src/td/display/state/DebugWorldState.cpp index 7baab80..162ee6f 100644 --- a/src/td/display/state/DebugWorldState.cpp +++ b/src/td/display/state/DebugWorldState.cpp @@ -52,7 +52,7 @@ DebugWorldState::DebugWorldState(Display& a_Display) : DisplayState(a_Display) { }); list.OnPlayerKick.Connect([this](PlayerID a_Player) { - auto it = std::find_if(m_FakeClients.begin(), m_FakeClients.end(), [a_Player](auto& clientPtr){ + auto it = std::find_if(m_FakeClients.begin(), m_FakeClients.end(), [a_Player](auto& clientPtr) { if (!clientPtr->GetId().has_value()) return false; return clientPtr->GetId().value() == a_Player; @@ -85,6 +85,7 @@ void DebugWorldState::OnAspectRatioChange(float a_Ratio) { void DebugWorldState::OnKeyDown(SDL_Keycode a_Key) { // temporary tests + constexpr int SECONDS = 10; switch (a_Key) { case SDLK_A: m_Client->SendPacket(td::protocol::packets::SpawnTroopPacket(td::EntityType::Zombie, 1)); @@ -94,6 +95,11 @@ void DebugWorldState::OnKeyDown(SDL_Keycode a_Key) { m_Client->SendPacket(td::protocol::packets::PlaceTowerPacket(td::TowerType::Archer, td::TowerCoords(77, 13))); break; + case SDLK_F: + m_Server->Update(SECONDS); + m_Client->Update(SECONDS); + break; + default: break; } diff --git a/src/td/simulation/ClientSimulation.cpp b/src/td/simulation/ClientSimulation.cpp index dfb69c6..d3bcbe7 100644 --- a/src/td/simulation/ClientSimulation.cpp +++ b/src/td/simulation/ClientSimulation.cpp @@ -51,8 +51,8 @@ float ClientSimulation::Update(float a_Delta) { // TODO: handle freezes (m_CurrentTime > 2 * m_StepTime) static const float stepTimeSecond = static_cast(m_StepTime) / 1000.0f; m_CurrentTime += a_Delta; - if (m_CurrentTime > stepTimeSecond) { - m_CurrentTime = std::fmod(m_CurrentTime, stepTimeSecond); + while (m_CurrentTime > stepTimeSecond) { + m_CurrentTime -= stepTimeSecond; Step(); } return (float)m_CurrentTime / stepTimeSecond;