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
feat(gameclient): hud scales with the screen's height
Olcay Seygan557b0508f151
diff --git a/GeneralsMD/Code/GameEngine/Include/GameClient/ControlBar.h b/GeneralsMD/Code/GameEngine/Include/GameClient/ControlBar.hindex 32c2a617e..169a02fa0 100644--- a/GeneralsMD/Code/GameEngine/Include/GameClient/ControlBar.h+++ b/GeneralsMD/Code/GameEngine/Include/GameClient/ControlBar.h@@ -1613,16 +1613,24 @@ extern Bool ControlBarPanelDesignToScreen( Int panel, const IRegion2D *design,extern Real ControlBarUniformScale( void );extern Real ControlBarUniformScaleFor( Int displayWidth, Int displayHeight ); ///< ...for a screen you name-/** The scale the bottom HUD's page and everything laid out on it are drawn at: the uniform scale cut- * to CONTROL_BAR_HUD_PERCENT of itself, the owner's "too big" of 2026-09-28, with HUD Size on top,- * then fitted to the screen's width by ControlBarHudScaleFit. ControlBarHudScaleFor, the scale- * before HUD Size and the fit, is never below 1; ControlBarHudScale is, on a screen narrower than- * the console, 800x600's 0.91. The tooltips, the boards and the menus keep the uniform scale. */+/** The scale the bottom HUD's page and everything laid out on it are drawn at: the screen's height+ * over 600, cut to CONTROL_BAR_HUD_PERCENT of itself, the owner's "too big" of 2026-09-28, with HUD+ * Size on top, then fitted to the screen's width by ControlBarHudScaleFit. It follows the height+ * alone and is not rounded or floored, the owner's rule of 2026-10-01: the HUD covers the same part+ * of the screen's height at every resolution, and a wider screen does not make it bigger. 1.26 at+ * 1920x1080, as it was when it went by the narrower axis; 0.84 at 1280x720. ControlBarHudScaleFor+ * is the scale before HUD Size and the fit. */enum { CONTROL_BAR_HUD_PERCENT = 70 };extern Real ControlBarHudScale( void );extern Real ControlBarHudScaleFor( Int displayWidth, Int displayHeight );/** `scale` cut down until the console, InGameUI_consolePageWidth page pixels, fits `displayWidth`. */extern Real ControlBarHudScaleFit( Real scale, Int displayWidth );+/** The in-match HUD's other pages - the event feed, the chat, the network box, the scoreboard, the+ * build card, the observer's and the replay's strips - authored at the uniform scale's size: the HUD+ * scale over CONTROL_BAR_HUD_PERCENT, so they keep their size beside the console at every+ * resolution and HUD Size, and are what they were at 1920x1080. The shell's pages, the quit menu+ * and the promotion screen keep the uniform scale. */+extern Real ControlBarHudPageScale( void );/** Undo the .wnd loader's separate-axis stretch over a whole layout: every window under 'root' is* recovered to its authored 800x600 rectangle and put back at ControlBarUniformScale(), anchoreddiff --git a/GeneralsMD/Code/GameEngine/Include/GameClient/HtmlOverlay.h b/GeneralsMD/Code/GameEngine/Include/GameClient/HtmlOverlay.hindex cf2f7bef5..c2598028a 100644--- a/GeneralsMD/Code/GameEngine/Include/GameClient/HtmlOverlay.h+++ b/GeneralsMD/Code/GameEngine/Include/GameClient/HtmlOverlay.h@@ -60,6 +60,9 @@ public:/** Lay the page out at ControlBarHudScale(), the bottom HUD's, rather than the uniform scale. */void setHud( Bool hud );+ /** Lay the page out at ControlBarHudPageScale(), an in-match HUD page beside the console's. */+ void setHudPage( Bool hudPage );+/** Lay the page out with a page pixel one pixel of the screen. At any other scale a page pixel is* a whole number of screen pixels only by luck, and a row of equal cells comes out with its gaps* two pixels here and three there; a page whose every length the game has already turned intodiff --git a/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/ControlBar/ControlBar.cpp b/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/ControlBar/ControlBar.cppindex c353fcf64..efafce3ce 100644--- a/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/ControlBar/ControlBar.cpp+++ b/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/ControlBar/ControlBar.cpp@@ -1613,8 +1613,13 @@ Real ControlBarUniformScale( void )//-------------------------------------------------------------------------------------------------Real ControlBarHudScaleFor( Int displayWidth, Int displayHeight ){- const Real s = ControlBarUniformScaleFor( displayWidth, displayHeight ) * CONTROL_BAR_HUD_PERCENT / 100.0f;- return s < 1.0f ? 1.0f : s;+ return (Real)displayHeight / CONTROL_BAR_DESIGN_H * CONTROL_BAR_HUD_PERCENT / 100.0f;+}++//-------------------------------------------------------------------------------------------------+Real ControlBarHudPageScale( void )+{+ return ControlBarHudScale() * 100.0f / CONTROL_BAR_HUD_PERCENT;}//-------------------------------------------------------------------------------------------------diff --git a/GeneralsMD/Code/GameEngine/Source/GameClient/HtmlOverlay.cpp b/GeneralsMD/Code/GameEngine/Source/GameClient/HtmlOverlay.cppindex a62c0318d..4a599f620 100644--- a/GeneralsMD/Code/GameEngine/Source/GameClient/HtmlOverlay.cpp+++ b/GeneralsMD/Code/GameEngine/Source/GameClient/HtmlOverlay.cpp@@ -202,6 +202,7 @@ private:Int m_alpha; ///< the whole page's, OPAQUE_ALPHA unless it is fadingpublic:Bool m_hud; ///< laid out at ControlBarHudScale(), the bottom HUD's own+ Bool m_hudPage; ///< laid out at ControlBarHudPageScale(), the in-match HUD's other pagesBool m_screenPixels; ///< laid out in the screen's own pixels, over either scale};@@ -215,6 +216,7 @@ HtmlOverlayContainer::HtmlOverlayContainer( const AsciiString &defaultFont ) :m_stamp( 0 ),m_alpha( OPAQUE_ALPHA ),m_hud( FALSE ),+ m_hudPage( FALSE ),m_screenPixels( FALSE ){}@@ -236,7 +238,7 @@ void HtmlOverlayContainer::setPage( const std::string &html ){const Int width = TheDisplay->getWidth();const Int height = TheDisplay->getHeight();- const Real scale = m_screenPixels ? 1.0f : m_hud ? ControlBarHudScale() : ControlBarUniformScale();+ const Real scale = m_screenPixels ? 1.0f : m_hud ? ControlBarHudScale() : m_hudPage ? ControlBarHudPageScale() : ControlBarUniformScale();if( m_document && html == m_page && width == m_screenWidth && height == m_screenHeight && scale == m_scale )return;@@ -813,6 +815,7 @@ HtmlOverlay::~HtmlOverlay( void )void HtmlOverlay::setPage( const std::string &html ) { m_container->setPage( html ); }void HtmlOverlay::draw( void ) { m_container->draw(); }void HtmlOverlay::setHud( Bool hud ) { m_container->m_hud = hud; }+void HtmlOverlay::setHudPage( Bool hudPage ) { m_container->m_hudPage = hudPage; }void HtmlOverlay::setScreenPixels( Bool screenPixels ) { m_container->m_screenPixels = screenPixels; }void HtmlOverlay::setAlpha( Int alpha ) { m_container->setAlpha( alpha ); }Bool HtmlOverlay::hover( const ICoord2D &mouse ) { return m_container->hover( mouse ); }diff --git a/GeneralsMD/Code/GameEngine/Source/GameClient/InGameUI.cpp b/GeneralsMD/Code/GameEngine/Source/GameClient/InGameUI.cppindex f3e1e35b7..4440f419e 100644--- a/GeneralsMD/Code/GameEngine/Source/GameClient/InGameUI.cpp+++ b/GeneralsMD/Code/GameEngine/Source/GameClient/InGameUI.cpp@@ -185,7 +185,7 @@ static const Real BLIND_SPOT_RING_WIDTH = PATHFIND_CELL_SIZE_F * 0.5f; ///< two//-------------------------------------------------------------------------------------------------static Int stripPixels( Int nominal ){- return REAL_TO_INT_CEIL( nominal * ControlBarUniformScale() );+ return REAL_TO_INT_CEIL( nominal * ControlBarHudPageScale() );}//-------------------------------------------------------------------------------------------------@@ -2267,7 +2267,7 @@ static void fillReplayValues( HtmlValues &values, Int floor )// Spectator.html's #replay with its padding and its borders, and a gap under itenum { REPLAY_STRIP_WIDTH = 322, REPLAY_STRIP_HEIGHT = 52 };- const Real scale = ControlBarUniformScale();+ const Real scale = ControlBarHudPageScale();const UnsignedInt frame = TheGameLogic->getFrame();const UnsignedInt length = replayLength();values[ "replay" ] = "on";@@ -2512,7 +2512,10 @@ void InGameUI::drawSpectatorPage( void )if( m_spectatorPage.empty() )return;if( m_spectatorOverlay == NULL )+ {m_spectatorOverlay = new HtmlOverlay( m_superweaponNormalFont );+ m_spectatorOverlay->setHudPage( TRUE );+ }// a unit selected turns the page to his side's steel the same frame, not half a second onconst UnsignedInt frame = TheGameLogic->getFrame();@@ -4520,10 +4523,13 @@ void InGameUI::drawFeed( void )if( m_feedPage.empty() )return;if( m_feedOverlay == NULL )+ {m_feedOverlay = new HtmlOverlay( m_superweaponNormalFont );+ m_feedOverlay->setHudPage( TRUE );+ }HtmlValues values;- values[ "top" ] = std::to_string( REAL_TO_INT_FLOOR( feedTop() / ControlBarUniformScale() ) );+ values[ "top" ] = std::to_string( REAL_TO_INT_FLOOR( feedTop() / ControlBarHudPageScale() ) );m_feedOverlay->setPage( HtmlTemplate_expand( m_feedPage, values, lists, lookupGameText ) );m_feedOverlay->draw();}@@ -4587,7 +4593,7 @@ void InGameUI::drawChat( void )// under the feed, clear of all FEED_LINES_KEPT of its lines so it does not move as the feed grows,// and open, clear of the feed's whole history over it too; the lines stand on the typing bar, which// stands under room for every line kept, so a line coming in does not move it- const Real scale = ControlBarUniformScale();+ const Real scale = ControlBarHudPageScale();const size_t feedLines = max( (size_t)FEED_LINES_KEPT, active ? m_feedLines.size() : 0 );const Int bar = REAL_TO_INT_FLOOR( feedTop() / scale ) + (Int)feedLines * FEED_LINE_HEIGHT + FEED_FOOT + CHAT_OVER_FEED +CHAT_LINES_KEPT * FEED_LINE_HEIGHT + FEED_FOOT;@@ -4606,7 +4612,10 @@ void InGameUI::drawChat( void )if( m_chatPage.empty() )return;if( m_chatOverlay == NULL )+ {m_chatOverlay = new HtmlOverlay( m_superweaponNormalFont );+ m_chatOverlay->setHudPage( TRUE );+ }HtmlValues values;values[ "bar" ] = std::to_string( bar );@@ -10876,7 +10885,10 @@ void InGameUI::drawScoreboard( void )if( m_scoreboardPage.empty() )return;if( m_scoreboardOverlay == NULL )+ {m_scoreboardOverlay = new HtmlOverlay( m_superweaponNormalFont );+ m_scoreboardOverlay->setHudPage( TRUE );+ }// counted again twice a second, as the spectator page is: the money moves every frame, and every// change lays the whole page out again@@ -10982,7 +10994,7 @@ std::string InGameUI::scoreboardHtml( void )// hanging from the top page's foot in the middle of the screen, the two one plateenum { BOARD_WIDTH = 708 };- const Real scale = ControlBarUniformScale();+ const Real scale = ControlBarHudPageScale();HtmlValues values;values[ "side" ] = spectatorSide();values[ "clock" ] = spectatorClock( TheGameLogic->getFrame() );@@ -11727,7 +11739,10 @@ void InGameUI::drawNetPage( void )if( m_netPage.empty() )return;if( m_netOverlay == NULL )+ {m_netOverlay = new HtmlOverlay( m_superweaponNormalFont );+ m_netOverlay->setHudPage( TRUE );+ }HtmlValues values = m_hudValues;values[ "side" ] = spectatorSide();@@ -14547,7 +14562,10 @@ Bool InGameUI::drawTooltipPage( const UnicodeString &cursorText, const RGBColorreturn TRUE;if( m_tooltipOverlay == NULL )+ {m_tooltipOverlay = new HtmlOverlay( m_superweaponNormalFont );+ m_tooltipOverlay->setHudPage( TRUE );+ }HtmlValues values;HtmlLists lists;@@ -14576,7 +14594,7 @@ Bool InGameUI::drawTooltipPage( const UnicodeString &cursorText, const RGBColorconst Int screenWidth = TheDisplay->getWidth();const Int screenHeight = TheDisplay->getHeight();const ICoord2D &mouse = TheMouse->getMouseStatus()->pos;- const Int gap = REAL_TO_INT( TOOLTIP_ANCHOR_GAP * ControlBarUniformScale() );+ const Int gap = REAL_TO_INT( TOOLTIP_ANCHOR_GAP * ControlBarHudPageScale() );for( Int pass = 0; pass < TOOLTIP_LAYOUT_PASSES; pass++ ){IRegion2D box;@@ -14599,7 +14617,7 @@ Bool InGameUI::drawTooltipPage( const UnicodeString &cursorText, const RGBColor}box.hi.x = box.lo.x + m_tooltipSize.x;box.hi.y = box.lo.y + m_tooltipSize.y;- putPageRect( values, "box", box, TRUE );+ putPageRect( values, "box", box, TRUE, ControlBarHudPageScale() );m_tooltipOverlay->setPage( HtmlTemplate_expand( m_tooltipPage, values, lists, lookupGameText ) );std::vector< IRegion2D > laidOut;diff --git a/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/GUI/Gadget/W3DPushButton.cpp b/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/GUI/Gadget/W3DPushButton.cppindex 1c4943cdb..777eee9a2 100644--- a/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/GUI/Gadget/W3DPushButton.cpp+++ b/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/GUI/Gadget/W3DPushButton.cpp@@ -94,6 +94,12 @@ extern Real ControlBarHudScale( void );* bar itself is laid out at. */static const Real BADGE_DESIGN_POINTS = 7.0f;+/** The smallest a marking is set. At 1280x720 the HUD's 0.84 makes seven points 5, and at 5 this+ * font's figures run together: $600 read $800 and 2500 read 2600, and a misread price is worse+ * than none. So the marking stays at 6, and one still too wide sheds its unit - "$2000" is+ * "2000", "24s" is "24" - before it is clipped. */+static const Int BADGE_LEAST_POINTS = 6;+/** The queue count is the one marking a player reads at a glance in the middle of a fight - how* many more of these are still coming - and at seven points against a busy cameo it was a smudge* nobody found without looking for it. It gets its own size, and an opaque plate under it. */@@ -120,8 +126,8 @@ static GameFont *getBadgeFont( GameWindow *window, Real designPoints = BADGE_DESreturn NULL;Int pointSize = REAL_TO_INT_FLOOR( designPoints * ControlBarHudScale() );- if( pointSize < 6 )- pointSize = 6;+ if( pointSize < BADGE_LEAST_POINTS )+ pointSize = BADGE_LEAST_POINTS;// bold, because these are markings on a picture: at seven points against a busy cameo the light// weight reads as noise on the artwork rather than as a letter@@ -133,7 +139,7 @@ static GameFont *getBadgeFont( GameWindow *window, Real designPoints = BADGE_DES} // end getBadgeFontstatic void drawBadge( GameWindow *window, const UnicodeString &text, Real designPoints,- HudReadoutCorner corner, Color color );+ HudReadoutCorner corner, Color color, const UnicodeString &bare = UnicodeString::TheEmptyString );// drawButtonText =============================================================/** Draw button text to the screen */@@ -253,10 +259,15 @@ static void drawCountBadge( GameWindow *window, Int count )* rectangle, inside the frame the command bar's page draws over the button's* edge. Text too wide for the button is set a point smaller until it fits, so* a four figure price or a three figure countdown shrinks instead of running- * out over the frame or into the next button. */+ * out over the frame or into the next button, down to BADGE_LEAST_POINTS. A+ * marking with a unit is drawn as `bare`, its figures alone, where the HUD's+ * scale would set it under BADGE_LEAST_POINTS: held up at that size it shares+ * its row with the corner beside it, and "$2000" ran under the hotkey's plate+ * while "6s" lost its "s" to a block - and as `bare` too when it still does not+ * fit at that size. *///=============================================================================static void drawBadge( GameWindow *window, const UnicodeString &text, Real designPoints,- HudReadoutCorner corner, Color color )+ HudReadoutCorner corner, Color color, const UnicodeString &bare ){IRegion2D cell;ICoord2D size;@@ -266,17 +277,20 @@ static void drawBadge( GameWindow *window, const UnicodeString &text, Real desigcell.hi.y = cell.lo.y + size.y;GameFont *font = getBadgeFont( window, designPoints );- DisplayString *badge = badgeString( text, font );+ const Bool cramped = REAL_TO_INT_FLOOR( designPoints * ControlBarHudScale() ) < BADGE_LEAST_POINTS;+ DisplayString *badge = badgeString( cramped && !bare.isEmpty() ? bare : text, font );if( badge == NULL )return;// each size tried is a string badgeString keeps, so a marking that had to shrink is looked up// the next frame, not lettered again- while( font != NULL && font->pointSize > 6 && !HudReadout_fits( badge, cell ) )+ while( font != NULL && font->pointSize > BADGE_LEAST_POINTS && !HudReadout_fits( badge, cell ) ){font = TheFontLibrary->getFont( font->nameString, font->pointSize - 1, TRUE );badge = badgeString( text, font );}+ if( !bare.isEmpty() && !HudReadout_fits( badge, cell ) )+ badge = badgeString( bare, font );HudReadout_draw( badge, cell, corner, color );@@ -288,9 +302,10 @@ static void drawBadge( GameWindow *window, const UnicodeString &text, Real desig//=============================================================================static void drawSecondsBadge( GameWindow *window, Int seconds ){- UnicodeString text;+ UnicodeString text, bare;text.format( L"%ds", seconds );- drawBadge( window, text, BADGE_DESIGN_POINTS, HUD_READOUT_BOTTOM_LEFT, GameMakeColor( 255, 255, 255, 255 ) );+ bare.format( L"%d", seconds );+ drawBadge( window, text, BADGE_DESIGN_POINTS, HUD_READOUT_BOTTOM_LEFT, GameMakeColor( 255, 255, 255, 255 ), bare );} // end drawSecondsBadge@@ -301,9 +316,10 @@ static void drawSecondsBadge( GameWindow *window, Int seconds )//=============================================================================static void drawCostBadge( GameWindow *window, Int cost ){- UnicodeString text;+ UnicodeString text, bare;text.format( L"$%d", cost );- drawBadge( window, text, BADGE_DESIGN_POINTS, HUD_READOUT_TOP_RIGHT, GameMakeColor( 235, 210, 120, 255 ) );+ bare.format( L"%d", cost );+ drawBadge( window, text, BADGE_DESIGN_POINTS, HUD_READOUT_TOP_RIGHT, GameMakeColor( 235, 210, 120, 255 ), bare );} // end drawCostBadgediff --git a/GeneralsMD/Code/Tests/test_gameengine.cpp b/GeneralsMD/Code/Tests/test_gameengine.cppindex 1ab2d4a1c..50385dce7 100644--- a/GeneralsMD/Code/Tests/test_gameengine.cpp+++ b/GeneralsMD/Code/Tests/test_gameengine.cpp@@ -11747,21 +11747,31 @@ TEST(the_hud_is_measured_at_the_command_bars_own_scale)CHECK_NEAR( ControlBarUniformScaleFor( 0, 0 ), 1.0f, 0.001f );}-/* The bottom HUD is drawn smaller than the rest, the owner's "too big": seventy percent of the- uniform scale, so 1.26 at 1920x1080 where the boards stand at 1.8, and never under what was- authored, so 1280x720 stays at 1 where seventy percent would have been 0.84. */-TEST(controlbar_hud_scale_is_seventy_percent_and_never_below_one)+/* The bottom HUD follows the screen's height alone, the owner's rule of 2026-10-01: seventy percent+ of the height over 600, so 1.26 at 1920x1080 as before, with no floor and no whole steps. It+ covers the same part of the height at 720, 1080 and 1440, and an ultrawide screen of the same+ height draws it no bigger. */+TEST(controlbar_hud_scale_follows_the_screens_height){CHECK_NEAR( ControlBarHudScaleFor( 1920, 1080 ), 1.26f, 0.001f );CHECK_NEAR( ControlBarHudScaleFor( 3840, 2160 ), 2.52f, 0.001f );- CHECK_NEAR( ControlBarHudScaleFor( 2560, 1080 ), 1.26f, 0.001f );- CHECK_NEAR( ControlBarHudScaleFor( 1280, 720 ), 1.0f, 0.001f );- CHECK_NEAR( ControlBarHudScaleFor( 800, 600 ), 1.0f, 0.001f );- CHECK( ControlBarHudScaleFor( 1920, 1080 ) < ControlBarUniformScaleFor( 1920, 1080 ) );+ CHECK_NEAR( ControlBarHudScaleFor( 1280, 720 ), 0.84f, 0.001f );++ struct Screen { Int w, h; };+ const Screen screens[] = { { 1280, 720 }, { 1920, 1080 }, { 2560, 1440 } };+ const Real reference = ControlBarHudScaleFit( ControlBarHudScaleFor( 1920, 1080 ), 1920 ) / 1080.0f;+ for( Int i = 0; i < (Int)ARRAY_SIZE( screens ); i++ )+ {+ const Real covered = ControlBarHudScaleFit( ControlBarHudScaleFor( screens[ i ].w, screens[ i ].h ), screens[ i ].w ) / screens[ i ].h;+ CHECK_NEAR( covered, reference, 0.0001f );+ }+ CHECK_NEAR( ControlBarHudScaleFit( ControlBarHudScaleFor( 2560, 1080 ), 2560 ),+ ControlBarHudScaleFit( ControlBarHudScaleFor( 1920, 1080 ), 1920 ), 0.0001f );}-/* HUD Size grows the console until it would no longer fit the screen's width, and there it stops.- Only a screen narrower than the console at its authored size takes it under 1: 800x600 does. */+/* HUD Size grows the console until it would no longer fit the screen's width, and there it stops:+ at HUD Size 100% only a screen narrower than about 1.05:1, at 150% one narrower than about 1.57:1,+ which takes in 4:3 and 5:4. */TEST(controlbar_hud_size_stops_where_the_console_fills_the_width){const Int console = InGameUI_consolePageWidth();@@ -11771,6 +11781,9 @@ TEST(controlbar_hud_size_stops_where_the_console_fills_the_width)CHECK( ControlBarHudScaleFit( 1.5f, 1280 ) * console <= 1280.0f );CHECK_NEAR( ControlBarHudScaleFit( 1.0f, 1024 ), 1.0f, 0.001f );CHECK( ControlBarHudScaleFit( 1.0f, 800 ) < 1.0f );+ const Real narrow = ControlBarHudScaleFor( 1024, 768 );+ CHECK_NEAR( ControlBarHudScaleFit( narrow, 1024 ), narrow, 0.0001f );+ CHECK( ControlBarHudScaleFit( narrow * 1.5f, 1024 ) < narrow * 1.5f );}/* A health bar is drawn in raw pixels over a tank whose own size on screen is set by the camera,