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(gameclient): scale the text and the HUD with the screen
Olcay Seygan56ea7ad9274b
diff --git a/CHANGELOG.md b/CHANGELOG.mdindex d5a65a6fd..55562a496 100644--- a/CHANGELOG.md+++ b/CHANGELOG.md@@ -280,6 +280,7 @@ found and fixed — EA's own, not port damage.**## Health bars+- A health bar keeps its size against the unit at any resolution. It was a fixed number of pixels wide and three tall, so the bigger the screen the thinner the thread over a tank.- Health bars are in the owner's colour instead of green to red.- A building's bar sits above its roof rather than inside its art.- Every garrisonable building shows how full it is, whoever holds it.@@ -303,6 +304,8 @@ found and fixed — EA's own, not port damage.**## It fits your monitor+- The writing on screen grows with your monitor now. Every panel is stretched to your resolution and always was, but the text inside it stayed the size it was drawn at in 2003, and what growth there was stopped dead at twice - so on a 2560 wide screen a command bar three times its original size still wore eight point lettering. The keys on the build buttons, the prices and the build times were the worst of it: at 2K they were drawn, and unreadable.+- The strip of everything your base is building follows the screen too, instead of staying a row of postage stamps under a command bar three times its size.- Widescreen resolutions are back in the options menu.- Zoom further out, with the whole map drawn instead of black corners.- The zoom-out ceiling is the same for everyone; no setting buys you a wider view.diff --git a/GeneralsMD/Code/GameEngine/Include/GameClient/Display.h b/GeneralsMD/Code/GameEngine/Include/GameClient/Display.hindex 1a6a0aa31..6ebcb0cb6 100644--- a/GeneralsMD/Code/GameEngine/Include/GameClient/Display.h+++ b/GeneralsMD/Code/GameEngine/Include/GameClient/Display.h@@ -220,6 +220,21 @@ protected:// the singletonextern Display *TheDisplay;+//-------------------------------------------------------------------------------------------------+/** How much bigger this screen is than the 800x600 every window layout and every hand-placed HUD+ * pixel in the game was drawn for. The .wnd rectangles are stretched by exactly this+ * (parseScreenRect), so anything drawn beside them in raw pixels - a production strip cameo, a+ * health bar - has to be multiplied by it too, or it keeps its 2003 size while the screen around+ * it triples. Never below 1: nothing shrinks under 800 wide. */+//-------------------------------------------------------------------------------------------------+inline Real TheUIScale( void )+{+ if( TheDisplay == NULL )+ return 1.0f;+ Real scale = TheDisplay->getWidth() / 800.0f;+ return scale < 1.0f ? 1.0f : scale;+}+extern void StatDebugDisplay( DebugDisplayInterface *dd, void *, FILE *fp = NULL );//Added By Saaddiff --git a/GeneralsMD/Code/GameEngine/Include/GameClient/GlobalLanguage.h b/GeneralsMD/Code/GameEngine/Include/GameClient/GlobalLanguage.hindex 42b07b96b..4d88f4776 100644--- a/GeneralsMD/Code/GameEngine/Include/GameClient/GlobalLanguage.h+++ b/GeneralsMD/Code/GameEngine/Include/GameClient/GlobalLanguage.h@@ -106,6 +106,11 @@ public:Int adjustFontSize(Int theFontSize); // Adjusts font size for resolution. jba.+ /** the whole of the policy behind adjustFontSize, with the screen width and the damping handed+ * in rather than read off the globals - which is the only way to check it without a+ * GlobalData, and a GlobalData cannot be built without a file system and the registry. */+ static Int adjustFontSizeForWidth(Int theFontSize, Int screenWidth, Real damping);+typedef std::list<AsciiString> StringList; // Used for our font file names that we want to loadtypedef StringList::iterator StringListIt;diff --git a/GeneralsMD/Code/GameEngine/Source/GameClient/Drawable.cpp b/GeneralsMD/Code/GameEngine/Source/GameClient/Drawable.cppindex 92e30529e..aaee560af 100644--- a/GeneralsMD/Code/GameEngine/Source/GameClient/Drawable.cpp+++ b/GeneralsMD/Code/GameEngine/Source/GameClient/Drawable.cpp@@ -2805,9 +2805,18 @@ static Bool computeHealthRegion( const Drawable *draw, IRegion2D& region )healthBoxWidth *= widthScale;healthBoxHeight *= heightScale;+ //+ // the width above is world units treated as pixels, and the height below is a flat three of+ // them, so both stayed the size they were in 2003 while the unit they sit over grew with the+ // screen: on a 2560 wide screen a tank was three times its 800x600 size wearing the same+ // hairline bar. Both follow the screen now.+ //+ const Real uiScale = TheUIScale();+ healthBoxWidth *= uiScale;+// do this so health bar doesn't get too skinny or fat after scaling//healthBoxHeight = max(3.0f, healthBoxHeight);- healthBoxHeight = 3.0f;+ healthBoxHeight = 3.0f * uiScale;// figure out the final region for the health boxregion.lo.x = screenCenter.x - healthBoxWidth * 0.45f;diff --git a/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/GameWindowManagerScript.cpp b/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/GameWindowManagerScript.cppindex f1970609d..234ab0802 100644--- a/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/GameWindowManagerScript.cpp+++ b/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/GameWindowManagerScript.cpp@@ -71,6 +71,7 @@#include "GameClient/GadgetSlider.h"#include "GameClient/GameText.h"#include "GameClient/HeaderTemplate.h"+#include "GameClient/GlobalLanguage.h"#ifdef _INTERNAL// for occasional debugging...@@ -622,6 +623,18 @@ static Bool parseFont( char *token, WinInstanceData *instData,c = strtok( NULL, seps ); // valuescanInt( c, fontBold );+ //+ // every point size in a .wnd is the one the layout was drawn at, at its CREATIONRESOLUTION,+ // and parseScreenRect stretches the window itself by the resolution ratio. The font has to+ // follow or the text shrinks inside its own panel as the screen grows: a command button's+ // "Arial 8" is unreadable on a 2560 wide screen, which is where the build hotkey letters and+ // the price and time badges went. Windows that name a HEADERTEMPLATE have always been+ // adjusted this way (HeaderTemplateManager::populateGameFonts); the ones that name only a+ // FONT never were.+ //+ if( TheGlobalLanguageData )+ fontSize = TheGlobalLanguageData->adjustFontSize( fontSize );+if( TheFontLibrary ){GameFont *font;diff --git a/GeneralsMD/Code/GameEngine/Source/GameClient/GlobalLanguage.cpp b/GeneralsMD/Code/GameEngine/Source/GameClient/GlobalLanguage.cppindex 93a8c989a..8858510ac 100644--- a/GeneralsMD/Code/GameEngine/Source/GameClient/GlobalLanguage.cpp+++ b/GeneralsMD/Code/GameEngine/Source/GameClient/GlobalLanguage.cpp@@ -1,4 +1,4 @@-/*+/*** Command & Conquer Generals Zero Hour(tm)** Copyright 2025 Electronic Arts Inc.**@@ -191,10 +191,23 @@ void GlobalLanguage::parseFontFileName( INI *ini, void * instance, void *store,Int GlobalLanguage::adjustFontSize(Int theFontSize){- Real adjustFactor = TheGlobalData->m_xResolution/800.0f;- adjustFactor = 1.0f + (adjustFactor-1.0f) * m_resolutionFontSizeAdjustment;+ return adjustFontSizeForWidth( theFontSize, TheGlobalData->m_xResolution,+ m_resolutionFontSizeAdjustment );+}++Int GlobalLanguage::adjustFontSizeForWidth(Int theFontSize, Int screenWidth, Real damping)+{+ Real adjustFactor = screenWidth/800.0f;+ adjustFactor = 1.0f + (adjustFactor-1.0f) * damping;if (adjustFactor<1.0f) adjustFactor = 1.0f;- if (adjustFactor>2.0f) adjustFactor = 2.0f;+ //+ // the window layouts themselves are stretched by the full resolution ratio, so a font ceiling+ // of 2x meant that from about 1950 pixels wide up the text stopped growing while the panel it+ // sits in kept going - at 2560 a command bar three times the size of its 800x600 original wore+ // 8pt letters. The damping factor already keeps the text below the layout's own scale+ // (0.7 < 1), so the ceiling only has to be high enough not to bite before 4K.+ //+ if (adjustFactor>4.0f) adjustFactor = 4.0f;Int pointSize = REAL_TO_INT_FLOOR(theFontSize*adjustFactor);return pointSize;}diff --git a/GeneralsMD/Code/GameEngine/Source/GameClient/InGameUI.cpp b/GeneralsMD/Code/GameEngine/Source/GameClient/InGameUI.cppindex 6a3f99bb7..ea0942f5e 100644--- a/GeneralsMD/Code/GameEngine/Source/GameClient/InGameUI.cpp+++ b/GeneralsMD/Code/GameEngine/Source/GameClient/InGameUI.cpp@@ -117,6 +117,17 @@ enumPRODUCTION_STRIP_MORE = 34 ///< width kept for the "+N" that closes an overflowing row};+//-------------------------------------------------------------------------------------------------+/** Every number above is an 800x600 one, the resolution the command bar right below the strip was+ * drawn at - and that bar is stretched to the screen while these are not, so on a 2560 wide+ * screen the strip came out a third of the size of the row of buttons it belongs to. Every one+ * of them goes through here. */+//-------------------------------------------------------------------------------------------------+static Int stripPixels( Int nominal )+{+ return REAL_TO_INT_CEIL( nominal * TheUIScale() );+}+//-------------------------------------------------------------------------------------------------/** Pointer to show while a structure rides the cursor. Mouse::BUILD_PLACEMENT and* INVALID_BUILD_PLACEMENT are two names in CursorININames[] that no shipped Mouse.ini ever@@ -6064,17 +6075,21 @@ void InGameUI::drawProductionStripRow( Int row, Int y )const Int cameoW = m_productionStripCameoW;const Int cameoH = m_productionStripCameoH;+ const Int gap = stripPixels( PRODUCTION_STRIP_GAP );+ const Int left = stripPixels( PRODUCTION_STRIP_LEFT );+ const Int more = stripPixels( PRODUCTION_STRIP_MORE );+ const Int plate = stripPixels( 3 );const Int hidden = m_productionStripTotal[ row ] - count;- Int rowWidth = count * cameoW + ( count - 1 ) * PRODUCTION_STRIP_GAP;+ Int rowWidth = count * cameoW + ( count - 1 ) * gap;if( hidden > 0 )- rowWidth += PRODUCTION_STRIP_GAP + PRODUCTION_STRIP_MORE;+ rowWidth += gap + more;// one plate behind the row, so the cameos read over any terrain- TheDisplay->drawFillRect( PRODUCTION_STRIP_LEFT - 3, y - 3, rowWidth + 6, cameoH + 6,+ TheDisplay->drawFillRect( left - plate, y - plate, rowWidth + 2 * plate, cameoH + 2 * plate,GameMakeColor( 0, 0, 0, 130 ) );- Int x = PRODUCTION_STRIP_LEFT;+ Int x = left;for( Int i = 0; i < count; i++ ){ProductionStripSlot *slot = &m_productionStrip[ row ][ i ];@@ -6149,7 +6164,7 @@ void InGameUI::drawProductionStripRow( Int row, Int y )if( cancelHover ){const Int barInset = cameoW / 4;- const Int barHeight = 4;+ const Int barHeight = stripPixels( 4 );TheDisplay->drawFillRect( x, y, cameoW, cameoH,GameMakeColor( 190, 0, 0, 120 ) );@@ -6158,7 +6173,7 @@ void InGameUI::drawProductionStripRow( Int row, Int y )GameMakeColor( 255, 255, 255, 255 ) );}- x += cameoW + PRODUCTION_STRIP_GAP;+ x += cameoW + gap;}//@@ -6182,7 +6197,7 @@ void InGameUI::drawProductionStripRow( Int row, Int y )Int textWidth = 0, textHeight = 0;m_productionStripOverflow->getSize( &textWidth, &textHeight );- m_productionStripOverflow->draw( x + ( PRODUCTION_STRIP_MORE - textWidth ) / 2,+ m_productionStripOverflow->draw( x + ( more - textWidth ) / 2,y + ( cameoH - textHeight ) / 2,GameMakeColor( 235, 235, 235, 255 ),GameMakeColor( 0, 0, 0, 255 ) );@@ -6288,8 +6303,8 @@ void InGameUI::drawProductionStrip( void )// Take the aspect from a real command button and keep the box's area at the nominal size, so// the row stays as long as it was: a wider cameo is a correspondingly shorter one.//- m_productionStripCameoW = PRODUCTION_STRIP_CAMEO;- m_productionStripCameoH = PRODUCTION_STRIP_CAMEO;+ m_productionStripCameoW = stripPixels( PRODUCTION_STRIP_CAMEO );+ m_productionStripCameoH = stripPixels( PRODUCTION_STRIP_CAMEO );static NameKeyType commandButtonKey = TheNameKeyGenerator->nameToKey( "ControlBar.wnd:ButtonCommand01" );GameWindow *commandButton = TheWindowManager->winGetWindowFromId( NULL, commandButtonKey );if( commandButton )@@ -6299,7 +6314,7 @@ void InGameUI::drawProductionStrip( void )if( buttonSize.x > 0 && buttonSize.y > 0 ){const Real aspect = INT_TO_REAL( buttonSize.x ) / INT_TO_REAL( buttonSize.y );- const Real area = INT_TO_REAL( PRODUCTION_STRIP_CAMEO * PRODUCTION_STRIP_CAMEO );+ const Real area = INT_TO_REAL( m_productionStripCameoW * m_productionStripCameoH );m_productionStripCameoH = REAL_TO_INT_CEIL( (Real)sqrt( area / aspect ) );m_productionStripCameoW = REAL_TO_INT_CEIL( m_productionStripCameoH * aspect );}@@ -6311,8 +6326,8 @@ void InGameUI::drawProductionStrip( void )// bar. A row that would run off the top of the screen is dropped rather than drawn over the// tactical view's edge.//- const Int lowerY = barTop - m_productionStripCameoH - PRODUCTION_STRIP_LIFT;- const Int rowStep = m_productionStripCameoH + PRODUCTION_STRIP_GAP;+ const Int lowerY = barTop - m_productionStripCameoH - stripPixels( PRODUCTION_STRIP_LIFT );+ const Int rowStep = m_productionStripCameoH + stripPixels( PRODUCTION_STRIP_GAP );for( Int row = rowsUsed - 1; row >= 0; row-- ){diff --git a/GeneralsMD/Code/Tests/test_gameengine.cpp b/GeneralsMD/Code/Tests/test_gameengine.cppindex 8c360cf3b..950b3c56c 100644--- a/GeneralsMD/Code/Tests/test_gameengine.cpp+++ b/GeneralsMD/Code/Tests/test_gameengine.cpp@@ -71,6 +71,7 @@#include "GameLogic/Module/SupplyTruckAIUpdate.h"#include "GameLogic/Module/SpecialAbilityUpdate.h"#include "GameClient/InGameUI.h"+#include "GameClient/GlobalLanguage.h"#include "GameClient/View.h"#include "GameLogic/IncomingDamage.h"#include "GameLogic/AIPlayer.h"@@ -6290,3 +6291,39 @@ TEST(every_ai_seat_survives_the_options_string_the_host_sends_round)CHECK( !IsAISlotState( SLOT_PLAYER ) );CHECK( !OptionsCharToSlotState( 'Q', NULL ) );}++/* Every .wnd layout is drawn at 800x600 and stretched to the screen by the resolution ratio, but+ the point size written beside it was handed to the font library untouched, and what adjustment+ there was stopped dead at twice the original. So from about 1950 pixels wide up the text+ stopped growing while the panel around it kept going: on a 2560 wide screen the command bar was+ three times its designed size wearing the same 8pt letters, which is where the build hotkeys,+ the prices and the build times went. */+TEST(text_keeps_growing_with_the_screen_instead_of_stopping_at_twice)+{+ const Real damping = 0.7f; // the shipped ResolutionFontAdjustment, and the class default++ // 800x600 is the resolution every layout was drawn at, so nothing may move there - and nothing+ // shrinks below it either+ CHECK_EQ( 8, GlobalLanguage::adjustFontSizeForWidth( 8, 800, damping ) );+ CHECK_EQ( 8, GlobalLanguage::adjustFontSizeForWidth( 8, 640, damping ) );++ // a command button's "Arial 8" used to stop at 16 for ever, 1950 pixels wide and up+ CHECK( GlobalLanguage::adjustFontSizeForWidth( 8, 2560, damping ) > 16 );+ CHECK( GlobalLanguage::adjustFontSizeForWidth( 8, 3840, damping ) >+ GlobalLanguage::adjustFontSizeForWidth( 8, 2560, damping ) );++ Int previous = 0;+ for( Int width = 800; width <= 3840; width += 32 )+ {+ const Int size = GlobalLanguage::adjustFontSizeForWidth( 100, width, damping );++ // it never outruns the stretch applied to the window it sits in, or the text spills out of+ // its own panel - which is what the old ceiling was there to prevent+ CHECK( size <= 100 * width / 800 );++ // and it never goes backwards as the screen grows+ CHECK( size >= previous );+ previous = size;+ }+}+