gecco.server.actionprocessor
Class ActionProcessor

java.lang.Object
  |
  +--gecco.server.actionprocessor.ActionProcessor
All Implemented Interfaces:
Runnable, SignalRunnable

public class ActionProcessor
extends Object
implements SignalRunnable

The action processor handles the scheduling and execution of actions for the units in the ongoing game.

Author:
Henrik Bäärnhielm, Karl Hasselström, Henrik Hägerström

Field Summary
 
Fields inherited from interface gecco.util.SignalRunnable
SIGKILL, SIGNONE, SIGPAUSE, SIGQUIT, SIGRESUME
 
Constructor Summary
ActionProcessor()
          Constructor for the ActionProcessor object
 
Method Summary
 boolean abortAction(String fromRole, int actionHandle)
          Aborts an ongoing action for a unit.
 void continueGame()
           
 void executeInstantaneousAction(Action action)
          Executes an instantaneous action.
 Action getAction(String role, int actionHandle)
          Gets the action with the given handle ordered by the given role.
 TreeSet getActionQueue()
          Returns the TreeSet object which is the queue that holds the current scheduled actions for the units in the game.
 void handleAutomatonUnitEvent(int x, int y, UnitEvent unitEvent)
          This method handles an incoming UnitEvent coming from the automaton-layer, most probably due to a change of state in the automaton at position (x, y).
 void handleUnitToUnitEvent(Unit unit, UnitEvent unitEvent)
          This method handles an incoming UnitEvent which originates from another unit in the game.
 void initiateAction(String fromRole, Action action)
          Initiates an action for a unit.
 void publicCheckActionBlocklist(Unit u)
           
 void publicCheckChangedPosition(double oldx, double oldy, Unit u)
           
 void publicCheckChangedProperties(Unit u)
           
 void run()
          Main processing method for the execution of actions.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ActionProcessor

public ActionProcessor()
Constructor for the ActionProcessor object

Method Detail

getActionQueue

public TreeSet getActionQueue()
Returns the TreeSet object which is the queue that holds the current scheduled actions for the units in the game. This method is primarily used when another thread wants to synchronize on the queue object, preventing any other thread to add a new action to the queue.

Returns:
The priority queue that is used for scheduling actions for units.

getAction

public Action getAction(String role,
                        int actionHandle)
Gets the action with the given handle ordered by the given role. Will return null if there is no such action, or if it has already completed.

Returns:
The action.

initiateAction

public void initiateAction(String fromRole,
                           Action action)
Initiates an action for a unit.

Parameters:
fromRole - The commanding role which initiated the action.
action - The Action class itself.

executeInstantaneousAction

public void executeInstantaneousAction(Action action)
Executes an instantaneous action. An instantaneous action is an action that can be executed during the execution of another (scheduled) action. A unit can for example be executing a movement action, and fire a missile at another unit at the same time. The instantaneous action will never be queued. There is only one single call made to the checkPoint() method in the action class.

Parameters:
action - The class representing the instantaneous action.

handleAutomatonUnitEvent

public void handleAutomatonUnitEvent(int x,
                                     int y,
                                     UnitEvent unitEvent)
This method handles an incoming UnitEvent coming from the automaton-layer, most probably due to a change of state in the automaton at position (x, y).

Parameters:
x - The x-coordinate of the automaton.
y - The y-coordinate of the automaton.
unitEvent - The UnitEvent class.

handleUnitToUnitEvent

public void handleUnitToUnitEvent(Unit unit,
                                  UnitEvent unitEvent)
This method handles an incoming UnitEvent which originates from another unit in the game.

Parameters:
unit - The affected unit.
unitEvent - The UnitEvent class.

abortAction

public boolean abortAction(String fromRole,
                           int actionHandle)
Aborts an ongoing action for a unit.

Parameters:
fromRole - The commanding role
actionHandle - The actionHandle
Returns:
true if the action was found and removed, false otherwise.

run

public void run()
Main processing method for the execution of actions.

Specified by:
run in interface Runnable

publicCheckChangedProperties

public void publicCheckChangedProperties(Unit u)

publicCheckActionBlocklist

public void publicCheckActionBlocklist(Unit u)

publicCheckChangedPosition

public void publicCheckChangedPosition(double oldx,
                                       double oldy,
                                       Unit u)

continueGame

public void continueGame()