     stop-loop ;
 
 { "game.loop" "prettyprint" } "game.loop.prettyprint" require-when
-

continuations destructors fry kernel math math.order memory
namespaces sequences specialized-vectors system
tools.memory ui ui.gadgets.worlds vm vocabs.loader arrays
benchmark.struct ;
IN: game.loop

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

STRUCT: game-loop-benchmark

    [ frame#>> <game-loop-benchmark> ]
    [ benchmark-data>> ] tri push ;

: last-tick-percent-offset ( loop -- float )
    [ draw-timer>> iteration-start-nanos>> nano-count swap - ]
    [ tick-interval-nanos>> ] bi /f 1.0 min ;

: redraw ( loop -- )
    [ 1 + ] change-frame#
    [
        [ last-tick-percent-offset ] [ draw-delegate>> ] bi
        [ draw* ] with-benchmarking
    ] keep record-benchmarking ;

: tick ( loop -- )
