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.

perf(gameengine): queue clip status only for drawables that show it

Olcay Seygan09223757151a
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 584d6cfcb..5e10c6e4b 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -483,6 +483,7 @@ found and fixed, EA's own, not port damage.**
- The interface spends less time each frame on the fog of war, leaders' aura rings and guard shields, so big late-game battles draw faster.
- Late in a match the picture caught less often. Every ten seconds each computer player looked over its economy, its spending and the enemy army all in one step, 8 to 10ms of work landing on a single picture. Those three now run a fifth of a second apart. With four Hard computer players on Twilight Flame at minutes 24 and 25, pictures slower than 16.7ms went from 29 a minute to 22, and the slowest one in a hundred from 14.7ms to 14.0ms. Two more hitches got smaller in the same match. The map of where units can drive is rebuilt whenever a building goes up or comes down, and that rebuild went from 9.9ms to 7.4ms, with the ones over 8ms halved (90 to 43). A Hard computer steering its Particle Cannon beam now weighs the ground around it in 0.9ms instead of 2.6ms. Neither changes a single move: the match ends on the same checksum.
- Counting a player's units costs less. The computer's scripts and the build menu keep asking how many of some unit or building a player owns, and every answer went through every unit on every one of that player's teams. Each player now keeps its units grouped by type, so an answer looks only at the types it was asked about. Over an hour of eight Hard computer players on Twilight Flame, the step that works out the battle went from 6.15ms to 6.01ms on average and from 13.75ms to 13.25ms at the slowest one in a hundred, and pictures slower than 16.7ms fell from 1,279 to 1,072. The match ends on the same checksum.
+- Every armed unit stopped asking its model to show its loaded missiles. Each one asked on every step of the battle, and only the Tomahawk, the Scud Launcher, the Scorpion and the Scud Storm carry missiles you can see on the model; for the hundreds of others the answer was nothing, and it still had to be queued and read back. Those four keep asking, so their racks still empty and refill as they fire and reload. Over an hour of eight Hard computer players on Twilight Flame the battle step went from 7.15ms to 6.81ms on average, pictures slower than 16.7ms fell from 7,065 to 5,826, and minute 50 ran at 8.6ms a picture instead of 10.7. The match ends on the same checksum.
- The game no longer freezes for seconds when your hard drive is busy. It writes a log of the match as it plays, and once a second the battle itself stopped to push that log to disk. On a drive already busy with something else, Windows can hold such a write back for seconds, and the whole game stood still behind it: a 2v2 against the computer froze for 7.8 seconds on a single step. The log is written on the side now and the battle never waits for it. Three matches played while another program kept the drive busy froze for 6.2 seconds in two of them before; with the change, the slowest step in all three took 48ms.
- The game's log no longer grows without limit. Players sent us logs of half a gigabyte up to 19 GB, enough to fill a disk, and the launcher could not open them to report a crash. Most of it was the network code writing a line for every order and every frame, which only a developer's build writes now: a 100-second two-player network match went from 10.9 MB of log to 175 KB, and a skirmish from 600 KB to 166 KB. Past 64 MB the log keeps its first 8 MB, which say how the game started and on what machine, and its most recent lines, so it stays under 64 MB however long you play.
- The replay no longer stops the battle either. Every order given in a match went to the replay file on disk the moment it was recorded, and on a busy hard drive Windows held each of those writes back. Two long matches against the computer, played while another program kept the drive busy, stalled 115 times for over a tenth of a second, the worst for 0.63 seconds. The replay is written on the side now, about once a second. The same two matches never stalled past 35ms and finished 40% sooner. The file itself has not changed: a replay recorded by the old game and the new one from the same match is identical byte for byte, the clock times aside. A game that crashes still saves its replay up to the crash; one killed from Task Manager can lose its last second.
diff --git a/GeneralsMD/Code/GameEngine/Include/Common/DrawModule.h b/GeneralsMD/Code/GameEngine/Include/Common/DrawModule.h
index 9ae0602f5..a8577613a 100644
--- a/GeneralsMD/Code/GameEngine/Include/Common/DrawModule.h
+++ b/GeneralsMD/Code/GameEngine/Include/Common/DrawModule.h
@@ -199,6 +199,7 @@ public:
virtual Bool getCurrentWorldspaceClientBonePositions(const char* boneName, Matrix3D& transform) const = 0;
virtual Bool getProjectileLaunchOffset(const ModelConditionFlags& condition, WeaponSlotType wslot, Int specificBarrelToUse, Matrix3D* launchPos, WhichTurretType tur, Coord3D* turretRotPos, Coord3D* turretPitchPos) const = 0;
virtual void updateProjectileClipStatus( UnsignedInt shotsRemaining, UnsignedInt maxShots, WeaponSlotType slot ) = 0; ///< This will do the show/hide work if ProjectileBoneFeedbackEnabled is set.
+ virtual Int getProjectileClipFeedbackSlots() const = 0; ///< a bit per WeaponSlotType that updateProjectileClipStatus acts on, fixed by the module data
virtual void updateDrawModuleSupplyStatus( Int maxSupply, Int currentSupply ) = 0; ///< This will do visual feedback on Supplies carried
virtual void notifyDrawModuleDependencyCleared( ) = 0; ///< if you were waiting for something before you drew, it's ready now
diff --git a/GeneralsMD/Code/GameEngine/Include/GameClient/Drawable.h b/GeneralsMD/Code/GameEngine/Include/GameClient/Drawable.h
index 8509f6818..a12dae2fe 100644
--- a/GeneralsMD/Code/GameEngine/Include/GameClient/Drawable.h
+++ b/GeneralsMD/Code/GameEngine/Include/GameClient/Drawable.h
@@ -919,6 +919,7 @@ private:
mutable Bool m_clientWorkQueued; ///< this drawable's ID is in the list flushPendingClientWork walks
Bool m_transformPending; ///< the tick moved it; the draw modules have not been told
Bool m_renderPending; ///< made in a tick: the draw modules have not built their render objects
+ Int m_clipFeedbackSlots; ///< the draw modules' getProjectileClipFeedbackSlots, or'd at creation
struct PendingStep
{
ModelConditionFlags condition; ///< a state an in-tick flush would have applied, when work is empty
diff --git a/GeneralsMD/Code/GameEngine/Source/GameClient/Drawable.cpp b/GeneralsMD/Code/GameEngine/Source/GameClient/Drawable.cpp
index 29e504b99..dd073902a 100644
--- a/GeneralsMD/Code/GameEngine/Source/GameClient/Drawable.cpp
+++ b/GeneralsMD/Code/GameEngine/Source/GameClient/Drawable.cpp
@@ -757,6 +757,14 @@ Drawable::Drawable( const ThingTemplate *thingTemplate, DrawableStatus statusBit
}
*m = NULL;
+ m_clipFeedbackSlots = 0;
+ for (DrawModule** dm = getDrawModulesNonDirty(); *dm; ++dm)
+ {
+ ObjectDrawInterface* di = (*dm)->getObjectDrawInterface();
+ if (di)
+ m_clipFeedbackSlots |= di->getProjectileClipFeedbackSlots();
+ }
+
const ModuleInfo& cuMI = thingTemplate->getClientUpdateModuleInfo();
if (cuMI.getCount())
{
@@ -6443,6 +6451,11 @@ void Drawable::setDrawableHidden( Bool hidden )
//-------------------------------------------------------------------------------------------------
void Drawable::updateDrawableClipStatus( UnsignedInt shotsRemaining, UnsignedInt maxShots, WeaponSlotType slot )
{
+ // every armed object asks every frame; only a model with projectile bones on this slot answers,
+ // so the rest queue nothing. Those that do still ask every frame, which is what shows the bones
+ // again after a model state change rebuilt the render object
+ if ((m_clipFeedbackSlots & (1 << slot)) == 0)
+ return;
doClientWork( [this, shotsRemaining, maxShots, slot]() {
for (DrawModule** dm = getDrawModulesNonDirty(); *dm; ++dm)
{
diff --git a/GeneralsMD/Code/GameEngineDevice/Include/W3DDevice/GameClient/Module/W3DModelDraw.h b/GeneralsMD/Code/GameEngineDevice/Include/W3DDevice/GameClient/Module/W3DModelDraw.h
index 4d133d0f5..d85fa60dd 100644
--- a/GeneralsMD/Code/GameEngineDevice/Include/W3DDevice/GameClient/Module/W3DModelDraw.h
+++ b/GeneralsMD/Code/GameEngineDevice/Include/W3DDevice/GameClient/Module/W3DModelDraw.h
@@ -411,6 +411,7 @@ public:
virtual Bool getCurrentWorldspaceClientBonePositions(const char* boneName, Matrix3D& transform) const;
virtual Bool getProjectileLaunchOffset(const ModelConditionFlags& condition, WeaponSlotType wslot, Int specificBarrelToUse, Matrix3D* launchPos, WhichTurretType tur, Coord3D* turretRotPos, Coord3D* turretPitchPos = NULL) const;
virtual void updateProjectileClipStatus( UnsignedInt shotsRemaining, UnsignedInt maxShots, WeaponSlotType slot ); ///< This will do the show/hide work if ProjectileBoneFeedbackEnabled is set.
+ virtual Int getProjectileClipFeedbackSlots() const;
virtual void updateDrawModuleSupplyStatus( Int maxSupply, Int currentSupply ); ///< This will do visual feedback on Supplies carried
virtual void notifyDrawModuleDependencyCleared( ){}///< if you were waiting for something before you drew, it's ready now
diff --git a/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/Drawable/Draw/W3DModelDraw.cpp b/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/Drawable/Draw/W3DModelDraw.cpp
index 7f48d11ec..543f8d94b 100644
--- a/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/Drawable/Draw/W3DModelDraw.cpp
+++ b/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/Drawable/Draw/W3DModelDraw.cpp
@@ -4701,6 +4701,12 @@ void W3DModelDraw::updateProjectileClipStatus( UnsignedInt shotsRemaining, Unsig
doHideShowProjectileObjects( shotsRemaining, maxShots, slot );// Means effectively, show m of n.
}
+//-------------------------------------------------------------------------------------------------
+Int W3DModelDraw::getProjectileClipFeedbackSlots() const
+{
+ return getW3DModelDrawModuleData()->m_projectileBoneFeedbackEnabledSlots;
+}
+
//-------------------------------------------------------------------------------------------------
void W3DModelDraw::updateDrawModuleSupplyStatus( Int , Int )
{