Page 1 of 1

[Solved]Project Structure Help

Posted: Tue Mar 16, 2010 2:42 pm
by Jabza
Hi everyone,
I'm writing in hope of some much appreciated guidance as I feel the way in which I structure my C++ projects/games isn't always the best.

Currently I aim to have as few lines of code as possible in main, just the main loop (I used to have it all dumped in one 'main' file :oops: ), now I include separate .cpp and headers. However the way in which I have separated my files seems... disorganized. I usually have one big .cpp and .h with all my classes in and one file containing all my structures. I also try to split relevant code into separate files (ie, a file for 'input' functions, a file for 'TextBox' functions) but this sometimes causes compiler errors which I usually get around with by adding a header file full of includes ect. (Not the best way I feel). I'm sure I'm missing a trick here and I'm hoping to improve. Should I really have a separate 'input' file or include it within a 'player class' which actually utilizes the input, I'm hoping this makes sense. So what code structures do you implement within your projects, if any?

Thanks in advance!

Re: Project Structure Help

Posted: Tue Mar 16, 2010 2:57 pm
by Maevik
Typically you should have a seperate .cpp/.h pair for each class. This will mean lots of #include lines as well as a robust list of project files, but that's ok! The benefits of doing it this way are:

*It's easy to locate relevant data to your class
*Makes it easy to debug an improperly applied scope resolution tag in your .cpp's
*Once each of your classes is completed and properly debugged, it's a portable and hopefully reusable piece of code!

Good luck, hope this helps :D

Re: Project Structure Help

Posted: Tue Mar 16, 2010 3:06 pm
by Jabza
Cheers for the quick response :) , it sounds like i need to include far more classes than i usually do... to get rid of my stray functions. Not sure to what extent however.

Re: Project Structure Help

Posted: Wed Mar 17, 2010 7:29 pm
by Falco Girgis
Welcome to the biggest, most complex, yet most important question that newbies ask when they begin game development. Honestly, this kind of thing can only be learned through experience. You have to experience what designs work, what don't, why things need to be done a certain way, and why they can't be done others.

Re: Project Structure Help

Posted: Thu Mar 18, 2010 6:20 am
by Live-Dimension
What GyroVorbis said.

I'm still learning a huge amount of things about "project structure". It's just something you get better at over time. You can follow some rules, or "guidelines" but in the end, there is multiple ways to solve each puzzle. Some are better some are worse, none is the "best" way as each situation is different.

Re: Project Structure Help

Posted: Thu Mar 18, 2010 1:41 pm
by Jabza
Thanks for all the replies. Seems like a try, try and try again scenario. Which is what i now intend to do. :)