Class SynchronousStateQueue

java.lang.Object
  extended by SynchronousStateQueue

public class SynchronousStateQueue
extends java.lang.Object

Allows global state snapshots to be passed between threads, thus giving safe communication between graphics and simulation components


Constructor Summary
SynchronousStateQueue()
           
 
Method Summary
 double addState(double[] arrLfPositions, StateBundle[] arrStates, IAgent agent, double lfTime, CommGraph graph)
          push another simulated state onto the queue, return the difference in (simulation) time between the last frame requested by the drawing engine and the last frame pushed on by the simulator graph must be copied before calling this.
 double addStateIfEmpty(double[] arrLfPositions, StateBundle[] arrStates, IAgent agent, double lfTime, CommGraph graph)
          push another simulated state onto the queue, but only if the queue is empty return the difference in (simulation) time between the last frame requested by the drawing engine and the last frame pushed on by the simulator graph must be copied before calling this.
 SwarmState getLeastRecent(SwarmState lclCache)
          gets a copy of the least recent state in the queue, returns lclCache if the timestamp of lclCache matches that of the least recent state.
 int removeBefore(double lfTime)
          removes all elements on the queue corresonding to times less then lfTime, unless doing so empties queue, in which case it leaves the last element.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

SynchronousStateQueue

public SynchronousStateQueue()
Method Detail

getLeastRecent

public SwarmState getLeastRecent(SwarmState lclCache)
gets a copy of the least recent state in the queue, returns lclCache if the timestamp of lclCache matches that of the least recent state.

Parameters:
lclCache - to prevent excessive copying should this be called multiple times, anything passed as "lclCache" should only be touched by one thread.
Returns:
copy of least recent swarm state, or lclCache if lclCache's timestamp matches that of the least recent state.

removeBefore

public int removeBefore(double lfTime)
removes all elements on the queue corresonding to times less then lfTime, unless doing so empties queue, in which case it leaves the last element.

Parameters:
lfTime - remove all elements before this time (except for last element in the queue)
Returns:
number of elements removed

addState

public double addState(double[] arrLfPositions,
                       StateBundle[] arrStates,
                       IAgent agent,
                       double lfTime,
                       CommGraph graph)
push another simulated state onto the queue, return the difference in (simulation) time between the last frame requested by the drawing engine and the last frame pushed on by the simulator graph must be copied before calling this.


addStateIfEmpty

public double addStateIfEmpty(double[] arrLfPositions,
                              StateBundle[] arrStates,
                              IAgent agent,
                              double lfTime,
                              CommGraph graph)
push another simulated state onto the queue, but only if the queue is empty return the difference in (simulation) time between the last frame requested by the drawing engine and the last frame pushed on by the simulator graph must be copied before calling this.