diff options
| author | Jonathan Bradley <jcb@pikum.xyz> | 2025-11-06 22:19:19 -0500 |
|---|---|---|
| committer | Jonathan Bradley <jcb@pikum.xyz> | 2025-11-06 22:19:19 -0500 |
| commit | 2611f216e87f8799c4baa757a3148221a83b7729 (patch) | |
| tree | 1b1eed38c108ccd930d9cd6d431a0485aa050155 | |
| parent | c081c633f4980bcd39233526304b0cc44277ba07 (diff) | |
pke: ecs unregister events on entity removal
| -rw-r--r-- | src/ecs.cpp | 12 |
1 files changed, 8 insertions, 4 deletions
diff --git a/src/ecs.cpp b/src/ecs.cpp index b0e5d7b..d755853 100644 --- a/src/ecs.cpp +++ b/src/ecs.cpp @@ -220,6 +220,9 @@ void ECS_Tick_Early(double delta) { while (b == true) { Entity_Base *ent = ecs.bc.entityPtrs[iter_comp_ev->entity_handle]; if (ent->isMarkedForRemoval) { + if (iter_comp_ev->ev_id != pk_ev_id_T_MAX) { + pk_ev_unregister_ev(iter_comp_ev->ev_mgr_id, iter_comp_ev->ev_id); + } pk_bkt_arr_free_handle(&ecs.bc.ev_mgrs, iter_comp_ev->pke_event_handle); new (&(*iter_comp_ev)) pke_component_event{}; } @@ -629,7 +632,7 @@ pke_component_event *ECS_CreateEv(Entity_Base *entity, pk_uuid uuid) { assert(entity != nullptr && entity != CAFE_BABE(Entity_Base)); PkeEventHandle pke_ev_handle { pk_bkt_arr_new_handle(&ecs.bc.ev_mgrs) }; - auto *comp = &ecs.bc.ev_mgrs[pke_ev_handle]; + pke_component_event *comp = &ecs.bc.ev_mgrs[pke_ev_handle]; new (comp) pke_component_event{}; comp->entity_handle = entity->handle; comp->pke_event_handle = pke_ev_handle; @@ -644,12 +647,13 @@ pke_component_event *ECS_CreateEv(Entity_Base *entity, pk_uuid uuid) { } pke_component_event *ECS_GetEv(PkeEventHandle handle) { - if (handle == PkeEventHandle_MAX) return nullptr; + pke_component_event *comp_ev = nullptr; + if (handle == PkeEventHandle_MAX) return comp_ev; assert(pk_bkt_arr_handle_validate(&ecs.bc.ev_mgrs, handle) == PK_BKT_ARR_HANDLE_VALIDATION_VALID); - auto *ev_mgr = &ecs.bc.ev_mgrs[handle]; + comp_ev = &ecs.bc.ev_mgrs[handle]; - return ev_mgr; + return comp_ev; } void ECS_GetEvs(Entity_Base *entity, pk_arr_t<pke_component_event *> &arr) { |
