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
fix(gameengine): keep a countdown string per building
Olcay Seygand9e882558c3e
diff --git a/CHANGELOG.md b/CHANGELOG.mdindex 09c62c1c5..0274184e7 100644--- a/CHANGELOG.md+++ b/CHANGELOG.md@@ -16,6 +16,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 one counting down to a payout, 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 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/GameClient/Drawable.h b/GeneralsMD/Code/GameEngine/Include/GameClient/Drawable.hindex a629ef304..4e7b2c34d 100644--- a/GeneralsMD/Code/GameEngine/Include/GameClient/Drawable.h+++ b/GeneralsMD/Code/GameEngine/Include/GameClient/Drawable.h@@ -733,6 +733,8 @@ private:DisplayString* m_constructDisplayString; ///< string to display construction % completeDisplayString* m_supplyCashDisplayString; ///< string to display the cash left in a supply pileInt m_lastSupplyCashDisplayed; ///< so the string is only rebuilt when the pile shrinks+ DisplayString* m_productionTimeDisplayString; ///< seconds left on what this building is making+ DisplayString* m_chargeTimeDisplayString; ///< seconds left on a public timer charging hereDisplayString* m_captionDisplayString; ///< string to display captionDisplayString* m_groupNumber; ///< string to display the group number of this drawablediff --git a/GeneralsMD/Code/GameEngine/Source/GameClient/Drawable.cpp b/GeneralsMD/Code/GameEngine/Source/GameClient/Drawable.cppindex 260be7941..92cb83339 100644--- a/GeneralsMD/Code/GameEngine/Source/GameClient/Drawable.cpp+++ b/GeneralsMD/Code/GameEngine/Source/GameClient/Drawable.cpp@@ -498,6 +498,8 @@ Drawable::Drawable( const ThingTemplate *thingTemplate, DrawableStatus statusBitm_lastConstructDisplayed = -1.0f;m_supplyCashDisplayString = NULL;m_lastSupplyCashDisplayed = -1;+ m_productionTimeDisplayString = NULL;+ m_chargeTimeDisplayString = NULL;//Added By Sadullah Nader//Fix for the building percent@@ -662,6 +664,14 @@ Drawable::~Drawable()TheDisplayStringManager->freeDisplayString( m_supplyCashDisplayString );m_supplyCashDisplayString = NULL;+ if( m_productionTimeDisplayString )+ TheDisplayStringManager->freeDisplayString( m_productionTimeDisplayString );+ m_productionTimeDisplayString = NULL;++ if( m_chargeTimeDisplayString )+ TheDisplayStringManager->freeDisplayString( m_chargeTimeDisplayString );+ m_chargeTimeDisplayString = NULL;+if ( m_captionDisplayString )TheDisplayStringManager->freeDisplayString( m_captionDisplayString );m_captionDisplayString = NULL;@@ -4189,6 +4199,43 @@ void Drawable::drawCaptureProgress( void )// ------------------------------------------------------------------------------------------------/** Draw health bar information for drawable */// ------------------------------------------------------------------------------------------------+//-------------------------------------------------------------------------------------------------+/** Seconds left, drawn just above a bar. The line belongs to this drawable. One string shared by+ * every building in view was set to a different countdown for each of them, and every change+ * built a new text texture, so a base full of timers paid that cost every frame. */+//-------------------------------------------------------------------------------------------------+static void freeOwnCountdown( DisplayString *&countdown )+{+ if( countdown == NULL )+ return;++ TheDisplayStringManager->freeDisplayString( countdown );+ countdown = NULL;+}++static Int drawOwnCountdown( DisplayString *&countdown, Int seconds, Int x, Int y )+{+ if( countdown == NULL )+ {+ countdown = TheDisplayStringManager->newDisplayString();+ if( countdown == NULL )+ return 0;++ countdown->setFont( TheFontLibrary->getFont( TheInGameUI->getDrawableCaptionFontName(),+ TheGlobalLanguageData->adjustFontSize( TheInGameUI->getDrawableCaptionPointSize() - 2 ),+ FALSE ) );+ }++ UnicodeString text;+ text.format( L"%ds", seconds );+ countdown->setText( text );++ Int textW, textH;+ countdown->getSize( &textW, &textH );+ countdown->draw( x, y - textH, GameMakeColor( 255, 255, 255, 255 ), GameMakeColor( 0, 0, 0, 255 ) );+ return textH;+}+//-------------------------------------------------------------------------------------------------void Drawable::drawHealthBar(const IRegion2D* healthBarRegion){@@ -4429,27 +4476,13 @@ void Drawable::drawHealthBar(const IRegion2D* healthBarRegion): pe->getProductionUpgrade()->calcTimeToBuild( player );Int secondsLeft = ControlBar_secondsFromFrames( totalFrames * (1.0f - pct * 0.01f) );- // one shared string: draw() renders immediately, and the manager lives for the whole app- static DisplayString *prodTimeString = NULL;- if( prodTimeString == NULL )- {- prodTimeString = TheDisplayStringManager->newDisplayString();- prodTimeString->setFont( TheFontLibrary->getFont( TheInGameUI->getDrawableCaptionFontName(),- TheGlobalLanguageData->adjustFontSize( TheInGameUI->getDrawableCaptionPointSize() - 2 ),- FALSE ) );- }- UnicodeString text;- text.format( L"%ds", secondsLeft );- if( prodTimeString->getText().compare( text ) != 0 )- prodTimeString->setText( text );- Int textW, textH;- prodTimeString->getSize( &textW, &textH );- prodTimeString->draw( healthBarRegion->lo.x, prodY - textH,- GameMakeColor( 255, 255, 255, 255 ), GameMakeColor( 0, 0, 0, 255 ) );+ Int textH = drawOwnCountdown( m_productionTimeDisplayString, secondsLeft, healthBarRegion->lo.x, prodY );// whatever comes next goes above the seconds, not through themstackY = prodY - textH - 1;}+ else+ freeOwnCountdown( m_productionTimeDisplayString );//// A superweapon charging, or a building on a timed payout (the supply drop zone), gets the@@ -4588,29 +4621,17 @@ void Drawable::drawHealthBar(const IRegion2D* healthBarRegion)// a clock.//if( chargeFramesLeft > 0 )- {- // one shared string: draw() renders immediately and the manager lives for the app- static DisplayString *chargeTimeString = NULL;- if( chargeTimeString == NULL )- {- chargeTimeString = TheDisplayStringManager->newDisplayString();- chargeTimeString->setFont( TheFontLibrary->getFont( TheInGameUI->getDrawableCaptionFontName(),- TheGlobalLanguageData->adjustFontSize( TheInGameUI->getDrawableCaptionPointSize() - 2 ),- FALSE ) );- }-- UnicodeString text;- text.format( L"%ds", ControlBar_secondsFromFrames( INT_TO_REAL( chargeFramesLeft ) ) );- if( chargeTimeString->getText().compare( text ) != 0 )- chargeTimeString->setText( text );-- Int textW, textH;- chargeTimeString->getSize( &textW, &textH );- chargeTimeString->draw( healthBarRegion->lo.x, chargeY - textH,- GameMakeColor( 255, 255, 255, 255 ), GameMakeColor( 0, 0, 0, 255 ) );- }+ drawOwnCountdown( m_chargeTimeDisplayString,+ ControlBar_secondsFromFrames( INT_TO_REAL( chargeFramesLeft ) ),+ healthBarRegion->lo.x, chargeY );+ else+ freeOwnCountdown( m_chargeTimeDisplayString );}+ else+ freeOwnCountdown( m_chargeTimeDisplayString );}+ else+ freeOwnCountdown( m_chargeTimeDisplayString );} // end if