From bce46bc93fc376a54d8a213ba54e69513f5d1cbb Mon Sep 17 00:00:00 2001 From: Laud Boateng Date: Wed, 15 Jan 2025 07:03:28 -0500 Subject: [PATCH] Fix World Each to iterate multiple archetypes (#174) * Add tests for entity-child relationships and removal in world queries, fixed world_each * Correct test case --------- Co-authored-by: Marcus --- jecs.luau | 1 + test/tests.luau | 27 +++++++++++++++++++++++---- 2 files changed, 24 insertions(+), 4 deletions(-) diff --git a/jecs.luau b/jecs.luau index d922ef5..940e4b7 100644 --- a/jecs.luau +++ b/jecs.luau @@ -1995,6 +1995,7 @@ local function world_each(world: World, id): () -> () archetype = archetypes[archetype_id] entities = archetype.entities row = #entities + entity = entities[row] end row -= 1 return entity diff --git a/test/tests.luau b/test/tests.luau index bd38030..2a376e4 100644 --- a/test/tests.luau +++ b/test/tests.luau @@ -900,20 +900,39 @@ end) TEST("world:children", function() local world = world_new() + local C = world:component() + local T = world:entity() + local e1 = world:entity() + world:set(e1, C, true) + local e2 = world:entity() - local e3 = world:entity() + world:add(e2, T) world:add(e2, pair(ChildOf, e1)) + + local e3 = world:entity() world:add(e3, pair(ChildOf, e1)) - for entity in world:children(pair(ChildOf, e1)) do + local count = 0 + for entity in world:children(e1) do + count += 1 if entity == e2 or entity == e3 then CHECK(true) continue end CHECK(false) end + CHECK(count == 2) + + world:remove(e2, pair(ChildOf, e1)) + + count = 0 + for entity in world:children(e1) do + count += 1 + end + + CHECK(count == 1) end) TEST("world:clear()", function() @@ -1562,9 +1581,9 @@ TEST("repro", function() local world = world_new() local component1 = world:component() local tag1 = world:entity() - + local query = world:query(component1):with(tag1):cached() - + local entity = world:entity() world:set(entity, component1, "some data")