Game Development Reference
In-Depth Information
It follows a similar pattern as before: When obtaining data from unmanaged C++,
the code asks for the size of memory needed with GetActorXmlSize() . Then a
temporary unmanaged memory buffer of that size is allocated, the data is copied
into that buffer with a call to the C++ DLL, and finally the results are processed
into managed memory.
The processing includes a call to Marshal.PtrToStringAnsi() , which can con-
vert an unmanaged ANSI string into a managed C# string. Once that is done, the
string is converted into an XmlElement , which is a very useful class to read and
write XML. You ' ll be seeing much more of XmlElement shortly because
it is the
backbone data structure for the editor.
The next method uses GetActorList() and GetActorXml() to initialize the actor
TreeView and the List<XmlNode> .
private void InitializeActors()
{
TreeView_Actors.Nodes.Clear();
int[] actorList = GetActorList();
// Game starts actors at Id=1, so we
'
ll make a space for a null actor here.
m_ActorsXmlNodes.Add(null);
// Add each actor as its own node in the treeview.
for (int i = 0; i < actorList.GetLength(0); i++)
{
uint actorId = Convert.ToUInt32(actorList[i]);
TreeNode node = new TreeNode();
XmlElement actorXml = GetActorXml(actorId);
if (actorXml != null)
{
node.Name = actorList[i].ToString();
m_ActorsXmlNodes.Add((XmlNode)actorXml);
node.Text = actorXml.GetAttribute(
type
);
}
else
{
node.Text =
<undefined actor - no xml>
;
}
TreeView_Actors.Nodes.Add(node);
}
}
Search WWH ::




Custom Search