Loading up a scene graph using tinyXml
Since in a scene graph each node can have child nodes and those nodes can have child nodes and so on, how can i go through the graph if i dont know how 'deep' it is?
I need to create a TiXmlElement for each node that has children but then i need another while statement to loop through that and so on and thats not viable at all.
Maybe im looking at this the wrong way and there is another better way. please tell me.
The basic structure of my xml file is
<level>
<node>
<node />
<node>
<node />
</node>
</node>
</level
Im sure if someone has used tinyXml before or has done something like this they will understand what im saying.
Sorry if that isnt very clear but im not sure how else to explain it.
Thanks
Your parse should definitely handle recursion. Then you can create a callback function for each type of node, and you can do something like this:
pseudo code:
File file("scene.xml");
file.ForEachNode("Model", &ModelCallback);
ModelCallback, may do another "foreach" for the different properties of the model.
for instance:
File material("wood.xml")
file.ForEachNode("Texture", &TextureCallback);
You'll also likely want to add a parameter to the callback so that you can pass around the current instance reference. Since the callbacks will need to be static.
ex:
//c cast just for illustration
file.ForEachNode("Model", &ModelCallback, (Scene*)m_CurrentScene);
pseudo code:
File file("scene.xml");
file.ForEachNode("Model", &ModelCallback);
ModelCallback, may do another "foreach" for the different properties of the model.
for instance:
File material("wood.xml")
file.ForEachNode("Texture", &TextureCallback);
You'll also likely want to add a parameter to the callback so that you can pass around the current instance reference. Since the callbacks will need to be static.
ex:
//c cast just for illustration
file.ForEachNode("Model", &ModelCallback, (Scene*)m_CurrentScene);
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement