Skip to content

Commit 4291c8d

Browse files
committed
New impl
1 parent 389c16e commit 4291c8d

File tree

5 files changed

+13
-4
lines changed

5 files changed

+13
-4
lines changed

GeneralsMD/Code/GameEngine/Include/Common/GameEngine.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ class GameEngine : public SubsystemInterface
8080
virtual Int getFramesPerSecondLimit( void ); ///< Get the max render and engine update fps.
8181
Real getUpdateTime(); ///< Get the last engine update delta time in seconds.
8282
Real getUpdateFps(); ///< Get the last engine update fps.
83+
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.
8384

8485
static Bool isTimeFrozen(); ///< Returns true if a script has frozen time.
8586
static Bool isGameHalted(); ///< Returns true if the game is paused or the network is stalling.

GeneralsMD/Code/GameEngine/Source/Common/GameEngine.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -338,6 +338,14 @@ Real GameEngine::getUpdateFps()
338338
return 1.0f / m_updateTime;
339339
}
340340

341+
//-------------------------------------------------------------------------------------------------
342+
Real GameEngine::getBaseOverUpdateFpsRatio(Real minUpdateFps)
343+
{
344+
// TheSuperHackers @info Update fps is floored to default 5 fps, 200 ms.
345+
// Useful to prevent insane ratios on frame spikes/stalls.
346+
return (Real)BaseFps / std::max(getUpdateFps(), minUpdateFps);
347+
}
348+
341349
//-------------------------------------------------------------------------------------------------
342350
Bool GameEngine::isTimeFrozen()
343351
{

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 = TheGameEngine->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: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -439,7 +439,7 @@ GameMessageDisposition LookAtTranslator::translateGameMessage(const GameMessage
439439
{
440440

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

444444
switch (m_scrollType)
445445
{

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

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

0 commit comments

Comments
 (0)