Game Module Structure Question

Posts: 17
Joined: 2005.08
Post: #1
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)
Quote this message in a reply
Posts: 133
Joined: 2008.05
Post: #2
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.
Quote this message in a reply
Posts: 17
Joined: 2005.08
Post: #3
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.
Quote this message in a reply
Posts: 834
Joined: 2002.09
Post: #4
Try searching for the "singleton pattern" on google.
Quote this message in a reply
Posts: 208
Joined: 2005.04
Post: #5
I'd highly recommend reading this book. It will give you plenty of ideas on how to clean up the structure of your program.
Quote this message in a reply
Posts: 168
Joined: 2004.10
Post: #6
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...

Quote this message in a reply
Posts: 338
Joined: 2004.07
Post: #7
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.

Justin Ficarrotta
"It is better to be The Man than to work for The Man." - Alexander Seropian
Quote this message in a reply
Posts: 1,199
Joined: 2004.10
Post: #8
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.
Quote this message in a reply
Post Reply 

Possibly Related Threads...
Thread: Author Replies: Views: Last Post
  Module Based Game? KiroNeem 5 3,050 Nov 30, 2005 09:17 AM
Last Post: ThemsAllTook
  question about code structure/style Najdorf 3 3,050 Nov 13, 2005 10:55 AM
Last Post: Zekaric
  Triangular Data Structure Sta7ic 4 4,241 Jan 22, 2003 02:45 PM
Last Post: OneSadCookie