mirror of
https://github.com/RetroDECK/Supermodel.git
synced 2024-11-26 15:45:41 +00:00
change throttle logic for smoother playback, we could get closer to 60fps if SDL timers weren't so lame
This commit is contained in:
parent
2f49012786
commit
0a7c0d0864
|
@ -899,6 +899,15 @@ void EndFrameVideo()
|
||||||
SDL_GL_SwapBuffers();
|
SDL_GL_SwapBuffers();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void SuperSleep(UINT32 time)
|
||||||
|
{
|
||||||
|
UINT32 start = SDL_GetTicks();
|
||||||
|
UINT32 tics = start;
|
||||||
|
|
||||||
|
while (start + time > tics) {
|
||||||
|
tics = SDL_GetTicks();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/******************************************************************************
|
/******************************************************************************
|
||||||
Main Program Loop
|
Main Program Loop
|
||||||
|
@ -913,9 +922,7 @@ int Supermodel(const char *zipFile, IEmulator *Model3, CInputs *Inputs, COutputs
|
||||||
{
|
{
|
||||||
#endif // SUPERMODEL_DEBUGGER
|
#endif // SUPERMODEL_DEBUGGER
|
||||||
unsigned prevFPSTicks;
|
unsigned prevFPSTicks;
|
||||||
unsigned startTicks;
|
|
||||||
unsigned fpsFramesElapsed;
|
unsigned fpsFramesElapsed;
|
||||||
unsigned framesElapsed;
|
|
||||||
bool gameHasLightguns = false;
|
bool gameHasLightguns = false;
|
||||||
bool quit = false;
|
bool quit = false;
|
||||||
bool paused = false;
|
bool paused = false;
|
||||||
|
@ -990,9 +997,7 @@ int Supermodel(const char *zipFile, IEmulator *Model3, CInputs *Inputs, COutputs
|
||||||
|
|
||||||
// Emulate!
|
// Emulate!
|
||||||
fpsFramesElapsed = 0;
|
fpsFramesElapsed = 0;
|
||||||
framesElapsed = 0;
|
|
||||||
prevFPSTicks = SDL_GetTicks();
|
prevFPSTicks = SDL_GetTicks();
|
||||||
startTicks = prevFPSTicks;
|
|
||||||
quit = false;
|
quit = false;
|
||||||
paused = false;
|
paused = false;
|
||||||
dumpTimings = false;
|
dumpTimings = false;
|
||||||
|
@ -1005,6 +1010,8 @@ int Supermodel(const char *zipFile, IEmulator *Model3, CInputs *Inputs, COutputs
|
||||||
#endif
|
#endif
|
||||||
while (!quit)
|
while (!quit)
|
||||||
{
|
{
|
||||||
|
auto startTime = SDL_GetTicks();
|
||||||
|
|
||||||
// Render if paused, otherwise run a frame
|
// Render if paused, otherwise run a frame
|
||||||
if (paused)
|
if (paused)
|
||||||
Model3->RenderFrame();
|
Model3->RenderFrame();
|
||||||
|
@ -1287,15 +1294,13 @@ int Supermodel(const char *zipFile, IEmulator *Model3, CInputs *Inputs, COutputs
|
||||||
|
|
||||||
if (paused || g_Config.throttle)
|
if (paused || g_Config.throttle)
|
||||||
{
|
{
|
||||||
++framesElapsed;
|
UINT32 endTime = SDL_GetTicks();
|
||||||
unsigned targetTicks = startTicks + (unsigned) ((float)framesElapsed * 1000.0f/60.0f);
|
UINT32 diff = endTime - startTime;
|
||||||
if (currentTicks <= targetTicks) // add a delay until we reach the next (target) frame time
|
UINT32 frameTime = (UINT32)(1000 / 60.f); // 60 fps, we could roll with 57.5? that would be a jerk fest on 60hz screens though
|
||||||
SDL_Delay(targetTicks - currentTicks);
|
|
||||||
else // begin a new frame
|
if (diff < frameTime) {
|
||||||
{
|
SuperSleep(frameTime - diff);
|
||||||
framesElapsed = 0;
|
}
|
||||||
startTicks = currentTicks;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (dumpTimings && !paused)
|
if (dumpTimings && !paused)
|
||||||
|
|
Loading…
Reference in a new issue