diff --git a/extra/game/loop/loop-docs.factor b/extra/game/loop/loop-docs.factor index 1605c45284..6dbef30442 100644 --- a/extra/game/loop/loop-docs.factor +++ b/extra/game/loop/loop-docs.factor @@ -31,16 +31,16 @@ HELP: benchmark-frames-per-second { "loop" game-loop } { "n" float } } -{ $description "Returns the average number of times per second the game loop has called " { $link draw* } " on its delegate since the game loop was started with " { $link start-loop } " or since the benchmark counters have been reset with " { $link reset-loop-benchmark } "." } ; +{ $description "Returns the average number of times per second the game loop has called " { $link draw* } " on its delegate since the game loop was started with " { $link start-loop } "." } ; HELP: benchmark-ticks-per-second { $values { "loop" game-loop } { "n" float } } -{ $description "Returns the average number of times per second the game loop has called " { $link tick* } " on its tick delegate since the game loop was started with " { $link start-loop } " or since the benchmark counters have been reset with " { $link reset-loop-benchmark } "." } ; +{ $description "Returns the average number of times per second the game loop has called " { $link tick* } " on its tick delegate since the game loop was started." } ; -{ reset-loop-benchmark benchmark-frames-per-second benchmark-ticks-per-second } related-words +{ benchmark-frames-per-second benchmark-ticks-per-second } related-words HELP: draw* { $values @@ -59,12 +59,6 @@ HELP: game-loop-error } { $description "If an uncaught error is thrown from inside a game loop delegate's " { $link tick* } " or " { $link draw* } ", the game loop will catch the error, stop the game loop, and rethrow an error of this class." } ; -HELP: reset-loop-benchmark -{ $values - { "loop" game-loop } -} -{ $description "Resets the benchmark counters on a " { $link game-loop } ". Subsequent calls to " { $link benchmark-frames-per-second } " and " { $link benchmark-ticks-per-second } " will measure their values from the point " { $snippet "reset-loop-benchmark" } " was called." } ; - HELP: start-loop { $values { "loop" game-loop } @@ -111,7 +105,6 @@ ARTICLE: "game.loop" "Game loops" } "The game loop maintains performance counters:" { $subsections - reset-loop-benchmark benchmark-frames-per-second benchmark-ticks-per-second } diff --git a/extra/game/loop/loop.factor b/extra/game/loop/loop.factor index c4c190355b..a26a52226e 100644 --- a/extra/game/loop/loop.factor +++ b/extra/game/loop/loop.factor @@ -1,6 +1,9 @@ ! (c)2009 Joe Groff bsd license -USING: accessors alarms calendar continuations destructors fry -kernel math math.order namespaces system ui ui.gadgets.worlds ; +USING: accessors alarms alien.c-types calendar classes.struct +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 @@ -9,12 +12,23 @@ TUPLE: game-loop draw-delegate { last-tick integer } { running? boolean } - { tick-number integer } - { frame-number integer } - { benchmark-time integer } - { benchmark-tick-number integer } - { benchmark-frame-number integer } - alarm ; + { tick# integer } + { frame# integer } + alarm + 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 -- ) @@ -44,16 +58,25 @@ TUPLE: game-loop-error game-loop error ; > ] + [ frame#>> ] + [ benchmark-data>> ] tri push ; + : redraw ( loop -- ) - [ 1 + ] change-frame-number - [ tick-slice ] [ draw-delegate>> ] bi draw* ; + [ 1 + ] change-frame# + [ + [ tick-slice ] [ draw-delegate>> ] bi [ draw* ] with-benchmarking + ] keep record-benchmarking ; : tick ( loop -- ) - tick-delegate>> tick* ; + [ + [ tick-delegate>> tick* ] with-benchmarking + ] keep record-benchmarking ; : increment-tick ( loop -- ) - [ 1 + ] change-tick-number - dup tick-interval-nanos>> [ + ] curry change-last-tick + [ 1 + ] change-tick# + dup tick-interval-nanos>> '[ _ + ] change-last-tick drop ; : ?tick ( loop count -- ) @@ -63,20 +86,13 @@ TUPLE: game-loop-error game-loop error ; [ 2drop ] if ] if-zero ; -: benchmark-nanos ( loop -- nanos ) - nano-count swap benchmark-time>> - ; - PRIVATE> -: reset-loop-benchmark ( loop -- loop ) - nano-count >>benchmark-time - dup tick-number>> >>benchmark-tick-number - dup frame-number>> >>benchmark-frame-number ; +! : benchmark-ticks-per-second ( loop -- n ) + ! [ tick#>> ] [ benchmark-tick#>> - ] [ benchmark-nanos ] tri /f ; -: benchmark-ticks-per-second ( loop -- n ) - [ tick-number>> ] [ benchmark-tick-number>> - ] [ benchmark-nanos ] tri /f ; -: benchmark-frames-per-second ( loop -- n ) - [ frame-number>> ] [ benchmark-frame-number>> - ] [ benchmark-nanos ] tri /f ; +! : benchmark-frames-per-second ( loop -- n ) + ! [ frame#>> ] [ benchmark-frame#>> - ] [ benchmark-nanos ] tri /f ; : (game-tick) ( loop -- ) dup running?>> @@ -91,7 +107,6 @@ PRIVATE> : start-loop ( loop -- ) nano-count >>last-tick t >>running? - reset-loop-benchmark [ [ '[ _ game-tick ] f ] [ tick-interval-nanos>> nanoseconds ] bi @@ -103,7 +118,8 @@ PRIVATE> alarm>> stop-alarm ; : ( tick-interval-nanos tick-delegate draw-delegate -- loop ) - nano-count f 0 0 nano-count 0 0 f + nano-count f 0 0 f + game-loop-benchmark-vector{ } clone game-loop boa ; : ( tick-interval-nanos delegate -- loop ) @@ -112,6 +128,5 @@ PRIVATE> M: game-loop dispose stop-loop ; -USE: vocabs.loader - { "game.loop" "prettyprint" } "game.loop.prettyprint" require-when + diff --git a/extra/terrain/terrain.factor b/extra/terrain/terrain.factor index e1051cf21b..5a65851037 100644 --- a/extra/terrain/terrain.factor +++ b/extra/terrain/terrain.factor @@ -229,9 +229,9 @@ M: terrain-world tick-game-world GL_TEXTURE_2D GL_TEXTURE_WRAP_T GL_CLAMP_TO_EDGE glTexParameteri ; : sky-gradient ( world -- t ) - game-loop>> tick-number>> SKY-PERIOD mod SKY-PERIOD /f ; + game-loop>> tick#>> SKY-PERIOD mod SKY-PERIOD /f ; : sky-theta ( world -- theta ) - game-loop>> tick-number>> SKY-SPEED * ; + game-loop>> tick#>> SKY-SPEED * ; M: terrain-world begin-game-world "2.0" { "GL_ARB_vertex_buffer_object" "GL_ARB_shader_objects" }