summaryrefslogtreecommitdiff
path: root/2d
diff options
context:
space:
mode:
authorDavid Thompson <dthompson@member.fsf.org>2014-04-24 21:22:06 -0400
committerDavid Thompson <dthompson@member.fsf.org>2014-04-24 21:27:01 -0400
commit257b4c2498640dc31c3d807e04c1637cf5ba4967 (patch)
tree07baed7b26151339a9f0a65614f083705cb11f09 /2d
parent21466040f58bece701670324c2548f15bcec325e (diff)
Run game loop with a prompt.
* 2d/game.scm (game-loop-status, game-running?, game-paused?) (pause-game, resume-game, paused-agenda): Delete. (run-game-loop): Call game loop with prompt. (quit-game): Abort to game loop prompt.
Diffstat (limited to '2d')
-rw-r--r--2d/game.scm63
1 files changed, 16 insertions, 47 deletions
diff --git a/2d/game.scm b/2d/game.scm
index 770d3b1..7f24193 100644
--- a/2d/game.scm
+++ b/2d/game.scm
@@ -32,38 +32,29 @@
#:export (ticks-per-second
tick-interval
game-agenda
- paused-agenda
draw-hook
run-game-loop
- quit-game
- pause-game
- resume-game
- game-running?
- game-paused?))
+ quit-game))
;;;
;;; Game Loop
;;;
-;; Possible states are:
-;; * stopped
-;; * running
-;; * paused
-(define game-loop-status (make-parameter 'stopped))
(define ticks-per-second 60)
(define tick-interval (make-parameter 0))
(define draw-hook (make-hook 2))
(define game-agenda (make-agenda))
-;; This agenda is only ticked when the game loop is in the paused
-;; state. Useful for things like the REPL that should be run even
-;; though the game is paused.
-(define paused-agenda (make-agenda))
(define (run-game-loop)
"Start the game loop."
- (parameterize ((game-loop-status 'running)
- (tick-interval (floor (/ 1000 ticks-per-second))))
- (game-loop (SDL:get-ticks) 0)))
+ (parameterize ((tick-interval (floor (/ 1000 ticks-per-second))))
+ (call-with-prompt
+ 'game-loop-prompt
+ (lambda ()
+ (game-loop (SDL:get-ticks) 0))
+ (lambda (cont callback)
+ (when (procedure? callback)
+ (callback cont))))))
(define (draw dt alpha)
"Render a frame."
@@ -90,34 +81,12 @@ is the unused accumulator time."
(define (game-loop previous-time lag)
"Update game state, and render. PREVIOUS-TIME is the time in
milliseconds of the last iteration of the game loop."
- (when (game-running?)
- (let* ((current-time (SDL:get-ticks))
- (dt (- current-time previous-time)))
- (process-events)
- (let ((lag (update (+ lag dt))))
- (draw dt (alpha lag))
- (game-loop current-time lag)))))
-
-;;;
-;;; State management
-;;;
-
-(define (game-running?)
- (or (eq? (game-loop-status) 'running)
- (eq? (game-loop-status) 'paused)))
-
-(define (game-paused?)
- (eq? (game-loop-status) 'paused))
-
-(define (pause-game)
- "Pauses the game loop. Useful when developing."
- (game-loop-status 'paused))
-
-(define (resume-game)
- "Resumes the game loop."
- (when (game-paused?)
- (game-loop-status 'running)))
+ (let* ((current-time (SDL:get-ticks))
+ (dt (- current-time previous-time)))
+ (process-events)
+ (let ((lag (update (+ lag dt))))
+ (draw dt (alpha lag))
+ (game-loop current-time lag))))
(define (quit-game)
- "Finish the current frame and terminate the game loop."
- (game-loop-status 'stopped))
+ (abort-to-prompt 'game-loop-prompt #f))