src/behavior.c

changeset 286
26a41832c81d
parent 279
97a1a7fb4f1a
--- a/src/behavior.c	Thu Nov 13 22:09:53 2025 +0100
+++ b/src/behavior.c	Sun Nov 16 21:12:20 2025 +0100
@@ -31,7 +31,7 @@
 #include "ascension/util.h"
 #include "ascension/error.h"
 
-#include <cx/kv_list.h>
+#include <cx/linked_list.h>
 #include <cx/tree.h>
 
 #include <assert.h>
@@ -45,20 +45,17 @@
     }
 }
 
-static CxMap *asc_behavior_new_map(void) {
-    CxMap *map = cxKvListCreateAsMapSimple(sizeof(AscBehavior));
-    cxDefineDestructor(map, asc_behavior_destroy);
-    return map;
+static CxList *asc_behavior_new_list(void) {
+    CxList *list = cxLinkedListCreateSimple(sizeof(AscBehavior));
+    cxDefineDestructor(list, asc_behavior_destroy);
+    return list;
 }
 
 AscBehavior *asc_behavior_add_(AscSceneNode *node, struct asc_behavior_create_args args) {
     if (node->behaviors == NULL) {
-        node->behaviors = asc_behavior_new_map();
+        node->behaviors = asc_behavior_new_list();
     }
-    cxmutstr name = args.name == NULL
-        ? asc_util_gen_name("behavior")
-        : cx_mutstr(strdup(args.name));
-    AscBehavior *behavior = cxMapEmplace(node->behaviors, name);
+    AscBehavior *behavior = cxListEmplace(node->behaviors);
     assert(behavior != NULL);
     behavior->enabled = !args.start_disabled;
     behavior->always_enabled = args.always_enabled;
@@ -71,7 +68,9 @@
     behavior->interval = args.interval;
     behavior->last_execution = 0;
     behavior->disable_while_hidden = args.disable_while_hidden;
-    behavior->name = name;
+    behavior->name = args.name == NULL
+        ? asc_util_gen_name("behavior")
+        : cx_mutstr(strdup(args.name));
     asc_dprintf("Create behavior: %"CX_PRIstr, CX_SFMT(behavior->name));
     return behavior;
 }
@@ -92,7 +91,7 @@
     if (behavior->last_execution + behavior->interval > asc_context.total_nanos) {
         return;
     }
-    // the behavior is disable while the node is hidden
+    // the behavior is disabled while the node is hidden
     if (!behavior->always_enabled && behavior->disable_while_hidden && asc_scene_node_is_hidden(behavior->node)) {
         behavior->reactivated = true;
         return;
@@ -103,38 +102,29 @@
     behavior->last_execution = asc_context.total_nanos;
 }
 
-cxstring asc_behavior_get_name(const AscBehavior *behavior) {
-    assert(behavior != NULL);
-    return cx_strcast(behavior->name);
-}
-
-AscBehavior *asc_behavior_find_(const AscSceneNode *node, cxstring name) {
-    return cxMapGet(node->behaviors, name);
-}
-
 void asc_behavior_enable_all(AscSceneNode *node) {
-    CxMapIterator iter = cxMapIteratorValues(node->behaviors);
+    CxIterator iter = cxListIterator(node->behaviors);
     cx_foreach(AscBehavior*, behavior, iter) {
         asc_behavior_enable(behavior);
     }
 }
 
 void asc_behavior_disable_all(AscSceneNode *node) {
-    CxMapIterator iter = cxMapIteratorValues(node->behaviors);
+    CxIterator iter = cxListIterator(node->behaviors);
     cx_foreach(AscBehavior*, behavior, iter) {
         asc_behavior_disable(behavior);
     }
 }
 
 void asc_behavior_disable_all_while_hidden(AscSceneNode *node) {
-    CxMapIterator iter = cxMapIteratorValues(node->behaviors);
+    CxIterator iter = cxListIterator(node->behaviors);
     cx_foreach(AscBehavior*, behavior, iter) {
         asc_behavior_disable_while_hidden(behavior);
     }
 }
 
 void asc_behavior_enable_all_while_hidden(AscSceneNode *node) {
-    CxMapIterator iter = cxMapIteratorValues(node->behaviors);
+    CxIterator iter = cxListIterator(node->behaviors);
     cx_foreach(AscBehavior*, behavior, iter) {
         asc_behavior_enable_while_hidden(behavior);
     }

mercurial