org.mars_sim.msp.simulation.time
Class MasterClock

java.lang.Object
  extended by org.mars_sim.msp.simulation.time.MasterClock
All Implemented Interfaces:
java.io.Serializable, java.lang.Runnable

public class MasterClock
extends java.lang.Object
implements java.lang.Runnable, java.io.Serializable

The MasterClock represents the simulated time clock on virtual Mars. Virtual Mars has only one master clock. The master clock delivers a clock pulse the virtual Mars every second or so, which represents a pulse of simulated time. All actions taken with virtual Mars and its units are synchronized with this clock pulse.

See Also:
Serialized Form

Field Summary
static long TIME_PULSE_LENGTH
           
 
Constructor Summary
MasterClock()
          Constructor
 
Method Summary
 void addClockListener(ClockListener newListener)
          Adds a clock listener
 void exitProgram()
          Sets the exit program flag.
 EarthClock getEarthClock()
          Returns the Earth clock
 MarsClock getInitialMarsTime()
          Gets the initial Mars time at the start of the simulation.
 MarsClock getMarsClock()
          Returns the Martian clock
 double getTimePulse()
          Gets the time pulse length
 double getTimeRatio()
          Gets the simulation/real-time ratio.
 UpTimer getUpTimer()
          Returns uptime timer
 boolean isLoadingSimulation()
          Checks if in the process of loading a simulation.
 boolean isPaused()
          Checks if the simulation is paused or not.
 boolean isSavingSimulation()
          Checks if in the process of saving a simulation.
 void loadSimulation(java.io.File file)
          Sets the load simulation flag and the file to load from.
 void removeClockListener(ClockListener oldListener)
          Removes a clock listener
 void run()
          Run clock
 void saveSimulation(java.io.File file)
          Sets the save simulation flag and the file to save to.
 void setPaused(boolean isPaused)
          Set if the simulation is paused or not.
 void setTimeRatio(double ratio)
          Sets the simulation/real-time ratio.
 void stop()
          Stop the clock
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

TIME_PULSE_LENGTH

public static final long TIME_PULSE_LENGTH
See Also:
Constant Field Values
Constructor Detail

MasterClock

public MasterClock()
            throws java.lang.Exception
Constructor

Throws:
java.lang.Exception - if clock could not be constructed.
Method Detail

getMarsClock

public MarsClock getMarsClock()
Returns the Martian clock

Returns:
Martian clock instance

getInitialMarsTime

public MarsClock getInitialMarsTime()
Gets the initial Mars time at the start of the simulation.

Returns:
initial Mars time.

getEarthClock

public EarthClock getEarthClock()
Returns the Earth clock

Returns:
Earth clock instance

getUpTimer

public UpTimer getUpTimer()
Returns uptime timer

Returns:
uptimer instance

addClockListener

public final void addClockListener(ClockListener newListener)
Adds a clock listener

Parameters:
newListener - the listener to add.

removeClockListener

public final void removeClockListener(ClockListener oldListener)
Removes a clock listener

Parameters:
oldListener - the listener to remove.

loadSimulation

public void loadSimulation(java.io.File file)
Sets the load simulation flag and the file to load from.

Parameters:
file - the file to load from.

isLoadingSimulation

public boolean isLoadingSimulation()
Checks if in the process of loading a simulation.

Returns:
true if loading simulation.

saveSimulation

public void saveSimulation(java.io.File file)
Sets the save simulation flag and the file to save to.

Parameters:
file - save to file or null if default file.

isSavingSimulation

public boolean isSavingSimulation()
Checks if in the process of saving a simulation.

Returns:
true if saving simulation.

exitProgram

public void exitProgram()
Sets the exit program flag.


getTimePulse

public double getTimePulse()
                    throws java.lang.Exception
Gets the time pulse length

Returns:
time pulse length in millisols
Throws:
java.lang.Exception - if time pulse length could not be determined.

setTimeRatio

public void setTimeRatio(double ratio)
                  throws java.lang.Exception
Sets the simulation/real-time ratio. Value cannot be 0 or less.

Parameters:
ratio - the simulation/real-time ratio.
Throws:
java.lang.Exception - if parameter is invalid.

getTimeRatio

public double getTimeRatio()
Gets the simulation/real-time ratio.

Returns:
ratio

run

public void run()
Run clock

Specified by:
run in interface java.lang.Runnable

stop

public void stop()
Stop the clock


setPaused

public void setPaused(boolean isPaused)
Set if the simulation is paused or not.

Parameters:
isPaused - true if simulation is paused.

isPaused

public boolean isPaused()
Checks if the simulation is paused or not.

Returns:
true if paused.