summaryrefslogtreecommitdiff
path: root/2d
diff options
context:
space:
mode:
authorDavid Thompson <dthompson2@worcester.edu>2013-10-07 23:03:51 -0400
committerDavid Thompson <dthompson2@worcester.edu>2013-10-23 19:44:51 -0400
commit3cb0269d8b86d315abc0762a5c36a6838c097f43 (patch)
treeac5c0c1d91e746921acb59550aa6cd791622db74 /2d
parentbba3d11def443f4b3452724925d0551cf9e8f8ee (diff)
Implement game loop pausing.
Diffstat (limited to '2d')
-rw-r--r--2d/game-loop.scm21
1 files changed, 15 insertions, 6 deletions
diff --git a/2d/game-loop.scm b/2d/game-loop.scm
index 168f6f7..d5f1ed0 100644
--- a/2d/game-loop.scm
+++ b/2d/game-loop.scm
@@ -237,6 +237,19 @@ the stack."
(define running? #f)
(define paused? #f)
+(define (tick dt accumulator)
+ "Advance the game by one frame."
+ (if paused?
+ (begin
+ (run-repl)
+ (SDL:delay tick-interval)
+ accumulator)
+ (let ((remainder (update accumulator)))
+ (run-repl)
+ (render dt)
+ (switch-scenes-maybe)
+ remainder)))
+
(define (game-loop last-time accumulator)
"Update game state, and render. LAST-TIME is the time in
milliseconds of the last iteration of the loop. ACCUMULATOR is the
@@ -244,12 +257,8 @@ time in milliseconds that has passed since the last game update."
(when running?
(let* ((current-time (SDL:get-ticks))
(dt (- current-time last-time))
- (remainder (update (+ accumulator dt))))
- (run-repl)
- (render dt)
- (switch-scenes-maybe)
- (game-loop current-time
- remainder))))
+ (accumulator (+ accumulator dt)))
+ (game-loop current-time (tick dt accumulator)))))
(define (run-game game)
"Open a window and start the game loop for GAME."