NAME

SDL::App::FPS::Timer - a timer class for SDL::App::FPS

SYNOPSIS

my $timer = SDL::App::FPS::Timer->new(
	$time_to_first_shot,
	$count,
	$delay_between_shots,
	$randomize,
	$now,
	$callback,
	@arguments_to_callback
);

DESCRIPTION

This package provides a timer class. It is used by SDL::App::FPS and you need not to use it directly.

CALLBACK

Once the timer has expired, the callback code (CODE ref) is called with the following parameters:

&{$callback}($self,$timer,$overdue,@arguments);

$self is the app the timer resides in (e.g. the object of type SDL::App::FPS), $timer is the timer itself, $overdue is the time the timer is late (e.g. it fires now, but should have fired -$overdue ms ago) and the additional arguments are whatever was passed when the timer was created.

METHODS

new()
my $timer = SDL::App::FPS::Timer->new(
	$time_to_first_shot,
	$count,
	$delay_between_shots,
	$randomize,
	$now,
	$callback,
	@arguments_to_callback
);

Creates a new timer that will first fire at $time_to_first_shot from $now on (assuming $now is the current time), fire at most of $count times (negative counts means infinitely often), and between each shot will wait for $delay. Both initial time and delay are in ms.

The randomize parameter should be smaller than the time and/or delay, it will be used to randomize the delay times.

If you setup a timer with a delay of 1000 ms and a randomize value of 100, the earliest time it will fire is 900 ms, and the latest time would be 1100 ms.

next_shot()
$timer->next_shot();

Returns the absolute time when the timer will fire the next time.

due()

Check whether the time is due or not. If is ise due (or overdue), it will fire.

id()

Returns the timers unique id.

fired()

Returns whether the timer fired or not. Use only after calling due().

count()

Returns the number of 'shots' left. Negative value means the timer will fire infinitely often.

group()
my $group = $timer->group();

Returns the ref to the group this timer belongs to, or undef.

is_active()
$timer->is_active();

Returns true if the timer is active, or false for inactive. Inactive timers do not fire.

activate()

Set the timer to active. Newly created ones are always active.

deactivate()

Set the timer to inactive. Newly created ones are always active.

BUGS

due() does ignore when the timer should have fire multiple times between it was started and the time it is checked. E.g. when then timer is due in 100 ms, and should fire 3 times, and then is checked the first time after 1000 ms, it should imidiately 3 times, each time having a different overdue time.

Currently it fires only once.

AUTHORS

(c) 2002, 2003, Tels <http://bloodgate.com/>

SEE ALSO

SDL:App::FPS, SDL::App and SDL.