[Solved]Project Structure Help

Whether you're a newbie or an experienced programmer, any questions, help, or just talk of any language will be welcomed here.

Moderator: Coders of Rage

Post Reply
User avatar
Jabza
Chaos Rift Newbie
Chaos Rift Newbie
Posts: 8
Joined: Sat Jan 16, 2010 9:54 am
Favorite Gaming Platforms: PC
Programming Language of Choice: C++
Location: United Kingdom

[Solved]Project Structure Help

Post 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!
Last edited by Jabza on Thu Mar 18, 2010 1:54 pm, edited 2 times in total.
User avatar
Maevik
Chaos Rift Junior
Chaos Rift Junior
Posts: 230
Joined: Mon Mar 02, 2009 3:22 pm
Current Project: www.keedepictions.com/Pewpew/
Favorite Gaming Platforms: PC
Programming Language of Choice: C++
Location: Long Beach, CA

Re: Project Structure Help

Post 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
My love is like a Haddoken, it's downright fierce!
User avatar
Jabza
Chaos Rift Newbie
Chaos Rift Newbie
Posts: 8
Joined: Sat Jan 16, 2010 9:54 am
Favorite Gaming Platforms: PC
Programming Language of Choice: C++
Location: United Kingdom

Re: Project Structure Help

Post 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.
User avatar
Falco Girgis
Elysian Shadows Team
Elysian Shadows Team
Posts: 10294
Joined: Thu May 20, 2004 2:04 pm
Current Project: Elysian Shadows
Favorite Gaming Platforms: Dreamcast, SNES, NES
Programming Language of Choice: C/++
Location: Studio Vorbis, AL
Contact:

Re: Project Structure Help

Post 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.
Live-Dimension
Chaos Rift Junior
Chaos Rift Junior
Posts: 345
Joined: Tue Jan 12, 2010 7:23 pm
Favorite Gaming Platforms: PC - Windows 7
Programming Language of Choice: c++;haxe
Contact:

Re: Project Structure Help

Post 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.
Image
User avatar
Jabza
Chaos Rift Newbie
Chaos Rift Newbie
Posts: 8
Joined: Sat Jan 16, 2010 9:54 am
Favorite Gaming Platforms: PC
Programming Language of Choice: C++
Location: United Kingdom

Re: Project Structure Help

Post by Jabza »

Thanks for all the replies. Seems like a try, try and try again scenario. Which is what i now intend to do. :)
Post Reply