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
refactor(gamelogic): drop progress getters left over from the white bar
Olcay Seygan8aa781f699bf
diff --git a/CHANGELOG.md b/CHANGELOG.mdindex 7c066d239..95b619e1a 100644--- a/CHANGELOG.md+++ b/CHANGELOG.md@@ -138,7 +138,7 @@ found and fixed — EA's own, not port damage.**- A slow moment costs you a dropped frame, not a slow game.- Explosions no longer catch the picture. The first time each kind of fire, smoke or blast reached the screen, the game stopped for 25 to 60ms to prepare it, and the opening volley of a fight cost 300ms at once. That work is kept on disk and ships with the game, so it happens while the map loads, in about 3ms, and the worst frame of the same battle went from 141ms to 38ms.- The price, build time and power figures on the command bar buttons stopped costing you frames. All the buttons shared one piece of text, so every figure on the bar was lettered from scratch every frame, about 33 of them. Each now keeps its own: a battle that averaged 14ms a frame averages 11.7ms, frames slower than 60 a second went from one in six to one in a hundred, and the old renderer gets about 0.8ms back too. The money readout was lettered again every frame as well, for a number that had not changed; it is lettered when the number moves. Over a whole battle the game now letters 163 pieces of text where it lettered 68,227.-- The seconds over a building that is producing, or over a superweapon charging, were lettered from one shared line. Every building in view with a different time left had that line made again, every frame. Each building keeps its own, and it is made again only when the second changes. Twelve supply zones counting together, 1,200 frames: 313 letters, where the shared line wrote 6,181. The frame stayed at 8.6ms.+- The seconds over a building that is producing, or over a superweapon charging, were lettered from one shared line. Every building in view with a different time left had that line made again, every frame. Each building keeps its own, and it is made again only when the second changes. Twelve buildings counting down together, 1,200 frames: 313 letters, where the shared line wrote 6,181. The frame stayed at 8.6ms.- The new command bar stopped eating half the frame. The clock and the frame counter in the top right corner sat inside the bar's own page, so every tick of them had the whole bar laid out again from scratch, 15ms a time and thirty times a second. The corner box is a page of its own now, the scoreboard counts again twice a second instead of every frame, and a click on the battlefield no longer lays the bar out twice. In the same four-player battle, almost half the frames used to miss 60 a second; now fewer than one in four hundred do, and the game draws more than twice as many frames. When the bar does have to be laid out again, on a hover, a click on it or the scoreboard's twice-a-second count, it takes 2ms where it took 14: the page engine was building an object for every word of the bar's style sheet and every space of its indenting, and reading the same style sheet from scratch each time. All ten pages were laid out both ways and every box and every word came out in the same place, size and colour.- A screen full of fire and smoke is cheaper to draw. Thirty Inferno Cannons shelling twenty Crusaders used to send the graphics card 459 separate batches of see-through effects a frame, mostly the same texture again and again, and the game looked up the same seven card settings from scratch for every one of them. Matching effects go out together now, and settings that have not changed are not looked up again: 177 batches, and the same battle went from 11.6ms a frame to 8.6ms. It is at 6.7ms now, since the game stopped preparing everything it draws a second time for a copy of the picture nobody sees. Nothing on screen changes, the effects are drawn in exactly the order they were.- The same battle with the particle limit turned up costs 7.6ms a frame where it cost 9.1ms, and the old renderer went from 9.3ms to 6.3ms. Both were keeping a count of every kind of draw the game makes, and both did it by writing out and reading back a description of each one, on every draw, for a report no player ever opens. They glance at one draw in sixteen now. The new renderer also stopped re-sending the graphics card settings it had just sent.diff --git a/GeneralsMD/Code/GameEngine/Include/GameLogic/Module/AutoDepositUpdate.h b/GeneralsMD/Code/GameEngine/Include/GameLogic/Module/AutoDepositUpdate.hindex d376c5890..e3d48c8f2 100644--- a/GeneralsMD/Code/GameEngine/Include/GameLogic/Module/AutoDepositUpdate.h+++ b/GeneralsMD/Code/GameEngine/Include/GameLogic/Module/AutoDepositUpdate.h@@ -123,13 +123,6 @@ public:void awardInitialCaptureBonus( Player *player ); // Test and award the initial capture bonusvirtual UpdateSleepTime update( void );- /** How far along the wait for the next payout is, 0..1, or negative when this thing is not- * actually paying anyone (neutral, still under construction, or set to deposit nothing).- * Only so a bar can be drawn over it - the black market and the oil derricks pay on a clock- * the player otherwise cannot see. */- Real getDepositProgress( void ) const;- UnsignedInt getDepositFramesLeft( void ) const;-protected:Int getUpgradedSupplyBoost() const;diff --git a/GeneralsMD/Code/GameEngine/Include/GameLogic/Module/HackInternetAIUpdate.h b/GeneralsMD/Code/GameEngine/Include/GameLogic/Module/HackInternetAIUpdate.hindex 2bc70f9f5..3743b4f33 100644--- a/GeneralsMD/Code/GameEngine/Include/GameLogic/Module/HackInternetAIUpdate.h+++ b/GeneralsMD/Code/GameEngine/Include/GameLogic/Module/HackInternetAIUpdate.h@@ -185,11 +185,6 @@ class HackInternetAIInterfacepublic:virtual Bool isHacking() const = 0;virtual Bool isHackingPackingOrUnpacking() const = 0;-- /** How far along the wait for the next payout is, 0..1, or negative when not hacking.- * HackInternetState keeps the countdown; this is only so a bar can be drawn over it. */- virtual Real getHackProgress() const = 0;- virtual void setHackProgress( Real progress ) = 0;};//-------------------------------------------------------------------------------------------------@@ -227,16 +222,12 @@ public:virtual Bool isHacking() const;virtual Bool isHackingPackingOrUnpacking() const;- virtual Real getHackProgress() const { return m_hackProgress; }- virtual void setHackProgress( Real progress ) { m_hackProgress = progress; }-protected:virtual AIStateMachine* makeStateMachine();AICommandParmsStorage m_pendingCommand;- Bool m_hasPendingCommand;- Real m_hackProgress; ///< 0..1 towards the next payout, negative while not hacking+ Bool m_hasPendingCommand;};#endifdiff --git a/GeneralsMD/Code/GameEngine/Include/GameLogic/Module/SupplyTruckAIUpdate.h b/GeneralsMD/Code/GameEngine/Include/GameLogic/Module/SupplyTruckAIUpdate.hindex 965594c2f..b03131652 100644--- a/GeneralsMD/Code/GameEngine/Include/GameLogic/Module/SupplyTruckAIUpdate.h+++ b/GeneralsMD/Code/GameEngine/Include/GameLogic/Module/SupplyTruckAIUpdate.h@@ -35,20 +35,6 @@#include "Common/StateMachine.h"#include "GameLogic/Module/AIUpdate.h"-//--------------------------------------------------------------------------------------------------/** How far through a dock action (fetching or handing over one box) frame 'now' is, given the- * window the dock state announced. Negative outside the window - which is also what a docker- * that is not docked reads, since nothing but the dock state ever moves the window. Shared by- * SupplyTruckAIUpdate and WorkerAIUpdate, which implement the same interface side by side. */-//--------------------------------------------------------------------------------------------------inline Real dockActionProgress( UnsignedInt now, UnsignedInt start, UnsignedInt end )-{- if( end <= start || now >= end || now < start )- return -1.0f;-- return INT_TO_REAL( now - start ) / INT_TO_REAL( end - start );-}-//-------------------------------------------------------------------------------------------------/** Is there another box in this for the docker after the one just handed over? Asked the moment a* box changes hands, so that a docking that is finished ends there and then: a docker that stays@@ -248,10 +234,9 @@ public:virtual Int getUpgradedSupplyBoost() const = 0;virtual Int getMaxBoxes() const = 0; ///< how many boxes a full load is- /** The dock state announces how long the box it is working on takes; that window is what the- * progress bar over the worker's head fills across. (See AIDockProcessDockState.) */+ /** The dock state announces how long the load it is working on takes; the end of that window+ * times the shortest leg to the next docking. (See AIDockProcessDockState.) */virtual void noteDockActionWindow( UnsignedInt frames ) = 0;- virtual Real getDockActionProgress() const = 0; ///< 0..1 while loading or unloading, negative otherwise};//-------------------------------------------------------------------------------------------------@@ -293,7 +278,6 @@ public:virtual Int getMaxBoxes() const { return getSupplyTruckAIUpdateModuleData()->m_maxBoxesData; }virtual void noteDockActionWindow( UnsignedInt frames );- virtual Real getDockActionProgress() const;virtual UpdateSleepTime update();virtual void aiDoCommand(const AICommandParms* parms);@@ -305,8 +289,7 @@ protected:virtual void privateIdle(CommandSourceType cmdSource); ///< Enter idle state.private:- UnsignedInt m_dockActionStartFrame; ///< when the box currently being moved started- UnsignedInt m_dockActionEndFrame; ///< and when it lands; equal means "not docking"+ UnsignedInt m_dockActionEndFrame; ///< when the load currently being moved landsSupplyTruckStateMachine* m_supplyTruckStateMachine;ObjectID m_preferredDock; ///< Instead of searching, try this one firstInt m_numberBoxes;diff --git a/GeneralsMD/Code/GameEngine/Include/GameLogic/Module/WorkerAIUpdate.h b/GeneralsMD/Code/GameEngine/Include/GameLogic/Module/WorkerAIUpdate.hindex 2160a3fb2..b6748d56f 100644--- a/GeneralsMD/Code/GameEngine/Include/GameLogic/Module/WorkerAIUpdate.h+++ b/GeneralsMD/Code/GameEngine/Include/GameLogic/Module/WorkerAIUpdate.h@@ -218,7 +218,6 @@ public:virtual Int getMaxBoxes() const { return getWorkerAIUpdateModuleData()->m_maxBoxesData; }virtual void noteDockActionWindow( UnsignedInt frames );- virtual Real getDockActionProgress() const;protected:@@ -246,8 +245,7 @@ protected:// Supply Truck dataInt m_numberBoxes;- UnsignedInt m_dockActionStartFrame; ///< when the box currently being moved started- UnsignedInt m_dockActionEndFrame; ///< and when it lands; equal means "not docking"+ UnsignedInt m_dockActionEndFrame; ///< when the load currently being moved landsObjectID m_preferredDock; ///< Instead of searching, try this one firstObjectID m_dockBeforeBuilding; ///< the dock we left to go build, so we can go back (WorkersReturnToSupply)diff --git a/GeneralsMD/Code/GameEngine/Source/GameLogic/AI/AIDock.cpp b/GeneralsMD/Code/GameEngine/Source/GameLogic/AI/AIDock.cppindex 4aafe46bb..7bff4234e 100644--- a/GeneralsMD/Code/GameEngine/Source/GameLogic/AI/AIDock.cpp+++ b/GeneralsMD/Code/GameEngine/Source/GameLogic/AI/AIDock.cpp@@ -607,7 +607,7 @@ void AIDockProcessDockState::setNextDockActionFrame(){UnsignedInt delay = supplyTruck->getActionDelayForDock( getMachineGoalObject() );m_nextDockActionFrame = TheGameLogic->getFrame() + delay;- // ... and let the docker publish that window, so a bar can fill over it while it works+ // ... and let the docker keep where that window ends, which times its next legsupplyTruck->noteDockActionWindow( delay );return;}diff --git a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/AIUpdate/HackInternetAIUpdate.cpp b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/AIUpdate/HackInternetAIUpdate.cppindex c4d98e8c9..d9dc1d331 100644--- a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/AIUpdate/HackInternetAIUpdate.cpp+++ b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/AIUpdate/HackInternetAIUpdate.cpp@@ -63,9 +63,8 @@ AIStateMachine* HackInternetAIUpdate::makeStateMachine()//-------------------------------------------------------------------------------------------------HackInternetAIUpdate::HackInternetAIUpdate( Thing *thing, const ModuleData* moduleData ) : AIUpdateInterface( thing, moduleData ){- m_hasPendingCommand = false;- m_hackProgress = -1.0f;-}+ m_hasPendingCommand = false;+}//-------------------------------------------------------------------------------------------------HackInternetAIUpdate::~HackInternetAIUpdate( void )@@ -474,7 +473,6 @@ StateReturnType HackInternetState::onEnter()MAKE_MODELCONDITION_MASK( MODELCONDITION_FIRING_A ) );m_framesRemaining = ai->getCashUpdateDelay();- ai->setHackProgress( 0.0f );return STATE_CONTINUE;}@@ -495,17 +493,6 @@ StateReturnType HackInternetState::update()return STATE_CONTINUE;}- //- // Where the next payout has got to, so a bar can fill over the hacker's head (see- // Drawable::drawHealthBar). The delay is the only clock the player has on this and it was- // entirely invisible - a hacker either dropped cash or looked idle.- //- {- UnsignedInt full = ai->getCashUpdateDelay();- ai->setHackProgress( full > 0 ? 1.0f - INT_TO_REAL( m_framesRemaining ) / INT_TO_REAL( full )- : -1.0f );- }-if( m_framesRemaining > 0 ){//Decrement frame counter.@@ -619,9 +606,4 @@ void HackInternetState::onExit( StateExitType status ){Object *owner = getMachineOwner();owner->clearModelConditionState( MODELCONDITION_FIRING_A );-- // packed up: no payout is on the way, so take the bar down with the animation- HackInternetAIUpdate *ai = (HackInternetAIUpdate*)owner->getAIUpdateInterface();- if( ai )- ai->setHackProgress( -1.0f );}diff --git a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/AIUpdate/SupplyTruckAIUpdate.cpp b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/AIUpdate/SupplyTruckAIUpdate.cppindex 062c59cb4..4374ea258 100644--- a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/AIUpdate/SupplyTruckAIUpdate.cpp+++ b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/AIUpdate/SupplyTruckAIUpdate.cpp@@ -86,7 +86,6 @@ SupplyTruckAIUpdate::SupplyTruckAIUpdate( Thing *thing, const ModuleData* modulem_numberBoxes = 0;m_forcePending = FALSE;m_forcedBusyPending = FALSE;- m_dockActionStartFrame = 0;m_dockActionEndFrame = 0;m_supplyTruckStateMachine = newInstance(SupplyTruckStateMachine)( getObject() );m_supplyTruckStateMachine->initDefaultState();@@ -250,18 +249,7 @@ UnsignedInt SupplyTruckAIUpdate::getActionDelayForDock( Object *dock )//----------------------------------------------------------------------------------------void SupplyTruckAIUpdate::noteDockActionWindow( UnsignedInt frames ){- m_dockActionStartFrame = TheGameLogic->getFrame();- m_dockActionEndFrame = m_dockActionStartFrame + frames;-}--//-----------------------------------------------------------------------------------------/** How far through fetching or handing over the current box we are, for the bar drawn over the- * worker's head. Negative once the window has run out, which is also what a worker that is not- * docked reads: nothing refreshes the window but the dock state. */-//-----------------------------------------------------------------------------------------Real SupplyTruckAIUpdate::getDockActionProgress() const-{- return dockActionProgress( TheGameLogic->getFrame(), m_dockActionStartFrame, m_dockActionEndFrame );+ m_dockActionEndFrame = TheGameLogic->getFrame() + frames;}//-------------------------------------------------------------------------------------------------@@ -299,11 +287,12 @@ void SupplyTruckAIUpdate::crc( Xfer *xfer )/** Xfer method* Version Info:* 1: Initial version- * 2: The dock action window, which now times the shortest leg between two supply dockings */+ * 2: The dock action window, which now times the shortest leg between two supply dockings+ * 3: Only the window's end; its start fed nothing but a progress bar */// ------------------------------------------------------------------------------------------------void SupplyTruckAIUpdate::xfer( Xfer *xfer ){- XferVersion currentVersion = 2;+ XferVersion currentVersion = 3;XferVersion version = currentVersion;xfer->xferVersion( &version, currentVersion );@@ -314,11 +303,13 @@ void SupplyTruckAIUpdate::xfer( Xfer *xfer )xfer->xferObjectID(&m_preferredDock);xfer->xferInt(&m_numberBoxes);xfer->xferBool(&m_forcePending);- if( version >= 2 )+ if( version == 2 ){- xfer->xferUnsignedInt(&m_dockActionStartFrame);- xfer->xferUnsignedInt(&m_dockActionEndFrame);+ UnsignedInt startFrame = 0;+ xfer->xferUnsignedInt(&startFrame);}+ if( version >= 2 )+ xfer->xferUnsignedInt(&m_dockActionEndFrame);} // end xferdiff --git a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/AIUpdate/WorkerAIUpdate.cpp b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/AIUpdate/WorkerAIUpdate.cppindex bcaeec024..4a28ba5cf 100644--- a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/AIUpdate/WorkerAIUpdate.cpp+++ b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/AIUpdate/WorkerAIUpdate.cpp@@ -120,7 +120,6 @@ WorkerAIUpdate::WorkerAIUpdate( Thing *thing, const ModuleData* moduleData ) :m_dockBeforeBuilding = INVALID_ID;m_forcePending = FALSE;m_forcedBusyPending = FALSE;- m_dockActionStartFrame = 0;m_dockActionEndFrame = 0;m_workerMachine = NULL;@@ -247,18 +246,7 @@ UnsignedInt WorkerAIUpdate::getActionDelayForDock( Object *dock )//----------------------------------------------------------------------------------------void WorkerAIUpdate::noteDockActionWindow( UnsignedInt frames ){- m_dockActionStartFrame = TheGameLogic->getFrame();- m_dockActionEndFrame = m_dockActionStartFrame + frames;-}--//-----------------------------------------------------------------------------------------/** How far through fetching or handing over the current box we are, for the bar drawn over the- * worker's head. Negative once the window has run out, which is also what a worker that is not- * docked reads: nothing refreshes the window but the dock state. */-//-----------------------------------------------------------------------------------------Real WorkerAIUpdate::getDockActionProgress() const-{- return dockActionProgress( TheGameLogic->getFrame(), m_dockActionStartFrame, m_dockActionEndFrame );+ m_dockActionEndFrame = TheGameLogic->getFrame() + frames;}//-------------------------------------------------------------------------------------------------@@ -1527,11 +1515,12 @@ void WorkerAIUpdate::crc( Xfer *xfer )/** Xfer method* Version Info:* 1: Initial version- * 2: The dock action window, which now times the shortest leg between two supply dockings */+ * 2: The dock action window, which now times the shortest leg between two supply dockings+ * 3: Only the window's end; its start fed nothing but a progress bar */// ------------------------------------------------------------------------------------------------void WorkerAIUpdate::xfer( Xfer *xfer ){- XferVersion currentVersion = 2;+ XferVersion currentVersion = 3;XferVersion version = currentVersion;xfer->xferVersion( &version, currentVersion );@@ -1575,11 +1564,13 @@ void WorkerAIUpdate::xfer( Xfer *xfer )xfer->xferObjectID(&m_preferredDock);xfer->xferInt(&m_numberBoxes);xfer->xferBool(&m_forcePending);- if( version >= 2 )+ if( version == 2 ){- xfer->xferUnsignedInt(&m_dockActionStartFrame);- xfer->xferUnsignedInt(&m_dockActionEndFrame);+ UnsignedInt startFrame = 0;+ xfer->xferUnsignedInt(&startFrame);}+ if( version >= 2 )+ xfer->xferUnsignedInt(&m_dockActionEndFrame);//-------------------------- xfer Worker infoxfer->xferSnapshot(m_workerMachine);diff --git a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/AutoDepositUpdate.cpp b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/AutoDepositUpdate.cppindex a9958fc27..503b152dc 100644--- a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/AutoDepositUpdate.cpp+++ b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/AutoDepositUpdate.cpp@@ -144,40 +144,6 @@ void AutoDepositUpdate::awardInitialCaptureBonus( Player *player )m_awardInitialCaptureBonus = FALSE;}-//--------------------------------------------------------------------------------------------------//--------------------------------------------------------------------------------------------------UnsignedInt AutoDepositUpdate::getDepositFramesLeft( void ) const-{- const AutoDepositUpdateModuleData *modData = getAutoDepositUpdateModuleData();- UnsignedInt now = TheGameLogic->getFrame();-- if( modData->m_depositFrame == 0 || modData->m_depositAmount <= 0 )- return 0;- if( getObject()->isNeutralControlled() )- return 0;- if( getObject()->getConstructionPercent() != CONSTRUCTION_COMPLETE )- return 0;- if( m_depositOnFrame <= now )- return 0;-- return m_depositOnFrame - now;-}--//--------------------------------------------------------------------------------------------------//--------------------------------------------------------------------------------------------------Real AutoDepositUpdate::getDepositProgress( void ) const-{- UnsignedInt left = getDepositFramesLeft();- if( left == 0 )- return -1.0f;-- const UnsignedInt full = getAutoDepositUpdateModuleData()->m_depositFrame;- if( left > full )- return -1.0f;-- return 1.0f - INT_TO_REAL( left ) / INT_TO_REAL( full );-}-//-------------------------------------------------------------------------------------------------//-------------------------------------------------------------------------------------------------UpdateSleepTime AutoDepositUpdate::update( void )diff --git a/GeneralsMD/Code/Tests/test_gameengine.cpp b/GeneralsMD/Code/Tests/test_gameengine.cppindex 07c58c0ea..3b9b19f6e 100644--- a/GeneralsMD/Code/Tests/test_gameengine.cpp+++ b/GeneralsMD/Code/Tests/test_gameengine.cpp@@ -10892,29 +10892,6 @@ TEST(a_factorys_queue_is_as_deep_as_its_ini_says_not_as_wide_as_the_button_stripCHECK( data.m_maxQueueEntries > MAX_BUILD_QUEUE_BUTTONS );}-/** The bar over a worker's head while it loads or unloads a box fills across the window the dock- state announced. Outside that window there is no bar at all - which is how a worker walking- between the pile and the refinery reads, since nothing but the dock state ever moves the- window - and the ends of the window are exclusive so a stale one cannot leave a full bar- hanging over an idle worker. */-TEST(a_dock_action_bar_fills_across_its_window_and_shows_nothing_outside_it)-{- // half way through a thirty frame box- CHECK_NEAR( 0.5f, dockActionProgress( 115, 100, 130 ), 0.0001f );- CHECK_NEAR( 0.0f, dockActionProgress( 100, 100, 130 ), 0.0001f );-- // the frame it lands on, and every frame after, is over: no bar- CHECK( dockActionProgress( 130, 100, 130 ) < 0.0f );- CHECK( dockActionProgress( 400, 100, 130 ) < 0.0f );-- // before it starts, and a window that was never set, are both no bar- CHECK( dockActionProgress( 99, 100, 130 ) < 0.0f );- CHECK( dockActionProgress( 0, 0, 0 ) < 0.0f );-- // a zero-length window is not a divide by zero- CHECK( dockActionProgress( 100, 100, 100 ) < 0.0f );-}-/** A docking ends on the frame the last box changes hands, not one action delay later. Both endscan finish it: the docker filling up, or the pile running out. Staying docked past that pointcost a worker a whole extra delay per trip standing at a pile it could take nothing from. */