Core/ApplicationBase: Fix elapsedTime in updaters for non-fixed intervals

This commit is contained in:
SirLynix 2023-05-01 18:03:01 +02:00
parent 147f1bc1cf
commit 3e4f32140e
2 changed files with 7 additions and 0 deletions

View File

@ -78,6 +78,7 @@ namespace Nz
else else
updaterEntry.nextUpdate = updaterEntry.lastUpdate + (-interval); updaterEntry.nextUpdate = updaterEntry.lastUpdate + (-interval);
updaterEntry.lastUpdate = m_currentTime;
updaterEntry.nextUpdate = std::max(updaterEntry.nextUpdate, m_currentTime); updaterEntry.nextUpdate = std::max(updaterEntry.nextUpdate, m_currentTime);
} }

View File

@ -39,6 +39,8 @@ SCENARIO("Application", "[CORE][ABSTRACTHASH]")
INFO("First update should have elapsed time as zero"); INFO("First update should have elapsed time as zero");
CHECK(elapsedTime == Nz::Time::Zero()); CHECK(elapsedTime == Nz::Time::Zero());
} }
else
CHECK(elapsedTime < Nz::Time::Milliseconds(200));
triggerCount++; triggerCount++;
}); });
@ -51,6 +53,10 @@ SCENARIO("Application", "[CORE][ABSTRACTHASH]")
CHECK(triggerCount == 2); CHECK(triggerCount == 2);
app.Update(Nz::Time::Milliseconds(90)); app.Update(Nz::Time::Milliseconds(90));
CHECK(triggerCount == 2); // this does not trigger since 100ms have not elapsed since last update CHECK(triggerCount == 2); // this does not trigger since 100ms have not elapsed since last update
app.Update(Nz::Time::Milliseconds(10));
CHECK(triggerCount == 3);
app.Update(Nz::Time::Milliseconds(100));
CHECK(triggerCount == 4);
} }
WHEN("Using fixed-time interval") WHEN("Using fixed-time interval")