public interface Scheduler extends Schedulable
Scheduler works by assigning a pot of execution time among a variety of tasks, based on which ones need the time.
Different AI tasks can and should be run at different frequencies. You can simply schedule some tasks to run every few frames and other tasks to run more frequently, slicing up the overall AI and distributing it over time. It is a powerful technique for making sure that the game doesn't take too much AI time overall.
The tasks that get called are passed timing information so they can decide when to stop running and return. However, note that there is nothing to stop a task from running for as long as it wants. The scheduler trusts that they will be well behaved.
Notes:
Scheduler extends the Schedulable interface, allowing a scheduling system to
be run as a task by another scheduler. This technique is known as hierarchical scheduling. Also, it's worth noting that with a
hierarchical approach, there's no reason why the schedulers at different levels should be of the same kind. For instance, it is
possible to use a frequency-based scheduler for the whole game and priority-based schedulers for individual characters.| Modifier and Type | Method and Description |
|---|---|
void |
add(Schedulable schedulable,
int frequency,
int phase)
Adds the
schedulable to the list using the given frequency and phase |
void |
addWithAutomaticPhasing(Schedulable schedulable,
int frequency)
Adds the
schedulable to the list using the given frequency and a phase calculated by this scheduler. |
runvoid addWithAutomaticPhasing(Schedulable schedulable, int frequency)
schedulable to the list using the given frequency and a phase calculated by this scheduler.schedulable - the task to schedulefrequency - the frequencyvoid add(Schedulable schedulable, int frequency, int phase)
schedulable to the list using the given frequency and phaseschedulable - the task to schedulefrequency - the frequencyphase - the phase