Game Development Reference
In-Depth Information
void ModifyActor ( BSTR bstrActorModificationXML )
{
std::string actorModificationXML =
ws2s(std::wstring(bstrActorModificationXML,
SysStringLen(bstrActorModificationXML)));
TiXmlDocument doc;
doc.Parse(actorModificationXML.c_str());
TiXmlElement* pRoot = doc.RootElement();
if (!pRoot)
return;
g_pApp->m_pGame->VModifyActor(atoi(pRoot->Attribute(
id
)), pRoot);
}
The BSTR parameter sent from the editor is a bit of XML data the editor creates to
tell the game engine exactly how the actor is changing. Basically, the XML contains a
snippet of the component XML you saw previously, but only the part that has chan-
ged. For example, if the editor changed the orientation of a Grid actor to rotate 90
degrees around the Y-axis, the XML sent from the editor would look like this:
<Actor type=
>
<TransformComponent>
<YawPitchRoll x=
Grid
0
y=
90
z=
0
/>
</TransformComponent>
</Actor>
The BaseGameLogic::VModifyActor() method finds the actor and calls a mem-
ber of the ActorFactory class you
ve never seen before, which is very similar to the
ActorFactory::VCreateComponent() method that initializes a new actor. It runs
through the XML above, either creates or finds the components, and initializes them.
'
void ActorFactory::ModifyActor(StrongActorPtr pActor, TiXmlElement* overrides)
{
// Loop through each child element and load the component
for (TiXmlElement* pNode = overrides->FirstChildElement();
pNode; pNode = pNode->NextSiblingElement())
{
ComponentId componentId = ActorComponent::GetIdFromName(pNode->Value());
StrongActorComponentPtr pComponent =
MakeStrongPtr(pActor->GetComponent<ActorComponent>(componentId));
if (pComponent)
{
pComponent->VInit(pNode);
}
Search WWH ::




Custom Search