Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion GeneralsMD/Code/GameEngine/Include/Common/DamageFX.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
49 changes: 24 additions & 25 deletions GeneralsMD/Code/GameEngine/Include/Common/NameKeyGenerator.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,22 +36,20 @@
#include "Common/AsciiString.h"

//-------------------------------------------------------------------------------------------------
/**

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a particular reason why removing /**? A quick search yields its applied over 9,000 in the code. Do we want to fix it everywhere?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am in favor of replacing all block comments with inline comments. It caused syntax coloring issues in Visual Studio.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've created a task for that.

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
{
Expand All @@ -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
{
Expand All @@ -92,23 +90,21 @@ 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);
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:

Expand All @@ -122,8 +118,11 @@ 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);

void freeSockets();

Expand Down
9 changes: 5 additions & 4 deletions GeneralsMD/Code/GameEngine/Include/Common/Upgrade.h
Original file line number Diff line number Diff line change
Expand Up @@ -235,10 +235,11 @@ 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 *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

Expand Down
9 changes: 6 additions & 3 deletions GeneralsMD/Code/GameEngine/Include/GameClient/Image.h
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@ friend class ImageCollection;
//-------------------------------------------------------------------------------------------------
class ImageCollection : public SubsystemInterface
{
typedef std::map<NameKeyType, Image *> ImageMap;

public:

Expand All @@ -128,22 +129,24 @@ class ImageCollection : public SubsystemInterface

void load( Int textureSize ); ///< load images

const Image *findImageByName( const AsciiString& name ); ///< find image based on name
const Image *findImage( NameKeyType namekey ) const; ///< find image based on name key
const Image *findImageByName( const AsciiString& name ) const; ///< find image based on name
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this looks wrong in isolation. Would make first commit fail compile.

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);

/// enumerates the list of existing images
Image *Enum(unsigned index)
{
for (std::map<unsigned,Image *>::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<unsigned,Image *> m_imageMap; ///< maps named keys to images
ImageMap m_imageMap; ///< maps named keys to images
};

// INLINING ///////////////////////////////////////////////////////////////////////////////////////
Expand Down
4 changes: 3 additions & 1 deletion GeneralsMD/Code/GameEngine/Include/GameLogic/Armor.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down
3 changes: 2 additions & 1 deletion GeneralsMD/Code/GameEngine/Include/GameLogic/Weapon.h
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
19 changes: 15 additions & 4 deletions GeneralsMD/Code/GameEngine/Source/Common/DamageFX.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand All @@ -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()
{
Expand Down
4 changes: 2 additions & 2 deletions GeneralsMD/Code/GameEngine/Source/Common/INI/INI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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;
Expand Down
10 changes: 3 additions & 7 deletions GeneralsMD/Code/GameEngine/Source/Common/INI/INIMappedImage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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) );

}

Expand Down
Loading
Loading