--- a/src/ascension/scene.h Sun Oct 06 19:45:34 2024 +0200 +++ b/src/ascension/scene.h Sun Oct 06 20:49:43 2024 +0200 @@ -34,7 +34,6 @@ #include "texture.h" #include <cx/list.h> -#include <cx/tree.h> typedef struct AscSceneNode AscSceneNode; @@ -47,11 +46,12 @@ ASC_RENDER_GROUP_COUNT }; -typedef CxTree* AscScene; - struct AscSceneNode { - struct cx_tree_node_base_s base; - AscScene scene; + AscSceneNode *parent; + AscSceneNode *prev; + AscSceneNode *next; + AscSceneNode *children; + AscSceneNode *last_child; CxList *behaviors; asc_scene_free_func free_func; asc_scene_update_func update_func; @@ -69,7 +69,6 @@ uint32_t flags; }; -// TODO: move to sprite.h typedef struct AscSprite { AscSceneNode data; AscTexture tex; @@ -101,57 +100,56 @@ #define ASC_SCENE_NODE_HIDDEN 0x80000000 /** - * Draws the specified scene. + * Draws the scene with the specified root node. * - * @param scene the scene graph + * @param root the root node of the scene graph * @param viewport the window viewport the scene shall be drawn to * @param camera the camera to obtain the view and projection matrix from */ __attribute__((__nonnull__)) -void asc_scene_draw(AscScene scene, asc_recti viewport, AscCamera *camera); - -AscScene asc_scene_create(void); -void asc_scene_destroy(AscScene scene); +void asc_scene_draw(AscSceneNode *root, asc_recti viewport, AscCamera *camera); /** * Creates an empty node that may serve as a container for other nodes. * + * The free_func of this node will be a simple free(). + * * @return the new node */ AscSceneNode *asc_scene_node_empty(void); /** - * Adds a node to a (new) parent. + * Unlinks the node from its parent and frees the entire subtree. + * + * The free_func of this node and all child nodes is called, starting + * with the leaf nodes and terminating with \p node. + * + * @param node the node to unlink + */ +void asc_scene_node_free(AscSceneNode *node); + +/** + * Links a node to a (new) parent. * * @param parent the (new) parent - * @param node the node to add + * @param node the node to link */ __attribute__((__nonnull__)) -void asc_scene_node_add( +void asc_scene_node_link( AscSceneNode *restrict parent, AscSceneNode *restrict node ); /** - * Removes a node from its scene. + * Unlinks a node from its parent. * * This might be useful to temporarily remove a subtree from a scene. + * To permanently remove the node use asc_scene_node_free(). * - * @param node the node to remove from its scene + * @param node the node to unlink */ __attribute__((__nonnull__)) -void asc_scene_node_remove(AscSceneNode *node); - -/** - * Retrieves the parent of a particular node. - * - * @param node the node - * @return the parent of \p node (or NULL when it is the root node) - */ -__attribute__((__nonnull__)) -static inline AscSceneNode *asc_scene_node_parent(AscSceneNode *node) { - return (AscSceneNode *) node->base.parent; -} +void asc_scene_node_unlink(AscSceneNode *node); /** * Adds a behavior function to the node.