State Managers

Discussion about everything. New games, 3d math, development tips...
Post Reply
torleif
Posts: 188
Joined: Mon Jun 30, 2008 4:53 am

State Managers

Post by torleif »

What's the best way to construct a state manager for a game?

For my game paper, we used this:

Code: Select all

//in game manager file:
class GameStateMgr;
//in current state file:
class currentState extends GameStateMgr

//when making a state:
mainStateManager = new currentState;
As you can see, it has its advantages, but changing states isn't that great.

I'm very lazy, and for my games so far I've used this:

Code: Select all

class gameState
gameState function state1
gameState function state2

in main loop:
switch gameState->getState(){
  case state1:gameState->state1
}
As you can see, it's a nasty way of managing states, but is easy to implement (but not extend). C++ coders like me are screaming on the inside about the memory leaks from this method

I'm probably missing a chapter or to from game dev 101. What's the best game state manager to use for a concrete base?
BlindSide
Admin
Posts: 2821
Joined: Thu Dec 08, 2005 9:09 am
Location: NZ!

Post by BlindSide »

You have a game paper in Otago!? You bastards, we only get bread and butter compsci papers up here in auckland uni..

What language is that? Java or the like?

I don't think the state should extend the state manager, rather it should extend a state, and the state manager manages those. :P

Have a look at irrWizard it's a pretty concrete example of basic game state management in C++.
ShadowMapping for Irrlicht!: Get it here
Need help? Come on the IRC!: #irrlicht on irc://irc.freenode.net
torleif
Posts: 188
Joined: Mon Jun 30, 2008 4:53 am

Post by torleif »

Game programing (Cosc360) is a fantastic paper, defiantly worth the three years at Otago to get there ><. Otago has a great compsci department, we beat Auckland a lot of the time in the prog competitions, despite our small size. In Cosc360 we program in C#, but as you tell my code is pseudocode

Thanks for the hint on a state manager btw, I've read & bookmarked IrrWizard for future reference :D
rogerborg
Admin
Posts: 3590
Joined: Mon Oct 09, 2006 9:36 am
Location: Scotland - gonnae no slag aff mah Engleesh
Contact:

Post by rogerborg »

Uh, use a simple enum and a switch. If you have to keep "extending" your states, then you failed in your requirement or design phase.
Please upload candidate patches to the tracker.
Need help now? IRC to #irrlicht on irc.freenode.net
How To Ask Questions The Smart Way
stevend
Posts: 114
Joined: Sat Mar 01, 2008 7:18 pm

Post by stevend »

like rogerborg said i would make an enum with all your states, and maybe poll the state manager in your game loop

i also make each basic GUI control attached to a state and setvisible to it depending on the current state when the statemanager is polled

that is just me :P
Post Reply