T
- The subclass of CellGame that this Thinker's CellGameState is used
byU
- The subclass of CellGameState that this Thinker is used byV
- The subclass of Thinker that this Thinker isW
- The subclass of ThinkerState that this Thinker usespublic abstract class Thinker<T extends CellGame,U extends CellGameState<T,U,V,W>,V extends Thinker<T,U,V,W>,W extends ThinkerState<T,U,V,W>>
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. A Thinker's time factor represents the average number of discrete 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 V that extend Thinker<T,U,V,W> and interact with CellGameStates of class U and ThinkerStates of class W. 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(T game,
U state)
Actions for this Thinker to take immediately after being added to a new
CellGameState.
|
void |
frameActions(T game,
U 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.
|
long |
getEffectiveTimeFactor()
Returns this Thinker's effective time factor; that is, the average number
of time units it experiences every frame.
|
U |
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.
|
U |
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.
|
W |
getThinkerState()
Returns this Thinker's current ThinkerState.
|
int |
getThinkerStateDuration()
Returns the remaining duration in time units of this Thinker's current
ThinkerState.
|
abstract V |
getThis()
A method which returns this Thinker as a V, rather than as a
Thinker<T,U,V,W>.
|
long |
getTimeFactor()
Returns this Thinker's time factor.
|
int |
getTimerValue(TimedEvent<U> timedEvent)
Returns the current value of this Thinker's timer for the specified
TimedEvent.
|
void |
removedActions(T game,
U state)
Actions for this Thinker to take immediately before being removed from
its CellGameState.
|
void |
setActionPriority(int actionPriority)
Sets this Thinker's action priority to the specified value.
|
void |
setGameState(U state)
Sets the CellGameState to which this Thinker is currently assigned.
|
void |
setThinkerState(W 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(long timeFactor)
Sets this Thinker's time factor to the specified value.
|
void |
setTimerValue(TimedEvent<U> timedEvent,
int value)
Sets the value of this Thinker's timer for the specified TimedEvent to
the specified value.
|
void |
timeUnitActions(T game,
U state)
Actions for this Thinker to take once every time unit, after
AnimationInstances update their indices but before Thinkers take their
frameActions().
|
public abstract V getThis()
public final U getGameState()
public final U getNewGameState()
public final void setGameState(U state)
state
- The CellGameState to which this Thinker should be assignedpublic final long getTimeFactor()
public final long getEffectiveTimeFactor()
public final void setTimeFactor(long 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 W getThinkerState()
public final void setThinkerState(W 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<U> timedEvent)
timedEvent
- The TimedEvent whose timer value should be returnedpublic final void setTimerValue(TimedEvent<U> timedEvent, int value)
timedEvent
- The TimedEvent whose timer value should be setvalue
- The new value of the specified TimedEvent's timerpublic void timeUnitActions(T game, U state)
game
- This Thinker's CellGamestate
- This Thinker's CellGameStatepublic void frameActions(T game, U state)
game
- This Thinker's CellGamestate
- This Thinker's CellGameStatepublic void addedActions(T game, U state)
game
- This Thinker's CellGamestate
- This Thinker's CellGameState