Class StateManager

java.lang.Object
com.blackrook.engine.state.StateManager
All Implemented Interfaces:
EngineInputHandler, EngineUpdateHandler

public class StateManager extends Object implements EngineUpdateHandler, EngineInputHandler
The state manager class for maintaining exclusive, updatable states.
Author:
Matthew Tropiano
  • Constructor Details

    • StateManager

      public StateManager()
  • Method Details

    • change

      public void change(StateManager.StateEntry... changeStates)
      Changes the current state by emptying the state stack and pushing new ones onto the stack by name. Calls State.exit() on each state popped and State.enter(StateConfig) on each state pushed.
      Parameters:
      changeStates - the states to push in the specified order.
    • push

      public void push(StateManager.StateEntry... pushStates)
      Pushes new states onto the stack. Calls State.enter(StateConfig) on each state pushed.
      Parameters:
      pushStates - the states to push in the specified order. onto the stack, false if at least one was not.
    • pop

      public State pop()
      Pops a bunch of game states off of the state stack as returns it. Calls State.exit() on the state popped.
      Returns:
      the state popped.
    • pop

      public void pop(int stateCount)
      Pops a bunch of game states off of the state stack. Calls State.exit() on each state popped.
      Parameters:
      stateCount - the amount of states to pop.
    • update

      public void update(long tick, long currentNanos)
      Description copied from interface: EngineUpdateHandler
      Updates this component.
      Specified by:
      update in interface EngineUpdateHandler
      Parameters:
      tick - the current tick in the updater (counts upward each update).
      currentNanos - the current nanotime for the update frame.
    • onInputFlag

      public boolean onInputFlag(String code, boolean set)
      Description copied from interface: EngineInputHandler
      Handles a boolean input code setting. This is best used for things like key presses and mouse buttons and anything else that has a semantically boolean state.

      This method is called if the previous input listeners did not handle this.

      Specified by:
      onInputFlag in interface EngineInputHandler
      Parameters:
      code - the input code.
      set - true if active, false if inactive.
      Returns:
      true if this method handled the call, false otherwise.
    • onInputValue

      public boolean onInputValue(String code, double value)
      Description copied from interface: EngineInputHandler
      Handles an input value change. This is best used for things like axis changes, throttles, and whatever has a variable input value.

      This method is called if the previous input listeners did not handle this.

      Specified by:
      onInputValue in interface EngineInputHandler
      Parameters:
      code - the input code.
      value - the value of the input.
      Returns:
      true if this method handled the call, false otherwise.
    • size

      public int size()
      Returns:
      the amount of states in the stack.
    • isEmpty

      public boolean isEmpty()
      Returns:
      true if there are no states on the stack.