summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid Thompson <dthompson2@worcester.edu>2018-08-21 10:45:35 -0400
committerDavid Thompson <dthompson2@worcester.edu>2018-08-23 08:02:20 -0400
commit0e67d24f8d155e0a0864a0083fb9f8e622f95ee6 (patch)
tree4c9859c10a5c714c19879c94976e00ae8cf196f8
parente61e1f84c10934221154d312cc47758be2e90133 (diff)
Add default game loop error handler.
* chickadee.scm (default-error-handler): New procedure. (run-game): Set default value for 'error' arg to 'default-error-handler'. * chickadee/sdl.scm (run-game/sdl): Ditto.
-rw-r--r--chickadee.scm14
-rw-r--r--chickadee/sdl.scm2
2 files changed, 11 insertions, 5 deletions
diff --git a/chickadee.scm b/chickadee.scm
index 09212fe..4176b5d 100644
--- a/chickadee.scm
+++ b/chickadee.scm
@@ -16,7 +16,8 @@
;;; <http://www.gnu.org/licenses/>.
(define-module (chickadee)
- #:export (run-game
+ #:export (default-error-handler
+ run-game
abort-game))
@@ -43,11 +44,14 @@
(set! stack (make-stack #t 3))))))
(define-syntax-rule (with-error-handling handler body ...)
- (call-with-error-handling handler (lambda () body ...)))
+ (call-with-error-handling handler (lambda () body ...)))
+
+(define (default-error-handler stack key args)
+ (apply throw key args))
;;;
-;;; Game loop core
+;;; Game loop kernel
;;;
(define game-loop-prompt-tag (make-prompt-tag 'game-loop))
@@ -55,7 +59,9 @@
(define (abort-game)
(abort-to-prompt game-loop-prompt-tag #f))
-(define* (run-game #:key update render time error (update-hz 60))
+(define* (run-game #:key update render time
+ (error default-error-handler)
+ (update-hz 60))
(let ((timestep (round (/ 1000 update-hz))))
(call-with-prompt game-loop-prompt-tag
(lambda ()
diff --git a/chickadee/sdl.scm b/chickadee/sdl.scm
index bb8d5e3..b00e30e 100644
--- a/chickadee/sdl.scm
+++ b/chickadee/sdl.scm
@@ -85,7 +85,7 @@
(controller-press (const #t))
(controller-release (const #t))
(controller-move (const #t))
- (error (const #t)))
+ (error default-error-handler))
(sdl-init)
(false-if-exception (mixer-init))
(open-audio)