mirror of
https://github.com/Ukendio/jecs.git
synced 2025-04-24 17:10:03 +00:00
Clear ID will remove ID from all entities
This commit is contained in:
parent
4d6c2ccbb8
commit
75f2584bf4
3 changed files with 43 additions and 0 deletions
16
jecs.luau
16
jecs.luau
|
@ -1073,6 +1073,22 @@ local function world_clear(world: ecs_world_t, entity: i53)
|
||||||
local archetype = record.archetype
|
local archetype = record.archetype
|
||||||
local row = record.row
|
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
|
if archetype then
|
||||||
-- In the future should have a destruct mode for
|
-- In the future should have a destruct mode for
|
||||||
-- deleting archetypes themselves. Maybe requires recycling
|
-- deleting archetypes themselves. Maybe requires recycling
|
||||||
|
|
|
@ -1093,6 +1093,33 @@ TEST("world:children", function()
|
||||||
end)
|
end)
|
||||||
|
|
||||||
TEST("world:clear()", function()
|
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
|
do
|
||||||
CASE("should remove its components")
|
CASE("should remove its components")
|
||||||
local world = jecs.World.new() :: World
|
local world = jecs.World.new() :: World
|
||||||
|
|
0
text.txt
Normal file
0
text.txt
Normal file
Loading…
Reference in a new issue