start skipping frames when we are too slow
This commit is contained in:
parent
104d89de91
commit
afc5d8765b
1 changed files with 26 additions and 0 deletions
|
@ -719,6 +719,8 @@ const EventCallback *GetCallbacks()
|
|||
return Callbacks;
|
||||
}
|
||||
|
||||
static int SkipFrameMask = 0;
|
||||
|
||||
/**
|
||||
** Wait for interactive input event for one frame.
|
||||
**
|
||||
|
@ -738,6 +740,27 @@ void WaitEventsOneFrame()
|
|||
Uint32 ticks = SDL_GetTicks();
|
||||
if (ticks > NextFrameTicks) { // We are too slow :(
|
||||
++SlowFrameCounter;
|
||||
if (SlowFrameCounter > FRAMES_PER_SECOND) {
|
||||
unsigned long pct = (SlowFrameCounter * 100) / (FrameCounter ? FrameCounter : 1);
|
||||
bool warn = false;
|
||||
if (pct >= 40) {
|
||||
warn = (SkipFrameMask > 0b1);
|
||||
SkipFrameMask = 0b1;
|
||||
} else if (pct >= 20) {
|
||||
warn = (SkipFrameMask > 0b11);
|
||||
SkipFrameMask = 0b11;
|
||||
} else if (pct >= 10) {
|
||||
warn = (SkipFrameMask == 0);
|
||||
SkipFrameMask = 0b111;
|
||||
}
|
||||
if (warn) {
|
||||
fprintf(stdout, "WARNING WARNING WARNING\n"
|
||||
"Frames %lu, Slow frames %d = %lu%%, starting to skip every %d%s frame.\n",
|
||||
FrameCounter, SlowFrameCounter, pct, SkipFrameMask + 1, SkipFrameMask == 1 ? "nd" : "th");
|
||||
fflush(stdout);
|
||||
SlowFrameCounter = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
InputMouseTimeout(*GetCallbacks(), ticks);
|
||||
|
@ -803,6 +826,9 @@ void RealizeVideoMemory()
|
|||
if (dummyRenderer) {
|
||||
return;
|
||||
}
|
||||
if (SkipFrameMask && (FrameCounter & SkipFrameMask) == SkipFrameMask) {
|
||||
return;
|
||||
}
|
||||
if (NumRects) {
|
||||
//SDL_UpdateWindowSurfaceRects(TheWindow, Rects, NumRects);
|
||||
SDL_UpdateTexture(TheTexture, NULL, TheScreen->pixels, TheScreen->pitch);
|
||||
|
|
Loading…
Reference in a new issue