wyvern.lib
Interface EventQueue

All Superinterfaces:
java.lang.Runnable

public interface EventQueue
extends java.lang.Runnable

Holds every CommandEvent for a particular Commandable (such as a Monster, Player or Spell) waiting to be executed by the game scheduler.

You almost never need to use an EventQueue directly - you can issue commands to a monster, player or other commandable by invoking either of these methods:

These are equivalent to getting the commandable's event queue using getQueue() and manually calling enqueue() or pushFront().

Version:
1.0, 10/01/97
Author:
Steve Yegge

Method Summary
 void clear()
          Dumps all the events in the queue.
 void destroy()
          Shuts down the event queue, permanently.
 void enqueue(CommandEvent event)
          Puts an event at the end of the queue, to be executed after all other events ahead of it finish executing.
 CommandEvent find(GenericPredicate p)
          Looks for the first event in the queue that matches the passed predicate.
 Commandable getOwner()
          Gets the agent to which this queue belongs.
 boolean isDead()
          Checks if the queue is dead (i.e. has been destroyed).
 boolean isEmpty()
          Returns true if the queue has no events in it.
 boolean isIdle()
          Returns true if current queue state is QueueState.IDLE
 boolean isWaiting()
          Returns true if getState() == QueueState.WAITING
 CommandEvent peek()
          Returns the next item in the queue without removing it.
 void pushFront(CommandEvent event)
          Puts an event at the front of the queue, so it'll be executed next.
 boolean remove(CommandEvent event)
          Removes an event from the queue.
 void requestEvent()
          Notify the producer for this queue (if any) that the queue is ready to receive another event.
 void setProducer(AI producer)
          Registers an AI with a queue, so when the queue needs another command, it can notify the AI.
 java.lang.String shortString()
          Returns a short description of the queue.
 int size()
          Returns the number of events currently in the queue.
 
Methods inherited from interface java.lang.Runnable
run
 

Method Detail

setProducer

public void setProducer(AI producer)
Registers an AI with a queue, so when the queue needs another command, it can notify the AI.

Parameters:
producer - an AI. There should be no reason to set this to anything but an AI. The queue will notify the AI when it's ready to receive another command.

requestEvent

public void requestEvent()
Notify the producer for this queue (if any) that the queue is ready to receive another event. Called by the Dispatcher when the queue is found to be both empty and done with its wait.


enqueue

public void enqueue(CommandEvent event)
Puts an event at the end of the queue, to be executed after all other events ahead of it finish executing.

Parameters:
event - the Event object to enqueue

pushFront

public void pushFront(CommandEvent event)
Puts an event at the front of the queue, so it'll be executed next.

Parameters:
event - the event to execute next

clear

public void clear()
Dumps all the events in the queue. Use with caution.


remove

public boolean remove(CommandEvent event)
Removes an event from the queue.


destroy

public void destroy()
Shuts down the event queue, permanently. Sets state to QueueState.DEAD.


peek

public CommandEvent peek()
Returns the next item in the queue without removing it.

Returns:
a reference to the next queue item, if any.

find

public CommandEvent find(GenericPredicate p)
Looks for the first event in the queue that matches the passed predicate.

Parameters:
p - a wyvern.lib.Predicate that returns true if the event meets whatever criteria the caller is looking for.
Returns:
the first event that passes the predicate, or null if no such event is found.

isEmpty

public boolean isEmpty()
Returns true if the queue has no events in it.

Returns:
true if there are no events in the queue

size

public int size()
Returns the number of events currently in the queue.


isWaiting

public boolean isWaiting()
Returns true if getState() == QueueState.WAITING

Returns:
true if the EventQueue is currently in the scheduler WaitQueue. You shouldn't care.

isIdle

public boolean isIdle()
Returns true if current queue state is QueueState.IDLE


isDead

public boolean isDead()
Checks if the queue is dead (i.e. has been destroyed).

Returns:
true if getState() == QueueState.DEAD

getOwner

public Commandable getOwner()
Gets the agent to which this queue belongs.

Returns:
the Commandable using this queue for its commands.

shortString

public java.lang.String shortString()
Returns a short description of the queue. toString() returns the entire contents of the queue, which can be overkill sometimes.