Class AppStateManager

java.lang.Object
com.jme3.app.state.AppStateManager

public class AppStateManager extends Object
The AppStateManager holds a list of AppStates 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

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    boolean
    Attach a state to the AppStateManager, the same state cannot be attached twice.
    void
    attachAll(AppState... states)
    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
    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>
    T
    getState(Class<T> stateClass)
    Returns the first state that is an instance of subclass of the specified class.
    <T extends AppState>
    T
    getState(Class<T> stateClass, boolean failOnMiss)
    Returns the first state that is an instance of subclass of the specified class.
    <T extends AppState>
    T
    getState(String id, Class<T> stateClass)
    Returns 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
    Calls render for all attached and initialized states, do not call directly.
    <T extends AppState>
    T
    stateForId(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.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • AppStateManager

      public AppStateManager(Application app)
  • Method Details

    • getApplication

      public Application getApplication()
      Returns the Application to which this AppStateManager belongs.
      Returns:
      the pre-existing instance
    • getInitializing

      protected AppState[] getInitializing()
    • getTerminating

      protected AppState[] getTerminating()
    • getStates

      protected AppState[] getStates()
    • attach

      public boolean attach(AppState state)
      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

      public void attachAll(AppState... states)
      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

      public void attachAll(Iterable<AppState> states)
      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

      public boolean detach(AppState state)
      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

      public boolean hasState(AppState state)
      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

      public <T extends AppState> T getState(Class<T> stateClass)
      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

      public <T extends AppState> T getState(Class<T> stateClass, boolean failOnMiss)
      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
      failOnMiss - 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

      public <T extends AppState> T getState(String id, Class<T> stateClass)
      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 ID
      stateClass - the desired type of AppState
      Returns:
      the pre-existing instance, or null if not found
    • hasState

      public boolean hasState(String id)
      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

      public <T extends AppState> T stateForId(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.
      Type Parameters:
      T - the desired type of AppState
      Parameters:
      id - the AppState ID
      stateClass - 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

      public void render(RenderManager rm)
      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.