summaryrefslogtreecommitdiff
path: root/2d
diff options
context:
space:
mode:
authorDavid Thompson <dthompson2@worcester.edu>2013-12-15 20:58:43 -0500
committerDavid Thompson <dthompson2@worcester.edu>2013-12-15 20:58:43 -0500
commitb4d1d462da6f4d0d5ff271df3d9c4e0de6eed6d1 (patch)
treeb3fdd1f7161fc44c9272ae7bbf657c9845ef882c /2d
parent70a7ea2c3aaaf7492de172177513351c8b90d3b5 (diff)
Restructure game callbacks and signals.
* 2d/game.scm (game-draw): Add signal. (run-game): Remove update callback. (draw): Use alpha value. (update): Remove call to obsolete update callback. (update-and-render): Pass alpha value.
Diffstat (limited to '2d')
-rw-r--r--2d/game.scm18
1 files changed, 7 insertions, 11 deletions
diff --git a/2d/game.scm b/2d/game.scm
index f1b5f79..7c618aa 100644
--- a/2d/game.scm
+++ b/2d/game.scm
@@ -34,7 +34,8 @@
#:use-module (2d repl repl)
#:use-module (2d signals)
#:use-module (2d vector2)
- #:export (run-game
+ #:export (game-draw
+ run-game
quit-game
pause-game
resume-game
@@ -50,36 +51,32 @@
(define (default-draw)
#f)
-(define (default-update)
- #f)
-
;; Possible states are:
;; * stopped
;; * running
;; * paused
(define %state 'stopped)
(define %draw #f)
-(define %update #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* (run-game #:optional #:key
- (draw default-draw)
- (update default-update))
+ (draw default-draw))
"Start the game loop."
(set! %state 'running)
(set! %draw draw)
- (set! %update update)
(resume-game)
(spawn-server)
(game-loop (SDL:get-ticks) 0))
-(define (draw dt)
+(define (draw dt alpha)
"Render a frame."
(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)
(SDL:gl-swap-buffers)
(accumulate-fps! dt))
@@ -92,14 +89,13 @@ is the unused accumulator time."
(begin
(handle-events)
(update-agenda)
- (%update)
(update (- accumulator tick-interval)))
accumulator))
(define (update-and-render dt accumulator)
(let ((remainder (update accumulator)))
(run-repl)
- (draw dt)
+ (draw dt (/ remainder tick-interval))
remainder))
(define (tick dt accumulator)