summaryrefslogtreecommitdiff
path: root/2d
diff options
context:
space:
mode:
authorDavid Thompson <dthompson2@worcester.edu>2014-01-07 21:42:34 -0500
committerDavid Thompson <dthompson2@worcester.edu>2014-01-07 21:42:34 -0500
commitb830d683cd4ecd7953a6b2b6ad455f1ee7ab5472 (patch)
tree1d2d78379cf6baae90b054f9f73957492c888d00 /2d
parent97a454af3b3f9a713e14b6e1463bf300999bdcea (diff)
Add draw-hook.
* 2d/game.scm (run-game, run-game-loop): Rename and remove draw callback parameter. (draw-hook): New hook. (draw): Run draw hook.
Diffstat (limited to '2d')
-rw-r--r--2d/game.scm19
1 files changed, 6 insertions, 13 deletions
diff --git a/2d/game.scm b/2d/game.scm
index 7c618aa..3e1f982 100644
--- a/2d/game.scm
+++ b/2d/game.scm
@@ -34,8 +34,8 @@
#:use-module (2d repl repl)
#:use-module (2d signals)
#:use-module (2d vector2)
- #:export (game-draw
- run-game
+ #:export (draw-hook
+ run-game-loop
quit-game
pause-game
resume-game
@@ -48,25 +48,19 @@
;;; Game Loop
;;;
-(define (default-draw)
- #f)
-
;; Possible states are:
;; * stopped
;; * running
;; * paused
(define %state 'stopped)
-(define %draw #f)
-(define game-draw (make-root-signal 0))
;; TODO: Make this configurable
(define ticks-per-second 60)
(define tick-interval (floor (/ 1000 ticks-per-second)))
+(define draw-hook (make-hook))
-(define* (run-game #:optional #:key
- (draw default-draw))
+(define (run-game-loop)
"Start the game loop."
(set! %state 'running)
- (set! %draw draw)
(resume-game)
(spawn-server)
(game-loop (SDL:get-ticks) 0))
@@ -76,8 +70,7 @@
(set-gl-matrix-mode (matrix-mode modelview))
(gl-load-identity)
(gl-clear (clear-buffer-mask color-buffer depth-buffer))
- (signal-set! game-draw alpha)
- (%draw)
+ (run-hook draw-hook)
(SDL:gl-swap-buffers)
(accumulate-fps! dt))
@@ -88,7 +81,7 @@ is the unused accumulator time."
(if (>= accumulator tick-interval)
(begin
(handle-events)
- (update-agenda)
+ (tick-agenda!)
(update (- accumulator tick-interval)))
accumulator))