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): passes that skip the draw fade and park light pulses
Olcay Seygan39a59dc66c95
diff --git a/CHANGELOG.md b/CHANGELOG.mdindex 764c27629..f959c6fcc 100644--- a/CHANGELOG.md+++ b/CHANGELOG.md@@ -457,7 +457,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.+- 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. Only drawing a picture ever put a spent light aside, so a replay's fast forward, which draws one picture a game second, and a network match left minimised, which draws none, still piled them up, and a jump forward in a replay landed on a battlefield lit by the muzzle flashes it had skipped. Every step puts them aside now, drawn or not. The hour-long eight-player match we time the game with, played with no picture, finished in 1,723 seconds instead of 2,072, and its steps slower than 16.7ms went from one in ten to about one in two hundred, on the same checksum.- 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.- First use of Modern water, GPU particle floods, multisampling and the new shadow casters no longer stalls for a compile: those programs ship ready-made.- 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.diff --git a/GeneralsMD/Code/GameEngine/Include/GameClient/Display.h b/GeneralsMD/Code/GameEngine/Include/GameClient/Display.hindex cb6d8d1c2..505798ec3 100644--- a/GeneralsMD/Code/GameEngine/Include/GameClient/Display.h+++ b/GeneralsMD/Code/GameEngine/Include/GameClient/Display.h@@ -127,6 +127,7 @@ public:virtual void createLightPulse( const Coord3D *pos, const RGBColor *color, Real innerRadius,Real attenuationWidth,UnsignedInt increaseFrameTime, UnsignedInt decayFrameTime//, Bool donut = FALSE) = 0;+ virtual void stepDynamicLights( void ) { } ///< a pass that skips the draw: fade the light pulses and park the spent ones, as the draw does/// draw a line on the display in pixel coordinates with the specified colorvirtual void drawLine( Int startX, Int startY, Int endX, Int endY,diff --git a/GeneralsMD/Code/GameEngine/Source/GameClient/GameClient.cpp b/GeneralsMD/Code/GameEngine/Source/GameClient/GameClient.cppindex 1c130ee82..69fd31f21 100644--- a/GeneralsMD/Code/GameEngine/Source/GameClient/GameClient.cpp+++ b/GeneralsMD/Code/GameEngine/Source/GameClient/GameClient.cpp@@ -1014,7 +1014,7 @@ void GameClient::update( void )TheClientDrawMS = (Real)((double)(drawEnd - drawStart) * 1000.0 / (double)freq);#endif}- else if( TheParticleSystemManager )+ else{//// The particle manager is updated from inside the draw, and its update is the only thing@@ -1028,7 +1028,11 @@ void GameClient::update( void )// the same bookkeeping a rendered run does, on a run that has no picture. The same seed// ends with 138 systems instead of 26,811, and the run takes 19.1s against 18.8 and 19.0.//- TheParticleSystemManager->update();+ if( TheParticleSystemManager )+ TheParticleSystemManager->update();+ // The light pulses are the same story: only the render faded and parked them, so a headless+ // match kept every muzzle flash of the match switched on, and each new one walked them all.+ TheDisplay->stepDynamicLights();}}diff --git a/GeneralsMD/Code/GameEngineDevice/Include/W3DDevice/GameClient/W3DDisplay.h b/GeneralsMD/Code/GameEngineDevice/Include/W3DDevice/GameClient/W3DDisplay.hindex 5718c9227..78cc9ed99 100644--- a/GeneralsMD/Code/GameEngineDevice/Include/W3DDevice/GameClient/W3DDisplay.h+++ b/GeneralsMD/Code/GameEngineDevice/Include/W3DDevice/GameClient/W3DDisplay.h@@ -87,6 +87,7 @@ public:virtual void createLightPulse( const Coord3D *pos, const RGBColor *color, Real innerRadius,Real outerRadius,UnsignedInt increaseFrameTime, UnsignedInt decayFrameTime//, Bool donut = FALSE);+ virtual void stepDynamicLights( void );virtual void setTimeOfDay ( TimeOfDay tod );/// draw a line on the display in screen coordinatesdiff --git a/GeneralsMD/Code/GameEngineDevice/Include/W3DDevice/GameClient/W3DScene.h b/GeneralsMD/Code/GameEngineDevice/Include/W3DDevice/GameClient/W3DScene.hindex 92226d365..62effab5b 100644--- a/GeneralsMD/Code/GameEngineDevice/Include/W3DDevice/GameClient/W3DScene.h+++ b/GeneralsMD/Code/GameEngineDevice/Include/W3DDevice/GameClient/W3DScene.h@@ -99,6 +99,7 @@ public:RefRenderObjListClass *getLightList(void) {return &LightList;}; ///< for a stack iterator where a heap one per call costsRefRenderObjListClass *getDynamicLights(void) {return &m_dynamicLightList;};W3DDynamicLight *getADynamicLight(void);+ void stepDynamicLights(void); ///< what Customized_Render does to the lights, for a pass that does not rendervoid setGlobalLight(LightClass *pLight,Int lightIndex=0);LightEnvironmentClass &getDefaultLightEnv(void) {return m_defaultLightEnv;}diff --git a/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DDisplay.cpp b/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DDisplay.cppindex 34e8b4d7b..5b8884129 100644--- a/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DDisplay.cpp+++ b/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DDisplay.cpp@@ -2464,8 +2464,9 @@ void W3DDisplay::draw( void )// the particle update below is the only thing that retires a particle system, so skipping// it with the draw stacked up every system the match made in the meantime, all of them to// start emitting at once on return (TheSuperHackers #2709 reproduce it with Propaganda- // Towers). Same bookkeeping as the lost-device branch below.+ // Towers). Same bookkeeping as the lost-device branch below, and the light pulses' with it.TheParticleSystemManager->update();+ stepDynamicLights();return;}#endif@@ -2812,9 +2813,11 @@ AGAIN:// read the client transform while it is still valid. There is no updateViews here and// nothing to draw the result of, so a frame's worth of stale transforms costs nothing.// Not beside a tick (phase 4's pictures drawn again), which may be making systems.+ // The light pulses fade and park only in the render as well (RTS3DScene::stepDynamicLights).//if (!drawAgain)TheParticleSystemManager->update();+ stepDynamicLights();}Debug_Statistics::End_Statistics(); //record number of polygons rendered in RenderTargetTextures.@@ -3040,6 +3043,12 @@ AGAIN:}}}+ else+ {+ // A replay's fast forward and a seek draw one frame a game second, and only the draw+ // faded and parked the light pulses, so the frame after a seek was lit by its muzzle flashes.+ stepDynamicLights();+ }#ifdef DEBUG_LOGGINGif (tOverlapStart)TheOverlapWindowMS += w3dElapsedMS( tOverlapStart, Clock_Ticks() );@@ -3176,6 +3185,11 @@ void W3DDisplay::createLightPulse( const Coord3D *pos, const RGBColor *color,theDynamicLight->Set_Flag(LightClass::FAR_ATTENUATION,true);}+void W3DDisplay::stepDynamicLights( void )+{+ m_3DScene->stepDynamicLights();+}+void W3DDisplay::toggleLetterBox(void){m_letterBoxEnabled = !m_letterBoxEnabled;diff --git a/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DScene.cpp b/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DScene.cppindex 15372df3d..5830438ff 100644--- a/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DScene.cpp+++ b/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DScene.cpp@@ -2088,6 +2088,26 @@ void RTS3DScene::parkSpentDynamicLights(void)}}+//=============================================================================+// RTS3DScene::stepDynamicLights+//=============================================================================+/** The lights' half of Customized_Render, in its order, for a pass whose draw is skipped: -headless,+ * the undrawn stretch of -jumpToFrame, a minimised window, a lost device, a replay's fast forward and+ * seek (29 passes in 30 skip the draw). Only the render stepped a light's fade and parked it, so+ * those runs kept every light pulse of the match switched on and getADynamicLight walked all of+ * them for each new one: 28 to 37% of the main thread late in a+ * headless match, and a -jumpToFrame's first drawn frame lit by every muzzle flash of the jump. The+ * fade counts logic frames and is gated on the client frame, so a later render steps nothing twice,+ * and a light the terrain still holds is not spent and waits for it. */+//=============================================================================+void RTS3DScene::stepDynamicLights(void)+{+ parkSpentDynamicLights();+ RefRenderObjListIterator dynaLightIt(&m_dynamicLightList);+ for (dynaLightIt.First(); !dynaLightIt.Is_Done(); dynaLightIt.Next())+ dynaLightIt.Peek_Obj()->On_Frame_Update();+}+//=============================================================================// RTS3DScene::removeDynamicLight//=============================================================================