game-loop


Vocabulary
game.loop

Class description
Objects of the game-loop class manage game loops. See Game loops for an overview of the game loop library. To construct a game loop, use <game-loop>. To start and stop a game loop, use the start-loop and stop-loop words.

The tick-delegate and draw-delegate slots of a game loop object determine where the loop sends its tick* and draw* events. These slots can be changed while the game loop is running.

Definition
USING: kernel math ;

IN: game.loop

TUPLE: game-loop
{ tick-interval-nanos integer read-only initial: 0 }
tick-delegate draw-delegate
{ running? boolean initial: f }
{ tick# integer initial: 0 } { frame# integer initial: 0 }
tick-timer draw-timer benchmark-data ;


Methods
USING: destructors game.loop ;

M: game-loop dispose stop-loop ;


USING: accessors combinators game.loop game.loop.benchmark
game.loop.private kernel sequences tools.time.struct ;

M: game-loop record-benchmarking
[
[ [ ( loop -- ) call-effect ] with-benchmarking ]
[ drop tick#>> ] [ drop frame#>> ] 2tri
<game-loop-benchmark>
] [ drop ensure-benchmark-data ] 2bi push ;