From 5292542c30c4379aeb7474e76f6a8b54775f0b6d Mon Sep 17 00:00:00 2001 From: Rodolfo Barcelli Jo Date: Thu, 22 Jan 2026 07:45:38 +0800 Subject: [PATCH] Rewrite test --- test/main.c | 67 ++++++++++++++++++++++++++++++++++++----------------- 1 file changed, 46 insertions(+), 21 deletions(-) diff --git a/test/main.c b/test/main.c index f978452..5aee508 100644 --- a/test/main.c +++ b/test/main.c @@ -1,11 +1,12 @@ #include #include +#include -#define MAX_ENTITIES 100 -#define NUM_COMPONENTS 2 +#define BECS_MAX_ENTITIES 100 +#define BECS_MAX_COMPONENTS 2 #define BECS_IMPLEMENTATION -#include "../becs2.h" +#include "../becs3.h" typedef struct compA { uint32_t thing; @@ -15,33 +16,57 @@ typedef struct compB { uint32_t thing; } compB; -int main(void) { - BECS_Properties EcsProps = {}; +enum { + COMPA, + COMPB +}; +int main(void) { size_t componentSizes[2] = { sizeof(compA), sizeof(compB), }; - for (uint32_t i = 0; i < NUM_COMPONENTS; i++) - { - EcsProps.componentSizes[i] = componentSizes[i]; - } + size_t MinMemorySize = BECS_GetMinMemoryArenaSize(componentSizes, 2); - size_t MinMemorySize = BECS_GetMinMemorySize(EcsProps); - printf("%llu\n", MinMemorySize); + printf("%lu\n", MinMemorySize); - BECS_ECS *ecs = malloc(MinMemorySize); - BECS_Init(ecs, MinMemorySize, EcsProps); + void *memory= malloc(MinMemorySize); + BECS_ECS ecs = BECS_InitECS(memory, MinMemorySize); - uint32_t entityID = 0; - compA *component = (compA *)BECS_AddComponent(ecs, entityID, 0); - - component->thing = 1; - - compA *component2 = (compA *)BECS_GetComponent(ecs, entityID, 0); - - BECS_RemoveComponent(ecs, entityID, 0); + BECS_ComponentRegister(&ecs, sizeof(compA), BECS_MAX_ENTITIES); + BECS_ComponentRegister(&ecs, sizeof(compB), BECS_MAX_ENTITIES); printf("Initialized\n"); + + BECS_Entity entity1 = BECS_EntityCreate(&ecs); + BECS_Entity entity2 = BECS_EntityCreate(&ecs); + + BECS_ComponentAdd(&ecs, entity1, COMPA); + BECS_ComponentAdd(&ecs, entity2, COMPB); + + bool testComponent1 = BECS_ComponentHas(&ecs, entity1, 0); + bool testComponent2 = BECS_ComponentHas(&ecs, entity1, 1); + + bool testComponent3 = BECS_ComponentHas(&ecs, entity2, 0); + bool testComponent4 = BECS_ComponentHas(&ecs, entity2, 1); + + if (testComponent1) + { + printf("Entity:%u has compA\n", entity1); + } + if (testComponent2) + { + printf("Entity:%u has compB\n", entity1); + } + if (testComponent3) + { + printf("Entity:%u has compA\n", entity2); + } + if (testComponent4) + { + printf("Entity:%u has compB\n", entity2); + } + + return 0; }