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): split the command bar into three anchored panels
Olcay Seygan6d57016bd866
diff --git a/CHANGELOG.md b/CHANGELOG.mdindex 412533dac..5740bbda3 100644--- a/CHANGELOG.md+++ b/CHANGELOG.md@@ -366,6 +366,7 @@ found and fixed — EA's own, not port damage.**- 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.+- On a widescreen monitor the command bar is three pieces instead of one stretched strip. It was drawn for a 4:3 screen and every measurement in it is multiplied by your resolution separately across and down, so at 16:9 the whole thing came out a third wider than it is tall: square build pictures as rectangles, and one slab of metal across the entire bottom edge. The radar now sits hard in the left corner, the build grid in the middle, the selected unit's panel hard in the right corner, each at the size it was drawn at, and the battlefield shows through the two gaps that opens. At 4:3 the three pieces meet and it is the bar it has always been.- Widescreen resolutions are back in the options menu.- Borderless fullscreen: start with `-borderless` and the game fills the screen at your desktop resolution with no frame and no display mode change, so alt-tab is instant, nothing on the desktop gets shuffled around behind it, and a second monitor stays usable. Screen-edge scrolling works there, the way it does in fullscreen. The loading picture still opens as its own small window with your desktop around it, and the game only takes the screen once it has something to draw.- Picking High detail gives you high resolution textures. The setting was ignored: the resolution came from a machine benchmark that answers 'low' on anything modern, so there was no way to ask for better.@@ -492,7 +493,8 @@ found and fixed — EA's own, not port damage.**- That found every multiplayer replay falsely accusing itself of desync since 2003.- Every fix was proved by putting the bug back and watching the test fail.- No debugger here: a crash symboliser, a sampling profiler, probes in live matches.-- Reverted and recorded: wide FOV, four pathfinding experiments, a three-panel command bar, tree shadows.+- Reverted and recorded: wide FOV, four pathfinding experiments, tree shadows.+- The three-piece command bar was reverted once, for having nowhere to put the painting of the bar, and is back now that the painting has been cut into three to match. Each piece is fitted by matching it against the artwork it was cut from rather than by eye: the eyeballed fit was four percent out, which nobody sees on the metal and everybody sees on the money readout.- The opponent's decisions are argued with a number: 20 headless matches per change, same seeds, win rate and match length before and after.- That caught two changes that looked right and measured catastrophic - a wave that waited jammed the whole production line, and a retreat rule that counted buildings as gunfire sent every attack home. Both showed up as twenty matches with zero kills.- Massing an army before attacking is written and measured but switched off: it needs somewhere to wait that is not the production queue.diff --git a/GeneralsMD/Code/CMakeLists.txt b/GeneralsMD/Code/CMakeLists.txtindex 0e0df3070..1c52fc412 100644--- a/GeneralsMD/Code/CMakeLists.txt+++ b/GeneralsMD/Code/CMakeLists.txt@@ -517,7 +517,12 @@ add_custom_command(TARGET generals POST_BUILD# in gitignored Run/.COMMAND ${CMAKE_COMMAND} -E copy_if_different${CMAKE_CURRENT_SOURCE_DIR}/Data/Install_Final.bmp- ${CMAKE_CURRENT_SOURCE_DIR}/../Run/)+ ${CMAKE_CURRENT_SOURCE_DIR}/../Run/+ # The three command bar plates per side. A loose texture beats every .big, so+ # these land in Run/Art/Textures where the W3D file system looks first.+ COMMAND ${CMAKE_COMMAND} -E copy_directory+ ${CMAKE_CURRENT_SOURCE_DIR}/Data/Art/Textures+ ${CMAKE_CURRENT_SOURCE_DIR}/../Run/Art/Textures)add_dependencies(generals d3d8to9)# ===========================================================================diff --git a/GeneralsMD/Code/Data/Art/Textures/RebornBarAmericaCenter.tga b/GeneralsMD/Code/Data/Art/Textures/RebornBarAmericaCenter.tganew file mode 100644index 000000000..6cce4b962Binary files /dev/null and b/GeneralsMD/Code/Data/Art/Textures/RebornBarAmericaCenter.tga differdiff --git a/GeneralsMD/Code/Data/Art/Textures/RebornBarAmericaLeft.tga b/GeneralsMD/Code/Data/Art/Textures/RebornBarAmericaLeft.tganew file mode 100644index 000000000..38b537444Binary files /dev/null and b/GeneralsMD/Code/Data/Art/Textures/RebornBarAmericaLeft.tga differdiff --git a/GeneralsMD/Code/Data/Art/Textures/RebornBarAmericaRight.tga b/GeneralsMD/Code/Data/Art/Textures/RebornBarAmericaRight.tganew file mode 100644index 000000000..73339cad6Binary files /dev/null and b/GeneralsMD/Code/Data/Art/Textures/RebornBarAmericaRight.tga differdiff --git a/GeneralsMD/Code/Data/Art/Textures/RebornBarChinaCenter.tga b/GeneralsMD/Code/Data/Art/Textures/RebornBarChinaCenter.tganew file mode 100644index 000000000..a932a25cfBinary files /dev/null and b/GeneralsMD/Code/Data/Art/Textures/RebornBarChinaCenter.tga differdiff --git a/GeneralsMD/Code/Data/Art/Textures/RebornBarChinaLeft.tga b/GeneralsMD/Code/Data/Art/Textures/RebornBarChinaLeft.tganew file mode 100644index 000000000..679d2653cBinary files /dev/null and b/GeneralsMD/Code/Data/Art/Textures/RebornBarChinaLeft.tga differdiff --git a/GeneralsMD/Code/Data/Art/Textures/RebornBarChinaRight.tga b/GeneralsMD/Code/Data/Art/Textures/RebornBarChinaRight.tganew file mode 100644index 000000000..0ec15435eBinary files /dev/null and b/GeneralsMD/Code/Data/Art/Textures/RebornBarChinaRight.tga differdiff --git a/GeneralsMD/Code/Data/Art/Textures/RebornBarGLACenter.tga b/GeneralsMD/Code/Data/Art/Textures/RebornBarGLACenter.tganew file mode 100644index 000000000..458b0ba5eBinary files /dev/null and b/GeneralsMD/Code/Data/Art/Textures/RebornBarGLACenter.tga differdiff --git a/GeneralsMD/Code/Data/Art/Textures/RebornBarGLALeft.tga b/GeneralsMD/Code/Data/Art/Textures/RebornBarGLALeft.tganew file mode 100644index 000000000..2b96e0960Binary files /dev/null and b/GeneralsMD/Code/Data/Art/Textures/RebornBarGLALeft.tga differdiff --git a/GeneralsMD/Code/Data/Art/Textures/RebornBarGLARight.tga b/GeneralsMD/Code/Data/Art/Textures/RebornBarGLARight.tganew file mode 100644index 000000000..3b7727b69Binary files /dev/null and b/GeneralsMD/Code/Data/Art/Textures/RebornBarGLARight.tga differdiff --git a/GeneralsMD/Code/GameEngine/Include/GameClient/ControlBar.h b/GeneralsMD/Code/GameEngine/Include/GameClient/ControlBar.hindex 8f62deb4f..fc7b76dcb 100644--- a/GeneralsMD/Code/GameEngine/Include/GameClient/ControlBar.h+++ b/GeneralsMD/Code/GameEngine/Include/GameClient/ControlBar.h@@ -871,7 +871,33 @@ public:Bool hasAnyShortcutSelection() const;+ //+ // The bar is three independently anchored panels rather than one strip stretched across the+ // bottom edge. layoutPanels() re-places every window in ControlBar.wnd at a single uniform+ // scale inside one of them; the plate art is drawn around the content rectangles it records.+ //+ enum ControlBarPanel+ {+ CB_PANEL_LEFT = 0, ///< radar, hard against the left edge+ CB_PANEL_CENTER, ///< money, power, the toolbar column and the command grid, centred+ CB_PANEL_RIGHT, ///< selection portrait and the general's tabs, hard against the right edge++ CB_PANEL_COUNT+ };++ /// the whole panel, art included - this is what blocks a click from reaching the world+ const IRegion2D *getPanelRect( Int which ) const { return &m_panelRect[ which ]; }++ /** Re-anchor the three panels at one uniform scale. Idempotent, and safe to call again after+ * something else has moved a window - ControlBarScheme::init does, every time a scheme is+ * set - because it remembers both the authored rectangle and the one it last handed out. */+ void layoutPanels( void );+protected:+ /// place one window and its descendants inside 'panel'; see layoutPanels+ void placeInPanel( GameWindow *win, Int panel,+ Int oldParentX, Int oldParentY, Int newParentX, Int newParentY );+void updateRadarAttackGlow ( void );void setDefaultControlBarConfig( void );@@ -1010,6 +1036,8 @@ protected:ICoord2D m_defaultControlBarPosition; ///< Stored the original position of the control bar on the screenControlBarStages m_currentControlBarStage;+ IRegion2D m_panelRect[ CB_PANEL_COUNT ]; ///< screen rect of each panel, filled by layoutPanels()+Bool m_UIDirty; ///< the context UI must be re-evaluatedCommandButton *m_commandButtons; ///< list of possible commands to have@@ -1237,6 +1265,38 @@ private:// EXTERNALS //////////////////////////////////////////////////////////////////////////////////////extern ControlBar *TheControlBar;+//-------------------------------------------------------------------------------------------------+/** The plate one panel wears.+ *+ * The scheme art (ControlBarScheme) is one wide painting of the whole bar, drawn from a single+ * anchor and stretched by the display over 800x600. The bar is three separately anchored panels+ * now, so that painting has nowhere to go and is not drawn at all: each panel wears a plate.+ *+ * The nine plates are the three shipped paintings cut into three, so each one has an exact+ * rectangle in the .wnd's own 800x600 space - the rectangle of the painting it came from. That+ * is what a plate carries, and drawing it is that rectangle put through the same anchor and the+ * same uniform scale layoutPanels puts every window through. Nothing is measured by eye, so the+ * money slot, the power rail and the toolbar column land on the windows the scheme puts there,+ * and at 4:3 each side's three plates slide back together into the strip they came from. */+//-------------------------------------------------------------------------------------------------+struct ControlBarPlate+{+ const char *filename; ///< the targa, which is all the Image needs+ IRegion2D design; ///< the 800x600 rectangle of the painting this piece is+};++/** The plate 'panel' wears while the bar is dressed in 'side'. A general's scheme names a side+ * like "ChinaTankGeneral", so the match is on the front of the name. NULL when nothing fits. */+extern const ControlBarPlate *ControlBarPlateForSide( const AsciiString& side, Int panel );++/** Where a design rectangle belonging to 'panel' lands on a display this size. This is the one+ * piece of arithmetic the whole layout is built out of: one uniform scale, and an anchor that+ * pins the left panel to the left edge, the right panel to the right edge and the middle one to+ * the middle. FALSE for a panel that does not exist. */+extern Bool ControlBarPanelDesignToScreen( Int panel, const IRegion2D *design,+ Int displayWidth, Int displayHeight,+ IRegion2D *rectOut );+//-------------------------------------------------------------------------------------------------/** Logic frames as the whole seconds they will really take at the current logic rate, rounded up* and never down to zero. Defined in ControlBarCommand.cpp; every countdown and build time thediff --git a/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/ControlBar/ControlBar.cpp b/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/ControlBar/ControlBar.cppindex 27e2fd44f..1a7c2357c 100644--- a/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/ControlBar/ControlBar.cpp+++ b/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/ControlBar/ControlBar.cpp@@ -30,6 +30,8 @@// USER INCLUDES //////////////////////////////////////////////////////////////////////////////////#include "PreRTS.h" // This must go first in EVERY cpp file int the GameEngine++#include <map>#define DEFINE_GUI_COMMMAND_NAMES#define DEFINE_COMMAND_OPTION_NAMES#define DEFINE_WEAPONSLOTTYPE_NAMES@@ -1104,6 +1106,12 @@ ControlBar::ControlBar( void )m_commandBarBorderColor = GameMakeColor(0,0,0,100);for( i = 0; i < NUM_CONTEXT_PARENTS; i++ )m_contextParent[ i ] = NULL;+ // an empty panel is a panel with no plate, which is what the builder tool wants+ for( i = 0; i < CB_PANEL_COUNT; i++ )+ {+ m_panelRect[ i ].lo.x = m_panelRect[ i ].lo.y = 0;+ m_panelRect[ i ].hi.x = m_panelRect[ i ].hi.y = 0;+ }for( i = 0; i < MAX_COMMANDS_PER_SET; i++ ){m_commandWindows[ i ] = NULL;@@ -1274,6 +1282,331 @@ ControlBar::~ControlBar( void )} // end ~ControlBarvoid ControlBarPopupDescriptionUpdateFunc( WindowLayout *layout, void *param );+//-------------------------------------------------------------------------------------------------+// Three-panel control bar layout -----------------------------------------------------------------+//-------------------------------------------------------------------------------------------------+//+// ControlBar.wnd is authored at 800x600 and GameWindowManagerScript stretches every coordinate by+// the display size over that, separately in x and y. On a 16:9 screen that is a 1.33x horizontal+// smear: square cameos come out as rectangles and one strip eats the whole bottom of the screen.+// layoutPanels throws the stretch away. It recovers each window's authored rectangle, then puts it+// back at ONE uniform scale inside one of three panels - radar hard left, command grid centred,+// selection hard right. Nothing is distorted and the world shows through the two gaps.+//++static const Real CONTROL_BAR_DESIGN_W = 800.0f;+static const Real CONTROL_BAR_DESIGN_H = 600.0f;+static const Real CONTROL_BAR_DESIGN_TOP = 404.0f; ///< the highest any panel reaches++//+// The authored 800x600 rectangle each panel covers, art and all - the three plate rectangles below+// unioned over the three sides, run down to the bottom edge of the screen. It is what the panel's+// input-blocking pane becomes, so a click on the artwork does not reach the world behind it.+//+static const IRegion2D thePanelDesignRect[ ControlBar::CB_PANEL_COUNT ] =+{+ { { 0, 410 }, { 216, 600 } }, // CB_PANEL_LEFT - radar+ { { 167, 417 }, { 624, 600 } }, // CB_PANEL_CENTER - money, power, toolbar column, command grid+ { { 609, 421 }, { 800, 600 } }, // CB_PANEL_RIGHT - selection portrait and the general's tabs+};++/// where each panel is pinned: the fraction of the screen its anchor lands on...+static const Real thePanelAnchorFraction[ ControlBar::CB_PANEL_COUNT ] = { 0.0f, 0.5f, 1.0f };+/// ...and which authored x that anchor is, so at 4:3 the three plates reassemble the shipped bar+static const Real thePanelAnchorDesignX[ ControlBar::CB_PANEL_COUNT ] = { 0.0f, 400.0f, 800.0f };++//-------------------------------------------------------------------------------------------------+Bool ControlBarPanelDesignToScreen( Int panel, const IRegion2D *design,+ Int displayWidth, Int displayHeight, IRegion2D *rectOut )+{+ if( panel < 0 || panel >= ControlBar::CB_PANEL_COUNT || design == NULL || rectOut == NULL )+ return FALSE;+ if( displayWidth <= 0 || displayHeight <= 0 )+ return FALSE;++ const Real dispW = (Real)displayWidth;+ const Real dispH = (Real)displayHeight;++ //+ // One scale for both axes, the smaller of the two so the three panels always fit side by side.+ // At 4:3 that is exactly what the .wnd loader would have used and the panels still meet; at+ // anything wider they shrink together and leave the middle of the screen bottom open instead of+ // stretching to fill it.+ //+ const Real loadScaleX = dispW / CONTROL_BAR_DESIGN_W;+ const Real loadScaleY = dispH / CONTROL_BAR_DESIGN_H;+ const Real s = loadScaleX < loadScaleY ? loadScaleX : loadScaleY;++ const Real originX = dispW * thePanelAnchorFraction[ panel ]+ - thePanelAnchorDesignX[ panel ] * s;++ rectOut->lo.x = REAL_TO_INT_FLOOR( originX + design->lo.x * s );+ rectOut->hi.x = REAL_TO_INT_CEIL ( originX + design->hi.x * s );+ rectOut->lo.y = REAL_TO_INT_FLOOR( dispH - ( CONTROL_BAR_DESIGN_H - design->lo.y ) * s );+ rectOut->hi.y = REAL_TO_INT_CEIL ( dispH - ( CONTROL_BAR_DESIGN_H - design->hi.y ) * s );++ return TRUE;+}++//-------------------------------------------------------------------------------------------------+/** What layoutPanels remembers about one window: the 800x600 rectangle it was authored at, and the+ * screen rectangle it was last given. If a window is not where we left it, something else moved+ * it - ControlBarScheme::init does, in the loader's own stretched space - and its authored+ * rectangle has to be read back out of that. */+//-------------------------------------------------------------------------------------------------+struct ControlBarPanelPlacement+{+ Bool known;+ Real designX, designY, designW, designH;+ Int placedX, placedY, placedW, placedH;+};+typedef std::map< GameWindow *, ControlBarPanelPlacement > ControlBarPanelPlacementMap;+static ControlBarPanelPlacementMap theControlBarPlacement;++//-------------------------------------------------------------------------------------------------+/** Which panel a direct child of ControlBarParent belongs to. Everything not named here rides in+ * the middle, which is where the .wnd already puts the money, power and command windows - and+ * where the plate art puts the column of worker/beacon/chat/options slots.+ *+ * The three GameWinBlockInput panes have no name at all, and one of them sits over each panel in+ * the authored layout, so they go by where they were drawn: the pane that used to cover the radar+ * keeps covering the radar. */+//-------------------------------------------------------------------------------------------------+static Int panelForWindow( const char *shortName, Real designCenterX )+{+ static const char *leftNames[] =+ {+ "LeftHUD", "WinUAttack", "BackgroundMarker", "ForegroundMarker", "OnTopDraw", NULL+ };+ static const char *rightNames[] =+ {+ "RightHUD", "GeneralsExp", "ExpBarForeground", "ButtonGeneral",+ "ButtonSmall", "ButtonMedium", "ButtonLarge", NULL+ };++ if( shortName[ 0 ] == 0 )+ {+ for( Int p = 0; p < ControlBar::CB_PANEL_COUNT; p++ )+ if( designCenterX >= thePanelDesignRect[ p ].lo.x &&+ designCenterX <= thePanelDesignRect[ p ].hi.x )+ return p;+ return ControlBar::CB_PANEL_CENTER;+ }++ for( const char **n = leftNames; *n; n++ )+ if( strcmp( shortName, *n ) == 0 )+ return ControlBar::CB_PANEL_LEFT;++ for( const char **n = rightNames; *n; n++ )+ if( strcmp( shortName, *n ) == 0 )+ return ControlBar::CB_PANEL_RIGHT;++ return ControlBar::CB_PANEL_CENTER;+}++//-------------------------------------------------------------------------------------------------+// The plates -------------------------------------------------------------------------------------+//-------------------------------------------------------------------------------------------------+//+// Three per side, cut from that side's shipped painting of the bar. See ControlBar.h for what the+// readout rectangle is and why it is the thing that gets anchored.+//++struct ControlBarPlateSet+{+ const char *sidePrefix; ///< matched against the scheme's Side, so every China general fits China+ ControlBarPlate plate[ ControlBar::CB_PANEL_COUNT ];+};++static const ControlBarPlateSet thePlateSets[] =+{+ { "America",+ {+ { "RebornBarAmericaLeft.tga", { { 0, 412 }, { 183, 599 } } },+ // this one was cut a little above the bar's bottom edge and has that strip put back on it+ { "RebornBarAmericaCenter.tga", { { 180, 419 }, { 623, 599 } } },+ { "RebornBarAmericaRight.tga", { { 610, 433 }, { 800, 599 } } },+ }+ },+ { "China",+ {+ { "RebornBarChinaLeft.tga", { { 1, 417 }, { 196, 598 } } },+ { "RebornBarChinaCenter.tga", { { 176, 433 }, { 617, 597 } } },+ { "RebornBarChinaRight.tga", { { 611, 424 }, { 798, 598 } } },+ }+ },+ { "GLA",+ {+ { "RebornBarGLALeft.tga", { { 0, 416 }, { 215, 599 } } },+ { "RebornBarGLACenter.tga", { { 168, 437 }, { 617, 599 } } },+ { "RebornBarGLARight.tga", { { 612, 423 }, { 799, 599 } } },+ }+ },+};+static const Int NUM_PLATE_SETS = sizeof( thePlateSets ) / sizeof( thePlateSets[ 0 ] );++//-------------------------------------------------------------------------------------------------+const ControlBarPlate *ControlBarPlateForSide( const AsciiString& side, Int panel )+{+ if( side.isEmpty() || panel < 0 || panel >= ControlBar::CB_PANEL_COUNT )+ return NULL;++ // the boss bar is Chinese and the observer bar is American - EA built each out of that art+ if( side.startsWithNoCase( "Boss" ) )+ return &thePlateSets[ 1 ].plate[ panel ];+ if( side.startsWithNoCase( "Observer" ) )+ return &thePlateSets[ 0 ].plate[ panel ];++ for( Int i = 0; i < NUM_PLATE_SETS; i++ )+ if( side.startsWithNoCase( thePlateSets[ i ].sidePrefix ) )+ return &thePlateSets[ i ].plate[ panel ];++ return NULL;+}++//-------------------------------------------------------------------------------------------------+/** The part of a window's decorated name after the colon. */+//-------------------------------------------------------------------------------------------------+static const char *shortWindowName( GameWindow *win )+{+ const char *name = win->winGetInstanceData()->m_decoratedNameString.str();+ const char *colon = strchr( name, ':' );+ return colon ? colon + 1 : name;+}++//-------------------------------------------------------------------------------------------------+/** Place 'win' and everything under it inside 'panel'. Positions are relative to the parent, so+ * both the parent's old and new screen origins travel down the recursion: the old one to work out+ * where the window was, the new one to say where to put it. */+//-------------------------------------------------------------------------------------------------+void ControlBar::placeInPanel( GameWindow *win, Int panel,+ Int oldParentX, Int oldParentY,+ Int newParentX, Int newParentY )+{+ const Real dispW = (Real)TheDisplay->getWidth();+ const Real dispH = (Real)TheDisplay->getHeight();+ const Real loadScaleX = dispW / CONTROL_BAR_DESIGN_W;+ const Real loadScaleY = dispH / CONTROL_BAR_DESIGN_H;+ const Real s = loadScaleX < loadScaleY ? loadScaleX : loadScaleY;+ const Real originX = dispW * thePanelAnchorFraction[ panel ]+ - thePanelAnchorDesignX[ panel ] * s;++ ICoord2D rel, size;+ win->winGetPosition( &rel.x, &rel.y );+ win->winGetSize( &size.x, &size.y );++ const Int oldX = oldParentX + rel.x;+ const Int oldY = oldParentY + rel.y;++ ControlBarPanelPlacement &place = theControlBarPlacement[ win ];+ if( place.known == FALSE || oldX != place.placedX || oldY != place.placedY ||+ size.x != place.placedW || size.y != place.placedH )+ {+ // first sight of this window, or somebody else has moved it in the loader's stretched space+ place.designX = oldX / loadScaleX;+ place.designY = oldY / loadScaleY;+ place.designW = size.x / loadScaleX;+ place.designH = size.y / loadScaleY;+ }++ Int newX = REAL_TO_INT_FLOOR( originX + place.designX * s );+ Int newY = REAL_TO_INT_FLOOR( dispH - ( CONTROL_BAR_DESIGN_H - place.designY ) * s );+ Int newW = REAL_TO_INT_CEIL( place.designW * s );+ Int newH = REAL_TO_INT_CEIL( place.designH * s );++ const char *shortName = shortWindowName( win );++ //+ // The unnamed children are the GameWinBlockInput panes: their only job is to keep clicks on the+ // bar out of the world, so they become exactly their panel. CenterBackground blocks input as+ // well as holding the command windows, and is authored full width, so it gets the same+ // treatment - left alone it would swallow every click over the gaps we just opened up.+ //+ if( shortName[ 0 ] == 0 || strcmp( shortName, "CenterBackground" ) == 0 )+ {+ newX = m_panelRect[ panel ].lo.x;+ newW = m_panelRect[ panel ].width();+ if( shortName[ 0 ] == 0 )+ {+ newY = m_panelRect[ panel ].lo.y;+ newH = m_panelRect[ panel ].height();+ }+ }++ win->winSetPosition( newX - newParentX, newY - newParentY );+ win->winSetSize( newW, newH );++ place.known = TRUE;+ place.placedX = newX;+ place.placedY = newY;+ place.placedW = newW;+ place.placedH = newH;++ for( GameWindow *child = win->winGetChild(); child; child = child->winGetNext() )+ placeInPanel( child, panel, oldX, oldY, newX, newY );++} // end placeInPanel++//-------------------------------------------------------------------------------------------------+/** Re-anchor the control bar as three panels at one uniform scale. */+//-------------------------------------------------------------------------------------------------+void ControlBar::layoutPanels( void )+{+ GameWindow *parent = m_contextParent[ CP_MASTER ];+ if( parent == NULL || TheDisplay == NULL )+ return;++ const Real dispW = (Real)TheDisplay->getWidth();+ const Real dispH = (Real)TheDisplay->getHeight();++ // what the .wnd loader already multiplied every coordinate by, so we can divide it back out+ const Real loadScaleX = dispW / CONTROL_BAR_DESIGN_W;+ const Real loadScaleY = dispH / CONTROL_BAR_DESIGN_H;++ //+ // One scale for both axes, the smaller of the two so the three panels always fit side by side.+ // At 4:3 that is exactly the old scale and the panels still meet; at anything wider they shrink+ // together and leave the middle of the screen bottom open instead of stretching to fill it.+ //+ const Real s = loadScaleX < loadScaleY ? loadScaleX : loadScaleY;++ Int p;+ for( p = 0; p < CB_PANEL_COUNT; p++ )+ ControlBarPanelDesignToScreen( p, &thePanelDesignRect[ p ],+ TheDisplay->getWidth(), TheDisplay->getHeight(),+ &m_panelRect[ p ] );++ // the children's positions are relative to the frame, so grab where it is before moving it+ ICoord2D barOrigin;+ parent->winGetScreenPosition( &barOrigin.x, &barOrigin.y );++ // the frame itself stays full width - it draws nothing and passes input through+ const Int parentTop =+ REAL_TO_INT_FLOOR( dispH - ( CONTROL_BAR_DESIGN_H - CONTROL_BAR_DESIGN_TOP ) * s );+ parent->winSetPosition( 0, parentTop );+ parent->winSetSize( REAL_TO_INT_CEIL( dispW ), REAL_TO_INT_CEIL( dispH ) - parentTop );++ for( GameWindow *child = parent->winGetChild(); child; child = child->winGetNext() )+ {+ // the nameless panes go by where they were authored, so ask the cache before it is rewritten+ ControlBarPanelPlacementMap::const_iterator it = theControlBarPlacement.find( child );+ Real designCenterX;+ if( it != theControlBarPlacement.end() && it->second.known )+ designCenterX = it->second.designX + it->second.designW * 0.5f;+ else+ {+ ICoord2D rel, size;+ child->winGetPosition( &rel.x, &rel.y );+ child->winGetSize( &size.x, &size.y );+ designCenterX = ( barOrigin.x + rel.x + size.x * 0.5f ) / loadScaleX;+ }++ placeInPanel( child, panelForWindow( shortWindowName( child ), designCenterX ),+ barOrigin.x, barOrigin.y, 0, parentTop );+ }++} // end layoutPanels+//-------------------------------------------------------------------------------------------------/** Initialzie the control bar, this is our interface to the context sinsitive GUI *///-------------------------------------------------------------------------------------------------@@ -1311,6 +1644,14 @@ void ControlBar::init( void )id = TheNameKeyGenerator->nameToKey( "ControlBar.wnd:ControlBarParent" );m_contextParent[ CP_MASTER ] = TheWindowManager->winGetWindowFromId( NULL, id );+ //+ // These windows are new, so anything remembered about the last set of them is about+ // addresses that may well have been handed back out. Re-anchor the bar as three uniformly+ // scaled panels before anything reads a position off it.+ //+ theControlBarPlacement.clear();+ layoutPanels();+m_contextParent[ CP_MASTER ]->winGetPosition(&m_defaultControlBarPosition.x, &m_defaultControlBarPosition.y);m_scienceLayout = TheWindowManager->winCreateLayout("GeneralsExpPoints.wnd");diff --git a/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/ControlBar/ControlBarScheme.cpp b/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/ControlBar/ControlBarScheme.cppindex ab1b0f92e..58e6669e1 100644--- a/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/ControlBar/ControlBarScheme.cpp+++ b/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/ControlBar/ControlBarScheme.cpp@@ -684,6 +684,15 @@ void ControlBarScheme::init(void)win->winSetSize(m_powerPurchaseImage->getImageWidth() * resMultiplier.x, m_powerPurchaseImage->getImageHeight() * resMultiplier.y);}}++ //+ // Everything above put a window back where the loader would have stretched it to, which is+ // the whole width of the screen rather than one of the three panels the bar is really in.+ // layoutPanels reads those positions and re-anchors them; it is why it has to run last, and+ // why it runs again every time a scheme is set rather than once at startup.+ //+ if( TheControlBar )+ TheControlBar->layoutPanels();}//diff --git a/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/GUI/GUICallbacks/W3DControlBar.cpp b/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/GUI/GUICallbacks/W3DControlBar.cppindex 03c76ed56..5ddabafe7 100644--- a/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/GUI/GUICallbacks/W3DControlBar.cpp+++ b/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/GUI/GUICallbacks/W3DControlBar.cpp@@ -37,6 +37,7 @@#include "GameClient/ControlBar.h"#include "GameClient/GameWindowManager.h"#include "GameClient/ControlBarScheme.h"+#include "GameClient/Image.h"#include "GameClient/MapUtil.h"#include "GameLogic/GameLogic.h"#ifdef _INTERNAL@@ -633,52 +634,78 @@ void W3DCommandBarTopDraw( GameWindow *window, WinInstanceData *instData )}-void W3DCommandBarBackgroundDraw( GameWindow *window, WinInstanceData *instData )+//-------------------------------------------------------------------------------------------------+/** The Image for one plate. These are not in any MappedImage INI - the whole targa is the image+ * and nothing else uses it - so the first draw builds one and hands it to the mapped image+ * collection, which owns it from then on. */+//-------------------------------------------------------------------------------------------------+static const Image *plateImage( const ControlBarPlate *plate ){+ if( TheMappedImageCollection == NULL )+ return NULL;++ AsciiString name( plate->filename );+ const Image *found = TheMappedImageCollection->findImageByName( name );+ if( found )+ return found;++ Image *image = newInstance( Image );+ image->setName( name );+ image->setFilename( name );++ // the whole targa is the image, so there is nothing to look up and no page to share+ Region2D uv;+ uv.lo.x = 0.0f;+ uv.lo.y = 0.0f;+ uv.hi.x = 1.0f;+ uv.hi.y = 1.0f;+ image->setUV( &uv );++ ICoord2D size;+ size.x = plate->design.width();+ size.y = plate->design.height();+ image->setTextureWidth( size.x );+ image->setTextureHeight( size.y );+ image->setImageSize( &size );++ TheMappedImageCollection->addImage( image );+ return image;+}- ControlBarSchemeManager *man = TheControlBar->getControlBarSchemeManager();- if(!man)+//-------------------------------------------------------------------------------------------------+/** Each panel wears a plate of its own now - see ControlBarPlateForSide in ControlBar.cpp for what+ * a plate is and why the scheme's one-piece painting is not drawn at all. */+//-------------------------------------------------------------------------------------------------+void W3DCommandBarBackgroundDraw( GameWindow *window, WinInstanceData *instData )+{+ ControlBarSchemeManager *man = TheControlBar ? TheControlBar->getControlBarSchemeManager() : NULL;+ if( man == NULL || TheDisplay == NULL )return;- static NameKeyType winNamekey = TheNameKeyGenerator->nameToKey( AsciiString( "ControlBar.wnd:BackgroundMarker" ) );- GameWindow *win = TheWindowManager->winGetWindowFromId(NULL,winNamekey);- static ICoord2D basePos;- if(!win)++ for( Int p = 0; p < ControlBar::CB_PANEL_COUNT; p++ ){- return;- //win = TheWindowManager->winGetWindowFromId(NULL,TheNameKeyGenerator->nameToKey( AsciiString( "ControlBar.wnd:BackgroundMarker" ) ));+ const ControlBarPlate *plate = ControlBarPlateForSide( man->getCurrentSide(), p );+ if( plate == NULL )+ plate = ControlBarPlateForSide( man->getCurrentArtTwinSide(), p );+ if( plate == NULL )+ continue;++ IRegion2D rect;+ if( ControlBarPanelDesignToScreen( p, &plate->design, TheDisplay->getWidth(),+ TheDisplay->getHeight(), &rect ) == FALSE )+ continue;++ const Image *image = plateImage( plate );+ if( image )+ TheDisplay->drawImage( image, rect.lo.x, rect.lo.y, rect.hi.x, rect.hi.y );}- TheControlBar->getBackgroundMarkerPos(&basePos.x, &basePos.y);- ICoord2D pos, offset;- win->winGetScreenPosition(&pos.x,&pos.y);- offset.x = pos.x - basePos.x;- offset.y = pos.y - basePos.y;-- man->drawBackground(offset);}void W3DCommandBarForegroundDraw( GameWindow *window, WinInstanceData *instData ){- ControlBarSchemeManager *man = TheControlBar->getControlBarSchemeManager();- if(!man)- return;-- static NameKeyType winNamekey = TheNameKeyGenerator->nameToKey( AsciiString( "ControlBar.wnd:BackgroundMarker" ) );- GameWindow *win = TheWindowManager->winGetWindowFromId(NULL,winNamekey);- static ICoord2D basePos;- if(!win)- {- return;- //win = TheWindowManager->winGetWindowFromId(NULL,TheNameKeyGenerator->nameToKey( AsciiString( "ControlBar.wnd:BackgroundMarker" ) ));- }- TheControlBar->getForegroundMarkerPos(&basePos.x, &basePos.y);- ICoord2D pos, offset;- win->winGetScreenPosition(&pos.x,&pos.y);- offset.x = pos.x - basePos.x;- offset.y = pos.y - basePos.y;-- man->drawForeground(offset);+ // nothing sits on top of the plates - see W3DCommandBarBackgroundDraw}diff --git a/GeneralsMD/Code/Tests/test_gameengine.cpp b/GeneralsMD/Code/Tests/test_gameengine.cppindex 89f28bf04..ca5ff1bac 100644--- a/GeneralsMD/Code/Tests/test_gameengine.cpp+++ b/GeneralsMD/Code/Tests/test_gameengine.cpp@@ -7726,6 +7726,129 @@ TEST(borderless_asks_for_a_windowed_device_the_size_of_the_desktop)delete scratch;}+TEST(every_side_has_three_plates_and_every_general_wears_its_sides)+{+ /* The bar is three panels and each wears a plate cut from its side's own painting. A scheme+ names a side like "ChinaTankGeneral", the boss bar calls itself "Boss" and the observer bar+ "Observer", and none of those three has artwork of its own - so a side that fell through this+ lookup would leave the whole bar with no background at all. */+ static const char *sides[] =+ {+ "America", "China", "GLA",+ "AmericaSuperWeaponGeneral", "AmericaLaserGeneral", "AmericaAirForceGeneral",+ "ChinaTankGeneral", "ChinaInfantryGeneral", "ChinaNukeGeneral",+ "GLAToxinGeneral", "GLADemolitionGeneral", "GLAStealthGeneral",+ "Boss", "Observer", NULL+ };++ for( const char **s = sides; *s; s++ )+ {+ Int previousRight = -1;+ for( Int p = 0; p < ControlBar::CB_PANEL_COUNT; p++ )+ {+ const ControlBarPlate *plate = ControlBarPlateForSide( AsciiString( *s ), p );+ CHECK( plate != NULL );+ CHECK( plate->filename != NULL && plate->filename[ 0 ] != 0 );++ /* every piece is a rectangle of the shipped painting, which is drawn across the bottom+ of the .wnd's 800x600 - so it lives in the bottom quarter and nowhere else */+ CHECK( plate->design.width() > 0 && plate->design.height() > 0 );+ CHECK( plate->design.lo.x >= 0 && plate->design.hi.x <= 800 );+ CHECK( plate->design.lo.y >= 399 && plate->design.hi.y <= 600 );++ // left, middle, right, in that order+ CHECK( plate->design.hi.x > previousRight );+ previousRight = plate->design.hi.x;+ }+ }++ /* a side nobody drew art for gets no plate rather than somebody else's */+ CHECK( ControlBarPlateForSide( AsciiString( "Martians" ), ControlBar::CB_PANEL_LEFT ) == NULL );+ CHECK( ControlBarPlateForSide( AsciiString::TheEmptyString, ControlBar::CB_PANEL_LEFT ) == NULL );+ CHECK( ControlBarPlateForSide( AsciiString( "America" ), ControlBar::CB_PANEL_COUNT ) == NULL );+}++TEST(the_three_panels_are_one_bar_at_4x3_and_pull_apart_on_a_wide_screen)+{+ /* Every window and every plate goes through this one piece of arithmetic, so it is where a+ misplaced money slot or a smeared cameo would come from. Two things have to hold: at 4:3 it+ reproduces what the .wnd loader would have done, which is what makes the three plates slide+ back into the one strip EA drew; and above 4:3 it scales by one factor for both axes and+ opens the two gaps rather than stretching to fill them. */+ IRegion2D whole; // the whole authored bar+ whole.lo.x = 0;+ whole.lo.y = 408;+ whole.hi.x = 800;+ whole.hi.y = 600;++ IRegion2D left, centre, right;+ CHECK( ControlBarPanelDesignToScreen( ControlBar::CB_PANEL_LEFT, &whole, 800, 600, &left ) );+ CHECK( ControlBarPanelDesignToScreen( ControlBar::CB_PANEL_CENTER, &whole, 800, 600, ¢re ) );+ CHECK( ControlBarPanelDesignToScreen( ControlBar::CB_PANEL_RIGHT, &whole, 800, 600, &right ) );++ // at the authored size all three anchors land on the authored rectangle itself+ CHECK_EQ( left.lo.x, 0 ); CHECK_EQ( left.hi.x, 800 );+ CHECK_EQ( centre.lo.x, 0 ); CHECK_EQ( centre.hi.x, 800 );+ CHECK_EQ( right.lo.x, 0 ); CHECK_EQ( right.hi.x, 800 );+ CHECK_EQ( left.lo.y, 408 ); CHECK_EQ( left.hi.y, 600 );++ /* 1920x1080 is 1.8 times the authored height and 2.4 times its width; the smaller one wins, so+ a square cameo stays square instead of coming out a third wider than it is tall */+ CHECK( ControlBarPanelDesignToScreen( ControlBar::CB_PANEL_LEFT, &whole, 1920, 1080, &left ) );+ CHECK( ControlBarPanelDesignToScreen( ControlBar::CB_PANEL_CENTER, &whole, 1920, 1080, ¢re ) );+ CHECK( ControlBarPanelDesignToScreen( ControlBar::CB_PANEL_RIGHT, &whole, 1920, 1080, &right ) );++ CHECK_NEAR( (Real)left.width(), 800.0f * 1.8f, 1.5f );+ CHECK_NEAR( (Real)left.height(), 192.0f * 1.8f, 1.5f );++ // left edge to left edge, right edge to right edge, and the middle one centred between them+ CHECK_EQ( left.lo.x, 0 );+ CHECK_EQ( right.hi.x, 1920 );+ CHECK_NEAR( (Real)( centre.lo.x + centre.hi.x ) * 0.5f, 960.0f, 2.0f );++ // and every panel still sits on the bottom edge of the screen+ CHECK_EQ( left.hi.y, 1080 );+ CHECK_EQ( centre.hi.y, 1080 );+ CHECK_EQ( right.hi.y, 1080 );++ CHECK( ControlBarPanelDesignToScreen( ControlBar::CB_PANEL_COUNT, &whole, 1920, 1080, &left ) == FALSE );+ CHECK( ControlBarPanelDesignToScreen( ControlBar::CB_PANEL_LEFT, &whole, 0, 0, &left ) == FALSE );+}++TEST(a_plate_covers_the_windows_its_panel_is_responsible_for)+{+ /* The plates are cuts of the shipped painting and the windows are at the coordinates the .wnd+ and ControlBarScheme.ini give them, so the two only agree if the plate rectangles are right.+ These are the windows a player looks at: the radar, the money readout, the power rail, the+ toolbar column, the command grid and the selection portrait. A plate that has drifted - and+ an earlier version of this, fitted by eye instead of to the painting, had drifted about four+ percent - leaves one of them hanging off its own artwork. */+ struct Seated { const char *what; Int panel; Int x0, y0, x1, y1; };+ static const Seated seated[] =+ {+ { "radar", ControlBar::CB_PANEL_LEFT, 7, 443, 174, 595 },+ { "money", ControlBar::CB_PANEL_CENTER, 360, 437, 439, 462 },+ { "power bar", ControlBar::CB_PANEL_CENTER, 259, 469, 538, 476 },+ { "toolbar column", ControlBar::CB_PANEL_CENTER, 184, 490, 220, 592 },+ { "command grid", ControlBar::CB_PANEL_CENTER, 223, 494, 603, 589 },+ { "selection portrait", ControlBar::CB_PANEL_RIGHT, 621, 483, 760, 592 },+ { NULL, 0, 0, 0, 0, 0 }+ };+ static const char *sides[] = { "America", "China", "GLA", NULL };++ for( const char **s = sides; *s; s++ )+ for( const Seated *w = seated; w->what; w++ )+ {+ const ControlBarPlate *plate = ControlBarPlateForSide( AsciiString( *s ), w->panel );+ CHECK( plate != NULL );++ // the bottom edge is the one that may hang off: the bar runs to the bottom of the screen+ CHECK( plate->design.lo.x <= w->x0 );+ CHECK( plate->design.hi.x >= w->x1 );+ CHECK( plate->design.lo.y <= w->y0 );+ }+}+/* A build order is a message, and the structure it orders does not exist until the logic runs it -on a network game, however long the link takes. Until then the client remembers the ground itspent, so a shift-held run of clicks does not put two structures on the same square. What it