Package rekit.util.state
Class State
java.lang.Object
rekit.util.state.State
Abstract State whose concrete implementations that a TimeStateMachine
can be in.
Concrete classes may add functionality to
enter(TimeStateMachine parent)
(that is called upon entering this
state), leave()
(that is called upon leaving this state) and
logicLoop()
(that is called periodically by the
TimeStateMachine
).
For automatic switching states, the implementations must supply a
getTimerTime()
that specifies how (in millis) the
TimeStateMachine
is supposed to be in this state as well as a
getNextState()
that returns the next state to enter after that time.
- Author:
- Angelo Aracri
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected TimeStateMachine
A reference to the parentingTimeStateMachine
that is used to switchStates
.protected Timer
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoid
enter
(TimeStateMachine parent) Method that is called by theTimeStateMachine
upon entering thisState
.abstract State
Must supply a fully instantiatedState
that the parentingTimeStateMachine
will enter after thisState
is out of time as specified ingetTimerTime()
.abstract long
Must supply the time in millis how long theTimeStateMachine
is supposed to be in thisState
before switching to the next as specified ingetNextState()
.protected void
Method that may or may not be implemented by a concrete state to perform periodic actionsvoid
leave()
Method that is called by theTimeStateMachine
upon leaving thisState
.void
Method that is periodically called by theTimeStateMachine
.
-
Field Details
-
parent
A reference to the parentingTimeStateMachine
that is used to switchStates
. -
timer
-
-
Constructor Details
-
State
public State()Constructor that initializes thetimer
usinggetTimerTime()
.
-
-
Method Details
-
enter
Method that is called by theTimeStateMachine
upon entering thisState
.- Parameters:
parent
- the parentingTimeStateMachine
that handles this (and probably other)States
.
-
leave
public void leave()Method that is called by theTimeStateMachine
upon leaving thisState
. -
logicLoop
public void logicLoop()Method that is periodically called by theTimeStateMachine
. -
internalLogicLoop
protected void internalLogicLoop()Method that may or may not be implemented by a concrete state to perform periodic actions -
getNextState
Must supply a fully instantiatedState
that the parentingTimeStateMachine
will enter after thisState
is out of time as specified ingetTimerTime()
.- Returns:
- the next
State
to enter.
-
getTimerTime
public abstract long getTimerTime()Must supply the time in millis how long theTimeStateMachine
is supposed to be in thisState
before switching to the next as specified ingetNextState()
.- Returns:
- the time in millis to stay in this
State
.
-