From 1c372a918cb48ad2d3c3b656510cb3311d8ffbd5 Mon Sep 17 00:00:00 2001 From: Glenn Maynard Date: Wed, 11 Oct 2006 07:33:38 +0000 Subject: [PATCH] move code out of macro move common code into ActorUtil::Create --- stepmania/src/ActorUtil.cpp | 10 ++++++++-- stepmania/src/ActorUtil.h | 16 ++++++---------- 2 files changed, 14 insertions(+), 12 deletions(-) diff --git a/stepmania/src/ActorUtil.cpp b/stepmania/src/ActorUtil.cpp index b66f46132f..df82e5d197 100644 --- a/stepmania/src/ActorUtil.cpp +++ b/stepmania/src/ActorUtil.cpp @@ -40,8 +40,14 @@ Actor* ActorUtil::Create( const RString& sClassName, const XNode* pNode, Actor * 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)( pNode, pParentActor ); + const CreateActorFn &pfn = iter->second; + Actor *pRet = pfn(); + + if( pParentActor ) + pRet->SetParent( pParentActor ); + + pRet->LoadFromNode( pNode ); + return pRet; } void ActorUtil::ResolvePath( RString &sPath, const RString &sName ) diff --git a/stepmania/src/ActorUtil.h b/stepmania/src/ActorUtil.h index 757b90bbbe..e785c1cf8a 100644 --- a/stepmania/src/ActorUtil.h +++ b/stepmania/src/ActorUtil.h @@ -8,19 +8,15 @@ class XNode; -typedef Actor* (*CreateActorFn)(const XNode* pNode, Actor* pParent); +typedef Actor* (*CreateActorFn)(); + +template +Actor *CreateActor() { return new T; } // 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 XNode* pNode, Actor* pParent) { \ - className *pRet = new className; \ - if( pParent ) \ - pRet->SetParent( pParent ); \ - pRet->LoadFromNode(pNode); \ - return pRet; } \ - class Register##className { \ - public: \ - Register##className() { ActorUtil::Register(#externalClassName,Create##className); } \ + struct Register##className { \ + Register##className() { ActorUtil::Register(#externalClassName, CreateActor); } \ }; \ static Register##className register##className; \ Actor *className::Copy() const { return new className(*this); }