Replace float/UInt64 durations by a more precise Time class (#388)

Improve Clock class with atomic RestartIfOver method and allows to choose required precision
This commit is contained in:
Jérôme Leclercq
2022-12-29 21:31:46 +01:00
committed by GitHub
parent 1de5f65536
commit dd421a6385
84 changed files with 1278 additions and 663 deletions

View File

@@ -127,19 +127,11 @@ int main()
mainWindow.EnableEventPolling(true);
Nz::Clock updateClock;
Nz::Clock secondClock;
Nz::MillisecondClock fpsClock;
unsigned int fps = 0;
float elapsedTime = 0.f;
Nz::UInt64 time = Nz::GetElapsedMicroseconds();
while (mainWindow.IsOpen())
{
Nz::UInt64 now = Nz::GetElapsedMicroseconds();
elapsedTime = (now - time) / 1'000'000.f;
time = now;
Nz::WindowEvent event;
while (mainWindow.PollEvent(&event))
{
@@ -158,13 +150,10 @@ int main()
fps++;
if (secondClock.GetMilliseconds() >= 1000)
if (fpsClock.RestartIfOver(Nz::Time::Second()))
{
mainWindow.SetTitle(windowTitle + " - " + Nz::NumberToString(fps) + " FPS" + " - " + Nz::NumberToString(registry.alive()) + " entities");
fps = 0;
secondClock.Restart();
}
}