SimpleAppState vs BaseAppState: which one is reccommended?

I usually extend SimpleAppState, but (unsurprisingly) lemur and in general pspeed’s code uses BaseAppState.

It may seem a dumb question, as it is probably a matter of personal preference, but which one is better?

Can I put my code from cleanup() into stateDetached() and forget about it?

StateDetached is not the same as cleanup, no. Its called when the state is detached and not guaranteed to run on the update thread. Its only for very special things really. Otherwise yes, its a matter of preference.

Oh well… should have checked
http://wiki.jmonkeyengine.org/doku.php/jme3:advanced:application_states

:sweat:

Where does this class come from? I don’t see it in JME.

Most app states will be easier to write if they extend (JME’s) BaseAppState (which is a direct copy of Lemur’s). It provides a nicer enable/disable life cycle and makes it incredibly easy to look up other app states.

And yeah, almost always if you are putting code in stateAttached() or stateDetached() then you are doing something wrong.

Found on a plugin:

Ugh… definitely don’t use that. It repeats every anti-pattern that SimpleApplication does and it’s even worse for being an app state.

This assumes that SimpleApplication contains several antipattern that I should avoid. Is there a wiki for that?

SimpleApplication provides the handy getGuiNode()… is it an anti-pattern?

The anti-pattern is all of the protected fields. Let’s say we wanted to move management of the root node and guiNode into app states like they probably should have been (hindsight being 20/20)… well, the class says a big f*ck you to that. This is why this class will be deprecated soon. I already had to do “very bad things” ™ to move fly cam to an app state… and don’t get me started on the stats crap.

I think one day I will print this class out and set the print out on fire just to get some closure.

2 Likes

And then you’ll be free to take care of BitmapText :wink:

1 Like

“Sir… please, just put the rifle down and get face down on the ground…”

@nehon pretty cruel today or?
Best is to never speak about that class anymore.

I wonder, if we revert BitmapText to the version from 2009, would anyone notice?

I certainly would… it’s bound to have bugs that haven’t been fixed yet. And for the moment BitmapText is working as long as one treads lightly in the code.

Someday, I will rewrite the whole thing to centralize more of the functionality on BitmapFont where it belongs instead of having it implemented two or three times… but I need to be in the proper frame of mind.

I would not, I know why I stay as far away as possible by using JFX :stuck_out_tongue:

1 Like

I usually just extend http://javadoc.jmonkeyengine.org/com/jme3/app/state/AbstractAppState.html

Works fine for 99% of my use cases.

The new BaseAppState is even better. It helps manage the setEnabled() life cycle which can be tricky to get right on your own… plus it provides easy access to other states, the application, etc…

I must have a look at that then :smiley: