Zero Hour rebuilt from EA's source: x64, Direct3D 11, VS2022/CMake, ~60 original bugs fixed, an AI that builds a base. Bring your own game.
C++ cmakecnccommand-and-conquercppdirectx11game-enginegame-preservationgeneralsrtssage-enginex64zero-hour
fix(gameclient): pad the plate targas so the loader stops rescaling them
Olcay Seygan5f1ab494a296
diff --git a/CHANGELOG.md b/CHANGELOG.mdindex e38e6a0dc..d04a49495 100644--- a/CHANGELOG.md+++ b/CHANGELOG.md@@ -383,7 +383,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. The three pieces reach the screen: the paintings stop a pixel or two inside their own edges, which left a hairline of ground down both sides and along the bottom, and anything that close to an edge is now that edge. The American middle piece stands on the bottom edge like the other two sides' do, instead of hanging ten units high with a band of battlefield under the build grid, your money now sits in the middle of its readout instead of riding the top rim of it, and the build buttons are centred in the panel they are drawn on instead of pushing against its left edge with a strip of empty metal on the right. A one-pixel light line that stood off the right edge of that same piece at 1920x1080, from the top of the frame to the bottom, is gone too.+- 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. The three pieces reach the screen: the paintings stop a pixel or two inside their own edges, which left a hairline of ground down both sides and along the bottom, and anything that close to an edge is now that edge. The American middle piece stands on the bottom edge like the other two sides' do, instead of hanging ten units high with a band of battlefield under the build grid, your money now sits in the middle of its readout instead of riding the top rim of it, and the build buttons are centred in the panel they are drawn on instead of pushing against its left edge with a strip of empty metal on the right. The stray pixels along the right-hand edges of the pieces are gone: a one-pixel light line down the side of the middle piece, and a lit speck sitting in the battlefield next to the bottom corner of the Chinese radar. Both were the same thing. The bar's artwork was being rescaled as it went to the graphics card, which left the last column of each picture holding a mirrored copy of it, and the last column of pixels on screen drew from there.- 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.- Fullscreen, borderless and windowed are one saved setting now, so borderless no longer means adding a switch to your shortcut every time. `WindowMode` in `Options.ini` takes 0, 1 or 2 in that order; a switch on the command line still wins for that one run.diff --git a/GeneralsMD/Code/Data/Art/Textures/RebornBarAmericaCenter.tga b/GeneralsMD/Code/Data/Art/Textures/RebornBarAmericaCenter.tgaindex 888f372c8..fda918da5 100644Binary files a/GeneralsMD/Code/Data/Art/Textures/RebornBarAmericaCenter.tga 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.tgaindex 38b537444..602e3f8b8 100644Binary files a/GeneralsMD/Code/Data/Art/Textures/RebornBarAmericaLeft.tga 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.tgaindex 73339cad6..25e386438 100644Binary files a/GeneralsMD/Code/Data/Art/Textures/RebornBarAmericaRight.tga 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.tgaindex a932a25cf..b8c211f48 100644Binary files a/GeneralsMD/Code/Data/Art/Textures/RebornBarChinaCenter.tga 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.tgaindex 679d2653c..dd69005fb 100644Binary files a/GeneralsMD/Code/Data/Art/Textures/RebornBarChinaLeft.tga 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.tgaindex 0ec15435e..89b3a81f6 100644Binary files a/GeneralsMD/Code/Data/Art/Textures/RebornBarChinaRight.tga 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.tgaindex 458b0ba5e..1e1fd0577 100644Binary files a/GeneralsMD/Code/Data/Art/Textures/RebornBarGLACenter.tga 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.tgaindex 2b96e0960..4e831ea1a 100644Binary files a/GeneralsMD/Code/Data/Art/Textures/RebornBarGLALeft.tga 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.tgaindex 3b7727b69..238de8191 100644Binary files a/GeneralsMD/Code/Data/Art/Textures/RebornBarGLARight.tga 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 c9eb69ab5..32aeecf7e 100644--- a/GeneralsMD/Code/GameEngine/Include/GameClient/ControlBar.h+++ b/GeneralsMD/Code/GameEngine/Include/GameClient/ControlBar.h@@ -1286,6 +1286,7 @@ struct ControlBarPlateIRegion2D design; ///< the 800x600 rectangle of the painting this piece isInt readoutShiftY; ///< design units the money readout moves to sit in this art's boxInt gridShiftX; ///< design units the command grid moves to centre in this art's field+ Int artW, artH; ///< texels of painting in the targa; the rest is power-of-two padding};/** The plate 'panel' wears while the bar is dressed in 'side'. A general's scheme names a sidediff --git a/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/ControlBar/ControlBar.cpp b/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/ControlBar/ControlBar.cppindex bd6d60d99..0f2f8cac8 100644--- a/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/ControlBar/ControlBar.cpp+++ b/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/ControlBar/ControlBar.cpp@@ -1445,7 +1445,7 @@ static const ControlBarPlateSet thePlateSets[] ={{ "America",{- { "RebornBarAmericaLeft.tga", { { 0, 412 }, { 183, 599 } } },+ { "RebornBarAmericaLeft.tga", { { 0, 412 }, { 183, 599 } }, 0, 0, 293, 301 },/* This painting is 170 design units tall for a 180-unit slot, and it is the plate's owncomposition rather than a straight cut of the shipped bar: its grid field lines up withthe command buttons (494-589) exactly where it stands, and its money box does not line@@ -1457,22 +1457,22 @@ static const ControlBarPlateSet thePlateSets[] =runs 224.6 to 614.2, and the fourteen command buttons are 223 to 603: the firstcolumn overhangs the left bezel by a unit and a half while eleven units stand emptyon the right. Six to the right centres the block in the field. */- { "RebornBarAmericaCenter.tga", { { 180, 429 }, { 623, 599 } }, 10, 6 },- { "RebornBarAmericaRight.tga", { { 610, 433 }, { 800, 599 } } },+ { "RebornBarAmericaCenter.tga", { { 180, 429 }, { 623, 599 } }, 10, 6, 706, 271 },+ { "RebornBarAmericaRight.tga", { { 610, 433 }, { 800, 599 } }, 0, 0, 304, 268 },}},{ "China",{- { "RebornBarChinaLeft.tga", { { 1, 417 }, { 196, 598 } } },- { "RebornBarChinaCenter.tga", { { 176, 433 }, { 617, 597 } } },- { "RebornBarChinaRight.tga", { { 611, 424 }, { 798, 598 } } },+ { "RebornBarChinaLeft.tga", { { 1, 417 }, { 196, 598 } }, 0, 0, 315, 295 },+ { "RebornBarChinaCenter.tga", { { 176, 433 }, { 617, 597 } }, 0, 0, 718, 269 },+ { "RebornBarChinaRight.tga", { { 611, 424 }, { 798, 598 } }, 0, 0, 303, 284 },}},{ "GLA",{- { "RebornBarGLALeft.tga", { { 0, 416 }, { 215, 599 } } },- { "RebornBarGLACenter.tga", { { 168, 437 }, { 617, 599 } } },- { "RebornBarGLARight.tga", { { 612, 423 }, { 799, 599 } } },+ { "RebornBarGLALeft.tga", { { 0, 416 }, { 215, 599 } }, 0, 0, 345, 295 },+ { "RebornBarGLACenter.tga", { { 168, 437 }, { 617, 599 } }, 0, 0, 720, 261 },+ { "RebornBarGLARight.tga", { { 612, 423 }, { 799, 599 } }, 0, 0, 300, 284 },}},};diff --git a/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/GUI/GUICallbacks/W3DControlBar.cpp b/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/GUI/GUICallbacks/W3DControlBar.cppindex 8c6373b28..2b9de3e56 100644--- a/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/GUI/GUICallbacks/W3DControlBar.cpp+++ b/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/GUI/GUICallbacks/W3DControlBar.cpp@@ -654,21 +654,28 @@ static const Image *plateImage( const ControlBarPlate *plate )image->setFilename( name );//- // The whole targa is the image, so there is nothing to look up and no page to share. Not quite- // the whole targa, though: the last pixel column the quad draws samples the texture's outermost- // texel, and on the American centre plate that came out as a one-pixel light line standing off- // the plate's right edge, from the top of the frame to the bottom, over rows the painting leaves- // transparent. Drawing the plate with the centre panel skipped removed it, so it is this draw- // and nothing behind it. Stopping a texel and a half short of each edge keeps the sampler off- // that column; the painting's own edges are transparent or a rim of bezel, so nothing is lost.+ // Nothing else uses this targa, so there is no page to look the image up in - but there is+ // padding. The painting is artW by artH texels in a texture rounded up to the next power of+ // two, because the loader hands D3DXCreateTextureFromFileEx D3DX_DEFAULT for both dimensions and+ // that *stretches* a non-power-of-two image into the bigger texture. That stretch left the+ // texture's last column holding a vertically mirrored copy of the painting, and the last pixel+ // column of every quad drawn from it sampled that column: a one-pixel wire down the right edge+ // of a plate, and where the mirrored row happened to be opaque, a lit speck standing out in the+ // battlefield. Padded to a power of two there is no resize and no mirrored column.//- const Real insetX = 1.5f / (Real)( plate->design.width() * 1.6f ); // the targas are ~1.6 texels per design unit- const Real insetY = 1.5f / (Real)( plate->design.height() * 1.6f );+ // So the UV is the painting's own corner of the texture, half a texel in at each edge, which is+ // the mapping that puts the quad's first and last pixel centres on the first and last texel+ // centres.+ //+ Real potW = 1.0f, potH = 1.0f;+ while( potW < (Real)plate->artW ) potW *= 2.0f;+ while( potH < (Real)plate->artH ) potH *= 2.0f;+Region2D uv;- uv.lo.x = insetX;- uv.lo.y = insetY;- uv.hi.x = 1.0f - insetX;- uv.hi.y = 1.0f - insetY;+ uv.lo.x = 0.5f / potW;+ uv.lo.y = 0.5f / potH;+ uv.hi.x = ( (Real)plate->artW - 0.5f ) / potW;+ uv.hi.y = ( (Real)plate->artH - 0.5f ) / potH;image->setUV( &uv );ICoord2D size;diff --git a/GeneralsMD/Code/Tests/test_gameengine.cpp b/GeneralsMD/Code/Tests/test_gameengine.cppindex aa0e7c9f9..b7234ae5c 100644--- a/GeneralsMD/Code/Tests/test_gameengine.cpp+++ b/GeneralsMD/Code/Tests/test_gameengine.cpp@@ -7844,6 +7844,38 @@ TEST(a_plate_covers_the_windows_its_panel_is_responsible_for)}}+TEST(a_plates_targa_is_the_shape_its_design_rectangle_says)+{+ /* Each plate carries the size of the painting inside its targa, because the targa is padded out+ to a power of two: the loader hands D3DXCreateTextureFromFileEx D3DX_DEFAULT for width and+ height, and that stretches a non-power-of-two image into the bigger texture - which left the+ texture's last column holding a vertically mirrored copy of the painting, and every quad's+ last pixel column sampling it. The UV comes from these two numbers, so a typo in them+ stretches or crops the plate. The painting is a cut of the side's bar at one scale, so its+ texels-per-design-unit is the same across and down; that is what this checks. */+ static const char *sides[] = { "America", "China", "GLA", NULL };++ for( const char **s = sides; *s; s++ )+ for( Int p = 0; p < ControlBar::CB_PANEL_COUNT; p++ )+ {+ const ControlBarPlate *plate = ControlBarPlateForSide( AsciiString( *s ), p );+ CHECK( plate != NULL );+ CHECK( plate->artW > 0 );+ CHECK( plate->artH > 0 );++ const Real acrossScale = (Real)plate->artW / (Real)plate->design.width();+ const Real downScale = (Real)plate->artH / (Real)plate->design.height();+ CHECK_NEAR( acrossScale, downScale, 0.03f );++ // and a power-of-two texture has room for it+ Int potW = 1, potH = 1;+ while( potW < plate->artW ) potW *= 2;+ while( potH < plate->artH ) potH *= 2;+ CHECK( potW >= plate->artW && potW < plate->artW * 2 );+ CHECK( potH >= plate->artH && potH < plate->artH * 2 );+ }+}+TEST(the_grid_and_the_readout_follow_the_plate_that_paints_them){/* A plate is its side's own painting rather than a cut of the shipped bar, so the money box and