1
0
Fork 0
mirror of https://github.com/k4zmu2a/SpaceCadetPinball.git synced 2024-11-21 16:30:19 +01:00

Fixed unaccounted frame time, now game should be stable at 8ms/125UPS.

Fixed pause handling.
This commit is contained in:
Muzychenko Andrey 2021-11-12 16:21:02 +03:00
parent ec13bca129
commit 0b2fd28fda

View file

@ -224,7 +224,7 @@ int winmain::WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLi
else
pb::replay_level(0);
DWORD someTimeCounter = 300u, prevTime = 0u;
DWORD someTimeCounter = 300u, prevTime = 0u, frameStart = timeGetTime();
int sleepRemainder = 0, frameDuration = TargetFrameTime;
while (true)
{
@ -277,7 +277,6 @@ int winmain::WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLi
if (!single_step)
{
auto frameStart = timeGetTime();
auto dt = frameDuration;
if (!no_time_loss)
pb::frame(dt);
@ -313,12 +312,21 @@ int winmain::WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLi
auto updateEnd = timeGetTime();
auto sleepDuration = TargetFrameTime - (int)(updateEnd - frameStart) - sleepRemainder;
DWORD frameEnd;
if (sleepDuration > 0)
{
Sleep(sleepDuration);
frameEnd = timeGetTime();
sleepRemainder = (frameEnd - updateEnd) - sleepDuration;
}
else
{
frameEnd = updateEnd;
sleepRemainder = 0;
}
auto frameEnd = timeGetTime();
sleepRemainder = (frameEnd - updateEnd) - sleepDuration;
frameDuration = min(frameEnd - frameStart, TargetFrameTime * 2);
frameStart = frameEnd;
--someTimeCounter;
}