StandardGame and gamestates

By following the StandardGame example, I've created a little test app but I can't seem to figure out how to get get GameStates that are attached to GameStateManager to run their update methods.



public static void main(String[] args) throws Exception {
      // Instantiate StandardGame
      StandardGame game = new StandardGame("A Simple Test");
      // Create a DebugGameState - has all the built-in features that SimpleGame provides
      // NOTE: for a distributable game implementation you'll want to use something like
      // BasicGameState instead and provide control features yourself.
      DebugGameState state;
      // the terrain we will drive over.
      GameTerrain terrain;
      // Show settings screen
      if (GameSettingsPanel.prompt(game.getSettings())) {
         // Start StandardGame, it will block until it has initialized successfully, then return
         game.start();
         
         state = new DebugGameState();
         terrain = new GameTerrain("Terrain",game);
         state.getRootNode().attachChild(terrain.getTerrainBlock());
         
         
         // Put our box in it
         Box box = new Box("my box", new Vector3f(0, 0, 0), 2, 2, 2);
          box.setModelBound(new BoundingSphere());
          box.updateModelBound();
          // We had to add the following line because the render thread is already running
          // Anytime we add content we need to updateRenderState or we get funky effects
          box.updateRenderState();
          state.getRootNode().attachChild(box);
         // Add it to the manager
         GameStateManager.getInstance().attachChild(state);
         // Activate the game state
         state.setActive(true);
      }
   }



In the above snippet, GameTerrain extends GameState and does nothing other than make a terrain block, put a texture on it, etc.  The textured terrain shows up as expected but the update method of GameTerrain is not being called... It seems like the snippet above is setting up the StandardGame but isn't calling update on my GameTerrain's class... any idea what I'm doing wrong?  I've read the wiki entries on GameStates but they don't really discuss how to use them to create a main game loop...

Yeah… I used setActive(true)



For Completeness:



public GameTerrain(String name, StandardGame game)
   {      
      super();
      this.game = game;
      init();
   }
   
   
   private void init()
   {
      MidPointHeightMap heightMap = new MidPointHeightMap(64, 1f);
       // Scale the data
       Vector3f terrainScale = new Vector3f(4, 0.0575f, 4);
       // create a terrainblock
        tb = new TerrainBlock("Terrain", heightMap.getSize(), terrainScale,
               heightMap.getHeightMap(), new Vector3f(0, 0, 0), false);

       tb.setModelBound(new BoundingBox());
       tb.updateModelBound();

       // generate a terrain texture with 2 textures
       ProceduralTextureGenerator pt = new ProceduralTextureGenerator(
               heightMap);
       pt.addTexture(new ImageIcon(TestTerrain.class.getClassLoader()
               .getResource("jmetest/data/texture/grassb.png")), -128, 0, 128);
       pt.addTexture(new ImageIcon(TestTerrain.class.getClassLoader()
               .getResource("jmetest/data/texture/dirt.jpg")), 0, 128, 255);
       pt.addTexture(new ImageIcon(TestTerrain.class.getClassLoader()
               .getResource("jmetest/data/texture/highest.jpg")), 128, 255,
               384);
       pt.createTexture(32);
      
       // assign the texture to the terrain
      
       TextureState ts = game.getDisplay().getRenderer().createTextureState();
       Texture t1 = TextureManager.loadTexture(pt.getImageIcon().getImage(),
               Texture.MM_LINEAR_LINEAR, Texture.FM_LINEAR, true);
       ts.setTexture(t1, 0);
      
       //load a detail texture and set the combine modes for the two terrain textures.
       Texture t2 = TextureManager.loadTexture(
               TestTerrain.class.getClassLoader().getResource(
               "jmetest/data/texture/Detail.jpg"),
               Texture.MM_LINEAR_LINEAR,
               Texture.FM_LINEAR);

       ts.setTexture(t2, 1);
       t2.setWrap(Texture.WM_WRAP_S_WRAP_T);

       t1.setApply(Texture.AM_COMBINE);
       t1.setCombineFuncRGB(Texture.ACF_MODULATE);
       t1.setCombineSrc0RGB(Texture.ACS_TEXTURE);
       t1.setCombineOp0RGB(Texture.ACO_SRC_COLOR);
       t1.setCombineSrc1RGB(Texture.ACS_PRIMARY_COLOR);
       t1.setCombineOp1RGB(Texture.ACO_SRC_COLOR);
       t1.setCombineScaleRGB(1.0f);

       t2.setApply(Texture.AM_COMBINE);
       t2.setCombineFuncRGB(Texture.ACF_ADD_SIGNED);
       t2.setCombineSrc0RGB(Texture.ACS_TEXTURE);
       t2.setCombineOp0RGB(Texture.ACO_SRC_COLOR);
       t2.setCombineSrc1RGB(Texture.ACS_PREVIOUS);
       t2.setCombineOp1RGB(Texture.ACO_SRC_COLOR);
       t2.setCombineScaleRGB(1.0f);

       tb.setRenderState(ts);
       //set the detail parameters.
       tb.setDetailTexture(1, 16);
       tb.setRenderQueueMode(Renderer.QUEUE_OPAQUE);
       tb.updateRenderState();
       setActive(true);
   }
   
   public TerrainBlock getTerrainBlock()
   {
      return tb;
   }
   
   public void update(float num)
   {
      logger.info("Updating...");
   }

did you activate the GameTerrain GameState?

I don't see you overriding the GameState's update to call your terrain's update call… you need to do that explicitly, the DebugGameState does not know what method to call depending on each object that is attached… It only calls updateGeometricState on the root node at each iteration.



Which update method are you talking about in your terrain?