summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid Thompson <dthompson2@worcester.edu>2013-06-25 22:59:28 -0400
committerDavid Thompson <dthompson2@worcester.edu>2013-06-25 22:59:28 -0400
commit8322351e99ecc9eeb0fd3cb2dcfbfc920bae61d2 (patch)
tree805fc0a70c0f27fb4f8f937ca27c8d908754c820
parentd0d08c004ea00514c8a0bb36397dab4fffc8e479 (diff)
Use delayed evaluation of SDL:get-ticks to avoid initial frame stutter.
-rw-r--r--2d/game-loop.scm12
1 files changed, 6 insertions, 6 deletions
diff --git a/2d/game-loop.scm b/2d/game-loop.scm
index 2d015ba..7b36e57 100644
--- a/2d/game-loop.scm
+++ b/2d/game-loop.scm
@@ -134,15 +134,15 @@
(SDL:gl-swap-buffers))
(define accumulate-fps
- (let ((last-time 0)
+ (let ((last-time (delay (SDL:get-ticks)))
(fps 0))
(lambda ()
"Calculates frames per second."
(let ((time (SDL:get-ticks)))
(set! fps (1+ fps))
- (when (>= time (+ last-time 1000))
+ (when (>= time (+ (force last-time) 1000))
(pk 'FPS fps)
- (set! last-time time)
+ (set! last-time (delay time))
(set! fps 0))))))
(define (update accumulator)
@@ -157,15 +157,15 @@ is the unused accumulator time."
(define update-and-render
(let ((remainder 0)
- (last-time 0))
+ (last-time (delay (SDL:get-ticks))))
(lambda ()
"Calls update and draw callback when enough time has passed
since the last tick."
(let* ((time (SDL:get-ticks))
- (elapsed (- time last-time))
+ (elapsed (- time (force last-time)))
(accumulator (+ remainder elapsed)))
(when (>= accumulator frame-interval)
- (set! last-time time)
+ (set! last-time (delay time))
(set! remainder (update accumulator))
(accumulate-fps)
(render))))))