rlgamekit.scheduler
Class Scheduler

java.lang.Object
  extended by rlgamekit.scheduler.Scheduler

public class Scheduler
extends java.lang.Object

Scheduler class for scheduled action objects. Helps to execute actions in a given order. Can be used for both, turn based and realtime games.

See Also:
ScheduledAction

Constructor Summary
Scheduler()
          Create a new scheduler with an empty queue of actions.
 
Method Summary
 void clear()
          Clears the action queue from all actions.
 void execute(long upToOrder)
          Execute all scheduled actions up to a given order.
 ScheduledAction getNext()
          If the execute loop of the scheduler class is not suitable for a project, this method allows to retrieve the next action, that is, the action with the lowest order number in the queue.
 void insert(ScheduledAction action)
          Insert a new action into the scheduler.
 long peekNextOrder()
          Get the order of the next scheduled action.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Scheduler

public Scheduler()
Create a new scheduler with an empty queue of actions.

Method Detail

clear

public void clear()
Clears the action queue from all actions. Leaves the queue empty.


getNext

public ScheduledAction getNext()
If the execute loop of the scheduler class is not suitable for a project, this method allows to retrieve the next action, that is, the action with the lowest order number in the queue. This way a project can implement it's own action loop.

Returns:
The next action from the queue.

insert

public void insert(ScheduledAction action)
Insert a new action into the scheduler. Order must be set.

Parameters:
action - An action with order value set.

peekNextOrder

public long peekNextOrder()
Get the order of the next scheduled action.

Returns:
The lowest order value in the queue or -1 if the queue is empty.

execute

public void execute(long upToOrder)
Execute all scheduled actions up to a given order.

Parameters:
upToOrder - Process all actions with an order smaller than this.