Thu, 22 Feb 2024 22:34:50 +0100
apply new CxTreeIterator from ucx 3.1 preview
src/scene.c | file | annotate | diff | comparison | revisions |
1.1 --- a/src/scene.c Tue Jan 23 21:34:12 2024 +0100 1.2 +++ b/src/scene.c Thu Feb 22 22:34:50 2024 +0100 1.3 @@ -32,9 +32,11 @@ 1.4 1.5 #include <assert.h> 1.6 1.7 -#define asc_scene_node_layout \ 1.8 +#define node_layout_ \ 1.9 offsetof(AscSceneNode, parent), offsetof(AscSceneNode, children), \ 1.10 offsetof(AscSceneNode, prev), offsetof(AscSceneNode, next) 1.11 +#define child_list_off_ \ 1.12 + offsetof(AscSceneNode, children), offsetof(AscSceneNode, next) 1.13 1.14 void asc_scene_init(AscScene *scene) { 1.15 if (scene->root != NULL) { 1.16 @@ -52,23 +54,14 @@ 1.17 asc_scene_node_link(scene->root, node); 1.18 } 1.19 1.20 -static void asc_scene_draw_node(AscSceneNode *node) { 1.21 - if (node->draw_func != NULL) { 1.22 - node->draw_func(node); 1.23 +void asc_scene_draw(AscScene const *scene) { 1.24 + // TODO: don't visit the tree, visit the render groups 1.25 + CxTreeIterator iter = cx_tree_iterator(scene->root, false, child_list_off_); 1.26 + cx_foreach(AscSceneNode*, node, iter) { 1.27 + if (node->draw_func != NULL) { 1.28 + node->draw_func(node); 1.29 + } 1.30 } 1.31 - if (node->children != NULL) { 1.32 - asc_scene_draw_node(node->children); 1.33 - } 1.34 - if (node->next != NULL) { 1.35 - asc_scene_draw_node(node->next); 1.36 - } 1.37 -} 1.38 - 1.39 -void asc_scene_draw(AscScene const *scene) { 1.40 - // TODO: replace with UCX tree visitor 1.41 - // TODO: don't visit the tree, visit the render groups 1.42 - // TODO: avoid recursion 1.43 - asc_scene_draw_node(scene->root); 1.44 } 1.45 1.46 AscSceneNode *asc_scene_node_empty(void) { 1.47 @@ -100,9 +93,9 @@ 1.48 } 1.49 1.50 void asc_scene_node_link(AscSceneNode * restrict parent, AscSceneNode * restrict node) { 1.51 - cx_tree_link(parent, node, asc_scene_node_layout); 1.52 + cx_tree_link(parent, node, node_layout_); 1.53 } 1.54 1.55 void asc_scene_node_unlink(AscSceneNode *node) { 1.56 - cx_tree_unlink(node, asc_scene_node_layout); 1.57 + cx_tree_unlink(node, node_layout_); 1.58 } 1.59 \ No newline at end of file