Update: Update delete component function
This commit is contained in:
parent
4cb275434e
commit
e698975a79
13
becs2.h
13
becs2.h
|
|
@ -3,6 +3,7 @@
|
||||||
|
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
#include <stddef.h>
|
#include <stddef.h>
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
#define MAX_ENTITIES 100
|
#define MAX_ENTITIES 100
|
||||||
#define NUM_COMPONENTS 2
|
#define NUM_COMPONENTS 2
|
||||||
|
|
@ -142,9 +143,19 @@ int32_t BECS_RemoveComponent(BECS_ECS *ecs, uint32_t entityID, uint32_t componen
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
uint32_t lastEntityAdded = componentArray->sparseArray[componentArray->lastEntityAdded];
|
uint32_t lastEntityAddedIndex = componentArray->sparseArray[componentArray->lastEntityAdded];
|
||||||
uint32_t deletedCompIndex = componentArray->sparseArray[entityID];
|
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;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue