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(gameengine): give each BitFlags set its own name table
Olcay Seyganea13ec0f6bf2
diff --git a/CHANGELOG.md b/CHANGELOG.mdindex 5d9b1071b..97021b286 100644--- a/CHANGELOG.md+++ b/CHANGELOG.md@@ -384,6 +384,8 @@ found and fixed — EA's own, not port damage.**- A mission script that waits for a line of speech to finish waits the same length of time on every machine. It used to ask the sound hardware how long the file was, so a player whose sound card was not working, or was turned off, got the answer zero and walked straight through waits that everyone else sat out. That is a different game on two screens, and a replay that stops matching the machine that recorded it. The length now comes out of the file itself: measured on one line of speech, a silent machine said 0 milliseconds and a machine with sound said 3,285. Both say 3,285 now.- Laying a foundation costs less the further up the map you build. Flattening the ground under a new building scanned every row of the map from the bottom edge up to the building, threw all of them away bar the ones actually under it, and did that once per column. It works out the rows it needs now. The ground comes out identical, down to the last unit of height.- EVA announcements that were queued behind another one no longer go quiet. A request waits its turn and expires if its turn never comes, and the sum that worked out when that was could wrap round to zero, retiring the announcement on the frame it was asked for.+- A windowed game has a minimise button, like every other window on your desktop. There was none, and the system menu offered a Minimise entry that did nothing; the only way out was alt-tab.+- Mods can mark a thing as not worth an alarm. Walls, mines and scenery are shot at constantly and each one shouting drowns out the attack that matters; NO_ATTACK_WARNING on an object says damage to it raises no ping, no radar flash and no EVA line.- "Your base is under attack" fires for the attack you are actually under. The check that decides whether a warning is a repeat of one you just heard was computing something that was not a distance at all, so an attack on the far side of the map could silence the warning for one at your front door, and two hits on the same building could each get their own.- Scorch marks and tank tracks keep their colour on a brightly lit map. The shade was worked out from the map's own lighting with nothing holding it to a byte, and the red channel sits sixteen bits up, so anything over full brightness spilled into the transparency and the mark came out the wrong colour at the wrong opacity.- Two tanks shelling the same spot no longer wipe a scorch mark off the far side of the map. With the ground already carrying its full quota of marks, a repeat crater threw the oldest one away and then declined to add itself, so a mark vanished and nothing replaced it.diff --git a/GeneralsMD/Code/GameEngine/Include/Common/BitFlags.h b/GeneralsMD/Code/GameEngine/Include/Common/BitFlags.hindex 00fb45c6a..73bb63fcf 100644--- a/GeneralsMD/Code/GameEngine/Include/Common/BitFlags.h+++ b/GeneralsMD/Code/GameEngine/Include/Common/BitFlags.h@@ -48,7 +48,19 @@ class AsciiString;So we wrap to correct this, but leave the bitset "exposed" so that we can use all the non-ctorfunctions on it directly (since it doesn't overload operator= to do the "wrong" thing, strangley enough)*/-template <size_t NUMBITS>+/*+ TAG exists only to keep two flag sets that happen to have the same number of bits from becoming+ the same type. s_bitNameList is a static member of the instantiation, so two such sets used to+ share one name table: the linker folded the two definitions and kept whichever it felt like, and+ what that looked like from the outside was one INI parser suddenly refusing to recognise any of+ its own keywords, in a file that had nothing to do with the change that caused it. Adding a+ single KindOf was enough - it took KINDOF_COUNT to 117, which is what MODELCONDITION_COUNT+ already was. Every typedef below therefore carries its own tag, and+ bitflags_counts_are_all_different in test_gameengine says so out loud if two ever meet again.++ It costs nothing at runtime: the layout is the bitset and nothing else.+*/+template <size_t NUMBITS, int TAG = 0>class BitFlags{private:diff --git a/GeneralsMD/Code/GameEngine/Include/Common/BitFlagsIO.h b/GeneralsMD/Code/GameEngine/Include/Common/BitFlagsIO.hindex f18792e78..5bbaf7173 100644--- a/GeneralsMD/Code/GameEngine/Include/Common/BitFlagsIO.h+++ b/GeneralsMD/Code/GameEngine/Include/Common/BitFlagsIO.h@@ -39,8 +39,8 @@//-------------------------------------------------------------------------------------------------/*-template <size_t NUMBITS>-void BitFlags<NUMBITS>::buildDescription( AsciiString* str ) const+template <size_t NUMBITS, int TAG>+void BitFlags<NUMBITS, TAG>::buildDescription( AsciiString* str ) const{if ( str == NULL )return;//sanity@@ -59,8 +59,8 @@ void BitFlags<NUMBITS>::buildDescription( AsciiString* str ) const*///--------------------------------------------------------------------------------------------------template <size_t NUMBITS>-void BitFlags<NUMBITS>::parse(INI* ini, AsciiString* str)+template <size_t NUMBITS, int TAG>+void BitFlags<NUMBITS, TAG>::parse(INI* ini, AsciiString* str){// m_bits.reset();if (str)@@ -132,16 +132,16 @@ void BitFlags<NUMBITS>::parse(INI* ini, AsciiString* str)//-------------------------------------------------------------------------------------------------//--------------------------------------------------------------------------------------------------template <size_t NUMBITS>-/*static*/ void BitFlags<NUMBITS>::parseFromINI(INI* ini, void* /*instance*/, void *store, const void* /*userData*/)+template <size_t NUMBITS, int TAG>+/*static*/ void BitFlags<NUMBITS, TAG>::parseFromINI(INI* ini, void* /*instance*/, void *store, const void* /*userData*/){((BitFlags*)store)->parse(ini, NULL);}//-------------------------------------------------------------------------------------------------//--------------------------------------------------------------------------------------------------template <size_t NUMBITS>-/*static*/ void BitFlags<NUMBITS>::parseSingleBitFromINI(INI* ini, void* /*instance*/, void *store, const void* /*userData*/)+template <size_t NUMBITS, int TAG>+/*static*/ void BitFlags<NUMBITS, TAG>::parseSingleBitFromINI(INI* ini, void* /*instance*/, void *store, const void* /*userData*/){const char *token = ini->getNextToken();Int bitIndex = INI::scanIndexList(token, s_bitNameList); // this throws if the token is not found@@ -155,8 +155,8 @@ template <size_t NUMBITS>* Version Info:* 1: Initial version *///--------------------------------------------------------------------------------------------------template <size_t NUMBITS>-void BitFlags<NUMBITS>::xfer(Xfer* xfer)+template <size_t NUMBITS, int TAG>+void BitFlags<NUMBITS, TAG>::xfer(Xfer* xfer){// this deserves a version numberXferVersion currentVersion = 1;diff --git a/GeneralsMD/Code/GameEngine/Include/Common/DisabledTypes.h b/GeneralsMD/Code/GameEngine/Include/Common/DisabledTypes.hindex a3f38a7b6..0eb441f5f 100644--- a/GeneralsMD/Code/GameEngine/Include/Common/DisabledTypes.h+++ b/GeneralsMD/Code/GameEngine/Include/Common/DisabledTypes.h@@ -64,7 +64,7 @@ enum DisabledTypeDISABLED_ANY = 65535 ///< Do not use this value for setting disabled types (read-only)};-typedef BitFlags<DISABLED_COUNT> DisabledMaskType;+typedef BitFlags<DISABLED_COUNT, 1> DisabledMaskType;#define MAKE_DISABLED_MASK(k) DisabledMaskType(DisabledMaskType::kInit, (k))#define MAKE_DISABLED_MASK2(k,a) DisabledMaskType(DisabledMaskType::kInit, (k), (a))diff --git a/GeneralsMD/Code/GameEngine/Include/Common/DynamicAudioEventInfo.h b/GeneralsMD/Code/GameEngine/Include/Common/DynamicAudioEventInfo.hindex bf8690b5c..2ab568953 100644--- a/GeneralsMD/Code/GameEngine/Include/Common/DynamicAudioEventInfo.h+++ b/GeneralsMD/Code/GameEngine/Include/Common/DynamicAudioEventInfo.h@@ -102,7 +102,7 @@ class DynamicAudioEventInfo : public AudioEventInfo};// Warning: update xferNoName if you modify the enum list!- BitFlags< OVERRIDE_COUNT > m_overriddenFields;+ BitFlags< OVERRIDE_COUNT, 10 > m_overriddenFields;// Retain the original name so we can look it up laterAsciiString m_originalName;diff --git a/GeneralsMD/Code/GameEngine/Include/Common/KindOf.h b/GeneralsMD/Code/GameEngine/Include/Common/KindOf.hindex 42e60a328..7d1866322 100644--- a/GeneralsMD/Code/GameEngine/Include/Common/KindOf.h+++ b/GeneralsMD/Code/GameEngine/Include/Common/KindOf.h@@ -170,12 +170,13 @@ enum KindOfTypeKINDOF_DEMOTRAP, ///< Added strictly only for disarming purposes. They don't act like mines which have rendering and selection implications!KINDOF_CONSERVATIVE_BUILDING, ///< Conservative structures aren't considered part of your base for sneak attack boundary calculations...KINDOF_IGNORE_DOCKING_BONES, ///< Structure will not look up docking bones. Patch 1.03 hack.+ KINDOF_NO_ATTACK_WARNING, ///< Damage to this raises no "under attack" alarm, ping or EVA line.KINDOF_COUNT // total number of kindofs};-typedef BitFlags<KINDOF_COUNT> KindOfMaskType;+typedef BitFlags<KINDOF_COUNT, 2> KindOfMaskType;#define MAKE_KINDOF_MASK(k) KindOfMaskType(KindOfMaskType::kInit, (k))diff --git a/GeneralsMD/Code/GameEngine/Include/Common/ModelState.h b/GeneralsMD/Code/GameEngine/Include/Common/ModelState.hindex 8579d2dcf..72ec7597e 100644--- a/GeneralsMD/Code/GameEngine/Include/Common/ModelState.h+++ b/GeneralsMD/Code/GameEngine/Include/Common/ModelState.h@@ -247,7 +247,7 @@ enum ModelConditionFlagType//--------------------------------------------------------------------------------------------------typedef BitFlags<MODELCONDITION_COUNT> ModelConditionFlags;+typedef BitFlags<MODELCONDITION_COUNT, 3> ModelConditionFlags;#define MAKE_MODELCONDITION_MASK(k) ModelConditionFlags(ModelConditionFlags::kInit, (k))#define MAKE_MODELCONDITION_MASK2(k,a) ModelConditionFlags(ModelConditionFlags::kInit, (k), (a))diff --git a/GeneralsMD/Code/GameEngine/Include/Common/ObjectStatusTypes.h b/GeneralsMD/Code/GameEngine/Include/Common/ObjectStatusTypes.hindex 7aaf7859e..9a9f495df 100644--- a/GeneralsMD/Code/GameEngine/Include/Common/ObjectStatusTypes.h+++ b/GeneralsMD/Code/GameEngine/Include/Common/ObjectStatusTypes.h@@ -95,7 +95,7 @@ enum ObjectStatusTypes};-typedef BitFlags<OBJECT_STATUS_COUNT> ObjectStatusMaskType;+typedef BitFlags<OBJECT_STATUS_COUNT, 4> ObjectStatusMaskType;#define MAKE_OBJECT_STATUS_MASK(k) ObjectStatusMaskType(ObjectStatusMaskType::kInit, (k))#define MAKE_OBJECT_STATUS_MASK2(k,a) ObjectStatusMaskType(ObjectStatusMaskType::kInit, (k), (a))diff --git a/GeneralsMD/Code/GameEngine/Include/Common/SpecialPowerMaskType.h b/GeneralsMD/Code/GameEngine/Include/Common/SpecialPowerMaskType.hindex d3433923b..664f8faf4 100644--- a/GeneralsMD/Code/GameEngine/Include/Common/SpecialPowerMaskType.h+++ b/GeneralsMD/Code/GameEngine/Include/Common/SpecialPowerMaskType.h@@ -34,6 +34,6 @@#include "Common/BitFlagsIO.h"#include "Common/SpecialPowerType.h"-typedef BitFlags<SPECIALPOWER_COUNT> SpecialPowerMaskType;+typedef BitFlags<SPECIALPOWER_COUNT, 5> SpecialPowerMaskType;#endif /* __SPECIALPOWERMASKTYPE_H__ */\ No newline at end of filediff --git a/GeneralsMD/Code/GameEngine/Include/Common/Upgrade.h b/GeneralsMD/Code/GameEngine/Include/Common/Upgrade.hindex f9dc98ec0..659f19c20 100644--- a/GeneralsMD/Code/GameEngine/Include/Common/Upgrade.h+++ b/GeneralsMD/Code/GameEngine/Include/Common/Upgrade.h@@ -59,7 +59,7 @@ enum UpgradeStatusType// field, so raising it costs 48 bytes per player and per object that carries one.#define UPGRADE_MAX_COUNT 512-typedef BitFlags<UPGRADE_MAX_COUNT> UpgradeMaskType;+typedef BitFlags<UPGRADE_MAX_COUNT, 6> UpgradeMaskType;#define MAKE_UPGRADE_MASK(k) UpgradeMaskType(UpgradeMaskType::kInit, (k))#define MAKE_UPGRADE_MASK2(k,a) UpgradeMaskType(UpgradeMaskType::kInit, (k), (a))diff --git a/GeneralsMD/Code/GameEngine/Include/GameLogic/ArmorSet.h b/GeneralsMD/Code/GameEngine/Include/GameLogic/ArmorSet.hindex 446a646f2..75c180e7c 100644--- a/GeneralsMD/Code/GameEngine/Include/GameLogic/ArmorSet.h+++ b/GeneralsMD/Code/GameEngine/Include/GameLogic/ArmorSet.h@@ -59,7 +59,7 @@ enum ArmorSetType};//--------------------------------------------------------------------------------------------------typedef BitFlags<ARMORSET_COUNT> ArmorSetFlags;+typedef BitFlags<ARMORSET_COUNT, 7> ArmorSetFlags;//-------------------------------------------------------------------------------------------------class ArmorTemplateSetdiff --git a/GeneralsMD/Code/GameEngine/Include/GameLogic/Damage.h b/GeneralsMD/Code/GameEngine/Include/GameLogic/Damage.hindex 9037570ad..9790d233e 100644--- a/GeneralsMD/Code/GameEngine/Include/GameLogic/Damage.h+++ b/GeneralsMD/Code/GameEngine/Include/GameLogic/Damage.h@@ -96,7 +96,7 @@ enum DamageType//-------------------------------------------------------------------------------------------------//--------------------------------------------------------------------------------------------------typedef BitFlags<DAMAGE_NUM_TYPES> DamageTypeFlags;+typedef BitFlags<DAMAGE_NUM_TYPES, 8> DamageTypeFlags;inline Bool getDamageTypeFlag(DamageTypeFlags flags, DamageType dt){diff --git a/GeneralsMD/Code/GameEngine/Include/GameLogic/WeaponSetFlags.h b/GeneralsMD/Code/GameEngine/Include/GameLogic/WeaponSetFlags.hindex df1c3a75b..ec22f80b7 100644--- a/GeneralsMD/Code/GameEngine/Include/GameLogic/WeaponSetFlags.h+++ b/GeneralsMD/Code/GameEngine/Include/GameLogic/WeaponSetFlags.h@@ -32,6 +32,6 @@#include "GameLogic/WeaponSetType.h"-typedef BitFlags<WEAPONSET_COUNT> WeaponSetFlags;+typedef BitFlags<WEAPONSET_COUNT, 9> WeaponSetFlags;#endif /* __WEAPONSETFLAGS_H__ */diff --git a/GeneralsMD/Code/GameEngine/Source/Common/System/KindOf.cpp b/GeneralsMD/Code/GameEngine/Source/Common/System/KindOf.cppindex 47ef9795f..d4696f181 100644--- a/GeneralsMD/Code/GameEngine/Source/Common/System/KindOf.cpp+++ b/GeneralsMD/Code/GameEngine/Source/Common/System/KindOf.cpp@@ -157,6 +157,7 @@ const char* KindOfMaskType::s_bitNameList[] ="DEMOTRAP","CONSERVATIVE_BUILDING","IGNORE_DOCKING_BONES",+ "NO_ATTACK_WARNING",NULL};diff --git a/GeneralsMD/Code/GameEngine/Source/Common/System/Radar.cpp b/GeneralsMD/Code/GameEngine/Source/Common/System/Radar.cppindex 443eac3e5..ecfe2e307 100644--- a/GeneralsMD/Code/GameEngine/Source/Common/System/Radar.cpp+++ b/GeneralsMD/Code/GameEngine/Source/Common/System/Radar.cpp@@ -1185,6 +1185,14 @@ void Radar::tryUnderAttackEvent( const Object *obj )if( obj == NULL )return;+ //+ // Some things are shot at constantly and raising the alarm for each of them buries the one that+ // matters: a wall segment, a mine, a piece of scenery a stray shell clipped. NO_ATTACK_WARNING+ // in an object's KindOf says damage to it is not news - no ping, no glow, no EVA line.+ //+ if( obj->isKindOf( KINDOF_NO_ATTACK_WARNING ) )+ return;+// try to create the eventBool eventCreated = tryEvent( RADAR_EVENT_UNDER_ATTACK, obj->getPosition() );diff --git a/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DDisplay.cpp b/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DDisplay.cppindex c702a2bee..7c4d36cf4 100644--- a/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DDisplay.cpp+++ b/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DDisplay.cpp@@ -611,7 +611,7 @@ static void applyWindowFrame( Int mode )DWORD style = WS_POPUP | WS_VISIBLE | WS_SYSMENU;if( mode == WINDOW_MODE_WINDOWED )- style |= WS_DLGFRAME | WS_CAPTION;+ style |= WS_DLGFRAME | WS_CAPTION | WS_MINIMIZEBOX; // see WinMain: windowed means a real window::SetWindowLong( ApplicationHWnd, GWL_STYLE, style );diff --git a/GeneralsMD/Code/Main/WinMain.cpp b/GeneralsMD/Code/Main/WinMain.cppindex de0b0eafe..2b1f7bf61 100644--- a/GeneralsMD/Code/Main/WinMain.cpp+++ b/GeneralsMD/Code/Main/WinMain.cpp@@ -743,7 +743,10 @@ static Bool initializeAppWindows( HINSTANCE hInstance, Int nCmdShow, Bool runWinelse if (ApplicationIsBorderless)windowStyle |= WS_SYSMENU; // no caption, no frame; system menu so alt+F4 still closes itelse if (runWindowed)- windowStyle |= WS_DLGFRAME | WS_CAPTION | WS_SYSMENU;+ // WS_MINIMIZEBOX: a windowed game should have the button every other window has. Without it+ // the only way out of the window was alt+tab, and the system menu offered a Minimise entry+ // that did nothing.+ windowStyle |= WS_DLGFRAME | WS_CAPTION | WS_SYSMENU | WS_MINIMIZEBOX;elsewindowStyle |= WS_EX_TOPMOST | WS_SYSMENU;diff --git a/GeneralsMD/Code/Tests/test_gameengine.cpp b/GeneralsMD/Code/Tests/test_gameengine.cppindex 2db849b47..f0db605a8 100644--- a/GeneralsMD/Code/Tests/test_gameengine.cpp+++ b/GeneralsMD/Code/Tests/test_gameengine.cpp@@ -1162,6 +1162,66 @@ TEST(attack_move_turns_on_whoever_is_shooting_it)CHECK( !AIAttackMove_shouldRetaliate( 0xffffffff, 0xfffffff0, WINDOW, false, true ) );}+/* BitFlags used to be templated on the bit count alone, and its name table is a static+ member of the instantiation - so two flag sets with the same count were the SAME type+ and shared one s_bitNameList. The linker folded the two definitions and kept whichever+ it liked. From the outside that looked like one INI parser suddenly refusing to+ recognise any of its own keywords, in a file with no connection to the change that+ caused it: adding a single KindOf took KINDOF_COUNT to 117, which is what+ MODELCONDITION_COUNT already was, and airforcegeneral.ini stopped parsing on a+ ConditionState line.++ Each typedef now carries its own tag, so equal counts are harmless. This test keeps+ watch anyway - a tag that gets copied and pasted rather than incremented puts the trap+ straight back, and it is cheaper to read it here than to find it there. */+#include "Common/KindOf.h"+#include "Common/ModelState.h"+#include "Common/DisabledTypes.h"+#include "Common/ObjectStatusTypes.h"+#include "Common/SpecialPowerMaskType.h"+#include "GameLogic/ArmorSet.h"+#include "GameLogic/Damage.h"+#include "GameLogic/WeaponSetFlags.h"++TEST(bitflags_types_keep_their_own_name_tables)+{+ /* KINDOF_COUNT and MODELCONDITION_COUNT are in fact equal - both 117 - which is exactly+ the case that used to break. The tags are what keeps them apart now. */+ struct Named { const char *name; const char **names; const char *firstExpected; };+ const Named tables[] = {+ { "KINDOF", KindOfMaskType::getBitNames(), "OBSTACLE" },+ { "MODELCONDITION", ModelConditionFlags::getBitNames(), NULL },+ { "DISABLED", DisabledMaskType::getBitNames(), NULL },+ { "OBJECT_STATUS", ObjectStatusMaskType::getBitNames(),NULL },+ { "SPECIALPOWER", SpecialPowerMaskType::getBitNames(),NULL },+ { "ARMORSET", ArmorSetFlags::getBitNames(), NULL },+ { "DAMAGE", DamageTypeFlags::getBitNames(), NULL },+ { "WEAPONSET", WeaponSetFlags::getBitNames(), NULL },+ };+ const Int n = sizeof(tables) / sizeof(tables[0]);++ /* every table is somebody else's table only if two flag sets ended up the same type */+ for( Int i = 0; i < n; ++i )+ {+ CHECK( tables[i].names != NULL );+ CHECK( tables[i].names[0] != NULL );+ for( Int j = i + 1; j < n; ++j )+ {+ if( tables[i].names == tables[j].names )+ {+ printf( " BitFlags name table shared between %s and %s - they are the same type\n",+ tables[i].name, tables[j].name );+ }+ CHECK( tables[i].names != tables[j].names );+ }+ }++ /* and the KindOf table is the KindOf table, not whatever the linker felt like */+ CHECK_STR( KindOfMaskType::getBitNames()[0], "OBSTACLE" );+ CHECK_EQ( KindOfMaskType::getSingleBitFromName("STRUCTURE"), (Int)KINDOF_STRUCTURE );+ CHECK_EQ( ModelConditionFlags::getSingleBitFromName("RUBBLE"), (Int)MODELCONDITION_RUBBLE );+}+/* GameWindowManager.cpp: destroying a modal window that is not the top of the modal stackused to leave its entry behind, holding a pointer to freed memory. */#include "GameClient/GameWindow.h"