Timer Events

Timer Events — Events sent at fixed intervals

Functions

Includes

#include <libchimara/glk.h>

Description

You can request that an event be sent at fixed intervals, regardless of what the player does. Unlike input events, timer events can be tested for with glk_select_poll() as well as glk_select().

It is possible that the library does not support timer events. You can check this with the gestalt_Timer selector.

Functions

glk_request_timer_events ()

void
glk_request_timer_events (glui32 millisecs);

Initially, there is no timer and you get no timer events. If you call glk_request_timer_events(<emphasis>N</emphasis>), with N not 0, you will get timer events about every N milliseconds thereafter. (Assuming that they are supported — if not, glk_request_timer_events() has no effect.) Unlike keyboard and mouse events, timer events will continue until you shut them off. You do not have to re-request them every time you get one. Call glk_request_timer_events(0) to stop getting timer events.

The rule is that when you call glk_select() or glk_select_poll(), if it has been more than N milliseconds since the last timer event, and (for glk_select()) if there is no player input, you will receive an event whose type is evtype_Timer. (win , val1 , and val2 will all be 0.)

Timer events do not stack up. If you spend 10N milliseconds doing computation, and then call glk_select(), you will not get ten timer events in a row. The library will simply note that it has been more than N milliseconds, and return a timer event right away. If you call glk_select() again immediately, it will be N milliseconds before the next timer event.

This means that the timing of timer events is approximate, and the library will err on the side of being late. If there is a conflict between player input events and timer events, the player input takes precedence.

This prevents the user from being locked out by overly enthusiastic timer events. Unfortunately, it also means that your timer can be locked out on slower machines, if the player pounds too enthusiastically on the keyboard. Sorry.

I don't have to tell you that a millisecond is one thousandth of a second, do I?

Parameters

millisecs

Interval in milliseconds to request timer events for, or 0 to stop timer events.