diff options
author | David Thompson <dthompson@vistahigherlearning.com> | 2019-06-20 07:52:23 -0400 |
---|---|---|
committer | David Thompson <dthompson@vistahigherlearning.com> | 2019-06-20 07:52:23 -0400 |
commit | 177ffdd7a986208a6ff041b6d7b50c81abc56cf2 (patch) | |
tree | 9ecfe5c26b5ea24305498b84059348524ae26cb0 | |
parent | 1b1fce7c0b21887a45dce29796300bd034c583a8 (diff) |
node: Add pause/resume feature.
-rw-r--r-- | starling/node.scm | 28 |
1 files changed, 20 insertions, 8 deletions
diff --git a/starling/node.scm b/starling/node.scm index dbfc702..ee4fbb8 100644 --- a/starling/node.scm +++ b/starling/node.scm @@ -33,6 +33,7 @@ booted? active? visible? + paused? on-boot on-enter on-exit @@ -40,6 +41,8 @@ deactivate show hide + pause + resume update update-tree render @@ -50,7 +53,8 @@ detach run-script stop-scripts - blink)) + blink) + #:replace (pause)) (define-class <node> () ;; Symbolic name. Used for easy lookup of children within a parent. @@ -74,6 +78,8 @@ ;; Determines whether or not the node and all of its children are ;; rendered. (visible? #:accessor visible? #:init-form #t #:init-keyword #:visible?) + ;; Determines whether or not updates happen. + (paused? #:accessor paused? #:init-form #f #:init-keyword #:paused?) ;; Use redefinable classes when in dev mode. #:metaclass (if developer-mode? <redefinable-class> @@ -94,13 +100,13 @@ (define-method (update-tree (node <node>) dt) "Update NODE and all of its children. DT is the amount of time passed since the last update, in milliseconds." - ;; Update children first, recursively. - (for-each-child (lambda (child) (update-tree child dt)) node) - ;; Update script, then "physics" (or whatever the update method is - ;; doing). - (with-agenda (agenda node) - (update-agenda 1) - (update node dt))) + (unless (paused? node) + ;; Update children first, recursively. + (for-each-child (lambda (child) (update-tree child dt)) node) + ;; Scripts take precedence over the update method. + (with-agenda (agenda node) + (update-agenda 1) + (update node dt)))) (define-method (render (node <node>) alpha) "Render NODE. ALPHA is the distance between the previous update and @@ -161,6 +167,12 @@ represented as a ratio in the range [0, 1]." "Mark NODE as invisible." (set! (visible? node) #f)) +(define-method (pause (node <node>)) + (set! (paused? node) #t)) + +(define-method (resume (node <node>)) + (set! (paused? node) #f)) + ;;; ;;; Child management |