merge different bools of AscSceneNode into flags

Fri, 12 Apr 2024 22:43:00 +0200

author
Mike Becker <universe@uap-core.de>
date
Fri, 12 Apr 2024 22:43:00 +0200
changeset 61
b7954818a6b7
parent 60
3954c551ded3
child 62
5a592625e2f9

merge different bools of AscSceneNode into flags

src/Makefile file | annotate | diff | comparison | revisions
src/ascension/scene.h file | annotate | diff | comparison | revisions
src/ascension/utils.h file | annotate | diff | comparison | revisions
src/scene.c file | annotate | diff | comparison | revisions
test/Makefile file | annotate | diff | comparison | revisions
     1.1 --- a/src/Makefile	Fri Apr 12 22:23:31 2024 +0200
     1.2 +++ b/src/Makefile	Fri Apr 12 22:43:00 2024 +0200
     1.3 @@ -91,7 +91,7 @@
     1.4   ascension/transform.h ascension/camera.h ascension/context.h \
     1.5   ascension/window.h ascension/glcontext.h ascension/primitives.h \
     1.6   ascension/mesh.h ascension/shader.h ascension/scene.h \
     1.7 - ascension/ui/font.h ascension/shader.h
     1.8 + ascension/ui/font.h ascension/utils.h ascension/shader.h
     1.9  	@echo "Compiling $<"
    1.10  	$(CC) -o $@ $(CFLAGS) -c $<
    1.11  
    1.12 @@ -103,10 +103,11 @@
    1.13  $(BUILD_DIR)/text.o: text.c ascension/ui/text.h ascension/ui/font.h \
    1.14   ascension/ui/../scene.h ascension/ui/../datatypes.h \
    1.15   ascension/ui/../transform.h ascension/ui/../camera.h \
    1.16 - ascension/ui/../texture.h ascension/context.h ascension/datatypes.h \
    1.17 - ascension/window.h ascension/glcontext.h ascension/primitives.h \
    1.18 - ascension/mesh.h ascension/shader.h ascension/scene.h \
    1.19 - ascension/ui/font.h ascension/error.h ascension/shader.h
    1.20 + ascension/ui/../texture.h ascension/ui/../utils.h ascension/context.h \
    1.21 + ascension/datatypes.h ascension/window.h ascension/glcontext.h \
    1.22 + ascension/primitives.h ascension/mesh.h ascension/shader.h \
    1.23 + ascension/scene.h ascension/ui/font.h ascension/error.h \
    1.24 + ascension/shader.h
    1.25  	@echo "Compiling $<"
    1.26  	$(CC) -o $@ $(CFLAGS) -c $<
    1.27  
     2.1 --- a/src/ascension/scene.h	Fri Apr 12 22:23:31 2024 +0200
     2.2 +++ b/src/ascension/scene.h	Fri Apr 12 22:43:00 2024 +0200
     2.3 @@ -62,9 +62,6 @@
     2.4      asc_transform transform;
     2.5      asc_transform world_transform;
     2.6      enum AscRenderGroup render_group;
     2.7 -    bool hidden;
     2.8 -    bool need_graphics_update;
     2.9 -    bool need_transform_update;
    2.10      /**
    2.11       * Custom flags for this node.
    2.12       * The #ASC_SCENE_NODE_FLAGS_MASK bits are reserved for general flags.
    2.13 @@ -72,7 +69,10 @@
    2.14      uint32_t flags;
    2.15  };
    2.16  
    2.17 -#define ASC_SCENE_NODE_FLAGS_MASK 0xFF000000
    2.18 +#define ASC_SCENE_NODE_FLAGS_MASK       0xFF000000
    2.19 +#define ASC_SCENE_NODE_UPDATE_GRAPHICS  0x01000000
    2.20 +#define ASC_SCENE_NODE_UPDATE_TRANSFORM 0x02000000
    2.21 +#define ASC_SCENE_NODE_HIDDEN           0x80000000
    2.22  
    2.23  /**
    2.24   * Place this as first member of a structure that shall be used as a scene node.
    2.25 @@ -161,12 +161,11 @@
    2.26          asc_scene_update_func behavior
    2.27  );
    2.28  
    2.29 -#define asc_node_update(node) \
    2.30 -    ((AscSceneNode*)node)->need_graphics_update = true
    2.31 -
    2.32 +__attribute__((__nonnull__))
    2.33 +void asc_node_update(AscSceneNode *node);
    2.34  
    2.35  __attribute__((__nonnull__))
    2.36 -void asc_update_transform(AscSceneNode *node);
    2.37 +void asc_node_update_transform(AscSceneNode *node);
    2.38  
    2.39  
    2.40  __attribute__((__nonnull__)) static inline
    2.41 @@ -174,7 +173,7 @@
    2.42      node->position.x = x;
    2.43      node->position.y = y;
    2.44      node->position.z = z;
    2.45 -    asc_update_transform(node);
    2.46 +    asc_node_update_transform(node);
    2.47  }
    2.48  
    2.49  __attribute__((__nonnull__)) static inline
    2.50 @@ -182,7 +181,7 @@
    2.51      node->position.x = (float)x;
    2.52      node->position.y = (float)y;
    2.53      node->position.z = 0.f;
    2.54 -    asc_update_transform(node);
    2.55 +    asc_node_update_transform(node);
    2.56  }
    2.57  
    2.58  __attribute__((__nonnull__)) static inline
    2.59 @@ -195,7 +194,7 @@
    2.60      node->scale.width = width;
    2.61      node->scale.height = height;
    2.62      node->scale.depth = depth;
    2.63 -    asc_update_transform(node);
    2.64 +    asc_node_update_transform(node);
    2.65  }
    2.66  
    2.67  __attribute__((__nonnull__)) static inline
    2.68 @@ -203,7 +202,7 @@
    2.69      node->scale.width = (float)width;
    2.70      node->scale.height = (float)height;
    2.71      node->scale.depth = 1.f;
    2.72 -    asc_update_transform(node);
    2.73 +    asc_node_update_transform(node);
    2.74  }
    2.75  
    2.76  __attribute__((__nonnull__)) static inline
     3.1 --- a/src/ascension/utils.h	Fri Apr 12 22:23:31 2024 +0200
     3.2 +++ b/src/ascension/utils.h	Fri Apr 12 22:43:00 2024 +0200
     3.3 @@ -32,9 +32,9 @@
     3.4  
     3.5  #define asc_test_flag(reg, flag) ((reg & flag) == flag)
     3.6  #define asc_test_flag_masked(reg, mask, flag) ((reg & mask) == flag)
     3.7 -#define asc_clear_flag(reg, flag) (reg &= ~flag)
     3.8 +#define asc_clear_flag(reg, flag) (reg &= ~(flag))
     3.9  #define asc_set_flag(reg, flag) (reg |= flag)
    3.10 -#define asc_set_flag_masked(reg, mask, flag) (reg = (reg & ~mask) | flag)
    3.11 +#define asc_set_flag_masked(reg, mask, flag) (reg = (reg & ~(mask)) | flag)
    3.12  
    3.13  #endif /* ASCENSION_UTILS_H */
    3.14  
     4.1 --- a/src/scene.c	Fri Apr 12 22:23:31 2024 +0200
     4.2 +++ b/src/scene.c	Fri Apr 12 22:43:00 2024 +0200
     4.3 @@ -28,6 +28,7 @@
     4.4  #include "ascension/scene.h"
     4.5  
     4.6  #include "ascension/context.h"
     4.7 +#include "ascension/utils.h"
     4.8  
     4.9  #include <cx/linked_list.h>
    4.10  #include <cx/array_list.h>
    4.11 @@ -84,7 +85,7 @@
    4.12          node->depth = iter.depth;
    4.13  
    4.14          // skip hidden nodes (and all their children)
    4.15 -        if (node->hidden) {
    4.16 +        if (asc_test_flag(node->flags, ASC_SCENE_NODE_HIDDEN)) {
    4.17              cxTreeVisitorContinue(iter);
    4.18          }
    4.19  
    4.20 @@ -97,16 +98,15 @@
    4.21          }
    4.22  
    4.23          // TODO: implement culling
    4.24 -        // TODO: implement a hidden flag (requires UCX tree-continue function)
    4.25  
    4.26          // check if geometry needs update
    4.27 -        if (node->need_graphics_update) {
    4.28 +        if (asc_test_flag(node->flags, ASC_SCENE_NODE_UPDATE_GRAPHICS)) {
    4.29              assert(node->update_func != NULL);
    4.30 -            node->need_graphics_update = false;
    4.31 +            asc_clear_flag(node->flags, ASC_SCENE_NODE_UPDATE_GRAPHICS);
    4.32              node->update_func(node);
    4.33          }
    4.34 -        if (node->need_transform_update) {
    4.35 -            node->need_transform_update = false;
    4.36 +        if (asc_test_flag(node->flags, ASC_SCENE_NODE_UPDATE_TRANSFORM)) {
    4.37 +            asc_test_flag(node->flags, ASC_SCENE_NODE_UPDATE_TRANSFORM);
    4.38              asc_transform_from_parts(
    4.39                      node->transform,
    4.40                      node->position,
    4.41 @@ -242,12 +242,21 @@
    4.42      }
    4.43  }
    4.44  
    4.45 -void asc_update_transform(AscSceneNode *node) {
    4.46 -    if (node->need_transform_update) return;
    4.47 +void asc_node_update(AscSceneNode *node) {
    4.48 +    asc_set_flag(node->flags, ASC_SCENE_NODE_UPDATE_GRAPHICS);
    4.49 +}
    4.50 +
    4.51 +void asc_node_update_transform(AscSceneNode *node) {
    4.52 +    // fast skip if node is already marked
    4.53 +    if (asc_test_flag(node->flags, ASC_SCENE_NODE_UPDATE_TRANSFORM)) {
    4.54 +        return;
    4.55 +    }
    4.56  
    4.57      CxTreeIterator iter = asc_scene_node_iterator(node, false);
    4.58      cx_foreach(AscSceneNode*, n, iter) {
    4.59 -        // TODO: break/continue when subtree is already marked for update
    4.60 -        n->need_transform_update = true;
    4.61 +        if (asc_test_flag(n->flags, ASC_SCENE_NODE_UPDATE_TRANSFORM)) {
    4.62 +            cxTreeIteratorContinue(iter);
    4.63 +        }
    4.64 +        asc_set_flag(n->flags, ASC_SCENE_NODE_UPDATE_TRANSFORM);
    4.65      }
    4.66  }
     5.1 --- a/test/Makefile	Fri Apr 12 22:23:31 2024 +0200
     5.2 +++ b/test/Makefile	Fri Apr 12 22:43:00 2024 +0200
     5.3 @@ -50,7 +50,7 @@
     5.4   ../src/ascension/camera.h ../src/ascension/ui/font.h \
     5.5   ../src/ascension/ui.h ../src/ascension/ui/text.h \
     5.6   ../src/ascension/ui/font.h ../src/ascension/ui/../scene.h \
     5.7 - ../src/ascension/ui/../texture.h
     5.8 + ../src/ascension/ui/../texture.h ../src/ascension/ui/../utils.h
     5.9  	@echo "Compiling $<"
    5.10  	$(CC) -o $@ $(CFLAGS) -c $<
    5.11  

mercurial