Glimmr Canvas Animation

version 1/111030 by Erik Temple

  • Home page
  • Beginning
  • Previous
  • Next



  • Section - Timer control phrases

    The global timer interval is a number variable.
    [The standard interval divisor is used for performance reasons. We round all timer requests so that they are multiples of this number. This makes it more likely that we will have larger actual timer intervals. Without it, if the author specified intervals for concurrent animations of 41 and 83, then the timer would have to tick every millisecond in order to space them accurately (no Glulx VM can currently manage this accurately). With the standard interval divisor set to 10, GCA will silently adjust the intervals to 40 and 80, meaning that the timer will tick every 40 ms.]
    The standard interval divisor is a number variable. The standard interval divisor is 10.

    To start a/-- Glulx timer of (T - a number) millisecond/milliseconds:
        let N be MAX (standard interval divisor) or T to the nearest (standard interval divisor);[we round to the nearest 10 ms by default]
        #if utilizing animation debugging;
        say "[>console][CA]Interval of [T] ms specified for animation[if N is not T], rounded to [N] (nearest [standard interval divisor])[end if].[<]";
        #end if;
        if the global timer interval is greater than 0 and the number of animation-active animation tracks > 1:
            let N be the greatest common divisor of N and the global timer interval;
            #if utilizing animation debugging;
            say "[>console][CA]Global timer interval of [N] ms selected as greatest common divisor of the specified interval and the existing timer interval of [global timer interval] ms.[<]";
            #end if;
            let standardizer be N as a fixed point number real divided by global timer interval;
            repeat with track running through animation-active animation tracks:
                if the timer frame-multiple of the track is 0, now the timer frame-multiple of the track is 1;[prevents division errors]
                now the timer count of the track is the remainder after dividing the timer count of the track by the timer frame-multiple of the track;
                unless standardizer real equals 1.0000:
                    now the timer count of the track is the timer count of the track multiplied by the standardizer as an integer;
                now the timer frame-multiple of the track is the timer interval of the track divided by N;
                #if utilizing animation debugging;
                say "[>console][CA]Track [i][track][/i] will fire every [timer frame-multiple of the track] tick(s) of the timer. Current offset: [timer count of the track] frames.[<]";
                #end if;
        request Glk timer event at N milliseconds;
        #if utilizing animation debugging;
        say "[>console][CA]Timer event requested for every [N] milliseconds.[<]";
        #end if.

    To pause/stop the/-- Glulx timer:
        request Glk timer event at 0 milliseconds;
        #if utilizing animation debugging;
        say "[>console][CA]Timer event requested at 0 milliseconds.[<]";
        #end if.

    To request Glk timer event at (T - a number) milliseconds:
        (- glk_request_timer_events({T}); (+ global timer interval +) = {T}; -).

    To reset the Glulx timer:
        start a Glulx timer of (global timer interval) milliseconds.