SimpleGame - light version of SimpleApp

Hello everyone :smiley:
I’ve seen topic, where someone complained about SimpleApp class. So, here is simplest and lightest version

game.SimpleGame.class
[java]
/**

  • SimpleGame - light version of com.jme3.app.SimpleApplication

  • @author

  • @since

  • @version
    */
    public abstract class SimpleGame extends Application
    {
    // -------------------------------------------------------- \
    // ===========================================================
    // Constants
    // ===========================================================

    /** Root Node **/
    protected final Node rootNode = new Node(“Root Node”);

    /** GUI Node **/
    protected Node guiNode = new Node(“Gui Node”);

    /** Show application settings ? **/
    private boolean showSettings;

    // ===========================================================
    // Fields
    // ===========================================================
    // ===========================================================
    // Constructors
    // ===========================================================

    /**

    • Default constructor
      */
      public SimpleGame( )
      {
      super( );
      }

    // ===========================================================
    // Getter & Setter
    // ===========================================================

    /**

    • Retrieves guiNode
    • @return guiNode Node object

    */
    public final Node getGuiNode( ) { return guiNode; }

    /**

    • Retrieves rootNode
    • @return rootNode Node object

    */
    public final Node getRootNode( ) { return rootNode; }

    /**

    • <b>Sets showSettings</b>
    • <br>
    • <i>If showSettings == true => JME3 settings windows will be shown.
    • <br>
    • <u>Default value of showSettings is false</u></i>
    • <br>
    • <br>
    • @param pValue - <i>value to set</i>
      */
      public final void setShowSettings( final boolean pValue ) { showSettings = pValue; }

    // ===========================================================
    // Methods for/from SuperClass/Interfaces
    // ===========================================================

    @Override
    public final void start( )
    {
    // set some default settings in-case
    // settings dialog is not shown
    boolean loadSettings = false;
    if (settings == null) {
    setSettings(new AppSettings(true));
    loadSettings = true;
    }

     // show settings dialog
     if (showSettings) {
         if (!JmeSystem.showSettingsDialog(settings, loadSettings)) {
             return;
         }
     }
     
     //re-setting settings they can have been merged from the registry.
     setSettings(settings);
     super.start();
    

    }

    @Override
    public final void initialize( )
    {
    super.initialize();

     guiNode.setQueueBucket( Bucket.Gui );
     guiNode.setCullHint( CullHint.Never );
     viewPort.attachScene( rootNode );
     guiViewPort.attachScene( guiNode );
     
     onInit( );
    

    }

    @Override
    public final void update( )
    {
    super.update( );// makes sure to execute AppTasks

     if (speed == 0 || paused)
         return;
     
     final float tpf = timer.getTimePerFrame() * speed;
     
     // update states
     stateManager.update(tpf);
     
     // simple update and root node
     onUpdate(tpf);
     
     rootNode.updateLogicalState(tpf);
     guiNode.updateLogicalState(tpf);
     
     rootNode.updateGeometricState();
     guiNode.updateGeometricState();
     
     // render states
     stateManager.render(renderManager);
     renderManager.render(tpf, context.isRenderable());
     onRender(renderManager);
     stateManager.postRender(); 
    

    }

    // ===========================================================
    // Methods
    // ===========================================================

    /**

    • <i><b>Override this method to handle initialization</b></i>
    • <br>
    • <br>
      */
      protected abstract void onInit( );

    /**

    • <i><b>Override this method to handle logic update</b></i>
    • <br>
    • <br>
    • @param timePerFrame - <i>time since last update called</i>
      */
      protected abstract void onUpdate( final float timePerFrame );

    /**

    • <i><b>Override this method to handle render</b></i>
    • <br>
    • <br>
    • @param renderManager - <i>RenderManager</i>
      */
      protected abstract void onRender( final RenderManager renderManager );

    // ===========================================================
    // Inner and Anonymous Classes
    // ===========================================================
    // -------------------------------------------------------- \
    }
    [/java]

Since it has protected access to methods, subclasses must be in same package
And here is an example:

game.Game.class

[java]
public final class Game extends SimpleGame
{
// -------------------------------------------------------- \
// ===========================================================
// Constants
// ===========================================================
// ===========================================================
// Fields
// ===========================================================
// ===========================================================
// Constructors
// ===========================================================
// ===========================================================
// Getter & Setter
// ===========================================================
// ===========================================================
// Methods for/from SuperClass/Interfaces
// ===========================================================

@Override
protected final void onInit( )
{
    
}

@Override
protected final void onUpdate( final float timePerFrame )
{
    
}

@Override
protected final void onRender( final RenderManager renderManager )
{
    
}

// ===========================================================
// Methods
// ===========================================================

public final static void main( final String[] args )
{
    //Create game
    final Game game = new Game( );
    
    //Create AppSettings
    final AppSettings settings = new AppSettings( true );
    
    //Set App settings
    game.setSettings( settings );
    
    //Disable default settings screen
    game.setShowSettings( false );
    
    game.start( );
}

// ===========================================================
// Inner and Anonymous Classes
// ===========================================================
// -------------------------------------------------------- \\

}
[/java]

In practice, SimpleApp is better to use, since it has all-in-one. :stuck_out_tongue_winking_eye:

1 Like

SimpleApplication is always better to use. There is no real downside and the complaint you saw must have been ancient. Stuff was refactored maybe two years ago now so that you could easily remove the stuff you don’t want.

Also, this: “Since it has protected access to methods, subclasses must be in same package” is not true.

I recommend that everyone use SimpleApplication to avoid support issues. At least until I deprecate it and replace it with a better named BaseApplication class.

1 Like

Sorry about pooping all over your contribution. It’s nice that you wanted to contribute but this is a bit of a sore spot. Thanks for the effort, though.

It’s a very nice initiative. I hope this won’t deter you from suggesting other improvements. Just try tell us in advance what you’re working on so we can coordinate better. If you could please link to some of the topics with complaints about the SimpleApplication class, we could review them and see if anything does in fact need to be addressed.

1 Like