diff --git a/Generals/Code/GameEngine/Include/Common/GameEngine.h b/Generals/Code/GameEngine/Include/Common/GameEngine.h index 5785212386..90be51a76c 100644 --- a/Generals/Code/GameEngine/Include/Common/GameEngine.h +++ b/Generals/Code/GameEngine/Include/Common/GameEngine.h @@ -78,7 +78,7 @@ class GameEngine : public SubsystemInterface virtual void setFramesPerSecondLimit( Int fps ); ///< Set the max render and engine update fps. virtual Int getFramesPerSecondLimit( void ); ///< Get the max render and engine update fps. - Real getUpdateTime(); ///< Get the last engine update delta time. + Real getUpdateTime(); ///< Get the last engine update delta time in seconds. Real getUpdateFps(); ///< Get the last engine update fps. static Bool isTimeFrozen(); ///< Returns true if a script has frozen time. @@ -128,7 +128,7 @@ class GameEngine : public SubsystemInterface Int m_maxFPS; ///< Maximum frames per second for rendering Int m_logicTimeScaleFPS; ///< Maximum frames per second for logic time scale - Real m_updateTime; ///< Last engine update delta time + Real m_updateTime; ///< Last engine update delta time in seconds Real m_logicTimeAccumulator; ///< Frame time accumulated towards submitting a new logic frame Bool m_quitting; ///< true when we need to quit the game diff --git a/Generals/Code/GameEngineDevice/Include/W3DDevice/GameClient/W3DDisplay.h b/Generals/Code/GameEngineDevice/Include/W3DDevice/GameClient/W3DDisplay.h index ffac86708e..7f4cdeacee 100644 --- a/Generals/Code/GameEngineDevice/Include/W3DDevice/GameClient/W3DDisplay.h +++ b/Generals/Code/GameEngineDevice/Include/W3DDevice/GameClient/W3DDisplay.h @@ -161,7 +161,7 @@ class W3DDisplay : public Display void drawCurrentDebugDisplay( void ); ///< draws current debug display void calculateTerrainLOD(void); ///< Calculate terrain LOD. void renderLetterBox(UnsignedInt time); ///< draw letter box border - void updateAverageFPS(void); ///< figure out the average fps over the last 30 frames. + void updateAverageFPS(void); ///< calculate the average fps over the last 30 frames. Byte m_initialized; ///< TRUE when system is initialized LightClass *m_myLight[LightEnvironmentClass::MAX_LIGHTS]; ///< light hack for now diff --git a/Generals/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DDisplay.cpp b/Generals/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DDisplay.cpp index c839a8e988..07d9519107 100644 --- a/Generals/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DDisplay.cpp +++ b/Generals/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DDisplay.cpp @@ -34,6 +34,7 @@ static void drawFramerateBar(void); // SYSTEM INCLUDES //////////////////////////////////////////////////////////// +#include #include #include #include @@ -835,21 +836,16 @@ void W3DDisplay::reset( void ) const UnsignedInt START_CUMU_FRAME = LOGICFRAMES_PER_SECOND / 2; // skip first half-sec -/** Update a moving average of the last 30 fps measurements. Also try to filter out temporary spikes. - This code is designed to be used by the GameLOD sytems to determine the correct dynamic LOD setting. -*/ void W3DDisplay::updateAverageFPS(void) { - const Real MaximumFrameTimeCutoff = 0.5f; //largest frame interval (seconds) we accept before ignoring it as a momentary "spike" - const Int FPS_HISTORY_SIZE = 30; //keep track of the last 30 frames + constexpr const Int FPS_HISTORY_SIZE = 30; static Int64 lastUpdateTime64 = 0; static Int historyOffset = 0; - static Int numSamples = 0; - static double fpsHistory[FPS_HISTORY_SIZE]; + static Real fpsHistory[FPS_HISTORY_SIZE] = {0}; - Int64 freq64 = getPerformanceCounterFrequency(); - Int64 time64 = getPerformanceCounter(); + const Int64 freq64 = getPerformanceCounterFrequency(); + const Int64 time64 = getPerformanceCounter(); #if defined(RTS_DEBUG) if (TheGameLogic->getFrame() == START_CUMU_FRAME) @@ -858,37 +854,21 @@ void W3DDisplay::updateAverageFPS(void) } #endif - Int64 timeDiff = time64 - lastUpdateTime64; + const Int64 timeDiff = time64 - lastUpdateTime64; // convert elapsed time to seconds - double elapsedSeconds = (double)timeDiff/(double)(freq64); - - if (elapsedSeconds <= MaximumFrameTimeCutoff) //make sure it's not a spike - { - // append new sameple to fps history. - if (historyOffset >= FPS_HISTORY_SIZE) - historyOffset = 0; + Real elapsedSeconds = (Real)timeDiff/(Real)freq64; - m_currentFPS = 1.0/elapsedSeconds; - fpsHistory[historyOffset++] = m_currentFPS; - numSamples++; - if (numSamples > FPS_HISTORY_SIZE) - numSamples = FPS_HISTORY_SIZE; - } + // append new sample to fps history. + if (historyOffset >= FPS_HISTORY_SIZE) + historyOffset = 0; - if (numSamples) - { - // determine average frame rate over our past history. - Real average=0; - for (Int i=0,j=historyOffset-1; i #include #include #include @@ -885,21 +886,16 @@ void W3DDisplay::reset( void ) const UnsignedInt START_CUMU_FRAME = LOGICFRAMES_PER_SECOND / 2; // skip first half-sec -/** Update a moving average of the last 30 fps measurements. Also try to filter out temporary spikes. - This code is designed to be used by the GameLOD sytems to determine the correct dynamic LOD setting. -*/ void W3DDisplay::updateAverageFPS(void) { - const Real MaximumFrameTimeCutoff = 0.5f; //largest frame interval (seconds) we accept before ignoring it as a momentary "spike" - const Int FPS_HISTORY_SIZE = 30; //keep track of the last 30 frames + constexpr const Int FPS_HISTORY_SIZE = 30; static Int64 lastUpdateTime64 = 0; static Int historyOffset = 0; - static Int numSamples = 0; - static double fpsHistory[FPS_HISTORY_SIZE]; + static Real fpsHistory[FPS_HISTORY_SIZE] = {0}; - Int64 freq64 = getPerformanceCounterFrequency(); - Int64 time64 = getPerformanceCounter(); + const Int64 freq64 = getPerformanceCounterFrequency(); + const Int64 time64 = getPerformanceCounter(); #if defined(RTS_DEBUG) if (TheGameLogic->getFrame() == START_CUMU_FRAME) @@ -908,37 +904,21 @@ void W3DDisplay::updateAverageFPS(void) } #endif - Int64 timeDiff = time64 - lastUpdateTime64; + const Int64 timeDiff = time64 - lastUpdateTime64; // convert elapsed time to seconds - double elapsedSeconds = (double)timeDiff/(double)(freq64); - - if (elapsedSeconds <= MaximumFrameTimeCutoff) //make sure it's not a spike - { - // append new sameple to fps history. - if (historyOffset >= FPS_HISTORY_SIZE) - historyOffset = 0; + Real elapsedSeconds = (Real)timeDiff/(Real)freq64; - m_currentFPS = 1.0/elapsedSeconds; - fpsHistory[historyOffset++] = m_currentFPS; - numSamples++; - if (numSamples > FPS_HISTORY_SIZE) - numSamples = FPS_HISTORY_SIZE; - } + // append new sample to fps history. + if (historyOffset >= FPS_HISTORY_SIZE) + historyOffset = 0; - if (numSamples) - { - // determine average frame rate over our past history. - Real average=0; - for (Int i=0,j=historyOffset-1; i