mirror of
https://github.com/Ukendio/jecs.git
synced 2025-08-04 19:29:18 +00:00
Compare commits
3 commits
669c216387
...
5e3739036a
Author | SHA1 | Date | |
---|---|---|---|
|
5e3739036a | ||
|
0296c4b2f9 | ||
|
c354a29fb1 |
2 changed files with 67 additions and 3 deletions
|
@ -957,8 +957,10 @@ local function archetype_delete(world: World, archetype: Archetype, row: number,
|
||||||
|
|
||||||
-- TODO: if last == 0 then deactivate table
|
-- TODO: if last == 0 then deactivate table
|
||||||
|
|
||||||
|
local component_index = world.componentIndex
|
||||||
for _, id in id_types do
|
for _, id in id_types do
|
||||||
local on_remove: (entity: i53) -> () = world_get_one_inline(world, id, EcsOnRemove)
|
local idr = component_index[id]
|
||||||
|
local on_remove = idr.hooks.on_remove
|
||||||
if on_remove then
|
if on_remove then
|
||||||
on_remove(delete)
|
on_remove(delete)
|
||||||
end
|
end
|
||||||
|
@ -1156,7 +1158,6 @@ do
|
||||||
local idr_t_archetype = archetypes[archetype_id]
|
local idr_t_archetype = archetypes[archetype_id]
|
||||||
|
|
||||||
local idr_t_types = idr_t_archetype.types
|
local idr_t_types = idr_t_archetype.types
|
||||||
local on_remove = idr_t.hooks.on_remove
|
|
||||||
|
|
||||||
for _, child in idr_t_archetype.entities do
|
for _, child in idr_t_archetype.entities do
|
||||||
table.insert(children, child)
|
table.insert(children, child)
|
||||||
|
@ -1178,6 +1179,7 @@ do
|
||||||
end
|
end
|
||||||
break
|
break
|
||||||
else
|
else
|
||||||
|
local on_remove = id_record.hooks.on_remove
|
||||||
local to = archetype_traverse_remove(world, id, idr_t_archetype)
|
local to = archetype_traverse_remove(world, id, idr_t_archetype)
|
||||||
if on_remove then
|
if on_remove then
|
||||||
for _, child in children do
|
for _, child in children do
|
||||||
|
@ -2311,7 +2313,7 @@ export type World = {
|
||||||
}
|
}
|
||||||
|
|
||||||
return {
|
return {
|
||||||
World = World,
|
World = World :: { new: () -> World },
|
||||||
|
|
||||||
OnAdd = EcsOnAdd :: Entity<(entity: Entity) -> ()>,
|
OnAdd = EcsOnAdd :: Entity<(entity: Entity) -> ()>,
|
||||||
OnRemove = EcsOnRemove :: Entity<(entity: Entity) -> ()>,
|
OnRemove = EcsOnRemove :: Entity<(entity: Entity) -> ()>,
|
||||||
|
|
|
@ -1659,4 +1659,66 @@ TEST("wildcard query", function()
|
||||||
CHECK(counter == 1)
|
CHECK(counter == 1)
|
||||||
end
|
end
|
||||||
end)
|
end)
|
||||||
|
|
||||||
|
TEST("world:delete() invokes OnRemove hook", function()
|
||||||
|
do CASE "#1"
|
||||||
|
local world = world_new()
|
||||||
|
|
||||||
|
local A = world:entity()
|
||||||
|
local entity = world:entity()
|
||||||
|
|
||||||
|
local called = false
|
||||||
|
world:set(A, jecs.OnRemove, function(e)
|
||||||
|
called = true
|
||||||
|
end)
|
||||||
|
|
||||||
|
world:add(entity, A)
|
||||||
|
world:delete(entity)
|
||||||
|
|
||||||
|
CHECK(called)
|
||||||
|
end
|
||||||
|
do CASE "#2"
|
||||||
|
local world = world_new()
|
||||||
|
local pair = jecs.pair
|
||||||
|
|
||||||
|
local Relation = world:entity()
|
||||||
|
local A = world:entity()
|
||||||
|
local B = world:entity()
|
||||||
|
|
||||||
|
world:add(Relation, pair(jecs.OnDelete, jecs.Delete))
|
||||||
|
|
||||||
|
local entity = world:entity()
|
||||||
|
|
||||||
|
local called = false
|
||||||
|
world:set(A, jecs.OnRemove, function(e)
|
||||||
|
called = true
|
||||||
|
end)
|
||||||
|
|
||||||
|
world:add(entity, A)
|
||||||
|
world:add(entity, pair(Relation, B))
|
||||||
|
|
||||||
|
world:delete(B)
|
||||||
|
|
||||||
|
CHECK(called)
|
||||||
|
end
|
||||||
|
do CASE "#3"
|
||||||
|
local world = world_new()
|
||||||
|
local pair = jecs.pair
|
||||||
|
|
||||||
|
local viewingContainer = world:entity()
|
||||||
|
local character = world:entity()
|
||||||
|
local container = world:entity()
|
||||||
|
|
||||||
|
local called = false
|
||||||
|
world:set(viewingContainer, jecs.OnRemove, function(e)
|
||||||
|
called = true
|
||||||
|
end)
|
||||||
|
|
||||||
|
world:add(character, pair(viewingContainer, container))
|
||||||
|
|
||||||
|
world:delete(container)
|
||||||
|
|
||||||
|
CHECK(called)
|
||||||
|
end
|
||||||
|
end)
|
||||||
FINISH()
|
FINISH()
|
||||||
|
|
Loading…
Reference in a new issue