diff options
| author | Jonathan Bradley <jcb@pikum.xyz> | 2024-01-15 18:20:58 -0500 |
|---|---|---|
| committer | Jonathan Bradley <jcb@pikum.xyz> | 2024-01-15 18:20:58 -0500 |
| commit | c30b1f9b2f5d231e98194db526560eb4e010edff (patch) | |
| tree | 328825d5187f5f0b3ffd6754f8795f6a5947b8f7 /src/ecs.cpp | |
| parent | 05a6ca44e40da855a1ddc32cfe799edef74f7bdf (diff) | |
major refactor so cameras are entities and have a rigid body instance
Diffstat (limited to 'src/ecs.cpp')
| -rw-r--r-- | src/ecs.cpp | 35 |
1 files changed, 20 insertions, 15 deletions
diff --git a/src/ecs.cpp b/src/ecs.cpp index d087e45..203adb5 100644 --- a/src/ecs.cpp +++ b/src/ecs.cpp @@ -160,15 +160,17 @@ void ECS_Tick(double delta) { if (entityRemovalCount > 0) { int64_t removeIndex = entitiesYetToBeRemoved.FindFirstIndex(DynArrayFindComponent, inst.entHandle); if (removeIndex != -1) { - int64_t afterIndex = updateGrBinds.FindFirstIndex(DynArrayFindGrBinds, inst.grBindsHandle); - updateGrBindsAfter *after = nullptr; - if (afterIndex != -1) { - after = &updateGrBinds[afterIndex]; - } else { - after = &updateGrBinds.Push(); - after->grBindsHandle = inst.grBindsHandle; + if (inst.grBindsHandle != GrBindsHandle_MAX) { + int64_t afterIndex = updateGrBinds.FindFirstIndex(DynArrayFindGrBinds, inst.grBindsHandle); + updateGrBindsAfter *after = nullptr; + if (afterIndex != -1) { + after = &updateGrBinds[afterIndex]; + } else { + after = &updateGrBinds.Push(); + after->grBindsHandle = inst.grBindsHandle; + } + after->count += 1; } - after->count += 1; inst.entHandle = EntityHandle_MAX; inst.grBindsHandle = GrBindsHandle_MAX; @@ -183,7 +185,7 @@ void ECS_Tick(double delta) { continue; } } - if (updateGrBinds.Count() > 0) { + if (updateGrBinds.Count() > 0 && inst.instanceHandle != InstanceHandle_MAX) { int64_t afterIndex = updateGrBinds.FindFirstIndex(DynArrayFindGrBinds, inst.grBindsHandle); if (afterIndex > -1) { auto &after = updateGrBinds[afterIndex]; @@ -251,6 +253,8 @@ void ECS_Tick_Late(double delta) { continue; if (inst.entHandle == EntityHandle_MAX) continue; + if (inst.grBindsHandle == GrBindsHandle_MAX) + continue; auto &grBinds = ecs.bc.grBinds.buckets[inst.grBindsHandle.bucketIndex][inst.grBindsHandle.itemIndex]; @@ -433,7 +437,6 @@ CompGrBinds *ECS_GetGrBinds(uint64_t bucketIndex, uint64_t &itemCount) { CompInstance *ECS_CreateInstance(Entity_Base *entity, CompGrBinds *entityTypeGrBinds) { assert(entity != nullptr && entity != CAFE_BABE(Entity_Base)); - assert(entityTypeGrBinds != nullptr && entityTypeGrBinds != CAFE_BABE(CompGrBinds)); InstanceHandle instanceHandle{Buckets_NewHandle(ecs.bc.instances)}; @@ -441,13 +444,15 @@ CompInstance *ECS_CreateInstance(Entity_Base *entity, CompGrBinds *entityTypeGrB auto *comp = &instBkt[instanceHandle.itemIndex]; new (comp) CompInstance{}; comp->entHandle = entity->handle; - comp->grBindsHandle = entityTypeGrBinds->grBindsHandle; comp->instanceHandle = instanceHandle; - comp->index = entityTypeGrBinds->instanceCounter++; - comp->isNeedingUpdated = true; - if (entityTypeGrBinds->instanceCounter > entityTypeGrBinds->instanceBufferMaxCount) { - EntitiesWithExcessInstances.Push(ECS_GetEntity(entityTypeGrBinds->entHandle)); + if (entityTypeGrBinds != nullptr) { + comp->grBindsHandle = entityTypeGrBinds->grBindsHandle; + comp->index = entityTypeGrBinds->instanceCounter++; + comp->isNeedingUpdated = true; + if (entityTypeGrBinds->instanceCounter > entityTypeGrBinds->instanceBufferMaxCount) { + EntitiesWithExcessInstances.Push(ECS_GetEntity(entityTypeGrBinds->entHandle)); + } } return comp; |
