make frame skip a preference

good values are
 1 - render only even frames
 3 - render only frames divisble by 4 (i.e., only 25%)

anything higher is probably just choppy
This commit is contained in:
Tim Felgentreff 2022-07-26 18:04:15 +02:00
parent a2ddef78de
commit d5c916b724
4 changed files with 6 additions and 22 deletions

View file

@ -469,6 +469,8 @@ public:
bool HardwareCursor; /// If true, uses the hardware to draw the cursor. Shaders do no longer apply to the cursor, but this way it's decoupled from the game refresh rate
bool SelectionRectangleIndicatesDamage; /// If true, the selection rectangle interpolates color to indicate damage
int FrameSkip; /// Mask used to skip rendering frames (useful for slow renderers that keep up with the game logic, but not the rendering to screen like e.g. original Raspberry Pi)
int ShowOrders; /// How many second show orders of unit on map.
int ShowNameDelay; /// How many cycles need to wait until unit's name popup will appear.
int ShowNameTime; /// How many cycles need to show unit's name popup.

View file

@ -405,7 +405,7 @@ void Exit(int err)
FreeButtonStyles();
FreeAllContainers();
freeGuichan();
fprintf(stdout, "Frames %lu, Slow frames %d = %ld%%\n",
fprintf(stdout, "Frames %lu, Slow frames %ld = %ld%%\n",
FrameCounter, SlowFrameCounter,
(SlowFrameCounter * 100) / (FrameCounter ? FrameCounter : 1));
lua_settop(Lua, 0);

View file

@ -37,6 +37,8 @@ class CPreference
bool HardwareCursor;
bool SelectionRectangleIndicatesDamage;
unsigned int FrameSkip;
unsigned int ShowOrders;
unsigned int ShowNameDelay;
unsigned int ShowNameTime;

View file

@ -719,9 +719,6 @@ const EventCallback *GetCallbacks()
return Callbacks;
}
static int SkipFrameMask = 0;
static unsigned long NextSlowFrameReaction = FRAMES_PER_SECOND * 10;
/**
** Wait for interactive input event for one frame.
**
@ -741,23 +738,6 @@ void WaitEventsOneFrame()
Uint32 ticks = SDL_GetTicks();
if (ticks > NextFrameTicks) { // We are too slow :(
++SlowFrameCounter;
if (SlowFrameCounter > NextSlowFrameReaction) {
unsigned long pct = (SlowFrameCounter * 100) / (FrameCounter ? FrameCounter : 1);
if (pct >= 60) {
SkipFrameMask = 0b111;
} else if (pct >= 40) {
SkipFrameMask = 0b101;
} else if (pct >= 20) {
SkipFrameMask = 0b11;
} else if (pct >= 10) {
SkipFrameMask = 0b1;
}
NextSlowFrameReaction += FRAMES_PER_SECOND * 10;
fprintf(stdout, "WARNING WARNING WARNING\n"
"Frames %lu, Slow frames %d = %lu%%, starting to render only every %d%s frame.\n",
FrameCounter, SlowFrameCounter, pct, SkipFrameMask + 1, SkipFrameMask == 1 ? "nd" : "th");
fflush(stdout);
}
}
InputMouseTimeout(*GetCallbacks(), ticks);
@ -855,7 +835,7 @@ void RealizeVideoMemory()
if (dummyRenderer) {
return;
}
if (FrameCounter & SkipFrameMask) {
if (Preference.FrameSkip && (FrameCounter & Preference.FrameSkip)) {
return;
}
if (NumRects) {