Skip to content

Commit 3355fd8

Browse files
author
Bart Roossien
committed
[GEN] Backport fast-forward of replays (TheSuperHackers#825)
1 parent 2713267 commit 3355fd8

File tree

9 files changed

+77
-13
lines changed

9 files changed

+77
-13
lines changed

Generals/Code/GameEngine/Include/Common/GlobalData.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -437,6 +437,8 @@ class GlobalData : public SubsystemInterface
437437
Real m_keyboardCameraRotateSpeed; ///< How fast the camera rotates when rotated via keyboard controls.
438438
Int m_playStats; ///< Int whether we want to log play stats or not, if <= 0 then we don't log
439439

440+
Bool m_TiVOFastMode; ///< When true, the client speeds up the framerate... set by HOTKEY!
441+
440442
#if defined(RTS_DEBUG) || defined(RTS_INTERNAL)
441443
Bool m_wireframe;
442444
Bool m_stateMachineDebug;

Generals/Code/GameEngine/Include/Common/MessageStream.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -266,6 +266,8 @@ class GameMessage : public MemoryPoolObject
266266
MSG_META_BEGIN_CAMERA_ZOOM_OUT,
267267
MSG_META_END_CAMERA_ZOOM_OUT,
268268
MSG_META_CAMERA_RESET,
269+
MSG_META_TOGGLE_FAST_FORWARD_REPLAY, ///< Toggle the fast forward feature
270+
269271

270272
// META items that are really for debug/demo/development use only...
271273
// They do not get built into RELEASE builds.

Generals/Code/GameEngine/Source/Common/GameEngine.cpp

Lines changed: 22 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -667,19 +667,29 @@ void GameEngine::execute( void )
667667
::Sleep(1); // give everyone else a tiny time slice.
668668
#endif
669669

670-
// limit the framerate
671-
DWORD now = timeGetTime();
672-
DWORD limit = (1000.0f/m_maxFPS)-1;
673-
while (TheGlobalData->m_useFpsLimit && (now - prevTime) < limit)
674-
{
675-
::Sleep(0);
676-
now = timeGetTime();
677-
}
678-
//Int slept = now - prevTime;
679-
//DEBUG_LOG(("delayed %d\n",slept));
680670

681-
prevTime = now;
682-
}
671+
#if defined(_ALLOW_DEBUG_CHEATS_IN_RELEASE)
672+
if ( ! TheGlobalData->m_TiVOFastMode )
673+
#else //always allow this cheatkey if we're in a replaygame.
674+
if ( ! (TheGlobalData->m_TiVOFastMode && TheGameLogic->isInReplayGame()))
675+
#endif
676+
{
677+
// limit the framerate
678+
DWORD now = timeGetTime();
679+
DWORD limit = (1000.0f/m_maxFPS)-1;
680+
while (TheGlobalData->m_useFpsLimit && (now - prevTime) < limit)
681+
{
682+
::Sleep(0);
683+
now = timeGetTime();
684+
}
685+
//Int slept = now - prevTime;
686+
//DEBUG_LOG(("delayed %d\n",slept));
687+
688+
prevTime = now;
689+
690+
}
691+
692+
}
683693
}
684694

685695
} // perfgather for execute_loop

Generals/Code/GameEngine/Source/Common/GlobalData.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -543,6 +543,8 @@ GlobalData::GlobalData()
543543
m_theOriginal = this;
544544
m_next = NULL;
545545

546+
m_TiVOFastMode = FALSE;
547+
546548
#if defined(RTS_DEBUG) || defined(RTS_INTERNAL)
547549
m_wireframe = 0;
548550
m_stateMachineDebug = FALSE;

Generals/Code/GameEngine/Source/Common/MessageStream.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -364,6 +364,9 @@ AsciiString GameMessage::getCommandTypeAsAsciiString(GameMessage::Type t)
364364
CHECK_IF(MSG_META_BEGIN_CAMERA_ZOOM_OUT)
365365
CHECK_IF(MSG_META_END_CAMERA_ZOOM_OUT)
366366
CHECK_IF(MSG_META_CAMERA_RESET)
367+
368+
CHECK_IF(MSG_META_TOGGLE_FAST_FORWARD_REPLAY)
369+
367370
#if defined(RTS_DEBUG) || defined(RTS_INTERNAL)
368371
CHECK_IF(MSG_META_DEMO_TOGGLE_BEHIND_BUILDINGS)
369372
CHECK_IF(MSG_META_DEMO_TOGGLE_LETTERBOX)

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

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3050,7 +3050,24 @@ GameMessageDisposition CommandTranslator::translateGameMessage(const GameMessage
30503050
case GameMessage::MSG_META_CAMERA_RESET:
30513051
TheInGameUI->resetCamera();
30523052
break;
3053-
3053+
case GameMessage::MSG_META_TOGGLE_FAST_FORWARD_REPLAY:
3054+
{
3055+
if (TheGlobalData)
3056+
{
3057+
#if !defined(_ALLOW_DEBUG_CHEATS_IN_RELEASE)//may be defined in GameCommon.h
3058+
if (TheGameLogic->isInReplayGame())
3059+
#endif
3060+
{
3061+
TheWritableGlobalData->m_TiVOFastMode = 1 - TheGlobalData->m_TiVOFastMode;
3062+
TheInGameUI->message(UnicodeString(L"m_TiVOFastMode: %s"),
3063+
TheGlobalData->m_TiVOFastMode ? L"ON" : L"OFF");
3064+
}
3065+
} // end if
3066+
3067+
disp = DESTROY_MESSAGE;
3068+
break;
3069+
3070+
} // end toggle special power delays
30543071
//-----------------------------------------------------------------------------------------
30553072
case GameMessage::MSG_META_BEGIN_FORCEMOVE:
30563073
DEBUG_ASSERTCRASH(!TheInGameUI->isInForceMoveToMode(), ("forceMoveToMode mismatch"));

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

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,7 @@ static const LookupListRec GameMessageMetaTypeNames[] =
171171
{ "BEGIN_CAMERA_ZOOM_OUT", GameMessage::MSG_META_BEGIN_CAMERA_ZOOM_OUT },
172172
{ "END_CAMERA_ZOOM_OUT", GameMessage::MSG_META_END_CAMERA_ZOOM_OUT },
173173
{ "CAMERA_RESET", GameMessage::MSG_META_CAMERA_RESET },
174+
{ "TOGGLE_FAST_FORWARD_REPLAY", GameMessage::MSG_META_TOGGLE_FAST_FORWARD_REPLAY },
174175

175176
#if defined(RTS_DEBUG) || defined(RTS_INTERNAL)
176177
{ "HELP", GameMessage::MSG_META_HELP },
@@ -448,6 +449,27 @@ GameMessageDisposition MetaEventTranslator::translateGameMessage(const GameMessa
448449
}
449450
else
450451
{
452+
453+
// THIS IS A GREASY HACK... MESSAGE SHOULD BE HANDLED IN A TRANSLATOR, BUT DURING CINEMATICS THE TRANSLATOR IS DISABLED
454+
if (map->m_meta == GameMessage::MSG_META_TOGGLE_FAST_FORWARD_REPLAY)
455+
{
456+
#if defined(_ALLOW_DEBUG_CHEATS_IN_RELEASE)//may be defined in GameCommon.h
457+
if (TheGlobalData)
458+
#else
459+
if (TheGlobalData && TheGameLogic->isInReplayGame())
460+
#endif
461+
{
462+
if (TheWritableGlobalData)
463+
TheWritableGlobalData->m_TiVOFastMode = 1 - TheGlobalData->m_TiVOFastMode;
464+
465+
if (TheInGameUI)
466+
TheInGameUI->message(TheGlobalData->m_TiVOFastMode ? "Fast Forward ON" : "Fast Forward OFF");
467+
}
468+
disp = KEEP_MESSAGE; // cause for goodness sake, this key gets used a lot by non-replay hotkeys
469+
break;
470+
}
471+
472+
451473
/*GameMessage *metaMsg =*/ TheMessageStream->appendMessage(map->m_meta);
452474
//DEBUG_LOG(("Frame %d: MetaEventTranslator::translateGameMessage() normal: %s\n", TheGameLogic->getFrame(), findGameMessageNameByType(map->m_meta)));
453475
}

Generals/Code/GameEngine/Source/GameLogic/System/GameLogic.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1036,6 +1036,7 @@ void GameLogic::startNewGame( Bool saveGame )
10361036
m_rankLevelLimit = 1000; // this is reset every game.
10371037
setDefaults( saveGame );
10381038
TheWritableGlobalData->m_loadScreenRender = TRUE; ///< mark it so only a few select things are rendered during load
1039+
TheWritableGlobalData->m_TiVOFastMode = FALSE; //always disable the TIVO fast-forward mode at the start of a new game.
10391040

10401041
m_showBehindBuildingMarkers = TRUE;
10411042
m_drawIconUI = TRUE;

Generals/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DDisplay.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1761,6 +1761,11 @@ void W3DDisplay::draw( void )
17611761
Int numRenderTargetVertices=Debug_Statistics::Get_DX8_Vertices();
17621762

17631763
// start render block
1764+
#if defined(_ALLOW_DEBUG_CHEATS_IN_RELEASE)
1765+
if ((TheGameLogic->getFrame() % 30 == 1) || (!(!TheGameLogic->isGamePaused() && TheGlobalData->m_TiVOFastMode)))
1766+
#else
1767+
if ((TheGameLogic->getFrame() % 30 == 1) || (!(!TheGameLogic->isGamePaused() && TheGlobalData->m_TiVOFastMode && TheGameLogic->isInReplayGame())))
1768+
#endif
17641769
{
17651770
//USE_PERF_TIMER(BigAssRenderLoop)
17661771
static Bool couldRender = true;

0 commit comments

Comments
 (0)