Skip to content

Zero Hour rebuilt from EA's source: x64, Direct3D 11, VS2022/CMake, ~60 original bugs fixed, an AI that builds a base. Bring your own game.

fix(gameengine): missions keep their script's pace, route and input hold

Olcay Seygan16ac013e890c
diff --git a/CHANGELOG.md b/CHANGELOG.md
index f3e4b7fc6..ca7b3ee62 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -8,6 +8,12 @@ found and fixed, EA's own, not port damage.**
---
+## Missions keep the time their script wrote
+
+- EA's cinematics slow the game on purpose, so the radio lines fit and the camera lands where the next shot starts. This build had stopped honouring that on 18 October. Every mission's cutscenes now run at the pace their script asks for. China's parade had 16 seconds of radio talking over itself, and has 11 now: what is left is EA's own script, which starts the tank crews' lines two thirds of a second apart.
+- Parade tanks drive the road. A mission's waypoint route had been handing out a lane per vehicle, which put China's column up to 82 feet off its line. The furthest any tank strays now is under a foot.
+- China's first mission could hang in its opening shot. Your own idle tanks opened fire on the bomb truck during the cutscene and killed it before it reached the crowd, and the scene waited for a blast that never came. Nothing you own starts a fight on its own until the script hands you control, as in EA's game.
+
## Classic first, Reforged when you ask
- A first start now opens the game EA shipped: its own textures and ground, the hard stencil shadows, the flat 2003 light, no glow, bilinear filtering, the original sound mix, health bars only on what you select or point at. The HD art stays on your disk, unmounted. Every setting this build added to the picture, the sound and the controls starts off, and each one is a box in Options.
diff --git a/GeneralsMD/Code/GameEngine/Include/Common/GameEngine.h b/GeneralsMD/Code/GameEngine/Include/Common/GameEngine.h
index 962612f20..6b4b85ca0 100644
--- a/GeneralsMD/Code/GameEngine/Include/Common/GameEngine.h
+++ b/GeneralsMD/Code/GameEngine/Include/Common/GameEngine.h
@@ -58,6 +58,16 @@ Int GameEngine_logicCatchupMaxFrames( Int logicFps );
replay plays back at the speed its match had. */
Int GameEngine_matchFramesPerSecond( Bool turbo );
+/** The logic frames a second a mission runs at after its script's SET_FPS_LIMIT. EA's cinematics ask
+ for 20 to 28 of retail's 30 and time their voices against that; 0 or 30 and up ask for the game back,
+ which is the match's speed, turbo mode included. */
+Int GameEngine_missionFramesPerSecond( Int askedRetailFps, Int matchFps );
+
+/** How fast a mission's logic runs against the wall clock: 0.77 in a cinematic that asked for 23, 2
+ in turbo mode, 1 everywhere else. Whatever a cinematic times against its script's frames and draws
+ on the wall clock (the scripted camera, W3D's animation clock) multiplies by this. */
+Real GameEngine_missionTimeRate( void );
+
/** R1, smooth motion: the renderer's blend reads how far into the next logic tick the wall clock is
(0 when the last tick was due, 1 a whole tick later or more; always 1 in fast mode or before the first
tick). GameEngine_tickFraction is the arithmetic, on the fine clock's ticks: 1 for a tick length of
diff --git a/GeneralsMD/Code/GameEngine/Include/GameLogic/ScriptEngine.h b/GeneralsMD/Code/GameEngine/Include/GameLogic/ScriptEngine.h
index 7c9d736ef..63a297e2e 100644
--- a/GeneralsMD/Code/GameEngine/Include/GameLogic/ScriptEngine.h
+++ b/GeneralsMD/Code/GameEngine/Include/GameLogic/ScriptEngine.h
@@ -337,6 +337,12 @@ public:
void doFreezeTime( void );
void doUnfreezeTime( void );
+ /** A script has taken the player's input away (a mission's opening cinematic, say): the logic's own
+ copy of what the client's UI hears after the tick. Not saved: a load lands in a playable game, and
+ the worst a load mid-cinematic does is post the retaliation switch early. */
+ Bool isInputHeldByScript( void ) const { return m_inputHeldByScript; }
+ void setInputHeldByScript( Bool held ) { m_inputHeldByScript = held; }
+
/// The following functions are used to update and query the debug window
Bool isTimeFrozenDebug( void ); ///< Ask whether the debug window has requested a pause.
Bool isTimeFast( void ); ///< Ask whether the debug window has requested a fast forward.
@@ -515,6 +521,7 @@ protected:
GameDifficulty m_gameDifficulty;
Bool m_freezeByScript;
+ Bool m_inputHeldByScript;
AllObjectTypes m_allObjectTypeLists;
Bool m_objectsShouldReceiveDifficultyBonus;
Bool m_ChooseVictimAlwaysUsesNormal;
diff --git a/GeneralsMD/Code/GameEngine/Source/Common/GameEngine.cpp b/GeneralsMD/Code/GameEngine/Source/Common/GameEngine.cpp
index 2871f0f1d..f3402532f 100644
--- a/GeneralsMD/Code/GameEngine/Source/Common/GameEngine.cpp
+++ b/GeneralsMD/Code/GameEngine/Source/Common/GameEngine.cpp
@@ -1659,6 +1659,20 @@ Int GameEngine_matchFramesPerSecond( Bool turbo )
return fps > 1000 ? 1000 : fps;
}
+Int GameEngine_missionFramesPerSecond( Int askedRetailFps, Int matchFps )
+{
+ if (askedRetailFps <= 0 || askedRetailFps >= RETAIL_LOGICFRAMES_PER_SECOND)
+ return matchFps;
+ return ConvertRetailFrames( askedRetailFps );
+}
+
+Real GameEngine_missionTimeRate( void )
+{
+ if (TheGameLogic == NULL || !TheGameLogic->isInSinglePlayerGame() || TheGameLogic->isInReplayGame())
+ return 1.0f;
+ return (Real)TheGameEngine->getFramesPerSecondLimit() / (Real)LOGICFRAMES_PER_SECOND;
+}
+
Bool GameEngine_mayStartAnotherCatchupTick( Int ticksSoFar, Int maxTicks, Real elapsedMsInLoop )
{
if (ticksSoFar >= maxTicks)
diff --git a/GeneralsMD/Code/GameEngine/Source/Common/RTS/Player.cpp b/GeneralsMD/Code/GameEngine/Source/Common/RTS/Player.cpp
index 3e41fa4c0..1cf14198d 100644
--- a/GeneralsMD/Code/GameEngine/Source/Common/RTS/Player.cpp
+++ b/GeneralsMD/Code/GameEngine/Source/Common/RTS/Player.cpp
@@ -812,7 +812,12 @@ void Player::update()
{
UnsignedInt now = TheGameLogic->getFrame();
//Only check and post the message once every second so we don't spam the message stream to account for lag.
- if( now % LOGICFRAMES_PER_SECOND == 0 )
+ // Not while a mission's script holds the player's input, as EA's input gate kept it out: retaliation
+ // in an opening cinematic set the player's idle props shooting at what the script needs alive. On
+ // China's first mission they killed the bomb truck short of the area its detonation waits for, so the
+ // cinematic never ended.
+ const Bool inputHeldByMission = TheGameLogic->isInSinglePlayerGame() && TheScriptEngine->isInputHeldByScript();
+ if( now % LOGICFRAMES_PER_SECOND == 0 && !inputHeldByMission )
{
if( TheGlobalData->m_clientRetaliationModeEnabled != isLogicalRetaliationModeEnabled() )
{
diff --git a/GeneralsMD/Code/GameEngine/Source/GameLogic/AI/AIGroup.cpp b/GeneralsMD/Code/GameEngine/Source/GameLogic/AI/AIGroup.cpp
index 4e1b37c5a..0db3176da 100644
--- a/GeneralsMD/Code/GameEngine/Source/GameLogic/AI/AIGroup.cpp
+++ b/GeneralsMD/Code/GameEngine/Source/GameLogic/AI/AIGroup.cpp
@@ -2035,6 +2035,11 @@ static void crowdSeedLanesAlongWaypoint( AIGroup *group, std::list<Object *>& me
{
if (group == NULL || way == NULL)
return;
+ /* A waypoint path in a mission is a route a scripter drew, down a road between what the cinematic
+ puts on either side of it. With a lane each, China's parade fanned out 80 feet across the road and
+ off it, so the team drives its own offsets, as in EA's game. */
+ if (TheGameLogic->isInSinglePlayerGame())
+ return;
Coord2D min, max;
Coord3D center;
group->getMinMaxAndCenter( &min, &max, &center );
diff --git a/GeneralsMD/Code/GameEngine/Source/GameLogic/ScriptEngine/ScriptActions.cpp b/GeneralsMD/Code/GameEngine/Source/GameLogic/ScriptEngine/ScriptActions.cpp
index 8bf0f6da5..96127976c 100644
--- a/GeneralsMD/Code/GameEngine/Source/GameLogic/ScriptEngine/ScriptActions.cpp
+++ b/GeneralsMD/Code/GameEngine/Source/GameLogic/ScriptEngine/ScriptActions.cpp
@@ -3297,6 +3297,7 @@ void ScriptActions::doMergeTeamIntoTeam(const AsciiString& teamSrcName, const As
//-------------------------------------------------------------------------------------------------
void ScriptActions::doDisableInput()
{
+ TheScriptEngine->setInputHeldByScript( TRUE );
#if defined(_DEBUG) || defined(_INTERNAL)
if (!TheGlobalData->m_disableScriptedInputDisabling)
#endif
@@ -3322,6 +3323,7 @@ void ScriptActions::doDisableInput()
//-------------------------------------------------------------------------------------------------
void ScriptActions::doEnableInput()
{
+ TheScriptEngine->setInputHeldByScript( FALSE );
LogicThread::callAfterTick( []{
TheInGameUI->setInputEnabled(true);
TheMouse->setVisibility(true);
@@ -7181,8 +7183,15 @@ void ScriptActions::executeAction( ScriptAction *pAction )
// (LOGIC-THREAD.md hazard 24), which is when the engine next paces anyway
const Int asked = pAction->getParameter(0)->getInt();
LogicThread::callAfterTick( [asked]{
- // A match someone plays, or its replay, keeps the speed it started at: normal, or turbo
- // mode's twice that. Only the shell map's scripts may still pace themselves.
+ // A mission's cinematic slows the game down, and its voices and music are timed to that speed:
+ // a line the script starts 70 frames after the last one needs the 3 seconds 23 frames a second
+ // gives it. Skirmish, a network room or a replay keeps the speed it started at: normal, or
+ // turbo mode's twice that. The shell map's scripts pace themselves as they always did.
+ if (TheGameLogic->isInSinglePlayerGame() && !TheGameLogic->isInReplayGame())
+ {
+ TheGameEngine->setFramesPerSecondLimit( GameEngine_missionFramesPerSecond( asked, GameEngine_matchFramesPerSecond( TheGlobalData->m_turboMode ) ) );
+ return;
+ }
if (!TheGameLogic->isInShellGame())
return;
if (!asked)
diff --git a/GeneralsMD/Code/GameEngine/Source/GameLogic/ScriptEngine/ScriptEngine.cpp b/GeneralsMD/Code/GameEngine/Source/GameLogic/ScriptEngine/ScriptEngine.cpp
index 743467b1f..fc58a11a3 100644
--- a/GeneralsMD/Code/GameEngine/Source/GameLogic/ScriptEngine/ScriptEngine.cpp
+++ b/GeneralsMD/Code/GameEngine/Source/GameLogic/ScriptEngine/ScriptEngine.cpp
@@ -478,6 +478,7 @@ m_currentPlayer(NULL),
m_skirmishHumanPlayer(NULL),
m_fade(FADE_NONE),
m_freezeByScript(FALSE),
+m_inputHeldByScript(FALSE),
m_frameObjectCountChanged(0),
//Added By Sadullah Nader
//Initializations inserted
@@ -5349,6 +5350,7 @@ void ScriptEngine::reset( void )
m_breezeInfo.m_breezeVersion = 0;
m_freezeByScript = FALSE;
+ m_inputHeldByScript = FALSE;
m_objectsShouldReceiveDifficultyBonus = TRUE;
m_ChooseVictimAlwaysUsesNormal = false;
diff --git a/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DDisplay.cpp b/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DDisplay.cpp
index 3d441e2e4..29e0380e9 100644
--- a/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DDisplay.cpp
+++ b/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DDisplay.cpp
@@ -2668,6 +2668,15 @@ AGAIN:
const UnsignedInt MAX_SYNC_STEP_MS = TheW3DFrameLengthInMsec * 4 * LOGICFRAMES_PER_RETAIL_FRAME;
if (deltaMs > MAX_SYNC_STEP_MS)
deltaMs = MAX_SYNC_STEP_MS;
+ // a cinematic that slowed the game slows the animations with it, or soldiers march on the spot
+ const Real missionRate = GameEngine_missionTimeRate();
+ if (missionRate < 1.0f)
+ {
+ static Real slowedMs = 0.0f;
+ slowedMs += deltaMs * missionRate;
+ deltaMs = (UnsignedInt)slowedMs;
+ slowedMs -= deltaMs;
+ }
// a recorded picture is its share of a logic frame however long it took to draw and save, so the
// clock moves that much too, or the footage plays every animation fast. Read off the pictures'
// own clock rather than added up: a 60 Hz frame is not a whole number of milliseconds, and
diff --git a/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DView.cpp b/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DView.cpp
index 5cc2c2568..c41d756a7 100644
--- a/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DView.cpp
+++ b/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DView.cpp
@@ -1773,6 +1773,25 @@ void W3DView::update(void)
if (waypointElapsedMs > 100)
waypointElapsedMs = 100; // a hitch should not teleport the camera down the path
+ /* EA stepped a scripted move once an engine frame, so a move kept time with the script's timers at
+ whatever speed the map ran. On the wall clock it arrives early in a cinematic that slowed the game
+ and late in turbo mode, and the timer that starts the next shot cuts it off. A pan that froze the
+ logic has no other clock, and a recorded picture is a logic frame already. */
+ const Real scriptedRate = pictureClock || (isTimeFrozen() && !isCameraMovementFinished()) ? 1.0f : GameEngine_missionTimeRate();
+ static Real scriptedWaypointMs = 0.0f;
+ scriptedWaypointMs += waypointElapsedMs * scriptedRate;
+ const Int scriptedElapsedMs = (Int)scriptedWaypointMs;
+ scriptedWaypointMs -= scriptedElapsedMs;
+ Bool scriptedStepTime = stepTime;
+ if (scriptedRate != 1.0f)
+ {
+ static Real scriptedStepMs = 0.0f;
+ scriptedStepMs += waypointElapsedMs * scriptedRate;
+ scriptedStepTime = scriptedStepMs >= (Real)CAMERA_STEP_MSEC;
+ if (scriptedStepTime)
+ scriptedStepMs -= (Real)CAMERA_STEP_MSEC;
+ }
+
IRegion2D dirtyTerrain;
if (TheTerrainRenderObject->doesNeedFullUpdate()) {
RefRenderObjListIterator *it = W3DDisplay::m_3DScene->createLightsIterator();
@@ -2014,12 +2033,12 @@ void W3DView::update(void)
// when both are scripted, as before)
if (scriptMovesAllowed && m_doingMoveCameraOnWaypointPath && !m_doingRotateCamera) {
m_previousLookAtPosition = *getPosition();
- moveAlongWaypointPath(waypointElapsedMs);
+ moveAlongWaypointPath(scriptedElapsedMs);
didScriptedMovement = true;
recalcCamera = true;
}
- if (stepTime && scriptMovesAllowed) {
+ if (scriptedStepTime && scriptMovesAllowed) {
// If we aren't frozen for debug, allow the camera to follow scripted movements.
if (updateCameraMovements()) {
didScriptedMovement = true;
diff --git a/GeneralsMD/Code/Tests/test_gameengine.cpp b/GeneralsMD/Code/Tests/test_gameengine.cpp
index 72942bb0f..ecf923821 100644
--- a/GeneralsMD/Code/Tests/test_gameengine.cpp
+++ b/GeneralsMD/Code/Tests/test_gameengine.cpp
@@ -5679,6 +5679,19 @@ TEST(player_game_speed_is_normal_or_turbo)
CHECK_EQ( ClampPlayerGameSpeed( ConvertRetailFrames( 5 ) ), LOGICFRAMES_PER_SECOND );
}
+TEST(mission_cinematic_runs_at_the_speed_its_script_asks_for)
+{
+ /* CHI01's opening asks for 23 of retail's 30 and for 0 when it hands the game back; USA06 hands it
+ back with 30. Below 30 is the cinematic's pace, turbo mode or not; the rest is the match's speed. */
+ const Int normal = LOGICFRAMES_PER_SECOND;
+ const Int turbo = LOGICFRAMES_PER_SECOND * 2;
+ CHECK_EQ( GameEngine_missionFramesPerSecond( 23, normal ), 46 );
+ CHECK_EQ( GameEngine_missionFramesPerSecond( 23, turbo ), 46 );
+ CHECK_EQ( GameEngine_missionFramesPerSecond( 0, normal ), normal );
+ CHECK_EQ( GameEngine_missionFramesPerSecond( 0, turbo ), turbo );
+ CHECK_EQ( GameEngine_missionFramesPerSecond( RETAIL_LOGICFRAMES_PER_SECOND, turbo ), turbo );
+}
+
TEST(match_speed_is_frames_per_second_limit_doubled_by_turbo)
{
/* Every MSG_NEW_GAME a player starts passes this: GameData.ini's normal speed, or -fps for a test,