Rewrite test

This commit is contained in:
Rodolfo Barcelli Jo 2026-01-22 07:45:38 +08:00
parent 8d0db596a9
commit 5292542c30

View file

@ -1,11 +1,12 @@
#include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>
#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;
}