de.rico.adventure.actions
Class ActionScheduler

java.lang.Object
  extended by de.rico.adventure.actions.ActionScheduler

public class ActionScheduler
extends java.lang.Object

This is a very important class in the adventure framework. It is used to process game actions sequencially and makes use of the singleton design pattern.

Note: Don't forget to call the update() and draw() methods of the singleton instance in the game's main update() and draw() methods.

Author:
Frank Bruns

Field Summary
 java.util.concurrent.ConcurrentLinkedQueue<AbstractConcurrentAction> queueConcurrent
          This list is for concurrent game actions only.
 
Method Summary
 void add(AbstractAction action)
          Adds a game action to the queue of game actions.
 void add(AbstractConcurrentAction action, ScriptInterpreter i)
          Adds a game action to the concurrent queue of game actions.
 void clear()
          Removes every game action from the queue of game actions
 void draw(javax.media.opengl.GL gl)
          Draws the currently active game action.
 AbstractAction getFirst()
          Returns first element of the game action queue without removing it.
 java.util.LinkedList<AbstractAction> getGameActions()
          Returns the list of with the actions of the game actions queue.
static ActionScheduler getInstance()
          Returns the singleton instance of the action scheduler.
 java.util.LinkedList<AbstractAction> getQueue()
          Returns the queue object that is used for the game actions queue.
 AbstractAction poll()
          Returns the first element of the queue and removes it at the same time from the queue.
 void removeConcurrentAction(AbstractConcurrentAction action)
          Removes the specified concurrent action from the concurrent game action queue.
 void removeFirst()
          Removes first element in the game action queue.
 void update(long elapsedTime)
          Updates the game action that is currently on top of the queue.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

queueConcurrent

public java.util.concurrent.ConcurrentLinkedQueue<AbstractConcurrentAction> queueConcurrent
This list is for concurrent game actions only. The update() and draw() method of each action in this list gets called every cycle. Note: Don't reference this object in your code directly! It had to be declared public to circumvent some trouble with scripting.

Method Detail

getInstance

public static ActionScheduler getInstance()
Returns the singleton instance of the action scheduler.

Returns:
instance of the action scheduler

getQueue

public java.util.LinkedList<AbstractAction> getQueue()
Returns the queue object that is used for the game actions queue.

Returns:
the queue object

add

public void add(AbstractAction action)
Adds a game action to the queue of game actions.

Parameters:
action - game action to add to the game action queue

add

public void add(AbstractConcurrentAction action,
                ScriptInterpreter i)
Adds a game action to the concurrent queue of game actions. The update() and draw() methods of each action in this list gets called every cycle.

Note: Be aware of potential game state conflicts when adding concurrent actions that are changing the game's state while running. I recommend only to run game actions in a concurrent way, if they do not influence the current game state. Also be aware that concurrent game actions cannot be aborted manually or prematurely.

Parameters:
action - game action to add to the concurrent game action queue
i - reference to the script interpreter of the current room

clear

public void clear()
Removes every game action from the queue of game actions


removeFirst

public void removeFirst()
Removes first element in the game action queue.


removeConcurrentAction

public void removeConcurrentAction(AbstractConcurrentAction action)
Removes the specified concurrent action from the concurrent game action queue.


getFirst

public AbstractAction getFirst()
Returns first element of the game action queue without removing it. It return null if the queue is empty.

Returns:
first element of the game action queue

poll

public AbstractAction poll()
Returns the first element of the queue and removes it at the same time from the queue.

Returns:
first element of the game action queue

getGameActions

public java.util.LinkedList<AbstractAction> getGameActions()
Returns the list of with the actions of the game actions queue.

Returns:
list of game actions

update

public void update(long elapsedTime)
Updates the game action that is currently on top of the queue.

Parameters:
elapsedTime - time between two frames

draw

public void draw(javax.media.opengl.GL gl)
Draws the currently active game action.

Parameters:
gl -