mirror of
https://github.com/k4zmu2a/SpaceCadetPinball.git
synced 2024-11-22 08:50: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
|
else
|
||||||
pb::replay_level(0);
|
pb::replay_level(0);
|
||||||
|
|
||||||
DWORD someTimeCounter = 300u, prevTime = 0u;
|
DWORD someTimeCounter = 300u, prevTime = 0u, frameStart = timeGetTime();
|
||||||
int sleepRemainder = 0, frameDuration = TargetFrameTime;
|
int sleepRemainder = 0, frameDuration = TargetFrameTime;
|
||||||
while (true)
|
while (true)
|
||||||
{
|
{
|
||||||
|
@ -277,7 +277,6 @@ int winmain::WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLi
|
||||||
|
|
||||||
if (!single_step)
|
if (!single_step)
|
||||||
{
|
{
|
||||||
auto frameStart = timeGetTime();
|
|
||||||
auto dt = frameDuration;
|
auto dt = frameDuration;
|
||||||
if (!no_time_loss)
|
if (!no_time_loss)
|
||||||
pb::frame(dt);
|
pb::frame(dt);
|
||||||
|
@ -313,12 +312,21 @@ int winmain::WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLi
|
||||||
auto updateEnd = timeGetTime();
|
auto updateEnd = timeGetTime();
|
||||||
auto sleepDuration = TargetFrameTime - (int)(updateEnd - frameStart) - sleepRemainder;
|
auto sleepDuration = TargetFrameTime - (int)(updateEnd - frameStart) - sleepRemainder;
|
||||||
|
|
||||||
|
DWORD frameEnd;
|
||||||
if (sleepDuration > 0)
|
if (sleepDuration > 0)
|
||||||
|
{
|
||||||
Sleep(sleepDuration);
|
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);
|
frameDuration = min(frameEnd - frameStart, TargetFrameTime * 2);
|
||||||
|
frameStart = frameEnd;
|
||||||
|
|
||||||
--someTimeCounter;
|
--someTimeCounter;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue