Skip to content

Commit 2b88c43

Browse files
committed
bugfix(fps): Decouple camera zoom and rotation time step from render update
1 parent db0a28c commit 2b88c43

File tree

4 files changed

+33
-30
lines changed

4 files changed

+33
-30
lines changed

GeneralsMD/Code/GameEngine/Include/GameClient/View.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -184,8 +184,7 @@ class View : public Snapshot
184184
virtual void setZoom(Real z) { }
185185
virtual Real getHeightAboveGround() { return m_heightAboveGround; }
186186
virtual void setHeightAboveGround(Real z) { m_heightAboveGround = z; }
187-
virtual void zoomIn( void ); ///< Zoom in, closer to the ground, limit to min
188-
virtual void zoomOut( void ); ///< Zoom out, farther away from the ground, limit to max
187+
virtual void zoom( Real height ); ///< Zoom in/out, closer to the ground, limit to min, or farther away from the ground, limit to max
189188
virtual void setZoomToDefault( void ) { } ///< Set zoom to default value
190189
virtual Real getMaxZoom( void ) { return m_maxZoom; } ///< return max zoom value
191190
virtual void setOkToAdjustHeight( Bool val ) { m_okToAdjustHeight = val; } ///< Set this to adjust camera height

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

Lines changed: 23 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1883,26 +1883,30 @@ void InGameUI::update( void )
18831883
layout->runUpdate();
18841884
}
18851885

1886-
//Handle keyboard camera rotations
1887-
if( m_cameraRotatingLeft && !m_cameraRotatingRight )
1886+
if (m_cameraRotatingLeft || m_cameraRotatingRight || m_cameraZoomingIn || m_cameraZoomingOut)
18881887
{
1889-
//Keyboard rotate left
1890-
TheTacticalView->setAngle( TheTacticalView->getAngle() - TheGlobalData->m_keyboardCameraRotateSpeed );
1891-
}
1892-
if( m_cameraRotatingRight && !m_cameraRotatingLeft )
1893-
{
1894-
//Keyboard rotate right
1895-
TheTacticalView->setAngle( TheTacticalView->getAngle() + TheGlobalData->m_keyboardCameraRotateSpeed );
1896-
}
1897-
if( m_cameraZoomingIn && !m_cameraZoomingOut )
1898-
{
1899-
//Keyboard zoom in
1900-
TheTacticalView->zoomIn();
1901-
}
1902-
if( m_cameraZoomingOut && !m_cameraZoomingIn )
1903-
{
1904-
//Keyboard zoom out
1905-
TheTacticalView->zoomOut();
1888+
// TheSuperHackers @tweak Decouples camera rotation and zoom from draw (aka render update)
1889+
const Real logicTimeScaleOverFpsRatio = TheGameEngine->getActualLogicTimeScaleOverFpsRatio();
1890+
const Real rotateAngle = TheGlobalData->m_keyboardCameraRotateSpeed * logicTimeScaleOverFpsRatio;
1891+
const Real zoomHeight = 10.0f * logicTimeScaleOverFpsRatio;
1892+
1893+
if( m_cameraRotatingLeft && !m_cameraRotatingRight )
1894+
{
1895+
TheTacticalView->setAngle( TheTacticalView->getAngle() - rotateAngle );
1896+
}
1897+
else if( m_cameraRotatingRight && !m_cameraRotatingLeft )
1898+
{
1899+
TheTacticalView->setAngle( TheTacticalView->getAngle() + rotateAngle );
1900+
}
1901+
1902+
if( m_cameraZoomingIn && !m_cameraZoomingOut )
1903+
{
1904+
TheTacticalView->zoom( -zoomHeight );
1905+
}
1906+
else if( m_cameraZoomingOut && !m_cameraZoomingIn )
1907+
{
1908+
TheTacticalView->zoom( +zoomHeight );
1909+
}
19061910
}
19071911

19081912

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

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
#include "PreRTS.h" // This must go first in EVERY cpp file int the GameEngine
3030

3131
#include "Common/GameType.h"
32+
#include "Common/GameEngine.h"
3233
#include "Common/MessageStream.h"
3334
#include "Common/Player.h"
3435
#include "Common/PlayerList.h"
@@ -366,15 +367,19 @@ GameMessageDisposition LookAtTranslator::translateGameMessage(const GameMessage
366367

367368
Int spin = msg->getArgument( 1 )->integer;
368369

370+
// TheSuperHackers @tweak Decouples camera zoom from draw (aka render update)
371+
const Real logicTimeScaleOverFpsRatio = TheGameEngine->getActualLogicTimeScaleOverFpsRatio();
372+
const Real zoomHeight = 10.0f * logicTimeScaleOverFpsRatio;
373+
369374
if (spin > 0)
370375
{
371376
for ( ; spin > 0; spin--)
372-
TheTacticalView->zoomIn();
377+
TheTacticalView->zoom( -zoomHeight );
373378
}
374379
else
375380
{
376381
for ( ;spin < 0; spin++ )
377-
TheTacticalView->zoomOut();
382+
TheTacticalView->zoom( +zoomHeight );
378383
}
379384
}
380385

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

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -125,14 +125,9 @@ View *View::prependViewToList( View *list )
125125
return this;
126126
}
127127

128-
void View::zoomIn( void )
128+
void View::zoom( Real height )
129129
{
130-
setHeightAboveGround(getHeightAboveGround() - 10.0f);
131-
}
132-
133-
void View::zoomOut( void )
134-
{
135-
setHeightAboveGround(getHeightAboveGround() + 10.0f);
130+
setHeightAboveGround(getHeightAboveGround() + height);
136131
}
137132

138133
/**

0 commit comments

Comments
 (0)