Class BaseAppState
- All Implemented Interfaces:
AppState
- Direct Known Subclasses:
ArmatureDebugAppState
,AudioListenerState
,BasicProfilerState
,ConstantVerifierState
,DetailedProfilerState
,EnvironmentCamera
,LightsDebugState
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.
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionfinal 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.final Application
getId()
Returns the unique ID for this AppState or null if it has no unique ID.final <T extends AppState>
Tfinal <T extends AppState>
Tfinal <T extends AppState>
Tfinal <T extends AppState>
Tfinal AppStateManager
protected abstract void
initialize
(Application app) Called during initialization once the app state is attached and before onEnable() is called.final void
initialize
(AppStateManager stateManager, Application app) Do not call directly: Called by the state manager to initialize this state post-attachment.final boolean
final boolean
protected abstract void
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
Called after all rendering commands are flushed.void
render
(RenderManager rm) Render the state.final void
setEnabled
(boolean enabled) Enable or disable the functionality of theAppState
.protected void
Sets the unique ID of this app state.void
stateAttached
(AppStateManager stateManager) Called byAppStateManager.attach(com.jme3.app.state.AppState)
when transitioning thisAppState
from detached to initializing.void
stateDetached
(AppStateManager stateManager) Called byAppStateManager.detach(com.jme3.app.state.AppState)
when transitioning thisAppState
from running to terminating.void
update
(float tpf) Called to update theAppState
.
-
Constructor Details
-
BaseAppState
protected BaseAppState() -
BaseAppState
-
-
Method Details
-
initialize
Called during initialization once the app state is attached and before onEnable() is called.- Parameters:
app
- the application
-
cleanup
Called after the app state is detached or during application shutdown if the state is still attached. onDisable() is called before this cleanup() method if the state is enabled at the time of cleanup.- Parameters:
app
- the application
-
onEnable
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. -
onDisable
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. -
initialize
Do not call directly: Called by the state manager to initialize this state post-attachment. This implementation calls initialize(app) and then onEnable() if the state is enabled.- Specified by:
initialize
in interfaceAppState
- Parameters:
stateManager
- The state managerapp
- The application
-
isInitialized
public final boolean isInitialized()- Specified by:
isInitialized
in interfaceAppState
- Returns:
- True if
initialize()
was called on the state, false otherwise.
-
setId
Sets the unique ID of this app state. Note: that setting this while an app state is attached to the state manager will have no effect on ID-based lookups.- Parameters:
id
- the desired ID
-
getId
Description copied from interface:AppState
Returns the unique ID for this AppState or null if it has no unique ID. -
getApplication
-
getStateManager
-
getState
-
getState
-
getState
-
getState
-
setEnabled
public final void setEnabled(boolean enabled) Description copied from interface:AppState
Enable or disable the functionality of theAppState
. The effect of this call depends on implementation. AnAppState
starts as being enabled by default. A disabledAppState
s does not get calls toAppState.update(float)
,AppState.render(RenderManager)
, orAppState.postRender()
from itsAppStateManager
.- Specified by:
setEnabled
in interfaceAppState
- Parameters:
enabled
- activate the AppState or not.
-
isEnabled
public final boolean isEnabled() -
stateAttached
Description copied from interface:AppState
Called byAppStateManager.attach(com.jme3.app.state.AppState)
when transitioning thisAppState
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.- Specified by:
stateAttached
in interfaceAppState
- Parameters:
stateManager
- State manager to which the state was attached to.
-
stateDetached
Description copied from interface:AppState
Called byAppStateManager.detach(com.jme3.app.state.AppState)
when transitioning thisAppState
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.- Specified by:
stateDetached
in interfaceAppState
- Parameters:
stateManager
- The state manager from which the state was detached from.
-
update
public void update(float tpf) Description copied from interface:AppState
Called to update theAppState
. This method will be called every render pass if theAppState
is both attached and enabled. -
render
Description copied from interface:AppState
Render the state. This method will be called every render pass if theAppState
is both attached and enabled. -
postRender
public void postRender()Description copied from interface:AppState
Called after all rendering commands are flushed. This method will be called every render pass if theAppState
is both attached and enabled.- Specified by:
postRender
in interfaceAppState
-
cleanup
public final void cleanup()Do not call directly: Called by the state manager to terminate this state post-detachment or during state manager termination. This implementation calls onDisable() if the state is enabled and then cleanup(app).
-