mirror of
https://github.com/k4zmu2a/SpaceCadetPinball.git
synced 2023-12-30 21:52:56 +00:00
Fixed unaccounted frame time, now game should be stable at 8ms/125UPS.
Fixed pause handling.
This commit is contained in:
parent
ec13bca129
commit
0b2fd28fda
@ -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);
|
||||
|
||||
auto frameEnd = timeGetTime();
|
||||
frameEnd = timeGetTime();
|
||||
sleepRemainder = (frameEnd - updateEnd) - sleepDuration;
|
||||
}
|
||||
else
|
||||
{
|
||||
frameEnd = updateEnd;
|
||||
sleepRemainder = 0;
|
||||
}
|
||||
|
||||
frameDuration = min(frameEnd - frameStart, TargetFrameTime * 2);
|
||||
frameStart = frameEnd;
|
||||
|
||||
--someTimeCounter;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user