summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid Thompson <dthompson2@worcester.edu>2020-12-15 17:59:09 -0500
committerDavid Thompson <dthompson2@worcester.edu>2020-12-15 17:59:09 -0500
commit8726cc42e3e7e5e6f34f7328898e35ed207bfb08 (patch)
treef2599a60f404b086c1054befa07106c3f6d1320d
parent11cf5c63610e8bb858fa21ecea37196d9c8f17e4 (diff)
Switch to high resolution timer.
-rw-r--r--chickadee.scm9
-rw-r--r--chickadee/game-loop.scm2
-rw-r--r--doc/api.texi3
-rw-r--r--examples/particles.scm2
-rw-r--r--examples/path.scm6
-rw-r--r--examples/sprite-batch.scm2
-rw-r--r--examples/tiled.scm2
7 files changed, 13 insertions, 13 deletions
diff --git a/chickadee.scm b/chickadee.scm
index e00b2b1..611674a 100644
--- a/chickadee.scm
+++ b/chickadee.scm
@@ -77,10 +77,11 @@
run-game)
#:re-export (abort-game))
+(define %time-freq (exact->inexact (sdl-performance-frequency)))
+
(define (elapsed-time)
- "Return the number of milliseconds that have passed since the game
-loop was started."
- (sdl-ticks))
+ "Return the current value of the system timer in seconds."
+ (/ (sdl-performance-counter) %time-freq))
(define (key-pressed? key)
"Return #t if KEY is currently being pressed."
@@ -390,7 +391,7 @@ border is disabled, otherwise it is enabled.")
(run-game* #:update update-sdl
#:render render-sdl-opengl
#:error error
- #:time sdl-ticks
+ #:time elapsed-time
#:update-hz update-hz)))
(lambda ()
(quit-audio)
diff --git a/chickadee/game-loop.scm b/chickadee/game-loop.scm
index 09f8a7b..6a14fab 100644
--- a/chickadee/game-loop.scm
+++ b/chickadee/game-loop.scm
@@ -58,7 +58,7 @@
(define* (run-game* #:key update render time error
(update-hz 60))
- (let ((timestep (round (/ 1000 update-hz))))
+ (let ((timestep (/ 1.0 update-hz)))
(call-with-prompt game-loop-prompt-tag
(lambda ()
;; Catch SIGINT and kill the loop.
diff --git a/doc/api.texi b/doc/api.texi
index e9aa72f..a74d6f2 100644
--- a/doc/api.texi
+++ b/doc/api.texi
@@ -354,8 +354,7 @@ behavior is to simply re-throw the error.
@end deffn
@deffn {Procedure} elapsed-time
-Return the number of milliseconds that have passed since the game loop
-was started.
+Return the current value of the system timer in seconds.
@end deffn
@node Input Devices
diff --git a/examples/particles.scm b/examples/particles.scm
index 97cdb1d..abefd94 100644
--- a/examples/particles.scm
+++ b/examples/particles.scm
@@ -49,7 +49,7 @@
(sleep 60)
(set! stats-text (format #f "particles: ~d fps: ~1,2f"
(particles-size particles)
- (/ 1000.0 avg-frame-time))))))
+ (/ 1.0 avg-frame-time))))))
(define stats-text-pos (vec2 4.0 (- window-height 16.0)))
(define sprite-position (vec2 (center-x 128.0) (center-y 128.0)))
diff --git a/examples/path.scm b/examples/path.scm
index 0223864..7bad91b 100644
--- a/examples/path.scm
+++ b/examples/path.scm
@@ -10,9 +10,9 @@
(define (stats-message)
(format #f "fps: ~1,2f"
- (/ 1000.0 avg-frame-time)))
+ (/ 1.0 avg-frame-time)))
(define start-time 0.0)
-(define avg-frame-time 16)
+(define avg-frame-time 0.0)
(define stats-text (stats-message))
(define stats-text-pos (vec2 4.0 464.0))
(define last-update start-time)
@@ -67,7 +67,7 @@
(+ (* (- current-time start-time) 0.1)
(* avg-frame-time 0.9)))
(set! start-time current-time)
- (when (>= (- current-time last-update) 1000)
+ (when (>= (- current-time last-update) 1.0)
(set! stats-text (stats-message))
(set! last-update current-time))))
diff --git a/examples/sprite-batch.scm b/examples/sprite-batch.scm
index 4b8d433..3aad219 100644
--- a/examples/sprite-batch.scm
+++ b/examples/sprite-batch.scm
@@ -31,7 +31,7 @@
(define (stats-message)
(format #f "sprites: ~d fps: ~1,2f"
num-sprites
- (/ 1000.0 avg-frame-time)))
+ (/ 1.0 avg-frame-time)))
(define stats-text (stats-message))
diff --git a/examples/tiled.scm b/examples/tiled.scm
index 0f7c4fa..c528f74 100644
--- a/examples/tiled.scm
+++ b/examples/tiled.scm
@@ -16,7 +16,7 @@
(define text "0, 0")
(define (stats-message)
(format #f "fps: ~1,2f"
- (/ 1000.0 avg-frame-time)))
+ (/ 1.0 avg-frame-time)))
(define start-time 0.0)
(define avg-frame-time 16)
(define stats-text (stats-message))