Update: fix Init bug
This commit is contained in:
parent
dd308bfc82
commit
748401ce97
29
becs.h
29
becs.h
|
|
@ -2,6 +2,7 @@
|
||||||
#define BECS_H
|
#define BECS_H
|
||||||
|
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
|
#include <stddef.h>
|
||||||
|
|
||||||
typedef struct BECS_ComponentArray BECS_ComponentArray;
|
typedef struct BECS_ComponentArray BECS_ComponentArray;
|
||||||
typedef struct BECS_Properties BECS_Properties;
|
typedef struct BECS_Properties BECS_Properties;
|
||||||
|
|
@ -11,7 +12,10 @@ size_t BECS_GetMinMemorySize(BECS_Properties props);
|
||||||
BECS_ECS *BECS_Init(void *memory, size_t size, BECS_Properties *props);
|
BECS_ECS *BECS_Init(void *memory, size_t size, BECS_Properties *props);
|
||||||
int32_t BECS_AddComponent(BECS_ECS *ecs, uint32_t entityID, uint64_t componentBitMask, void *component);
|
int32_t BECS_AddComponent(BECS_ECS *ecs, uint32_t entityID, uint64_t componentBitMask, void *component);
|
||||||
|
|
||||||
|
#define MAX_ENTITY_COUNT 100
|
||||||
|
|
||||||
#ifdef BECS_IMPLEMENTATION
|
#ifdef BECS_IMPLEMENTATION
|
||||||
|
#ifdef MAX_ENTITY_COUNT
|
||||||
|
|
||||||
struct BECS_ComponentArray {
|
struct BECS_ComponentArray {
|
||||||
uint32_t lastEntityAdded;
|
uint32_t lastEntityAdded;
|
||||||
|
|
@ -52,16 +56,36 @@ BECS_ECS *BECS_Init
|
||||||
{
|
{
|
||||||
BECS_ECS *ecs = (BECS_ECS *)memory;
|
BECS_ECS *ecs = (BECS_ECS *)memory;
|
||||||
uint64_t *bitMasks = (uint64_t *)(ecs + 1);
|
uint64_t *bitMasks = (uint64_t *)(ecs + 1);
|
||||||
BECS_ComponentArray *componentSets = (BECS_ComponentArray *)(bitMasks + props->maxEntities);
|
BECS_ComponentArray *componentSets = (BECS_ComponentArray *)((uint8_t *)(ecs + 1) + props->maxEntities);
|
||||||
ecs->bitMasks = bitMasks;
|
ecs->bitMasks = bitMasks;
|
||||||
ecs->componentSets = componentSets;
|
ecs->componentSets = componentSets;
|
||||||
ecs->props = *props;
|
ecs->props = *props;
|
||||||
|
|
||||||
ecs->bitMasks = 0;
|
for (uint32_t i = 0; i < props->maxEntities; i++)
|
||||||
|
{
|
||||||
|
ecs->bitMasks[i] = 0;
|
||||||
|
}
|
||||||
|
|
||||||
for (uint32_t i = 0; i < props->numComponents; i++)
|
for (uint32_t i = 0; i < props->numComponents; i++)
|
||||||
{
|
{
|
||||||
|
ecs->componentSets[i].unitSize = props->componentSizes[i];
|
||||||
|
ecs->componentSets[i].capacity = ecs->componentSets[i].unitSize * props->maxEntities;
|
||||||
|
ecs->componentSets[i].lastEntityAdded = props->maxEntities + 1;
|
||||||
ecs->componentSets[i].length = 0;
|
ecs->componentSets[i].length = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
uint32_t index = 0;
|
||||||
|
|
||||||
|
// FIX: This is completely fucked. I feel like I am overcomplicating this... Might be easier to use a defined constant :/
|
||||||
|
for (uint32_t i = 0; i < props->numComponents; i++)
|
||||||
|
{
|
||||||
|
uint32_t index = i;
|
||||||
|
if (index - 1 > props->numComponents)
|
||||||
|
{
|
||||||
|
index = 1;
|
||||||
|
}
|
||||||
|
ecs->componentSets[index - 1].array = componentSets + 4;
|
||||||
|
}
|
||||||
return ecs;
|
return ecs;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -108,5 +132,6 @@ BECS_AddComponent(BECS_ECS *ecs, uint32_t entityID, uint64_t componentBitMask, v
|
||||||
// {
|
// {
|
||||||
// }
|
// }
|
||||||
#endif
|
#endif
|
||||||
|
#endif
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue