11. GRTS: The GWindows Realtime System
GRTS is a new GWindows system for using the real-time features of Glk. It is still highly experimental. It is a core module, and, like gsound, can be used without the rest of GWindows. To use it, include "grts.h" in your source.
Define the constant GRTS_MAX_EVENTS before inclusion to increase the number of timed events which can be scheduled simultaneously. One-time and recurring events are counted seperately. (Default: 16)
11.2 Scheduling Events
To schedule a timed event, call
event is the function to be called, and
time is the time in
milliseconds you want to elapse before it is called.
Instead of passing a function into GRTS_Schedule, you can instead pass an object of class GRTS_event. If you do this, its .select() method will be called when the event occurs. Do not use the time_out or number properties of a GRTS_event.
There are several helper functions available for GRTS:
GRTS_ScheduleS, GRTS_Schedule_M, and GRTS_ScheduleH
behave like GRTS_Schedule, take their time arguments in seconds, minutes, and hours
respectively. You can pass additional arguments to each of these to add extra time (that is, GRTS_ScheduleH actually takes 5
arguments: the event, and the time expressed as hours, minutes, seconds, and milliseconds).
11.3 Recurrent Events
To schedule an event which will occur over and over at fixed intervals, create an object of class GRTS_recurrent_event as you would one of GRTS_event.
11.4 Caveat Emptor
GRTS is still experimental. Additionally, if an event takes too long, or the Glulx interpreter is busy with other things when the time-out occurs,the clock will skew and your events will be delayed. Unfortunately, Glk does not offer any means to avoid this or even any means to detect that it has happened. Be careful.
Additionally, the behavior of GRTS across a save, restore, or undo may cause considerable clock skew. GRTS should be used predominantly for scheduling events in the near future, for example, in tandem with GSound to provide fading of music.