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.
C++ cmakecnccommand-and-conquercppdirectx11game-enginegame-preservationgeneralsrtssage-enginex64zero-hour
feat(gameclient): replay strip with timeline and speed, observer bar
Olcay Seyganc6e5e851b4b3
diff --git a/CHANGELOG.md b/CHANGELOG.mdindex 1ba06a31f..112625af2 100644--- a/CHANGELOG.md+++ b/CHANGELOG.md@@ -314,6 +314,8 @@ found and fixed — EA's own, not port damage.**## Every replay, not just the last one+- A replay is watched the way an observer watches a match. The empty command grid and portrait plate are gone from the bottom of the screen, and in their place is a timeline with the time reached and the whole length. Click anywhere on it to jump there: forward, the replay races ahead to that moment; back, it starts over and races to it. Beside it are pause and five speeds, from half to eight times the speed the game was played at.+- Replays stopped crashing when an order took every unit out of the selection it was given to. The game throws an empty selection away at once, and with the recorded camera switched on the replay went on to read the one it had just thrown away.- Replay archiving saves each match under its own date-and-time name.- Long lists scroll the whole way, past two thousand rows.- Map, skirmish and replay menus read the catalogue once instead of rebuilding it.diff --git a/GeneralsMD/Code/Data/Window/Html/Spectator.html b/GeneralsMD/Code/Data/Window/Html/Spectator.htmlindex ed0c3e5a0..2edc64b1f 100644--- a/GeneralsMD/Code/Data/Window/Html/Spectator.html+++ b/GeneralsMD/Code/Data/Window/Html/Spectator.html@@ -36,6 +36,12 @@follows nobody and {{follownobody}} is "on" then; each folds up flip:follow. {{follow}}{{followcolor}} are the followed player's name and colour, or the nobody label and no colour{{fog}} "on" while the fog is drawn for the followed player, flipped with data-click="fog"+ In a replay only, the strip standing where a player's command grid is:+ {{replay}} "on", {{replaytime}} {{replaylength}} the time reached and the whole replay's,+ {{replayshare}} how far along it is in percent, {{replaypaused}} "paused",+ {{replayseeking}} "seeking" while a jump runs forward to its frame, and+ {{replay:speed:N}} "on" while it plays at N percent. data-click="replay:seek" on #track jumps+ to the frame under the pointer, replay:pause pauses and resumes, replay:speed:N sets the speedThe stats: networth, cash, income, army, kills, rank, power. A data-click of flip:name flips thename for the rest of the match; pick:group:choice picks and folds up flip:group.@@ -134,6 +140,23 @@.army .cell.head { clear: left; width: 30px; height: 18px; margin-right: 1px; }.army .cell.head img { left: 0; top: 0; width: 30px; height: 18px; }.count { position: absolute; right: 2px; bottom: 0; font-size: 8px; font-weight: bold; color: #ffffff; }++ /* ---- the replay strip, on the screen's bottom edge where the command grid stands in a match ---- */+ #replay { display: none; position: absolute; left: 240px; top: 551px; width: 320px; padding: 3px 0 4px 0; }+ #replay.on { display: block; }+ .clockline { position: relative; height: 11px; margin: 0 6px; }+ .clock { position: absolute; left: 0; top: 0; font-weight: bold; color: #e8d27a; }+ .seeking .clock { color: #b8f08a; }+ .length { position: absolute; right: 0; top: 0; color: #8a949f; }+ #track { height: 7px; margin: 2px 6px 4px 6px; background-color: #030709; border: 1px solid #0c1114; border-bottom-color: #778391; }+ #track:hover { border-color: #aab4bf; }+ #track .fill { height: 7px; background-image: url(PowerBarGreen); }+ .speeds { text-align: center; }+ .speed { display: inline-block; width: 36px; height: 11px; line-height: 11px; margin: 0 1px; text-align: center; font-size: 8px; color: #c9d2d9; }+ .speed.on { color: #b8f08a; }+ .speed .play { display: none; }+ .paused .speed .play { display: inline; }+ .paused .speed .hold { display: none; }</style></head><body>@@ -208,6 +231,19 @@</div></div>+<div id="replay" class="well {{replay}} {{replaypaused}} {{replayseeking}}">+ <div class="clockline"><span class="clock">{{replaytime}}</span><span class="length">{{replaylength}}</span></div>+ <div id="track" data-click="replay:seek"><div class="fill" style="width: {{replayshare}}%"></div></div>+ <div class="speeds">+ <span class="speed plate" data-click="replay:pause"><span class="hold">II</span><span class="play">►</span></span>+ <span class="speed plate {{replay:speed:50}}" data-click="replay:speed:50">½x</span>+ <span class="speed plate {{replay:speed:100}}" data-click="replay:speed:100">1x</span>+ <span class="speed plate {{replay:speed:200}}" data-click="replay:speed:200">2x</span>+ <span class="speed plate {{replay:speed:400}}" data-click="replay:speed:400">4x</span>+ <span class="speed plate {{replay:speed:800}}" data-click="replay:speed:800">8x</span>+ </div>+</div>+</div></body></html>diff --git a/GeneralsMD/Code/GameEngine/Include/Common/Recorder.h b/GeneralsMD/Code/GameEngine/Include/Common/Recorder.hindex 7298439e9..e95f8da5c 100644--- a/GeneralsMD/Code/GameEngine/Include/Common/Recorder.h+++ b/GeneralsMD/Code/GameEngine/Include/Common/Recorder.h@@ -109,6 +109,8 @@ public:Bool playbackFile(AsciiString filename); ///< Starts playback of the specified file.Bool testVersionPlayback(AsciiString filename); ///< Returns if the playback is a valid playback file for this version or not.AsciiString getCurrentReplayFilename( void ); ///< valid during playback only+ UnsignedInt getPlaybackFrameDuration( void ); ///< the replay's length in logic frames, from its header; 0 when not playing back+ Int getPlaybackFramesPerSecond( void ); ///< the logic rate the game was played at, 0 when it was not recordedvoid stopPlayback(); ///< Stops playback. Its fine to call this even if not playing back a file.#if defined _DEBUG || defined _INTERNALBool analyzeReplay( AsciiString filename );@@ -185,6 +187,8 @@ protected:Int m_currentFilePosition;RecorderModeType m_mode;AsciiString m_currentReplayFilename; ///< valid during playback only+ UnsignedInt m_playbackFrameDuration; ///< valid during playback only+ Int m_playbackFramesPerSecond; ///< valid during playback onlyReplayGameInfo m_gameInfo;Bool m_wasDesync;diff --git a/GeneralsMD/Code/GameEngine/Source/Common/Recorder.cpp b/GeneralsMD/Code/GameEngine/Source/Common/Recorder.cppindex c9dfad927..5db91a8a2 100644--- a/GeneralsMD/Code/GameEngine/Source/Common/Recorder.cpp+++ b/GeneralsMD/Code/GameEngine/Source/Common/Recorder.cpp@@ -361,9 +361,11 @@ RecorderClass *TheRecorder = NULL;/*** Constructor*/-RecorderClass::RecorderClass()+RecorderClass::RecorderClass(){m_originalGameMode = GAME_NONE;+ m_playbackFrameDuration = 0;+ m_playbackFramesPerSecond = 0;m_mode = RECORDERMODETYPE_RECORD;m_file = NULL;m_fileName.clear();@@ -400,6 +402,8 @@ RecorderClass::~RecorderClass() {*/void RecorderClass::init() {m_originalGameMode = GAME_NONE;+ m_playbackFrameDuration = 0;+ m_playbackFramesPerSecond = 0;m_mode = RECORDERMODETYPE_NONE;m_file = NULL;m_fileName.clear();@@ -958,6 +962,16 @@ AsciiString RecorderClass::getCurrentReplayFilename( void )return AsciiString::TheEmptyString;}+UnsignedInt RecorderClass::getPlaybackFrameDuration( void )+{+ return m_mode == RECORDERMODETYPE_PLAYBACK ? m_playbackFrameDuration : 0;+}++Int RecorderClass::getPlaybackFramesPerSecond( void )+{+ return m_mode == RECORDERMODETYPE_PLAYBACK ? m_playbackFramesPerSecond : 0;+}+CRCInfo::CRCInfo(){m_localPlayer = ~0;@@ -1097,6 +1111,7 @@ Bool RecorderClass::playbackFile(AsciiString filename){return FALSE;}+ m_playbackFrameDuration = header.frameDuration;#ifdef DEBUG_LOGGINGBool versionStringDiff = header.versionString != TheVersion->getUnicodeVersion();@@ -1167,6 +1182,7 @@ Bool RecorderClass::playbackFile(AsciiString filename)Int maxFPS = 0;fread(&maxFPS, sizeof(maxFPS), 1, m_file);+ m_playbackFramesPerSecond = maxFPS;DEBUG_LOG(("RecorderClass::playbackFile() - original game was mode %d\n", m_originalGameMode));diff --git a/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/ControlBar/ControlBar.cpp b/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/ControlBar/ControlBar.cppindex ffb99b749..533338949 100644--- a/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/ControlBar/ControlBar.cpp+++ b/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/ControlBar/ControlBar.cpp@@ -5845,8 +5845,9 @@ void ControlBar::switchControlBarStage( ControlBarStages stage ){if(stage < CONTROL_BAR_STAGE_DEFAULT || stage >= MAX_CONTROL_BAR_STAGES)return;- if (TheRecorder && TheRecorder->getMode() == RECORDERMODETYPE_PLAYBACK)- return;+ // Retail returned here during playback, so a replay never laid its observer bar out: the command+ // grid and the portrait plate stayed up, empty, over the battlefield. A replay is watched like+ // any observer seat, and the spectator page's replay strip stands where the grid was.switch (stage) {case CONTROL_BAR_STAGE_DEFAULT:setDefaultControlBarConfig();diff --git a/GeneralsMD/Code/GameEngine/Source/GameClient/InGameUI.cpp b/GeneralsMD/Code/GameEngine/Source/GameClient/InGameUI.cppindex cac69849e..118672005 100644--- a/GeneralsMD/Code/GameEngine/Source/GameClient/InGameUI.cpp+++ b/GeneralsMD/Code/GameEngine/Source/GameClient/InGameUI.cpp@@ -2203,6 +2203,84 @@ static void fillSpectatorCameraValues( std::vector< HtmlValues > &follows, HtmlVvalues[ "followcolor" ] = head.at( "color" );}+//-------------------------------------------------------------------------------------------------+// The replay strip, on the spectator's page where a player's command grid stands: the timeline and+// the playback speed. data-click="replay:seek" on #track jumps to the frame under the pointer,+// "replay:pause" pauses and resumes, and "replay:speed:N" plays at N percent of the logic rate the+// game was played at. A seek forward fast-forwards, one+// picture in thirty drawn, until the frame is reached; a seek back has nothing to rewind to and+// starts the replay over, then runs forward the same way.+//-------------------------------------------------------------------------------------------------+static const std::string REPLAY_ACTION = "replay:";+static const std::string REPLAY_SEEK = REPLAY_ACTION + "seek";+static const std::string REPLAY_PAUSE = REPLAY_ACTION + "pause";+static const std::string REPLAY_SPEED = REPLAY_ACTION + "speed:";+static const char *const REPLAY_TRACK = "#track";+static const Int REPLAY_SPEEDS[] = { 50, 100, 200, 400, 800 };++/** The frame a seek runs to, 0 for none. Not a member: a seek back resets the whole interface when+ * it starts the replay over, and the frame has to outlive that. */+static UnsignedInt TheReplaySeekFrame = 0;++/** 1x: the rate the game was played at. A skirmish on its fast setting recorded 60. */+static Int replayNormalFramesPerSecond( void )+{+ const Int recorded = TheRecorder->getPlaybackFramesPerSecond();+ return recorded > 0 ? recorded : LOGICFRAMES_PER_SECOND;+}++/** The replay's length, or the frame reached if the header never had it written. */+static UnsignedInt replayLength( void )+{+ return max( TheRecorder->getPlaybackFrameDuration(), TheGameLogic->getFrame() );+}++static void fillReplayValues( HtmlValues &values )+{+ if( !TheGameLogic->isInReplayGame() )+ return;++ const UnsignedInt frame = TheGameLogic->getFrame();+ const UnsignedInt length = replayLength();+ values[ "replay" ] = "on";+ values[ "replaypaused" ] = TheGameLogic->isGamePaused() ? "paused" : "";+ values[ "replayseeking" ] = TheReplaySeekFrame > 0 ? "seeking" : "";+ values[ "replaytime" ] = spectatorClock( frame );+ values[ "replaylength" ] = spectatorClock( length );+ values[ "replayshare" ] = std::to_string( length > 0 ? frame * PERCENT / length : 0 );++ const Int speed = TheGameEngine->getFramesPerSecondLimit() * PERCENT / replayNormalFramesPerSecond();+ for( Int each = 0; each < (Int)ARRAY_SIZE( REPLAY_SPEEDS ); each++ )+ values[ REPLAY_SPEED + std::to_string( REPLAY_SPEEDS[ each ] ) ] = speed == REPLAY_SPEEDS[ each ] ? "on" : "";+}++static void seekReplay( UnsignedInt target )+{+ TheGameLogic->setGamePaused( FALSE );+ if( target <= TheGameLogic->getFrame() )+ {+ // the way the quit menu restarts one: no score screen between the two+ const AsciiString replayFile = TheRecorder->getCurrentReplayFilename();+ TheGameLogic->clearGameData( FALSE );+ TheGameEngine->setQuitting( FALSE );+ TheRecorder->playbackFile( replayFile );+ }+ TheReplaySeekFrame = target;+}++/** Every client pass, so a seek stops on its frame and not on the next picture drawn. The new game+ * a seek back starts turns fast-forward off while it loads; this turns it on again. */+static void updateReplaySeek( void )+{+ if( TheReplaySeekFrame == 0 || !TheGameLogic->isInGame() || TheGameLogic->isLoadingMap() )+ return;++ const Bool seeking = TheGameLogic->isInReplayGame() && TheGameLogic->getFrame() < TheReplaySeekFrame;+ TheWritableGlobalData->m_TiVOFastMode = seeking;+ if( !seeking )+ TheReplaySeekFrame = 0;+}+//-------------------------------------------------------------------------------------------------/** The key a command bar slot is bound to right now, "Q" for KEY_Q, so the page names the key the* player really has: the WASD camera moves the whole top row along by one. Empty when unbound. */@@ -2289,6 +2367,7 @@ void InGameUI::drawSpectatorPage( void )HtmlValues values = m_spectatorTotals;fillSpectatorCameraValues( m_spectatorLists[ "follows" ], values );+ fillReplayValues( values );for( std::map< std::string, std::string >::const_iterator pick = m_spectatorPicked.begin(); pick != m_spectatorPicked.end(); ++pick ){values[ PICK_ACTION + pick->first ] = pick->second;@@ -2314,7 +2393,18 @@ Bool InGameUI::handleSpectatorPageClick( const ICoord2D *mouse, Bool act )if( !act )return TRUE;- runSpectatorAction( m_spectatorOverlay->click( *mouse ) );+ const std::string action = m_spectatorOverlay->click( *mouse );+ if( action == REPLAY_SEEK && TheGameLogic->isInReplayGame() )+ {+ std::vector< IRegion2D > tracks;+ m_spectatorOverlay->rectsOf( REPLAY_TRACK, tracks );+ const IRegion2D &track = tracks.front();+ const Real share = clamp( 0.0f, (Real)( mouse->x - track.lo.x ) / (Real)( track.hi.x - track.lo.x ), 1.0f );+ seekReplay( REAL_TO_UNSIGNEDINT( share * replayLength() ) );+ return TRUE;+ }++ runSpectatorAction( action );return TRUE;}@@ -2387,6 +2477,11 @@ void InGameUI::runSpectatorAction( const std::string &action )}else if( action == FOG_ACTION )TheObserverCamera.setFog( !TheObserverCamera.isFogOn() );+ // the pause key's own message, so the key and the button are one path+ else if( action == REPLAY_PAUSE && TheGameLogic->isInReplayGame() )+ TheMessageStream->appendMessage( GameMessage::MSG_META_TOGGLE_PAUSE );+ else if( action.compare( 0, REPLAY_SPEED.size(), REPLAY_SPEED ) == 0 && TheGameLogic->isInReplayGame() )+ TheGameEngine->setFramesPerSecondLimit( atoi( action.substr( REPLAY_SPEED.size() ).c_str() ) * replayNormalFramesPerSecond() / PERCENT );}//-------------------------------------------------------------------------------------------------@@ -3406,6 +3501,8 @@ void InGameUI::update( void ){USE_PERF_TIMER(InGameUI_update)+ updateReplaySeek();+/// @todo make sure this code gets called even when the UI is not being drawnif ( m_videoStream && m_videoBuffer ){diff --git a/GeneralsMD/Code/GameEngine/Source/GameClient/MessageStream/CommandXlat.cpp b/GeneralsMD/Code/GameEngine/Source/GameClient/MessageStream/CommandXlat.cppindex 204568434..163366580 100644--- a/GeneralsMD/Code/GameEngine/Source/GameClient/MessageStream/CommandXlat.cpp+++ b/GeneralsMD/Code/GameEngine/Source/GameClient/MessageStream/CommandXlat.cpp@@ -3558,6 +3558,10 @@ GameMessageDisposition CommandTranslator::translateGameMessage(const GameMessage{Bool paused = !TheGameLogic->isGamePaused();TheGameLogic->setGamePaused( paused );+ // a paused replay is still watched: the camera moves and the strip's play button takes+ // its click, and a replay has no orders for the input lock to hold back+ if( paused && TheGameLogic->isInReplayGame() )+ TheInGameUI->setInputEnabled( TRUE );TheInGameUI->message( paused ? "GUI:GamePaused" : "GUI:GameResumed" );}disp = DESTROY_MESSAGE;diff --git a/GeneralsMD/Code/GameEngine/Source/GameLogic/System/GameLogicDispatch.cpp b/GeneralsMD/Code/GameEngine/Source/GameLogic/System/GameLogicDispatch.cppindex 181427898..6056f6bdb 100644--- a/GeneralsMD/Code/GameEngine/Source/GameLogic/System/GameLogicDispatch.cpp+++ b/GeneralsMD/Code/GameEngine/Source/GameLogic/System/GameLogicDispatch.cpp@@ -551,6 +551,12 @@ void GameLogic::logicMessageDispatcher( GameMessage *msg, AIGroup *orderedGroup&& thisPlayer->getOrderQueue()->takeMessage( msg, currentlySelectedGroup, thisPlayer ) )return; // the queue destroyed the group+ // An order can take every unit out of the group - a sale, a unit boarding, a unit dying - and+ // AIGroup::remove destroys a group the moment it is empty. After the switch the pointer is only+ // good while the AI still has a group by this id; the replay's selection copy below read a freed+ // one and crashed playback.+ const UnsignedInt selectedGroupID = currentlySelectedGroup ? currentlySelectedGroup->getID() : 0;+switch( msgType ){//---------------------------------------------------------------------------------------------@@ -2544,6 +2550,9 @@ void GameLogic::logicMessageDispatcher( GameMessage *msg, AIGroup *orderedGroup} // end switch+ if( currentlySelectedGroup && TheAI->findGroup( selectedGroupID ) == NULL )+ currentlySelectedGroup = NULL;+/**/ /// @todo: multiplayer semanticsif (currentlySelectedGroup && orderedGroup == NULL && TheRecorder->getMode() == RECORDERMODETYPE_PLAYBACK && TheGlobalData->m_useCameraInReplay && TheControlBar->getObserverLookAtPlayer() == thisPlayer /*&& !TheRecorder->isMultiplayer()*/){diff --git a/GeneralsMD/Code/Tests/test_gameengine.cpp b/GeneralsMD/Code/Tests/test_gameengine.cppindex 0a03fcf86..4ffe47e4f 100644--- a/GeneralsMD/Code/Tests/test_gameengine.cpp+++ b/GeneralsMD/Code/Tests/test_gameengine.cpp@@ -13902,6 +13902,10 @@ TEST(the_spectator_page_has_its_pieces_and_no_option_clicks)CHECK( page.find( "data-each=\"players\"" ) != std::string::npos );// the players are on the Tab scoreboard, not in a strip across the topCHECK( page.find( "data-each=\"seats\"" ) == std::string::npos );+ // a replay's timeline: InGameUI reads the pointer's place along the element with id track+ CHECK( page.find( "id=\"track\" data-click=\"replay:seek\"" ) != std::string::npos );+ CHECK( page.find( "data-click=\"replay:pause\"" ) != std::string::npos );+ CHECK( page.find( "data-click=\"replay:speed:100\"" ) != std::string::npos );}#include "test_camera_behavior.inc"