mirror of
https://github.com/Ukendio/jecs.git
synced 2025-08-04 03:09:18 +00:00
Optimize removal path
This commit is contained in:
parent
95a9fecbd0
commit
c4da2c2b02
1 changed files with 34 additions and 8 deletions
42
jecs.luau
42
jecs.luau
|
@ -2582,15 +2582,41 @@ local function world_new()
|
||||||
archetype_destroy(world, idr_archetype)
|
archetype_destroy(world, idr_archetype)
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
for archetype_id in idr.records do
|
local on_remove = idr.hooks.on_remove
|
||||||
local idr_archetype = archetypes[archetype_id]
|
if on_remove then
|
||||||
local entities = idr_archetype.entities
|
for archetype_id in idr.records do
|
||||||
local n = #entities
|
local idr_archetype = archetypes[archetype_id]
|
||||||
for i = n, 1, -1 do
|
local to = archetype_traverse_remove(world, entity, idr_archetype)
|
||||||
inner_world_remove(world, entities[i], entity)
|
local entities = idr_archetype.entities
|
||||||
end
|
local n = #entities
|
||||||
|
for i = n, 1, -1 do
|
||||||
|
local e = entities[i]
|
||||||
|
on_remove(e, entity)
|
||||||
|
local r = eindex_sparse_array[ECS_ID(e :: number)]
|
||||||
|
local from = r.archetype
|
||||||
|
if from ~= idr_archetype then
|
||||||
|
-- unfortunately the on_remove hook allows a window where `e` can have changed archetype
|
||||||
|
-- this is hypothetically not that expensive of an operation anyways
|
||||||
|
to = archetype_traverse_remove(world, entity, from)
|
||||||
|
end
|
||||||
|
entity_move(entity_index, e, r, to)
|
||||||
|
end
|
||||||
|
|
||||||
archetype_destroy(world, idr_archetype)
|
archetype_destroy(world, idr_archetype)
|
||||||
|
end
|
||||||
|
else
|
||||||
|
for archetype_id in idr.records do
|
||||||
|
local idr_archetype = archetypes[archetype_id]
|
||||||
|
local to = archetype_traverse_remove(world, entity, idr_archetype)
|
||||||
|
local entities = idr_archetype.entities
|
||||||
|
local n = #entities
|
||||||
|
for i = n, 1, -1 do
|
||||||
|
local e = entities[i]
|
||||||
|
entity_move(entity_index, e, eindex_sparse_array[ECS_ID(e :: number)], to)
|
||||||
|
end
|
||||||
|
|
||||||
|
archetype_destroy(world, idr_archetype)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue