NAME

Game::Floppy::Ticker - when the next tick is due

VERSION

Version 0.09

SYNOPSIS

my $ticker = Game::Floppy::Ticker->new;
$ticker->start(1 / $game->speed);

while (...) {
    wait_for_a_key($ticker->remaining);
    if ($ticker->due) {
        $game->tick;
        $ticker->tick(1 / $game->speed);
    }
}

DESCRIPTION

The schedule both front ends tick the engine on. It is given the period on every call because the game's speed rises as it goes.

Lost time is dropped, never caught up: a tick that is overdue fires once and the schedule restarts from now, counted in late. A burst of unseen falls after a stall is how a one-button game kills you for the machine's sins.

METHODS

new

Game::Floppy::Ticker->new(clock => sub { ... });

clock is a code reference returning seconds; the default reads Time::HiRes. A test hands in a clock of its own.

start

$ticker->start($period);

The next tick is one period from now.

remaining

Seconds until the next tick, never negative.

due

True once the next tick's time has come.

tick

$ticker->tick($period);

Counts a tick and moves the schedule on by one period, or, when that time has already passed, to one period from now.

clock, next, ticks, late

The clock, when the next tick is due, how many ticks have been counted, and how many were late.

AUTHOR

LNATION, <email at lnation.org>

LICENSE AND COPYRIGHT

This software is Copyright (c) 2024 by LNATION.

This is free software, licensed under:

The Artistic License 2.0 (GPL Compatible)