From d5c916b724a6d2ad233a972b21b71fc4ed0772ca Mon Sep 17 00:00:00 2001 From: Tim Felgentreff Date: Tue, 26 Jul 2022 18:04:15 +0200 Subject: [PATCH] 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 --- src/include/unit.h | 2 ++ src/stratagus/stratagus.cpp | 2 +- src/tolua/unit.pkg | 2 ++ src/video/sdl.cpp | 22 +--------------------- 4 files changed, 6 insertions(+), 22 deletions(-) diff --git a/src/include/unit.h b/src/include/unit.h index 72c48208e..af9b7de33 100644 --- a/src/include/unit.h +++ b/src/include/unit.h @@ -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. diff --git a/src/stratagus/stratagus.cpp b/src/stratagus/stratagus.cpp index 9748f71a5..b824c8064 100644 --- a/src/stratagus/stratagus.cpp +++ b/src/stratagus/stratagus.cpp @@ -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); diff --git a/src/tolua/unit.pkg b/src/tolua/unit.pkg index a51535f21..c1946ed86 100644 --- a/src/tolua/unit.pkg +++ b/src/tolua/unit.pkg @@ -37,6 +37,8 @@ class CPreference bool HardwareCursor; bool SelectionRectangleIndicatesDamage; + unsigned int FrameSkip; + unsigned int ShowOrders; unsigned int ShowNameDelay; unsigned int ShowNameTime; diff --git a/src/video/sdl.cpp b/src/video/sdl.cpp index 7c8269d20..f956484a8 100644 --- a/src/video/sdl.cpp +++ b/src/video/sdl.cpp @@ -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) {