Skip to content

Commit ce035c5

Browse files
committed
New impl
1 parent aff378b commit ce035c5

File tree

5 files changed

+13
-4
lines changed

5 files changed

+13
-4
lines changed

Core/GameEngine/Include/Common/FramePacer.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ class FramePacer
4848

4949
Real getUpdateTime() const; ///< Get the last update delta time in seconds.
5050
Real getUpdateFps() const; ///< Get the last update fps.
51+
Real getBaseOverUpdateFpsRatio(Real minUpdateFps = 5.0f); ///< Get the last engine base over update fps ratio. Used to scale user inputs to a frame rate independent speed.
5152

5253
void setTimeFrozen(Bool frozen); ///< Set time frozen. Allows scripted camera movement.
5354
void setGameHalted(Bool halted); ///< Set game halted. Does not allow scripted camera movement.

Core/GameEngine/Source/Common/FramePacer.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,13 @@ Real FramePacer::getUpdateFps() const
118118
return 1.0f / m_updateTime;
119119
}
120120

121+
Real FramePacer::getBaseOverUpdateFpsRatio(Real minUpdateFps)
122+
{
123+
// Update fps is floored to default 5 fps, 200 ms.
124+
// Useful to prevent insane ratios on frame spikes/stalls.
125+
return (Real)BaseFps / std::max(getUpdateFps(), minUpdateFps);
126+
}
127+
121128
void FramePacer::setTimeFrozen(Bool frozen)
122129
{
123130
m_isTimeFrozen = frozen;

GeneralsMD/Code/GameEngine/Source/GameClient/InGameUI.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1945,7 +1945,7 @@ void InGameUI::update( void )
19451945
if (m_cameraRotatingLeft || m_cameraRotatingRight || m_cameraZoomingIn || m_cameraZoomingOut)
19461946
{
19471947
// TheSuperHackers @tweak The camera rotation and zoom are now decoupled from the render update.
1948-
const Real fpsRatio = (Real)BaseFps / TheGameEngine->getUpdateFps();
1948+
const Real fpsRatio = TheFramePacer->getBaseOverUpdateFpsRatio();
19491949
const Real rotateAngle = TheGlobalData->m_keyboardCameraRotateSpeed * fpsRatio;
19501950
const Real zoomHeight = (Real)View::ZoomHeightPerSecond * fpsRatio;
19511951

GeneralsMD/Code/GameEngine/Source/GameClient/MessageStream/LookAtXlat.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828

2929
#include "PreRTS.h" // This must go first in EVERY cpp file int the GameEngine
3030

31+
#include "Common/FramePacer.h"
3132
#include "Common/GameType.h"
3233
#include "Common/GameEngine.h"
3334
#include "Common/MessageStream.h"
@@ -439,7 +440,7 @@ GameMessageDisposition LookAtTranslator::translateGameMessage(const GameMessage
439440
{
440441

441442
// TheSuperHackers @bugfix Mauller 07/06/2025 The camera scrolling is now decoupled from the render update.
442-
const Real fpsRatio = (Real)BaseFps / TheGameEngine->getUpdateFps();
443+
const Real fpsRatio = TheFramePacer->getBaseOverUpdateFpsRatio();
443444

444445
switch (m_scrollType)
445446
{

GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DView.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1356,7 +1356,7 @@ void W3DView::update(void)
13561356
// if scrolling, only adjust if we're too close or too far
13571357
if (m_scrollAmount.length() < m_scrollAmountCutoff || (m_currentHeightAboveGround < m_minHeightAboveGround) || (TheGlobalData->m_enforceMaxCameraHeight && m_currentHeightAboveGround > m_maxHeightAboveGround))
13581358
{
1359-
const Real fpsRatio = (Real)BaseFps / TheGameEngine->getUpdateFps();
1359+
const Real fpsRatio = TheFramePacer->getBaseOverUpdateFpsRatio();
13601360
const Real zoomAdj = (desiredZoom - m_zoom) * TheGlobalData->m_cameraAdjustSpeed * fpsRatio;
13611361
if (fabs(zoomAdj) >= 0.0001f) // only do positive
13621362
{
@@ -1368,7 +1368,7 @@ void W3DView::update(void)
13681368
else if (!didScriptedMovement)
13691369
{
13701370
// we're not scrolling; settle toward desired height above ground
1371-
const Real fpsRatio = (Real)BaseFps / TheGameEngine->getUpdateFps();
1371+
const Real fpsRatio = TheFramePacer->getBaseOverUpdateFpsRatio();
13721372
const Real zoomAdj = (m_zoom - desiredZoom) * TheGlobalData->m_cameraAdjustSpeed * fpsRatio;
13731373
if (fabs(zoomAdj) >= 0.0001f)
13741374
{

0 commit comments

Comments
 (0)