Scene tree

This commit is contained in:
2025-08-21 09:52:15 -05:00
parent c8390bdb12
commit 4688358d6a
10 changed files with 346 additions and 15 deletions

91
src/scene/scenetree.h Normal file
View File

@@ -0,0 +1,91 @@
/**
* Copyright (c) 2025 Dominic Masters
*
* This software is released under the MIT License.
* https://opensource.org/licenses/MIT
*/
#pragma once
#include "ecs/ecs.h"
#define SCENE_ITEM_CHILD_MAX 16
typedef struct {
ecsentityid_t children[SCENE_ITEM_CHILD_MAX];
uint8_t childCount;
ecsentityid_t parent;
} scenetreenode_t;
typedef struct scene_s {
scenetreenode_t items[ECS_ENTITY_COUNT_MAX];
} scenetree_t;
extern scenetree_t SCENE_TREE;
/**
* Initialize the scene tree.
*
* This will initialize the ECS system and prepare the scene tree for use.
*/
void sceneTreeInit(void);
/**
* Create a new scene item in the scene tree.
* This will create a new entity in the ECS and return its ID.
*
* @return The ID of the newly created scene item.
*/
ecsentityid_t sceneTreeCreate(void);
/**
* Get the parent of a given scene item.
*
* @param id The ID of the scene item.
* @return The ID of the parent scene item, or -1 if it has no parent.
*/
ecsentityid_t sceneTreeParentGet(const ecsentityid_t child);
/**
* Get the children of a given scene item. If children is NULL only the count
* will be returned.
*
* @param id The ID of the scene item.
* @param children Pointer to an array where the children IDs will be stored.
* @return The number of children found.
*/
uint8_t sceneTreeChildGetAll(const ecsentityid_t id, ecsentityid_t *children);
/**
* Add a child to a parent in the scene tree.
*
* @param parent The ID of the parent scene item.
* @param child The ID of the child scene item to add.
*/
void sceneTreeChildAdd(const ecsentityid_t parent, const ecsentityid_t child);
/**
* Remove a child from a parent in the scene tree.
*
* @param prnt The ID of the parent scene item.
* @param child The ID of the child scene item to remove.
*/
void sceneTreeChildRemove(const ecsentityid_t prnt, const ecsentityid_t child);
/**
* Remove all children from a parent in the scene tree.
*
* @param parent The ID of the parent scene item.
*/
void sceneTreeChildRemoveAll(const ecsentityid_t parent);
/**
* Returns true if the child is within the parent's children, recursively.
*
* @param parent The ID of the parent scene item.
* @param child The ID of the child scene item to check.
* @return True if the child is in the parent's children, false otherwise.
*/
bool_t sceneTreeChildInTree(
const ecsentityid_t parent,
const ecsentityid_t child
);