4444#include " Common/ThingFactory.h"
4545#include " Common/file.h"
4646#include " Common/FileSystem.h"
47+ #include " Common/FrameRateLimit.h"
4748#include " Common/ArchiveFileSystem.h"
4849#include " Common/LocalFileSystem.h"
4950#include " Common/CDManager.h"
@@ -668,8 +669,8 @@ extern HWND ApplicationHWnd;
668669 */
669670void GameEngine::execute ( void )
670671{
672+ FrameRateLimit* frameRateLimit = new FrameRateLimit ();
671673
672- DWORD prevTime = timeGetTime ();
673674#if defined(RTS_DEBUG)
674675 DWORD startTime = timeGetTime () / 1000 ;
675676#endif
@@ -743,35 +744,28 @@ void GameEngine::execute( void )
743744 if (TheTacticalView->getTimeMultiplier ()<=1 && !TheScriptEngine->isTimeFast ())
744745 {
745746
746- // I'm disabling this in internal because many people need alt-tab capability. If you happen to be
747+ // I'm disabling this in debug because many people need alt-tab capability. If you happen to be
747748 // doing performance tuning, please just change this on your local system. -MDC
748749 #if defined(RTS_DEBUG)
749750 ::Sleep (1 ); // give everyone else a tiny time slice.
750751 #endif
751752
752753
753754 #if defined(_ALLOW_DEBUG_CHEATS_IN_RELEASE)
754- if ( ! TheGlobalData->m_TiVOFastMode )
755- #else // always allow this cheatkey if we're in a replaygame .
756- if ( ! (TheGlobalData->m_TiVOFastMode && TheGameLogic->isInReplayGame ()))
755+ if ( ! TheGlobalData->m_TiVOFastMode )
756+ #else // always allow this cheat key if we're in a replay game .
757+ if ( ! (TheGlobalData->m_TiVOFastMode && TheGameLogic->isInReplayGame ()))
757758 #endif
758- {
759- // limit the framerate
760- DWORD now = timeGetTime ();
761- DWORD limit = (1000 .0f /m_maxFPS)-1 ;
762- while (TheGlobalData->m_useFpsLimit && (now - prevTime) < limit)
763- {
764- ::Sleep (0 );
765- now = timeGetTime ();
766- }
767- // Int slept = now - prevTime;
768- // DEBUG_LOG(("delayed %d",slept));
769-
770- prevTime = now;
771-
772- }
773-
774- }
759+ {
760+ // TheSuperHackers @bugfix xezon 05/08/2025 Re-implements the frame rate limiter
761+ // with higher resolution counters to cap the frame rate more accurately to the desired limit.
762+ if (TheGlobalData->m_useFpsLimit )
763+ {
764+ frameRateLimit->wait (m_maxFPS);
765+ }
766+ }
767+
768+ }
775769 }
776770
777771 } // perfgather for execute_loop
@@ -787,6 +781,7 @@ void GameEngine::execute( void )
787781
788782 }
789783
784+ delete frameRateLimit;
790785}
791786
792787/* * -----------------------------------------------------------------------------------------------
0 commit comments