Skip to content

Commit

Permalink
Optimize removal of children
Browse files Browse the repository at this point in the history
  • Loading branch information
Ukendio committed Jan 14, 2025
1 parent 4392f94 commit bacf056
Showing 1 changed file with 14 additions and 3 deletions.
17 changes: 14 additions & 3 deletions jecs.luau
Original file line number Diff line number Diff line change
Expand Up @@ -764,7 +764,7 @@ local function create_edge_for_remove(world: World, node: Archetype, edge: Graph
return to
end

local function archetype_traverse_add(world: World, id: i53, from: Archetype?): Archetype
local function archetype_traverse_add(world: World, id: i53, from: Archetype): Archetype
from = from or world.ROOT_ARCHETYPE
local edge = archetype_ensure_edge(world, from.add, id)

Expand Down Expand Up @@ -1156,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)
Expand All @@ -1177,8 +1178,18 @@ do
end
break
else
for _, child in children do
world_remove(world, child, id)
local to = archetype_traverse_remove(world, id, idr_t_archetype)
if on_remove then
for _, child in children do
on_remove(child)
local r = entity_index_try_get_fast(entity_index, child) :: Record
entity_move(entity_index, child, r, to)
end
else
for _, child in children do
local r = entity_index_try_get_fast(entity_index, child) :: Record
entity_move(entity_index, child, r, to)
end
end
end
end
Expand Down

0 comments on commit bacf056

Please sign in to comment.