Skip to content

tweak(fps): Decouple logic time step from render update #1451

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 7 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions GeneralsMD/Code/GameEngine/Include/GameClient/View.h
Original file line number Diff line number Diff line change
Expand Up @@ -184,8 +184,7 @@ class View : public Snapshot
virtual void setZoom(Real z) { }
virtual Real getHeightAboveGround() { return m_heightAboveGround; }
virtual void setHeightAboveGround(Real z) { m_heightAboveGround = z; }
virtual void zoomIn( void ); ///< Zoom in, closer to the ground, limit to min
virtual void zoomOut( void ); ///< Zoom out, farther away from the ground, limit to max
virtual void zoom( Real height ); ///< Zoom in/out, closer to the ground, limit to min, or farther away from the ground, limit to max
virtual void setZoomToDefault( void ) { } ///< Set zoom to default value
virtual Real getMaxZoom( void ) { return m_maxZoom; } ///< return max zoom value
virtual void setOkToAdjustHeight( Bool val ) { m_okToAdjustHeight = val; } ///< Set this to adjust camera height
Expand Down
42 changes: 23 additions & 19 deletions GeneralsMD/Code/GameEngine/Source/GameClient/InGameUI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1883,26 +1883,30 @@ void InGameUI::update( void )
layout->runUpdate();
}

//Handle keyboard camera rotations
if( m_cameraRotatingLeft && !m_cameraRotatingRight )
if (m_cameraRotatingLeft || m_cameraRotatingRight || m_cameraZoomingIn || m_cameraZoomingOut)
{
//Keyboard rotate left
TheTacticalView->setAngle( TheTacticalView->getAngle() - TheGlobalData->m_keyboardCameraRotateSpeed );
}
if( m_cameraRotatingRight && !m_cameraRotatingLeft )
{
//Keyboard rotate right
TheTacticalView->setAngle( TheTacticalView->getAngle() + TheGlobalData->m_keyboardCameraRotateSpeed );
}
if( m_cameraZoomingIn && !m_cameraZoomingOut )
{
//Keyboard zoom in
TheTacticalView->zoomIn();
}
if( m_cameraZoomingOut && !m_cameraZoomingIn )
{
//Keyboard zoom out
TheTacticalView->zoomOut();
// TheSuperHackers @tweak Decouples camera rotation and zoom from draw (aka render update)
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Simplify to just "from render update". Multiple times.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed

const Real logicTimeScaleOverFpsRatio = TheGameEngine->getActualLogicTimeScaleOverFpsRatio();
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the camera zoom and rotate should be decoupled from the logic time scale as well. It should just always be the same speed unless the user changes some specific option for it.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed

const Real rotateAngle = TheGlobalData->m_keyboardCameraRotateSpeed * logicTimeScaleOverFpsRatio;
const Real zoomHeight = 10.0f * logicTimeScaleOverFpsRatio;

if( m_cameraRotatingLeft && !m_cameraRotatingRight )
{
TheTacticalView->setAngle( TheTacticalView->getAngle() - rotateAngle );
}
else if( m_cameraRotatingRight && !m_cameraRotatingLeft )
{
TheTacticalView->setAngle( TheTacticalView->getAngle() + rotateAngle );
}

if( m_cameraZoomingIn && !m_cameraZoomingOut )
{
TheTacticalView->zoom( -zoomHeight );
}
else if( m_cameraZoomingOut && !m_cameraZoomingIn )
{
TheTacticalView->zoom( +zoomHeight );
}
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
#include "PreRTS.h" // This must go first in EVERY cpp file int the GameEngine

#include "Common/GameType.h"
#include "Common/GameEngine.h"
#include "Common/MessageStream.h"
#include "Common/Player.h"
#include "Common/PlayerList.h"
Expand Down Expand Up @@ -366,15 +367,19 @@ GameMessageDisposition LookAtTranslator::translateGameMessage(const GameMessage

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

// TheSuperHackers @tweak Decouples camera zoom from draw (aka render update)
const Real logicTimeScaleOverFpsRatio = TheGameEngine->getActualLogicTimeScaleOverFpsRatio();
const Real zoomHeight = 10.0f * logicTimeScaleOverFpsRatio;

if (spin > 0)
{
for ( ; spin > 0; spin--)
TheTacticalView->zoomIn();
TheTacticalView->zoom( -zoomHeight );
}
else
{
for ( ;spin < 0; spin++ )
TheTacticalView->zoomOut();
TheTacticalView->zoom( +zoomHeight );
}
}

Expand Down
9 changes: 2 additions & 7 deletions GeneralsMD/Code/GameEngine/Source/GameClient/View.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -125,14 +125,9 @@ View *View::prependViewToList( View *list )
return this;
}

void View::zoomIn( void )
void View::zoom( Real height )
{
setHeightAboveGround(getHeightAboveGround() - 10.0f);
}

void View::zoomOut( void )
{
setHeightAboveGround(getHeightAboveGround() + 10.0f);
setHeightAboveGround(getHeightAboveGround() + height);
}

/**
Expand Down
Loading