AppStates in ”SimpleApplication” rather than ”Application”

Hi,



I’ve got the classes of “RootNodeState” and “TestAppStates” from http://code.google.com/p/jmonkeyengine/source/browse/trunk/engine/src/test/jme3test/app/state/ successfully working. However, I notice that jMonkeyPlatform says



“Updating is not needed in JME3, check your update order if you need to call this”



about



[java]rootNode.updateLogicalState(tpf);

rootNode.updateGeometricState(); [/java]

(In effect, depreciating them?)



I’ve also edited the files so that TestAppStates extends SimpleApplication rather than just Application, so that I can see how it works in the context of the former.

The primary change is that in “TestAppStates” I changed initialise to simpleInitApp, and had “TestAppStates” extend SimpleApplication rather than Application. The code still works after I do this.



As such, I was wondering if anybody knew how I could alter “update” in TestAppStates to simpleUpdate, so that SimpleApplication is properly overridden, and also if a method exists to get rid of



[java]rootNode.updateLogicalState(tpf);

rootNode.updateGeometricState();[/java]

in TestAppStates (if at the end of the day, it’s not good practice)



Is it necassary for me to change these things, or shall I just stay with what works?



Thanks



The code for both files is here:



TestAppStates.java



[java]

package mygame;



import com.jme3.app.SimpleApplication;

import com.jme3.app.state.AppState;

import com.jme3.scene.Spatial;

import com.jme3.system.AppSettings;

import com.jme3.system.JmeContext;



public class TestAppStates extends SimpleApplication {

public static void main(String[] args) {

TestAppStates app = new TestAppStates();

app.start();

}



@Override

public void start(JmeContext.Type contextType) {

AppSettings simulatorSettings = new AppSettings(true);

simulatorSettings.setResolution(1280,720);

setSettings(simulatorSettings);

setShowSettings(false);

super.start(contextType);

}



@Override

public void simpleInitApp() {

RootNodeState rootNodeState = new RootNodeState();

viewPort.attachScene(rootNodeState.getRootNode());



Spatial model = assetManager.loadModel(“Models/Teapot/Teapot.obj”);

model.scale(3);

model.setMaterial(assetManager.loadMaterial(“Interface/Logo/Logo.j3m”));

rootNodeState.getRootNode().attachChild(model);



stateManager.attach((AppState)rootNodeState);

}



@Override

public void update() {

super.update();

// do some animation

float tpf = timer.getTimePerFrame();



stateManager.update(tpf);

stateManager.render(renderManager);



renderManager.render(tpf, context.isRenderable());

}

}

[/java]



RootNodeState.java



[java]

package mygame;



import com.jme3.app.Application;

import com.jme3.app.SimpleApplication;

import com.jme3.app.state.AbstractAppState;

import com.jme3.app.state.AppStateManager;

import com.jme3.scene.Node;

import com.jme3.scene.Spatial;



public class RootNodeState extends AbstractAppState {



protected SimpleApplication app;

protected Node rootNode = new Node(“Root Node”);;



public Node getRootNode() {

return rootNode;

}



@Override

public void update(float tpf) {

super.update(tpf);



rootNode.updateLogicalState(tpf);

rootNode.updateGeometricState();

}



@Override

public void initialize(AppStateManager stateManager, Application app) {

super.initialize(stateManager, app);

this.app=(SimpleApplication)app;

}

}

[/java]



EDIT: initialize in RootNodeState is not needed, I’ve accidentally left it from when working with screencontrollers

the updating message in the SDK is not correct in this case, its mainly for jME2 users who were used to use this call to get a world translation for their spatials. In this special case (you manage a rootNode yourself) it is correct to call these.

Thanks, that sorts that one out!



Is it necessary for me to change update to simpleUpdate if it works anyway? (As I want to extend SimpleApplication).



I don’t want any problems to arise later on!

Yeah, if you override update you need to implement all of its logic.

Well, I’ve tried changing update to simpleUpdate something like this:



[java]@Override

public void simpleUpdate(float tpf) {

super.simpleUpdate(tpf);

// do some animation



stateManager.update(tpf);

stateManager.render(renderManager);



renderManager.render(tpf, context.isRenderable());

}[/java]



But it doesn’t work; does anybody know what I have to change?

Hmm? You don’t have to do all that in SimpeApplication, it does that already.

so, should I leave update as it is, and not bother implementing simpleUpdate?

No, you just implement simpleUpdate if you need to do anything, apparently you don’t if thats all you would call. Its all done in SimpleApplication already. If you do everything else via AppStates theres no need to override any of the update methods of SimpleApplication.

Alright, so just have both if necessary ^^. Thanks for your help. :smiley:

You shouldn’t override update() or add functionality if you want to keep compatibility with future updates. If we make changes we make them in the expectance that people overrode simpleUpdate() and not update()

To bad there’s not a pair of annotations:

@DoNotOverride for SimpleApplication.update()



And then a corresponding:

@KnowImDoingBadThings for the simple application subclasses that really need to for some reason. :slight_smile:

We’ll get there ^^ Just need to get that darn annotation checker going, then this stuff can be added easily ^^