Clear ID will remove ID from all entities

This commit is contained in:
Ukendio 2025-03-27 05:08:38 +01:00
parent 4d6c2ccbb8
commit 75f2584bf4
3 changed files with 43 additions and 0 deletions

View file

@ -1073,6 +1073,22 @@ local function world_clear(world: ecs_world_t, entity: i53)
local archetype = record.archetype
local row = record.row
local idr = world.component_index[entity]
if idr then
local count = 0
local queue = {}
for archetype_id in idr.cache do
local idr_archetype = world.archetypes[archetype_id]
local entities = idr_archetype.entities
local n = #entities
count += n
table.move(entities, 1, n, #queue + 1, queue)
end
for _, e in queue do
world_remove(world, e, entity)
end
end
if archetype then
-- In the future should have a destruct mode for
-- deleting archetypes themselves. Maybe requires recycling

View file

@ -1093,6 +1093,33 @@ TEST("world:children", function()
end)
TEST("world:clear()", function()
do
CASE("should remove its components")
local world = jecs.World.new() :: World
local A = world:component()
local B = world:component()
local C = world:component()
local D = world:component()
local e = world:entity()
local e1 = world:entity()
local e2 = world:entity()
world:set(e, A, true)
world:set(e, B, true)
world:set(e1, A, true)
world:set(e1, B, true)
CHECK(world:get(e, A))
CHECK(world:get(e, B))
world:clear(A)
CHECK(world:get(e, A) == nil)
CHECK(world:get(e, B))
CHECK(world:get(e1, A) == nil)
CHECK(world:get(e1, B))
end
do
CASE("should remove its components")
local world = jecs.World.new() :: World

0
text.txt Normal file
View file