Game Development Reference
In-Depth Information
void GetActorXml ( int *actorXMLAddress, ActorId actorId )
{
StrongActorPtr pActor = MakeStrongPtr(g_pApp->m_pGame->VGetActor(actorId));
if ( !pActor )
{
return;
}
std::string xml = pActor->ToXML();
strncpy_s(reinterpret_cast<char *>(actorXMLAddress),
xml.length()+1, xml.c_str(), xml.length());
}
Both methods get a strong pointer to the actor, and they call Actor::ToXML() .C#
needs to be able to know how much memory to allocate before retrieving the XML
data, which is why there are two functions. The address to the memory allocated by
C# is sent in as a pointer to an integer, which is a common method for sending an
unknown amount of data across the C++/C# barrier.
The ToXML() method uses TinyXML to run through all the components attached to
an actor to create the complete definition of an actor that will, at some point, be
saved to a level file.
std::string Actor::ToXML()
{
TiXmlDocument outDoc;
// Actor element
TiXmlElement* pActorElement = GCC_NEW TiXmlElement(
Actor
);
pActorElement->SetAttribute(
type
, m_type.c_str());
// components
for (auto it = m_components.begin(); it != m_components.end(); ++it)
{
StrongActorComponentPtr pComponent = it->second;
TiXmlElement* pComponentElement = pComponent->VGenerateXml();
pActorElement->LinkEndChild(pComponentElement);
}
outDoc.LinkEndChild(pActorElement);
TiXmlPrinter printer;
outDoc.Accept(&printer);
return printer.CStr();
}
Search WWH ::




Custom Search