summaryrefslogtreecommitdiff
path: root/starling
diff options
context:
space:
mode:
authorDavid Thompson <dthompson@vistahigherlearning.com>2020-09-29 20:00:24 -0400
committerDavid Thompson <dthompson@vistahigherlearning.com>2020-09-29 20:04:20 -0400
commitf4e7322d392242898bddeccde0601e63af5ca737 (patch)
tree3f9a314040154a95e13c93fe7b9c1446f70e2b18 /starling
parent7116fee18e27064d29030848e28cc1f3a45ab961 (diff)
node: Allow nodes to have no name.
Diffstat (limited to 'starling')
-rw-r--r--starling/node.scm14
1 files changed, 9 insertions, 5 deletions
diff --git a/starling/node.scm b/starling/node.scm
index 947d1cb..38b75da 100644
--- a/starling/node.scm
+++ b/starling/node.scm
@@ -61,7 +61,7 @@
(define-class <node> ()
;; Symbolic name. Used for easy lookup of children within a parent.
- (name #:accessor name #:init-form (gensym "anonymous-") #:init-keyword #:name)
+ (name #:getter name #:init-form #f #:init-keyword #:name)
;; An integer value that determines priority order for
;; updating/rendering.
(rank #:accessor rank #:init-value 0 #:init-keyword #:rank)
@@ -71,7 +71,7 @@
;; List of children ordered by rank.
(children #:accessor children #:init-form '())
;; Children indexed by name for fast lookup.
- (children-map #:getter children-map #:init-form (make-hash-table))
+ (children-by-name #:getter children-by-name #:init-thunk make-hash-table)
;; Script scheduler.
(agenda #:getter agenda #:init-form (make-agenda))
;; Flips to #t upon first entering a scene.
@@ -199,7 +199,7 @@ represented as a ratio in the range [0, 1]."
(define-method (child-ref (parent <node>) name)
"Return the child node of PARENT whose name is NAME."
- (hashq-ref (children-map parent) name))
+ (hashq-ref (children-by-name parent) name))
(define-syntax &
(syntax-rules ()
@@ -234,7 +234,9 @@ represented as a ratio in the range [0, 1]."
;; index for quick lookup later.
(for-each (lambda (child)
(set! (parent child) new-parent)
- (hashq-set! (children-map new-parent) (name child) child)
+ ;; Add to name index.
+ (when (name child)
+ (hashq-set! (children-by-name new-parent) (name child) child))
;; If the parent is active, that means the new children
;; must also be active.
(when (active? new-parent)
@@ -250,7 +252,9 @@ represented as a ratio in the range [0, 1]."
(let ((p (parent node)))
(when p
(set! (children p) (delq node (children p)))
- (hashq-remove! (children-map p) (name node))
+ ;; Remove from name index.
+ (when (name node)
+ (hashq-remove! (children-by-name p) (name node)))
;; Detaching deactives the node and all of its children.
(when (active? node)
(deactivate node))