Starting with GBUI

Hi,



I'm trying to use GBUI for a test game and I'm having some troubles to put it in a game state. I'll add my game state code and I'd be very thankful with anyone can tell what I'm missing.

BTW: BuiSystem.init(new PolledRootNode(Timer.getTimer(), input), "atechnique/gbui/style2.bss"); is giving mw hard time… I tried to put in almost every folder related to my project (NetBeans 6.5) and I still get a run-time exception. If I use BuiSystem.init(), I don't get the exception, but nothing is shown. Actually I don't get any GUI stuff shown either way.



Thanks a lot,

Dirso.



The exception code:

java.lang.NullPointerException

        at java.io.Reader.<init>(Reader.java:61)

        at java.io.InputStreamReader.<init>(InputStreamReader.java:55)

        at com.jmex.bui.bss.BStyleSheetUtil.getStyleSheet(BStyleSheetUtil.java:134)

        at com.jmex.bui.bss.BStyleSheetUtil.getStyleSheet(BStyleSheetUtil.java:38)

        at com.jmex.bui.BuiSystem.init(BuiSystem.java:94)

        at com.jmex.bui.BuiSystem.init(BuiSystem.java:81)

        at superpong3d.MyBasicGameState.<clinit>(MyBasicGameState.java:60)

        at superpong3d.Main.main(Main.java:36)

java.lang.NullPointerException

        at java.io.Reader.<init>(Reader.java:61)

        at java.io.InputStreamReader.<init>(InputStreamReader.java:55)

        at com.jmex.bui.bss.BStyleSheetUtil.getStyleSheet(BStyleSheetUtil.java:134)

        at com.jmex.bui.bss.BStyleSheetUtil.getStyleSheet(BStyleSheetUtil.java:38)

        at com.jmex.bui.BuiSystem.init(BuiSystem.java:136)

        at com.jmex.bui.BuiSystem.init(BuiSystem.java:94)

        at com.jmex.bui.BuiSystem.init(BuiSystem.java:81)

        at superpong3d.MyBasicGameState.<clinit>(MyBasicGameState.java:60)

        at superpong3d.Main.main(Main.java:36)





MyBasicGameState:

public class MyBasicGameState extends GameState {

   /** The root of this GameStates scenegraph. */
   protected Node rootNode;
    static protected InputHandler input;
    static protected MouseInput mouse;

   // Unless we find a reason to have one of these for each sub-class, let's just share static instances
   protected static DisplaySystem display;
   protected BWindow _window;

    protected boolean manualActivation = false;

   static {
      display = DisplaySystem.getDisplaySystem();

        input = new InputHandler();
        mouse = MouseInput.get();

      BuiSystem.init(new PolledRootNode(Timer.getTimer(), input), "atechnique/gbui/style2.bss");
       
   }

   /**
    *
    * @param name The name of this GameState.
    */
   public MyBasicGameState(String name) {
      this.name = name;
      rootNode = new Node(name + ": RootNode");
      ZBufferState buf = DisplaySystem.getDisplaySystem().getRenderer().createZBufferState();
        buf.setEnabled(true);
        buf.setFunction(ZBufferState.TestFunction.LessThanOrEqualTo);
        rootNode.setRenderState(buf);
        // call virtual methods
        //
        initKeyBindings();
        // create scene
        initScene();
   }

   /**
    * Updates the rootNode.
    *
    * @see GameState#update(float)
    */
   public void update(float tpf) {
      rootNode.updateGeometricState(tpf, true);
        // test the input
         input.update(tpf);
   }

   /**
    * Draws the rootNode.
    *
    * @see GameState#render(float)
    */
   public void render(float tpf) {
      DisplaySystem.getDisplaySystem().getRenderer().draw(rootNode);
   }

   /**
    * Empty.
    *
    * @see GameState#cleanup()
    */
   public void cleanup() {
        //do nothing
   }

   public Node getRootNode() {
      return rootNode;
   }
   
    protected void initScene()
    {
        // do nothing again
    }

    /**
     *
     */
    protected void initKeyBindings()
    {
        // do nothing, derivated class responsability
    }

    public void halt(){
        Main.halt();
    }

    public void setCursorVisible(boolean v){
        mouse.setCursorVisible(v);
        if(v)
            mouse.setCursorPosition(display.getWidth()/2, display.getHeight()/2);
    }

    public void activate(){
        doActivation(true);
    }

    public void deactivate(){
        doActivation(false);
    }

    public void doActivation(boolean activate){
        if(isActive()==activate)return;
        manualActivation = activate;
        super.setActive(activate);
        if(activate)buildGUI();
        else cleanupGUI();
    }

    protected void buildGUI(){
        // Display the GBUI portion
      rootNode.attachChild(BuiSystem.getRootNode());
      rootNode.updateRenderState();
      GameTaskQueueManager.getManager().update(new Callable<Object>() {
         public Object call() throws Exception {
              BuiSystem.addWindow(_window);
            return null;
         }
      });
    }

    protected void cleanupGUI(){
      if (_window.getRootNode() != null) {
         _window.dismiss();
      }
      rootNode.detachChild(BuiSystem.getRootNode());
    }

    public static void changeGameState(String gsName){
        GameStateManager.getInstance().deactivateAllChildren();
        ((MyBasicGameState)GameStateManager.getInstance().getChild(gsName)).activate();
    }
}



MainMenuGameState:

public class MainMenuGameState extends MenuGameState {

   private BButton _btnCancel;
   private BButton _btnOk;

    /**
    *
    */
   public MainMenuGameState(){
        super("MainMenu");
   }
 
    /**
     * update the Inputhandler.
     */
    @Override
    public void update(float tpf) {
        super.update(tpf);
        if(KeyBindingManager.getKeyBindingManager().isValidCommand("exit", false)){
            halt();
        }
    }
 
    @Override
    public void cleanup() {
    }

    /**
     *
     */
    @Override
    public void initKeyBindings()
    {
        KeyBindingManager.getKeyBindingManager().set("exit",
                KeyInput.KEY_ESCAPE);
    }


    @Override
    protected void buildGUI(){
        super.buildGUI();
        // create the main window
        setCursorVisible(true);
      _window = new BWindow(BuiSystem.getStyle(), new AbsoluteLayout());
        _window.setSize(400, 300);
      int buttonWidth = _window.getWidth() / 4;
      int buttonHeight = 32;

      // Cancel button
      _btnCancel = new BButton("Cancel");
        _btnCancel.setPreferredSize(buttonWidth, buttonHeight);
      _window.add(_btnCancel, new Point(10, 20));

      // OK button
      _btnOk = new BButton("OK");
        _btnOk.setPreferredSize(buttonWidth, buttonHeight);
      _window.add(_btnOk, new Point(_window.getWidth() - 10 - buttonWidth, 20));

      _window.center();   
    }

    @Override
    protected void cleanupGUI(){
        super.cleanupGUI();
    }
}

The first thing I would try is to add the rsrc jar to your classpath.  That will fix a lot of your issues.



I'll run the code and see if you're missing anything else.


standtrooper said:

The first thing I would try is to add the rsrc jar to your classpath.  That will fix a lot of your issues.

I'll run the code and see if you're missing anything else.

I can play all demos without errors, so I think my classpath is correct. And it runs without any exception if I use .init without parameters. Thanks a lot for your support, I hope you can find what i'm doing wrong.

Thanks,
Dirso

Which imports did you use?  MenuGameState is quite ambiguous; there's the one I've got locally that I use with GBUI, there's the one mentioned in other places in this forums, and there's another one that's in another section of googlecode.

standtrooper said:

Which imports did you use?  MenuGameState is quite ambiguous; there's the one I've got locally that I use with GBUI, there's the one mentioned in other places in this forums, and there's another one that's in another section of googlecode.

Here is my MenuGameState

public class MenuGameState extends MyBasicGameState {
   public MenuGameState(String name){
        super(name);

   }

    @Override
    public void update(float tpf) {
        super.update(tpf);
    }

    @Override
    public void cleanup() {
    }
}

What is your Main class?  There's a reference to it, but no code for it (calls Main.hide I believe).


standtrooper said:

What is your Main class?  There's a reference to it, but no code for it (calls Main.hide I believe).

public class Main {

    static StandardGame game;
    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) throws Exception {
        game = new StandardGame("SuperPong3D");
      // Show settings screen
      GameSettingsPanel.prompt(game.getSettings());
      // Start StandardGame, it will block until it has initialized successfully, then return
      game.start();

        // creates the gui system


        PresentingGameState presState = new PresentingGameState();
        MainMenuGameState menuState = new MainMenuGameState();
        PongGameState pongState = new PongGameState();

      // Add it to the manager
      GameStateManager.getInstance().attachChild(presState);
        GameStateManager.getInstance().attachChild(menuState);
        GameStateManager.getInstance().attachChild(pongState);
      // Activate the game state
      presState.setActive(true);
        menuState.setActive(false);
        pongState.setActive(false);

    }

    public static void halt(){
        game.shutdown();
    }

ok, so I didn't have the other GameStates, but I changed the stylesheet to be a relative by adding a / in front of it



MyBasicGameState

change the line to this

BuiSystem.init(new PolledRootNode(Timer.getTimer(), input), "/atechnique/gbui/style2.bss");



that'll fix your issue.

standtrooper said:

ok, so I didn't have the other GameStates, but I changed the stylesheet to be a relative by adding a / in front of it

MyBasicGameState
change the line to this
BuiSystem.init(new PolledRootNode(Timer.getTimer(), input), "/atechnique/gbui/style2.bss");

that'll fix your issue.
I really don't understand.... Is there many differences between linux and windows? I'm running under WinXP and I still can't make it work... I even changed it to the Win full path "D:\atechnique\gbui\style2.bss" and I still get the exception:

INFO: Child (Some2DText) attached to this node (null)
java.lang.NullPointerException
        at java.io.Reader.<init>(Reader.java:61)
        at java.io.InputStreamReader.<init>(InputStreamReader.java:55)
        at com.jmex.bui.bss.BStyleSheetUtil.getStyleSheet(BStyleSheetUtil.java:134)
        at com.jmex.bui.bss.BStyleSheetUtil.getStyleSheet(BStyleSheetUtil.java:38)
        at com.jmex.bui.BuiSystem.init(BuiSystem.java:94)
        at com.jmex.bui.BuiSystem.init(BuiSystem.java:81)
        at superpong3d.MyBasicGameState.<clinit>(MyBasicGameState.java:60)
        at superpong3d.Main.main(Main.java:36)
java.lang.NullPointerException
        at java.io.Reader.<init>(Reader.java:61)
        at java.io.InputStreamReader.<init>(InputStreamReader.java:55)
        at com.jmex.bui.bss.BStyleSheetUtil.getStyleSheet(BStyleSheetUtil.java:134)
        at com.jmex.bui.bss.BStyleSheetUtil.getStyleSheet(BStyleSheetUtil.java:38)
        at com.jmex.bui.BuiSystem.init(BuiSystem.java:136)
        at com.jmex.bui.BuiSystem.init(BuiSystem.java:94)
        at com.jmex.bui.BuiSystem.init(BuiSystem.java:81)
        at superpong3d.MyBasicGameState.<clinit>(MyBasicGameState.java:60)
        at superpong3d.Main.main(Main.java:36)

I don't see what I'm doing wrong...
Thanks for your help,
Dirso

No, there aren't any differences between windows and linux, that I've ever found as far as classpaths.  If the data from atechnique is in your classpath you'll be fine.  I jar'd up the atechnique data and added that jar to my project classpath



Now, note that the atechnique data paths aren't included the same way…there's like atechnique/data/atechnique/data



I don't know why there's a duplicate of the root paths, I'll fix that one day…so the 2nd atechnique is the part you want to jar unless you change all your paths in the src to include the 2nd set of paths.



make sense?

I just ran your code just fine.  I'm running WinXP Pro.

standtrooper said:

No, there aren't any differences between windows and linux, that I've ever found as far as classpaths.  If the data from atechnique is in your classpath you'll be fine.  I jar'd up the atechnique data and added that jar to my project classpath

Now, note that the atechnique data paths aren't included the same way...there's like atechnique/data/atechnique/data

I don't know why there's a duplicate of the root paths, I'll fix that one day...so the 2nd atechnique is the part you want to jar unless you change all your paths in the src to include the 2nd set of paths.

make sense?
I just ran your code just fine.  I'm running WinXP Pro.

Sorry, I didn't knew I have to add the data folder to the path, now It runs fine, but still I can't see anything... I debugged to see if it was passing by the buildGUI code and it is, but nothing on screen... Is there anything else I should check?

Thanks again for your attention,
Dirso

hmm…dunno.  I didn't see anything either.  Let me look at the code again to see if there's anything there that I missed.

This is going to be a little more indepth…this is an issue where the GameState isn't being updated, or possibly added to.  I'll go through my GameState code in my engine and see what I did differently.  Right off hand nothing jumps right out

standtrooper said:

This is going to be a little more indepth...this is an issue where the GameState isn't being updated, or possibly added to.  I'll go through my GameState code in my engine and see what I did differently.  Right off hand nothing jumps right out

Thanks! I'll be waiting for your answer.

In the meantime you can check out

http://www.jmonkeyengine.com/jmeforum/index.php?topic=10923.0

and see if there are any differences between the two sets of code… I’ve got to look at both of them this evening

standtrooper said:

In the meantime you can check out
http://www.jmonkeyengine.com/jmeforum/index.php?topic=10923.0
and see if there are any differences between the two sets of code... I've got to look at both of them this evening
I'll take a look this weekend. I'm really enjoying JME. Thanks a lot all you for given us such a nice tool.