mirror of
https://github.com/k4zmu2a/SpaceCadetPinball.git
synced 2024-11-22 00:40:18 +01: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
1 changed files with 12 additions and 4 deletions
|
@ -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;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue