mirror of
https://github.com/Ukendio/jecs.git
synced 2025-08-04 11:19:17 +00:00
Handle removal of (*, R) pairs
This commit is contained in:
parent
0fea5a259d
commit
c50c61b30c
2 changed files with 22 additions and 1 deletions
|
@ -1413,11 +1413,11 @@ local function world_delete(world: ecs_world_t, entity: i53)
|
||||||
for i = tr, tr + tr_count - 1 do
|
for i = tr, tr + tr_count - 1 do
|
||||||
ids[types[i]] = true
|
ids[types[i]] = true
|
||||||
end
|
end
|
||||||
|
|
||||||
local n = #entities
|
local n = #entities
|
||||||
table.move(entities, 1, n, count + 1, children)
|
table.move(entities, 1, n, count + 1, children)
|
||||||
count += n
|
count += n
|
||||||
end
|
end
|
||||||
|
|
||||||
for _, child in children do
|
for _, child in children do
|
||||||
for id in ids do
|
for id in ids do
|
||||||
world_remove(world, child, id)
|
world_remove(world, child, id)
|
||||||
|
|
|
@ -289,6 +289,27 @@ TEST("world:contains()", function()
|
||||||
end)
|
end)
|
||||||
|
|
||||||
TEST("world:delete()", function()
|
TEST("world:delete()", function()
|
||||||
|
do CASE "remove (*, R) pairs when relationship is invalidated"
|
||||||
|
print("-------")
|
||||||
|
local world = jecs.world()
|
||||||
|
local e1 = world:entity()
|
||||||
|
local e2 = world:entity()
|
||||||
|
|
||||||
|
local A = world:component()
|
||||||
|
local B = world:component()
|
||||||
|
local C = world:component()
|
||||||
|
|
||||||
|
world:add(e1, pair(e2, A))
|
||||||
|
world:add(e1, B) -- Some stable component that should not be removed in the process
|
||||||
|
world:add(e1, pair(e2, C))
|
||||||
|
world:delete(e2)
|
||||||
|
|
||||||
|
CHECK(not world:contains(e2))
|
||||||
|
CHECK(not world:has(e1, pair(e2, A)))
|
||||||
|
CHECK(world:has(e1, B))
|
||||||
|
CHECK(not world:has(e1, pair(e2, C)))
|
||||||
|
CHECK(world:contains(e1))
|
||||||
|
end
|
||||||
do CASE "remove pair when relationship is deleted"
|
do CASE "remove pair when relationship is deleted"
|
||||||
local world = jecs.world()
|
local world = jecs.world()
|
||||||
local e1 = world:entity()
|
local e1 = world:entity()
|
||||||
|
|
Loading…
Reference in a new issue