About to break scene tree.

This commit is contained in:
2025-08-21 16:21:01 -05:00
parent 4688358d6a
commit 9f5894cdcb
17 changed files with 317 additions and 83 deletions

View File

@@ -7,4 +7,7 @@
target_sources(${DUSK_TARGET_NAME}
PRIVATE
scenetree.c
)
)
# Subdirs
add_subdirectory(test)

View File

@@ -13,17 +13,17 @@ void sceneTreeInit(void) {
memoryZero(&SCENE_TREE, sizeof(scenetree_t));
// Default all items to have no parent
for (ecsentityid_t i = 0; i < ECS_ENTITY_COUNT_MAX; i++) {
for (ecsid_t i = 0; i < ECS_ENTITY_COUNT_MAX; i++) {
SCENE_TREE.items[i].parent = -1;
}
}
ecsentityid_t sceneTreeParentGet(const ecsentityid_t child) {
ecsid_t sceneTreeParentGet(const ecsid_t child) {
assertTrue(child >= 0 && child < ECS_ENTITY_COUNT_MAX, "Invalid child ID");
return SCENE_TREE.items[child].parent;
}
uint8_t sceneTreeChildGetAll(const ecsentityid_t id, ecsentityid_t *children) {
uint8_t sceneTreeChildGetAll(const ecsid_t id, ecsid_t *children) {
assertTrue(id >= 0 && id < ECS_ENTITY_COUNT_MAX, "Invalid parent ID");
const scenetreenode_t *node = &SCENE_TREE.items[id];
@@ -32,7 +32,7 @@ uint8_t sceneTreeChildGetAll(const ecsentityid_t id, ecsentityid_t *children) {
return node->childCount;
}
void sceneTreeChildAdd(const ecsentityid_t parent, const ecsentityid_t child) {
void sceneTreeChildAdd(const ecsid_t parent, const ecsid_t child) {
assertTrue(parent >= 0 && parent < ECS_ENTITY_COUNT_MAX, "Invalid parent ID");
assertTrue(child >= 0 && child < ECS_ENTITY_COUNT_MAX, "Invalid child ID");
assertTrue(parent != child, "Child cannot be a child of itself.");
@@ -57,8 +57,8 @@ void sceneTreeChildAdd(const ecsentityid_t parent, const ecsentityid_t child) {
}
void sceneTreeChildRemove(
const ecsentityid_t parent,
const ecsentityid_t child
const ecsid_t parent,
const ecsid_t child
) {
assertTrue(parent >= 0 && parent < ECS_ENTITY_COUNT_MAX, "Invalid parent ID");
assertTrue(child >= 0 && child < ECS_ENTITY_COUNT_MAX, "Invalid child ID");
@@ -85,12 +85,12 @@ void sceneTreeChildRemove(
childNode->parent = -1;
}
void sceneTreeChildRemoveAll(const ecsentityid_t parent) {
void sceneTreeChildRemoveAll(const ecsid_t parent) {
assertTrue(parent >= 0 && parent < ECS_ENTITY_COUNT_MAX, "Invalid parent ID");
scenetreenode_t *parentNode = &SCENE_TREE.items[parent];
for(uint8_t i = 0; i < parentNode->childCount; i++) {
ecsentityid_t child = parentNode->children[i];
ecsid_t child = parentNode->children[i];
SCENE_TREE.items[child].parent = -1;
}
@@ -99,8 +99,8 @@ void sceneTreeChildRemoveAll(const ecsentityid_t parent) {
}
bool_t sceneTreeChildInTree(
const ecsentityid_t parent,
const ecsentityid_t child
const ecsid_t parent,
const ecsid_t child
) {
assertTrue(parent >= 0 && parent < ECS_ENTITY_COUNT_MAX, "Invalid parent ID");
assertTrue(child >= 0 && child < ECS_ENTITY_COUNT_MAX, "Invalid child ID");

View File

@@ -6,14 +6,14 @@
*/
#pragma once
#include "ecs/ecs.h"
#include "ecs/ecsentity.h"
#define SCENE_ITEM_CHILD_MAX 16
typedef struct {
ecsentityid_t children[SCENE_ITEM_CHILD_MAX];
ecsid_t children[SCENE_ITEM_CHILD_MAX];
uint8_t childCount;
ecsentityid_t parent;
ecsid_t parent;
} scenetreenode_t;
typedef struct scene_s {
@@ -35,7 +35,7 @@ void sceneTreeInit(void);
*
* @return The ID of the newly created scene item.
*/
ecsentityid_t sceneTreeCreate(void);
ecsid_t sceneTreeCreate(void);
/**
* Get the parent of a given scene item.
@@ -43,7 +43,7 @@ ecsentityid_t sceneTreeCreate(void);
* @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);
ecsid_t sceneTreeParentGet(const ecsid_t child);
/**
* Get the children of a given scene item. If children is NULL only the count
@@ -53,7 +53,7 @@ ecsentityid_t sceneTreeParentGet(const ecsentityid_t child);
* @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);
uint8_t sceneTreeChildGetAll(const ecsid_t id, ecsid_t *children);
/**
* Add a child to a parent in the scene tree.
@@ -61,7 +61,7 @@ uint8_t sceneTreeChildGetAll(const ecsentityid_t id, ecsentityid_t *children);
* @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);
void sceneTreeChildAdd(const ecsid_t parent, const ecsid_t child);
/**
* Remove a child from a parent in the scene tree.
@@ -69,14 +69,14 @@ void sceneTreeChildAdd(const ecsentityid_t parent, const ecsentityid_t child);
* @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);
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 ecsentityid_t parent);
void sceneTreeChildRemoveAll(const ecsid_t parent);
/**
* Returns true if the child is within the parent's children, recursively.
@@ -85,7 +85,4 @@ void sceneTreeChildRemoveAll(const ecsentityid_t parent);
* @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
);
bool_t sceneTreeChildInTree(const ecsid_t parent, const ecsid_t child);

View File

@@ -0,0 +1,10 @@
# Copyright (c) 2025 Dominic Masters
#
# This software is released under the MIT License.
# https://opensource.org/licenses/MIT
# Sources
target_sources(${DUSK_TARGET_NAME}
PRIVATE
scenetest.c
)

View File

@@ -0,0 +1,23 @@
/**
* Copyright (c) 2025 Dominic Masters
*
* This software is released under the MIT License.
* https://opensource.org/licenses/MIT
*/
#include "scenetest.h"
#include "scene/scenetree.h"
#include "display/camera.h"
ecsid_t sceneTestAdd(void) {
ecsid_t id = ecsEntityAdd();
// Initialize the entity with a camera component
ecsid_t camera = ecsEntityAdd();
sceneTreeChildAdd(id, camera);
camera_t *camData = cameraAdd(camera);
// Optionally, you can set other properties or components here
return id;
}

View File

@@ -0,0 +1,11 @@
/**
* Copyright (c) 2025 Dominic Masters
*
* This software is released under the MIT License.
* https://opensource.org/licenses/MIT
*/
#pragma once
#include "ecs/ecssystem.h"
ecsid_t sceneTestAdd(void);