Skip to content

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.

feat(gameclient): size the interface off the shorter screen edge

Olcay Seygandfa074adcbf4
diff --git a/GeneralsMD/Code/GameEngine/Include/GameClient/Display.h b/GeneralsMD/Code/GameEngine/Include/GameClient/Display.h
index 1f337079b..2b2e62355 100644
--- a/GeneralsMD/Code/GameEngine/Include/GameClient/Display.h
+++ b/GeneralsMD/Code/GameEngine/Include/GameClient/Display.h
@@ -240,14 +240,33 @@ extern Display *TheDisplay;
* pixel in the game was drawn for. The .wnd rectangles are stretched by exactly this
* (parseScreenRect), so anything drawn beside them in raw pixels - a production strip cameo, a
* health bar - has to be multiplied by it too, or it keeps its 2003 size while the screen around
- * it triples. Never below 1: nothing shrinks under 800 wide. */
+ * it triples. Never below 1: nothing shrinks under 800 wide.
+ *
+ * The smaller of the two axes, which is what the layouts themselves are stretched by
+ * (ControlBarUniformScaleFor, same number, spelt out again here because Display.h cannot see
+ * ControlBar.h). It used to be the width alone: on a 5120x1440 screen that says 6.4 where the
+ * height says 2.4, and a health bar came out two and a half times the width of the tank it was
+ * sitting over, because the tank's own size on screen follows the height. */
+//-------------------------------------------------------------------------------------------------
+inline Real UIScaleForScreen( Int screenWidth, Int screenHeight )
+{
+ if( screenWidth <= 0 || screenHeight <= 0 )
+ return 1.0f;
+
+ Real scale = screenWidth / 800.0f;
+ const Real byHeight = screenHeight / 600.0f;
+ if( byHeight < scale )
+ scale = byHeight;
+
+ return scale < 1.0f ? 1.0f : scale;
+}
+
//-------------------------------------------------------------------------------------------------
inline Real TheUIScale( void )
{
if( TheDisplay == NULL )
return 1.0f;
- Real scale = TheDisplay->getWidth() / 800.0f;
- return scale < 1.0f ? 1.0f : scale;
+ return UIScaleForScreen( TheDisplay->getWidth(), TheDisplay->getHeight() );
}
extern void StatDebugDisplay( DebugDisplayInterface *dd, void *, FILE *fp = NULL );
diff --git a/GeneralsMD/Code/GameEngine/Include/GameClient/GlobalLanguage.h b/GeneralsMD/Code/GameEngine/Include/GameClient/GlobalLanguage.h
index 4d88f4776..5050985b2 100644
--- a/GeneralsMD/Code/GameEngine/Include/GameClient/GlobalLanguage.h
+++ b/GeneralsMD/Code/GameEngine/Include/GameClient/GlobalLanguage.h
@@ -106,10 +106,12 @@ public:
Int adjustFontSize(Int theFontSize); // Adjusts font size for resolution. jba.
- /** the whole of the policy behind adjustFontSize, with the screen width and the damping handed
+ /** the whole of the policy behind adjustFontSize, with the screen size and the damping handed
* in rather than read off the globals - which is the only way to check it without a
- * GlobalData, and a GlobalData cannot be built without a file system and the registry. */
- static Int adjustFontSizeForWidth(Int theFontSize, Int screenWidth, Real damping);
+ * GlobalData, and a GlobalData cannot be built without a file system and the registry.
+ * Both axes, because the scale is the smaller of width over 800 and height over 600. */
+ static Int adjustFontSizeForScreen(Int theFontSize, Int screenWidth, Int screenHeight,
+ Real damping);
typedef std::list<AsciiString> StringList; // Used for our font file names that we want to load
typedef StringList::iterator StringListIt;
diff --git a/GeneralsMD/Code/GameEngine/Include/GameClient/View.h b/GeneralsMD/Code/GameEngine/Include/GameClient/View.h
index 3706cf116..7417928ae 100644
--- a/GeneralsMD/Code/GameEngine/Include/GameClient/View.h
+++ b/GeneralsMD/Code/GameEngine/Include/GameClient/View.h
@@ -345,4 +345,11 @@ extern Real View_stepAngleByEighths( Real angle, Int steps ); ///< snap, then mo
// EXTERNALS //////////////////////////////////////////////////////////////////////////////////////
extern View *TheTacticalView; ///< the main tactical interface to the game world
+/** The horizontal view cone a full-screen tactical view covers on a display this size, in radians.
+ * Retail's answer is a flat 50 degrees whatever the shape of the screen, which pins the world
+ * scale to the screen's width; past 16:9 this holds the vertical half-angle at its 16:9 value
+ * instead, so the same camera shows the same amount of world from top to bottom on every
+ * monitor and the extra width shows more of the map rather than magnifying what was there. */
+extern Real ViewHorizontalFovForScreen( Int displayWidth, Int displayHeight );
+
#endif // _VIEW_H_
diff --git a/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/GUICallbacks/Menus/PopupPlayerInfo.cpp b/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/GUICallbacks/Menus/PopupPlayerInfo.cpp
index 0fc76c0c3..909d1299f 100644
--- a/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/GUICallbacks/Menus/PopupPlayerInfo.cpp
+++ b/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/GUICallbacks/Menus/PopupPlayerInfo.cpp
@@ -473,8 +473,11 @@ void ResetBattleHonorInsertion(void)
}
void InsertBattleHonor(GameWindow *list, const Image *image, Bool enabled, Int itemData, Int& row, Int& column, UnicodeString text = UnicodeString::TheEmptyString, Int extra = 0)
{
- Int width = MAX_BATTLE_HONOR_IMAGE_WIDTH * (TheDisplay->getWidth() / 800.0f);
- Int height = MAX_BATTLE_HONOR_IMAGE_HEIGHT * (TheDisplay->getHeight() / 600.0f);
+ // one scale for both axes. Taken per axis, a 5120x1440 screen stretched the honor badge 6.4
+ // wide and 2.4 tall and the medal came out an oval.
+ const Real honorScale = UIScaleForScreen( TheDisplay->getWidth(), TheDisplay->getHeight() );
+ Int width = MAX_BATTLE_HONOR_IMAGE_WIDTH * honorScale;
+ Int height = MAX_BATTLE_HONOR_IMAGE_HEIGHT * honorScale;
static Int enabledColor = 0xFFFFFFFF;
static Int disabledColor = GameMakeColor(80, 80, 80, 255);
diff --git a/GeneralsMD/Code/GameEngine/Source/GameClient/GlobalLanguage.cpp b/GeneralsMD/Code/GameEngine/Source/GameClient/GlobalLanguage.cpp
index 8858510ac..5c2fcafe3 100644
--- a/GeneralsMD/Code/GameEngine/Source/GameClient/GlobalLanguage.cpp
+++ b/GeneralsMD/Code/GameEngine/Source/GameClient/GlobalLanguage.cpp
@@ -189,15 +189,30 @@ void GlobalLanguage::parseFontFileName( INI *ini, void * instance, void *store,
monkey->m_localFonts.push_front(asciiString);
}
-Int GlobalLanguage::adjustFontSize(Int theFontSize)
+Int GlobalLanguage::adjustFontSize(Int theFontSize)
{
- return adjustFontSizeForWidth( theFontSize, TheGlobalData->m_xResolution,
- m_resolutionFontSizeAdjustment );
+ return adjustFontSizeForScreen( theFontSize, TheGlobalData->m_xResolution,
+ TheGlobalData->m_yResolution,
+ m_resolutionFontSizeAdjustment );
}
-Int GlobalLanguage::adjustFontSizeForWidth(Int theFontSize, Int screenWidth, Real damping)
+Int GlobalLanguage::adjustFontSizeForScreen(Int theFontSize, Int screenWidth, Int screenHeight,
+ Real damping)
{
+ //
+ // The screen's size over the 800x600 everything was authored at, the smaller of the two axes -
+ // the same number ControlBarUniformScale() hands the command bar, and for the same reason. It
+ // used to be the width alone, which is only the same thing at 4:3: on a 5120x1440 screen the
+ // width says 6.4 where the height says 2.4, and the lettering came out twice the size the panel
+ // under it had grown to. A 1920x1080 shot and a 5120x1440 shot of the same bar have to
+ // overlay, and they only do if the text is measured off the axis the layout was measured off.
+ //
Real adjustFactor = screenWidth/800.0f;
+ if (screenHeight > 0)
+ {
+ const Real byHeight = screenHeight/600.0f;
+ if (byHeight < adjustFactor) adjustFactor = byHeight;
+ }
adjustFactor = 1.0f + (adjustFactor-1.0f) * damping;
if (adjustFactor<1.0f) adjustFactor = 1.0f;
//
diff --git a/GeneralsMD/Code/GameEngine/Source/GameClient/InGameUI.cpp b/GeneralsMD/Code/GameEngine/Source/GameClient/InGameUI.cpp
index 7d787e783..ec6703655 100644
--- a/GeneralsMD/Code/GameEngine/Source/GameClient/InGameUI.cpp
+++ b/GeneralsMD/Code/GameEngine/Source/GameClient/InGameUI.cpp
@@ -6091,10 +6091,15 @@ void InGameUI::drawHudOverlay( void )
m_hudDisplayString->getSize( &textWidth, &textHeight );
// top right, clear of the radar and the superweapon timers - and under the peace time countdown
- // while that is up, because the corner holds one plate above the other
- const Int pad = 4;
- Int x = TheDisplay->getWidth() - textWidth - pad - 8;
- Int y = (m_hudOverlayBottom > 0) ? m_hudOverlayBottom + 2 : 3;
+ // while that is up, because the corner holds one plate above the other.
+ //
+ // The three gaps are 800x600 numbers put through the command bar's own scale, like everything
+ // else on this overlay. Held at a flat pixel count the plate crept into the corner as the
+ // screen grew: the lettering inside it scales and the margin around it did not, so a 1440-tall
+ // shot and a 1080-tall one did not overlay however the text was sized.
+ const Int pad = stripPixels( 2 );
+ Int x = TheDisplay->getWidth() - textWidth - pad - stripPixels( 4 );
+ Int y = (m_hudOverlayBottom > 0) ? m_hudOverlayBottom + stripPixels( 1 ) : stripPixels( 2 );
// a plate behind it, so it stays legible over bright terrain
TheDisplay->drawFillRect( x - pad, y - 1, textWidth + pad*2, textHeight + 2,
diff --git a/GeneralsMD/Code/GameEngine/Source/GameClient/View.cpp b/GeneralsMD/Code/GameEngine/Source/GameClient/View.cpp
index a995fe81a..99e9ec4bf 100644
--- a/GeneralsMD/Code/GameEngine/Source/GameClient/View.cpp
+++ b/GeneralsMD/Code/GameEngine/Source/GameClient/View.cpp
@@ -38,6 +38,36 @@ UnsignedInt View::m_idNext = 1;
// the tactical view singleton
View *TheTacticalView = NULL;
+//-------------------------------------------------------------------------------------------------
+/** W3D's own default cone, and the one every camera number in the game was authored against. */
+static const Real VIEW_DESIGN_HFOV = 50.0f * PI / 180.0f;
+
+/** The widest screen that keeps that cone whole. 16:9 is where the shipped game is played and
+ * where the fork's own screenshots are taken, so it is the shape nothing may move under. */
+static const Real VIEW_REFERENCE_ASPECT = 16.0f / 9.0f;
+
+//-------------------------------------------------------------------------------------------------
+Real ViewHorizontalFovForScreen( Int displayWidth, Int displayHeight )
+{
+ if( displayWidth <= 0 || displayHeight <= 0 )
+ return VIEW_DESIGN_HFOV;
+
+ const Real aspect = (Real)displayWidth / (Real)displayHeight;
+ if( aspect <= VIEW_REFERENCE_ASPECT )
+ return VIEW_DESIGN_HFOV;
+
+ //
+ // Past 16:9 the horizontal cone opens instead of the vertical one closing. Retail pins the
+ // horizontal angle and lets the vertical follow the aspect, which on a 5120x1440 screen leaves
+ // 14.9 degrees of world from top to bottom against 29.4 at 16:9 - the same building fills the
+ // same slice of the screen's *width* and twice as much of its height, so an ultrawide shot and
+ // a 16:9 shot of the same camera look like two different zoom levels. Holding the vertical
+ // half-angle at its 16:9 value is what makes the two overlay.
+ //
+ const Real verticalHalf = (Real)tan( VIEW_DESIGN_HFOV * 0.5f ) / VIEW_REFERENCE_ASPECT;
+ return 2.0f * (Real)atan( verticalHalf * aspect );
+}
+
View::View( void )
{
diff --git a/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DView.cpp b/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DView.cpp
index 578ccbcea..c5f93378a 100644
--- a/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DView.cpp
+++ b/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DView.cpp
@@ -232,13 +232,21 @@ void W3DView::setWidth(Int width)
m_3DCamera->Set_Viewport(vMin,vMax);
//we want to maintain the same scale, so we'll need to adjust the fov.
- //default W3D fov for full-screen is 50 degrees.
- //Widescreen (PLAN.md Phase 6): deliberately retail behavior. A hor+
- //widening (vertical view pinned to 4:3, extra width showing more world)
- //was tried and reverted: the engine's maps assume the 4:3 view cone, and
- //the widened edges look past the map border into black from most camera
- //positions. Stock vert- keeps the horizontal view identical to 4:3.
- m_3DCamera->Set_View_Plane((Real)width/(Real)TheDisplay->getWidth()*DEG_TO_RADF(50.0f),-1);
+ //default W3D fov for full-screen is 50 degrees, and a view narrower than the
+ //display gets that same angle scaled down by its share of the width, so the
+ //world keeps the same size per pixel however much of the screen it owns.
+ //
+ //What the whole screen covers is ViewHorizontalFovForScreen's business: 50
+ //degrees up to 16:9, and past that the cone opens sideways instead of the
+ //vertical one closing. Retail's flat 50 pins the world scale to the screen's
+ //width, which on a 32:9 monitor is a 2.7x zoom over the same camera at 16:9 -
+ //the two screenshots do not overlay at any scale. A previous attempt at this
+ //pinned the vertical cone to 4:3 and was reverted for opening the map's own
+ //edges; 16:9 is the shape the game is played at, so nothing below it moves,
+ //and the terrain is drawn whole - what the wider view reaches is the map
+ //boundary, not black.
+ m_3DCamera->Set_View_Plane((Real)width/(Real)TheDisplay->getWidth()
+ * ViewHorizontalFovForScreen(TheDisplay->getWidth(), TheDisplay->getHeight()),-1);
}
//-------------------------------------------------------------------------------------------------