Hi there
I hope, this is the right place to ask this.
I got really stuck with my project. I think I have a nice flaw in my design, or maybe I simply lack of proper knowledge of C++.
Right, so I have a game engine. It handles different game states. Something like this:
// main.cpp
// include things
int main ()
{
Engine* MyEngine = Engine::GetInstance();
// declare game states
PtrToGameState Title(new TitleState(TITLE_STATE));
PtrToGameState Map(new MapState(MAP_STATE));
MyEngine->AddState(Title);
MyEngine->AddState(Map);
MyEngine->Init(...);
MyEngine->Run(...);
return 0;
}
The engine stores the game state objects in a vector, and when it's running it iterates through this vector and calls some function:
// hopefully this piece of code is easy to understand...
while (running && lState != EXIT_STATE)
{
for (iter = states.begin(); iter != states.end(); ++iter)
{
if ((*iter)->GetState() == lState)
{
(*iter)->Init();
lState = (*iter)->Mainloop();
}
}
}
So, with this I have a nice state manager-like thing, which handles various states I create, as long as I inherit from an abstract base class called, GameState.
However, the state objects can't communicate with eachother. I try to explain what I mean, and want to achieve.
I start a new game, and I'm playing it for 2 hours, then decide to call it a day. So I want to save my progress. But with this code I can't do that!
The TitleState don't know where I am in the MapState, so even though TitleState has a Save Game function, it doesn't know what I want to save. (And the engine only knows the GameState base class.)
I hope you understand my problem, and give me some advice on what should I modify in my design. Because I am out of ideas.