From 988e77463e46953730f6d2b01107b6813471dbb7 Mon Sep 17 00:00:00 2001 From: Slava Pestov Date: Mon, 5 Sep 2011 23:56:33 -0700 Subject: [PATCH] game.loop: split off benchmarking code into game.loop.benchmark --- extra/game/loop/benchmark/benchmark.factor | 37 +++++++++++++++++++ extra/game/loop/loop.factor | 42 +++++++--------------- 2 files changed, 50 insertions(+), 29 deletions(-) create mode 100644 extra/game/loop/benchmark/benchmark.factor diff --git a/extra/game/loop/benchmark/benchmark.factor b/extra/game/loop/benchmark/benchmark.factor new file mode 100644 index 0000000000..9e1b3fe915 --- /dev/null +++ b/extra/game/loop/benchmark/benchmark.factor @@ -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 + +: ( benchmark-data-pair tick frame -- obj ) + \ game-loop-benchmark + 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 + + ] + [ drop ensure-benchmark-data ] + 2bi push ; + diff --git a/extra/game/loop/loop.factor b/extra/game/loop/loop.factor index fa9d17eb0f..d788c41b29 100755 --- a/extra/game/loop/loop.factor +++ b/extra/game/loop/loop.factor @@ -1,9 +1,8 @@ ! (c)2009 Joe Groff bsd license USING: accessors timers alien.c-types calendar classes.struct continuations destructors fry kernel math math.order memory -namespaces sequences specialized-vectors system -ui ui.gadgets.worlds vm vocabs.loader arrays -tools.time.struct locals ; +namespaces sequences system ui ui.gadgets.worlds vm +vocabs.loader arrays locals ; IN: game.loop TUPLE: game-loop @@ -17,19 +16,6 @@ TUPLE: game-loop draw-timer benchmark-data ; -STRUCT: game-loop-benchmark - { benchmark-data-pair benchmark-data-pair } - { tick# ulonglong } - { frame# ulonglong } ; - -SPECIALIZED-VECTOR: game-loop-benchmark - -: ( benchmark-data-pair tick frame -- obj ) - \ game-loop-benchmark - swap >>frame# - swap >>tick# - swap >>benchmark-data-pair ; inline - GENERIC: tick* ( delegate -- ) GENERIC: draw* ( tick-slice delegate -- ) @@ -48,26 +34,24 @@ TUPLE: game-loop-error game-loop error ; > ] - [ frame#>> ] - [ 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 ; +GENERIC# record-benchmarking 1 ( loop quot -- ) + +M: object record-benchmarking + call( loop -- ) ; + : redraw ( loop -- ) [ 1 + ] change-frame# [ [ last-tick-percent-offset ] [ draw-delegate>> ] bi - [ draw* ] with-benchmarking - ] keep record-benchmarking ; + draw* + ] record-benchmarking ; : tick ( loop -- ) - [ - [ tick-delegate>> tick* ] with-benchmarking - ] keep record-benchmarking ; + [ tick-delegate>> tick* ] record-benchmarking ; : increment-tick ( loop -- ) [ 1 + ] change-tick# @@ -105,9 +89,7 @@ PRIVATE> [ tick-timer>> ] [ draw-timer>> ] bi [ stop-timer ] bi@ ; : ( tick-interval-nanos tick-delegate draw-delegate -- loop ) - f 0 0 f f - game-loop-benchmark-vector{ } clone - game-loop boa ; + f 0 0 f f f game-loop boa ; : ( tick-interval-nanos delegate -- loop ) dup ; inline @@ -116,3 +98,5 @@ M: game-loop dispose stop-loop ; { "game.loop" "prettyprint" } "game.loop.prettyprint" require-when +! { "game.loop" "tools.memory" } "game.loop.benchmark" require-when +"game.loop.benchmark" require