From 8af826fc3f83d8b2a4bf057ba176dc033f8d5a2b Mon Sep 17 00:00:00 2001 From: Glenn Maynard Date: Tue, 15 Aug 2006 19:25:45 +0000 Subject: [PATCH] set parent before calling LoadFromNode --- stepmania/src/ActorUtil.cpp | 16 ++++++++-------- stepmania/src/ActorUtil.h | 12 +++++++----- 2 files changed, 15 insertions(+), 13 deletions(-) diff --git a/stepmania/src/ActorUtil.cpp b/stepmania/src/ActorUtil.cpp index 3c9262d83b..34e75c7248 100644 --- a/stepmania/src/ActorUtil.cpp +++ b/stepmania/src/ActorUtil.cpp @@ -35,13 +35,13 @@ void ActorUtil::Register( const RString& sClassName, CreateActorFn pfn ) (*g_pmapRegistrees)[sClassName] = pfn; } -Actor* ActorUtil::Create( const RString& sClassName, const RString& sDir, const XNode* pNode ) +Actor* ActorUtil::Create( const RString& sClassName, const RString& sDir, const XNode* pNode, Actor *pParentActor ) { map::iterator iter = g_pmapRegistrees->find( sClassName ); ASSERT_M( iter != g_pmapRegistrees->end(), ssprintf("Actor '%s' is not registered.",sClassName.c_str()) ); CreateActorFn pfn = iter->second; - return (*pfn)( sDir, pNode ); + return (*pfn)( sDir, pNode, pParentActor ); } void ActorUtil::ResolvePath( RString &sPath, const RString &sName ) @@ -173,7 +173,7 @@ void ActorUtil::GetParam( Lua *L, const RString &sName ) } } -Actor* ActorUtil::LoadFromNode( const RString& sDir, const XNode* pNode ) +Actor* ActorUtil::LoadFromNode( const RString& sDir, const XNode* pNode, Actor *pParentActor ) { ASSERT( pNode ); @@ -241,7 +241,7 @@ Actor* ActorUtil::LoadFromNode( const RString& sDir, const XNode* pNode ) if( IsRegistered(sClass) ) { - pReturn = ActorUtil::Create( sClass, sDir, pNode ); + pReturn = ActorUtil::Create( sClass, sDir, pNode, pParentActor ); } else // sClass is empty or garbage (e.g. "1" or "0 // 0==Sprite") { @@ -268,7 +268,7 @@ Actor* ActorUtil::LoadFromNode( const RString& sDir, const XNode* pNode ) ActorUtil::ResolvePath( sNewPath, sDir ); - pReturn = ActorUtil::MakeActor( sNewPath, pNode ); + pReturn = ActorUtil::MakeActor( sNewPath, pNode, pParentActor ); if( pReturn == NULL ) goto all_done; } @@ -333,7 +333,7 @@ static void MergeActorXML( XNode *pChild, const XNode *pParent ) * If pParent is non-NULL, it's the parent node when nesting XML, which is * used only by ActorUtil::LoadFromNode. */ -Actor* ActorUtil::MakeActor( const RString &sPath_, const XNode *pParent ) +Actor* ActorUtil::MakeActor( const RString &sPath_, const XNode *pParent, Actor *pParentActor ) { static const XNode dummy; if( pParent == NULL ) @@ -383,7 +383,7 @@ Actor* ActorUtil::MakeActor( const RString &sPath_, const XNode *pParent ) XNode xml( *pParent ); xml.AppendAttr( "Texture", sPath ); - return ActorUtil::Create( "Sprite", sDir, &xml ); + return ActorUtil::Create( "Sprite", sDir, &xml, pParentActor ); } case FT_Model: { @@ -392,7 +392,7 @@ Actor* ActorUtil::MakeActor( const RString &sPath_, const XNode *pParent ) xml.AppendAttr( "Materials", sPath ); xml.AppendAttr( "Bones", sPath ); - return ActorUtil::Create( "Model", sDir, &xml ); + return ActorUtil::Create( "Model", sDir, &xml, pParentActor ); } default: RageException::Throw("File \"%s\" has unknown type, \"%s\"", diff --git a/stepmania/src/ActorUtil.h b/stepmania/src/ActorUtil.h index 881f8b1095..6c17d8bbd0 100644 --- a/stepmania/src/ActorUtil.h +++ b/stepmania/src/ActorUtil.h @@ -8,12 +8,14 @@ class XNode; -typedef Actor* (*CreateActorFn)(const RString& sDir, const XNode* pNode); +typedef Actor* (*CreateActorFn)(const RString& sDir, const XNode* pNode, Actor* pParent); // Each Actor class should have a REGISTER_ACTOR_CLASS in its CPP file. #define REGISTER_ACTOR_CLASS_WITH_NAME( className, externalClassName ) \ - Actor* Create##className(const RString& sDir, const XNode* pNode) { \ + Actor* Create##className(const RString& sDir, const XNode* pNode, Actor* pParent) { \ className *pRet = new className; \ + if( pParent ) \ + pRet->SetParent( pParent ); \ pRet->LoadFromNode(sDir, pNode); \ return pRet; } \ class Register##className { \ @@ -41,7 +43,7 @@ namespace ActorUtil { // Every screen should register its class at program initialization. void Register( const RString& sClassName, CreateActorFn pfn ); - Actor* Create( const RString& sClassName, const RString& sDir, const XNode* pNode ); + Actor* Create( const RString& sClassName, const RString& sDir, const XNode* pNode, Actor *pParentActor ); void SetXY( Actor& actor, const RString &sType ); @@ -66,8 +68,8 @@ namespace ActorUtil inline void SetXYAndOnCommand( Actor* pActor, const RString &sType ) { if(pActor) SetXYAndOnCommand( *pActor, sType ); } // Return a Sprite, BitmapText, or Model depending on the file type - Actor* LoadFromNode( const RString& sAniDir, const XNode* pNode ); - Actor* MakeActor( const RString &sPath, const XNode *pParent = NULL ); + Actor* LoadFromNode( const RString& sAniDir, const XNode* pNode, Actor *pParentActor = NULL ); + Actor* MakeActor( const RString &sPath, const XNode *pParent = NULL, Actor *pParentActor = NULL ); void ResolvePath( RString &sPath, const RString &sName );