framerate limiter that sucks less, based off SDL2_gfx
This commit is contained in:
parent
9fe24cb1e7
commit
63e15d2480
|
@ -371,7 +371,9 @@ wxThread::ExitCode EmuThread::Entry()
|
||||||
axismask = 0;
|
axismask = 0;
|
||||||
|
|
||||||
u32 nframes = 0;
|
u32 nframes = 0;
|
||||||
u32 lasttick = SDL_GetTicks();
|
u32 starttick = SDL_GetTicks();
|
||||||
|
u32 lasttick = starttick;
|
||||||
|
u32 lastmeasuretick = lasttick;
|
||||||
u32 fpslimitcount = 0;
|
u32 fpslimitcount = 0;
|
||||||
|
|
||||||
for (;;)
|
for (;;)
|
||||||
|
@ -384,8 +386,6 @@ wxThread::ExitCode EmuThread::Entry()
|
||||||
|
|
||||||
if (emustatus == 1)
|
if (emustatus == 1)
|
||||||
{
|
{
|
||||||
u32 starttick = SDL_GetTicks();
|
|
||||||
|
|
||||||
NDS::RunFrame();
|
NDS::RunFrame();
|
||||||
|
|
||||||
SDL_LockTexture(sdltex, NULL, &texpixels, &texstride);
|
SDL_LockTexture(sdltex, NULL, &texpixels, &texstride);
|
||||||
|
@ -409,21 +409,31 @@ wxThread::ExitCode EmuThread::Entry()
|
||||||
SDL_RenderCopy(sdlrend, sdltex, &botsrc, &botdst);
|
SDL_RenderCopy(sdlrend, sdltex, &botsrc, &botdst);
|
||||||
SDL_RenderPresent(sdlrend);
|
SDL_RenderPresent(sdlrend);
|
||||||
|
|
||||||
fpslimitcount++;
|
// framerate limiter based off SDL2_gfx
|
||||||
if (fpslimitcount >= 3) fpslimitcount = 0;
|
float framerate = 1000.0f / 60.0f;
|
||||||
u32 frametime = (fpslimitcount == 0) ? 16 : 17;
|
|
||||||
|
|
||||||
u32 endtick = SDL_GetTicks();
|
fpslimitcount++;
|
||||||
u32 diff = endtick - starttick;
|
u32 curtick = SDL_GetTicks();
|
||||||
if (diff < frametime)
|
u32 delay = curtick - lasttick;
|
||||||
Sleep(frametime - diff);
|
lasttick = curtick;
|
||||||
|
|
||||||
|
u32 wantedtick = starttick + (u32)((float)fpslimitcount * framerate);
|
||||||
|
if (curtick < wantedtick)
|
||||||
|
{
|
||||||
|
Sleep(wantedtick - curtick);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
fpslimitcount = 0;
|
||||||
|
starttick = curtick;
|
||||||
|
}
|
||||||
|
|
||||||
nframes++;
|
nframes++;
|
||||||
if (nframes >= 30)
|
if (nframes >= 30)
|
||||||
{
|
{
|
||||||
u32 tick = SDL_GetTicks();
|
u32 tick = SDL_GetTicks();
|
||||||
u32 diff = tick - lasttick;
|
u32 diff = tick - lastmeasuretick;
|
||||||
lasttick = tick;
|
lastmeasuretick = tick;
|
||||||
|
|
||||||
u32 fps = (nframes * 1000) / diff;
|
u32 fps = (nframes * 1000) / diff;
|
||||||
nframes = 0;
|
nframes = 0;
|
||||||
|
@ -437,6 +447,8 @@ wxThread::ExitCode EmuThread::Entry()
|
||||||
{
|
{
|
||||||
nframes = 0;
|
nframes = 0;
|
||||||
lasttick = SDL_GetTicks();
|
lasttick = SDL_GetTicks();
|
||||||
|
starttick = lasttick;
|
||||||
|
lastmeasuretick = lasttick;
|
||||||
fpslimitcount = 0;
|
fpslimitcount = 0;
|
||||||
|
|
||||||
Sleep(50);
|
Sleep(50);
|
||||||
|
|
Loading…
Reference in New Issue