diff options
author | David Thompson <dthompson2@worcester.edu> | 2014-01-07 21:51:30 -0500 |
---|---|---|
committer | David Thompson <dthompson2@worcester.edu> | 2014-01-07 21:51:30 -0500 |
commit | 4e307506829a3f710f40a58f4fe07b758e3636cc (patch) | |
tree | 1aca3b8dc0c77be8b377031e7280b4575c28c613 | |
parent | b830d683cd4ecd7953a6b2b6ad455f1ee7ab5472 (diff) |
Make tick-interval a parameter.
* 2d/game.scm (run-game-loop): Compute tick-interval.
(update, update-and-render, tick): Use tick-interval parameter.
-rw-r--r-- | 2d/game.scm | 24 |
1 files changed, 13 insertions, 11 deletions
diff --git a/2d/game.scm b/2d/game.scm index 3e1f982..da4e0b8 100644 --- a/2d/game.scm +++ b/2d/game.scm @@ -34,7 +34,9 @@ #:use-module (2d repl repl) #:use-module (2d signals) #:use-module (2d vector2) - #:export (draw-hook + #:export (ticks-per-second + tick-interval + draw-hook run-game-loop quit-game pause-game @@ -53,17 +55,17 @@ ;; * running ;; * paused (define %state 'stopped) -;; TODO: Make this configurable (define ticks-per-second 60) -(define tick-interval (floor (/ 1000 ticks-per-second))) +(define tick-interval (make-parameter 0)) (define draw-hook (make-hook)) (define (run-game-loop) "Start the game loop." - (set! %state 'running) - (resume-game) - (spawn-server) - (game-loop (SDL:get-ticks) 0)) + (parameterize ((tick-interval (floor (/ 1000 ticks-per-second)))) + (set! %state 'running) + (resume-game) + (spawn-server) + (game-loop (SDL:get-ticks) 0))) (define (draw dt alpha) "Render a frame." @@ -78,17 +80,17 @@ "Call the update callback. The update callback will be called as many times as `tick-interval` can divide ACCUMULATOR. The return value is the unused accumulator time." - (if (>= accumulator tick-interval) + (if (>= accumulator (tick-interval)) (begin (handle-events) (tick-agenda!) - (update (- accumulator tick-interval))) + (update (- accumulator (tick-interval)))) accumulator)) (define (update-and-render dt accumulator) (let ((remainder (update accumulator))) (run-repl) - (draw dt (/ remainder tick-interval)) + (draw dt (/ remainder (tick-interval))) remainder)) (define (tick dt accumulator) @@ -96,7 +98,7 @@ is the unused accumulator time." (if (game-paused?) (begin (run-repl) - (SDL:delay tick-interval) + (SDL:delay (tick-interval)) accumulator) (catch #t (lambda () |