Activating / Deactivating GameStates troubles

hey there.



my application starts with the loadingsScreenGamestate activated and it shows perfectly. in another thread, i create three more gamestates and after thats done i activate them like this:



      GameTaskQueueManager.getManager().update(new Callable<Object>() {

        public Object call() throws Exception {
          loadingScreenGameState.setActive(false);
          gameSelectionGameState.setActive(true);
          statusBarGameState.setActive(true);
          inputGameState.setActive(true);
          return null;
        } // call
      }); // Callable



the issue is that you can see a few frames rendered with the loadingScreenGameState and the gameSelectionGameState but no statusBarGameState and after these few frames the statusBarGameState is visible and the loadingScreenGameState becomes invisible. i need them activated and rendered (for the first time) in the same frame.

i call updateRenderState and updateGeometricState after initialisation on the rootnode of every  GameState.

what am i doing wrong?

Perhaps you should just take a look at the LoadingGameState and TransitionGameState - They also display a loading screen and they are already set up correctly. I use them both and have no problems. Well not exactly - I had a problem with the TransitionGameState not being displayed correctly, but that was fixed by starting gameState changes in a separate thread.



This is how I initialize a new game:


   public void actionSinglePlayerGame(){
      Thread t = new Thread(new Runnable() {
               public void run() {
               /* Display loading screen */
               transitionGamestate = new TransitionGameState(
                    mainMenuGamestate,
                    RiseToTheStars.class.getClassLoader().getResource(GameConstants.TEXTURE_LOADING_BACKGROUND));
              GameStateManager.getInstance().attachChild(transitionGamestate);
              transitionGamestate.setProgress(0.1f, "Initializing...");
              transitionGamestate.setActive(true);
              /* Start up the GameServer */
              transitionGamestate.setProgress(0.3f, "Initializing GameServer");
              gameServer = new LocalGameServer(false);
              gameServer.start();
              /* Creating a GameClient */
              transitionGamestate.setProgress(0.6f, "Initializing GameClient");
              LocalGameClient localGameClient = new LocalGameClient(gameServer);
              /* Starts up the ClientGamestate */
              transitionGamestate.setProgress(0.7f, "Initializing ClientGamestate");
              if (clientGamestate != null) GameStateManager.getInstance().detachChild(clientGamestate);
              clientGamestate = new ClientGamestate(localGameClient);
              GameStateManager.getInstance().attachChild(clientGamestate);
                   transitionGamestate.setProgress(1.0f, "Done");
              clientGamestate.setActive(true);
            }
        });
        t.start();
   }



Plus I think doing the setActive() calls in the OpenGL thread is really not necessary.
Mindgamer said:

Plus I think doing the setActive() calls in the OpenGL thread is really not necessary.


thanks for the reply.  :)

anyhow, the idea of doing it in the opengl thread is because that block is done in one piece from the GameTaskQueueManager. If i dont do it in the opengl thread, the opengl thread might be rendering the various states while i'm still setting the setActive(boolean) on the gamestates.

hmm… didn't think of that : :smiley:

as always i tend to forget the smileys and winks after my posts to make them friendlier. i didnt want to seem rude or anything  :wink:

Instead of using GameTaskQueue if you're using StandardGame just call lock() / unlock() around the calls to make sure it's not in the process of updating.  It will also keep your code looking a lot cleaner. :slight_smile:



You've added the GameStates to the GameStateManager, right?

darkfrog said:

Instead of using GameTaskQueue if you're using StandardGame just call lock() / unlock() around the calls to make sure it's not in the process of updating.  It will also keep your code looking a lot cleaner. :)


cool  :)

darkfrog said:

You've added the GameStates to the GameStateManager, right?


yes, they are rendered. I'll check what the changes above do to this issue.
[me=dhdd]thx the frog[/me]