T
- The subclass of CellGame that uses this Thinker's CellGameStatesU
- The subclass of CellGameState uses this ThinkerV
- The subclass of Thinker that this Thinker ispublic abstract class Thinker<T extends CellGame,U extends CellGameState<T,U,V>,V extends Thinker<T,U,V>> extends ThinkerGroup<T,U,V>
A Thinker is a collection of methods that contributes to the mechanics of the CellGameState to which it is assigned. A Thinker is also a ThinkerGroup, which means that Thinkers may be directly assigned to one other Thinker each. A Thinker is considered indirectly assigned to a CellGameState if it is assigned to another Thinker that is itself assigned to the CellGameState, directly or indirectly.
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 directly 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 indirectly assigned to an active CellGameState, it will use the time factor of the Thinker that it is assigned to that is directly assigned to the CellGameState. 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 take time-dependent actions, such as timeUnitActions() or frameActions(), relative to the other Thinkers in its ThinkerGroup. All of the Thinkers assigned to a ThinkerGroup will take each type of time-dependent actions in order from highest to lowest action priority. A Thinker that is assigned to another Thinker will take each type of time-dependent actions after its assignee Thinker does, but before any of the other Thinkers in its assignee Thinker's ThinkerGroup do.
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, before a Thinker takes its 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> and interact with CellGameStates of class U. BasicThinker is an example of such a class. This allows a Thinker's CellGameStates 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 after being added to a new ThinkerGroup,
immediately after the ThinkerGroup takes its addThinkerActions().
|
void |
addThinkerActions(T game,
U state,
V thinker)
Actions for this Thinker to take immediately after adding a Thinker to
itself, before the added Thinker takes its addedActions().
|
void |
addThinkerActions(V thinker)
Actions for this ThinkerGroup to take immediately after adding a Thinker
to itself, before the Thinker takes its addedActions().
|
void |
frameActions(T game,
U state)
Actions for this Thinker to take once every frame after 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.
|
T |
getGame()
Returns the CellGame of the CellGameState to which this Thinker is
directly or indirectly assigned, or null if it is not assigned to a
CellGameState.
|
U |
getGameState()
Returns the CellGameState to which this Thinker is directly or indirectly
assigned, or null if it is not assigned to one.
|
int |
getNewActionPriority()
Returns the action priority that this Thinker is about to have, but does
not yet have due to its ThinkerGroup's Thinker list being iterated over.
|
ThinkerGroup<T,U,V> |
getNewThinkerGroup()
Returns the ThinkerGroup 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.
|
ThinkerGroup<T,U,V> |
getThinkerGroup()
Returns the ThinkerGroup to which this Thinker is assigned, or null if it
is assigned to none.
|
abstract V |
getThis()
A method which returns this Thinker as a V, rather than as a
Thinker<T,U,V>.
|
long |
getTimeFactor()
Returns this Thinker's time factor.
|
int |
getTimerValue(TimedEvent 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 before being removed from its current
ThinkerGroup, immediately before the ThinkerGroup takes its
removeThinkerActions().
|
void |
removeThinkerActions(T game,
U state,
V thinker)
Actions for this ThinkerGroup to take immediately before removing a
Thinker from itself, after the soon-to-be-removed Thinker takes its
removedActions().
|
void |
removeThinkerActions(V thinker)
Actions for this ThinkerGroup to take immediately before removing a
Thinker from itself, after the Thinker takes its removedActions().
|
void |
setActionPriority(int actionPriority)
Sets this Thinker's action priority to the specified value.
|
void |
setThinkerGroup(ThinkerGroup<T,U,V> group)
Sets the ThinkerGroup to which this Thinker is assigned.
|
void |
setTimeFactor(long timeFactor)
Sets this Thinker's time factor to the specified value.
|
void |
setTimerValue(TimedEvent 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 its CellGameState
takes its frameActions().
|
addThinker, getNumThinkers, iteratingThroughThinkers, removeAllSubThinkers, removeAllThinkers, removeLineage, removeThinker, thinkerIterator, updateThinkerListActions
public abstract V getThis()
public final ThinkerGroup<T,U,V> getThinkerGroup()
public final ThinkerGroup<T,U,V> getNewThinkerGroup()
public final void setThinkerGroup(ThinkerGroup<T,U,V> group)
group
- The ThinkerGroup to which this Thinker should be assignedpublic final T getGame()
public final U getGameState()
public 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 int getTimerValue(TimedEvent timedEvent)
timedEvent
- The TimedEvent whose timer value should be returnedpublic final void setTimerValue(TimedEvent timedEvent, int value)
timedEvent
- The TimedEvent whose timer value should be setvalue
- The new value of the specified TimedEvent's timerpublic void addedActions(T game, U state)
game
- This Thinker's CellGameState's CellGame, or null if it has no
CellGameStatestate
- This Thinker's CellGameState, or null if it has nonepublic void removedActions(T game, U state)
game
- This Thinker's CellGameState's CellGame, or null if it has no
CellGameStatestate
- This Thinker's CellGameState, or null if it has nonepublic void timeUnitActions(T game, U state)
game
- This Thinker's CellGameState's CellGamestate
- This Thinker's CellGameStatepublic void frameActions(T game, U state)
game
- This Thinker's CellGameState's CellGamestate
- This Thinker's CellGameStatepublic final void addThinkerActions(V thinker)
ThinkerGroup
addThinkerActions
in class ThinkerGroup<T extends CellGame,U extends CellGameState<T,U,V>,V extends Thinker<T,U,V>>
thinker
- The Thinker that was addedpublic final void addThinkerActions(T game, U state, V thinker)
game
- This Thinker's CellGameState's CellGame, or null if it has no
CellGameStatestate
- This Thinker's CellGameState, or null if it has nonethinker
- The Thinker that was addedpublic final void removeThinkerActions(V thinker)
ThinkerGroup
removeThinkerActions
in class ThinkerGroup<T extends CellGame,U extends CellGameState<T,U,V>,V extends Thinker<T,U,V>>
thinker
- The Thinker that is about to be removedpublic final void removeThinkerActions(T game, U state, V thinker)
game
- This Thinker's CellGameState's CellGame, or null if it has no
CellGameStatestate
- This Thinker's CellGameState, or null if it has nonethinker
- The Thinker that is about to be removed