Package nl.colorize.multimedialib.scene
Class StateMachine<S>
java.lang.Object
nl.colorize.multimedialib.scene.StateMachine<S>
- Type Parameters:
S
- The type of state represented by this finite state machine. States are considered equal ifstateA.equals(stateB)
. If the state implements theUpdatable
interface, theupdate
method of the currently active state will be called when the state machine itself receives frame updates.
- All Implemented Interfaces:
Updatable
Finite state machine that allows a number of possible states, but can
only have one currently active state at any point in time.
The state machine implements the Updatable
interface, so it needs
to receive frame updates in order to function. Requested states are stored
in a queue, with the actual state change only occurring during the frame
update.
By default, every state is allowed to transition into every other state. The state machine can optionally be configured to restrict allowed transitions based on the currently active state.
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionvoid
allowTransitions
(BiPredicate<S, S> callback) Restricts state transitions based on the specified predicate.void
allowTransitions
(nl.colorize.util.stats.TupleList<S, S> allowed) Restricts state transitions to only those included in the specified list.void
forceState
(S nextState) Forces this state machine into the specified state, clearing the queue so that the requested state becomes active during the next frame update.boolean
requestState
(S nextState) Requests the state machine to transition into the specified state at the earliest opportunity.boolean
requestState
(S nextState, float duration) Requests the state machine to transition into the specified state at the earliest opportunity.void
update
(float deltaTime) Updates this object for the current frame.
-
Constructor Details
-
StateMachine
-
-
Method Details
-
requestState
Requests the state machine to transition into the specified state at the earliest opportunity. Once active, the state will remain active until another state is requested.Returns a boolean indicating if the state machine allows a transition from the preceding state in the queue into the requested state.
-
requestState
Requests the state machine to transition into the specified state at the earliest opportunity. Once active, the state will remain active for the specified duration (in seconds).Returns a boolean indicating if the state machine allows a transition from the preceding state in the queue into the requested state.
-
forceState
Forces this state machine into the specified state, clearing the queue so that the requested state becomes active during the next frame update. -
allowTransitions
Restricts state transitions based on the specified predicate. The first and second argument in the callback function refer to the current state and requested state respectively. -
allowTransitions
Restricts state transitions to only those included in the specified list. The first and second argument in each tuple refers to the current state and requested state respectively. -
update
public void update(float deltaTime) Description copied from interface:Updatable
Updates this object for the current frame.deltaTime
indicates the elapsed time since the last frame update, in seconds. -
getActiveState
-
getActiveStateTimer
-