GameState questions

I was perusing the GameState and GameStateManager classes and I had a few questions regarding it.


  1. Is there any reason that the GameStateManager contains a Node and then attaches the root node of the GameState to it? Why not just have a Node reference in the GameStateManager and assign it to current.getNode() ? That would save you having to detatch the current node and re-attach the new one. Perhaps is has something to do with the geometry update calls at the bottom of the switchTo() method?


  2. I saw talk of having an InputManager reference in the GameState class, is there any reason why that did not make it in?


  3. Is there any reason there is not a switchFrom() method in the GameState? The reason I ask is that I can forsee times when a GameState would need to do a small amount of housekeeping to prepare itself for being “paused”. One example I had for this is bringing up a menu screen.



    Say you want a menu to pop up but not take up the entire screen. You want the background to be blurred out while the menu is on the screen. I would accomplish this by rendering to texture the current scene, mapping that onto a quad and sticking it behind the menu. The render to texture operation would probably be done by the main game as it’s being switched away from. Of course you could probably have a GetFrameAsTexture() method in the main game GameState and then call that from the switchTo() method of the menu but I think it would be easier to do that work when switching away from the main game. Also, what if you had threads running that you needed to shut down before switching away, etc.


void switchFrom() {}



As long as that's called by the GameStateManager before switching the current state reference it wouldn't break any existing code AFAIK.[/code]

@1: (from the thread in code review)

"Per" wrote:
Hmm, true. Should the stateNode still be attached to the rootNode? Or should the stateNode be the rootNode?
"Badmi" wrote:
I say attached. This would allow you to have something like a sky box that all the sates should have.

@2: Umm.. GameState is an interface, and thus can not have a reference to an InputManager, but StandardGameState - which you in most cases want to extend - has.

@3: Agree, sounds like a good idea.

Maybe this thread should be moved to/continued in the Dev General topic?

#1. Ok I missed that in the other thread, I can see that being pretty handy.



#2. Doh! ://

Since I already asked some questions about the GameState system I figured I’d just take my other on here.



Is there any way to get the current game state from the GameStateManager? It would be useful to be able to say GameStateManager.getInstance().getCurrentState() instead of having to pass a reference to yourself to any child objects you create in your GameState. Also it would be handy to be able to get out the game states you put in earlier by saying getState(“StateName”);