1.1 --- a/src/scene.c Fri Apr 12 22:23:31 2024 +0200 1.2 +++ b/src/scene.c Fri Apr 12 22:43:00 2024 +0200 1.3 @@ -28,6 +28,7 @@ 1.4 #include "ascension/scene.h" 1.5 1.6 #include "ascension/context.h" 1.7 +#include "ascension/utils.h" 1.8 1.9 #include <cx/linked_list.h> 1.10 #include <cx/array_list.h> 1.11 @@ -84,7 +85,7 @@ 1.12 node->depth = iter.depth; 1.13 1.14 // skip hidden nodes (and all their children) 1.15 - if (node->hidden) { 1.16 + if (asc_test_flag(node->flags, ASC_SCENE_NODE_HIDDEN)) { 1.17 cxTreeVisitorContinue(iter); 1.18 } 1.19 1.20 @@ -97,16 +98,15 @@ 1.21 } 1.22 1.23 // TODO: implement culling 1.24 - // TODO: implement a hidden flag (requires UCX tree-continue function) 1.25 1.26 // check if geometry needs update 1.27 - if (node->need_graphics_update) { 1.28 + if (asc_test_flag(node->flags, ASC_SCENE_NODE_UPDATE_GRAPHICS)) { 1.29 assert(node->update_func != NULL); 1.30 - node->need_graphics_update = false; 1.31 + asc_clear_flag(node->flags, ASC_SCENE_NODE_UPDATE_GRAPHICS); 1.32 node->update_func(node); 1.33 } 1.34 - if (node->need_transform_update) { 1.35 - node->need_transform_update = false; 1.36 + if (asc_test_flag(node->flags, ASC_SCENE_NODE_UPDATE_TRANSFORM)) { 1.37 + asc_test_flag(node->flags, ASC_SCENE_NODE_UPDATE_TRANSFORM); 1.38 asc_transform_from_parts( 1.39 node->transform, 1.40 node->position, 1.41 @@ -242,12 +242,21 @@ 1.42 } 1.43 } 1.44 1.45 -void asc_update_transform(AscSceneNode *node) { 1.46 - if (node->need_transform_update) return; 1.47 +void asc_node_update(AscSceneNode *node) { 1.48 + asc_set_flag(node->flags, ASC_SCENE_NODE_UPDATE_GRAPHICS); 1.49 +} 1.50 + 1.51 +void asc_node_update_transform(AscSceneNode *node) { 1.52 + // fast skip if node is already marked 1.53 + if (asc_test_flag(node->flags, ASC_SCENE_NODE_UPDATE_TRANSFORM)) { 1.54 + return; 1.55 + } 1.56 1.57 CxTreeIterator iter = asc_scene_node_iterator(node, false); 1.58 cx_foreach(AscSceneNode*, n, iter) { 1.59 - // TODO: break/continue when subtree is already marked for update 1.60 - n->need_transform_update = true; 1.61 + if (asc_test_flag(n->flags, ASC_SCENE_NODE_UPDATE_TRANSFORM)) { 1.62 + cxTreeIteratorContinue(iter); 1.63 + } 1.64 + asc_set_flag(n->flags, ASC_SCENE_NODE_UPDATE_TRANSFORM); 1.65 } 1.66 }