Game Development Reference
In-Depth Information
{
StrongActorComponentPtr pComponent(CreateComponent(pNode));
if (pComponent)
{
pActor->AddComponent(pComponent);
pComponent->SetOwner(pActor);
}
else
{
return StrongActorPtr();
}
}
// Now that the actor has been fully created, run the post init phase
pActor->PostInit();
return pActor;
}
First, this function loads the resource, gets the root XML node, and does a little error
checking. Then it instantiates the actor object, generating and passing in the next
actor ID. The actor ID is important because it allows you to represent the actor
uniquely as a single primitive value (in this case, an unsigned long). It ' s generally fas-
ter and easier to pass this value around, especially when you start dealing with other
systems and languages. You
'
ll see this ID used quite a bit in Chapter 12,
Scripting
with Lua.
t have to know anything about the internals of the actor sys-
tem; it just knows that it has a value it can use to tell the actor system to do some-
thing with a specific actor.
The actor
Lua doesn
'
'
s Init() function is called to do any base-level initialization before adding
components. If this succeeds, the next step is to loop through all the components
defined in the XML file and load each one. This is done by calling the CreateCom-
ponent() function, passing in the XML node for that component. The component
returned is then added to the actor
s component map, and the component is told of
its new owner. If this process fails, the function aborts. Having no actor is better than
having a partially constructed one. Once the components have all been added, the
actor
'
s PostInit() function is run. The PostInit() function takes care of any
initialization that needs to occur after the actor and all components have been fully
created. That
'
s it, the newly composed actor is returned to the caller.
The CreateComponent() function is relatively simple.
'
StrongActorComponentPtr ActorFactory::CreateComponent(TiXmlElement* pData)
{
Search WWH ::




Custom Search