Sun, 16 Nov 2025 21:12:20 +0100
behaviors do not need names
| src/ascension/behavior.h | file | annotate | diff | comparison | revisions | |
| src/ascension/scene_node.h | file | annotate | diff | comparison | revisions | |
| src/behavior.c | file | annotate | diff | comparison | revisions | |
| src/scene.c | file | annotate | diff | comparison | revisions | |
| src/scene_node.c | file | annotate | diff | comparison | revisions |
--- a/src/ascension/behavior.h Thu Nov 13 22:09:53 2025 +0100 +++ b/src/ascension/behavior.h Sun Nov 16 21:12:20 2025 +0100 @@ -119,25 +119,6 @@ void asc_behavior_trigger(AscBehavior *behavior); /** - * Returns the name of a behavior. - * - * @param behavior the behavior - * @return the name of the behavior - */ -cxstring asc_behavior_get_name(const AscBehavior *behavior); - -AscBehavior *asc_behavior_find_(const AscSceneNode *node, cxstring name); - -/** - * Finds a behavior with the specified name. - * - * @param node the node with the expected behavior - * @param name the name of the behavior - * @return the behavior or @c NULL when the node has no behavior with that name - */ -#define asc_behavior_find(node, name) asc_behavior_find_(node, cx_strcast(name)) - -/** * Enables a behavior * * Has no effect on killed behaviors.
--- a/src/ascension/scene_node.h Thu Nov 13 22:09:53 2025 +0100 +++ b/src/ascension/scene_node.h Sun Nov 16 21:12:20 2025 +0100 @@ -58,10 +58,9 @@ AscSceneNode *last_child; cxmutstr name; /** - * Maps name → AscBehavior. - * Not a pointer map! + * List of AscBehavior structs. */ - CxMap *behaviors; + CxList *behaviors; asc_scene_node_destroy_func destroy_func; asc_scene_node_update_func update_func; asc_scene_node_draw_func draw_func;
--- 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); }
--- a/src/scene.c Thu Nov 13 22:09:53 2025 +0100 +++ b/src/scene.c Sun Nov 16 21:12:20 2025 +0100 @@ -73,7 +73,7 @@ offsetof(AscSceneNode, next) ); cx_foreach(AscSceneNode*, node, iter) { - CxMapIterator behavior_iter = cxMapIteratorValues(node->behaviors); + CxIterator behavior_iter = cxListIterator(node->behaviors); cx_foreach(AscBehavior*, behavior, behavior_iter) { asc_behavior_trigger(behavior); if (behavior->killed) {
--- a/src/scene_node.c Thu Nov 13 22:09:53 2025 +0100 +++ b/src/scene_node.c Sun Nov 16 21:12:20 2025 +0100 @@ -53,7 +53,7 @@ } static void asc_scene_node_destroy(AscSceneNode *node) { - cxMapFree(node->behaviors); + cxListFree(node->behaviors); if (node->user_data_free_func != NULL) { node->user_data_free_func((void*)node->user_data_allocator, node->user_data); }