Files
dusk/src/scene/scenetree.h
2025-08-21 22:58:39 -05:00

101 lines
2.7 KiB
C

/**
* Copyright (c) 2025 Dominic Masters
*
* This software is released under the MIT License.
* https://opensource.org/licenses/MIT
*/
#pragma once
#include "ecs/ecscomponent.h"
#define SCENE_ITEM_CHILD_MAX 16
typedef struct {
ecsid_t children[SCENE_ITEM_CHILD_MAX];
uint8_t childCount;
ecsid_t parent;
} scenetreenode_t;
extern scenetreenode_t SCENE_TREE_DATA[ECS_ENTITY_COUNT_MAX];
extern ecscomponent_t SCENE_TREE_COMPONENT;
/**
* 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.
*/
ecsid_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.
*/
ecsid_t sceneTreeParentGet(const ecsid_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 ecsid_t id, ecsid_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 ecsid_t parent, const ecsid_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 ecsid_t prnt, const ecsid_t child);
/**
* Remove all children from a parent in the scene tree.
*
* @param parent The ID of the parent scene item.
*/
void sceneTreeChildRemoveAll(const ecsid_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 ecsid_t parent, const ecsid_t child);
/**
* Callback for when an entity is added to the ECS.
* This will initialize the scene tree data for the entity.
*
* @param id The ID of the entity being added.
*/
void sceneTreeEntityAdded(const ecsid_t id);
/**
* Callback for when an entity is removed from the ECS.
* This will clean up any scene tree data associated with the entity.
*
* @param id The ID of the entity being removed.
*/
void sceneTreeEntityRemoved(const ecsid_t id);