From b345d228b38cf6d3b5206327d63fe969adc42811 Mon Sep 17 00:00:00 2001 From: David Thompson Date: Tue, 28 Aug 2018 09:00:16 -0400 Subject: node: Add visible? flag. --- starling/node-2d.scm | 41 +++++++++++++++++++++-------------------- starling/node.scm | 24 +++++++++++++++++++----- 2 files changed, 40 insertions(+), 25 deletions(-) diff --git a/starling/node-2d.scm b/starling/node-2d.scm index a0b2746..368e8a2 100644 --- a/starling/node-2d.scm +++ b/starling/node-2d.scm @@ -314,26 +314,27 @@ (next-method)) (define-method (render* (node ) alpha) - ;; Compute the linearly interpolated rendering position, in the case - ;; that node has moved since the last update. - (let ((p (position node)) - (lp (last-position node)) - (rp (render-position node)) - (beta (- 1.0 alpha))) - (unless (and (= (vec2-x lp) (vec2-x rp)) - (= (vec2-y lp) (vec2-y rp))) - (set-vec2-x! rp (+ (* (vec2-x p) alpha) (* (vec2-x lp) beta))) - (set-vec2-y! rp (+ (* (vec2-y p) alpha) (* (vec2-y lp) beta))) - (set! (dirty-matrix? node) #t))) - ;; Recompute dirty matrices. - (when (dirty-matrix? node) - (compute-matrices! node) - (set! (dirty-matrix? node) #f) - ;; If the parent is dirty, all the children need to be marked as - ;; dirty, too. - (for-each (lambda (node) - (set! (dirty-matrix? node) #t)) - (children node))) + (when (visible? node) + ;; Compute the linearly interpolated rendering position, in the case + ;; that node has moved since the last update. + (let ((p (position node)) + (lp (last-position node)) + (rp (render-position node)) + (beta (- 1.0 alpha))) + (unless (and (= (vec2-x lp) (vec2-x rp)) + (= (vec2-y lp) (vec2-y rp))) + (set-vec2-x! rp (+ (* (vec2-x p) alpha) (* (vec2-x lp) beta))) + (set-vec2-y! rp (+ (* (vec2-y p) alpha) (* (vec2-y lp) beta))) + (set! (dirty-matrix? node) #t))) + ;; Recompute dirty matrices. + (when (dirty-matrix? node) + (compute-matrices! node) + (set! (dirty-matrix? node) #f) + ;; If the parent is dirty, all the children need to be marked as + ;; dirty, too. + (for-each (lambda (node) + (set! (dirty-matrix? node) #t)) + (children node)))) (next-method)) (define-method (activate (node )) diff --git a/starling/node.scm b/starling/node.scm index 4ce46dd..51866d2 100644 --- a/starling/node.scm +++ b/starling/node.scm @@ -31,11 +31,14 @@ agenda booted? active? + visible? on-boot on-enter on-exit activate deactivate + show + hide update update* render @@ -63,7 +66,10 @@ ;; Flips to #t upon first entering a scene. (booted? #:accessor booted? #:init-form #f) ;; Flips to #t when node is part of current scene. - (active? #:accessor active? #:init-form #f)) + (active? #:accessor active? #:init-form #f) + ;; Determines whether or not the node and all of its children are + ;; rendered. + (visible? #:accessor visible? #:init-form #t #:init-keyword #:visible?)) (define (for-each-child proc node) (for-each proc (children node))) @@ -97,8 +103,9 @@ the next update represented as a ratio in the range [0, 1]." "Render NODE and all of its children, recursively. ALPHA is the distance between the previous update and the next update represented as a ratio in the range [0, 1]." - (render node alpha) - (for-each-child (lambda (child) (render* child alpha)) node)) + (when (visible? node) + (render node alpha) + (for-each-child (lambda (child) (render* child alpha)) node))) (define-method (on-boot (node )) "Perform initialization tasks for NODE." @@ -136,8 +143,15 @@ represented as a ratio in the range [0, 1]." (with-agenda (agenda node) (set! (active? node) #f) (on-exit node) - (for-each-child deactivate node) - (reset-agenda))) + (for-each-child deactivate node))) + +(define-method (show (node )) + "Mark NODE as visible." + (set! (visible? node) #t)) + +(define-method (hide (node )) + "Mark NODE as invisible." + (set! (visible? node) #f)) ;;; -- cgit v1.2.3