game.loop: split off benchmarking code into game.loop.benchmark
parent
22ad7c4fcd
commit
7446aa5a39
|
|
@ -0,0 +1,37 @@
|
||||||
|
! (c)2009 Joe Groff bsd license
|
||||||
|
USING: accessors alien.c-types classes.struct game.loop
|
||||||
|
game.loop.private kernel sequences specialized-vectors
|
||||||
|
tools.time.struct ;
|
||||||
|
IN: game.loop.benchmark
|
||||||
|
|
||||||
|
STRUCT: game-loop-benchmark
|
||||||
|
{ benchmark-data-pair benchmark-data-pair }
|
||||||
|
{ tick# ulonglong }
|
||||||
|
{ frame# ulonglong } ;
|
||||||
|
|
||||||
|
SPECIALIZED-VECTOR: game-loop-benchmark
|
||||||
|
|
||||||
|
: <game-loop-benchmark> ( benchmark-data-pair tick frame -- obj )
|
||||||
|
\ game-loop-benchmark <struct>
|
||||||
|
swap >>frame#
|
||||||
|
swap >>tick#
|
||||||
|
swap >>benchmark-data-pair ; inline
|
||||||
|
|
||||||
|
: ensure-benchmark-data ( loop -- vector )
|
||||||
|
dup benchmark-data>> [
|
||||||
|
game-loop-benchmark-vector{ } clone
|
||||||
|
>>benchmark-data
|
||||||
|
] unless
|
||||||
|
benchmark-data>> ; inline
|
||||||
|
|
||||||
|
M: game-loop record-benchmarking ( loop quot: ( loop -- benchmark-data-pair ) -- )
|
||||||
|
[
|
||||||
|
[ [ call( loop -- ) ] with-benchmarking ]
|
||||||
|
[ drop tick#>> ]
|
||||||
|
[ drop frame#>> ]
|
||||||
|
2tri
|
||||||
|
<game-loop-benchmark>
|
||||||
|
]
|
||||||
|
[ drop ensure-benchmark-data ]
|
||||||
|
2bi push ;
|
||||||
|
|
||||||
|
|
@ -1,9 +1,8 @@
|
||||||
! (c)2009 Joe Groff bsd license
|
! (c)2009 Joe Groff bsd license
|
||||||
USING: accessors timers alien.c-types calendar classes.struct
|
USING: accessors timers alien.c-types calendar classes.struct
|
||||||
continuations destructors fry kernel math math.order memory
|
continuations destructors fry kernel math math.order memory
|
||||||
namespaces sequences specialized-vectors system
|
namespaces sequences system ui ui.gadgets.worlds vm
|
||||||
ui ui.gadgets.worlds vm vocabs.loader arrays
|
vocabs.loader arrays locals ;
|
||||||
tools.time.struct locals ;
|
|
||||||
IN: game.loop
|
IN: game.loop
|
||||||
|
|
||||||
TUPLE: game-loop
|
TUPLE: game-loop
|
||||||
|
|
@ -17,19 +16,6 @@ TUPLE: game-loop
|
||||||
draw-timer
|
draw-timer
|
||||||
benchmark-data ;
|
benchmark-data ;
|
||||||
|
|
||||||
STRUCT: game-loop-benchmark
|
|
||||||
{ benchmark-data-pair benchmark-data-pair }
|
|
||||||
{ tick# ulonglong }
|
|
||||||
{ frame# ulonglong } ;
|
|
||||||
|
|
||||||
SPECIALIZED-VECTOR: game-loop-benchmark
|
|
||||||
|
|
||||||
: <game-loop-benchmark> ( benchmark-data-pair tick frame -- obj )
|
|
||||||
\ game-loop-benchmark <struct>
|
|
||||||
swap >>frame#
|
|
||||||
swap >>tick#
|
|
||||||
swap >>benchmark-data-pair ; inline
|
|
||||||
|
|
||||||
GENERIC: tick* ( delegate -- )
|
GENERIC: tick* ( delegate -- )
|
||||||
GENERIC: draw* ( tick-slice delegate -- )
|
GENERIC: draw* ( tick-slice delegate -- )
|
||||||
|
|
||||||
|
|
@ -48,26 +34,24 @@ TUPLE: game-loop-error game-loop error ;
|
||||||
|
|
||||||
<PRIVATE
|
<PRIVATE
|
||||||
|
|
||||||
: record-benchmarking ( benchark-data-pair loop -- )
|
|
||||||
[ tick#>> ]
|
|
||||||
[ frame#>> <game-loop-benchmark> ]
|
|
||||||
[ benchmark-data>> ] tri push ;
|
|
||||||
|
|
||||||
: last-tick-percent-offset ( loop -- float )
|
: last-tick-percent-offset ( loop -- float )
|
||||||
[ draw-timer>> iteration-start-nanos>> nano-count swap - ]
|
[ draw-timer>> iteration-start-nanos>> nano-count swap - ]
|
||||||
[ tick-interval-nanos>> ] bi /f 1.0 min ;
|
[ tick-interval-nanos>> ] bi /f 1.0 min ;
|
||||||
|
|
||||||
|
GENERIC# record-benchmarking 1 ( loop quot -- )
|
||||||
|
|
||||||
|
M: object record-benchmarking
|
||||||
|
call( loop -- ) ;
|
||||||
|
|
||||||
: redraw ( loop -- )
|
: redraw ( loop -- )
|
||||||
[ 1 + ] change-frame#
|
[ 1 + ] change-frame#
|
||||||
[
|
[
|
||||||
[ last-tick-percent-offset ] [ draw-delegate>> ] bi
|
[ last-tick-percent-offset ] [ draw-delegate>> ] bi
|
||||||
[ draw* ] with-benchmarking
|
draw*
|
||||||
] keep record-benchmarking ;
|
] record-benchmarking ;
|
||||||
|
|
||||||
: tick ( loop -- )
|
: tick ( loop -- )
|
||||||
[
|
[ tick-delegate>> tick* ] record-benchmarking ;
|
||||||
[ tick-delegate>> tick* ] with-benchmarking
|
|
||||||
] keep record-benchmarking ;
|
|
||||||
|
|
||||||
: increment-tick ( loop -- )
|
: increment-tick ( loop -- )
|
||||||
[ 1 + ] change-tick#
|
[ 1 + ] change-tick#
|
||||||
|
|
@ -105,9 +89,7 @@ PRIVATE>
|
||||||
[ tick-timer>> ] [ draw-timer>> ] bi [ stop-timer ] bi@ ;
|
[ tick-timer>> ] [ draw-timer>> ] bi [ stop-timer ] bi@ ;
|
||||||
|
|
||||||
: <game-loop*> ( tick-interval-nanos tick-delegate draw-delegate -- loop )
|
: <game-loop*> ( tick-interval-nanos tick-delegate draw-delegate -- loop )
|
||||||
f 0 0 f f
|
f 0 0 f f f game-loop boa ;
|
||||||
game-loop-benchmark-vector{ } clone
|
|
||||||
game-loop boa ;
|
|
||||||
|
|
||||||
: <game-loop> ( tick-interval-nanos delegate -- loop )
|
: <game-loop> ( tick-interval-nanos delegate -- loop )
|
||||||
dup <game-loop*> ; inline
|
dup <game-loop*> ; inline
|
||||||
|
|
@ -116,3 +98,5 @@ M: game-loop dispose
|
||||||
stop-loop ;
|
stop-loop ;
|
||||||
|
|
||||||
{ "game.loop" "prettyprint" } "game.loop.prettyprint" require-when
|
{ "game.loop" "prettyprint" } "game.loop.prettyprint" require-when
|
||||||
|
! { "game.loop" "tools.memory" } "game.loop.benchmark" require-when
|
||||||
|
"game.loop.benchmark" require
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue