From 31880b71ace6d45d9ed47afbcff8d82dbdbdc3fa Mon Sep 17 00:00:00 2001 From: Ukendio Date: Sun, 22 Sep 2024 03:36:44 +0200 Subject: [PATCH] Improve world_delete performance --- src/init.luau | 28 +++++++++++++--------------- 1 file changed, 13 insertions(+), 15 deletions(-) diff --git a/src/init.luau b/src/init.luau index e2f7d4d..e3f46d7 100644 --- a/src/init.luau +++ b/src/init.luau @@ -727,7 +727,6 @@ local function world_add(world: World, entity: i53, id: i53): () end end --- Symmetric like `World.add` but idempotent local function world_set(world: World, entity: i53, id: i53, data: unknown): () local entityIndex = world.entityIndex local record = entityIndex.sparse[entity] @@ -1032,27 +1031,26 @@ do if not ECS_IS_PAIR(id) then continue end - - local id_record = component_index[id] - - if id_record then + local object = ECS_ENTITY_T_LO(id) + if object == delete then + local id_record = component_index[id] local flags = id_record.flags if bit32.band(flags, ECS_ID_DELETE) ~= 0 then - for _, child in children do - -- Cascade deletions of it has Delete as component trait - world_delete(world, child, destruct) - end + for _, child in children do + -- Cascade deletions of it has Delete as component trait + world_delete(world, child, destruct) + end + + break else - local object = ECS_ENTITY_T_LO(id) - if object == delete then - for _, child in children do - world_remove(world, child, id) - end - end + for _, child in children do + world_remove(world, child, id) + end end end end + archetype_destroy(world, idr_t_archetype) end end