add debug fastforward

This commit is contained in:
2026-01-01 22:17:01 +01:00
parent aef0cf4d95
commit 2225151f72
3 changed files with 11 additions and 5 deletions

View File

@@ -25,8 +25,8 @@ void GameState::Update(float a_Delta) {
// TODO: don't make STEP_TIME constant
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);
while (m_Time > stepTimeSecond) {
m_Time -= stepTimeSecond;
auto lockStepPacket = m_Simulation.Update();
BroadcastPacket(lockStepPacket);
}

View File

@@ -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;
}

View File

@@ -51,8 +51,8 @@ float ClientSimulation::Update(float a_Delta) {
// TODO: handle freezes (m_CurrentTime > 2 * m_StepTime)
static const float stepTimeSecond = static_cast<float>(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;