From bd62fb22aac7098f7e8a92bd8ed129fb451c2bba Mon Sep 17 00:00:00 2001 From: Joe Groff Date: Fri, 15 Jan 2010 15:03:33 -0800 Subject: [PATCH] game-loop: change "tick-length" to more descriptive "tick-interval-micros" --- extra/game/loop/loop.factor | 10 +++++----- extra/game/worlds/worlds.factor | 7 +++++-- extra/gpu/demos/bunny/bunny.factor | 2 +- extra/gpu/demos/raytrace/raytrace.factor | 2 +- extra/terrain/terrain.factor | 2 +- 5 files changed, 13 insertions(+), 10 deletions(-) diff --git a/extra/game/loop/loop.factor b/extra/game/loop/loop.factor index c0f36d0294..0862a5e48c 100644 --- a/extra/game/loop/loop.factor +++ b/extra/game/loop/loop.factor @@ -4,7 +4,7 @@ sequences ; IN: game.loop TUPLE: game-loop - { tick-length integer read-only } + { tick-interval-micros integer read-only } delegate { last-tick integer } thread @@ -24,7 +24,7 @@ SYMBOL: game-loop last-tick>> system-micros swap - ; : tick-slice ( loop -- slice ) - [ since-last-tick ] [ tick-length>> ] bi /f 1.0 min ; + [ since-last-tick ] [ tick-interval-micros>> ] bi /f 1.0 min ; CONSTANT: MAX-FRAMES-TO-SKIP 5 @@ -49,12 +49,12 @@ TUPLE: game-loop-error game-loop error ; : increment-tick ( loop -- ) [ 1 + ] change-tick-number - dup tick-length>> [ + ] curry change-last-tick + dup tick-interval-micros>> [ + ] curry change-last-tick drop ; : ?tick ( loop count -- ) [ system-micros >>last-tick drop ] [ - over [ since-last-tick ] [ tick-length>> ] bi >= + over [ since-last-tick ] [ tick-interval-micros>> ] bi >= [ [ drop increment-tick ] [ drop tick ] [ 1 - ?tick ] 2tri ] [ 2drop ] if ] if-zero ; @@ -97,7 +97,7 @@ PRIVATE> f >>thread drop ; -: ( tick-length delegate -- loop ) +: ( tick-interval-micros delegate -- loop ) system-micros f f 0 0 system-micros 0 0 game-loop boa ; diff --git a/extra/game/worlds/worlds.factor b/extra/game/worlds/worlds.factor index 308b5006cf..cba57c89e9 100644 --- a/extra/game/worlds/worlds.factor +++ b/extra/game/worlds/worlds.factor @@ -6,14 +6,14 @@ TUPLE: game-world < world game-loop { tick-slice float initial: 0.0 } ; -GENERIC: tick-length ( world -- micros ) +GENERIC: tick-interval-micros ( world -- micros ) M: game-world draw* swap >>tick-slice relayout-1 yield ; M: game-world begin-world open-game-input - dup [ tick-length ] [ ] bi [ >>game-loop ] keep start-loop + dup [ tick-interval-micros ] [ ] bi [ >>game-loop ] keep start-loop drop ; M: game-world end-world @@ -21,3 +21,6 @@ M: game-world end-world close-game-input drop ; +TUPLE: game-attributes < world-attributes + { tick-interval-micros fixnum read-only } ; + diff --git a/extra/gpu/demos/bunny/bunny.factor b/extra/gpu/demos/bunny/bunny.factor index 57fcf4e3ea..b1a2f81a1e 100644 --- a/extra/gpu/demos/bunny/bunny.factor +++ b/extra/gpu/demos/bunny/bunny.factor @@ -294,7 +294,7 @@ AFTER: bunny-world resize-world [ sobel>> framebuffer>> ] [ dim>> ] bi resize-framebuffer ; M: bunny-world pref-dim* drop { 1024 768 } ; -M: bunny-world tick-length drop 1000000 60 /i ; +M: bunny-world tick-interval-micros drop 1000000 60 /i ; M: bunny-world wasd-movement-speed drop 1/160. ; M: bunny-world wasd-near-plane drop 1/32. ; M: bunny-world wasd-far-plane drop 256.0 ; diff --git a/extra/gpu/demos/raytrace/raytrace.factor b/extra/gpu/demos/raytrace/raytrace.factor index bac55beacd..dd31244a45 100644 --- a/extra/gpu/demos/raytrace/raytrace.factor +++ b/extra/gpu/demos/raytrace/raytrace.factor @@ -93,7 +93,7 @@ M: raytrace-world draw-world* } render ; M: raytrace-world pref-dim* drop { 1024 768 } ; -M: raytrace-world tick-length drop 1000000 60 /i ; +M: raytrace-world tick-interval-micros drop 1000000 60 /i ; M: raytrace-world wasd-movement-speed drop 1/4. ; : raytrace-window ( -- ) diff --git a/extra/terrain/terrain.factor b/extra/terrain/terrain.factor index 89c7ccb8ba..655fee5011 100644 --- a/extra/terrain/terrain.factor +++ b/extra/terrain/terrain.factor @@ -55,7 +55,7 @@ TUPLE: terrain-world < game-world float-4{ 0.0 0.0 0.0 1.0 } >>velocity VELOCITY-MODIFIER-NORMAL >>velocity-modifier ; -M: terrain-world tick-length +M: terrain-world tick-interval-micros drop 1000000 60 /i ; : frustum ( dim -- -x x -y y near far )