I have a question about the class design in my game engine, but first, a little backstory. Any feedback, especially negative, is more than welcome!
States manage the flow of the game code.
Usualy, one state when finished starts another, and shuts itself down.
For example, the following states are run in order.
ClientStateMainMenu:
This state displays the main menu and runs the apporopreate state depending on what the user selects.
If the user selects 'New Game' the state 'ServerStatePlay' and 'ClientStateConnect' are run.
ClientStateConnect:
This state connects to a server, verifies some things like entity lists, and then runs 'ClientStatePlay'.
ClientStatePlay:
This is the state that handles the main gameplay.
It has many responsibilities.
The code to run a state looks like this:
EngineAPI()->RunState( "ClientStateConnect" );
Versus
EngienAPI()->RunState( new ClientStateConnect );
This start state-by-name system prevents cross-includes.
An example potential cross-include:
'ClientStateMainMenu' runs 'ClientStateConnect' and if the connection fails, 'ClientStateConnect' needs to run 'ClientStateMainMenu' again.
=Primary Issue=
I have no way cleanly send data to a state I am starting. For example, sending the servers ip address to 'ClientStateConnect' when I start it from 'clientStateMainMenu'.
The way this is currently handled is through console variables (an idea shamelessly stolen from the Source engine, my favorite). However, not all inter-state data makes sense as a console variable.
An example of that is, if a connection fails, 'ClientStateMainMenu' is run again from 'ClientStateConnect'. However, 'ClientStateMainMenu' needs to display a message telling the user that the connection has failed. How can I tell it that it should do that?
One (horrible) idea I had was to have a generic system whereby I could send data casted as a void* into the state.
EngineAPI()->RunState( "ClientStateMainMenu", (void*)someData );
Which has obvious issues.
How could I best do somthing like this? I'm not even married to the whole state idea honestly.