Game Development Reference
In-Depth Information
All actors are defined with an XML data file. This data file allows you to define a
component configuration and any default values for that component. Here ' s some
sample XML for an actor:
<Actor>
<CubePhysicsComponent>
<InitialTransform>
<Position x=
0
y=
5
z=
0
/>
<Orientation degrees=
-90
/>
</InitialTransform>
<Shape>
<Dimensions x=
1
y=
1
z=
1
/>
</Shape>
<Density>castIron</Density>
<PhysicsMaterial>Normal</PhysicsMaterial>
</CubePhysicsComponent>
<TeapotRenderComponent>
<Color r=
0
g=
0
b=
1.0
a=
1.0
/>
</TeapotRenderComponent>
</Actor>
This XML file defines an actor with two components, a CubePhysicsComponent
and a TeapotRenderComponent . If you decide later on that the density of the
physics material needs to change, you can do that right here. If you decide that this
actor needs to have a brain, you can easily add an AI component without changing a
single line of code. That ' s the power of data-driven development.
Keep in mind that these actor XML files define the template for a type of actor, not a
specific actor instance. There can be many instances of this actor running around, each
with completely different sets of data within their components. The XML file only
defines the definition. You can think of it as defining a class for this type of actor.
Now that you
'
ve seen how to define types of actors, let
'
s take a look at the factory
'
class that
s responsible for parsing this data and creating the actor instance.
typedef ActorComponent *(*ActorComponentCreator)(void);
typedef std::map<std::string, ActorComponentCreator> ActorComponentCreatorMap;
// some actor typedefs to make our life easier
typdef unsigned long ActorId;
typedef shared_ptr<Actor> StrongActorPtr;
typedef shared_ptr<ActorComponent> StrongActorComponentPtr;
class ActorFactory
{
ActorId m_lastActorId;
Search WWH ::




Custom Search