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).
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.
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.
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!;