Rewrite test
This commit is contained in:
parent
8d0db596a9
commit
5292542c30
67
test/main.c
67
test/main.c
|
|
@ -1,11 +1,12 @@
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
#include <stdbool.h>
|
||||||
|
|
||||||
#define MAX_ENTITIES 100
|
#define BECS_MAX_ENTITIES 100
|
||||||
#define NUM_COMPONENTS 2
|
#define BECS_MAX_COMPONENTS 2
|
||||||
|
|
||||||
#define BECS_IMPLEMENTATION
|
#define BECS_IMPLEMENTATION
|
||||||
#include "../becs2.h"
|
#include "../becs3.h"
|
||||||
|
|
||||||
typedef struct compA {
|
typedef struct compA {
|
||||||
uint32_t thing;
|
uint32_t thing;
|
||||||
|
|
@ -15,33 +16,57 @@ typedef struct compB {
|
||||||
uint32_t thing;
|
uint32_t thing;
|
||||||
} compB;
|
} compB;
|
||||||
|
|
||||||
int main(void) {
|
enum {
|
||||||
BECS_Properties EcsProps = {};
|
COMPA,
|
||||||
|
COMPB
|
||||||
|
};
|
||||||
|
|
||||||
|
int main(void) {
|
||||||
size_t componentSizes[2] = {
|
size_t componentSizes[2] = {
|
||||||
sizeof(compA),
|
sizeof(compA),
|
||||||
sizeof(compB),
|
sizeof(compB),
|
||||||
};
|
};
|
||||||
|
|
||||||
for (uint32_t i = 0; i < NUM_COMPONENTS; i++)
|
size_t MinMemorySize = BECS_GetMinMemoryArenaSize(componentSizes, 2);
|
||||||
{
|
|
||||||
EcsProps.componentSizes[i] = componentSizes[i];
|
|
||||||
}
|
|
||||||
|
|
||||||
size_t MinMemorySize = BECS_GetMinMemorySize(EcsProps);
|
printf("%lu\n", MinMemorySize);
|
||||||
printf("%llu\n", MinMemorySize);
|
|
||||||
|
|
||||||
BECS_ECS *ecs = malloc(MinMemorySize);
|
void *memory= malloc(MinMemorySize);
|
||||||
BECS_Init(ecs, MinMemorySize, EcsProps);
|
BECS_ECS ecs = BECS_InitECS(memory, MinMemorySize);
|
||||||
|
|
||||||
uint32_t entityID = 0;
|
BECS_ComponentRegister(&ecs, sizeof(compA), BECS_MAX_ENTITIES);
|
||||||
compA *component = (compA *)BECS_AddComponent(ecs, entityID, 0);
|
BECS_ComponentRegister(&ecs, sizeof(compB), BECS_MAX_ENTITIES);
|
||||||
|
|
||||||
component->thing = 1;
|
|
||||||
|
|
||||||
compA *component2 = (compA *)BECS_GetComponent(ecs, entityID, 0);
|
|
||||||
|
|
||||||
BECS_RemoveComponent(ecs, entityID, 0);
|
|
||||||
|
|
||||||
printf("Initialized\n");
|
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;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue