From e698975a79225309ca61a153c2a387893adb1ad9 Mon Sep 17 00:00:00 2001 From: Rodolfo Barcelli Jo Date: Mon, 19 Jan 2026 13:53:21 +0800 Subject: [PATCH] Update: Update delete component function --- becs2.h | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/becs2.h b/becs2.h index 4a81425..cf142b4 100644 --- a/becs2.h +++ b/becs2.h @@ -3,6 +3,7 @@ #include #include +#include #define MAX_ENTITIES 100 #define NUM_COMPONENTS 2 @@ -142,9 +143,19 @@ int32_t BECS_RemoveComponent(BECS_ECS *ecs, uint32_t entityID, uint32_t componen return 0; } - uint32_t lastEntityAdded = componentArray->sparseArray[componentArray->lastEntityAdded]; + uint32_t lastEntityAddedIndex = componentArray->sparseArray[componentArray->lastEntityAdded]; uint32_t deletedCompIndex = componentArray->sparseArray[entityID]; + uintptr_t denseArray = (uintptr_t)componentArray->denseArray; + + uintptr_t lastEntityAdded = denseArray + (lastEntityAddedIndex * componentArray->unitSize); + uintptr_t deletedComp = denseArray + (lastEntityAddedIndex * componentArray->unitSize); + + memcpy((void *)deletedComp, (void*)lastEntityAdded, componentArray->unitSize); + + componentArray->denseArraylength--; + componentArray->sparseArray[entityID] = lastEntityAddedIndex; + return 0; }