Jump to content
  • Advertisement


This topic is now archived and is closed to further replies.


Loading data recursively

This topic is 5205 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

This is anoying as its so simple and i done these type of problems at school and college a million times but now i just cant think properly. I am loading information from a text file, i''ll give a really cut done example: shaderlist { effect id num of shaders shaders { effect id sub shaders } } now the shaders loading code is easy, just a simple for loop. But subshaders are exactly the same as shaders, meaning they may have subshaders with subshaders etc etc and i wont be able to know how many. How do i load this data, do/while loop?, should i use a stack? I actually feel a little embarrassed here lol. Oh well the simple things you forget when your brains been working overtime.

Share this post

Link to post
Share on other sites
Load the data recursively:

Shader readshader(filestream f):
read whatever header punctuation and discard
s : new Shader(read effect id)
n : read num of shaders
for i : 0..n-1
read whatever footer punctuation and discard

The filestream object (ifstream/ofstream in C++) is responsible for keeping track of the file position: the change is seen when you return from the recursion, so you can just pick up where you left off.

To purify your thinking, it may help to think of the shader list as itself being a "root" shader, whose children are the actual top-level shaders.

Share this post

Link to post
Share on other sites
Cheers, I feel stupid, it should have been so obvious to me to recursively call a function, I even said in the question Recursively, just shows what your brain does to you sometimes when your working on something exciting, you forget some of the obvious/easy beginners stuff, or at least I have done so a few times now.

Share this post

Link to post
Share on other sites

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!