Optional
opt_name: stringname of this Clock (optional)
Optional
opt_sysClock: SystemClocka SystemClock to use for this Clock (optional)
Private
clockwhen 'zero clock time' occurs, in system time, in seconds
Private
iswhether clock time is advancing
Private
realwhen 'zero real time' occurs, in system time, in seconds
Private
saveremembers the real time while clock is stopped, in seconds
Private
saveremembers clock time while clock is stopped, in seconds
Private
stepmeans we are currently in single-step mode: clock time has advanced even though clock is paused.
Private
tasks_array of ClockTasks to execute at their appointed times
Private
timerate at which clock time advances compared to system time
Static
Readonly
CLOCK_Name of the GenericEvent fired when the Clock is paused, see pause.
Static
Readonly
CLOCK_Name of the GenericEvent fired when the Clock is resumed, see resume.
Static
Readonly
CLOCK_Name of the GenericEvent fired when the Clock time is set, see setTime.
Static
Readonly
CLOCK_Name of the GenericEvent fired when the Clock is stepped, see step.
Adds the given Observer to this Subject's list of Observers, so that the Observer
will be notified of changes in this Subject. An Observer may call Subject.addObserver
during its observe
method.
the Observer to add
Adds the Parameter to the list of this Subject's available Parameters.
the Parameter to add
if a Parameter with the same name already exists.
Adds a ClockTask to the list of tasks which will be run, and schedules it to be run if its time is now or in the future. The time to run the task is specified in the ClockTask.
the ClockTask to add to list of tasks to be run
Notifies all Observers that this Subject has changed by calling observe on each Observer.
An Observer may call addObserver or removeObserver during its observe
method.
a SubjectEvent with information relating to the change
Notifies all Observers that the Parameter with the given name has changed by calling observe on each Observer.
the language-independent or English name of the Parameter that has changed
if there is no Parameter with the given name
Called during step mode, this indicates that the client has advanced the Simulation to match the clock time.
Converts clock time to system time. System time is defined by SystemClock.systemTime.
in seconds
system time equivalent of clockTime
Private
executeProtected
getReturns whether broadcasting is enabled for this Subject. See setBroadcast.
whether broadcasting is enabled for this Subject
Returns the ParameterBoolean with the given name.
the language-independent or English name of the ParameterBoolean
the ParameterBoolean with the given name
if there is no ParameterBoolean with the given name
Returns the ParameterNumber with the given name.
the language-independent or English name of the ParameterNumber
the ParameterNumber with the given name
if there is no ParameterNumber with the given name
Returns the ParameterString with the given name.
the language-independent or English name of the ParameterString
the ParameterString with the given name
if there is no ParameterString with the given name
Returns the real time in seconds which is in the same time scale as the clock time; used for checking simulation performance. Like clock time, real time starts at zero time; is paused when the Clock is paused; and runs at the same rate as clock time.
When a simulation cannot keep up with real time the Clock is retarded by client
code calling setTime to set clock time to an earlier time. In contrast, the
real time is unaffected by setTime
; therefore the difference between real time
and clock time tells us how far behind real time the simulation is.
When the simulation is reset, the clock is typically set to time zero. In that case the real time should be set to match clock time by using setRealTime.
current real time in seconds
Returns the clock time in seconds. When the Clock is running, the clock time advances along with system time at whatever time rate is specified.
the clock time in seconds
Returns true
when in step mode which means that clock time has
advanced even though the Clock is paused. The client should update the Simulation to
match the new clock time, and call clearStepMode to indicate that the
Simulation has advanced.
true
when in step mode
Pauses clock time and real time. Cancels all ClockTasks. Broadcasts a CLOCK_PAUSE event.
Removes the Observer from this Subject's list of Observers. An Observer may
call removeObserver
during its observe
method.
the Observer to detach from list of Observers
Removes the Parameter from the list of this Subject's available Parameters.
the Parameter to remove
Removes the ClockTask from the list of tasks to be run, and cancels the task.
the ClockTask to remove
Resumes increasing clock time and real time. Schedules all ClockTasks that should run at or after the current clock time. Broadcasts a CLOCK_RESUME event.
Protected
setSets whether this Subject will broadcast events, typically used to temporarily disable broadcasting. Intended to be used in situations where a subclass overrides a method that broadcasts an event. This allows the subclass to prevent the superclass broadcasting that event, so that the subclass can broadcast the event when the method is completed.
whether this Subject should broadcast events
the previous value
Sets the real time to the given time in seconds. See getRealTime.
the time to set
Sets the clock time, in seconds. Also schedules all ClockTasks that should run at or after the given time. Broadcasts a CLOCK_SET_TIME event.
the time in seconds to set this Clock to
Sets the rate at which clock time passes compared to system time. A value of 2 makes
clock time pass twice as fast as system time; a value of 0.5 makes clock time pass half
as fast as system time. Broadcasts the TIME_RATE
Parameter if the rate changes.
the rate at which clock time passes compared to system time
Performs a single step forward in time; puts the Clock into step mode; advances the clock time and real time by the specified time step; pauses the clock; and broadcasts a CLOCK_STEP event.
When the client sees that isStepping is true
, it should advance the
Simulation to match the current clock time, and then call clearStepMode.
amount of time to advance the clock in seconds
Converts system time to clock time. System time is defined by SystemClock.
in seconds
clock time equivalent of systemTime
Returns a minimal string representation of this object, usually giving just identity information like the class name and name of the object.
For an object whose main purpose is to represent another Printable object, it is
recommended to include the result of calling toStringShort
on that other object.
For example, calling toStringShort()
on a DisplayShape might return something like
this:
DisplayShape{polygon:Polygon{'chain3'}}
a minimal string representation of this object.
Generated using TypeDoc
Advances along with real time when active, and can execute tasks at appointed times. There are commands to pause, resume, and single-step the Clock, as well as set its time and speed relative to system time. Clock has a list of ClockTasks which it causes to be executed at the times specified by the ClockTasks. Clock has a parallel real time clock for measuring performance.
Clock time is used by a client object such as SimRunner to know how much to advance a simulation. This is how operations on Clock like pause, single-step, setting time rate, etc. affect the display of the Simulation. (When clock time is in the past, such as at time zero, then the client can restart the simulation from initial conditions.)
While a unit of simulation time can be interpreted to mean anything from a millisecond to a millenium, we use the Clock to advance the Simulation time along with real time as though each unit of time is equal to one second of real time.
Types of Time
There are several types of time considered here: system time, clock time, simulation time, and real time. All of these are measured in seconds, though simulation time might have a different meaning – see About Units Of Measurement.
Clock Time is given by getTime. Clock time advances at the current time rate (multiple of system time). Clock time can be modified directly by calling setTime. Clock time can be paused or resumed.
Simulation Time is given by Simulation.getTime. Simulation time is advanced by the client, usually to keep up with clock time. When performance problems occur, the clock time can be retarded via setTime to match the current simulation time.
ClockTask
A ClockTask contains a function which is to be executed at a particular time. The time is expressed in clock time.
ClockTasks are scheduled as a side effect of Clock methods such as
setTime()
,resume()
,addTask()
. ClockTasks are cancelled as a side effect of Clock methods such aspause()
,removeTask()
.A typical use of ClockTask is to restart the simulation after a few seconds, which makes the simulation repeatedly "loop" showing it's first few seconds.
Step Mode
The step method puts the Clock into a special step mode. Clients should check for this step mode by calling isStepping. Step mode being
true
means that clock time has advanced even though the clock is paused. The client should update the simulation to match the new clock time, and then call clearStepMode to indicate that it has advanced the simulation.Parameters Created
TIME_RATE
, see setTimeRateEvents Broadcast
All the Parameters are broadcast when their values change. In addition:
GenericEvent named
CLOCK_PAUSE
, see pauseGenericEvent named
CLOCK_RESUME
, see resumeGenericEvent named
CLOCK_STEP
, see stepGenericEvent named
CLOCK_SET_TIME
, see setTimeTO DO Should be able to have clock time (and therefore simulation time) start at something other than zero.