The Perl Toolchain Summit needs more sponsors. If your company depends on Perl, please support this very important event.

NAME

SDL::Time - a SDL perl extension for managing timers.

CATEGORY

Core

SYNOPSIS

        package foo;
        use threads;
        use threads::shared;

        use SDL;
        use SDL::Time;

        SDL::init(SDL_INIT_TIMER);

        my $tick :shared = 0;

        sub ticker { $tick++; warn $tick; return 100 };

        package main;

        my $id = SDL::Time::add_timer(100, 'foo::ticker');

        sleep(2);

        SDL::Time::remove_timer($id);

        SDL::quit();

METHODS

get_ticks()

This will be move to SDL::Time.

Returns the number of milliseconds since SDL library initialization. This value wraps around if the program runs for more than 49.7 days

delay(ms)

This will be move to SDL::Time.

This function waits a specified number of milliseconds before returning. It waits at least the specified time, but possible longer due to OS scheduling. The delay granularity is at least 10 ms. Some platforms have shorter clock ticks but this is the most common. SDL::delay doesn't returns anything.

add_timer(interval,callback)

This runs in a seperate thread and a cloned perl thread.

Adds a callback function to be run after the specified number of milliseconds has elapsed. The callback function is passed the current timer interval and the user supplied parameter from the SDL::add_timer call and returns the next timer interval. If the returned value from the callback is the same as the one passed in, the timer continues at the same rate. If the returned value from the callback is 0, the timer is cancelled.

Another way to cancel a currently-running timer is by calling SDL::remove_timer with the timer's ID (which was returned from SDL::add_timer).

The timer callback function may run in a different thread than your main program, and so shouldn't call any functions from within itself. However, you may always call SDL::push_event.

SDL::add_timer returns the identifier value of the generated timer or undef on error.

Note : If you use this function, you need to pass SDL_INIT_TIMER to SDL::init.

Parameters

        interval [in]   The desired interval of the timer, in milliseconds. 
                        The granularity of the timer is platform-dependent, but you should count on it being at least 10 ms as this is the most common number.
                        This means that if you request a 16 ms timer, your callback will run approximately 20 ms later on an unloaded system. 
                        If you wanted to set a flag signaling a frame update at 30 frames per second (every 33 ms), you might set a timer for 30 ms (see example below). 

        callback [in]   The SDL timer callback function which is called when the specified interval elapses. 

remove_timer( id )

Removes a timer callback previously added with SDL::add_timer. It returns 0 on succés or -1 on error.

1 POD Error

The following errors were encountered while parsing the POD:

Around line 85:

Non-ASCII character seen before =encoding in 'succés'. Assuming UTF-8