Normen Hansen videos

I added source code pages for Normens videos 1 & 2.
https://jmonkeyengine.github.io/wiki/jme3.html#controlling-game-logic

I did this because the videos have over 16k hits and the link to the code is broken on the forum page.

For ConfigAppState, I took the liberty of extending Pauls’ BaseAppState rather than AbstractAppState to introduce this class for the first time in the wiki. I just tweaked the code and added Pauls’ comments in a minor way to expose how it works to new users.

https://jmonkeyengine.github.io/wiki/jme3/advanced/sourcecode.html

At one time I had this in my test project and it ran fine, however due to an erroneous delete it got wiped. I had to do this by watching the video so if I missed something please let me know.

4 Likes

I have seen BaseAppState somewhere but I always have used AbstractAppState. What is BaseAppState and when do I use it?

1 Like

Javadoc is your friend:
http://javadoc.jmonkeyengine.org/com/jme3/app/state/BaseAppState.html

Always… pretty much.

AbstractAppState is like the most minimal of the minimal implementations of the AppState interface. You essentially still need to do everything yourself, including getting the funky enable/disable/initialized/terminate logic right.

Instead, just extend BaseAppState and you get onEnable() and onDisable() already worked out for you.

2 Likes

Just like pspeed said. I use BaseAppState since I know about it. It is much more friendly.

Shouldn’t the introduction to BaseAppState be in the App States section on the wiki?. I think that it is much more used (once you know it exists) than the AbstractAppState so it should be more centered on the former.

(In my opinion it could even replace it in the whole page but leave a mention to the AbstractAppState)

1 Like

As far as I’m aware paul wrote BaseAppState in lemur, and it made its way into core. A paragraph highlighting its presence and the differences between it and AbstractAppState would be nice.

2 Likes

Yes, but it wasn’t applicable officially until 3.1stable.

1 Like

I was planning on adding something shortly. Wiki is so massive and at same time I study the engine and fix things as I come to them. Ill list the differences here before hand to see if I miss something before making any changes.

Edit: Forgot to mention, I’m almost done with learning the engine so when things like this come up its because I am backtracking on stuff while I have a break.

1 Like

BaseAppState improvements.

You no longer need to call
super.initialize(stateManager, app);
because it is now called by BaseAppState upon initialization for you.

You no longer have to cast SimpleApplication to have access to AssetManager, AppStateManager, and you can even get a State directly. Paul added everything for you in BaseAppState.
getApplication();
getAssetManager();
getState(type);

You still have to cast SimpleApplication to get rootNode.

You no longer call super during cleanup, its done for you now.

As Paul said,[quote=“pspeed, post:3, topic:38796”]
Instead, just extend BaseAppState and you get onEnable() and onDisable() already worked out for you.
[/quote]

To quote Paul:

Cleanup and setEnabled now have logging built in.

I made a template, when I first started jMonkey, for my personal use that can be used in the SDK. Travis doesn’t like me when it comes to the SDK but if this template looks good to everyone it can be used.

<#assign licenseFirst = "/*">
<#assign licensePrefix = " * ">
<#assign licenseLast = " */">
<#include "../Licenses/license-${project.license}.txt">

<#if package?? && package != "">
package ${package};

</#if>
import com.jme3.app.Application;
import com.jme3.app.state.BaseAppState;

/**
 *
 * @author ${user}
 */
public class ${name} extends BaseAppState {
    
    @Override
    protected void initialize(Application app) {
        //It is technically safe to do all initialization and cleanup in the 
        //onEnable()/onDisable() methods. Choosing to use initialize() and 
        //cleanup() for this is a matter of performance specifics for the 
        //implementor.
        //TODO: initialize your AppState, e.g. attach spatials to rootNode
    }

    @Override
    protected void cleanup(Application app) {
        //TODO: clean up what you initialized in the initialize method,
        //e.g. remove all spatials from rootNode
    }

    //onEnable()/onDisable() can be used for managing things that should 
    //only exist while the state is enabled. Prime examples would be scene 
    //graph attachment or input listener attachment.
    @Override
    protected void onEnable() {
        //Called when the state is fully enabled, ie: is attached and 
        //isEnabled() is true or when the setEnabled() status changes after the 
        //state is attached.
    }

    @Override
    protected void onDisable() {
        //Called when the state was previously enabled but is now disabled 
        //either because setEnabled(false) was called or the state is being 
        //cleaned up.
    }
    
    @Override
    public void update(float tpf) {
        //TODO: implement behavior during runtime
    }
    
}

If I missed something please point it out.

5 Likes

The code is here: https://www.dropbox.com/s/pppw533p0dw1pmk/SDK-UsecaseDemo_1.zip?dl=1

1 Like

Sweet, it has the assets to. I made my own when I ran through your videos awhile back.

Do you mind if I upload the zip to the wiki and reference that instead?

Edit:By instead I mean instead of the code I pasted on the source page, keeping the link to your forum post on the videos in the source page and adding another link to the zip file.

1 Like

Sure, I also fixed the video in the post where it was originally linked.

1 Like