Package com.jme3.app.state
Class AppStateManager
java.lang.Object
com.jme3.app.state.AppStateManager
The
When an
AppStateManager
holds a list of AppState
s which
it will update and render.When an
AppState
is attached or detached, the
AppState.stateAttached(com.jme3.app.state.AppStateManager)
and
AppState.stateDetached(com.jme3.app.state.AppStateManager)
methods
will be called respectively.
The lifecycle for an attached AppState is as follows:
- stateAttached() : called when the state is attached on the thread on which the state was attached.
- initialize() : called ONCE on the render thread at the beginning of the next AppStateManager.update().
- stateDetached() : called when the state is detached on the thread on which the state was detached. This is not necessarily on the render thread and it is not necessarily safe to modify the scene graph, etc..
- cleanup() : called ONCE on the render thread at the beginning of the next update after the state has been detached or when the application is terminating.
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionboolean
Attach a state to the AppStateManager, the same state cannot be attached twice.void
Attaches many state to the AppStateManager in a way that is guaranteed that they will all get initialized before any of their updates are run.void
Attaches many state to the AppStateManager in a way that is guaranteed that they will all get initialized before any of their updates are run.void
cleanup()
Calls cleanup on attached states, do not call directly.boolean
Detaches the state from the AppStateManager.Returns the Application to which this AppStateManager belongs.protected AppState[]
<T extends AppState>
TReturns the first state that is an instance of subclass of the specified class.<T extends AppState>
TReturns the first state that is an instance of subclass of the specified class.<T extends AppState>
TReturns the state associated with the specified ID at the time it was attached or null if not state was attached with that ID.protected AppState[]
protected AppState[]
boolean
Check if a state is attached or not.boolean
Returns true if there is currently a state associated with the specified ID.protected void
void
Calls render for all attached and initialized states, do not call directly.void
render
(RenderManager rm) Calls render for all attached and initialized states, do not call directly.<T extends AppState>
TstateForId
(String id, Class<T> stateClass) Returns the state associated with the specified ID at the time it was attached or throws an IllegalArgumentException if the ID was not found.protected void
void
update
(float tpf) Calls update for attached states, do not call directly.
-
Constructor Details
-
AppStateManager
-
-
Method Details
-
getApplication
Returns the Application to which this AppStateManager belongs.- Returns:
- the pre-existing instance
-
getInitializing
-
getTerminating
-
getStates
-
attach
Attach a state to the AppStateManager, the same state cannot be attached twice. Throws an IllegalArgumentException if the state has an ID and that ID has already been associated with another AppState.- Parameters:
state
- The state to attach- Returns:
- True if the state was successfully attached, false if the state was already attached.
-
attachAll
Attaches many state to the AppStateManager in a way that is guaranteed that they will all get initialized before any of their updates are run. The same state cannot be attached twice and will be ignored.- Parameters:
states
- The states to attach
-
attachAll
Attaches many state to the AppStateManager in a way that is guaranteed that they will all get initialized before any of their updates are run. The same state cannot be attached twice and will be ignored.- Parameters:
states
- The states to attach
-
detach
Detaches the state from the AppStateManager.- Parameters:
state
- The state to detach- Returns:
- True if the state was detached successfully, false if the state was not attached in the first place.
-
hasState
Check if a state is attached or not.- Parameters:
state
- The state to check- Returns:
- True if the state is currently attached to this AppStateManager.
- See Also:
-
getState
Returns the first state that is an instance of subclass of the specified class.- Type Parameters:
T
- the desired type of AppState- Parameters:
stateClass
- the desired type of AppState- Returns:
- First attached state that is an instance of stateClass
-
getState
Returns the first state that is an instance of subclass of the specified class.- Type Parameters:
T
- the desired type of AppState- Parameters:
stateClass
- the desired type of AppStatefailOnMiss
- true to throw an exception, false to return null- Returns:
- First attached state that is an instance of stateClass. If failOnMiss is true then an IllegalArgumentException is thrown if the state is not attached.
-
getState
Returns the state associated with the specified ID at the time it was attached or null if not state was attached with that ID.- Type Parameters:
T
- the desired type of AppState- Parameters:
id
- the AppState IDstateClass
- the desired type of AppState- Returns:
- the pre-existing instance, or null if not found
-
hasState
Returns true if there is currently a state associated with the specified ID.- Parameters:
id
- the AppState ID- Returns:
- true if found, otherwise false
-
stateForId
Returns the state associated with the specified ID at the time it was attached or throws an IllegalArgumentException if the ID was not found.- Type Parameters:
T
- the desired type of AppState- Parameters:
id
- the AppState IDstateClass
- the desired type of AppState- Returns:
- the pre-existing instance (not null)
-
initializePending
protected void initializePending() -
terminatePending
protected void terminatePending() -
update
public void update(float tpf) Calls update for attached states, do not call directly.- Parameters:
tpf
- Time per frame.
-
render
Calls render for all attached and initialized states, do not call directly.- Parameters:
rm
- The RenderManager
-
postRender
public void postRender()Calls render for all attached and initialized states, do not call directly. -
cleanup
public void cleanup()Calls cleanup on attached states, do not call directly.
-