From 77f9d23d0fff01ab8d519359d2fed224e150b190 Mon Sep 17 00:00:00 2001 From: Matei Date: Sat, 13 Jan 2007 20:14:03 +0000 Subject: [PATCH] Added m_SoundGroupTable in CEntityTemplate to allow the soundgroup file for each animation to be specified in XML. This was SVN commit r4769. --- source/simulation/EntityStateProcessing.cpp | 4 ++ source/simulation/EntityTemplate.cpp | 72 +++++++++++++-------- source/simulation/EntityTemplate.h | 4 ++ 3 files changed, 54 insertions(+), 26 deletions(-) diff --git a/source/simulation/EntityStateProcessing.cpp b/source/simulation/EntityStateProcessing.cpp index 63f5052203..28973e8b4c 100644 --- a/source/simulation/EntityStateProcessing.cpp +++ b/source/simulation/EntityStateProcessing.cpp @@ -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 diff --git a/source/simulation/EntityTemplate.cpp b/source/simulation/EntityTemplate.cpp index 5aa440a8d3..9753b88a8a 100644 --- a/source/simulation/EntityTemplate.cpp +++ b/source/simulation/EntityTemplate.cpp @@ -13,6 +13,31 @@ STL_HASH_SET 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; im_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 SoundGroupTable; + SoundGroupTable m_SoundGroupTable; //SP properties float m_staminaMax;