mirror of
https://github.com/Ukendio/jecs.git
synced 2025-04-24 17:10:03 +00:00
Less allocation better?!
This commit is contained in:
parent
dec958b058
commit
31179d21c4
2 changed files with 25 additions and 20 deletions
|
@ -12,6 +12,7 @@ The format is based on [Keep a Changelog][kac], and this project adheres to
|
||||||
|
|
||||||
- `[world]`:
|
- `[world]`:
|
||||||
- 16% faster `world:get`
|
- 16% faster `world:get`
|
||||||
|
- 22% faster at deleting children
|
||||||
- `[typescript]`
|
- `[typescript]`
|
||||||
|
|
||||||
- Fixed Entity type to default to `undefined | unknown` instead of just `undefined`
|
- Fixed Entity type to default to `undefined | unknown` instead of just `undefined`
|
||||||
|
|
44
jecs.luau
44
jecs.luau
|
@ -1058,37 +1058,40 @@ do
|
||||||
local idr = component_index[delete]
|
local idr = component_index[delete]
|
||||||
|
|
||||||
if idr then
|
if idr then
|
||||||
local children = {}
|
|
||||||
for archetype_id in idr.cache do
|
|
||||||
local idr_archetype = archetypes[archetype_id]
|
|
||||||
|
|
||||||
for i, child in idr_archetype.entities do
|
|
||||||
table.insert(children, child)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
local flags = idr.flags
|
local flags = idr.flags
|
||||||
if bit32.band(flags, ECS_ID_DELETE) ~= 0 then
|
if bit32.band(flags, ECS_ID_DELETE) ~= 0 then
|
||||||
for _, child in children do
|
for archetype_id in idr.cache do
|
||||||
-- Cascade deletion to children
|
local idr_archetype = archetypes[archetype_id]
|
||||||
world_delete(world, child)
|
|
||||||
|
local ents = idr_archetype.entities
|
||||||
|
local n = #ents
|
||||||
|
for i = n, 1, -1 do
|
||||||
|
local child = ents[i]
|
||||||
|
world_delete(world, child)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
for _, child in children do
|
for archetype_id in idr.cache do
|
||||||
world_remove(world, child, delete)
|
local idr_archetype = archetypes[archetype_id]
|
||||||
|
|
||||||
|
local ents = idr_archetype.entities
|
||||||
|
local n = #ents
|
||||||
|
for i = n, 1, -1 do
|
||||||
|
local child = ents[i]
|
||||||
|
world_remove(world, child, delete)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
if idr_t then
|
if idr_t then
|
||||||
for archetype_id in idr_t.cache do
|
for archetype_id in idr_t.cache do
|
||||||
local children = {}
|
|
||||||
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
|
||||||
|
|
||||||
for _, child in idr_t_archetype.entities do
|
local ents = idr_t_archetype.entities
|
||||||
table.insert(children, child)
|
local n = #ents
|
||||||
end
|
|
||||||
|
|
||||||
for _, id in idr_t_types do
|
for _, id in idr_t_types do
|
||||||
if not ECS_IS_PAIR(id) then
|
if not ECS_IS_PAIR(id) then
|
||||||
|
@ -1100,13 +1103,14 @@ do
|
||||||
local flags = id_record.flags
|
local flags = id_record.flags
|
||||||
local flags_delete_mask: number = bit32.band(flags, ECS_ID_DELETE)
|
local flags_delete_mask: number = bit32.band(flags, ECS_ID_DELETE)
|
||||||
if flags_delete_mask ~= 0 then
|
if flags_delete_mask ~= 0 then
|
||||||
for _, child in children do
|
for i = n, 1, -1 do
|
||||||
-- Cascade deletions of it has Delete as component trait
|
local child = ents[i]
|
||||||
world_delete(world, child, destruct)
|
world_delete(world, child, destruct)
|
||||||
end
|
end
|
||||||
break
|
break
|
||||||
else
|
else
|
||||||
for _, child in children do
|
for i = n, 1, -1 do
|
||||||
|
local child = ents[i]
|
||||||
world_remove(world, child, id)
|
world_remove(world, child, id)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue