Compare commits

..

No commits in common. "5e3739036a792348e25761da9a8d5aff140a6e2c" and "669c216387f08da8c21f77731183b1779b611ea6" have entirely different histories.

2 changed files with 3 additions and 67 deletions

View file

@ -957,10 +957,8 @@ local function archetype_delete(world: World, archetype: Archetype, row: number,
-- TODO: if last == 0 then deactivate table
local component_index = world.componentIndex
for _, id in id_types do
local idr = component_index[id]
local on_remove = idr.hooks.on_remove
local on_remove: (entity: i53) -> () = world_get_one_inline(world, id, EcsOnRemove)
if on_remove then
on_remove(delete)
end
@ -1158,6 +1156,7 @@ do
local idr_t_archetype = archetypes[archetype_id]
local idr_t_types = idr_t_archetype.types
local on_remove = idr_t.hooks.on_remove
for _, child in idr_t_archetype.entities do
table.insert(children, child)
@ -1179,7 +1178,6 @@ do
end
break
else
local on_remove = id_record.hooks.on_remove
local to = archetype_traverse_remove(world, id, idr_t_archetype)
if on_remove then
for _, child in children do
@ -2313,7 +2311,7 @@ export type World = {
}
return {
World = World :: { new: () -> World },
World = World,
OnAdd = EcsOnAdd :: Entity<(entity: Entity) -> ()>,
OnRemove = EcsOnRemove :: Entity<(entity: Entity) -> ()>,

View file

@ -1659,66 +1659,4 @@ TEST("wildcard query", function()
CHECK(counter == 1)
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()