mirror of
https://github.com/Ukendio/jecs.git
synced 2025-07-09 08:09:18 +00:00
Remove second loop in archetype destroy
This commit is contained in:
parent
8fd32978b4
commit
29305cac5d
1 changed files with 73 additions and 105 deletions
100
jecs.luau
100
jecs.luau
|
@ -42,14 +42,12 @@ export type Iter<T...> = (query: Query<T...>) -> () -> (Entity, T...)
|
||||||
export type Query<T...> = typeof(setmetatable(
|
export type Query<T...> = typeof(setmetatable(
|
||||||
{} :: {
|
{} :: {
|
||||||
iter: Iter<T...>,
|
iter: Iter<T...>,
|
||||||
with:
|
with: (<a>(Query<T...>, Id<a>) -> Query<T...>)
|
||||||
(<a>(Query<T...>, Id<a>) -> Query<T...>)
|
|
||||||
& (<a, b>(Query<T...>, Id<a>, Id<b>) -> Query<T...>)
|
& (<a, b>(Query<T...>, Id<a>, Id<b>) -> Query<T...>)
|
||||||
& (<a, b, c>(Query<T...>, Id<a>, Id<b>, Id<c>) -> Query<T...>)
|
& (<a, b, c>(Query<T...>, Id<a>, Id<b>, Id<c>) -> Query<T...>)
|
||||||
& (<a, b, c>(Query<T...>, Id<a>, Id<b>, Id<c>) -> Query<T...>)
|
& (<a, b, c>(Query<T...>, Id<a>, Id<b>, Id<c>) -> Query<T...>)
|
||||||
& (<a, b, c, d>(Query<T...>, Id<a>, Id<b>, Id<c>, Id) -> Query<T...>),
|
& (<a, b, c, d>(Query<T...>, Id<a>, Id<b>, Id<c>, Id) -> Query<T...>),
|
||||||
without:
|
without: (<a>(Query<T...>, Id<a>) -> Query<T...>)
|
||||||
(<a>(Query<T...>, Id<a>) -> Query<T...>)
|
|
||||||
& (<a, b>(Query<T...>, Id<a>, Id<b>) -> Query<T...>)
|
& (<a, b>(Query<T...>, Id<a>, Id<b>) -> Query<T...>)
|
||||||
& (<a, b, c>(Query<T...>, Id<a>, Id<b>, Id<c>) -> Query<T...>)
|
& (<a, b, c>(Query<T...>, Id<a>, Id<b>, Id<c>) -> Query<T...>)
|
||||||
& (<a, b, c>(Query<T...>, Id<a>, Id<b>, Id<c>) -> Query<T...>)
|
& (<a, b, c>(Query<T...>, Id<a>, Id<b>, Id<c>) -> Query<T...>)
|
||||||
|
@ -1065,6 +1063,13 @@ local function archetype_destroy(world: World, archetype: Archetype)
|
||||||
local columns_map = archetype.columns_map
|
local columns_map = archetype.columns_map
|
||||||
|
|
||||||
for id in columns_map do
|
for id in columns_map do
|
||||||
|
local idr = component_index[id]
|
||||||
|
idr.records[archetype_id] = nil :: any
|
||||||
|
idr.counts[archetype_id] = nil
|
||||||
|
idr.size -= 1
|
||||||
|
if idr.size == 0 then
|
||||||
|
component_index[id] = nil :: any
|
||||||
|
end
|
||||||
local observer_list = find_observers(world, EcsOnArchetypeDelete, id)
|
local observer_list = find_observers(world, EcsOnArchetypeDelete, id)
|
||||||
if not observer_list then
|
if not observer_list then
|
||||||
continue
|
continue
|
||||||
|
@ -1075,16 +1080,6 @@ local function archetype_destroy(world: World, archetype: Archetype)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
for id in columns_map do
|
|
||||||
local idr = component_index[id]
|
|
||||||
idr.records[archetype_id] = nil :: any
|
|
||||||
idr.counts[archetype_id] = nil
|
|
||||||
idr.size -= 1
|
|
||||||
if idr.size == 0 then
|
|
||||||
component_index[id] = nil :: any
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
local function NOOP() end
|
local function NOOP() end
|
||||||
|
@ -2422,11 +2417,26 @@ local function world_new()
|
||||||
end
|
end
|
||||||
|
|
||||||
local from: Archetype = record.archetype
|
local from: Archetype = record.archetype
|
||||||
if ECS_IS_PAIR(id::number) then
|
|
||||||
local src = from or ROOT_ARCHETYPE
|
local src = from or ROOT_ARCHETYPE
|
||||||
local edge = archetype_edges[src.id]
|
local column = src.columns_map[id]
|
||||||
local to = edge[id]
|
if column then
|
||||||
|
local idr = component_index[id]
|
||||||
|
local idr_hooks = idr.hooks
|
||||||
|
column[record.row] = data
|
||||||
|
|
||||||
|
-- If the archetypes are the same it can avoid moving the entity
|
||||||
|
-- and just set the data directly.
|
||||||
|
local on_change = idr_hooks.on_change
|
||||||
|
if on_change then
|
||||||
|
on_change(entity, id, data)
|
||||||
|
end
|
||||||
|
else
|
||||||
|
local to: Archetype
|
||||||
local idr: ComponentRecord
|
local idr: ComponentRecord
|
||||||
|
local idr_hooks
|
||||||
|
if ECS_IS_PAIR(id::number) then
|
||||||
|
local edge = archetype_edges[src.id]
|
||||||
|
to = edge[id]
|
||||||
if not to then
|
if not to then
|
||||||
local first = ECS_PAIR_FIRST(id::number)
|
local first = ECS_PAIR_FIRST(id::number)
|
||||||
local wc = ECS_PAIR(first, EcsWildcard)
|
local wc = ECS_PAIR(first, EcsWildcard)
|
||||||
|
@ -2457,55 +2467,10 @@ local function world_new()
|
||||||
else
|
else
|
||||||
idr = component_index[id]
|
idr = component_index[id]
|
||||||
end
|
end
|
||||||
local idr_hooks = idr.hooks
|
idr_hooks = idr.hooks
|
||||||
if from == to then
|
|
||||||
local column = to.columns_map[id]
|
|
||||||
column[record.row] = data
|
|
||||||
|
|
||||||
-- If the archetypes are the same it can avoid moving the entity
|
|
||||||
-- and just set the data directly.
|
|
||||||
local on_change = idr_hooks.on_change
|
|
||||||
if on_change then
|
|
||||||
on_change(entity, id, data)
|
|
||||||
end
|
|
||||||
|
|
||||||
return
|
|
||||||
end
|
|
||||||
|
|
||||||
if from then
|
|
||||||
entity_move(entity_index, entity, record, to)
|
|
||||||
else
|
else
|
||||||
if #to.types > 0 then
|
to = inner_archetype_traverse_add(id, from)
|
||||||
new_entity(entity, record, to)
|
idr = component_index[id]
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
local column = to.columns_map[id]
|
|
||||||
column[record.row] = data
|
|
||||||
|
|
||||||
local on_add = idr.hooks.on_add
|
|
||||||
|
|
||||||
if on_add then
|
|
||||||
on_add(entity, id)
|
|
||||||
end
|
|
||||||
return
|
|
||||||
end
|
|
||||||
local to: Archetype = inner_archetype_traverse_add(id, from)
|
|
||||||
local idr = component_index[id]
|
|
||||||
local idr_hooks = idr.hooks
|
|
||||||
|
|
||||||
if from == to then
|
|
||||||
local column = to.columns_map[id]
|
|
||||||
column[record.row] = data
|
|
||||||
|
|
||||||
-- If the archetypes are the same it can avoid moving the entity
|
|
||||||
-- and just set the data directly.
|
|
||||||
local on_change = idr_hooks.on_change
|
|
||||||
if on_change then
|
|
||||||
on_change(entity, id, data)
|
|
||||||
end
|
|
||||||
|
|
||||||
return
|
|
||||||
end
|
end
|
||||||
|
|
||||||
if from then
|
if from then
|
||||||
|
@ -2514,7 +2479,9 @@ local function world_new()
|
||||||
else
|
else
|
||||||
new_entity(entity, record, to)
|
new_entity(entity, record, to)
|
||||||
end
|
end
|
||||||
local column = to.columns_map[id]
|
|
||||||
|
idr_hooks = idr.hooks
|
||||||
|
column = to.columns_map[id]
|
||||||
column[record.row] = data
|
column[record.row] = data
|
||||||
|
|
||||||
local on_add = idr_hooks.on_add
|
local on_add = idr_hooks.on_add
|
||||||
|
@ -2522,6 +2489,7 @@ local function world_new()
|
||||||
on_add(entity, id, data)
|
on_add(entity, id, data)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
end
|
||||||
|
|
||||||
local function inner_world_entity<T>(world: World, entity: Entity<T>?): Entity<T>
|
local function inner_world_entity<T>(world: World, entity: Entity<T>?): Entity<T>
|
||||||
if entity then
|
if entity then
|
||||||
|
|
Loading…
Reference in a new issue