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
perf(w3ddevice): park spent dynamic lights out of the scene lists
Olcay Seygan5b87d0bac5c2
diff --git a/CHANGELOG.md b/CHANGELOG.mdindex 17e38585b..5a611b2b8 100644--- a/CHANGELOG.md+++ b/CHANGELOG.md@@ -195,6 +195,7 @@ found and fixed — EA's own, not port damage.**- Display options has a vertical sync box. Off, the picture still runs free. On, it waits for the monitor so the frame does not tear. The box takes effect when you Accept.- With vertical sync off, the picture really is free again. Ever since the game started drawing through Direct3D 11, fullscreen and windowed games were still held to the monitor's refresh: 164 frames a second on a 164 Hz screen, and a 60 Hz screen sat at 60 and sank into the fifties in a fight, where the old renderer had given players over 450. The same match now takes 2.3ms a frame, over 400 a second, where it was pinned at 6.1ms. Every picture is the same one it was. Vertical sync on still waits for the monitor.- A slow moment costs you a dropped frame, not a slow game.+- A long match no longer drags every flash it ever lit behind it. The lights a muzzle flash or a blast puts on the ground were kept after they went out, ready for the next one, and the game looked at every one of them, lit or dark, five times a frame. By minute 24 of a four-way Hard match that was close to a quarter of the game's main loop. Spent lights now wait aside until they are needed again, and the game looks only at the ones that are burning.- 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 buildings counting down together, 1,200 frames: 313 letters, where the shared line wrote 6,181. The frame stayed at 8.6ms.diff --git a/GeneralsMD/Code/Data/Scenarios/logicscroll.txt b/GeneralsMD/Code/Data/Scenarios/logicscroll.txtnew file mode 100644index 000000000..b601e6f56--- /dev/null+++ b/GeneralsMD/Code/Data/Scenarios/logicscroll.txt@@ -0,0 +1,42 @@+# Logic thread scroll proof (2026-10-18): a fight just above the local player's command centre,+# inside the view the camera opens on, plus ambulances and Tomahawks driving off toward the other+# start, so a short hard scroll either way crosses health bars and the player's own units. Seat 0 is+# the player (no -observer), so the drag box selects real units and their selection markers show.+# Fed by waves so it is still fighting 40 seconds in. Driven by a script that holds the arrow keys,+# parks the pointer on the screen edges and drags selection boxes while the camera moves.+#+# generals.exe -borderless -xres 1280 -yres 720 -msaa 0 -quickstart -noshellmap -multiInstance+# -nochroma -noFPSLimit -map "Maps\Twilight Flame\Twilight Flame.map" -autoskirmish 2 -takeover+# -side 0 FactionAmerica -side 1 FactionChina -seed 7 -scenario logicscroll -logicthread 1+# -maxframes 3600++30 spawn 0 AmericaTankCrusader 10 start0:0:200 40+30 spawn 0 AmericaVehicleHumvee 6 start0:250:200 34+30 spawn 0 AmericaInfantryRanger 16 start0:-150:250 18+30 spawn 0 AmericaTankPaladin 4 start0:150:150 40+30 spawn 1 ChinaTankBattleMaster 10 start0:-50:520 40+30 spawn 1 ChinaInfantryRedguard 16 start0:-50:650 18+30 spawn 1 ChinaTankGattling 4 start0:200:520 36+30 spawn 0 AmericaVehicleMedic 8 start0:350:50 40+30 spawn 0 AmericaVehicleTomahawk 4 start0:350:-100 40++60 attackmove 1 * start0:0:250+90 attackmove 0 AmericaTankCrusader start0:0:450+90 attackmove 0 AmericaVehicleHumvee start0:0:450+90 attackmove 0 AmericaInfantryRanger start0:0:450+90 attackmove 0 AmericaTankPaladin start0:0:450+90 move 0 AmericaVehicleTomahawk start1+90 move 0 AmericaVehicleMedic start1++240 tally 0 *++900 spawn 1 ChinaTankBattleMaster 8 start0:-50:540 40+900 spawn 1 ChinaInfantryRedguard 12 start0:-50:700 18+930 attackmove 1 * start0:0:250+1200 spawn 0 AmericaTankCrusader 8 start0:0:150 40+1200 spawn 0 AmericaInfantryRanger 12 start0:-150:200 18+1230 attackmove 0 AmericaTankCrusader start0:0:450+1230 attackmove 0 AmericaInfantryRanger start0:0:450+1500 spawn 1 ChinaTankBattleMaster 8 start0:-50:540 40+1500 spawn 1 ChinaInfantryRedguard 12 start0:-50:700 18+1530 attackmove 1 * start0:0:250diff --git a/GeneralsMD/Code/GameEngineDevice/Include/W3DDevice/GameClient/W3DDynamicLight.h b/GeneralsMD/Code/GameEngineDevice/Include/W3DDevice/GameClient/W3DDynamicLight.hindex 51b32c1a7..b1b80e42c 100644--- a/GeneralsMD/Code/GameEngineDevice/Include/W3DDevice/GameClient/W3DDynamicLight.h+++ b/GeneralsMD/Code/GameEngineDevice/Include/W3DDevice/GameClient/W3DDynamicLight.h@@ -79,6 +79,8 @@ public:void setEnabled(Bool enabled) { m_enabled = enabled; m_decayRange = false; m_decayFrameCount = 0; m_decayColor = false; m_increaseFrameCount = 0;};Bool isEnabled(void) {return m_enabled;};+ /// off, and the terrain has taken it back out of its tiles, so nothing reads it until it is handed out again+ Bool isSpent(void) const {return !m_enabled && !m_priorEnable;};/// 0 frameIncreaseTime means it starts out full size/intensity, 0 decay time means it lasts forever.diff --git a/GeneralsMD/Code/GameEngineDevice/Include/W3DDevice/GameClient/W3DScene.h b/GeneralsMD/Code/GameEngineDevice/Include/W3DDevice/GameClient/W3DScene.hindex 41d7e468c..fa7708c99 100644--- a/GeneralsMD/Code/GameEngineDevice/Include/W3DDevice/GameClient/W3DScene.h+++ b/GeneralsMD/Code/GameEngineDevice/Include/W3DDevice/GameClient/W3DScene.h@@ -39,6 +39,7 @@#define __W3DSCENE_H_// SYSTEM INCLUDES ////////////////////////////////////////////////////////////+#include <vector>// USER INCLUDES //////////////////////////////////////////////////////////////#include "WW3D2/scene.h"@@ -112,8 +113,11 @@ protected:void flushOccludedObjectsIntoStencil(RenderInfoClass & rinfo);void updatePlayerColorPasses(void);+ void parkSpentDynamicLights(void);+protected:RefRenderObjListClass m_dynamicLightList;+ std::vector<W3DDynamicLight *> m_spentDynamicLights; ///< out of both lists, one reference each, for getADynamicLight to hand out againBool m_drawTerrainOnly;LightClass *m_globalLight[LightEnvironmentClass::MAX_LIGHTS]; ///< The global directional light (sun, moon) Applies to objects.LightClass *m_scratchLight; ///< a workspace for copying global lights and modifying // MLorenzendiff --git a/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DScene.cpp b/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DScene.cppindex 93db2541d..457a00744 100644--- a/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DScene.cpp+++ b/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DScene.cpp@@ -279,6 +279,9 @@ RTS3DScene::~RTS3DScene(){ REF_PTR_RELEASE(m_occludedMaterialPass[i]);}+ for (size_t spent = 0; spent < m_spentDynamicLights.size(); ++spent)+ m_spentDynamicLights[spent]->Release_Ref();+} // end ~RTS3DScene@@ -1365,10 +1368,12 @@ void RTS3DScene::Customized_Render( RenderInfoClass &rinfo )flagOccludedObjects(&rinfo.Camera);#endif}- Visibility_Checked = false;-+ Visibility_Checked = false;- RefRenderObjListIterator it(&UpdateList);+ if (m_customPassMode == SCENE_PASS_DEFAULT && !ShaderClass::Is_Backface_Culling_Inverted())+ parkSpentDynamicLights();++ RefRenderObjListIterator it(&UpdateList);// allow all objects in the update list to do their "every frame" processingfor (it.First(); !it.Is_Done(); it.Next()) {RenderObjClass * robj = it.Peek_Obj();@@ -1960,13 +1965,44 @@ W3DDynamicLight * RTS3DScene::getADynamicLight(void)return(pLight);}}- pLight = NEW_REF(W3DDynamicLight, ());+ if (m_spentDynamicLights.empty())+ pLight = NEW_REF(W3DDynamicLight, ());+ else+ {+ pLight = m_spentDynamicLights.back();+ m_spentDynamicLights.pop_back();+ }addDynamicLight( pLight );pLight->Release_Ref();pLight->setEnabled(true);return(pLight);}+//=============================================================================+// RTS3DScene::parkSpentDynamicLights+//=============================================================================+/** Takes the lights that are off and out of the terrain's tiles out of both lists. The pool used+ * to keep every light the busiest moment of the match had needed, mostly off, and the five walks+ * over it a frame (the fade, the terrain, the blast lights, the smoke's pulses, a model's own+ * lights under -d3d9) read each one: a late match had thousands to step over, all of it cache+ * misses the logic thread's own walks then had to share the memory with. */+//=============================================================================+void RTS3DScene::parkSpentDynamicLights(void)+{+ RefRenderObjListIterator dynaLightIt(&m_dynamicLightList);+ for (dynaLightIt.First(); !dynaLightIt.Is_Done(); )+ {+ W3DDynamicLight *pLight = (W3DDynamicLight*)dynaLightIt.Peek_Obj();+ dynaLightIt.Next();+ if (!pLight->isSpent())+ continue;+ pLight->Add_Ref();+ m_spentDynamicLights.push_back(pLight);+ UpdateList.Remove(pLight);+ m_dynamicLightList.Remove(pLight);+ }+}+//=============================================================================// RTS3DScene::removeDynamicLight//=============================================================================