fix BGAnimation doesn't load <children>

fix BGAnimation in Background leaks children
This commit is contained in:
Chris Danford
2005-03-01 16:59:29 +00:00
parent bcce4df6f7
commit 63868cee5e
6 changed files with 58 additions and 27 deletions
+21 -25
View File
@@ -19,31 +19,6 @@ LUA_REGISTER_CLASS( ActorFrame )
* that string instead create an ActorFrameAutoDeleteChildren object.
*/
//REGISTER_ACTOR_CLASS( ActorFrame )
class ActorFrameAutoDeleteChildren : public ActorFrame
{
public:
ActorFrameAutoDeleteChildren() { DeleteChildrenWhenDone(true); }
void LoadFromNode( const CString& sDir, const XNode* pNode )
{
ActorFrame::LoadFromNode( sDir, pNode );
//
// Load children
//
const XNode* pChildren = pNode->GetChild("children");
if( pChildren )
{
FOREACH_CONST_Child( pChildren, pChild )
{
Actor* pChildActor = ActorUtil::LoadFromActorFile( sDir, pChild );
if( pChildActor )
AddChild( pChildActor );
}
SortByDrawOrder();
}
}
};
REGISTER_ACTOR_CLASS_WITH_NAME( ActorFrameAutoDeleteChildren, ActorFrame )
@@ -72,6 +47,27 @@ void ActorFrame::LoadFromNode( const CString& sDir, const XNode* pNode )
m_bOverrideLighting = pNode->GetAttrValue( "Lighting", m_bLighting );
}
void ActorFrame::LoadChildrenFromNode( const CString& sDir, const XNode* pNode )
{
// Shoudn't be calling this unless we're going to delete our children.
ASSERT( m_bDeleteChildren );
//
// Load children
//
const XNode* pChildren = pNode->GetChild("children");
if( pChildren )
{
FOREACH_CONST_Child( pChildren, pChild )
{
Actor* pChildActor = ActorUtil::LoadFromActorFile( sDir, pChild );
if( pChildActor )
AddChild( pChildActor );
}
SortByDrawOrder();
}
}
void ActorFrame::AddChild( Actor* pActor )
{
#if _DEBUG
+13
View File
@@ -27,6 +27,7 @@ public:
virtual ~ActorFrame();
void LoadFromNode( const CString& sDir, const XNode* pNode );
void LoadChildrenFromNode( const CString& sDir, const XNode* pNode );
virtual void AddChild( Actor* pActor );
virtual void RemoveChild( Actor* pActor );
@@ -79,6 +80,18 @@ protected:
bool m_bLighting;
};
class ActorFrameAutoDeleteChildren : public ActorFrame
{
public:
ActorFrameAutoDeleteChildren() { DeleteChildrenWhenDone(true); }
void LoadFromNode( const CString& sDir, const XNode* pNode )
{
ActorFrame::LoadFromNode( sDir, pNode );
LoadChildrenFromNode( sDir, pNode );
}
};
#endif
/*
+10
View File
@@ -6,6 +6,16 @@
#include "IniFile.h"
#include "arch/Dialog/Dialog.h"
#include "RageLog.h"
#include "ActorUtil.h"
/* Tricky: We need ActorFrames created in XML to auto delete their children.
* We don't want classes that derive from ActorFrame to auto delete their
* children. The name "ActorFrame" is widely used in XML, so we'll have
* that string instead create an ActorFrameAutoDeleteChildren object.
*/
//REGISTER_ACTOR_CLASS( ActorScroller )
REGISTER_ACTOR_CLASS_WITH_NAME( ActorScrollerAutoDeleteChildren, ActorScroller )
ActorScroller::ActorScroller()
{
+12
View File
@@ -46,6 +46,18 @@ protected:
RageVector3 m_vTranslateTerm2;
};
class ActorScrollerAutoDeleteChildren : public ActorScroller
{
public:
ActorScrollerAutoDeleteChildren() { DeleteChildrenWhenDone(true); }
void LoadFromNode( const CString& sDir, const XNode* pNode )
{
ActorScroller::LoadFromNode( sDir, pNode );
LoadChildrenFromNode( sDir, pNode );
}
};
#endif
/*
+1 -1
View File
@@ -181,7 +181,7 @@ void BGAnimation::LoadFromNode( const CString& sDir, const XNode* pNode )
{
DEBUG_ASSERT( pNode->m_sName == "BGAnimation" );
ActorScroller::LoadFromNode( sDir, pNode );
ActorScrollerAutoDeleteChildren::LoadFromNode( sDir, pNode );
this->RunCommandsOnChildren( ActorCommands("PlayCommand,Init") );
+1 -1
View File
@@ -10,7 +10,7 @@
struct XNode;
class IniFile;
class BGAnimation : public ActorScroller
class BGAnimation : public ActorScrollerAutoDeleteChildren
{
public:
BGAnimation();