# HG changeset patch # User Mike Becker # Date 1708637690 -3600 # Node ID fceda550ebcb75ee9cb5245ab324cc2865a4dad5 # Parent 1d001eb694dcbc329c4c755aac21d30c2f10fa83 apply new CxTreeIterator from ucx 3.1 preview diff -r 1d001eb694dc -r fceda550ebcb src/scene.c --- a/src/scene.c Tue Jan 23 21:34:12 2024 +0100 +++ b/src/scene.c Thu Feb 22 22:34:50 2024 +0100 @@ -32,9 +32,11 @@ #include -#define asc_scene_node_layout \ +#define node_layout_ \ offsetof(AscSceneNode, parent), offsetof(AscSceneNode, children), \ offsetof(AscSceneNode, prev), offsetof(AscSceneNode, next) +#define child_list_off_ \ + offsetof(AscSceneNode, children), offsetof(AscSceneNode, next) void asc_scene_init(AscScene *scene) { if (scene->root != NULL) { @@ -52,23 +54,14 @@ asc_scene_node_link(scene->root, node); } -static void asc_scene_draw_node(AscSceneNode *node) { - if (node->draw_func != NULL) { - node->draw_func(node); - } - if (node->children != NULL) { - asc_scene_draw_node(node->children); +void asc_scene_draw(AscScene const *scene) { + // TODO: don't visit the tree, visit the render groups + CxTreeIterator iter = cx_tree_iterator(scene->root, false, child_list_off_); + cx_foreach(AscSceneNode*, node, iter) { + if (node->draw_func != NULL) { + node->draw_func(node); + } } - if (node->next != NULL) { - asc_scene_draw_node(node->next); - } -} - -void asc_scene_draw(AscScene const *scene) { - // TODO: replace with UCX tree visitor - // TODO: don't visit the tree, visit the render groups - // TODO: avoid recursion - asc_scene_draw_node(scene->root); } AscSceneNode *asc_scene_node_empty(void) { @@ -100,9 +93,9 @@ } void asc_scene_node_link(AscSceneNode * restrict parent, AscSceneNode * restrict node) { - cx_tree_link(parent, node, asc_scene_node_layout); + cx_tree_link(parent, node, node_layout_); } void asc_scene_node_unlink(AscSceneNode *node) { - cx_tree_unlink(node, asc_scene_node_layout); + cx_tree_unlink(node, node_layout_); } \ No newline at end of file