Added m_SoundGroupTable in CEntityTemplate to allow the soundgroup file for each animation to be specified in XML.

This was SVN commit r4769.
This commit is contained in:
Matei
2007-01-13 20:14:03 +00:00
parent e505843bb6
commit 77f9d23d0f
3 changed files with 54 additions and 26 deletions
@@ -439,6 +439,10 @@ bool CEntity::processContactActionNoPathing( CEntityOrder* current, size_t times
if( ( m_fsm_cyclepos <= action->m_Speed ) && ( nextpos > action->m_Speed ) )
{
m_actor->HideAmmunition();
// TODO: Play a sound here. Use m_base->m_SoundGroupTable[animation] to get the
// name of the soundgroup XML file to play.
if(!DispatchEvent( contactEvent ))
{
// Cancel current order
+46 -26
View File
@@ -13,6 +13,31 @@
STL_HASH_SET<CStr, CStr_hash_compare> CEntityTemplate::scriptsLoaded;
// Utility functions used in reading XML
namespace {
/**
* Converts the given string, consisting of underscores and letters,
* to camelCase: the first letter of each underscore-separated "word"
* is changed to lowercase. For example, the string MiniMap_Colour
* is converted to miniMap_colour.
*
* @param const std::string & str The string to convert.
* @return std::string The given string in camelCase.
**/
std::string toCamelCase( const std::string& str )
{
std::string ret = str;
for( size_t i=0; i<ret.size(); i++ )
{
if( i==0 || ret[i-1] == '_' )
{
ret[i] = tolower( ret[i] );
}
}
return ret;
}
}
CEntityTemplate::CEntityTemplate( CPlayer* player )
{
m_player = player;
@@ -61,7 +86,7 @@ CEntityTemplate::~CEntityTemplate()
void CEntityTemplate::loadBase()
{
// Don't bother if we're providing a replacement.
// Copy the parent's bounds, unless we're providing a replacement.
if( m_bound_type == CBoundingObject::BOUND_NONE )
{
if( m_base->m_bound_type == CBoundingObject::BOUND_CIRCLE )
@@ -79,6 +104,13 @@ void CEntityTemplate::loadBase()
m_bound_type = m_base->m_bound_type;
}
// Initialize sound group table from the parent's sound group table
for(SoundGroupTable::iterator it = m_base->m_SoundGroupTable.begin();
it != m_base->m_SoundGroupTable.end(); ++it)
{
m_SoundGroupTable[it->first] = it->second;
}
SetBase( m_base );
m_classes.SetParent( &( m_base->m_classes ) );
SetNextObject( m_base );
@@ -126,6 +158,7 @@ bool CEntityTemplate::loadXML( const CStr& filename )
EL(Height);
EL(Radius);
EL(Width);
EL(SoundGroups);
AT(Parent);
AT(On);
AT(File);
@@ -278,6 +311,18 @@ bool CEntityTemplate::loadXML( const CStr& filename )
}
}
}
else if( ChildName == el_SoundGroups )
{
// Read every child element's value into m_SoundGroupTable with its tag as the key
XMBElementList children = Child.getChildNodes();
for(int j = 0; j < children.Count; ++j)
{
XMBElement child = children.item(j);
CStr8 name = toCamelCase( XeroFile.getElementString( child.getNodeName() ) );
CStr8 value = child.getText();
m_SoundGroupTable[name] = value;
}
}
else
{
XMLLoadProperty( XeroFile, Child, CStrW() );
@@ -297,31 +342,6 @@ bool CEntityTemplate::loadXML( const CStr& filename )
return true;
}
/**
* Converts the given string, consisting of underscores and letters,
* to camelCase: the first letter of each underscore-separated "word"
* is changed to lowercase. For example, the string MiniMap_Colour
* is converted to miniMap_colour. This is consistent with the
* previous casing of entity attributes (all lowercase, with words
* separated by underscores), while allowing us to switch over to
* camelCase identifiers.
*
* @param const std::string & str The string to convert.
* @return std::string The given string in camelCase.
**/
std::string toCamelCase( const std::string& str )
{
std::string ret = str;
for( size_t i=0; i<ret.size(); i++ )
{
if( i==0 || ret[i-1] == '_' )
{
ret[i] = tolower( ret[i] );
}
}
return ret;
}
void CEntityTemplate::XMLLoadProperty( const CXeromyces& XeroFile, const XMBElement& Source, const CStrW& BasePropertyName )
{
// Add a property, put the node text into it.
+4
View File
@@ -62,6 +62,10 @@ public:
CBoundingCircle* m_bound_circle;
CBoundingBox* m_bound_box;
CBoundingObject::EBoundingType m_bound_type;
// Sound properties
typedef STL_HASH_MAP<CStr8, CStr8, CStrW_hash_compare> SoundGroupTable;
SoundGroupTable m_SoundGroupTable;
//SP properties
float m_staminaMax;