88 lines
2.3 KiB
C
88 lines
2.3 KiB
C
/**
|
|
* Copyright (c) 2025 Dominic Masters
|
|
*
|
|
* This software is released under the MIT License.
|
|
* https://opensource.org/licenses/MIT
|
|
*/
|
|
|
|
#pragma once
|
|
#include "ecs/ecsentity.h"
|
|
|
|
#define SCENE_ITEM_CHILD_MAX 16
|
|
|
|
typedef struct {
|
|
ecsid_t children[SCENE_ITEM_CHILD_MAX];
|
|
uint8_t childCount;
|
|
ecsid_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.
|
|
*/
|
|
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); |