From 49f93e5fe7261dd520a0013508fd02086af6ae17 Mon Sep 17 00:00:00 2001 From: David Thompson Date: Sun, 3 Nov 2013 20:02:44 -0500 Subject: Pass scene state to all observer event handlers. --- 2d/game-loop.scm | 5 +++-- 2d/scene.scm | 4 ++-- 2d/stage.scm | 8 ++++++-- 3 files changed, 11 insertions(+), 6 deletions(-) (limited to '2d') diff --git a/2d/game-loop.scm b/2d/game-loop.scm index a6cd669..a14459e 100644 --- a/2d/game-loop.scm +++ b/2d/game-loop.scm @@ -130,10 +130,11 @@ time in milliseconds that has passed since the last game update." ;; By default, pressing the escape key will pop the current scene, and ;; closing the window will quit the game. -(default-events `((key-down . ,(lambda (key mod unicode) +(default-events `((key-down . ,(lambda (state key mod unicode) (when (eq? key 'escape) (pop-scene)))) - (quit . ,quit-game))) + (quit . ,(lambda (state) + (quit-game))))) (define handle-events (let ((e (SDL:make-event))) diff --git a/2d/scene.scm b/2d/scene.scm index 7415f80..cb053b7 100644 --- a/2d/scene.scm +++ b/2d/scene.scm @@ -89,5 +89,5 @@ SCENE." "Call the update callback for SCENE with STATE." ((scene-update scene) state)) -(define (scene-trigger scene event . args) - (apply observer-trigger (scene-observer scene) event args)) +(define (scene-trigger scene state event . args) + (apply observer-trigger (scene-observer scene) event state args)) diff --git a/2d/stage.scm b/2d/stage.scm index fee18a3..bf966ab 100644 --- a/2d/stage.scm +++ b/2d/stage.scm @@ -87,7 +87,11 @@ (define (stage-trigger stage event . args) (with-agenda (stage-agenda stage) - (apply scene-trigger (stage-scene stage) event args))) + (apply scene-trigger + (stage-scene stage) + (stage-state stage) + event + args))) ;;; ;;; Stage management @@ -116,7 +120,7 @@ present." (exit-stage prev-stage)) (set! stack (cdr stack)) (when (current-stage) - (enter-stage (car stack))))) + (enter-stage (current-stage))))) (define (replace-scene scene) "Replace the current stage with STAGE." -- cgit v1.2.3