From 0351e5fbb2eded12ed01703f06516ac641230404 Mon Sep 17 00:00:00 2001 From: xezon <4720891+xezon@users.noreply.github.com> Date: Sun, 7 Dec 2025 12:51:46 +0100 Subject: [PATCH 1/2] refactor(namekey): Reduce code duplication in NameKeyGenerator functions, misc formatting tweaks --- .../Include/Common/NameKeyGenerator.h | 43 ++++++------ .../Code/GameEngine/Include/Common/Upgrade.h | 8 +-- .../GameEngine/Include/GameClient/Image.h | 2 +- .../Source/Common/NameKeyGenerator.cpp | 69 ++++++------------- .../Source/Common/System/Upgrade.cpp | 10 ++- 5 files changed, 50 insertions(+), 82 deletions(-) diff --git a/GeneralsMD/Code/GameEngine/Include/Common/NameKeyGenerator.h b/GeneralsMD/Code/GameEngine/Include/Common/NameKeyGenerator.h index bc98672b29..86b67e880c 100644 --- a/GeneralsMD/Code/GameEngine/Include/Common/NameKeyGenerator.h +++ b/GeneralsMD/Code/GameEngine/Include/Common/NameKeyGenerator.h @@ -36,22 +36,20 @@ #include "Common/AsciiString.h" //------------------------------------------------------------------------------------------------- -/** - Note that NameKeyType isn't a "real" enum, but an enum type used to enforce the - fact that NameKeys are really magic cookies, and aren't really interchangeable - with ints. NAMEKEY_INVALID is always a legal value, but all other values are dynamically - determined at runtime. (The generated code is basically identical, of course.) -*/ +// Note that NameKeyType isn't a "real" enum, but an enum type used to enforce the +// fact that NameKeys are really magic cookies, and aren't really interchangeable +// with integers. NAMEKEY_INVALID is always a legal value, but all other values are dynamically +// determined at runtime. (The generated code is basically identical, of course.) //------------------------------------------------------------------------------------------------- enum NameKeyType CPP_11(: Int) { NAMEKEY_INVALID = 0, - NAMEKEY_MAX = 1<<23, // max ordinal value of a NameKey (some code relies on these fitting into 24 bits safely) - FORCE_NAMEKEYTYPE_LONG = 0x7fffffff // a trick to ensure the NameKeyType is a 32-bit int + NAMEKEY_MAX = 1<<23, // max ordinal value of a NameKey (some code relies on these fitting into 24 bits safely) + FORCE_NAMEKEYTYPE_LONG = 0x7fffffff, // a trick to ensure the NameKeyType is a 32-bit int }; //------------------------------------------------------------------------------------------------- -/** A bucket entry for the name key generator */ +// A bucket entry for the name key generator //------------------------------------------------------------------------------------------------- class Bucket : public MemoryPoolObject { @@ -72,12 +70,12 @@ inline Bucket::Bucket() : m_nextInSocket(NULL), m_key(NAMEKEY_INVALID) { } inline Bucket::~Bucket() { } //------------------------------------------------------------------------------------------------- -/** This class implements the conversion of an arbitrary string into a unique - * integer "key". Calling the nameToKey() method with the same string is - * guaranteed to return the same key. Also, all keys generated by an - * instance of this class are guaranteed to be unique with respect to that - * instance's catalog of names. Multiple instances of this class can be - * created to service multiple namespaces. */ +// This class implements the conversion of an arbitrary string into a unique +// integer "key". Calling the nameToKey() method with the same string is +// guaranteed to return the same key. Also, all keys generated by an +// instance of this class are guaranteed to be unique with respect to that +// instance's catalog of names. Multiple instances of this class can be +// created to service multiple namespaces. //------------------------------------------------------------------------------------------------- class NameKeyGenerator : public SubsystemInterface { @@ -99,16 +97,14 @@ class NameKeyGenerator : public SubsystemInterface NameKeyType nameToKey(const char* name); NameKeyType nameToLowercaseKey(const char *name); - /** - given a key, return the name. this is almost never needed, - except for a few rare cases like object serialization. also - note that it's not particularly fast; it does a dumb linear - search for the key. - */ + // given a key, return the name. this is almost never needed, + // except for a few rare cases like object serialization. also + // note that it's not particularly fast; it does a dumb linear + // search for the key. AsciiString keyToName(NameKeyType key); - // Get a string out of the INI. Store it into a NameKeyType - static void parseStringAsNameKeyType( INI *ini, void *instance, void *store, const void* userData ); + // Get a string out of the INI. Store it into a NameKeyType + static void parseStringAsNameKeyType( INI *ini, void *instance, void *store, const void* userData ); private: @@ -124,6 +120,7 @@ class NameKeyGenerator : public SubsystemInterface NameKeyType nameToKeyImpl(const char* name); NameKeyType nameToLowercaseKeyImpl(const char *name); + NameKeyType createNameKey(UnsignedInt hash, const AsciiString& name); void freeSockets(); diff --git a/GeneralsMD/Code/GameEngine/Include/Common/Upgrade.h b/GeneralsMD/Code/GameEngine/Include/Common/Upgrade.h index 07aa657a65..33ce189637 100644 --- a/GeneralsMD/Code/GameEngine/Include/Common/Upgrade.h +++ b/GeneralsMD/Code/GameEngine/Include/Common/Upgrade.h @@ -235,10 +235,10 @@ class UpgradeCenter : public SubsystemInterface void reset( void ); ///< subsystem interface void update( void ) { } ///< subsystem interface - UpgradeTemplate *firstUpgradeTemplate( void ); ///< return the first upgrade template - const UpgradeTemplate *findUpgradeByKey( NameKeyType key ) const; ///< find upgrade by name key - const UpgradeTemplate *findUpgrade( const AsciiString& name ) const; ///< find and return upgrade by name - const UpgradeTemplate *findVeterancyUpgrade(VeterancyLevel level) const; ///< find and return upgrade by name + UpgradeTemplate *firstUpgradeTemplate( void ); ///< return the first upgrade template + const UpgradeTemplate *findUpgradeByKey( NameKeyType key ) const; ///< find upgrade by name key + const UpgradeTemplate *findUpgrade( const AsciiString& name ) const; ///< find and return upgrade by name + const UpgradeTemplate *findVeterancyUpgrade(VeterancyLevel level) const; ///< find and return upgrade by veterancy level UpgradeTemplate *newUpgrade( const AsciiString& name ); ///< allocate, link, and return new upgrade diff --git a/GeneralsMD/Code/GameEngine/Include/GameClient/Image.h b/GeneralsMD/Code/GameEngine/Include/GameClient/Image.h index 25ec6e0cf3..0714a96bb4 100644 --- a/GeneralsMD/Code/GameEngine/Include/GameClient/Image.h +++ b/GeneralsMD/Code/GameEngine/Include/GameClient/Image.h @@ -128,7 +128,7 @@ class ImageCollection : public SubsystemInterface void load( Int textureSize ); ///< load images - const Image *findImageByName( const AsciiString& name ); ///< find image based on name + const Image *findImageByName( const AsciiString& name ) const; ///< find image based on name /// adds the given image to the collection, transfers ownership to this object void addImage(Image *image); diff --git a/GeneralsMD/Code/GameEngine/Source/Common/NameKeyGenerator.cpp b/GeneralsMD/Code/GameEngine/Source/Common/NameKeyGenerator.cpp index 2ece01f373..6990bfa547 100644 --- a/GeneralsMD/Code/GameEngine/Source/Common/NameKeyGenerator.cpp +++ b/GeneralsMD/Code/GameEngine/Source/Common/NameKeyGenerator.cpp @@ -88,7 +88,7 @@ void NameKeyGenerator::freeSockets() } -/* ------------------------------------------------------------------------ */ +//------------------------------------------------------------------------------------------------- inline UnsignedInt calcHashForString(const char* p) { UnsignedInt result = 0; @@ -98,7 +98,7 @@ inline UnsignedInt calcHashForString(const char* p) return result; } -/* ------------------------------------------------------------------------ */ +//------------------------------------------------------------------------------------------------- inline UnsignedInt calcHashForLowercaseString(const char* p) { UnsignedInt result = 0; @@ -164,71 +164,45 @@ NameKeyType NameKeyGenerator::nameToLowercaseKey(const char *name) } //------------------------------------------------------------------------------------------------- -NameKeyType NameKeyGenerator::nameToKeyImpl(const char* nameString) +NameKeyType NameKeyGenerator::nameToKeyImpl(const char* name) { - Bucket *b; - - UnsignedInt hash = calcHashForString(nameString) % SOCKET_COUNT; + const UnsignedInt hash = calcHashForString(name) % SOCKET_COUNT; - // hmm, do we have it already? + // do we have it already? + const Bucket *b; for (b = m_sockets[hash]; b; b = b->m_nextInSocket) { - if (strcmp(nameString, b->m_nameString.str()) == 0) + if (strcmp(name, b->m_nameString.str()) == 0) return b->m_key; } // nope, guess not. let's allocate it. - b = newInstance(Bucket); - b->m_key = (NameKeyType)m_nextID++; - b->m_nameString = nameString; - b->m_nextInSocket = m_sockets[hash]; - m_sockets[hash] = b; - - NameKeyType result = b->m_key; - -#if defined(RTS_DEBUG) - // reality-check to be sure our hasher isn't going bad. - const Int maxThresh = 3; - Int numOverThresh = 0; - for (Int i = 0; i < SOCKET_COUNT; ++i) - { - Int numInThisSocket = 0; - for (b = m_sockets[i]; b; b = b->m_nextInSocket) - ++numInThisSocket; - - if (numInThisSocket > maxThresh) - ++numOverThresh; - } - - // if more than a small percent of the sockets are getting deep, probably want to increase the socket count. - if (numOverThresh > SOCKET_COUNT/20) - { - DEBUG_CRASH(("hmm, might need to increase the number of bucket-sockets for NameKeyGenerator (numOverThresh %d = %f%%)",numOverThresh,(Real)numOverThresh/(Real)(SOCKET_COUNT/20))); - } -#endif - - return result; - + return createNameKey(hash, name); } //------------------------------------------------------------------------------------------------- -NameKeyType NameKeyGenerator::nameToLowercaseKeyImpl(const char* nameString) +NameKeyType NameKeyGenerator::nameToLowercaseKeyImpl(const char* name) { - Bucket *b; + const UnsignedInt hash = calcHashForLowercaseString(name) % SOCKET_COUNT; - UnsignedInt hash = calcHashForLowercaseString(nameString) % SOCKET_COUNT; - - // hmm, do we have it already? + // do we have it already? + const Bucket *b; for (b = m_sockets[hash]; b; b = b->m_nextInSocket) { - if (_stricmp(nameString, b->m_nameString.str()) == 0) + if (_stricmp(name, b->m_nameString.str()) == 0) return b->m_key; } // nope, guess not. let's allocate it. - b = newInstance(Bucket); + return createNameKey(hash, name); +} + +//------------------------------------------------------------------------------------------------- +NameKeyType NameKeyGenerator::createNameKey(UnsignedInt hash, const AsciiString& name) +{ + Bucket *b = newInstance(Bucket); b->m_key = (NameKeyType)m_nextID++; - b->m_nameString = nameString; + b->m_nameString = name; b->m_nextInSocket = m_sockets[hash]; m_sockets[hash] = b; @@ -256,7 +230,6 @@ NameKeyType NameKeyGenerator::nameToLowercaseKeyImpl(const char* nameString) #endif return result; - } //------------------------------------------------------------------------------------------------- diff --git a/GeneralsMD/Code/GameEngine/Source/Common/System/Upgrade.cpp b/GeneralsMD/Code/GameEngine/Source/Common/System/Upgrade.cpp index b93fb4de03..65ff23f91f 100644 --- a/GeneralsMD/Code/GameEngine/Source/Common/System/Upgrade.cpp +++ b/GeneralsMD/Code/GameEngine/Source/Common/System/Upgrade.cpp @@ -293,7 +293,7 @@ void UpgradeCenter::reset( void ) } //------------------------------------------------------------------------------------------------- -/** Find upgrade matching name key */ +/** Find upgrade by veterancy level */ //------------------------------------------------------------------------------------------------- const UpgradeTemplate *UpgradeCenter::findVeterancyUpgrade( VeterancyLevel level ) const { @@ -302,7 +302,7 @@ const UpgradeTemplate *UpgradeCenter::findVeterancyUpgrade( VeterancyLevel level } //------------------------------------------------------------------------------------------------- -/** Find upgrade matching name key */ +/** Find upgrade by name key */ //------------------------------------------------------------------------------------------------- UpgradeTemplate *UpgradeCenter::findNonConstUpgradeByKey( NameKeyType key ) { @@ -329,7 +329,7 @@ UpgradeTemplate *UpgradeCenter::firstUpgradeTemplate( void ) } //------------------------------------------------------------------------------------------------- -/** Find upgrade matching name key */ +/** Find upgrade by name key */ //------------------------------------------------------------------------------------------------- const UpgradeTemplate *UpgradeCenter::findUpgradeByKey( NameKeyType key ) const { @@ -345,13 +345,11 @@ const UpgradeTemplate *UpgradeCenter::findUpgradeByKey( NameKeyType key ) const } //------------------------------------------------------------------------------------------------- -/** Find upgrade matching name */ +/** Find upgrade by name */ //------------------------------------------------------------------------------------------------- const UpgradeTemplate *UpgradeCenter::findUpgrade( const AsciiString& name ) const { - return findUpgradeByKey( TheNameKeyGenerator->nameToKey( name ) ); - } //------------------------------------------------------------------------------------------------- From a0316b9396bdd09fa84d4fafb406e47e5f35f112 Mon Sep 17 00:00:00 2001 From: xezon <4720891+xezon@users.noreply.github.com> Date: Sun, 7 Dec 2025 13:02:13 +0100 Subject: [PATCH 2/2] perf(namekey): Remove all superfluous AsciiString allocations for name key lookups --- .../Code/GameEngine/Include/Common/DamageFX.h | 4 +- .../Include/Common/NameKeyGenerator.h | 6 +- .../Code/GameEngine/Include/Common/Upgrade.h | 1 + .../GameEngine/Include/GameClient/Image.h | 7 ++- .../Code/GameEngine/Include/GameLogic/Armor.h | 4 +- .../GameEngine/Include/GameLogic/Weapon.h | 3 +- .../GameEngine/Source/Common/DamageFX.cpp | 19 ++++-- .../Code/GameEngine/Source/Common/INI/INI.cpp | 4 +- .../Source/Common/INI/INIMappedImage.cpp | 10 +--- .../Source/Common/NameKeyGenerator.cpp | 58 +++++++++++++++++++ .../Source/Common/System/FunctionLexicon.cpp | 2 +- .../Source/Common/System/Upgrade.cpp | 13 ++++- .../GUICallbacks/Menus/DifficultySelect.cpp | 3 +- .../GUI/GUICallbacks/Menus/DownloadMenu.cpp | 3 +- .../Menus/KeyboardOptionsMenu.cpp | 3 +- .../GUICallbacks/Menus/LanMapSelectMenu.cpp | 9 +-- .../GUI/GUICallbacks/Menus/MapSelectMenu.cpp | 12 ++-- .../GUI/GUICallbacks/Menus/OptionsMenu.cpp | 6 +- .../GUICallbacks/Menus/SinglePlayerMenu.cpp | 6 +- .../Menus/SkirmishMapSelectMenu.cpp | 12 ++-- .../GUICallbacks/Menus/WOLMapSelectMenu.cpp | 9 +-- .../GameClient/GUI/GameWindowGlobal.cpp | 2 +- .../GUI/GameWindowManagerScript.cpp | 4 +- .../Source/GameClient/GUI/LoadScreen.cpp | 6 +- .../Source/GameClient/System/Image.cpp | 22 +++++-- .../Source/GameLogic/Object/Armor.cpp | 19 ++++-- .../Object/Upgrade/CommandSetUpgrade.cpp | 2 +- .../Source/GameLogic/Object/Weapon.cpp | 16 ++++- .../GameClient/Drawable/Draw/W3DModelDraw.cpp | 6 +- .../RadioButtonProperties.cpp | 2 +- .../Tools/GUIEdit/Source/LayoutScheme.cpp | 2 +- .../Code/Tools/GUIEdit/Source/Properties.cpp | 2 +- GeneralsMD/Code/Tools/GUIEdit/Source/Save.cpp | 2 +- .../WorldBuilder/src/addplayerdialog.cpp | 3 +- 34 files changed, 189 insertions(+), 93 deletions(-) diff --git a/GeneralsMD/Code/GameEngine/Include/Common/DamageFX.h b/GeneralsMD/Code/GameEngine/Include/Common/DamageFX.h index bca57a3ce7..af9bfadd78 100644 --- a/GeneralsMD/Code/GameEngine/Include/Common/DamageFX.h +++ b/GeneralsMD/Code/GameEngine/Include/Common/DamageFX.h @@ -147,7 +147,9 @@ class DamageFXStore : public SubsystemInterface /** Find the DamageFX with the given name. If no such DamageFX exists, return null. */ - const DamageFX *findDamageFX( AsciiString name ) const; + const DamageFX *findDamageFX( NameKeyType namekey ) const; + const DamageFX *findDamageFX( const AsciiString& name ) const; + const DamageFX *findDamageFX( const char* name ) const; static void parseDamageFXDefinition(INI* ini); diff --git a/GeneralsMD/Code/GameEngine/Include/Common/NameKeyGenerator.h b/GeneralsMD/Code/GameEngine/Include/Common/NameKeyGenerator.h index 86b67e880c..813bf5cfa5 100644 --- a/GeneralsMD/Code/GameEngine/Include/Common/NameKeyGenerator.h +++ b/GeneralsMD/Code/GameEngine/Include/Common/NameKeyGenerator.h @@ -90,8 +90,8 @@ class NameKeyGenerator : public SubsystemInterface virtual void update() { } /// Given a string, convert into a unique integer key. - NameKeyType nameToKey(const AsciiString& name) { return nameToKey(name.str()); } - NameKeyType nameToLowercaseKey(const AsciiString& name) { return nameToLowercaseKey(name.str()); } + NameKeyType nameToKey(const AsciiString& name); + NameKeyType nameToLowercaseKey(const AsciiString& name); /// Given a string, convert into a unique integer key. NameKeyType nameToKey(const char* name); @@ -118,6 +118,8 @@ class NameKeyGenerator : public SubsystemInterface Bool addReservedKey(); #endif + NameKeyType nameToKeyImpl(const AsciiString& name); + NameKeyType nameToLowercaseKeyImpl(const AsciiString& name); NameKeyType nameToKeyImpl(const char* name); NameKeyType nameToLowercaseKeyImpl(const char *name); NameKeyType createNameKey(UnsignedInt hash, const AsciiString& name); diff --git a/GeneralsMD/Code/GameEngine/Include/Common/Upgrade.h b/GeneralsMD/Code/GameEngine/Include/Common/Upgrade.h index 33ce189637..accd45dc04 100644 --- a/GeneralsMD/Code/GameEngine/Include/Common/Upgrade.h +++ b/GeneralsMD/Code/GameEngine/Include/Common/Upgrade.h @@ -238,6 +238,7 @@ class UpgradeCenter : public SubsystemInterface UpgradeTemplate *firstUpgradeTemplate( void ); ///< return the first upgrade template const UpgradeTemplate *findUpgradeByKey( NameKeyType key ) const; ///< find upgrade by name key const UpgradeTemplate *findUpgrade( const AsciiString& name ) const; ///< find and return upgrade by name + const UpgradeTemplate *findUpgrade( const char* name ) const; ///< find and return upgrade by name const UpgradeTemplate *findVeterancyUpgrade(VeterancyLevel level) const; ///< find and return upgrade by veterancy level UpgradeTemplate *newUpgrade( const AsciiString& name ); ///< allocate, link, and return new upgrade diff --git a/GeneralsMD/Code/GameEngine/Include/GameClient/Image.h b/GeneralsMD/Code/GameEngine/Include/GameClient/Image.h index 0714a96bb4..5c791363fd 100644 --- a/GeneralsMD/Code/GameEngine/Include/GameClient/Image.h +++ b/GeneralsMD/Code/GameEngine/Include/GameClient/Image.h @@ -116,6 +116,7 @@ friend class ImageCollection; //------------------------------------------------------------------------------------------------- class ImageCollection : public SubsystemInterface { + typedef std::map ImageMap; public: @@ -128,7 +129,9 @@ class ImageCollection : public SubsystemInterface void load( Int textureSize ); ///< load images + const Image *findImage( NameKeyType namekey ) const; ///< find image based on name key const Image *findImageByName( const AsciiString& name ) const; ///< find image based on name + const Image *findImageByName( const char* name ) const; ///< find image based on name /// adds the given image to the collection, transfers ownership to this object void addImage(Image *image); @@ -136,14 +139,14 @@ class ImageCollection : public SubsystemInterface /// enumerates the list of existing images Image *Enum(unsigned index) { - for (std::map::iterator i=m_imageMap.begin();i!=m_imageMap.end();++i) + for (ImageMap::iterator i=m_imageMap.begin();i!=m_imageMap.end();++i) if (!index--) return i->second; return NULL; } protected: - std::map m_imageMap; ///< maps named keys to images + ImageMap m_imageMap; ///< maps named keys to images }; // INLINING /////////////////////////////////////////////////////////////////////////////////////// diff --git a/GeneralsMD/Code/GameEngine/Include/GameLogic/Armor.h b/GeneralsMD/Code/GameEngine/Include/GameLogic/Armor.h index 8e876d7813..b98b2ba8d9 100644 --- a/GeneralsMD/Code/GameEngine/Include/GameLogic/Armor.h +++ b/GeneralsMD/Code/GameEngine/Include/GameLogic/Armor.h @@ -105,10 +105,12 @@ class ArmorStore : public SubsystemInterface void reset() { } void update() { } + const ArmorTemplate* findArmorTemplate(NameKeyType namekey) const; /** Find the Armor with the given name. If no such Armor exists, return null. */ - const ArmorTemplate* findArmorTemplate(AsciiString name) const; + const ArmorTemplate* findArmorTemplate(const AsciiString& name) const; + const ArmorTemplate* findArmorTemplate(const char* name) const; inline Armor makeArmor(const ArmorTemplate *tmpl) const { diff --git a/GeneralsMD/Code/GameEngine/Include/GameLogic/Weapon.h b/GeneralsMD/Code/GameEngine/Include/GameLogic/Weapon.h index fa608967f4..47f50825da 100644 --- a/GeneralsMD/Code/GameEngine/Include/GameLogic/Weapon.h +++ b/GeneralsMD/Code/GameEngine/Include/GameLogic/Weapon.h @@ -839,7 +839,8 @@ class WeaponStore : public SubsystemInterface /** Find the WeaponTemplate with the given name. If no such WeaponTemplate exists, return null. */ - const WeaponTemplate *findWeaponTemplate(AsciiString name) const; + const WeaponTemplate *findWeaponTemplate(const AsciiString& name) const; + const WeaponTemplate *findWeaponTemplate(const char* name) const; const WeaponTemplate *findWeaponTemplateByNameKey( NameKeyType key ) const { return findWeaponTemplatePrivate( key ); } // this dynamically allocates a new Weapon, which is owned (and must be freed!) by the caller. diff --git a/GeneralsMD/Code/GameEngine/Source/Common/DamageFX.cpp b/GeneralsMD/Code/GameEngine/Source/Common/DamageFX.cpp index 6ba5997c44..8975fa7d60 100644 --- a/GeneralsMD/Code/GameEngine/Source/Common/DamageFX.cpp +++ b/GeneralsMD/Code/GameEngine/Source/Common/DamageFX.cpp @@ -272,11 +272,10 @@ DamageFXStore::~DamageFXStore() } //------------------------------------------------------------------------------------------------- -const DamageFX *DamageFXStore::findDamageFX(AsciiString name) const +const DamageFX *DamageFXStore::findDamageFX(NameKeyType namekey) const { - NameKeyType namekey = TheNameKeyGenerator->nameToKey(name); - DamageFXMap::const_iterator it = m_dfxmap.find(namekey); - if (it == m_dfxmap.end()) + DamageFXMap::const_iterator it = m_dfxmap.find(namekey); + if (it == m_dfxmap.end()) { return NULL; } @@ -286,6 +285,18 @@ const DamageFX *DamageFXStore::findDamageFX(AsciiString name) const } } +//------------------------------------------------------------------------------------------------- +const DamageFX *DamageFXStore::findDamageFX(const AsciiString& name) const +{ + return findDamageFX(TheNameKeyGenerator->nameToKey(name)); +} + +//------------------------------------------------------------------------------------------------- +const DamageFX *DamageFXStore::findDamageFX(const char* name) const +{ + return findDamageFX(TheNameKeyGenerator->nameToKey(name)); +} + //------------------------------------------------------------------------------------------------- void DamageFXStore::init() { diff --git a/GeneralsMD/Code/GameEngine/Source/Common/INI/INI.cpp b/GeneralsMD/Code/GameEngine/Source/Common/INI/INI.cpp index 890eeb4f65..edda2599bf 100644 --- a/GeneralsMD/Code/GameEngine/Source/Common/INI/INI.cpp +++ b/GeneralsMD/Code/GameEngine/Source/Common/INI/INI.cpp @@ -871,7 +871,7 @@ void INI::parseMappedImage( INI *ini, void * /*instance*/, void *store, const vo if( TheMappedImageCollection ) { typedef const Image* ConstImagePtr; - *(ConstImagePtr*)store = TheMappedImageCollection->findImageByName( AsciiString( token ) ); + *(ConstImagePtr*)store = TheMappedImageCollection->findImageByName( token ); } //KM: If we are in the worldbuilder, we want to parse commandbuttons for informational purposes, @@ -1376,7 +1376,7 @@ void INI::parseUpgradeTemplate( INI* ini, void * /*instance*/, void *store, cons throw ERROR_BUG; } - const UpgradeTemplate *uu = TheUpgradeCenter->findUpgrade( AsciiString( token ) ); + const UpgradeTemplate *uu = TheUpgradeCenter->findUpgrade( token ); DEBUG_ASSERTCRASH( uu || stricmp( token, "None" ) == 0, ("Upgrade %s not found!",token) ); typedef const UpgradeTemplate* ConstUpgradeTemplatePtr; diff --git a/GeneralsMD/Code/GameEngine/Source/Common/INI/INIMappedImage.cpp b/GeneralsMD/Code/GameEngine/Source/Common/INI/INIMappedImage.cpp index 159da910fa..f7a4c80154 100644 --- a/GeneralsMD/Code/GameEngine/Source/Common/INI/INIMappedImage.cpp +++ b/GeneralsMD/Code/GameEngine/Source/Common/INI/INIMappedImage.cpp @@ -42,11 +42,8 @@ //------------------------------------------------------------------------------------------------- void INI::parseMappedImageDefinition( INI* ini ) { - AsciiString name; - // read the name - const char* c = ini->getNextToken(); - name.set( c ); + const char* name = ini->getNextToken(); // // find existing item if present, note that we do not support overrides @@ -66,11 +63,10 @@ void INI::parseMappedImageDefinition( INI* ini ) { // image not found, create a new one - image = newInstance(Image); + image = newInstance(Image); image->setName( name ); TheMappedImageCollection->addImage(image); - DEBUG_ASSERTCRASH( image, ("parseMappedImage: unable to allocate image for '%s'", - name.str()) ); + DEBUG_ASSERTCRASH( image, ("parseMappedImage: unable to allocate image for '%s'", name) ); } diff --git a/GeneralsMD/Code/GameEngine/Source/Common/NameKeyGenerator.cpp b/GeneralsMD/Code/GameEngine/Source/Common/NameKeyGenerator.cpp index 6990bfa547..44894061da 100644 --- a/GeneralsMD/Code/GameEngine/Source/Common/NameKeyGenerator.cpp +++ b/GeneralsMD/Code/GameEngine/Source/Common/NameKeyGenerator.cpp @@ -139,6 +139,30 @@ Bool NameKeyGenerator::addReservedKey() } #endif +//------------------------------------------------------------------------------------------------- +NameKeyType NameKeyGenerator::nameToKey(const AsciiString& name) +{ + const NameKeyType key = nameToKeyImpl(name); + +#if RTS_ZEROHOUR && RETAIL_COMPATIBLE_CRC + while (addReservedKey()); +#endif + + return key; +} + +//------------------------------------------------------------------------------------------------- +NameKeyType NameKeyGenerator::nameToLowercaseKey(const AsciiString& name) +{ + const NameKeyType key = nameToLowercaseKeyImpl(name); + +#if RTS_ZEROHOUR && RETAIL_COMPATIBLE_CRC + while (addReservedKey()); +#endif + + return key; +} + //------------------------------------------------------------------------------------------------- NameKeyType NameKeyGenerator::nameToKey(const char* name) { @@ -163,6 +187,40 @@ NameKeyType NameKeyGenerator::nameToLowercaseKey(const char *name) return key; } +//------------------------------------------------------------------------------------------------- +NameKeyType NameKeyGenerator::nameToKeyImpl(const AsciiString& name) +{ + const UnsignedInt hash = calcHashForString(name.str()) % SOCKET_COUNT; + + // do we have it already? + const Bucket *b; + for (b = m_sockets[hash]; b; b = b->m_nextInSocket) + { + if (name.compare(b->m_nameString) == 0) + return b->m_key; + } + + // nope, guess not. let's allocate it. + return createNameKey(hash, name); +} + +//------------------------------------------------------------------------------------------------- +NameKeyType NameKeyGenerator::nameToLowercaseKeyImpl(const AsciiString& name) +{ + const UnsignedInt hash = calcHashForLowercaseString(name.str()) % SOCKET_COUNT; + + // do we have it already? + const Bucket *b; + for (b = m_sockets[hash]; b; b = b->m_nextInSocket) + { + if (name.compareNoCase(b->m_nameString) == 0) + return b->m_key; + } + + // nope, guess not. let's allocate it. + return createNameKey(hash, name); +} + //------------------------------------------------------------------------------------------------- NameKeyType NameKeyGenerator::nameToKeyImpl(const char* name) { diff --git a/GeneralsMD/Code/GameEngine/Source/Common/System/FunctionLexicon.cpp b/GeneralsMD/Code/GameEngine/Source/Common/System/FunctionLexicon.cpp index f922900cd1..3eccb5ef08 100644 --- a/GeneralsMD/Code/GameEngine/Source/Common/System/FunctionLexicon.cpp +++ b/GeneralsMD/Code/GameEngine/Source/Common/System/FunctionLexicon.cpp @@ -395,7 +395,7 @@ void FunctionLexicon::loadTable( TableEntry *table, { // assign key from name key based on name provided in table - entry->key = TheNameKeyGenerator->nameToKey( AsciiString(entry->name) ); + entry->key = TheNameKeyGenerator->nameToKey( entry->name ); // next table entry please entry++; diff --git a/GeneralsMD/Code/GameEngine/Source/Common/System/Upgrade.cpp b/GeneralsMD/Code/GameEngine/Source/Common/System/Upgrade.cpp index 65ff23f91f..1047f7970a 100644 --- a/GeneralsMD/Code/GameEngine/Source/Common/System/Upgrade.cpp +++ b/GeneralsMD/Code/GameEngine/Source/Common/System/Upgrade.cpp @@ -352,6 +352,14 @@ const UpgradeTemplate *UpgradeCenter::findUpgrade( const AsciiString& name ) con return findUpgradeByKey( TheNameKeyGenerator->nameToKey( name ) ); } +//------------------------------------------------------------------------------------------------- +/** Find upgrade by name */ +//------------------------------------------------------------------------------------------------- +const UpgradeTemplate *UpgradeCenter::findUpgrade( const char* name ) const +{ + return findUpgradeByKey( TheNameKeyGenerator->nameToKey( name ) ); +} + //------------------------------------------------------------------------------------------------- /** Allocate a new upgrade template */ //------------------------------------------------------------------------------------------------- @@ -471,8 +479,7 @@ std::vector UpgradeCenter::getUpgradeNames( void ) const void UpgradeCenter::parseUpgradeDefinition( INI *ini ) { // read the name - const char* c = ini->getNextToken(); - AsciiString name = c; + const char* name = ini->getNextToken(); // find existing item if present UpgradeTemplate* upgrade = TheUpgradeCenter->findNonConstUpgradeByKey( NAMEKEY(name) ); @@ -485,7 +492,7 @@ void UpgradeCenter::parseUpgradeDefinition( INI *ini ) } // sanity - DEBUG_ASSERTCRASH( upgrade, ("parseUpgradeDefinition: Unable to allocate upgrade '%s'", name.str()) ); + DEBUG_ASSERTCRASH( upgrade, ("parseUpgradeDefinition: Unable to allocate upgrade '%s'", name) ); // parse the ini definition ini->initFromINI( upgrade, upgrade->getFieldParse() ); diff --git a/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/GUICallbacks/Menus/DifficultySelect.cpp b/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/GUICallbacks/Menus/DifficultySelect.cpp index ae20452c8e..4e8d80624a 100644 --- a/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/GUICallbacks/Menus/DifficultySelect.cpp +++ b/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/GUICallbacks/Menus/DifficultySelect.cpp @@ -125,8 +125,7 @@ static void SetDifficultyRadioButton( void ) void DifficultySelectInit( WindowLayout *layout, void *userData ) { - AsciiString parentName( "DifficultySelect.wnd:DifficultySelectParent" ); - NameKeyType parentID = TheNameKeyGenerator->nameToKey( parentName ); + NameKeyType parentID = TheNameKeyGenerator->nameToKey( "DifficultySelect.wnd:DifficultySelectParent" ); GameWindow *parent = TheWindowManager->winGetWindowFromId( NULL, parentID ); buttonOkID = TheNameKeyGenerator->nameToKey( "DifficultySelect.wnd:ButtonOk" ); diff --git a/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/GUICallbacks/Menus/DownloadMenu.cpp b/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/GUICallbacks/Menus/DownloadMenu.cpp index b1b12b87fe..61a4e89ee7 100644 --- a/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/GUICallbacks/Menus/DownloadMenu.cpp +++ b/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/GUICallbacks/Menus/DownloadMenu.cpp @@ -349,8 +349,7 @@ WindowMsgHandledType DownloadMenuInput( GameWindow *window, UnsignedInt msg, // if( BitIsSet( state, KEY_STATE_UP ) ) { - AsciiString buttonName( "DownloadMenu.wnd:ButtonCancel" ); - NameKeyType buttonID = TheNameKeyGenerator->nameToKey( buttonName ); + NameKeyType buttonID = TheNameKeyGenerator->nameToKey( "DownloadMenu.wnd:ButtonCancel" ); GameWindow *button = TheWindowManager->winGetWindowFromId( window, buttonID ); TheWindowManager->winSendSystemMsg( window, GBM_SELECTED, diff --git a/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/GUICallbacks/Menus/KeyboardOptionsMenu.cpp b/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/GUICallbacks/Menus/KeyboardOptionsMenu.cpp index 9468c4500f..0c466741cc 100644 --- a/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/GUICallbacks/Menus/KeyboardOptionsMenu.cpp +++ b/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/GUICallbacks/Menus/KeyboardOptionsMenu.cpp @@ -499,8 +499,7 @@ WindowMsgHandledType KeyboardOptionsMenuInput( GameWindow *window, UnsignedInt m // if( BitIsSet( state, KEY_STATE_UP ) ) { - AsciiString buttonName( "KeyboardOptionsMenu.wnd:ButtonBack" ); - NameKeyType buttonID = TheNameKeyGenerator->nameToKey( buttonName ); + NameKeyType buttonID = TheNameKeyGenerator->nameToKey( "KeyboardOptionsMenu.wnd:ButtonBack" ); GameWindow *button = TheWindowManager->winGetWindowFromId( window, buttonID ); TheWindowManager->winSendSystemMsg( window, GBM_SELECTED, diff --git a/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/GUICallbacks/Menus/LanMapSelectMenu.cpp b/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/GUICallbacks/Menus/LanMapSelectMenu.cpp index 537352824c..5ff05f9ff1 100644 --- a/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/GUICallbacks/Menus/LanMapSelectMenu.cpp +++ b/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/GUICallbacks/Menus/LanMapSelectMenu.cpp @@ -122,8 +122,7 @@ void LanMapSelectMenuInit( WindowLayout *layout, void *userData ) showLANGameOptionsUnderlyingGUIElements(FALSE); // set keyboard focus to main parent - AsciiString parentName( "LanMapSelectMenu.wnd:LanMapSelectMenuParent" ); - NameKeyType parentID = TheNameKeyGenerator->nameToKey( parentName ); + NameKeyType parentID = TheNameKeyGenerator->nameToKey( "LanMapSelectMenu.wnd:LanMapSelectMenuParent" ); parent = TheWindowManager->winGetWindowFromId( NULL, parentID ); TheWindowManager->winSetFocus( parent ); @@ -165,8 +164,7 @@ void LanMapSelectMenuInit( WindowLayout *layout, void *userData ) } // get the listbox window - AsciiString listString( "LanMapSelectMenu.wnd:ListboxMap" ); - NameKeyType mapListID = TheNameKeyGenerator->nameToKey( listString ); + NameKeyType mapListID = TheNameKeyGenerator->nameToKey( "LanMapSelectMenu.wnd:ListboxMap" ); mapList = TheWindowManager->winGetWindowFromId( parent, mapListID ); if( mapList ) { @@ -228,8 +226,7 @@ WindowMsgHandledType LanMapSelectMenuInput( GameWindow *window, UnsignedInt msg, // if( BitIsSet( state, KEY_STATE_UP ) ) { - AsciiString buttonName( "LanMapSelectMenu.wnd:ButtonBack" ); - NameKeyType buttonID = TheNameKeyGenerator->nameToKey( buttonName ); + NameKeyType buttonID = TheNameKeyGenerator->nameToKey( "LanMapSelectMenu.wnd:ButtonBack" ); GameWindow *button = TheWindowManager->winGetWindowFromId( window, buttonID ); TheWindowManager->winSendSystemMsg( window, GBM_SELECTED, diff --git a/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/GUICallbacks/Menus/MapSelectMenu.cpp b/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/GUICallbacks/Menus/MapSelectMenu.cpp index ca0cf4fe1f..429d921a4f 100644 --- a/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/GUICallbacks/Menus/MapSelectMenu.cpp +++ b/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/GUICallbacks/Menus/MapSelectMenu.cpp @@ -108,8 +108,7 @@ static void shutdownComplete( WindowLayout *layout ) void SetDifficultyRadioButton( void ) { - AsciiString parentName( "MapSelectMenu.wnd:MapSelectMenuParent" ); - NameKeyType parentID = TheNameKeyGenerator->nameToKey( parentName ); + NameKeyType parentID = TheNameKeyGenerator->nameToKey( "MapSelectMenu.wnd:MapSelectMenuParent" ); GameWindow *parent = TheWindowManager->winGetWindowFromId( NULL, parentID ); if (!TheScriptEngine) @@ -171,8 +170,7 @@ void MapSelectMenuInit( WindowLayout *layout, void *userData ) Bool usesSystemMapDir = pref.usesSystemMapDir(); // get the listbox window - AsciiString listString( "MapSelectMenu.wnd:ListboxMap" ); - NameKeyType mapListID = TheNameKeyGenerator->nameToKey( listString ); + NameKeyType mapListID = TheNameKeyGenerator->nameToKey( "MapSelectMenu.wnd:ListboxMap" ); mapList = TheWindowManager->winGetWindowFromId( NULL, mapListID ); if( mapList ) { @@ -183,8 +181,7 @@ void MapSelectMenuInit( WindowLayout *layout, void *userData ) // set keyboard focus to main parent - AsciiString parentName( "MapSelectMenu.wnd:MapSelectMenuParent" ); - NameKeyType parentID = TheNameKeyGenerator->nameToKey( parentName ); + NameKeyType parentID = TheNameKeyGenerator->nameToKey( "MapSelectMenu.wnd:MapSelectMenuParent" ); GameWindow *parent = TheWindowManager->winGetWindowFromId( NULL, parentID ); TheWindowManager->winSetFocus( parent ); @@ -280,8 +277,7 @@ WindowMsgHandledType MapSelectMenuInput( GameWindow *window, UnsignedInt msg, // if( BitIsSet( state, KEY_STATE_UP ) ) { - AsciiString buttonName( "MapSelectMenu.wnd:ButtonBack" ); - NameKeyType buttonID = TheNameKeyGenerator->nameToKey( buttonName ); + NameKeyType buttonID = TheNameKeyGenerator->nameToKey( "MapSelectMenu.wnd:ButtonBack" ); GameWindow *button = TheWindowManager->winGetWindowFromId( window, buttonID ); TheWindowManager->winSendSystemMsg( window, GBM_SELECTED, diff --git a/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/GUICallbacks/Menus/OptionsMenu.cpp b/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/GUICallbacks/Menus/OptionsMenu.cpp index 14d6063f8e..a37446fec3 100644 --- a/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/GUICallbacks/Menus/OptionsMenu.cpp +++ b/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/GUICallbacks/Menus/OptionsMenu.cpp @@ -2117,8 +2117,7 @@ void OptionsMenuInit( WindowLayout *layout, void *userData ) layout->hide( FALSE ); // set keyboard focus to main parent - AsciiString parentName( "OptionsMenu.wnd:OptionsMenuParent" ); - NameKeyType parentID = TheNameKeyGenerator->nameToKey( parentName ); + NameKeyType parentID = TheNameKeyGenerator->nameToKey( "OptionsMenu.wnd:OptionsMenuParent" ); GameWindow *parent = TheWindowManager->winGetWindowFromId( NULL, parentID ); TheWindowManager->winSetFocus( parent ); @@ -2219,8 +2218,7 @@ WindowMsgHandledType OptionsMenuInput( GameWindow *window, UnsignedInt msg, // if( BitIsSet( state, KEY_STATE_UP ) ) { - AsciiString buttonName( "OptionsMenu.wnd:ButtonBack" ); - NameKeyType buttonID = TheNameKeyGenerator->nameToKey( buttonName ); + NameKeyType buttonID = TheNameKeyGenerator->nameToKey( "OptionsMenu.wnd:ButtonBack" ); GameWindow *button = TheWindowManager->winGetWindowFromId( window, buttonID ); TheWindowManager->winSendSystemMsg( window, GBM_SELECTED, diff --git a/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/GUICallbacks/Menus/SinglePlayerMenu.cpp b/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/GUICallbacks/Menus/SinglePlayerMenu.cpp index e30311d80d..5f72983f75 100644 --- a/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/GUICallbacks/Menus/SinglePlayerMenu.cpp +++ b/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/GUICallbacks/Menus/SinglePlayerMenu.cpp @@ -69,8 +69,7 @@ void SinglePlayerMenuInit( WindowLayout *layout, void *userData ) layout->hide( FALSE ); // set keyboard focus to main parent - AsciiString parentName( "SinglePlayerMenu.wnd:SinglePlayerMenuParent" ); - NameKeyType parentID = TheNameKeyGenerator->nameToKey( parentName ); + NameKeyType parentID = TheNameKeyGenerator->nameToKey( "SinglePlayerMenu.wnd:SinglePlayerMenuParent" ); GameWindow *parent = TheWindowManager->winGetWindowFromId( NULL, parentID ); TheWindowManager->winSetFocus( parent ); @@ -155,8 +154,7 @@ WindowMsgHandledType SinglePlayerMenuInput( GameWindow *window, UnsignedInt msg, // if( BitIsSet( state, KEY_STATE_UP ) ) { - AsciiString buttonName( "SinglePlayerMenu.wnd:ButtonBack" ); - NameKeyType buttonID = TheNameKeyGenerator->nameToKey( buttonName ); + NameKeyType buttonID = TheNameKeyGenerator->nameToKey( "SinglePlayerMenu.wnd:ButtonBack" ); GameWindow *button = TheWindowManager->winGetWindowFromId( window, buttonID ); TheWindowManager->winSendSystemMsg( window, GBM_SELECTED, diff --git a/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/GUICallbacks/Menus/SkirmishMapSelectMenu.cpp b/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/GUICallbacks/Menus/SkirmishMapSelectMenu.cpp index 8d66cac120..42ad7642cb 100644 --- a/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/GUICallbacks/Menus/SkirmishMapSelectMenu.cpp +++ b/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/GUICallbacks/Menus/SkirmishMapSelectMenu.cpp @@ -130,8 +130,7 @@ void skirmishPositionStartSpots( void ); void skirmishUpdateSlotList( void ); void showSkirmishGameOptionsUnderlyingGUIElements( Bool show ) { - AsciiString parentName( "SkirmishGameOptionsMenu.wnd:SkirmishGameOptionsMenuParent" ); - NameKeyType parentID = TheNameKeyGenerator->nameToKey( parentName ); + NameKeyType parentID = TheNameKeyGenerator->nameToKey( "SkirmishGameOptionsMenu.wnd:SkirmishGameOptionsMenuParent" ); GameWindow *parent = TheWindowManager->winGetWindowFromId( NULL, parentID ); if (!parent) return; @@ -252,8 +251,7 @@ void SkirmishMapSelectMenuInit( WindowLayout *layout, void *userData ) { // set keyboard focus to main parent - AsciiString parentName( "SkirmishMapSelectMenu.wnd:SkrimishMapSelectMenuParent" ); - NameKeyType parentID = TheNameKeyGenerator->nameToKey( parentName ); + NameKeyType parentID = TheNameKeyGenerator->nameToKey( "SkirmishMapSelectMenu.wnd:SkrimishMapSelectMenuParent" ); parent = TheWindowManager->winGetWindowFromId( NULL, parentID ); TheWindowManager->winSetFocus( parent ); @@ -298,8 +296,7 @@ void SkirmishMapSelectMenuInit( WindowLayout *layout, void *userData ) showSkirmishGameOptionsUnderlyingGUIElements(FALSE); // get the listbox window - AsciiString listString( "SkirmishMapSelectMenu.wnd:ListboxMap" ); - NameKeyType mapListID = TheNameKeyGenerator->nameToKey( listString ); + NameKeyType mapListID = TheNameKeyGenerator->nameToKey( "SkirmishMapSelectMenu.wnd:ListboxMap" ); mapList = TheWindowManager->winGetWindowFromId( parent, mapListID ); if( mapList ) { @@ -372,8 +369,7 @@ WindowMsgHandledType SkirmishMapSelectMenuInput( GameWindow *window, UnsignedInt // if( BitIsSet( state, KEY_STATE_UP ) ) { - AsciiString buttonName( "SkirmishMapSelectMenu.wnd:ButtonBack" ); - NameKeyType buttonID = TheNameKeyGenerator->nameToKey( buttonName ); + NameKeyType buttonID = TheNameKeyGenerator->nameToKey( "SkirmishMapSelectMenu.wnd:ButtonBack" ); GameWindow *button = TheWindowManager->winGetWindowFromId( window, buttonID ); TheWindowManager->winSendSystemMsg( window, GBM_SELECTED, diff --git a/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/GUICallbacks/Menus/WOLMapSelectMenu.cpp b/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/GUICallbacks/Menus/WOLMapSelectMenu.cpp index fffd934564..ea60f55856 100644 --- a/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/GUICallbacks/Menus/WOLMapSelectMenu.cpp +++ b/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/GUICallbacks/Menus/WOLMapSelectMenu.cpp @@ -127,8 +127,7 @@ void WOLMapSelectMenuInit( WindowLayout *layout, void *userData ) { // set keyboard focus to main parent - AsciiString parentName( "WOLMapSelectMenu.wnd:WOLMapSelectMenuParent" ); - NameKeyType parentID = TheNameKeyGenerator->nameToKey( parentName ); + NameKeyType parentID = TheNameKeyGenerator->nameToKey( "WOLMapSelectMenu.wnd:WOLMapSelectMenuParent" ); parent = TheWindowManager->winGetWindowFromId( NULL, parentID ); TheWindowManager->winSetFocus( parent ); @@ -182,8 +181,7 @@ void WOLMapSelectMenuInit( WindowLayout *layout, void *userData ) showGameSpyGameOptionsUnderlyingGUIElements( FALSE ); // get the listbox window - AsciiString listString( "WOLMapSelectMenu.wnd:ListboxMap" ); - NameKeyType mapListID = TheNameKeyGenerator->nameToKey( listString ); + NameKeyType mapListID = TheNameKeyGenerator->nameToKey( "WOLMapSelectMenu.wnd:ListboxMap" ); mapList = TheWindowManager->winGetWindowFromId( parent, mapListID ); if( mapList ) { @@ -254,8 +252,7 @@ WindowMsgHandledType WOLMapSelectMenuInput( GameWindow *window, UnsignedInt msg, // if( BitIsSet( state, KEY_STATE_UP ) ) { - AsciiString buttonName( "WOLMapSelectMenu.wnd:ButtonBack" ); - NameKeyType buttonID = TheNameKeyGenerator->nameToKey( buttonName ); + NameKeyType buttonID = TheNameKeyGenerator->nameToKey( "WOLMapSelectMenu.wnd:ButtonBack" ); GameWindow *button = TheWindowManager->winGetWindowFromId( window, buttonID ); TheWindowManager->winSendSystemMsg( window, GBM_SELECTED, diff --git a/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/GameWindowGlobal.cpp b/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/GameWindowGlobal.cpp index 8125a7c4fb..d0fb42146a 100644 --- a/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/GameWindowGlobal.cpp +++ b/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/GameWindowGlobal.cpp @@ -131,7 +131,7 @@ const Image *GameWindowManager::winFindImage( const char *name ) assert( TheMappedImageCollection ); if( TheMappedImageCollection ) - return TheMappedImageCollection->findImageByName( AsciiString( name ) ); + return TheMappedImageCollection->findImageByName( name ); return NULL; diff --git a/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/GameWindowManagerScript.cpp b/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/GameWindowManagerScript.cpp index 2684dfd832..f5e2871c92 100644 --- a/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/GameWindowManagerScript.cpp +++ b/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/GameWindowManagerScript.cpp @@ -1323,7 +1323,7 @@ static Bool parseDrawData( const char *token, WinInstanceData *instData, c = strtok( NULL, seps ); // value if( strcmp( c, "NoImage" ) ) - drawData->image = TheMappedImageCollection->findImageByName( AsciiString( c ) ); + drawData->image = TheMappedImageCollection->findImageByName( c ); else drawData->image = NULL; // COLOR: R G B A @@ -1652,7 +1652,7 @@ static GameWindow *createGadget( char *type, *c = 0; // terminate after filename (format is filename:gadgetname) assert( TheNameKeyGenerator ); if( TheNameKeyGenerator ) - rData->screen = (Int)(TheNameKeyGenerator->nameToKey( AsciiString(filename) )); + rData->screen = (Int)(TheNameKeyGenerator->nameToKey( filename )); instData->m_style |= GWS_RADIO_BUTTON; window = TheWindowManager->gogoGadgetRadioButton( parent, status, x, y, diff --git a/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/LoadScreen.cpp b/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/LoadScreen.cpp index 19cb7a2aea..ef054982de 100644 --- a/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/LoadScreen.cpp +++ b/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/LoadScreen.cpp @@ -1903,13 +1903,11 @@ void MapTransferLoadScreen::init( GameInfo *game ) Int i; // Load the Filename Text - winName.format( "MapTransferScreen.wnd:StaticTextCurrentFile"); - m_fileNameText = TheWindowManager->winGetWindowFromId( m_loadScreen,TheNameKeyGenerator->nameToKey( winName )); + m_fileNameText = TheWindowManager->winGetWindowFromId( m_loadScreen,TheNameKeyGenerator->nameToKey( "MapTransferScreen.wnd:StaticTextCurrentFile" )); DEBUG_ASSERTCRASH(m_fileNameText, ("Can't initialize the filename for the map transfer loadscreen")); // Load the Timeout Text - winName.format( "MapTransferScreen.wnd:StaticTextTimeout"); - m_timeoutText = TheWindowManager->winGetWindowFromId( m_loadScreen,TheNameKeyGenerator->nameToKey( winName )); + m_timeoutText = TheWindowManager->winGetWindowFromId( m_loadScreen,TheNameKeyGenerator->nameToKey( "MapTransferScreen.wnd:StaticTextTimeout" )); DEBUG_ASSERTCRASH(m_timeoutText, ("Can't initialize the timeout for the map transfer loadscreen")); Int netSlot = 0; diff --git a/GeneralsMD/Code/GameEngine/Source/GameClient/System/Image.cpp b/GeneralsMD/Code/GameEngine/Source/GameClient/System/Image.cpp index bcd7b6f79c..a701c03790 100644 --- a/GeneralsMD/Code/GameEngine/Source/GameClient/System/Image.cpp +++ b/GeneralsMD/Code/GameEngine/Source/GameClient/System/Image.cpp @@ -204,7 +204,7 @@ ImageCollection::ImageCollection( void ) //------------------------------------------------------------------------------------------------- ImageCollection::~ImageCollection( void ) { - for (std::map::iterator i=m_imageMap.begin();i!=m_imageMap.end();++i) + for (ImageMap::iterator i=m_imageMap.begin();i!=m_imageMap.end();++i) deleteInstance(i->second); } @@ -216,13 +216,27 @@ void ImageCollection::addImage( Image *image ) m_imageMap[TheNameKeyGenerator->nameToLowercaseKey(image->getName())]=image; } +//------------------------------------------------------------------------------------------------- +const Image *ImageCollection::findImage( NameKeyType namekey ) const +{ + ImageMap::const_iterator i = m_imageMap.find(namekey); + return i == m_imageMap.end() ? NULL : i->second; +} + +//------------------------------------------------------------------------------------------------- +/** Find an image given the image name */ +//------------------------------------------------------------------------------------------------- +const Image *ImageCollection::findImageByName( const AsciiString& name ) const +{ + return findImage(TheNameKeyGenerator->nameToLowercaseKey(name)); +} + //------------------------------------------------------------------------------------------------- /** Find an image given the image name */ //------------------------------------------------------------------------------------------------- -const Image *ImageCollection::findImageByName( const AsciiString& name ) +const Image *ImageCollection::findImageByName( const char* name ) const { - std::map::iterator i=m_imageMap.find(TheNameKeyGenerator->nameToLowercaseKey(name)); - return i==m_imageMap.end()?NULL:i->second; + return findImage(TheNameKeyGenerator->nameToLowercaseKey(name)); } //------------------------------------------------------------------------------------------------- diff --git a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Armor.cpp b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Armor.cpp index a313d54b67..6d4578d197 100644 --- a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Armor.cpp +++ b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Armor.cpp @@ -116,11 +116,10 @@ ArmorStore::~ArmorStore() } //------------------------------------------------------------------------------------------------- -const ArmorTemplate* ArmorStore::findArmorTemplate(AsciiString name) const +const ArmorTemplate* ArmorStore::findArmorTemplate(NameKeyType namekey) const { - NameKeyType namekey = TheNameKeyGenerator->nameToKey(name); - ArmorTemplateMap::const_iterator it = m_armorTemplates.find(namekey); - if (it == m_armorTemplates.end()) + ArmorTemplateMap::const_iterator it = m_armorTemplates.find(namekey); + if (it == m_armorTemplates.end()) { return NULL; } @@ -130,6 +129,18 @@ const ArmorTemplate* ArmorStore::findArmorTemplate(AsciiString name) const } } +//------------------------------------------------------------------------------------------------- +const ArmorTemplate* ArmorStore::findArmorTemplate(const AsciiString& name) const +{ + return findArmorTemplate(TheNameKeyGenerator->nameToKey(name)); +} + +//------------------------------------------------------------------------------------------------- +const ArmorTemplate* ArmorStore::findArmorTemplate(const char* name) const +{ + return findArmorTemplate(TheNameKeyGenerator->nameToKey(name)); +} + //------------------------------------------------------------------------------------------------- /*static */ void ArmorStore::parseArmorDefinition(INI *ini) { diff --git a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Upgrade/CommandSetUpgrade.cpp b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Upgrade/CommandSetUpgrade.cpp index 7d0286eb18..56c7b3b76b 100644 --- a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Upgrade/CommandSetUpgrade.cpp +++ b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Upgrade/CommandSetUpgrade.cpp @@ -68,7 +68,7 @@ void CommandSetUpgrade::upgradeImplementation( ) { Object *obj = getObject(); - const char * upgradeAlt = getCommandSetUpgradeModuleData()->m_triggerAlt.str(); + const AsciiString& upgradeAlt = getCommandSetUpgradeModuleData()->m_triggerAlt; const UpgradeTemplate *upgradeTemplate = TheUpgradeCenter->findUpgrade( upgradeAlt ); if (upgradeTemplate) diff --git a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Weapon.cpp b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Weapon.cpp index d9b9431ad8..5d700cbb1f 100644 --- a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Weapon.cpp +++ b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Weapon.cpp @@ -1622,12 +1622,22 @@ void WeaponStore::createAndFireTempWeapon(const WeaponTemplate* wt, const Object } //------------------------------------------------------------------------------------------------- -const WeaponTemplate *WeaponStore::findWeaponTemplate( AsciiString name ) const +const WeaponTemplate *WeaponStore::findWeaponTemplate( const AsciiString& name ) const { - if (stricmp(name.str(), "None") == 0) + if (name.compareNoCase("None") == 0) return NULL; const WeaponTemplate * wt = findWeaponTemplatePrivate( TheNameKeyGenerator->nameToKey( name ) ); - DEBUG_ASSERTCRASH(wt != NULL, ("Weapon %s not found!",name.str())); + DEBUG_ASSERTCRASH(wt != NULL, ("Weapon %s not found!",name)); + return wt; +} + +//------------------------------------------------------------------------------------------------- +const WeaponTemplate *WeaponStore::findWeaponTemplate( const char* name ) const +{ + if (stricmp(name, "None") == 0) + return NULL; + const WeaponTemplate * wt = findWeaponTemplatePrivate( TheNameKeyGenerator->nameToKey( name ) ); + DEBUG_ASSERTCRASH(wt != NULL, ("Weapon %s not found!",name)); return wt; } diff --git a/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/Drawable/Draw/W3DModelDraw.cpp b/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/Drawable/Draw/W3DModelDraw.cpp index 469b401b45..d7ca602a5a 100644 --- a/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/Drawable/Draw/W3DModelDraw.cpp +++ b/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/Drawable/Draw/W3DModelDraw.cpp @@ -1490,8 +1490,10 @@ void W3DModelDrawModuleData::parseConditionState(INI* ini, void *instance, void case PARSE_TRANSITION: { - AsciiString firstNm = ini->getNextToken(); firstNm.toLower(); - AsciiString secondNm = ini->getNextToken(); secondNm.toLower(); + AsciiString firstNm = ini->getNextToken(); + AsciiString secondNm = ini->getNextToken(); + firstNm.toLower(); + secondNm.toLower(); NameKeyType firstKey = NAMEKEY(firstNm); NameKeyType secondKey = NAMEKEY(secondNm); diff --git a/GeneralsMD/Code/Tools/GUIEdit/Source/Dialog Procedures/RadioButtonProperties.cpp b/GeneralsMD/Code/Tools/GUIEdit/Source/Dialog Procedures/RadioButtonProperties.cpp index 5695ad0781..524f483be8 100644 --- a/GeneralsMD/Code/Tools/GUIEdit/Source/Dialog Procedures/RadioButtonProperties.cpp +++ b/GeneralsMD/Code/Tools/GUIEdit/Source/Dialog Procedures/RadioButtonProperties.cpp @@ -177,7 +177,7 @@ static LRESULT CALLBACK radioButtonPropertiesCallback( HWND hWndDialog, // save group Int group = GetDlgItemInt( hWndDialog, COMBO_GROUP, NULL, FALSE ); - Int screen = TheNameKeyGenerator->nameToKey( AsciiString(TheEditor->getSaveFilename()) ); + Int screen = TheNameKeyGenerator->nameToKey( TheEditor->getSaveFilename() ); GadgetRadioSetGroup( window, group, screen ); } diff --git a/GeneralsMD/Code/Tools/GUIEdit/Source/LayoutScheme.cpp b/GeneralsMD/Code/Tools/GUIEdit/Source/LayoutScheme.cpp index 5e828d1837..bb83dbe0d3 100644 --- a/GeneralsMD/Code/Tools/GUIEdit/Source/LayoutScheme.cpp +++ b/GeneralsMD/Code/Tools/GUIEdit/Source/LayoutScheme.cpp @@ -2433,7 +2433,7 @@ Bool LayoutScheme::loadScheme( char *filename ) // store the info storeImageAndColor( (StateIdentifier)state, - TheMappedImageCollection->findImageByName( AsciiString( imageBuffer ) ), + TheMappedImageCollection->findImageByName( imageBuffer ), GameMakeColor( colorR, colorG, colorB, colorA ), GameMakeColor( bColorR, bColorG, bColorB, bColorA ) ); } diff --git a/GeneralsMD/Code/Tools/GUIEdit/Source/Properties.cpp b/GeneralsMD/Code/Tools/GUIEdit/Source/Properties.cpp index f5c1815382..1b6c26daf0 100644 --- a/GeneralsMD/Code/Tools/GUIEdit/Source/Properties.cpp +++ b/GeneralsMD/Code/Tools/GUIEdit/Source/Properties.cpp @@ -1258,7 +1258,7 @@ const Image *ComboBoxSelectionToImage( HWND comboBox ) SendMessage( comboBox, CB_GETLBTEXT, selected, (LPARAM)buffer ); // return the image loc that matches the string - return TheMappedImageCollection->findImageByName( AsciiString( buffer ) ); + return TheMappedImageCollection->findImageByName( buffer ); } diff --git a/GeneralsMD/Code/Tools/GUIEdit/Source/Save.cpp b/GeneralsMD/Code/Tools/GUIEdit/Source/Save.cpp index 02f7e27f3d..7849582e6b 100644 --- a/GeneralsMD/Code/Tools/GUIEdit/Source/Save.cpp +++ b/GeneralsMD/Code/Tools/GUIEdit/Source/Save.cpp @@ -1235,7 +1235,7 @@ Bool GUIEdit::saveData( char *filePathAndFilename, char *filename ) // update all radio button screen identifiers with the filename updateRadioScreenIdentifiers( TheWindowManager->winGetWindowList(), - TheNameKeyGenerator->nameToKey( AsciiString(m_saveFilename) ) ); + TheNameKeyGenerator->nameToKey( m_saveFilename ) ); // open the file fp = fopen( filePathAndFilename, "w" ); diff --git a/GeneralsMD/Code/Tools/WorldBuilder/src/addplayerdialog.cpp b/GeneralsMD/Code/Tools/WorldBuilder/src/addplayerdialog.cpp index bf608910a0..21e6149dc0 100644 --- a/GeneralsMD/Code/Tools/WorldBuilder/src/addplayerdialog.cpp +++ b/GeneralsMD/Code/Tools/WorldBuilder/src/addplayerdialog.cpp @@ -76,9 +76,8 @@ void AddPlayerDialog::OnOK() } else { faction->GetWindowText(theText); } - AsciiString name((LPCTSTR)theText); - const PlayerTemplate* pt = ThePlayerTemplateStore->findPlayerTemplate(NAMEKEY(name)); + const PlayerTemplate* pt = ThePlayerTemplateStore->findPlayerTemplate(NAMEKEY((LPCTSTR)theText)); if (pt) { m_addedSide = pt ? pt->getName() : AsciiString::TheEmptyString;