Hey,
This sounds to me like the perfect place for the Singleton design pattern...
Warning!!! this code is quick typed, messy and provides no thread safety but should serve to demonstrate the general pattern...
class GlobalGameState
{
public:
enum GameStates {_fplay, _main, _load, _world};
~GlobalGameState();
static GlobalGameState* getInstance();
GlobalGameState::GameStates getCurrentState();
void setCurrentState(GlobalGameState::GameStates state);
private:
GlobalGameState();
static GlobalGameState* mInstance;
GlobalGameState::GameStates mState;
};
GlobalGameState* GlobalGameState::mInstance = NULL;
GlobalGameState::GlobalGameState()
{
mState = GlobalGameState::_load;
}
GlobalGameState* GlobalGameState::getInstance()
{
if(mInstance == NULL)
{
mInstance = new GlobalGameState();
}
return(mInstance);
}
GlobalGameState::GameStates GlobalGameState::getCurrentState()
{
return(mState);
}
void GlobalGameState::setCurrentState(GlobalGameState::GameStates state)
{
mState = state;
}
Then to use in the program...
//Get the default state
GlobalGameState::GameStates state = GlobalGameState::getInstance()->getCurrentState();
//Set the state
GlobalGameState::getInstance()->setCurrentState(GlobalGameState::_fplay);
//Get the state again
state = GlobalGameState::getInstance()->getCurrentState();
The beauty of the singleton is it is global accessable but provides more functionality and control than a shed load of global variables. I use them all the time for config etc.
Hope that is helpful.