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): stand the production strip up as a column
Olcay Seyganf50a2efe003d
diff --git a/CHANGELOG.md b/CHANGELOG.mdindex 22a45c919..4c4bf9511 100644--- a/CHANGELOG.md+++ b/CHANGELOG.md@@ -284,7 +284,8 @@ found and fixed — EA's own, not port damage.**- 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. Ten tanks ordered back to back are one picture with an x10 in its corner rather than ten copies of the same tank eating the row, so what is left of the row still says what else is coming.+- The queue stands up out of the corner instead of lying across the bottom of the screen. It is a column now, five pictures high, growing upward from just above the command bar with the next thing to arrive at the bottom of it - so the one picture you actually read is always in the same place, a thumb's width above the buttons, and it does not move when six more tanks are ordered. What is left over closes the column as a sixth cell wearing a "+N". A busy base used to lay its whole queue across the battlefield; now it costs one picture's width of screen, whatever it has coming, and the buildings going up on the ground stand in a second column beside it. Watching a match, that is one column per player, side by side.+- 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. Ten tanks ordered back to back are one picture with an x10 in its corner rather than ten copies of the same tank eating the row, so what is left of the row still says what else is coming.- 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.diff --git a/GeneralsMD/Code/GameEngine/Include/GameClient/InGameUI.h b/GeneralsMD/Code/GameEngine/Include/GameClient/InGameUI.hindex 8f631e501..e032147d8 100644--- a/GeneralsMD/Code/GameEngine/Include/GameClient/InGameUI.h+++ b/GeneralsMD/Code/GameEngine/Include/GameClient/InGameUI.h@@ -614,18 +614,19 @@ 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 = 6 }; ///< cameos one row will draw; the rest become a "+N"- enum { PRODUCTION_STRIP_WATCH_MAX = 3 }; ///< and while watching, where eight rows share the screen- /// and a row is a whole player: three cameos and a "+N",- /// since a run of the same unit is one of them now- enum { PRODUCTION_STRIP_ROWS = 8 }; ///< playing: the global row and the selected producer's row.- /// watching: one row per player, so eight of them+ enum { PRODUCTION_STRIP_ROW_MAX = 5 }; ///< cameos one column will draw, stacked upward; whatever+ /// is left over closes it as a sixth cell wearing a "+N"+ enum { PRODUCTION_STRIP_WATCH_MAX = 3 }; ///< and while watching, where eight columns share the+ /// screen and a column is a whole player: three cameos and+ /// a "+N", since a run of the same unit is one of them now+ enum { PRODUCTION_STRIP_ROWS = 8 }; ///< playing: the global column and the selected producer's.+ /// watching: one column 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.+ // Which row is which while playing. A lower number stands further from the left edge, so the+ // queue is the column on the edge and the buildings going up on the map stand beside it. The+ // building you have selected does not get a column of its own - its items lead the queue column+ // instead. Rows nobody filled are closed up rather than left as a gap.//enum{@@ -1009,7 +1010,8 @@ protected:void drawIncomeRate( void ); ///< income per minute, drawn beside the money windowvoid updateIncomeEstimate( Player *player ); ///< income per minute, shown beside the moneyvoid drawProductionStrip( void ); ///< the production queue rows above the control bar- void drawProductionStripRow( Int row, Int y ); ///< one of those rows, at that top edge+ ///< one of those columns, its left edge at 'left' and its bottom cell's top edge at 'bottomY'+ void drawProductionStripColumn( Int row, Int left, Int bottomY );const Image *productionStripTray( void ); ///< the bar's tray, mirrored, kept until the bar changes sidevoid stripTrayMetrics( ICoord2D *tray, ICoord2D *cameo, ICoord2D *hole, Int *step ); ///< that tray's size, its cameo hole, and the column stepvoid drawStripSeconds( Int which, Int x, Int y, Int w, Int h, Int seconds, Bool plainSeconds = FALSE ); ///< countdown written inside a cameodiff --git a/GeneralsMD/Code/GameEngine/Source/GameClient/InGameUI.cpp b/GeneralsMD/Code/GameEngine/Source/GameClient/InGameUI.cppindex a54c5830f..cfaf9cc06 100644--- a/GeneralsMD/Code/GameEngine/Source/GameClient/InGameUI.cpp+++ b/GeneralsMD/Code/GameEngine/Source/GameClient/InGameUI.cpp@@ -6034,14 +6034,15 @@ void InGameUI::drawHudOverlay( void )}//--------------------------------------------------------------------------------------------------// The production strip: one cameo per queued item, drawn over the world just above the control-// bar, left aligned in a row that grows to the right, soonest to finish first - the item about to-// pop is always the leftmost one, wherever in the base it is being built. The top row is global --// everything the local player has queued anywhere. When a single producer is selected its own-// queue gets a second row beneath it. Each row draws at most PRODUCTION_STRIP_ROW_MAX cameos and finishes with a "+N" for-// whatever else is queued. Units and upgrades wear the same two border colours the command bar-// uses. The item a building is actually working on wears a radial fill. A click takes the camera-// to the building an item is queued on; ctrl-click cancels it.+// The production strip: one cameo per queued item, drawn over the world in a column standing on+// the corner just above the control bar and growing upward, soonest to finish at the bottom - the+// item about to pop is always the cell nearest the bar, wherever in the base it is being built.+// That column is global - everything the local player has queued anywhere - and the buildings+// going up on the ground stand in a second column beside it. A column draws at most+// PRODUCTION_STRIP_ROW_MAX cameos and closes with a sixth cell wearing a "+N" for whatever else is+// queued. Units and upgrades wear the same two border colours the command bar uses. The item a+// building is actually working on wears a radial fill. A click takes the camera to the building an+// item is queued on; ctrl-click cancels it.//-------------------------------------------------------------------------------------------------//-------------------------------------------------------------------------------------------------@@ -6683,17 +6684,20 @@ void InGameUI::drawSuperweaponStrip( void )}//--------------------------------------------------------------------------------------------------/** Lay out and draw one row, with its top edge at y. */+/** Lay out and draw one column, its left edge at x and the bottom cameo's top edge at bottomY.+ *+ * A column, not a row: the strip grows upward out of the corner instead of across the bottom of+ * the screen. The soonest thing to arrive is the bottom cell - the one nearest the command bar+ * and nearest the eye - and everything behind it is stacked above. Five cells, and whatever is+ * left over closes the column as a sixth wearing a "+N", so the strip's whole footprint is one+ * tray wide however much the base has queued. *///--------------------------------------------------------------------------------------------------void InGameUI::drawProductionStripRow( Int row, Int y )+void InGameUI::drawProductionStripColumn( Int row, Int left, Int bottomY ){const Int count = m_productionStripCount[ row ];if( count < 1 )return;- const Int gap = stripPixels( PRODUCTION_STRIP_GAP );- const Int more = stripPixels( PRODUCTION_STRIP_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@@ -6701,8 +6705,8 @@ void InGameUI::drawProductionStripRow( Int row, Int y )// 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.+ // Trays overlap by what that bar overlaps its own by, so a column of them is one run of metal+ // rather than a pile of separate boxes, and the column is flush against the left edge.//ICoord2D traySize, cameoSize, trayHole;Int trayStep = 0;@@ -6716,48 +6720,49 @@ void InGameUI::drawProductionStripRow( Int row, Int y )// the left is the same distance in from the right hereconst Int trayInsetX = trayW - trayHole.x - cameoW;const Int trayInsetY = trayHole.y;- const Int trayY = y - trayInsetY;+ const Int trayX = left;+ const Int x = left + trayInsetX; ///< every cameo in a column shares its left edge+ const Int cellStep = stripRowStep( trayH );const Image *tray = productionStripTray();//- // 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.+ // what the "+N" stands for is everything the column does not already show - and a cameo wearing+ // an "x5" shows five of them, so the run counts as five here or the same items are reported twice+ //+ Int shown = 0;+ for( Int shownSlot = 0; shownSlot < count; shownSlot++ )+ shown += m_productionStrip[ row ][ shownSlot ].quantity;++ const Int hidden = m_productionStripTotal[ row ] - shown;+ const Int cells = count + ( hidden > 0 ? 1 : 0 );++ //+ // The trays go down first, all of them, and from the top down: the bottom one carries the item+ // that arrives next, so it is the one drawn last and the one whose frame is whole.//// 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-- )+ for( Int back = cells - 1; back >= 0; back-- ){- const Int backX = back * trayStep;+ const Int backY = bottomY - back * cellStep - trayInsetY;if( tray )- TheDisplay->drawImage( tray, backX, trayY, backX + trayW, trayY + trayH );+ TheDisplay->drawImage( tray, trayX, backY, trayX + trayW, backY + trayH );else- TheDisplay->drawFillRect( backX, trayY, trayW, trayH, GameMakeColor( 0, 0, 0, 130 ) );+ TheDisplay->drawFillRect( trayX, backY, trayW, trayH, GameMakeColor( 0, 0, 0, 130 ) );}//- // what the "+N" stands for is everything the row does not already show - and a cameo wearing an- // "x5" shows five of them, so the run counts as five here or the same items are reported twice- //- Int shown = 0;- for( Int shownSlot = 0; shownSlot < count; shownSlot++ )- shown += m_productionStrip[ row ][ shownSlot ].quantity;-- const Int hidden = m_productionStripTotal[ row ] - shown;-- //- // What every cameo in the row is to be drawn with, worked out before any of it is drawn. The- // row then goes down a piece at a time - every picture, then every scrim, then every border -+ // What every cameo in the column is to be drawn with, worked out before any of it is drawn. The+ // column then goes down a piece at a time - every picture, then every scrim, then every border -// rather than a cameo at a time, because a run of pieces that ask the renderer for the same// thing is one draw call and the same pieces shuffled together are one draw call each. The// cameos do not overlap, so what lands on the screen is exactly what always did.//struct StripSlotDraw{- Int x; ///< left edge of this cameo+ Int y; ///< top edge of this cameoconst Image *cameo; ///< its picture, NULL when the template carries noneInt percent; ///< how much of the scrim has been swept off, -1 for no scrimInt seconds; ///< the countdown written across it, -1 for none@@ -6767,18 +6772,16 @@ void InGameUI::drawProductionStripRow( Int row, Int y )};StripSlotDraw slots[ PRODUCTION_STRIP_ROW_MAX ];- Int trayX = 0;- Int x = trayX + trayInsetX;for( Int i = 0; i < count; i++ ){ProductionStripSlot *slot = &m_productionStrip[ row ][ i ];StripSlotDraw *draw = &slots[ i ];- x = trayX + trayInsetX;+ const Int y = bottomY - i * cellStep; // the soonest is the bottom cellslot->pos.x = x;slot->pos.y = y;- draw->x = x;+ draw->y = y;draw->cameo = NULL;draw->percent = -1;draw->seconds = -1;@@ -6865,7 +6868,7 @@ void InGameUI::drawProductionStripRow( Int row, Int y ){const MouseIO *io = TheMouse->getMouseStatus();draw->cancelHover = io && io->pos.x >= x && io->pos.x < x + cameoW &&- io->pos.y >= y && io->pos.y < y + cameoH;+ io->pos.y >= draw->y && io->pos.y < draw->y + cameoH;}// same border colours the command bar puts on its build and upgrade buttons - except while@@ -6883,8 +6886,6 @@ void InGameUI::drawProductionStripRow( Int row, Int y )else if( TheControlBar )draw->border = slot->isUpgrade ? TheControlBar->getUpgradeBorderColor(): TheControlBar->getBuildBorderColor();-- trayX += trayStep;}// the pictures@@ -6892,7 +6893,7 @@ void InGameUI::drawProductionStripRow( Int row, Int y ){const StripSlotDraw *draw = &slots[ cameoSlot ];if( draw->cameo )- TheDisplay->drawImage( draw->cameo, draw->x, y, draw->x + cameoW, y + cameoH );+ TheDisplay->drawImage( draw->cameo, x, draw->y, x + cameoW, draw->y + cameoH );}// the sweeps over them@@ -6900,7 +6901,7 @@ void InGameUI::drawProductionStripRow( Int row, Int y ){const StripSlotDraw *draw = &slots[ clockSlot ];if( draw->percent >= 0 )- TheDisplay->drawRemainingRectClock( draw->x, y, cameoW, cameoH,+ TheDisplay->drawRemainingRectClock( x, draw->y, cameoW, cameoH,draw->percent, GameMakeColor( 0, 0, 0, 100 ) );}@@ -6910,7 +6911,7 @@ void InGameUI::drawProductionStripRow( Int row, Int y )const StripSlotDraw *draw = &slots[ secondsSlot ];if( draw->seconds >= 0 )drawStripSeconds( row * PRODUCTION_STRIP_ROW_MAX + secondsSlot,- draw->x, y, cameoW, cameoH, draw->seconds );+ x, draw->y, cameoW, cameoH, draw->seconds );}// how many of the same thing each one stands for, in the corner the countdown leaves free@@ -6919,14 +6920,14 @@ void InGameUI::drawProductionStripRow( Int row, Int y )const StripSlotDraw *draw = &slots[ quantitySlot ];if( draw->quantity > 1 )drawStripQuantity( row * PRODUCTION_STRIP_ROW_MAX + quantitySlot,- draw->x, y, cameoW, draw->quantity );+ x, draw->y, cameoW, draw->quantity );}// and the borders round them, a team border heavy enough to read as the row's whole labelfor( Int borderSlot = 0; borderSlot < count; borderSlot++ ){const StripSlotDraw *draw = &slots[ borderSlot ];- TheDisplay->drawOpenRect( draw->x, y, cameoW, cameoH,+ TheDisplay->drawOpenRect( x, draw->y, cameoW, cameoH,m_productionStripRowColor[ row ] != 0 ? 2.0f : 1.0f,draw->border );}@@ -6939,19 +6940,19 @@ void InGameUI::drawProductionStripRow( Int row, Int y )const Int barInset = cameoW / 4;const Int barHeight = stripPixels( 4 );- TheDisplay->drawFillRect( draw->x, y, cameoW, cameoH,+ TheDisplay->drawFillRect( x, draw->y, cameoW, cameoH,GameMakeColor( 190, 0, 0, 120 ) );- TheDisplay->drawFillRect( draw->x + barInset, y + ( cameoH - barHeight ) / 2,+ TheDisplay->drawFillRect( x + barInset, draw->y + ( cameoH - barHeight ) / 2,cameoW - 2 * barInset, barHeight,GameMakeColor( 255, 255, 255, 255 ) );}}- 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.+ // whatever did not fit closes the column as a sixth cell wearing a "+N", at the top of it: the+ // column is read from the bottom, so the overflow sits at the far end. It is not clickable -+ // there is no one item behind it, and what it stands for is already reachable by selecting the+ // building.//if( hidden > 0 ){@@ -6973,8 +6974,10 @@ void InGameUI::drawProductionStripRow( Int row, Int y )Int textWidth = 0, textHeight = 0;overflow->getSize( &textWidth, &textHeight );- overflow->draw( x + ( more - textWidth ) / 2,- y + ( cameoH - textHeight ) / 2,+ const Int moreY = bottomY - count * cellStep;++ overflow->draw( x + ( cameoW - textWidth ) / 2,+ moreY + ( cameoH - textHeight ) / 2,GameMakeColor( 235, 235, 235, 255 ),GameMakeColor( 0, 0, 0, 255 ) );}@@ -7056,9 +7059,9 @@ void InGameUI::drawProductionStrip( void )else{//- // 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+ // the buildings going up take the column beside the queue, off the edge: 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 column you glance at rather than the one you live on//ProductionStripGather sites;sites.slot = m_productionStrip[ PRODUCTION_ROW_SITES ];@@ -7144,33 +7147,39 @@ void InGameUI::drawProductionStrip( void )m_productionStripCameoH = cameoSize.y;//- // rows stack upwards from just above the control bar, last row nearest the bar: playing, that- // puts the selected building's row under the base's; watching, it just keeps the pile off the- // bar. A row that would run off the top of the screen is dropped rather than drawn over the- // tactical view's edge.+ // Each row is a column now, standing on the corner just above the control bar and growing+ // upward: the next thing to arrive is the bottom cell, always in the same place, and the rest+ // of the queue is stacked over it. Six cells is the whole of it, so the strip is one tray wide+ // however deep the base's queue goes - across the bottom of the screen it used to run over the+ // battlefield instead.//- // 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.+ // Columns then stand side by side, the last one flush against the left edge: playing, that puts+ // the queue on the edge and the buildings going up beside it; watching, it is one column per+ // player. Columns overlap sideways, and cells overlap upward, by the six that bar overlaps its+ // own slots by - 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 );//// The strip is the busiest thing on the screen that is drawn a quad at a time, so it is drawn- // as a batch: the rows hand the display their pieces in an order that lets it gather the ones+ // as a batch: the columns hand the display their pieces in an order that lets it gather the ones// asking for the same state into single draw calls. See Display::beginBatch2D.//TheDisplay->beginBatch2D();- for( Int at = rowsUsed - 1; at >= 0; at-- )+ //+ // The rightmost column is drawn first: the artwork is mirrored, so each tray's heavy rail is on+ // its left, and it takes the column to its left drawn over it to cover that rail.+ //+ for( Int at = 0; at < rowsUsed; at++ ){- const Int y = lowerY - ( rowsUsed - 1 - at ) * rowStep;- if( y - trayTop < 0 )- break;- drawProductionStripRow( used[ at ], y );+ const Int column = rowsUsed - 1 - at; // used[rowsUsed-1] is the one on the edge+ const Int x = column * trayStep;+ if( x + traySize.x > TheDisplay->getWidth() )+ continue;+ drawProductionStripColumn( used[ at ], x, lowerY );}TheDisplay->endBatch2D();diff --git a/GeneralsMD/Code/Tests/test_gameengine.cpp b/GeneralsMD/Code/Tests/test_gameengine.cppindex 20eb8de78..89f28bf04 100644--- a/GeneralsMD/Code/Tests/test_gameengine.cpp+++ b/GeneralsMD/Code/Tests/test_gameengine.cpp@@ -7164,16 +7164,26 @@ 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. */+/* Five is what a column of the strip shows before the rest of the queue folds into the "+N" that+ closes it as a sixth cell. It used to be sixteen across the bottom of the screen, which at a+ busy war factory ran the cameos most of the way over the map. */TEST(the_production_strip_folds_a_long_queue_into_its_overflow){- CHECK_EQ( 6, (Int)InGameUI::PRODUCTION_STRIP_ROW_MAX );+ CHECK_EQ( 5, (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+ // while watching, eight columns share the screen at once, so a column there is never the taller+ // one - and neither cap may outrun the slots the strip has room to rememberCHECK( (Int)InGameUI::PRODUCTION_STRIP_WATCH_MAX <= (Int)InGameUI::PRODUCTION_STRIP_ROW_MAX );++ //+ // The column, its overflow cell included, has to stand inside the 600 the layout is written in+ // with room to spare for the control bar it stands on: it grows upward out of the corner, and a+ // cell drawn past the top of the screen is a cell nobody can read.+ //+ const Int cells = (Int)InGameUI::PRODUCTION_STRIP_ROW_MAX + 1;+ const Int height = ( cells - 1 ) * InGameUI::stripRowStep( (Int)InGameUI::PRODUCTION_STRIP_TRAY_H )+ + (Int)InGameUI::PRODUCTION_STRIP_TRAY_H;+ CHECK( height < 600 / 2 );}/* Every cameo in the strip stands in the tray the general's powers stand in, down in the corner,