From f4e7322d392242898bddeccde0601e63af5ca737 Mon Sep 17 00:00:00 2001 From: David Thompson Date: Tue, 29 Sep 2020 20:00:24 -0400 Subject: node: Allow nodes to have no name. --- starling/node.scm | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) (limited to 'starling/node.scm') 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 () ;; 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 ) 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)) -- cgit v1.2.3