Game loops


The game.loop vocabulary contains the implementation of a game loop. The game loop supports decoupled rendering and game logic timers; given a "tick delegate" object with a method on the tick* generic and a "draw delegate" with a draw* method, the game loop will invoke the tick* method on the former at regular intervals while invoking the draw* method on the latter as frequently as possible. Game loop objects must first be constructed:
Game loop delegate
<game-loop> ( tick-interval-nanos delegate -- loop )

<game-loop*> ( tick-interval-nanos tick-delegate draw-delegate -- loop )


Once constructed, the game loop can be started and stopped:
start-loop ( loop -- )

stop-loop ( loop -- )


The game loop catches errors that occur in the delegate's methods during the course of the game loop:
game-loop-error ( error game-loop -- )


The game.worlds vocabulary provides a convenient world subclass that integrates the game loop implementation with UI applications, managing the starting and stopping of the loop for you.