diff options
author | David Thompson <dthompson2@worcester.edu> | 2023-04-18 07:44:23 -0400 |
---|---|---|
committer | David Thompson <dthompson2@worcester.edu> | 2023-04-18 07:44:23 -0400 |
commit | c6c63425f42a44e483b8676f562fa960e59c8777 (patch) | |
tree | 66ccfc07a1c123fc7618e6b42b35ebefdb669ca3 | |
parent | b593d7fa1a3d918bf0ba69d6c98bfd38f9152106 (diff) |
region: Use pushdown state.
-rw-r--r-- | catbird/region.scm | 31 |
1 files changed, 20 insertions, 11 deletions
diff --git a/catbird/region.scm b/catbird/region.scm index f1cc306..f42532a 100644 --- a/catbird/region.scm +++ b/catbird/region.scm @@ -25,6 +25,7 @@ #:use-module (catbird config) #:use-module (catbird mixins) #:use-module (catbird node) + #:use-module (catbird pushdown) #:use-module (catbird scene) #:use-module (chickadee) #:use-module (chickadee data array-list) @@ -53,8 +54,7 @@ (define-root-class <region> (<renderable> <updatable> <nameable> <rankable>) (area #:accessor area #:init-keyword #:area) (camera #:accessor camera #:init-keyword #:camera #:init-value #f) - (scene #:accessor scene #:init-keyword #:scene #:init-value #f) - (scene-stack #:getter scene-stack #:init-thunk make-array-list) + (scene-state #:accessor scene-state #:init-thunk make-pushdown-state) (viewport #:accessor viewport)) (define-method (area-x (region <region>)) @@ -99,23 +99,32 @@ (make-exception-with-message "region area exceeds window area"))) (make <region> #:area area #:name name #:rank rank))) -(define-method (replace-scene (r <region>) (new-scene <scene>)) - (let ((old-scene (scene r))) +(define-method (scene (region <region>)) + (state-current (scene-state region))) + +(define-method (replace-scene (region <region>) (new-scene <scene>)) + (let ((old-scene (scene region))) (when old-scene (on-exit old-scene)) - (set! (scene r) new-scene) - (set! (regions new-scene) (cons r (regions new-scene))) + (state-push! (scene-state region) new-scene) + (set! (regions new-scene) (cons region (regions new-scene))) (on-enter new-scene))) (define-method (push-scene (region <region>) (new-scene <scene>)) (let ((old-scene (scene region))) (when old-scene - (array-list-push! (scene-stack region) old-scene)) - (replace-scene region new-scene))) + (on-exit old-scene)) + (state-push! (scene-state region)) + (set! (regions new-scene) (cons region (regions new-scene))) + (on-enter new-scene))) (define-method (pop-scene (region <region>)) - (let ((stack (scene-stack region))) - (unless (array-list-empty? stack) - (replace-scene (array-list-pop! stack))))) + (let ((old-scene (state-pop! (scene-state region)))) + (on-exit old-scene) + (set! (regions old-scene) + (delq region (regions old-scene)))) + (let ((restored-scene (scene region))) + (when restored-scene + (on-enter restored-scene)))) (define-method (update (region <region>) dt) (let ((s (scene region))) |