set parent before calling LoadFromNode
This commit is contained in:
@@ -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<RString,CreateActorFn>::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\"",
|
||||
|
||||
@@ -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 );
|
||||
|
||||
|
||||
Reference in New Issue
Block a user