diff --git a/include/QF/ecs/hierarchy.h b/include/QF/ecs/hierarchy.h index 5a8056617..fa5f4ef8d 100644 --- a/include/QF/ecs/hierarchy.h +++ b/include/QF/ecs/hierarchy.h @@ -71,7 +71,8 @@ void Hierarchy_Delete (hierarchy_t *hierarchy); uint32_t Hierarchy_InsertHierarchy (hierarchy_t *dst, const hierarchy_t *src, uint32_t dstParent, uint32_t srcRoot); -void Hierarchy_RemoveHierarchy (hierarchy_t *hierarchy, uint32_t index); +void Hierarchy_RemoveHierarchy (hierarchy_t *hierarchy, uint32_t index, + int delEntities); hierref_t Hierarchy_SetParent (hierarchy_t *dst, uint32_t dstParent, hierarchy_t *src, uint32_t srcIndex); diff --git a/libs/ecs/hierarchy.c b/libs/ecs/hierarchy.c index 024c0700a..3cbaeec18 100644 --- a/libs/ecs/hierarchy.c +++ b/libs/ecs/hierarchy.c @@ -316,13 +316,19 @@ Hierarchy_InsertHierarchy (hierarchy_t *dst, const hierarchy_t *src, } static void -hierarchy_remove_children (hierarchy_t *hierarchy, uint32_t index) +hierarchy_remove_children (hierarchy_t *hierarchy, uint32_t index, + int delEntities) { uint32_t childIndex = hierarchy->childIndex[index]; uint32_t childCount = hierarchy->childCount[index]; for (uint32_t i = childCount; i-- > 0; ) { - hierarchy_remove_children (hierarchy, childIndex + i); + hierarchy_remove_children (hierarchy, childIndex + i, delEntities); + } + if (delEntities) { + for (uint32_t i = 0; i < childCount; i++) { + ECS_DelEntity (hierarchy->reg, hierarchy->ent[childIndex + i]); + } } hierarchy_close (hierarchy, childIndex, childCount); hierarchy->childCount[index] = 0; @@ -337,11 +343,15 @@ hierarchy_remove_children (hierarchy_t *hierarchy, uint32_t index) } void -Hierarchy_RemoveHierarchy (hierarchy_t *hierarchy, uint32_t index) +Hierarchy_RemoveHierarchy (hierarchy_t *hierarchy, uint32_t index, + int delEntities) { uint32_t parentIndex = hierarchy->parentIndex[index]; - hierarchy_remove_children (hierarchy, index); + hierarchy_remove_children (hierarchy, index, delEntities); + if (delEntities) { + ECS_DelEntity (hierarchy->reg, hierarchy->ent[index]); + } hierarchy_close (hierarchy, index, 1); hierarchy_UpdateTransformIndices (hierarchy, index, -1); @@ -442,7 +452,7 @@ Hierarchy_SetParent (hierarchy_t *dst, uint32_t dstParent, } r.hierarchy = dst; r.index = hierarchy_insertHierarchy (dst, src, dstParent, &srcRoot); - Hierarchy_RemoveHierarchy (src, srcRoot); + Hierarchy_RemoveHierarchy (src, srcRoot, 0); if (!src->num_objects) { Hierarchy_Delete (src); }