Advertisement Jump to content
Sign in to follow this  

Loading up a scene graph using tinyXml

This topic is 3955 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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

Share this post

Link to post
Share on other sites
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.

//c cast just for illustration
file.ForEachNode("Model", &ModelCallback, (Scene*)m_CurrentScene);

Share this post

Link to post
Share on other sites
Sign in to follow this  

  • Advertisement

Important Information

By using, you agree to our community Guidelines, Terms of Use, and Privacy Policy. is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!