T
- The subclass of CellGameState that this Thinker is used byU
- The subclass of Thinker that this Thinker isV
- The subclass of ThinkerState that this Thinker usespublic abstract class Thinker<T extends CellGameState<T,U,V>,U extends Thinker<T,U,V>,V extends ThinkerState<T,U,V>>
extends java.lang.Object
A Thinker is a collection of methods that contributes to the mechanics of the CellGameState to which it is assigned. A Thinker's assigned CellGameState will keep track of time for it, thus allowing it to take its own time-dependent actions, while the CellGameState is active. Because a CellGameState's internal list of Thinkers cannot be modified while it is being iterated through, the actual addition or removal of a Thinker to or from a CellGameState is delayed until all of its Thinkers have completed their timeUnitActions() or frameActions() if the CellGameState was instructed to add or remove the Thinker during those periods. Multiple delayed instructions may be successfully given to CellGameStates regarding the same Thinker without having to wait until the end of one of those periods.
A Thinker's time factor represents how many time units the Thinker will experience every frame while assigned to an active CellGameState. If its own time factor is negative, a Thinker will use its assigned CellGameState's time factor instead. If a Thinker is assigned to an inactive CellGameState or none at all, time will not pass for it.
A Thinker's action priority determines when it will act relative to other Thinkers. All of the Thinkers assigned to the active CellGameState will take their timeUnitActions() and their frameActions() in order from highest to lowest action priority.
A Thinker may occupy at most one ThinkerState at a time. ThinkerStates take actions alongside their Thinker's own, as well as when entered and left by a Thinker, and can help a Thinker keep track of its position in a multi-frame procedure. A ThinkerState can have a limited duration in time units, and at the beginning of the time unit when that duration is up, its Thinker automatically transitions to its next ThinkerState.
A Thinker has timers that can activate TimedEvents after a certain number of time units. Timers have integer values, with a positive value x indicating that the TimedEvent will be activated in x time units, a negative value indicating that the timer is not running, and a value of 0 indicating that either the TimedEvent was activated or the value was deliberately set to 0 this time unit. Each time unit, after a Thinker automatically changes ThinkerStates (if it did) but before it and its ThinkerState (if it has one) take their timeUnitActions(), its non-negative timers' values are decreased by 1 and the TimedEvents whose timers have reached 0 are activated.
The Thinker class is intended to be directly extended by classes U that extend Thinker<T,U,V> and interact with CellGameStates of class T and ThinkerStates of class V. BasicThinker is an example of such a class. This allows a Thinker's CellGameStates and ThinkerStates to interact with it in ways unique to its subclass of Thinker.
Constructor and Description |
---|
Thinker()
Creates a new Thinker.
|
Modifier and Type | Method and Description |
---|---|
void |
addedActions(CellGame game,
T state)
Actions for this Thinker to take immediately after being added to a new
CellGameState.
|
void |
frameActions(CellGame game,
T state)
Actions for this Thinker to take once every frame, after Thinkers take
their timeUnitActions() but before its CellGameState takes its own
frameActions().
|
int |
getActionPriority()
Returns this Thinker's action priority.
|
double |
getEffectiveTimeFactor()
Returns this Thinker's effective time factor; that is, how many time
units it experiences every frame.
|
T |
getGameState()
Returns the CellGameState to which this Thinker is currently assigned, or
null if it is assigned to none.
|
int |
getNewActionPriority()
Returns the action priority that this Thinker is about to have, but does
not yet have due to its CellGameState's Thinker list being iterated over.
|
T |
getNewGameState()
Returns the CellGameState to which this Thinker is about to be assigned,
but has not yet been due to one or more of the Thinker lists involved
being iterated over.
|
V |
getThinkerState()
Returns this Thinker's current ThinkerState.
|
int |
getThinkerStateDuration()
Returns the remaining duration in time units of this Thinker's current
ThinkerState.
|
abstract U |
getThis()
A method which returns this Thinker as a U, rather than as a
Thinker<T,U,V>.
|
double |
getTimeFactor()
Returns this Thinker's time factor.
|
int |
getTimerValue(TimedEvent<T> timedEvent)
Returns the current value of this Thinker's timer for the specified
TimedEvent.
|
void |
removedActions(CellGame game,
T state)
Actions for this Thinker to take immediately before being removed from
its CellGameState.
|
void |
setActionPriority(int actionPriority)
Sets this Thinker's action priority.
|
void |
setGameState(T state)
Sets the CellGameState to which this Thinker is currently
assigned.
|
void |
setThinkerState(V thinkerState)
Sets this Thinker's current ThinkerState to the specified one.
|
void |
setThinkerStateDuration(int duration)
Sets the remaining duration in time units of this Thinker's current
ThinkerState to the specified value.
|
void |
setTimeFactor(double timeFactor)
Sets this Thinker's time factor to the specified value.
|
void |
setTimerValue(TimedEvent<T> timedEvent,
int value)
Sets the value of this Thinker's timer for the specified TimedEvent to
the specified value.
|
void |
timeUnitActions(CellGame game,
T state)
Actions for this Thinker to take once every time unit, after
AnimationInstances update their indices but before Thinkers take their
frameActions().
|
public abstract U getThis()
public final T getGameState()
public final T getNewGameState()
public final void setGameState(T state)
state
- The CellGameState to which this Thinker should be assignedpublic final double getTimeFactor()
public final double getEffectiveTimeFactor()
public final void setTimeFactor(double timeFactor)
timeFactor
- The new time factorpublic final int getActionPriority()
public final int getNewActionPriority()
public final void setActionPriority(int actionPriority)
actionPriority
- The new action prioritypublic final V getThinkerState()
public final void setThinkerState(V thinkerState)
thinkerState
- The new ThinkerStatepublic final int getThinkerStateDuration()
public final void setThinkerStateDuration(int duration)
duration
- The new duration in time units of this Thinker's current
ThinkerStatepublic final int getTimerValue(TimedEvent<T> timedEvent)
timedEvent
- The TimedEvent whose timer value should be returnedpublic final void setTimerValue(TimedEvent<T> timedEvent, int value)
timedEvent
- The TimedEvent whose timer value should be setvalue
- The new value of the specified TimedEvent's timerpublic void timeUnitActions(CellGame game, T state)
game
- This Thinker's CellGamestate
- This Thinker's CellGameStatepublic void frameActions(CellGame game, T state)
game
- This Thinker's CellGamestate
- This Thinker's CellGameStatepublic void addedActions(CellGame game, T state)
game
- This Thinker's CellGamestate
- This Thinker's CellGameState