Skip to content

Commit ba85aae

Browse files
authored
refactor(lookat): Simplify pitch, fov, zoom logic in LookAtTranslator (TheSuperHackers#2351)
1 parent daf86de commit ba85aae

2 files changed

Lines changed: 28 additions & 52 deletions

File tree

  • GeneralsMD/Code/GameEngine/Source/GameClient/MessageStream
  • Generals/Code/GameEngine/Source/GameClient/MessageStream

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

Lines changed: 14 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -381,10 +381,8 @@ GameMessageDisposition LookAtTranslator::translateGameMessage(const GameMessage
381381
// rotate the view up/down
382382
if (m_isPitching)
383383
{
384-
const Real FACTOR = 0.01f;
385-
386-
Real angle = FACTOR * (m_currentPos.y - m_anchor.y);
387-
384+
constexpr const Real Scale = 0.01f;
385+
const Real angle = Scale * (m_currentPos.y - m_anchor.y);
388386
TheTacticalView->setPitch( TheTacticalView->getPitch() + angle );
389387
m_anchor = msg->getArgument( 0 )->pixel;
390388
}
@@ -393,10 +391,8 @@ GameMessageDisposition LookAtTranslator::translateGameMessage(const GameMessage
393391
// adjust the field of view
394392
if (m_isChangingFOV)
395393
{
396-
const Real FACTOR = 0.01f;
397-
398-
Real angle = FACTOR * (m_currentPos.y - m_anchor.y);
399-
394+
constexpr const Real Scale = 0.01f;
395+
const Real angle = Scale * (m_currentPos.y - m_anchor.y);
400396
TheTacticalView->setFieldOfView( TheTacticalView->getFieldOfView() + angle );
401397
m_anchor = msg->getArgument( 0 )->pixel;
402398
}
@@ -409,18 +405,9 @@ GameMessageDisposition LookAtTranslator::translateGameMessage(const GameMessage
409405
{
410406
m_lastMouseMoveTimeMsec = timeGetTime();
411407

412-
Int spin = msg->getArgument( 1 )->integer;
413-
414-
if (spin > 0)
415-
{
416-
for ( ; spin > 0; spin--)
417-
TheTacticalView->zoom( -View::ZoomHeightPerSecond );
418-
}
419-
else
420-
{
421-
for ( ;spin < 0; spin++ )
422-
TheTacticalView->zoom( +View::ZoomHeightPerSecond );
423-
}
408+
const Int spin = msg->getArgument( 1 )->integer;
409+
const Real zoom = -spin * View::ZoomHeightPerSecond;
410+
TheTacticalView->zoom(zoom);
424411

425412
break;
426413
}
@@ -440,17 +427,15 @@ GameMessageDisposition LookAtTranslator::translateGameMessage(const GameMessage
440427
{
441428
Coord2D offset = {0, 0};
442429

443-
// If we've been forced to stop scrolling (script action?) then stop
444430
if (m_isScrolling && !TheInGameUI->isScrolling())
445431
{
432+
// If we've been forced to stop scrolling (script action?)
446433
TheInGameUI->setScrollAmount(offset);
447434
stopScrolling();
448435
}
449-
else
450-
// scroll the view
451-
if (m_isScrolling)
436+
else if (m_isScrolling)
452437
{
453-
438+
// Scroll the view
454439
// TheSuperHackers @bugfix Mauller 07/06/2025 The camera scrolling is now decoupled from the render update.
455440
const Real fpsRatio = TheFramePacer->getBaseOverUpdateFpsRatio();
456441

@@ -532,8 +517,11 @@ GameMessageDisposition LookAtTranslator::translateGameMessage(const GameMessage
532517
TheInGameUI->setScrollAmount(offset);
533518
TheTacticalView->scrollBy( &offset );
534519
}
535-
else //not scrolling so reset amount
520+
else
521+
{
522+
//not scrolling so reset amount
536523
TheInGameUI->setScrollAmount(offset);
524+
}
537525

538526
//if (TheGlobalData->m_saveCameraInReplay /*&& TheRecorder->getMode() != RECORDERMODETYPE_PLAYBACK *//**/&& (TheGameLogic->isInSinglePlayerGame() || TheGameLogic->isInSkirmishGame())/**/)
539527
//if (TheGlobalData->m_saveCameraInReplay && (TheGameLogic->isInMultiplayerGame() || TheGameLogic->isInSinglePlayerGame() || TheGameLogic->isInSkirmishGame()))

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

Lines changed: 14 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -380,10 +380,8 @@ GameMessageDisposition LookAtTranslator::translateGameMessage(const GameMessage
380380
// rotate the view up/down
381381
if (m_isPitching)
382382
{
383-
const Real FACTOR = 0.01f;
384-
385-
Real angle = FACTOR * (m_currentPos.y - m_anchor.y);
386-
383+
constexpr const Real Scale = 0.01f;
384+
const Real angle = Scale * (m_currentPos.y - m_anchor.y);
387385
TheTacticalView->setPitch( TheTacticalView->getPitch() + angle );
388386
m_anchor = msg->getArgument( 0 )->pixel;
389387
}
@@ -392,10 +390,8 @@ GameMessageDisposition LookAtTranslator::translateGameMessage(const GameMessage
392390
// adjust the field of view
393391
if (m_isChangingFOV)
394392
{
395-
const Real FACTOR = 0.01f;
396-
397-
Real angle = FACTOR * (m_currentPos.y - m_anchor.y);
398-
393+
constexpr const Real Scale = 0.01f;
394+
const Real angle = Scale * (m_currentPos.y - m_anchor.y);
399395
TheTacticalView->setFieldOfView( TheTacticalView->getFieldOfView() + angle );
400396
m_anchor = msg->getArgument( 0 )->pixel;
401397
}
@@ -408,18 +404,9 @@ GameMessageDisposition LookAtTranslator::translateGameMessage(const GameMessage
408404
{
409405
m_lastMouseMoveTimeMsec = timeGetTime();
410406

411-
Int spin = msg->getArgument( 1 )->integer;
412-
413-
if (spin > 0)
414-
{
415-
for ( ; spin > 0; spin--)
416-
TheTacticalView->zoom( -View::ZoomHeightPerSecond );
417-
}
418-
else
419-
{
420-
for ( ;spin < 0; spin++ )
421-
TheTacticalView->zoom( +View::ZoomHeightPerSecond );
422-
}
407+
const Int spin = msg->getArgument( 1 )->integer;
408+
const Real zoom = -spin * View::ZoomHeightPerSecond;
409+
TheTacticalView->zoom(zoom);
423410

424411
break;
425412
}
@@ -439,17 +426,15 @@ GameMessageDisposition LookAtTranslator::translateGameMessage(const GameMessage
439426
{
440427
Coord2D offset = {0, 0};
441428

442-
// If we've been forced to stop scrolling (script action?) then stop
443429
if (m_isScrolling && !TheInGameUI->isScrolling())
444430
{
431+
// If we've been forced to stop scrolling (script action?)
445432
TheInGameUI->setScrollAmount(offset);
446433
stopScrolling();
447434
}
448-
else
449-
// scroll the view
450-
if (m_isScrolling)
435+
else if (m_isScrolling)
451436
{
452-
437+
// Scroll the view
453438
// TheSuperHackers @bugfix Mauller 07/06/2025 The camera scrolling is now decoupled from the render update.
454439
const Real fpsRatio = TheFramePacer->getBaseOverUpdateFpsRatio();
455440

@@ -531,8 +516,11 @@ GameMessageDisposition LookAtTranslator::translateGameMessage(const GameMessage
531516
TheInGameUI->setScrollAmount(offset);
532517
TheTacticalView->scrollBy( &offset );
533518
}
534-
else //not scrolling so reset amount
519+
else
520+
{
521+
//not scrolling so reset amount
535522
TheInGameUI->setScrollAmount(offset);
523+
}
536524

537525
//if (TheGlobalData->m_saveCameraInReplay /*&& TheRecorder->getMode() != RECORDERMODETYPE_PLAYBACK *//**/&& (TheGameLogic->isInSinglePlayerGame() || TheGameLogic->isInSkirmishGame())/**/)
538526
//if (TheGlobalData->m_saveCameraInReplay && (TheGameLogic->isInMultiplayerGame() || TheGameLogic->isInSinglePlayerGame() || TheGameLogic->isInSkirmishGame()))

0 commit comments

Comments
 (0)