]> gitweb.factorcode.org Git - factor.git/commitdiff
game.loop: using timer's next-nanos, which is in the future.
authorJohn Benediktsson <mrjbq7@gmail.com>
Mon, 6 Jan 2020 21:14:59 +0000 (13:14 -0800)
committerJohn Benediktsson <mrjbq7@gmail.com>
Mon, 6 Jan 2020 21:14:59 +0000 (13:14 -0800)
Also, use clamp to make sure tick offset is always [0,1].

extra/game/loop/loop.factor

index c2612fd2b77b99a5482ae5029567ac7eea619240..7047acf09d31fb9326be9cb1df9401fec6d3d4cd 100644 (file)
@@ -1,9 +1,8 @@
 ! Copyright (C) 2009 Joe Groff.
 ! See http://factorcode.org/license.txt for BSD license.
-USING: accessors timers alien.c-types calendar classes.struct
-continuations destructors fry kernel math math.order memory
-namespaces sequences system ui ui.gadgets.worlds vm
-vocabs.loader arrays locals ;
+USING: accessors calendar continuations destructors fry kernel
+locals math math.order system timers ui ui.gadgets.worlds
+vocabs.loader ;
 IN: game.loop
 
 TUPLE: game-loop
@@ -36,8 +35,8 @@ TUPLE: game-loop-error-state error game-loop ;
 <PRIVATE
 
 : last-tick-percent-offset ( loop -- float )
-    [ draw-timer>> next-nanos>> nano-count swap - ]
-    [ tick-interval-nanos>> ] bi /f 1.0 min ;
+    [ draw-timer>> next-nanos>> nano-count - ]
+    [ tick-interval-nanos>> ] bi /f 0.0 1.0 clamp ;
 
 GENERIC#: record-benchmarking 1 ( loop quot -- )