From e4604d5b84a71ac3cc8fe1a148d0a6250c7a715c Mon Sep 17 00:00:00 2001 From: Jonathan Bradley Date: Thu, 27 Mar 2025 11:58:47 -0400 Subject: pke: generate uuid and save to project+scene files --- src/ecs.cpp | 9 +++++++++ 1 file changed, 9 insertions(+) (limited to 'src/ecs.cpp') diff --git a/src/ecs.cpp b/src/ecs.cpp index 4174bd0..048669d 100644 --- a/src/ecs.cpp +++ b/src/ecs.cpp @@ -5,6 +5,7 @@ #include "game-settings.hpp" #include "math-helpers.hpp" #include "physics.hpp" +#include "pk.h" #include "window.hpp" #include @@ -68,6 +69,10 @@ void ECS_Init() { } Entity_Base *ECS_CreateGenericEntity() { + /* 2025-03-26 - JCB + * The only place this is called immediately calls ECS_CreateEntity afterwards. + * There is no need to generate a uuid + */ pk_handle newHandle{Buckets_NewHandle(ecs.bc.generics)}; return &ecs.bc.generics.buckets[newHandle.bucketIndex][newHandle.itemIndex]; } @@ -78,6 +83,7 @@ EntityHandle ECS_CreateEntity(Entity_Base *entity, Entity_Base *parentEntity) { EntityHandle entityHandle{Buckets_NewHandle(ecs.bc.entityPtrs)}; entity->handle = entityHandle; if (parentEntity) entity->parentHandle = parentEntity->handle; + if (entity->uuid == pk_uuid_max || entity->uuid == pk_uuid_zed) entity->uuid = pk_uuid_new_v7(); ecs.bc.entityPtrs.buckets[entityHandle.bucketIndex][entityHandle.itemIndex] = entity; return entityHandle; } @@ -443,6 +449,9 @@ CompInstance *ECS_CreateInstance(Entity_Base *entity, CompGrBinds *entityTypeGrB new (comp) CompInstance{}; comp->entHandle = entity->handle; comp->instanceHandle = instanceHandle; + // TODO this should be passed in - currently generating a new one each time + // Consider making a Component_Base that has a UUID, and pass in similar to ECS_CreateEntity + if (comp->uuid == pk_uuid_zed || comp->uuid == pk_uuid_max) comp->uuid = pk_uuid_new_v7(); if (entityTypeGrBinds != nullptr) { comp->grBindsHandle = entityTypeGrBinds->grBindsHandle; -- cgit v1.2.3