cad.simcad.worldsimulator.engine
Class CoreTimeMaster

java.lang.Object
  |
  +--java.lang.Thread
        |
        +--cad.simcad.worldsimulator.engine.CoreTimeMaster
All Implemented Interfaces:
java.lang.Runnable, Simulator

public class CoreTimeMaster
extends java.lang.Thread
implements Simulator

An implementation of Simulator.

Version:
Author:
Charles-Philip Bentley

Field Summary
 int _maxTimeStep
           
 int _minTimeStep
           
 int _simTimeStep
           
 int _stepIncrement
           
 long _turnCount
           
protected  java.lang.Thread loop
           
protected  int simDONE
           
protected  int simEXIT
           
protected  int simINIT
           
protected  int simPAUSE
           
protected  int simRUN
           
protected  int simSTART
           
protected  IntegerSemaphor simState
          Stores the state of the simulation {running, paused}
protected  int simSTOP
           
 
Fields inherited from class java.lang.Thread
MAX_PRIORITY, MIN_PRIORITY, NORM_PRIORITY
 
Constructor Summary
CoreTimeMaster(SimEnvironment simEnv, SimViewer sv)
          Creates new CoreTimeMaster
 
Method Summary
 void continueSimulation()
          Signals the simulation engine to continue the simulation.
 boolean decreaseSpeed()
          Signals the simulation to decrease the speed at which time is ticking.
 void exitSimulation()
          Signals the simulation engine to quit the simulation.
 int getTimeStep()
          Return the time for a simulation turn
 long getTurnCount()
          Return the turn counter value of the Simulator
 boolean increaseSpeed()
          Signals the simulation to increase the speed at which time is ticking.
 void pauseSimulation()
          Signals the simulation engine to pause the simulation.
 void run()
          This is the Thread-main-loop, that calls invokes one simulation cycle when necessary.
 void setSimViewer(SimViewer sv)
          Set the SimViewer for this Simulator
 void simulateCycle()
          this method does the complete simulation of one "game" or situation until the evaluation function determines the target condition to be reached.
 void simulateStep()
          does one step of the simulation.
 void startSimulation()
          Signals the simulation engine to start the simulation.
 void stopSimulation()
          Signals the simulation engine to stop the simulation.
 void updateView()
          Here the visualisation of the simulation is updated.
 
Methods inherited from class java.lang.Thread
activeCount, checkAccess, countStackFrames, currentThread, destroy, dumpStack, enumerate, getContextClassLoader, getName, getPriority, getThreadGroup, holdsLock, interrupt, interrupted, isAlive, isDaemon, isInterrupted, join, join, join, resume, setContextClassLoader, setDaemon, setName, setPriority, sleep, sleep, start, stop, stop, suspend, toString, yield
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

loop

protected java.lang.Thread loop

simState

protected IntegerSemaphor simState
Stores the state of the simulation {running, paused}


_turnCount

public long _turnCount

_simTimeStep

public int _simTimeStep

_maxTimeStep

public int _maxTimeStep

_minTimeStep

public int _minTimeStep

_stepIncrement

public int _stepIncrement

simINIT

protected final int simINIT
See Also:
Constant Field Values

simSTART

protected final int simSTART
See Also:
Constant Field Values

simRUN

protected final int simRUN
See Also:
Constant Field Values

simPAUSE

protected final int simPAUSE
See Also:
Constant Field Values

simDONE

protected final int simDONE
See Also:
Constant Field Values

simSTOP

protected final int simSTOP
See Also:
Constant Field Values

simEXIT

protected final int simEXIT
See Also:
Constant Field Values
Constructor Detail

CoreTimeMaster

public CoreTimeMaster(SimEnvironment simEnv,
                      SimViewer sv)
Creates new CoreTimeMaster

Method Detail

run

public void run()
This is the Thread-main-loop, that calls invokes one simulation cycle when necessary.

Specified by:
run in interface java.lang.Runnable
Overrides:
run in class java.lang.Thread

startSimulation

public void startSimulation()
Signals the simulation engine to start the simulation.

Specified by:
startSimulation in interface Simulator

pauseSimulation

public void pauseSimulation()
Signals the simulation engine to pause the simulation.

Specified by:
pauseSimulation in interface Simulator

continueSimulation

public void continueSimulation()
Signals the simulation engine to continue the simulation.

Specified by:
continueSimulation in interface Simulator

stopSimulation

public void stopSimulation()
Signals the simulation engine to stop the simulation.

Specified by:
stopSimulation in interface Simulator

exitSimulation

public void exitSimulation()
Signals the simulation engine to quit the simulation.

Specified by:
exitSimulation in interface Simulator

increaseSpeed

public boolean increaseSpeed()
Signals the simulation to increase the speed at which time is ticking.

Specified by:
increaseSpeed in interface Simulator
Pre:
-
Returns:
a boolean value telling if the speed has been increased or not
Post:
The simulation has increased its speed by 1 unit, then return true If we are at top speed allowed by the Simulator, return false

decreaseSpeed

public boolean decreaseSpeed()
Signals the simulation to decrease the speed at which time is ticking.

Specified by:
decreaseSpeed in interface Simulator
Pre:
-
Returns:
a boolean value telling if the speed has been decreased or not
Post:
The simulation has decreased its speed by 1 unit, then return true If we are at lowest speed allowed by the Simulator, return false

updateView

public void updateView()
Here the visualisation of the simulation is updated.


simulateCycle

public void simulateCycle()
this method does the complete simulation of one "game" or situation until the evaluation function determines the target condition to be reached.


setSimViewer

public void setSimViewer(SimViewer sv)
Description copied from interface: Simulator
Set the SimViewer for this Simulator

Specified by:
setSimViewer in interface Simulator
Parameters:
sv - A SimViewer object

getTurnCount

public long getTurnCount()
Description copied from interface: Simulator
Return the turn counter value of the Simulator

Specified by:
getTurnCount in interface Simulator
Returns:
a long value

getTimeStep

public int getTimeStep()
Description copied from interface: Simulator
Return the time for a simulation turn

Specified by:
getTimeStep in interface Simulator
Returns:
a int value

simulateStep

public void simulateStep()
does one step of the simulation. This means letting all objects do one movement and then do the collision detection. When a collision is may happen between two objects these are noticed using the isPossibleCollision-method of class SimObject.


Logo

With the help of www.sourceforge.net and www.info.ucl.ac.be