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(gameengine): build the HUD strips out of the general's power tray
Olcay Seygan1b830e62dee7
diff --git a/CHANGELOG.md b/CHANGELOG.mdindex 3eb5112c8..ea2e9c897 100644--- a/CHANGELOG.md+++ b/CHANGELOG.md@@ -254,6 +254,7 @@ found and fixed — EA's own, not port damage.**- One row above the command bar carries everything your base is building anywhere.- Ordered by time left, so it reads as the order things arrive.+- Select a building and what it is making moves to the front of that row, ahead of everything else, still soonest first among itself. It used to get a whole second row of its own under the base's, which said the same thing twice and pushed the strip further up the screen; now the head of the strip is the building you are looking at and the tail is the rest of your base.- Click a picture to jump the camera there; Ctrl-click cancels it.- One picture is one order, cut to match the command bar's artwork.- The strip is half the size it was: it says the same thing and takes back the screen it was eating.@@ -280,6 +281,10 @@ found and fixed — EA's own, not port damage.**- Every button's corner markings - the hotkey, the price, the time, the number queued - sit flush in the corners instead of floating a few pixels inside them, and are set a size smaller than the button's own text: four labels at full size were eating the picture they were meant to annotate.- A superweapon's wait is written in plain seconds - 200, not 3:20 - so it compares with every other countdown on the screen at a glance. Once it is charged the number goes away entirely and the picture itself breathes in your colour, which is the one thing you want to catch out of the corner of your eye.- The countdown inside a strip picture lost its black backing plate. On a picture that small the plate was most of the picture; the number now sits straight on the sweeping clock.+- Every picture in the row stands in a tray - the same tray your general's powers stand in down in the corner, your own side's copy of it, so the American, Chinese and GLA strips each carry their own metal. The tray is turned back to front, because that bar grows out of the right hand corner and the strip grows out of the left, so its heavy rail leads the row instead of standing between every pair of pictures. It is never stretched to fit, and the trays close up behind each other by exactly what that bar closes its own up by, so the row reads as one run of metal rather than a line of loose boxes. The strip is flush against the left edge, and a black rectangle laid over the battlefield is gone.+- A slot in it is a slot of that bar to the pixel, at every resolution - the size is measured off the bar itself rather than guessed - so the queue is read at a glance instead of squinted at: these were postage stamps a third of that size. Six of them is the most the row shows, and everything past them is counted at the end of it.+- Above the queue is a row of what is actually going up on the ground: every building your workers are raising, each with its own sweep and the seconds it still needs, soonest first. Click one and the camera goes to the site - a half-finished building under fire on the far side of the map is one click away instead of a hunt across the minimap. Nothing in that row can be cancelled by mistake: a building already standing is sold or lost, never cancelled, so Ctrl over it does nothing.+- The superweapon strip in the top right stands in the same metal, the right way round this time: it is anchored to the right hand edge and grows leftwards, which is the way that bar in the corner grows, so its rail closes the row against the edge of the screen. The black rectangle behind those pictures is gone with it, and the countdowns are the size of the ones down in the corner rather than half of it.- A game opens with nothing selected, so your first click is not a rally point.- Your general's powers no longer climb the right hand edge of the screen. They sit three abreast, filling from the bottom corner where the first one has always been and wrapping upward, so a general holding eleven of them still reads as a block instead of a ladder from the radar to the sky. The keys follow the same shape: the first press picks a row, the second picks the power in it, so every power is two keys away - F1 F1 for the one in the corner, F2 F1 for the row above it. Only the keys you can press next are written on the pictures, so you are never reading eleven labels to find one, and Escape drops a row you thought better of - so does clicking a power with the mouse, and so does a couple of seconds' pause, so a key hit by mistake in a fight never turns your next one into a superweapon. Rows with nothing in them yet cannot be picked at all: early on, when you hold three powers, only the row you have answers a key.- The tilde key opens the general's promotions, and Escape closes them - Escape used to bring up the pause menu on top of the open screen, leaving the small exit button in its corner as the only way out. The screen is five columns wide and 1 to 5 now name them: each number sits in the corner of the science that column would sell you next, and pressing it twice buys that one - once to mark, once to spend, so a point is never gone to a key hit in a hurry. Buy the top of a chain and the number drops onto the next rung down, so a whole column goes in with one finger while the fight carries on behind you.diff --git a/GeneralsMD/Code/GameEngine/Include/GameClient/ControlBar.h b/GeneralsMD/Code/GameEngine/Include/GameClient/ControlBar.hindex caf2d2c03..8141be3bd 100644--- a/GeneralsMD/Code/GameEngine/Include/GameClient/ControlBar.h+++ b/GeneralsMD/Code/GameEngine/Include/GameClient/ControlBar.h@@ -828,6 +828,16 @@ public:Color getUpgradeBorderColor( void ){return m_commandButtonBorderUpgradeColor;}void updateBorderColor( Color color) {m_commandBarBorderColor = color; }+ /** The tray one of the general's power shortcuts stands in, down in the corner - this side's own+ * copy of it, taken off the bar itself rather than named, so a mod's bar brings its own. */+ const Image *getSpecialPowerTrayImage( void );++ /** That tray at the size the bar draws it, the hole in it the cameo fills, and the step a row of+ * them runs at - measured off the loaded bar, so a borrowed tray is the size of the powers'+ * own at any resolution. Any out-parameter may be NULL; FALSE when there is no bar. */+ Bool getSpecialPowerTrayLayout( ICoord2D *traySize, ICoord2D *cameoSize,+ ICoord2D *cameoOffset, Int *columnStep );+/// set the command data into the buttonvoid setControlCommand( GameWindow *button, const CommandButton *commandButton );diff --git a/GeneralsMD/Code/GameEngine/Include/GameClient/Image.h b/GeneralsMD/Code/GameEngine/Include/GameClient/Image.hindex fa0f6a9d7..a7c201e53 100644--- a/GeneralsMD/Code/GameEngine/Include/GameClient/Image.h+++ b/GeneralsMD/Code/GameEngine/Include/GameClient/Image.h@@ -167,6 +167,14 @@ inline void Image::setRawTextureData( void *data ) { m_rawTextureData = data; }inline const void *Image::getRawTextureData( void ) const { return m_rawTextureData; }inline UnsignedInt Image::getStatus( void ) const { return m_status; }+//-------------------------------------------------------------------------------------------------+/** The same piece of texture, drawn back to front: a new Image over the same page, with the run of+ * its UV rect reversed left to right and everything else carried across. Nothing is copied out+ * of the page, so this costs one small object - and the original is left as it was, since+ * whoever owns it is still drawing from it. The caller owns what comes back. */+//-------------------------------------------------------------------------------------------------+extern Image *newMirroredImage( const Image *source );+// EXTERNALS //////////////////////////////////////////////////////////////////////////////////////extern ImageCollection *TheMappedImageCollection; ///< mapped imagesdiff --git a/GeneralsMD/Code/GameEngine/Include/GameClient/InGameUI.h b/GeneralsMD/Code/GameEngine/Include/GameClient/InGameUI.hindex 47fa4f90e..cea057faf 100644--- a/GeneralsMD/Code/GameEngine/Include/GameClient/InGameUI.h+++ b/GeneralsMD/Code/GameEngine/Include/GameClient/InGameUI.h@@ -586,16 +586,60 @@ public: // ********************************************************************// One cameo of the global production strip: which producer it belongs to, which entry of that// producer's queue it is, and where it was drawn this frame.//- enum { PRODUCTION_STRIP_ROW_MAX = 16 }; ///< cameos one row will draw; the rest become a "+N"+ enum { PRODUCTION_STRIP_ROW_MAX = 6 }; ///< cameos one row will draw; the rest become a "+N"enum { PRODUCTION_STRIP_WATCH_MAX = 5 }; ///< and while watching, where eight rows share the screenenum { PRODUCTION_STRIP_ROWS = 8 }; ///< playing: the global row and the selected producer's row./// watching: one row per player, so eight of them++ //+ // Which row is which while playing. A lower number is drawn higher up the screen, so the+ // buildings going up on the map stand above the queue. The building you have selected does not+ // get a row of its own - its items lead the queue row instead. Rows nobody filled are closed up+ // rather than left as a gap.+ //+ enum+ {+ PRODUCTION_ROW_SITES = 0, ///< buildings a dozer or a worker is putting up+ PRODUCTION_ROW_QUEUE = 1 ///< everything the whole base has queued+ };++ //+ // A queue slot is one slot of the general's power bar down in the corner, measurement for+ // measurement: that bar is where a tray of cameos already lives in this game, so the strip is+ // built out of the same tray instead of inventing a second look for the same job. Every number+ // here is read off GenPowersShortcutBar*.wnd, in the 800x600 the rest of the strip is written in.+ //+ enum+ {+ PRODUCTION_STRIP_TRAY_W = 48, ///< the tray, at the size that bar draws it - never stretched+ PRODUCTION_STRIP_TRAY_H = 41,+ PRODUCTION_STRIP_TRAY_X = 1, ///< where the cameo sits inside it+ PRODUCTION_STRIP_TRAY_Y = 7,+ PRODUCTION_STRIP_QUEUE_W = 39, ///< and how big it is there+ PRODUCTION_STRIP_QUEUE_H = 27,+ PRODUCTION_STRIP_TRAY_OVER = 6, ///< that bar steps 35 between 41-tall slots: its trays overlap+ /// by six, and ours overlap by the same six on both axes+ PRODUCTION_STRIP_BAR_STEP = 35 ///< the step itself, kept so the overlap can be checked against it+ };++ ///< how far one row of trays stands below the row above it, for a tray of that height+ static Int stripRowStep( Int trayHeight );++ ///< does an item go in front of one already in the row? the selected building's items are a+ ///< block of their own at the head of it; inside a block, soonest finished first, ties keeping+ ///< the order they were met in so a base of identical barracks does not shuffle frame to frame+ static Bool stripSlotGoesBefore( Bool leads, Int remaining,+ Bool otherLeads, Int otherRemaining );struct ProductionStripSlot{ObjectID producer; ///< the building this item is queued onInt id; ///< a unit's ProductionID, or an upgrade's name key/// (kept as an Int so this header stays clear of GameLogic)Bool isUpgrade; ///< which of those two the id means+ Bool isStructure; ///< the slot is a building going up on the map, not an item in+ /// a queue: 'producer' is that building and there is no id+ Bool leads; ///< it belongs to the building you have selected, so it stands at the+ /// head of the row whatever the rest of the base is finishingInt remaining; ///< logic frames until this item pops, waiting time ahead of it includedICoord2D pos; ///< top left corner of the cameo on screen};@@ -920,7 +964,8 @@ protected:void updateIncomeEstimate( Player *player ); ///< income per minute, shown beside the moneyvoid drawProductionStrip( void ); ///< the production queue rows above the control barvoid drawProductionStripRow( Int row, Int y ); ///< one of those rows, at that top edge- void updateStripCameoSize( void ); ///< cameo box both strips draw into, in the command bar's aspect+ const Image *productionStripTray( void ); ///< the power bar's tray, mirrored, kept until that bar changes side+ void stripTrayMetrics( ICoord2D *tray, ICoord2D *cameo, ICoord2D *hole, Int *step ); ///< that tray's size, its cameo hole, and the column stepvoid drawStripSeconds( Int x, Int y, Int w, Int h, Int seconds, Bool plainSeconds = FALSE ); ///< countdown written inside a cameovoid addSuperweaponIcon( const Image *image, Int seconds, Int percent, Bool ready, Color color );void drawSuperweaponStrip( void ); ///< those icons, top right, soonest at the right hand end@@ -968,6 +1013,8 @@ protected:Bool m_productionStripWatching; ///< the rows are every player's, not oursInt m_productionStripCameoW; ///< cameo size this frame, in the control bar's aspectInt m_productionStripCameoH;+ Image * m_productionStripTray; ///< our mirrored copy of the power bar's tray+ const Image * m_productionStripTraySource; ///< the tray it was made from, so a side change remakes itDisplayString * m_productionStripOverflow; ///< the "+N" that stands for the rest of a rowDisplayString * m_stripSecondsString; ///< the countdown written inside a cameo, either strip'sdiff --git a/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/ControlBar/ControlBar.cpp b/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/ControlBar/ControlBar.cppindex 0d7ba8141..6c84af3bc 100644--- a/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/ControlBar/ControlBar.cpp+++ b/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/ControlBar/ControlBar.cpp@@ -2658,6 +2658,88 @@ Bool ControlBar::clearSpecialPowerShortcutRow( void )} // end clearSpecialPowerShortcutRow+//-------------------------------------------------------------------------------------------------+/** The tray a general's power shortcut stands in: the background of one of that bar's slots, taken+ * off the slot itself. Each side ships its own bar and its own tray art, so reading it here is+ * what keeps anything that borrows the look - the production strip does - on the right side's+ * metal without naming a single image.+ *+ * NULL until that bar exists, and it never exists for a side whose template has no shortcuts. */+//-------------------------------------------------------------------------------------------------+const Image *ControlBar::getSpecialPowerTrayImage( void )+{+ if( m_specialPowerShortcutParent == NULL || m_specialPowerShortcutButtonParents[ 0 ] == NULL )+ return NULL;++ return m_specialPowerShortcutButtonParents[ 0 ]->winGetEnabledImage( 0 );++} // end getSpecialPowerTrayImage++//-------------------------------------------------------------------------------------------------+/** That tray at the size the bar itself draws it, the hole in its artwork the cameo fills, and the+ * step a row of them runs at. All of it read back off the loaded bar, which the loader has+ * already scaled to the running resolution - so nothing here is in 800x600 pixels, and anything+ * borrowing the look comes out the size of the powers themselves at every resolution.+ *+ * Any of the four out-parameters may be NULL. FALSE when there is no bar to measure. */+//-------------------------------------------------------------------------------------------------+Bool ControlBar::getSpecialPowerTrayLayout( ICoord2D *traySize, ICoord2D *cameoSize,+ ICoord2D *cameoOffset, Int *columnStep )+{+ if( m_specialPowerShortcutParent == NULL || m_specialPowerShortcutButtonParents[ 0 ] == NULL )+ return FALSE;++ Int slotWidth, slotHeight;+ m_specialPowerShortcutButtonParents[ 0 ]->winGetSize( &slotWidth, &slotHeight );+ if( slotWidth <= 0 || slotHeight <= 0 )+ return FALSE;++ //+ // where the cameo goes is the hole in the tray artwork, not a guess: SATraySmall is the 60x56+ // patch at 413,1 of SAControlBar512_001.tga and its transparent middle runs x 4..48, y 9..46.+ // Those are fractions of the art, so they hold at whatever size the loader gave the tray+ //+ const Int ART_WIDTH = 60;+ const Int ART_HEIGHT = 56;+ const Int HOLE_X = 4;+ const Int HOLE_Y = 9;+ const Int HOLE_WIDTH = 45;+ const Int HOLE_HEIGHT = 38;++ //+ // the tray's right edge is the thick one - eleven of the artwork's sixty columns. A row set+ // side by side shows that slab between every pair of cameos, so each slot after the rightmost+ // slides eight (of the tray's authored forty-eight) back under its neighbour, and the rightmost+ // is drawn last so it covers the slab rather than being covered by it+ //+ const Int TRAY_WIDTH = 48;+ const Int OVERLAP = 8;++ if( traySize )+ {+ traySize->x = slotWidth;+ traySize->y = slotHeight;+ }++ if( cameoSize )+ {+ cameoSize->x = ( slotWidth * HOLE_WIDTH + ART_WIDTH / 2 ) / ART_WIDTH;+ cameoSize->y = ( slotHeight * HOLE_HEIGHT + ART_HEIGHT / 2 ) / ART_HEIGHT;+ }++ if( cameoOffset )+ {+ cameoOffset->x = ( slotWidth * HOLE_X + ART_WIDTH / 2 ) / ART_WIDTH;+ cameoOffset->y = ( slotHeight * HOLE_Y + ART_HEIGHT / 2 ) / ART_HEIGHT;+ }++ if( columnStep )+ *columnStep = slotWidth - ( slotWidth * OVERLAP ) / TRAY_WIDTH;++ return TRUE;++} // end getSpecialPowerTrayLayout+//-------------------------------------------------------------------------------------------------/** How many of the slots carry a power right now. populateSpecialPowerShortcut() fills them from* the corner and hides the rest, so the ones in use are always the first n - and n is not@@ -4279,27 +4361,10 @@ void ControlBar::arrangeSpecialPowerShortcutGrid( void )if( rowStep <= 0 || slotWidth <= 0 || slotHeight <= 0 )return;- //- // where the cameo goes is the hole in the tray artwork, not a guess: SATraySmall is the 60x56- // patch at 413,1 of SAControlBar512_001.tga and its transparent middle runs x 4..48, y 9..46.- // Those are fractions of the art, so they hold at whatever size the loader gave the tray- //- const Int ART_WIDTH = 60;- const Int ART_HEIGHT = 56;- const Int HOLE_X = 4;- const Int HOLE_Y = 9;- const Int HOLE_WIDTH = 45;- const Int HOLE_HEIGHT = 38;-- //- // the tray's right edge is the thick one - eleven of the artwork's sixty columns. A row set- // side by side shows that slab between every pair of cameos, so each slot after the rightmost- // slides eight (of the tray's authored forty-eight) back under its neighbour, and the rightmost- // is drawn last so it covers the slab rather than being covered by it- //- const Int TRAY_WIDTH = 48;- const Int OVERLAP = 8;- const Int columnStep = slotWidth - ( slotWidth * OVERLAP ) / TRAY_WIDTH;+ ICoord2D cameoSize, cameoOffset;+ Int columnStep;+ if( getSpecialPowerTrayLayout( NULL, &cameoSize, &cameoOffset, &columnStep ) == FALSE )+ return;const Int columns = MIN( m_currentlyUsedSpecialPowersButtons, (Int)SPECIAL_POWER_SHORTCUT_COLS );const Int widen = ( columns - 1 ) * columnStep;@@ -4335,10 +4400,8 @@ void ControlBar::arrangeSpecialPowerShortcutGrid( void )// the cameo fills that hole exactly, rounded to the nearest pixel. The layout put it at// 1,7 39x27, which sat over the frame on the left and left a gap under it//- button->winSetSize( ( slotWidth * HOLE_WIDTH + ART_WIDTH / 2 ) / ART_WIDTH,- ( slotHeight * HOLE_HEIGHT + ART_HEIGHT / 2 ) / ART_HEIGHT );- button->winSetPosition( ( slotWidth * HOLE_X + ART_WIDTH / 2 ) / ART_WIDTH,- ( slotHeight * HOLE_Y + ART_HEIGHT / 2 ) / ART_HEIGHT );+ button->winSetSize( cameoSize.x, cameoSize.y );+ button->winSetPosition( cameoOffset.x, cameoOffset.y );}//diff --git a/GeneralsMD/Code/GameEngine/Source/GameClient/InGameUI.cpp b/GeneralsMD/Code/GameEngine/Source/GameClient/InGameUI.cppindex c8796de9e..e403494f8 100644--- a/GeneralsMD/Code/GameEngine/Source/GameClient/InGameUI.cpp+++ b/GeneralsMD/Code/GameEngine/Source/GameClient/InGameUI.cpp@@ -62,6 +62,7 @@#include "GameClient/GameWindowGlobal.h"#include "GameClient/GameWindowID.h"#include "GameClient/GUICallbacks.h"+#include "GameClient/Image.h"#include "GameClient/InGameUI.h"#include "GameClient/VideoPlayer.h"#include "GameClient/Mouse.h"@@ -110,7 +111,10 @@ static const RGBColor illegalBuildColor = { 1.0, 0.0, 0.0 };// ------------------------------------------------------------------------------------------------enum{- PRODUCTION_STRIP_CAMEO = 16, ///< nominal cameo edge in pixels; the real one keeps this area+ PRODUCTION_STRIP_CAMEO = 16, ///< a cameo edge to hit-test against before the first draw has+ /// measured the real one off the general's power bar+ /// (the tray a queue cameo stands in is up in InGameUI.h)+PRODUCTION_STRIP_GAP = 2, ///< space between cameos, and between the two rowsPRODUCTION_STRIP_LEFT = 8, ///< inset from the left edge of the screenPRODUCTION_STRIP_LIFT = 24, ///< clearance above the control bar@@ -1146,6 +1150,8 @@ InGameUI::InGameUI()m_productionStripWatching = FALSE;m_productionStripCameoW = PRODUCTION_STRIP_CAMEO;m_productionStripCameoH = PRODUCTION_STRIP_CAMEO;+ m_productionStripTray = NULL;+ m_productionStripTraySource = NULL;m_productionStripOverflow = NULL;m_stripSecondsString = NULL;m_superweaponIconCount = 0;@@ -1242,6 +1248,14 @@ InGameUI::~InGameUI()// clear world animationsclearWorldAnimations();resetIdleWorker();++ // our own mirrored copy of the power bar's tray - the bar keeps the original+ if( m_productionStripTray )+ {+ m_productionStripTray->deleteInstance();+ m_productionStripTray = NULL;+ m_productionStripTraySource = NULL;+ }}//-------------------------------------------------------------------------------------------------@@ -5926,10 +5940,15 @@ void InGameUI::drawHudOverlay( void )* time. Only the head of a queue carries progress, so this is what separates "arrives next" from* "arrives eventually" across a whole base's worth of buildings. A quantity modifier (the China* barracks' Red Guard pairs) does not multiply the wait - the entry overbuilds in place and all- * of its units pop in the same handful of frames. */+ * of its units pop in the same handful of frames.+ *+ * 'leads' marks the building you have selected: its items go to the head of the row ahead of+ * everything else, sorted among themselves the same way. The building you are looking at is the+ * one you want to read, and hunting its cameos out of the whole base's queue by their border was+ * the job a second row used to do badly. *///-------------------------------------------------------------------------------------------------static void appendProducerQueue( Object *obj, InGameUI::ProductionStripSlot *slots,- Int *count, Int max, Int *total )+ Int *count, Int max, Int *total, Bool leads ){if( obj == NULL )return;@@ -5981,10 +6000,14 @@ static void appendProducerQueue( Object *obj, InGameUI::ProductionStripSlot *slo//// walk back over the items that finish later than this one and drop it in front of them.// Ties keep the order they were met in, so a base full of identical barracks stays put- // instead of shuffling frame to frame.+ // instead of shuffling frame to frame. The selected building's items are a block of their+ // own at the head of the row: one of them passes everything that is not one of them, and+ // nothing else ever passes one.//Int at = *count;- while( at > 0 && slots[ at - 1 ].remaining > remaining )+ while( at > 0 && InGameUI::stripSlotGoesBefore( leads, remaining,+ slots[ at - 1 ].leads,+ slots[ at - 1 ].remaining ) )at--;if( at >= max )@@ -6000,12 +6023,73 @@ static void appendProducerQueue( Object *obj, InGameUI::ProductionStripSlot *sloslot->producer = obj->getID();slot->id = id;slot->isUpgrade = isUpgrade;+ slot->isStructure = FALSE;+ slot->leads = leads;slot->remaining = remaining;slot->pos.x = 0;slot->pos.y = 0;}}+//-------------------------------------------------------------------------------------------------+/** A building going up on the map, for the row above the queue.+ *+ * A factory's queue is the only production this strip used to know about, and a base spends half+ * its early game on the other kind: what a dozer or a worker is putting up is nowhere in a queue,+ * it is an object on the ground with a construction percentage on it. So it gets its own row,+ * sorted the same way - soonest finished first - and a click on one takes the camera to the site,+ * which is the question a half-built base actually raises: where is it. */+//-------------------------------------------------------------------------------------------------+static void appendStructureUnderConstruction( Object *obj, InGameUI::ProductionStripSlot *slots,+ Int *count, Int max, Int *total )+{+ if( obj == NULL || !obj->testStatus( OBJECT_STATUS_UNDER_CONSTRUCTION ) )+ return;++ //+ // A rebuild hole wears the same status while it puts a GLA structure back up, and it has no+ // cameo of its own to draw - it would come through as an empty box that jumps the camera.+ //+ if( obj->isKindOf( KINDOF_REBUILD_HOLE ) || obj->getTemplate() == NULL+ || obj->getTemplate()->getButtonImage() == NULL )+ return;++ const Real percent = obj->getConstructionPercent();+ const Int buildFrames = obj->getTemplate()->calcTimeToBuild( obj->getControllingPlayer() );++ Int remaining = REAL_TO_INT( buildFrames * ( 1.0f - percent / 100.0f ) );+ if( remaining < 0 )+ remaining = 0;++ (*total)++;++ // soonest first, ties in the order they were met - the same order the queue row is kept in+ Int at = *count;+ while( at > 0 && InGameUI::stripSlotGoesBefore( FALSE, remaining,+ slots[ at - 1 ].leads,+ slots[ at - 1 ].remaining ) )+ at--;++ if( at >= max )+ return;++ if( *count < max )+ (*count)++;++ for( Int j = *count - 1; j > at; j-- )+ slots[ j ] = slots[ j - 1 ];++ InGameUI::ProductionStripSlot *slot = &slots[ at ];+ slot->producer = obj->getID();+ slot->id = 0;+ slot->isUpgrade = FALSE;+ slot->isStructure = TRUE;+ slot->leads = FALSE;+ slot->remaining = remaining;+ slot->pos.x = 0;+ slot->pos.y = 0;+}+//-------------------------------------------------------------------------------------------------/** Player::iterateObjects callback for the global row. *///-------------------------------------------------------------------------------------------------@@ -6015,12 +6099,25 @@ struct ProductionStripGatherInt *count;Int *total;Int max; ///< cameos this row will draw; the rest are counted into the "+N"+ ObjectID skip; ///< a building already put into the row ahead of the sweep, so it is not+ /// gathered a second time when the sweep reaches it};static void gatherProductionStrip( Object *obj, void *userData ){ProductionStripGather *g = (ProductionStripGather *)userData;- appendProducerQueue( obj, g->slot, g->count, g->max, g->total );+ if( obj && obj->getID() == g->skip )+ return;+ appendProducerQueue( obj, g->slot, g->count, g->max, g->total, FALSE );+}++//-------------------------------------------------------------------------------------------------+/** Player::iterateObjects callback for the row of buildings going up. */+//-------------------------------------------------------------------------------------------------+static void gatherStripStructures( Object *obj, void *userData )+{+ ProductionStripGather *g = (ProductionStripGather *)userData;+ appendStructureUnderConstruction( obj, g->slot, g->count, g->max, g->total );}//-------------------------------------------------------------------------------------------------@@ -6049,32 +6146,84 @@ static const ProductionEntry *findStripEntry( ProductionUpdateInterface *pu,}//--------------------------------------------------------------------------------------------------/** The cameo box both strips draw into.+/** The tray a queue cameo stands in: the general's power bar's own, this side's copy of it, turned+ * back to front. That bar grows leftward out of the corner and its tray's heavy rail is on the+ * right hand edge, where in a row running rightward from the left of the screen it would stand+ * between every pair of cameos; mirrored, the rail leads the row and the trays close up behind+ * it.*- * The same cameo art the command bar draws is not square, so drawing it into a square box- * squashed it and the strip read as a different set of icons than the bar right below it. Take- * the aspect from a real command button and keep the box's area at the nominal size, so a row- * stays as long as it was: a wider cameo is a correspondingly shorter one. */+ * Kept until the bar hands back a different tray - a side change, a mod's own bar - rather than+ * rebuilt per cameo per frame. NULL for a side whose template ships no shortcut bar. *///--------------------------------------------------------------------------------------------------void InGameUI::updateStripCameoSize( void )+const Image *InGameUI::productionStripTray( void ){- m_productionStripCameoW = stripPixels( PRODUCTION_STRIP_CAMEO );- m_productionStripCameoH = stripPixels( PRODUCTION_STRIP_CAMEO );+ const Image *source = TheControlBar ? TheControlBar->getSpecialPowerTrayImage() : NULL;- static NameKeyType commandButtonKey = TheNameKeyGenerator->nameToKey( "ControlBar.wnd:ButtonCommand01" );- GameWindow *commandButton = TheWindowManager->winGetWindowFromId( NULL, commandButtonKey );- if( commandButton == NULL )- return;+ if( source != m_productionStripTraySource )+ {+ if( m_productionStripTray )+ {+ m_productionStripTray->deleteInstance();+ m_productionStripTray = NULL;+ }++ if( source )+ m_productionStripTray = newMirroredImage( source );++ m_productionStripTraySource = source;+ }- ICoord2D buttonSize;- commandButton->winGetSize( &buttonSize.x, &buttonSize.y );- if( buttonSize.x <= 0 || buttonSize.y <= 0 )+ return m_productionStripTray;+}++//-------------------------------------------------------------------------------------------------+/** How big a strip slot is and where the cameo sits in it - the general's power bar's own numbers,+ * at the size the loader gave that bar, so a slot here is a slot there at any resolution. 'hole'+ * is the inset the bar itself uses, measured from the tray's left edge; a strip that draws the+ * tray mirrored turns it round itself.+ *+ * Falls back to the 800x600 numbers that bar was authored with when there is no bar to measure -+ * a side whose template ships no shortcuts still gets a strip. */+//-------------------------------------------------------------------------------------------------+void InGameUI::stripTrayMetrics( ICoord2D *tray, ICoord2D *cameo, ICoord2D *hole, Int *step )+{+ if( TheControlBar+ && TheControlBar->getSpecialPowerTrayLayout( tray, cameo, hole, step ) )return;- const Real aspect = INT_TO_REAL( buttonSize.x ) / INT_TO_REAL( buttonSize.y );- 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 );+ tray->x = stripPixels( PRODUCTION_STRIP_TRAY_W );+ tray->y = stripPixels( PRODUCTION_STRIP_TRAY_H );+ cameo->x = stripPixels( PRODUCTION_STRIP_QUEUE_W );+ cameo->y = stripPixels( PRODUCTION_STRIP_QUEUE_H );+ hole->x = stripPixels( PRODUCTION_STRIP_TRAY_X );+ hole->y = stripPixels( PRODUCTION_STRIP_TRAY_Y );+ *step = tray->x - stripPixels( PRODUCTION_STRIP_TRAY_OVER );+}++//-------------------------------------------------------------------------------------------------+/** Where an item goes in a row: the selected building's items are one block at the head of it, and+ * inside a block the soonest to finish comes first. Every row of the strip is kept in this order+ * as it is filled, so the front of the row is always the next thing to arrive out of the building+ * you are looking at, and the row behind it is the rest of the base. */+//-------------------------------------------------------------------------------------------------+Bool InGameUI::stripSlotGoesBefore( Bool leads, Int remaining,+ Bool otherLeads, Int otherRemaining )+{+ if( leads != otherLeads )+ return leads; // the selected building's block leads, whatever anything finishes in++ return otherRemaining > remaining; // inside a block: soonest first, ties stay as they were met+}++//-------------------------------------------------------------------------------------------------+/** How far one row of trays stands below the row above it: a tray less the overlap that bar keeps+ * between its own stacked slots, taken as a fraction of the tray so it holds at any size. */+//-------------------------------------------------------------------------------------------------+Int InGameUI::stripRowStep( Int trayHeight )+{+ return trayHeight+ - ( trayHeight * (Int)PRODUCTION_STRIP_TRAY_OVER )+ / (Int)PRODUCTION_STRIP_TRAY_H;}//-------------------------------------------------------------------------------------------------@@ -6156,10 +6305,22 @@ void InGameUI::drawSuperweaponStrip( void )if( TheGameLogic == NULL || !TheGameLogic->isInGame() || TheGameLogic->isInShellGame() )return;- updateStripCameoSize();+ //+ // The same tray the production strip stands its cameos in, and the same measurements off the+ // general's power bar - but this strip is not mirrored. It is anchored to the right hand edge+ // and grows leftwards, which is the direction that bar itself grows, so the artwork sits the+ // way it was drawn: the heavy rail leads the row at the right hand end.+ //+ ICoord2D traySize, cameoSize, trayHole;+ Int trayStep = 0;+ stripTrayMetrics( &traySize, &cameoSize, &trayHole, &trayStep );++ const Int trayW = traySize.x;+ const Int trayH = traySize.y;+ const Int cameoW = cameoSize.x;+ const Int cameoH = cameoSize.y;+ const Image *tray = TheControlBar ? TheControlBar->getSpecialPowerTrayImage() : NULL;- const Int cameoW = m_productionStripCameoW;- const Int cameoH = m_productionStripCameoH;const Int gap = stripPixels( PRODUCTION_STRIP_GAP );const Int edge = stripPixels( PRODUCTION_STRIP_LEFT );const Int more = stripPixels( PRODUCTION_STRIP_MORE );@@ -6200,21 +6361,32 @@ void InGameUI::drawSuperweaponStrip( void )inRow = SUPERWEAPON_STRIP_COLS;const Bool lastRow = ( first + inRow >= m_superweaponIconCount );- Int rowWidth = inRow * cameoW + ( inRow - 1 ) * gap;+ Int rowWidth = ( inRow - 1 ) * trayStep + trayW;if( hidden > 0 && lastRow )rowWidth += gap + more;- const Int y = top + row * ( cameoH + gap );+ const Int trayY = top + row * stripRowStep( trayH );+ const Int y = trayY + trayHole.y;- // one plate behind the row, so the cameos read over any terrain- TheDisplay->drawFillRect( right - rowWidth - plate, y - plate,- rowWidth + 2 * plate, cameoH + 2 * plate,- GameMakeColor( 0, 0, 0, 130 ) );+ //+ // The trays go down first, all of them, and from the far end back: each tray's heavy rail+ // is on its right, and it takes the tray to its right drawn on top of it to cover that+ // rail. The rightmost is drawn last, and its rail is the one that closes the row against+ // the edge of the screen.+ //+ for( Int back = inRow - 1; back >= 0; back-- )+ {+ const Int backX = right - trayW - back * trayStep;+ if( tray )+ TheDisplay->drawImage( tray, backX, trayY, backX + trayW, trayY + trayH );+ else+ TheDisplay->drawFillRect( backX, trayY, trayW, trayH, GameMakeColor( 0, 0, 0, 130 ) );+ }for( Int i = 0; i < inRow; i++ ){const SuperweaponIconSlot *slot = &m_superweaponIcons[ first + i ];- const Int x = right - cameoW - i * ( cameoW + gap );+ const Int x = right - trayW + trayHole.x - i * trayStep;if( slot->image )TheDisplay->drawImage( slot->image, x, y, x + cameoW, y + cameoH );@@ -6291,34 +6463,92 @@ void InGameUI::drawProductionStripRow( Int row, Int y )if( count < 1 )return;- 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 ) * gap;- if( hidden > 0 )- rowWidth += gap + more;+ //+ // Every cameo stands in its own tray - the one the general's powers stand in, in the bottom+ // corner, and this side's own copy of it, read straight off that bar. Every measurement comes+ // off that bar too, at the size the loader gave it: a tray here is the size of a tray there at+ // any resolution, and it is never squeezed to fit anything - squeezed, its rail and its inner+ // frame collapse into a coloured smudge and none of it reads as that bar any more.+ //+ // Trays overlap by what that bar overlaps its own by, so a row of them is one run of metal+ // rather than a line of separate boxes, and the row is flush against the left edge of the screen.+ //+ ICoord2D traySize, cameoSize, trayHole;+ Int trayStep = 0;+ stripTrayMetrics( &traySize, &cameoSize, &trayHole, &trayStep );++ const Int trayW = traySize.x;+ const Int trayH = traySize.y;+ const Int cameoW = cameoSize.x;+ const Int cameoH = cameoSize.y;+ // the tray is drawn mirrored, so its hole is mirrored with it: what that bar measures in from+ // the left is the same distance in from the right here+ const Int trayInsetX = trayW - trayHole.x - cameoW;+ const Int trayInsetY = trayHole.y;+ const Int trayY = y - trayInsetY;++ const Image *tray = productionStripTray();- // one plate behind the row, so the cameos read over any terrain- TheDisplay->drawFillRect( left - plate, y - plate, rowWidth + 2 * plate, cameoH + 2 * plate,- GameMakeColor( 0, 0, 0, 130 ) );+ //+ // The trays go down first, all of them, and from the far end back: the artwork is mirrored, so+ // each tray's heavy rail is on its left, and it takes the tray to its left drawn on top of it to+ // cover that rail. Drawn the other way round the row shows a slab of metal between every pair of+ // cameos. The leftmost is drawn last and its rail is the one that leads the row.+ //+ // Without the art - a mod that ships no shortcut bar - a slot keeps the flat plate it used to+ // have rather than losing its backing.+ //+ for( Int back = count - 1; back >= 0; back-- )+ {+ const Int backX = back * trayStep;+ if( tray )+ TheDisplay->drawImage( tray, backX, trayY, backX + trayW, trayY + trayH );+ else+ TheDisplay->drawFillRect( backX, trayY, trayW, trayH, GameMakeColor( 0, 0, 0, 130 ) );+ }++ const Int hidden = m_productionStripTotal[ row ] - count;- Int x = left;+ Int trayX = 0;+ Int x = trayX + trayInsetX;for( Int i = 0; i < count; i++ ){ProductionStripSlot *slot = &m_productionStrip[ row ][ i ];+ x = trayX + trayInsetX;slot->pos.x = x;slot->pos.y = y;Object *producer = TheGameLogic->findObjectByID( slot->producer );ProductionUpdateInterface *pu = producer ? producer->getProductionUpdateInterface() : NULL;- const ProductionEntry *entry = findStripEntry( pu, slot );+ const ProductionEntry *entry = slot->isStructure ? NULL : findStripEntry( pu, slot );- if( entry )+ if( slot->isStructure && producer )+ {+ //+ // A building going up carries its own progress rather than a queue entry's: the same+ // sweep and the same countdown, read off the construction percentage on the object.+ //+ const Image *cameo = producer->getTemplate()->getButtonImage();+ if( cameo )+ TheDisplay->drawImage( cameo, x, y, x + cameoW, y + cameoH );++ const Real done = producer->getConstructionPercent();+ TheDisplay->drawRemainingRectClock( x, y, cameoW, cameoH,+ REAL_TO_INT( done ), GameMakeColor( 0, 0, 0, 100 ) );++ const Int totalFrames =+ producer->getTemplate()->calcTimeToBuild( producer->getControllingPlayer() );+ if( totalFrames > 0 )+ {+ const Real left = totalFrames * ( 1.0f - done / 100.0f );+ drawStripSeconds( x, y, cameoW, cameoH,+ ControlBar_secondsFromFrames( left > 0.0f ? left : 0.0f ) );+ }+ }+ else if( entry ){const Image *cameo = NULL;if( slot->isUpgrade )@@ -6376,8 +6606,10 @@ void InGameUI::drawProductionStripRow( Int row, Int y )// so: it goes red and wears a minus. Without it a ctrl-click is a guess about which cameo// the cursor is really on, and an accidental cancel costs the whole item.//+ // a building already standing on the map is not cancelled from here - it is sold or blown upBool cancelHover = FALSE;- if( !m_productionStripWatching && TheKeyboard && TheKeyboard->isCtrl() && TheMouse )+ if( !m_productionStripWatching && !slot->isStructure+ && TheKeyboard && TheKeyboard->isCtrl() && TheMouse ){const MouseIO *io = TheMouse->getMouseStatus();cancelHover = io && io->pos.x >= x && io->pos.x < x + cameoW &&@@ -6416,9 +6648,11 @@ void InGameUI::drawProductionStripRow( Int row, Int y )GameMakeColor( 255, 255, 255, 255 ) );}- x += cameoW + gap;+ trayX += trayStep;}+ x = trayX + gap;+//// whatever did not fit closes the row as a "+N". It is not clickable: there is no one item// behind it, and the row it stands for is already reachable by selecting the building.@@ -6487,6 +6721,7 @@ void InGameUI::drawProductionStrip( void )watch.total = &m_productionStripTotal[ row ];// eight rows are on screen at once here, so each one is the five soonest and a "+N"watch.max = PRODUCTION_STRIP_WATCH_MAX;+ watch.skip = INVALID_ID; // nothing is selected in somebody else's basep->iterateObjects( gatherProductionStrip, &watch );if( m_productionStripCount[ row ] > 0 )@@ -6498,30 +6733,59 @@ void InGameUI::drawProductionStrip( void )}else{- ProductionStripGather gather;- gather.slot = m_productionStrip[ 0 ];- gather.count = &m_productionStripCount[ 0 ];- gather.total = &m_productionStripTotal[ 0 ];- gather.max = PRODUCTION_STRIP_ROW_MAX;- player->iterateObjects( gatherProductionStrip, &gather );+ //+ // the buildings going up take the top row, above everything a factory is turning out: they+ // are the slower half of what a base is doing and the half that has a place on the map, so+ // they read as the row you look up rather than the row you scan+ //+ ProductionStripGather sites;+ sites.slot = m_productionStrip[ PRODUCTION_ROW_SITES ];+ sites.count = &m_productionStripCount[ PRODUCTION_ROW_SITES ];+ sites.total = &m_productionStripTotal[ PRODUCTION_ROW_SITES ];+ sites.max = PRODUCTION_STRIP_ROW_MAX;+ sites.skip = INVALID_ID;+ player->iterateObjects( gatherStripStructures, &sites );//- // a single selected producer gets its own row underneath, so the building you are looking at- // is readable without picking its items out of the whole base's queue+ // A single selected producer leads the queue row rather than getting a row of its own: what+ // the building you are looking at is making is the front of the strip, and the rest of the+ // base follows it. It goes in before the sweep over everything else, and the sweep skips it,+ // so nothing is drawn or counted twice.//+ ObjectID selected = INVALID_ID;if( getSelectCount() == 1 && !m_selectedDrawables.empty() ){Object *sel = m_selectedDrawables.front()->getObject();if( sel && sel->getControllingPlayer() == player )- appendProducerQueue( sel, m_productionStrip[ 1 ], &m_productionStripCount[ 1 ],- PRODUCTION_STRIP_ROW_MAX, &m_productionStripTotal[ 1 ] );+ {+ selected = sel->getID();+ appendProducerQueue( sel, m_productionStrip[ PRODUCTION_ROW_QUEUE ],+ &m_productionStripCount[ PRODUCTION_ROW_QUEUE ],+ PRODUCTION_STRIP_ROW_MAX,+ &m_productionStripTotal[ PRODUCTION_ROW_QUEUE ],+ TRUE );+ }}++ ProductionStripGather gather;+ gather.slot = m_productionStrip[ PRODUCTION_ROW_QUEUE ];+ gather.count = &m_productionStripCount[ PRODUCTION_ROW_QUEUE ];+ gather.total = &m_productionStripTotal[ PRODUCTION_ROW_QUEUE ];+ gather.max = PRODUCTION_STRIP_ROW_MAX;+ gather.skip = selected;+ player->iterateObjects( gatherProductionStrip, &gather );}+ //+ // The rows in use are closed up before they are placed: the sites row is empty for most of a+ // match, and leaving the space it would have taken puts a band of nothing between the queue and+ // the control bar.+ //+ Int used[ PRODUCTION_STRIP_ROWS ];Int rowsUsed = 0;for( Int row = 0; row < PRODUCTION_STRIP_ROWS; row++ )if( m_productionStripCount[ row ] > 0 )- rowsUsed = row + 1;+ used[ rowsUsed++ ] = row;if( rowsUsed == 0 )return;@@ -6540,7 +6804,17 @@ void InGameUI::drawProductionStrip( void )barTop = barPos.y;}- updateStripCameoSize();+ //+ // A queue cameo is one cameo of the general's power bar, to the pixel: the row is built out of+ // that bar's own trays, so the pictures standing in them are the size of the pictures standing+ // in it.+ //+ ICoord2D traySize, cameoSize, trayHole;+ Int trayStep = 0;+ stripTrayMetrics( &traySize, &cameoSize, &trayHole, &trayStep );++ m_productionStripCameoW = cameoSize.x;+ m_productionStripCameoH = cameoSize.y;//// rows stack upwards from just above the control bar, last row nearest the bar: playing, that@@ -6548,15 +6822,21 @@ 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 - stripPixels( PRODUCTION_STRIP_LIFT );- const Int rowStep = m_productionStripCameoH + stripPixels( PRODUCTION_STRIP_GAP );+ // A row is as tall as a tray, not as tall as a cameo, and rows overlap by the six that bar+ // overlaps its own slots by - which is exactly its 35 pixel step between 41 pixel slots, taken+ // as a fraction of the tray so it holds at whatever size that bar was loaded at.+ //+ const Int trayTop = trayHole.y;+ const Int trayBelow = traySize.y - trayHole.y;+ const Int lowerY = barTop - trayBelow - stripPixels( PRODUCTION_STRIP_LIFT );+ const Int rowStep = stripRowStep( traySize.y );- for( Int row = rowsUsed - 1; row >= 0; row-- )+ for( Int at = rowsUsed - 1; at >= 0; at-- ){- const Int y = lowerY - ( rowsUsed - 1 - row ) * rowStep;- if( y < 0 )+ const Int y = lowerY - ( rowsUsed - 1 - at ) * rowStep;+ if( y - trayTop < 0 )break;- drawProductionStripRow( row, y );+ drawProductionStripRow( used[ at ], y );}}@@ -6580,7 +6860,7 @@ Bool InGameUI::handleProductionStripClick( const ICoord2D *mouse, Bool cancel )if( producer == NULL )return TRUE; // the building died under the cursor - the click is still ours- if( cancel && producer->isLocallyControlled() )+ if( cancel && !slot->isStructure && producer->isLocallyControlled() ){//// the producer travels with the message: the strip cancels on buildings that are notdiff --git a/GeneralsMD/Code/GameEngine/Source/GameClient/System/Image.cpp b/GeneralsMD/Code/GameEngine/Source/GameClient/System/Image.cppindex 99cd8239e..8b2cd3c81 100644--- a/GeneralsMD/Code/GameEngine/Source/GameClient/System/Image.cpp+++ b/GeneralsMD/Code/GameEngine/Source/GameClient/System/Image.cpp@@ -190,6 +190,36 @@ UnsignedInt Image::clearStatus( UnsignedInt bit )} // end clearStatus+//-------------------------------------------------------------------------------------------------+/** The same piece of texture, drawn back to front. Only the run of the UV rect is reversed - the+ * page underneath is untouched and shared - so a mirrored copy costs one small object and the+ * original goes on being drawn by whoever owns it. */+//-------------------------------------------------------------------------------------------------+Image *newMirroredImage( const Image *source )+{+ Image *copy = newInstance( Image );++ copy->setName( source->getName() );+ copy->setFilename( source->getFilename() );+ copy->setTextureWidth( source->getTextureSize()->x );+ copy->setTextureHeight( source->getTextureSize()->y );++ ICoord2D size = *source->getImageSize();+ copy->setImageSize( &size );++ copy->setRawTextureData( (void *)source->getRawTextureData() );+ copy->setStatus( source->getStatus() );++ Region2D uv = *source->getUV();+ const Real left = uv.lo.x;+ uv.lo.x = uv.hi.x;+ uv.hi.x = left;+ copy->setUV( &uv );++ return copy;++} // end newMirroredImage+/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////diff --git a/GeneralsMD/Code/Tests/test_gameengine.cpp b/GeneralsMD/Code/Tests/test_gameengine.cppindex 48ed1c087..52cd39bf1 100644--- a/GeneralsMD/Code/Tests/test_gameengine.cpp+++ b/GeneralsMD/Code/Tests/test_gameengine.cpp@@ -55,6 +55,7 @@#include "Common/Recorder.h"#include "Common/RadarShroudCache.h"#include "GameClient/Gadget.h"+#include "GameClient/Image.h"#include "GameNetwork/NetworkUtil.h"#include "GameNetwork/NetCommandList.h"#include "GameNetwork/NetCommandWrapperList.h"@@ -6885,3 +6886,168 @@ TEST(every_ai_rung_is_named_the_same_way_as_every_other)for (Int b = a + 1; b < numRungs; ++b)CHECK( wcscmp( SlotStateName( rungs[a] ).str(), SlotStateName( rungs[b] ).str() ) != 0 );}+/* Six is what the strip shows before the rest of the queue folds into its "+N". It used to be+ sixteen, which at a busy war factory ran the cameos most of the way across the screen and buried+ the map under them. */+TEST(the_production_strip_folds_a_long_queue_into_its_overflow)+{+ CHECK_EQ( 6, (Int)InGameUI::PRODUCTION_STRIP_ROW_MAX );++ // while watching, eight rows share the screen at once, so a row there is never the longer one -+ // and neither cap may outrun the slots the strip has room to remember+ CHECK( (Int)InGameUI::PRODUCTION_STRIP_WATCH_MAX <= (Int)InGameUI::PRODUCTION_STRIP_ROW_MAX );+}++/* Every cameo in the strip stands in the tray the general's powers stand in, down in the corner,+ and it stands in it at the size that bar draws it - stretched, the tray's rail and inner frame+ collapse into a coloured smudge and it stops reading as that bar at all. So the strip does not+ get to pick its own numbers: it borrows that bar's, and these are the ones that make the borrowed+ art come out right. Sliding the cameo out of the box painted for it, or over the rail, is the+ way this goes wrong quietly - it still draws, it just looks like a mistake. */+TEST(a_queue_cameo_sits_in_the_general_power_tray_the_way_that_bar_sits_in_it)+{+ // the cameo is inside its tray, both ways, art and all+ CHECK( (Int)InGameUI::PRODUCTION_STRIP_TRAY_X >= 0 );+ CHECK( (Int)InGameUI::PRODUCTION_STRIP_TRAY_Y >= 0 );+ CHECK( (Int)InGameUI::PRODUCTION_STRIP_TRAY_X + (Int)InGameUI::PRODUCTION_STRIP_QUEUE_W+ <= (Int)InGameUI::PRODUCTION_STRIP_TRAY_W );+ CHECK( (Int)InGameUI::PRODUCTION_STRIP_TRAY_Y + (Int)InGameUI::PRODUCTION_STRIP_QUEUE_H+ <= (Int)InGameUI::PRODUCTION_STRIP_TRAY_H );++ //+ // The overlap is that bar's own: it steps 35 between slots 41 tall, so consecutive trays cover+ // six of each other and a row of them is one run of metal rather than a line of loose boxes.+ //+ CHECK_EQ( (Int)InGameUI::PRODUCTION_STRIP_TRAY_H - (Int)InGameUI::PRODUCTION_STRIP_BAR_STEP,+ (Int)InGameUI::PRODUCTION_STRIP_TRAY_OVER );++ // and it never eats a whole tray: the step has to stay positive on both axes or the row stacks+ CHECK( (Int)InGameUI::PRODUCTION_STRIP_TRAY_OVER < (Int)InGameUI::PRODUCTION_STRIP_TRAY_W );+ CHECK( (Int)InGameUI::PRODUCTION_STRIP_TRAY_OVER < (Int)InGameUI::PRODUCTION_STRIP_TRAY_H );++ //+ // Six trays at that step, plus the tray the last one still needs the rest of, is what the row+ // costs across - and that has to fit inside the 800 the whole layout is written in, or the strip+ // runs off the side of the screen before its overflow count is ever reached.+ //+ const Int step = (Int)InGameUI::PRODUCTION_STRIP_TRAY_W - (Int)InGameUI::PRODUCTION_STRIP_TRAY_OVER;+ const Int rowWidth = ( (Int)InGameUI::PRODUCTION_STRIP_ROW_MAX - 1 ) * step+ + (Int)InGameUI::PRODUCTION_STRIP_TRAY_W;+ CHECK( rowWidth < 800 );+}++/* Rows of trays stack by the same overlap the trays close up by sideways, so a pile of rows reads+ as one sheet of metal. The general's power bar itself is the check: it steps 35 between 41-tall+ slots, and the step has to come out of the tray height as a fraction so it survives a bar the+ loader gave a different size to - twice the tray is twice the step, never twice the tray less+ the same six pixels. */+TEST(a_row_of_trays_stacks_on_the_row_above_it_by_that_bars_own_step)+{+ CHECK_EQ( (Int)InGameUI::PRODUCTION_STRIP_BAR_STEP,+ InGameUI::stripRowStep( (Int)InGameUI::PRODUCTION_STRIP_TRAY_H ) );++ // twice the size, twice the step - the overlap is a fraction of the tray, not a constant+ CHECK_EQ( 2 * (Int)InGameUI::PRODUCTION_STRIP_BAR_STEP,+ InGameUI::stripRowStep( 2 * (Int)InGameUI::PRODUCTION_STRIP_TRAY_H ) );++ // and a step always shorter than the tray it steps, or the rows separate instead of overlapping+ CHECK( InGameUI::stripRowStep( (Int)InGameUI::PRODUCTION_STRIP_TRAY_H )+ < (Int)InGameUI::PRODUCTION_STRIP_TRAY_H );+ CHECK( InGameUI::stripRowStep( (Int)InGameUI::PRODUCTION_STRIP_TRAY_H ) > 0 );++ //+ // the superweapon strip stands in the same trays, three rows of six of them, and that pile has+ // to fit under the corner clock plate rather than run off the bottom of the 800x600 it is+ // written in+ //+ const Int rows = (Int)InGameUI::SUPERWEAPON_STRIP_ROWS;+ const Int pileHeight = ( rows - 1 ) * InGameUI::stripRowStep( (Int)InGameUI::PRODUCTION_STRIP_TRAY_H )+ + (Int)InGameUI::PRODUCTION_STRIP_TRAY_H;+ CHECK( pileHeight < 600 / 2 );++ const Int step = (Int)InGameUI::PRODUCTION_STRIP_TRAY_W - (Int)InGameUI::PRODUCTION_STRIP_TRAY_OVER;+ const Int rowWidth = ( (Int)InGameUI::SUPERWEAPON_STRIP_COLS - 1 ) * step+ + (Int)InGameUI::PRODUCTION_STRIP_TRAY_W;+ CHECK( rowWidth < 800 );+}++/* Buildings going up on the map are not in anybody's queue - they are objects standing on the+ ground with a percentage on them - so they get their own row, and it is drawn above the queue:+ the strip reads top to bottom as what is being raised and what is being turned out. Both are+ rows of the same array, so the later of them has to be inside it. */+TEST(the_buildings_going_up_have_their_own_row_above_the_queue)+{+ CHECK( (Int)InGameUI::PRODUCTION_ROW_SITES < (Int)InGameUI::PRODUCTION_ROW_QUEUE );+ CHECK( (Int)InGameUI::PRODUCTION_ROW_SITES >= 0 );+ CHECK( (Int)InGameUI::PRODUCTION_ROW_QUEUE < (Int)InGameUI::PRODUCTION_STRIP_ROWS );+}++/* The building you have selected does not get a row of its own: its items lead the queue row, so+ the front of the strip is what the thing you are looking at is making and the rest of the base+ follows it. Inside either block the soonest to finish is still first, and a tie never moves -+ an item only goes in front of one it beats, so a base full of identical barracks does not+ shuffle from frame to frame. */+TEST(the_selected_buildings_items_lead_the_queue_row)+{+ // a selected item passes anything that is not selected, however long it has left+ CHECK( InGameUI::stripSlotGoesBefore( TRUE, 9000, FALSE, 1 ) );+ // and nothing that is not selected ever passes one+ CHECK( !InGameUI::stripSlotGoesBefore( FALSE, 1, TRUE, 9000 ) );++ // inside a block, soonest first+ CHECK( InGameUI::stripSlotGoesBefore( FALSE, 100, FALSE, 200 ) );+ CHECK( !InGameUI::stripSlotGoesBefore( FALSE, 200, FALSE, 100 ) );+ CHECK( InGameUI::stripSlotGoesBefore( TRUE, 100, TRUE, 200 ) );+ CHECK( !InGameUI::stripSlotGoesBefore( TRUE, 200, TRUE, 100 ) );++ // a tie holds its place - in both blocks+ CHECK( !InGameUI::stripSlotGoesBefore( FALSE, 100, FALSE, 100 ) );+ CHECK( !InGameUI::stripSlotGoesBefore( TRUE, 100, TRUE, 100 ) );+}++/* That bar grows leftward out of the corner, so the heavy rail of its tray is on the right hand+ edge of the artwork. A row running rightward from the left of the screen wants that rail on the+ other side, so the strip draws the tray mirrored - and it mirrors it in the UV rect alone, over+ the same texture page, rather than shipping a second copy of the art the other way round. Every+ other field has to come across with it or the copy draws the wrong piece of the page at the wrong+ size, and the original has to be left alone, because the bar in the corner is still drawing it. */+TEST(a_mirrored_image_is_the_same_piece_of_texture_the_other_way_round)+{+ Image *source = newInstance( Image );+ source->setName( AsciiString( "SATraySmall" ) );+ source->setFilename( AsciiString( "SAControlBar512_001.tga" ) );+ source->setTextureWidth( 512 );+ source->setTextureHeight( 512 );++ ICoord2D size = { 60, 56 };+ source->setImageSize( &size );++ Region2D uv;+ uv.lo.x = 413.0f / 512.0f;+ uv.lo.y = 1.0f / 512.0f;+ uv.hi.x = 473.0f / 512.0f;+ uv.hi.y = 57.0f / 512.0f;+ source->setUV( &uv );++ Image *mirrored = newMirroredImage( source );++ // the whole point: the horizontal run of the UV rect is reversed+ CHECK_NEAR( 473.0f / 512.0f, mirrored->getUV()->lo.x, 0.0001f );+ CHECK_NEAR( 413.0f / 512.0f, mirrored->getUV()->hi.x, 0.0001f );++ // and nothing else about it moves+ CHECK_NEAR( 1.0f / 512.0f, mirrored->getUV()->lo.y, 0.0001f );+ CHECK_NEAR( 57.0f / 512.0f, mirrored->getUV()->hi.y, 0.0001f );+ CHECK_STR( "SAControlBar512_001.tga", mirrored->getFilename().str() );+ CHECK_EQ( 512, mirrored->getTextureSize()->x );+ CHECK_EQ( 512, mirrored->getTextureSize()->y );+ CHECK_EQ( 60, mirrored->getImageWidth() );+ CHECK_EQ( 56, mirrored->getImageHeight() );++ // the tray the control bar owns is left exactly as it was found+ CHECK_NEAR( 413.0f / 512.0f, source->getUV()->lo.x, 0.0001f );+ CHECK_NEAR( 473.0f / 512.0f, source->getUV()->hi.x, 0.0001f );++ mirrored->deleteInstance();+ source->deleteInstance();+}