summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--starling/node.scm28
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