public abstract class BaseAppState extends java.lang.Object implements AppState
initialize() and cleanup() can be used by subclasses to manage resources that should exist the entire time that the app state is attached. This is useful for resources that might be expensive to create or load.
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.
The base class logic is such that onDisable() will always be called before cleanup() if the state is enabled. Likewise, enable() will always be called after initialize() if the state is enable(). onEnable()/onDisable() are also called appropriate when setEnabled() is called that changes the enabled state AND if the state is attached. In other words, onEnable()/onDisable() are only ever called on an already attached state.
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.
Modifier | Constructor and Description |
---|---|
protected |
BaseAppState() |
protected |
BaseAppState(java.lang.String id) |
Modifier and Type | Method and Description |
---|---|
void |
cleanup()
Do not call directly: Called by the state manager to terminate this
state post-detachment or during state manager termination.
|
protected abstract void |
cleanup(Application app)
Called after the app state is detached or during
application shutdown if the state is still attached.
|
Application |
getApplication() |
java.lang.String |
getId()
Returns the unique ID for this AppState or null if it has no
unique ID.
|
<T extends AppState> |
getState(java.lang.Class<T> type) |
<T extends AppState> |
getState(java.lang.Class<T> type,
boolean failOnMiss) |
<T extends AppState> |
getState(java.lang.String id,
java.lang.Class<T> type) |
<T extends AppState> |
getState(java.lang.String id,
java.lang.Class<T> type,
boolean failOnMiss) |
AppStateManager |
getStateManager() |
protected abstract void |
initialize(Application app)
Called during initialization once the app state is
attached and before onEnable() is called.
|
void |
initialize(AppStateManager stateManager,
Application app)
Do not call directly: Called by the state manager to initialize this
state post-attachment.
|
boolean |
isEnabled() |
boolean |
isInitialized() |
protected abstract 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.
|
protected abstract 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.
|
void |
postRender()
Called after all rendering commands are flushed.
|
void |
render(RenderManager rm)
Render the state.
|
void |
setEnabled(boolean enabled)
Enable or disable the functionality of the
AppState . |
protected void |
setId(java.lang.String id)
Sets the unique ID of this app state.
|
void |
stateAttached(AppStateManager stateManager)
Called by
AppStateManager.attach(com.jme3.app.state.AppState)
when transitioning this
AppState from detached to initializing. |
void |
stateDetached(AppStateManager stateManager)
Called by
AppStateManager.detach(com.jme3.app.state.AppState)
when transitioning this
AppState from running to terminating. |
void |
update(float tpf)
Called to update the
AppState . |
protected BaseAppState()
protected BaseAppState(java.lang.String id)
protected abstract void initialize(Application app)
app
- the applicationprotected abstract void cleanup(Application app)
app
- the applicationprotected abstract void onEnable()
protected abstract void onDisable()
public final void initialize(AppStateManager stateManager, Application app)
initialize
in interface AppState
stateManager
- The state managerapp
- The applicationpublic final boolean isInitialized()
isInitialized
in interface AppState
initialize()
was called on the state,
false otherwise.protected void setId(java.lang.String id)
id
- the desired IDpublic java.lang.String getId()
AppState
public final Application getApplication()
public final AppStateManager getStateManager()
public final <T extends AppState> T getState(java.lang.Class<T> type)
public final <T extends AppState> T getState(java.lang.Class<T> type, boolean failOnMiss)
public final <T extends AppState> T getState(java.lang.String id, java.lang.Class<T> type)
public final <T extends AppState> T getState(java.lang.String id, java.lang.Class<T> type, boolean failOnMiss)
public final void setEnabled(boolean enabled)
AppState
AppState
.
The effect of this call depends on implementation. An
AppState
starts as being enabled by default.
A disabled AppState
s does not get calls to
AppState.update(float)
, AppState.render(RenderManager)
, or
AppState.postRender()
from its AppStateManager
.setEnabled
in interface AppState
enabled
- activate the AppState or not.public final boolean isEnabled()
isEnabled
in interface AppState
AppState
is enabled, false otherwise.AppState.setEnabled(boolean)
public void stateAttached(AppStateManager stateManager)
AppState
AppStateManager.attach(com.jme3.app.state.AppState)
when transitioning this
AppState
from detached to initializing.
There is no assumption about the thread from which this function is
called, therefore it is unsafe to modify the scene graph
from this method. Please use
AppState.initialize(com.jme3.app.state.AppStateManager, com.jme3.app.Application)
instead.
stateAttached
in interface AppState
stateManager
- State manager to which the state was attached to.public void stateDetached(AppStateManager stateManager)
AppState
AppStateManager.detach(com.jme3.app.state.AppState)
when transitioning this
AppState
from running to terminating.
There is no assumption about the thread from which this function is
called, therefore it is unsafe to modify the scene graph
from this method. Please use
AppState.cleanup()
instead.
stateDetached
in interface AppState
stateManager
- The state manager from which the state was detached from.public void update(float tpf)
AppState
AppState
. This method will be called
every render pass if the AppState
is both attached and enabled.public void render(RenderManager rm)
AppState
AppState
is both attached and enabled.public void postRender()
AppState
AppState
is both attached and enabled.postRender
in interface AppState