<<<<<<<<<<<<<<<<<

clock(ad) Aegis Display clock(ad)

NAME

clock - Event-driven clock for interval timing

DESCRIPTION

The clock class provides an interval timer that can be used to control the execution rate of a LYMB script. After the clock is started running, control is returned to the application so that actions for that interval can be performed. This class has been used to control the pace of a simulation that also involves asynchonous user- initiated events.

When the application has nothing left to do during the current interval, the wait_interval! message can be used to wait for the remaining time to expire. Even during this idle time, a block of event_actions can be periodically called to check for asynchonous events.

The resolution of the clock is potentially one millisecond, however it is limited to the resolution of the hardware clock (e.g. 1/60th of a second for Suns).

SUPERCLASS

object

INSTANCE VARIABLES

interval is a floating point value containing the time interval in seconds

event_action is the name of an actions object to which a tick! is sent periodically while the clock is executing the wait_interval! message.

MESSAGES

interval= value sets the interval of the timer

event_action= actions_name sets the event_action which will be sent a tick! periodically while the clock is executing the wait_interval! message.

start_interval! starts the timer running, but returns control to the caller immediately.

stop_interval! stops the timer.

wait_interval! waits for the time remaining in the interval to run out. If the timer has already run out, control is returned immediately, otherwise control is not returned until the timer has run out. During this period, however the event_actions are sent a tick! message (after each check of the timer). This gives control back to the application so that (for example) user input events could be processed or some other asynchonous action could be performed. The event_actions could stop the timer, which will cause control to be returned from the wait_interval! call.

EXAMPLE

clock interval= .5 -- real time interval per simultion step event_action= process_events -- event-processing loop ;

loop new: run_loop resolution= 1 -- ** this loop clocked in sim time ** duration= 3600 -- one hour simulated time tick_actions= ` clock start_interval!; -- Do this every second of sim time... active_sim_objects tick!; -- Simulation objects all take one step render_action tick!; -- Renderer updates graphic display clock wait_interval!; -- ...Now wait for rest of the interval ';

actions new: "process_events" tick_actions= ` ui process_events!; -- Process user interface events ';

run_loop start!;

SEE ALSO

timer (LYMB), ftime (3V)


Please send comments and suggestions to
consult@rpi.edu