iDevGames Forums
Game Module Structure Question - Printable Version

+- iDevGames Forums (http://www.idevgames.com/forums)
+-- Forum: Development Zone (/forum-3.html)
+--- Forum: Game Programming Fundamentals (/forum-7.html)
+--- Thread: Game Module Structure Question (/thread-5094.html)



Game Module Structure Question - Lunatic - Sep 4, 2005 05:26 PM

Hi All,

I've been slowly chugging along in my SDL game learning process, but a problem is becoming more apparent as my game becomes more and more complicated.

I've been basing the design in my head along the lines of having each "area" managed by a Manager class to organise smaller elements. I.e. A Player Manager, GUI Manager etc.

Things started to get problematic, once I had gui elements trying to access player objects, but not being able to see the player manager (I declared the Player Manager object in main()). I've tried to declare the Player Manager outside of main as a global variable, etc but i usually end of getting undefined symbol errors.

My question is: Should I persist in this line of design? Is having manager classes a good idea? or is there some other idea I should follow? If it is the best idea, is there some way of making C++ classes globally accessible to all?

Thanks in advance for any suggestions.

(C++, Latest SDL, XCode 2.0, Tiger OSX)


Game Module Structure Question - longjumper - Sep 4, 2005 07:45 PM

It's a good idea, I'd assume(because I do it), that most people have "managers" just like you do. You could just make a global instance of your classes or make them static classes.


Game Module Structure Question - Lunatic - Sep 4, 2005 11:05 PM

Is there an easy way to create a global instance of a class? As I mentioned before Im trying to make it global but it doesnt seem to permeate. I havent yet tried it as a static though, I'll see if that fixes the problem.


Game Module Structure Question - Fenris - Sep 5, 2005 12:01 AM

Try searching for the "singleton pattern" on google.


Game Module Structure Question - Andrew - Sep 5, 2005 05:34 AM

I'd highly recommend reading this book. It will give you plenty of ideas on how to clean up the structure of your program.


Game Module Structure Question - socksy - Sep 5, 2005 06:39 AM

Fenris Wrote:Try searching for the "singleton pattern" on google.
From The Game Programming Wiki I found this.
GPWiki is always a good place for a quick look up, I'm surprised it isn't linked by idevgames, and I think that people here should contribute. It's for all platforms...

Smile


Game Module Structure Question - JustinFic - Sep 5, 2005 11:40 AM

I'll second using design patterns. If you check out the code for my game "Kill Dr. Cote" you can see singletons in action.

Source code

Singleton.h is the singleton taken from Game Programming Gems (1 I think) and texturemgr and soundmgr are examples of managers as child classes of singleton.


Game Module Structure Question - TomorrowPlusX - Sep 6, 2005 04:27 AM

While singletons are useful, they can bite you in the long run. What I do is make an Application class, which is a singleton ( since there can, by definition, be only one running app ) and have it have pointers to my TextureManager, SoundManager, MusicManager, Hud, World, and so on. This makes for a fairly clean design.

Plus, it makes it super easy to subclass my Manager classes and assign them to my Application.