From 8322351e99ecc9eeb0fd3cb2dcfbfc920bae61d2 Mon Sep 17 00:00:00 2001 From: David Thompson Date: Tue, 25 Jun 2013 22:59:28 -0400 Subject: Use delayed evaluation of SDL:get-ticks to avoid initial frame stutter. --- 2d/game-loop.scm | 12 ++++++------ 1 file 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)))))) -- cgit v1.2.3