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(w3ddevice): draw hotkey letters in place, heavier and larger text
Olcay Seyganfeb4accbd2bc
diff --git a/GeneralsMD/Code/GameEngine/Include/GameClient/DisplayString.h b/GeneralsMD/Code/GameEngine/Include/GameClient/DisplayString.hindex e0ca7336c..ee28bffdd 100644--- a/GeneralsMD/Code/GameEngine/Include/GameClient/DisplayString.h+++ b/GeneralsMD/Code/GameEngine/Include/GameClient/DisplayString.h@@ -95,7 +95,7 @@ public:virtual void getSize( Int *width, Int *height ) = 0; ///< get render sizevirtual Int getWidth( Int charPos = -1 ) = 0; ///< get text with up to charPos characters, 1- = all characters- virtual void setUseHotkey( Bool useHotkey, Color hotKeyColor ) = 0;+ virtual void setUseHotkey( Bool useHotkey ) = 0; ///< hide '&' hotkey markers; the letter stays in the text's own colourvirtual void setClipRegion( IRegion2D *region ); ///< clip text in this regiondiff --git a/GeneralsMD/Code/GameEngine/Include/GameClient/GlobalLanguage.h b/GeneralsMD/Code/GameEngine/Include/GameClient/GlobalLanguage.hindex 5050985b2..d9c1927d4 100644--- a/GeneralsMD/Code/GameEngine/Include/GameClient/GlobalLanguage.h+++ b/GeneralsMD/Code/GameEngine/Include/GameClient/GlobalLanguage.h@@ -101,6 +101,7 @@ public:FontDesc m_creditsNormalFont;Real m_resolutionFontSizeAdjustment;+ static const Real TEXT_GROWS_WITH_LAYOUT; ///< the damping init sets: text grows exactly as its layout does//UnicodeString m_unicodeFontNameUStr;diff --git a/GeneralsMD/Code/GameEngine/Source/GameClient/GlobalLanguage.cpp b/GeneralsMD/Code/GameEngine/Source/GameClient/GlobalLanguage.cppindex 5c2fcafe3..115d28f73 100644--- a/GeneralsMD/Code/GameEngine/Source/GameClient/GlobalLanguage.cpp+++ b/GeneralsMD/Code/GameEngine/Source/GameClient/GlobalLanguage.cpp@@ -154,6 +154,13 @@ void GlobalLanguage::init( void )ini.load( fname, INI_LOAD_OVERWRITE, NULL );++ // EA's Language.ini grows the lettering at 0.7 of the rate the screen grows. The window layouts+ // grow at the full rate, so on a 1920x1080 screen every label was drawn a size or two smaller than+ // the box drawn for it, and on 2560x1440 a tooltip's text filled half its panel. The text keeps+ // pace with its panel now, which is also the size it was authored at on 800x600.+ m_resolutionFontSizeAdjustment = TEXT_GROWS_WITH_LAYOUT;+StringListIt it = m_localFonts.begin();while( it != m_localFonts.end()){@@ -189,6 +196,8 @@ void GlobalLanguage::parseFontFileName( INI *ini, void * instance, void *store,monkey->m_localFonts.push_front(asciiString);}+const Real GlobalLanguage::TEXT_GROWS_WITH_LAYOUT = 1.0f;+Int GlobalLanguage::adjustFontSize(Int theFontSize){return adjustFontSizeForScreen( theFontSize, TheGlobalData->m_xResolution,@@ -219,8 +228,8 @@ Int GlobalLanguage::adjustFontSizeForScreen(Int theFontSize, Int screenWidth, In// the window layouts themselves are stretched by the full resolution ratio, so a font ceiling// of 2x meant that from about 1950 pixels wide up the text stopped growing while the panel it// sits in kept going - at 2560 a command bar three times the size of its 800x600 original wore- // 8pt letters. The damping factor already keeps the text below the layout's own scale- // (0.7 < 1), so the ceiling only has to be high enough not to bite before 4K.+ // 8pt letters. The damping factor keeps the text at or below the layout's own scale (init+ // sets 1, the layout's), so the ceiling only has to be high enough not to bite before 4K.//if (adjustFactor>4.0f) adjustFactor = 4.0f;Int pointSize = REAL_TO_INT_FLOOR(theFontSize*adjustFactor);diff --git a/GeneralsMD/Code/GameEngineDevice/Include/W3DDevice/GameClient/W3DDisplayString.h b/GeneralsMD/Code/GameEngineDevice/Include/W3DDevice/GameClient/W3DDisplayString.hindex 5cae6c660..a97d545a3 100644--- a/GeneralsMD/Code/GameEngineDevice/Include/W3DDevice/GameClient/W3DDisplayString.h+++ b/GeneralsMD/Code/GameEngineDevice/Include/W3DDevice/GameClient/W3DDisplayString.h@@ -88,7 +88,7 @@ public:void setWordWrap( Int wordWrap ); ///< set the word wrap widthvoid setWordWrapCentered( Bool isCentered ); ///< If this is set to true, the text on a new line is centeredvoid setFont( GameFont *font ); ///< set a font for display- void setUseHotkey( Bool useHotkey, Color hotKeyColor = 0xffffffff );+ void setUseHotkey( Bool useHotkey ); ///< hide '&' hotkey markers in the textvoid setClipRegion( IRegion2D *region ); ///< clip text in this regionprotected:@@ -100,13 +100,9 @@ protected:void computeExtents( void ); ///< compupte text width and heightRender2DSentenceClass m_textRenderer; ///< for drawing text- Render2DSentenceClass m_textRendererHotKey; ///< for drawing textBool m_textChanged; ///< when contents of string change this is TRUEBool m_fontChanged; ///< when font has chagned this is TRUE- UnicodeString m_hotkey; ///< holds the current hotkey marker.- Bool m_useHotKey;- ICoord2D m_hotKeyPos;- Color m_hotKeyColor;+ Bool m_useHotKey; ///< '&' hotkey markers are hiddenICoord2D m_textPos; ///< current text pos set in text rendererColor m_currTextColor, ///< current color used in text rendererm_currDropColor; ///< current color used for shadow in textdiff --git a/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/GUI/Gadget/W3DStaticText.cpp b/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/GUI/Gadget/W3DStaticText.cppindex 800ee688f..8c4119df6 100644--- a/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/GUI/Gadget/W3DStaticText.cpp+++ b/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/GUI/Gadget/W3DStaticText.cpp@@ -104,10 +104,8 @@ static void drawStaticTextText( GameWindow *window, WinInstanceData *instData,text->setWordWrapCentered(TRUE);elsetext->setWordWrapCentered(FALSE);- if( BitTest( window->winGetStatus(), WIN_STATUS_HOTKEY_TEXT ) && TheGlobalData)- text->setUseHotkey(TRUE, TheGlobalData->m_hotKeyTextColor);- else- text->setUseHotkey(FALSE, 0);+ // a HOTKEY_TEXT window hides its label's '&' markers; the letter is no longer painted apart+ text->setUseHotkey( BitTest( window->winGetStatus(), WIN_STATUS_HOTKEY_TEXT ) );// how much space will this text take updiff --git a/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DDisplayString.cpp b/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DDisplayString.cppindex 27cfcae9c..a399a8325 100644--- a/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DDisplayString.cpp+++ b/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DDisplayString.cpp@@ -56,7 +56,6 @@#include "GameClient/GameClient.h"#include "GameClient/Display.h"#include "W3DDevice/GameClient/W3DDisplayString.h"-#include "GameClient/HotKey.h"#include "GameClient/GameFont.h"#include "GameClient/GlobalLanguage.h"@@ -124,9 +123,6 @@ W3DDisplayString::W3DDisplayString( void )m_clipRegion.hi.y = 0;m_lastResourceFrame = 0;m_useHotKey = FALSE;- m_hotKeyPos.x = 0;- m_hotKeyPos.y = 0;- m_hotKeyColor = GameMakeColor(255,255,255,255);} // end W3DDisplayString@@ -150,16 +146,7 @@ void W3DDisplayString::notifyTextChanged( void )DisplayString::notifyTextChanged();if(TheGlobalLanguageData){- if(TheGlobalLanguageData->m_useHardWrap == TRUE)- {- m_textRenderer.Set_Use_Hard_Word_Wrap(true);- m_textRendererHotKey.Set_Use_Hard_Word_Wrap(true);- }- else- {- m_textRenderer.Set_Use_Hard_Word_Wrap(false);- m_textRendererHotKey.Set_Use_Hard_Word_Wrap(false);- }+ m_textRenderer.Set_Use_Hard_Word_Wrap(TheGlobalLanguageData->m_useHardWrap == TRUE);}// get our new text extents@@ -173,7 +160,6 @@ void W3DDisplayString::notifyTextChanged( void )// reset data for our text rendererm_textRenderer.Reset();- m_textRendererHotKey.Reset();} // end notifyTextChanged@@ -209,21 +195,9 @@ void W3DDisplayString::draw( Int x, Int y, Color color, Color dropColor, Int xDr// if our font or text has changed we need to build a new sentenceif( m_fontChanged || m_textChanged ){- if(m_useHotKey)- {- m_textRenderer.Set_Hot_Key_Parse(TRUE);- m_textRenderer.Build_Sentence( getText().str(), &m_hotKeyPos.x, &m_hotKeyPos.y );- m_hotkey.translate(TheHotKeyManager->searchHotKey(getText()));- if(!m_hotkey.isEmpty())- m_textRendererHotKey.Build_Sentence(m_hotkey.str(), NULL, NULL);- else- {- m_useHotKey = FALSE;- m_textRendererHotKey.Reset();- }- }- else- m_textRenderer.Build_Sentence( getText().str(), NULL, NULL );+ // Reset() clears the parse flag on every text change, so it is put back here, where it is read+ m_textRenderer.Set_Hot_Key_Parse( m_useHotKey != FALSE );+ m_textRenderer.Build_Sentence( getText().str(), NULL, NULL );m_fontChanged = FALSE;m_textChanged = FALSE;needNewPolys = TRUE;@@ -261,15 +235,7 @@ void W3DDisplayString::draw( Int x, Int y, Color color, Color dropColor, Int xDr// draw the textm_textRenderer.Set_Location( Vector2( m_textPos.x, m_textPos.y ) );m_textRenderer.Draw_Sentence( m_currTextColor );-- if(m_useHotKey)- {- m_textRendererHotKey.Reset_Polys();- m_textRendererHotKey.Set_Location( Vector2( m_textPos.x + m_hotKeyPos.x , m_textPos.y +m_hotKeyPos.y) );- m_textRendererHotKey.Draw_Sentence( m_hotKeyColor );- m_textRendererHotKey.Render();- }-+} // end if// render the text@@ -345,15 +311,7 @@ void W3DDisplayString::setFont( GameFont *font )// set the font in our rendererm_textRenderer.Set_Font( static_cast<FontCharsClass *>(m_font->fontData) );-- //- // The hotkey underline is drawn in the bold cut of the same font, and the library hands back- // null when it has not got one - a font set that ships without its bold face, or a malformed- // one that failed to load. This read straight through that.- //- GameFont *boldFont = TheFontLibrary->getFont( font->nameString, font->pointSize, TRUE );- m_textRendererHotKey.Set_Font( boldFont ? static_cast<FontCharsClass *>(boldFont->fontData)- : static_cast<FontCharsClass *>(m_font->fontData) );+// recompute extents for text with new fontcomputeExtents();@@ -386,10 +344,6 @@ void W3DDisplayString::setClipRegion( IRegion2D *region )m_clipRegion.lo.y,m_clipRegion.hi.x,m_clipRegion.hi.y ) );- m_textRendererHotKey.Set_Clipping_Rect( RectClass( m_clipRegion.lo.x,- m_clipRegion.lo.y,- m_clipRegion.hi.x,- m_clipRegion.hi.y ) );} // end if} // end setClipRegion@@ -430,11 +384,10 @@ void W3DDisplayString::setWordWrap( Int wordWrap )notifyTextChanged();}// void setWordWrap( Int wordWrap )-void W3DDisplayString::setUseHotkey( Bool useHotkey, Color hotKeyColor )+void W3DDisplayString::setUseHotkey( Bool useHotkey ){- const Bool unchanged = ( m_useHotKey == useHotkey && m_hotKeyColor == hotKeyColor );+ const Bool unchanged = ( m_useHotKey == useHotkey );m_useHotKey = useHotkey;- m_hotKeyColor = hotKeyColor;m_textRenderer.Set_Hot_Key_Parse(useHotkey);// W3DStaticText asks again on every draw, and a rebuilt sentence is a new text texture: the moneydiff --git a/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DDisplayStringManager.cpp b/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DDisplayStringManager.cppindex 99df197cb..5e8320093 100644--- a/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DDisplayStringManager.cpp+++ b/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DDisplayStringManager.cpp@@ -204,7 +204,6 @@ void W3DDisplayStringManager::update( void )// free the resourcesstring->m_textRenderer.Reset();- string->m_textRendererHotKey.Reset();//// mark data in the string as changed so that if it needs to// be drawn again it will know to reconstruct the render datadiff --git a/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/render2dsentence.cpp b/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/render2dsentence.cppindex 2e48d37e0..b42941c38 100644--- a/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/render2dsentence.cpp+++ b/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/render2dsentence.cpp@@ -40,6 +40,7 @@#include "wwprofile.h"#include "wwmemlog.h"#include "dx8wrapper.h"+#include <math.h>#ifdef _INTERNAL// for occasional debugging...@@ -772,7 +773,6 @@ void Render2DSentenceClass::Build_Sentence_Centered (const WCHAR *text, int *hkXint hotKeyPosX = 0;int hotKeyPosY = 0;bool calcHotKeyX = false;- bool dontBlit = false;while (!end){//@@ -881,14 +881,15 @@ void Render2DSentenceClass::Build_Sentence_Centered (const WCHAR *text, int *hkXfor(int i = 0; i <= charCount; i++) {WCHAR ch = *text++;- dontBlit = false;//- // Determine how much horizontal space this character requires+ // Determine how much horizontal space this character requires. A hotkey '&' is+ // dropped and the letter after it drawn like any other: the grid keys are the+ // shortcuts now, and the letter used to be left out here for a second renderer to+ // paint in yellow, which drew nothing at all for a letter outside ASCII.//if(ParseHotKey && (ch == L'&') && (*text != 0) && (*text > L' ') && (*text != L'\n')){ch = *text++;- dontBlit = true;}float char_spacing = Font->Get_Char_Spacing (ch);@@ -953,18 +954,8 @@ void Render2DSentenceClass::Build_Sentence_Centered (const WCHAR *text, int *hkX//// Blit the character to the surface//- if(!dontBlit)- Font->Blit_Char (ch, LockedPtr, LockedStride, TextureOffset.I, TextureOffset.J);-- if (dontBlit) {- // we don't blit for a hot key character. So add extra spacing.- char_spacing += Font->Get_Extra_Overlap();- // Brutal hack #27 Gamma - Bolded M's are just a problem. jba.- if (ch=='M') {- char_spacing++;- }- }-+ Font->Blit_Char (ch, LockedPtr, LockedStride, TextureOffset.I, TextureOffset.J);+TextureOffset.I += char_spacing;}}@@ -996,7 +987,6 @@ Vector2 Render2DSentenceClass::Build_Sentence_Not_Centered (const WCHAR *text, iint hotKeyPosX = 0;int hotKeyPosY = 0;bool calcHotKeyX = false;- bool dontBlit = false;Vector2i textureOffset = TextureOffset;@@ -1026,9 +1016,9 @@ Vector2 Render2DSentenceClass::Build_Sentence_Not_Centered (const WCHAR *text, i//while (text != NULL) {WCHAR ch = *text++;- dontBlit = false;//- // Determine how much horizontal space this character requires+ // Determine how much horizontal space this character requires; a hotkey '&' is+ // dropped and its letter drawn like the rest, as in Build_Sentence_Centered//if(ParseHotKey && (ch == L'&') && (*text != 0) && (*text > L' ') && (*text != L'\n')){@@ -1039,7 +1029,6 @@ Vector2 Render2DSentenceClass::Build_Sentence_Not_Centered (const WCHAR *text, ihotKeyPosX = Cursor.X + TextureOffset.I -TextureStartX;//TextureOffset.I;ch = *text++;- dontBlit = true;}float char_spacing = Font->Get_Char_Spacing (ch);@@ -1144,7 +1133,7 @@ Vector2 Render2DSentenceClass::Build_Sentence_Not_Centered (const WCHAR *text, i//// Blit the character to the surface//- if (!justCalcExtents && !dontBlit )+ if (!justCalcExtents){Font->Blit_Char (ch, LockedPtr, LockedStride, TextureOffset.I, TextureOffset.J);}@@ -1452,9 +1441,12 @@ FontCharsClass::Store_GDI_Char (WCHAR ch)//// Convert the pixel intensity from 8bit to 4bit and- // store it in our buffer+ // store it in our buffer. Coverage goes through a square root first: GDI's+ // antialiased coverage taken straight as alpha leaves every edge pixel of a+ // small glyph two thirds transparent, and light lettering on the game's dark+ // panels read as hairlines. Fully covered and empty pixels stay what they were.//- uint8 alpha_value = ((pixel_value >> 4) & 0xF);+ uint8 alpha_value = (uint8)( sqrt( pixel_value / 255.0 ) * 15.0 + 0.5 );*curr_buffer_p++ = pixel_color | (alpha_value << 12);}}