|
|
|
|
@@ -141,8 +141,8 @@ local __minor_chunks = {} ---@type table<evolved.fragment, evolved.assoc_list<ev
|
|
|
|
|
local __query_chunks = {} ---@type table<evolved.query, evolved.assoc_list<evolved.chunk>>
|
|
|
|
|
local __major_queries = {} ---@type table<evolved.fragment, evolved.assoc_list<evolved.query>>
|
|
|
|
|
|
|
|
|
|
local __entity_chunks = {} ---@type (evolved.chunk|false)[]
|
|
|
|
|
local __entity_places = {} ---@type integer[]
|
|
|
|
|
local __entity_chunks = {} ---@type table<integer, evolved.chunk>
|
|
|
|
|
local __entity_places = {} ---@type table<integer, integer>
|
|
|
|
|
|
|
|
|
|
local __sorted_includes = {} ---@type table<evolved.query, evolved.assoc_list<evolved.fragment>>
|
|
|
|
|
local __sorted_excludes = {} ---@type table<evolved.query, evolved.assoc_list<evolved.fragment>>
|
|
|
|
|
@@ -243,13 +243,8 @@ local __lua_table_new = (function()
|
|
|
|
|
if table_create then return function(nseq) return table_create(nseq or 0) end end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
if package and package.loaded then
|
|
|
|
|
local loaded_table_create = package.loaded.table and package.loaded.table.create
|
|
|
|
|
if loaded_table_create then return function(nseq) return loaded_table_create(nseq or 0) end end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
if package and package.preload then
|
|
|
|
|
local table_new_loader = package.preload['table.new']
|
|
|
|
|
do
|
|
|
|
|
local table_new_loader = package and package.preload and package.preload['table.new']
|
|
|
|
|
local table_new = table_new_loader and table_new_loader()
|
|
|
|
|
if table_new then return function(nseq) return table_new(nseq or 0, 0) end end
|
|
|
|
|
end
|
|
|
|
|
@@ -270,13 +265,8 @@ local __lua_table_clear = (function()
|
|
|
|
|
if table_clear then return table_clear end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
if package and package.loaded then
|
|
|
|
|
local loaded_table_clear = package.loaded.table and package.loaded.table.clear
|
|
|
|
|
if loaded_table_clear then return loaded_table_clear end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
if package and package.preload then
|
|
|
|
|
local table_clear_loader = package.preload['table.clear']
|
|
|
|
|
do
|
|
|
|
|
local table_clear_loader = package and package.preload and package.preload['table.clear']
|
|
|
|
|
local table_clear = table_clear_loader and table_clear_loader()
|
|
|
|
|
if table_clear then return table_clear end
|
|
|
|
|
end
|
|
|
|
|
@@ -309,13 +299,8 @@ local __lua_table_move = (function()
|
|
|
|
|
if table_move then return table_move end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
if package and package.loaded then
|
|
|
|
|
local loaded_table_move = package.loaded.table and package.loaded.table.move
|
|
|
|
|
if loaded_table_move then return loaded_table_move end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
if package and package.preload then
|
|
|
|
|
local table_move_loader = package.preload['table.move']
|
|
|
|
|
do
|
|
|
|
|
local table_move_loader = package and package.preload and package.preload['table.move']
|
|
|
|
|
local table_move = table_move_loader and table_move_loader()
|
|
|
|
|
if table_move then return table_move end
|
|
|
|
|
end
|
|
|
|
|
@@ -674,9 +659,6 @@ local function __acquire_id()
|
|
|
|
|
local acquired_id = acquired_primary + shifted_secondary
|
|
|
|
|
freelist_ids[acquired_primary] = acquired_id
|
|
|
|
|
|
|
|
|
|
__entity_chunks[acquired_primary] = false
|
|
|
|
|
__entity_places[acquired_primary] = 0
|
|
|
|
|
|
|
|
|
|
return acquired_id --[[@as evolved.id]]
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
@@ -803,28 +785,29 @@ end
|
|
|
|
|
---
|
|
|
|
|
---
|
|
|
|
|
|
|
|
|
|
local __list_fns = {}
|
|
|
|
|
local __list_new
|
|
|
|
|
local __list_dup
|
|
|
|
|
local __list_lwr
|
|
|
|
|
|
|
|
|
|
---@param reserve? integer
|
|
|
|
|
---@return any[]
|
|
|
|
|
---@nodiscard
|
|
|
|
|
function __list_fns.new(reserve)
|
|
|
|
|
function __list_new(reserve)
|
|
|
|
|
return __lua_table_new(reserve)
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
---@generic V
|
|
|
|
|
---@param list V[]
|
|
|
|
|
---@param size? integer
|
|
|
|
|
---@return V[]
|
|
|
|
|
---@nodiscard
|
|
|
|
|
function __list_fns.dup(list, size)
|
|
|
|
|
local list_size = size or #list
|
|
|
|
|
function __list_dup(list)
|
|
|
|
|
local list_size = #list
|
|
|
|
|
|
|
|
|
|
if list_size == 0 then
|
|
|
|
|
return {}
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
local dup_list = __list_fns.new(list_size)
|
|
|
|
|
local dup_list = __list_new(list_size)
|
|
|
|
|
|
|
|
|
|
__lua_table_move(
|
|
|
|
|
list, 1, list_size,
|
|
|
|
|
@@ -837,11 +820,10 @@ end
|
|
|
|
|
---@param list V[]
|
|
|
|
|
---@param item V
|
|
|
|
|
---@param comp? fun(a: V, b: V): boolean
|
|
|
|
|
---@param size? integer
|
|
|
|
|
---@return integer lower_bound_index
|
|
|
|
|
---@nodiscard
|
|
|
|
|
function __list_fns.lwr(list, item, comp, size)
|
|
|
|
|
local lower, upper = 1, size or #list
|
|
|
|
|
function __list_lwr(list, item, comp)
|
|
|
|
|
local lower, upper = 1, #list
|
|
|
|
|
|
|
|
|
|
if comp then
|
|
|
|
|
while lower <= upper do
|
|
|
|
|
@@ -882,12 +864,20 @@ end
|
|
|
|
|
--- __item_count: integer,
|
|
|
|
|
--- }
|
|
|
|
|
|
|
|
|
|
local __assoc_list_fns = {}
|
|
|
|
|
local __assoc_list_new
|
|
|
|
|
local __assoc_list_move
|
|
|
|
|
local __assoc_list_move_ex
|
|
|
|
|
local __assoc_list_sort
|
|
|
|
|
local __assoc_list_sort_ex
|
|
|
|
|
local __assoc_list_insert
|
|
|
|
|
local __assoc_list_insert_ex
|
|
|
|
|
local __assoc_list_remove
|
|
|
|
|
local __assoc_list_remove_ex
|
|
|
|
|
|
|
|
|
|
---@param reserve? integer
|
|
|
|
|
---@return evolved.assoc_list
|
|
|
|
|
---@nodiscard
|
|
|
|
|
function __assoc_list_fns.new(reserve)
|
|
|
|
|
function __assoc_list_new(reserve)
|
|
|
|
|
---@type evolved.assoc_list
|
|
|
|
|
return {
|
|
|
|
|
__item_set = __lua_table_new(),
|
|
|
|
|
@@ -902,8 +892,8 @@ end
|
|
|
|
|
---@param src_item_last integer
|
|
|
|
|
---@param dst_al evolved.assoc_list<K>
|
|
|
|
|
---@return integer new_dst_item_count
|
|
|
|
|
function __assoc_list_fns.move(src_item_list, src_item_first, src_item_last, dst_al)
|
|
|
|
|
local new_dst_item_count = __assoc_list_fns.move_ex(
|
|
|
|
|
function __assoc_list_move(src_item_list, src_item_first, src_item_last, dst_al)
|
|
|
|
|
local new_dst_item_count = __assoc_list_move_ex(
|
|
|
|
|
src_item_list, src_item_first, src_item_last,
|
|
|
|
|
dst_al.__item_set, dst_al.__item_list, dst_al.__item_count)
|
|
|
|
|
|
|
|
|
|
@@ -920,8 +910,8 @@ end
|
|
|
|
|
---@param dst_item_count integer
|
|
|
|
|
---@return integer new_dst_item_count
|
|
|
|
|
---@nodiscard
|
|
|
|
|
function __assoc_list_fns.move_ex(src_item_list, src_item_first, src_item_last,
|
|
|
|
|
dst_item_set, dst_item_list, dst_item_count)
|
|
|
|
|
function __assoc_list_move_ex(src_item_list, src_item_first, src_item_last,
|
|
|
|
|
dst_item_set, dst_item_list, dst_item_count)
|
|
|
|
|
if src_item_last < src_item_first then
|
|
|
|
|
return dst_item_count
|
|
|
|
|
end
|
|
|
|
|
@@ -941,8 +931,8 @@ end
|
|
|
|
|
---@generic K
|
|
|
|
|
---@param al evolved.assoc_list<K>
|
|
|
|
|
---@param comp? fun(a: K, b: K): boolean
|
|
|
|
|
function __assoc_list_fns.sort(al, comp)
|
|
|
|
|
__assoc_list_fns.sort_ex(
|
|
|
|
|
function __assoc_list_sort(al, comp)
|
|
|
|
|
__assoc_list_sort_ex(
|
|
|
|
|
al.__item_set, al.__item_list, al.__item_count,
|
|
|
|
|
comp)
|
|
|
|
|
end
|
|
|
|
|
@@ -952,7 +942,7 @@ end
|
|
|
|
|
---@param al_item_list K[]
|
|
|
|
|
---@param al_item_count integer
|
|
|
|
|
---@param comp? fun(a: K, b: K): boolean
|
|
|
|
|
function __assoc_list_fns.sort_ex(al_item_set, al_item_list, al_item_count, comp)
|
|
|
|
|
function __assoc_list_sort_ex(al_item_set, al_item_list, al_item_count, comp)
|
|
|
|
|
if al_item_count < 2 then
|
|
|
|
|
return
|
|
|
|
|
end
|
|
|
|
|
@@ -969,8 +959,8 @@ end
|
|
|
|
|
---@param al evolved.assoc_list<K>
|
|
|
|
|
---@param item K
|
|
|
|
|
---@return integer new_al_count
|
|
|
|
|
function __assoc_list_fns.insert(al, item)
|
|
|
|
|
local new_al_count = __assoc_list_fns.insert_ex(
|
|
|
|
|
function __assoc_list_insert(al, item)
|
|
|
|
|
local new_al_count = __assoc_list_insert_ex(
|
|
|
|
|
al.__item_set, al.__item_list, al.__item_count,
|
|
|
|
|
item)
|
|
|
|
|
|
|
|
|
|
@@ -985,7 +975,7 @@ end
|
|
|
|
|
---@param item K
|
|
|
|
|
---@return integer new_al_count
|
|
|
|
|
---@nodiscard
|
|
|
|
|
function __assoc_list_fns.insert_ex(al_item_set, al_item_list, al_item_count, item)
|
|
|
|
|
function __assoc_list_insert_ex(al_item_set, al_item_list, al_item_count, item)
|
|
|
|
|
local item_index = al_item_set[item]
|
|
|
|
|
|
|
|
|
|
if item_index then
|
|
|
|
|
@@ -1003,8 +993,8 @@ end
|
|
|
|
|
---@param al evolved.assoc_list<K>
|
|
|
|
|
---@param item K
|
|
|
|
|
---@return integer new_al_count
|
|
|
|
|
function __assoc_list_fns.remove(al, item)
|
|
|
|
|
local new_al_count = __assoc_list_fns.remove_ex(
|
|
|
|
|
function __assoc_list_remove(al, item)
|
|
|
|
|
local new_al_count = __assoc_list_remove_ex(
|
|
|
|
|
al.__item_set, al.__item_list, al.__item_count,
|
|
|
|
|
item)
|
|
|
|
|
|
|
|
|
|
@@ -1019,7 +1009,7 @@ end
|
|
|
|
|
---@param item K
|
|
|
|
|
---@return integer new_al_count
|
|
|
|
|
---@nodiscard
|
|
|
|
|
function __assoc_list_fns.remove_ex(al_item_set, al_item_list, al_item_count, item)
|
|
|
|
|
function __assoc_list_remove_ex(al_item_set, al_item_list, al_item_count, item)
|
|
|
|
|
local item_index = al_item_set[item]
|
|
|
|
|
|
|
|
|
|
if not item_index then
|
|
|
|
|
@@ -1290,7 +1280,7 @@ function __new_chunk(chunk_parent, chunk_fragment)
|
|
|
|
|
local chunk_parent_fragment_list = chunk_parent.__fragment_list
|
|
|
|
|
local chunk_parent_fragment_count = chunk_parent.__fragment_count
|
|
|
|
|
|
|
|
|
|
chunk_fragment_count = __assoc_list_fns.move_ex(
|
|
|
|
|
chunk_fragment_count = __assoc_list_move_ex(
|
|
|
|
|
chunk_parent_fragment_list, 1, chunk_parent_fragment_count,
|
|
|
|
|
chunk_fragment_set, chunk_fragment_list, chunk_fragment_count)
|
|
|
|
|
end
|
|
|
|
|
@@ -1355,11 +1345,11 @@ function __new_chunk(chunk_parent, chunk_fragment)
|
|
|
|
|
|
|
|
|
|
if not major_chunks then
|
|
|
|
|
---@type evolved.assoc_list<evolved.chunk>
|
|
|
|
|
major_chunks = __assoc_list_fns.new(4)
|
|
|
|
|
major_chunks = __assoc_list_new(4)
|
|
|
|
|
__major_chunks[major] = major_chunks
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
__assoc_list_fns.insert(major_chunks, chunk)
|
|
|
|
|
__assoc_list_insert(major_chunks, chunk)
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
for chunk_fragment_index = 1, chunk_fragment_count do
|
|
|
|
|
@@ -1368,11 +1358,11 @@ function __new_chunk(chunk_parent, chunk_fragment)
|
|
|
|
|
|
|
|
|
|
if not minor_chunks then
|
|
|
|
|
---@type evolved.assoc_list<evolved.chunk>
|
|
|
|
|
minor_chunks = __assoc_list_fns.new(4)
|
|
|
|
|
minor_chunks = __assoc_list_new(4)
|
|
|
|
|
__minor_chunks[minor] = minor_chunks
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
__assoc_list_fns.insert(minor_chunks, chunk)
|
|
|
|
|
__assoc_list_insert(minor_chunks, chunk)
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
__update_chunk_caches(chunk)
|
|
|
|
|
@@ -1415,9 +1405,9 @@ end
|
|
|
|
|
|
|
|
|
|
---@param root evolved.chunk
|
|
|
|
|
function __add_root_chunk(root)
|
|
|
|
|
local root_index = __list_fns.lwr(__root_list, root, function(a, b)
|
|
|
|
|
local root_index = __list_lwr(__root_list, root, function(a, b)
|
|
|
|
|
return a.__fragment < b.__fragment
|
|
|
|
|
end, __root_count)
|
|
|
|
|
end)
|
|
|
|
|
|
|
|
|
|
for sib_root_index = __root_count, root_index, -1 do
|
|
|
|
|
local sib_root = __root_list[sib_root_index]
|
|
|
|
|
@@ -1460,9 +1450,9 @@ end
|
|
|
|
|
---@param child evolved.chunk
|
|
|
|
|
---@param parent evolved.chunk
|
|
|
|
|
function __add_child_chunk(child, parent)
|
|
|
|
|
local child_index = __list_fns.lwr(parent.__child_list, child, function(a, b)
|
|
|
|
|
local child_index = __list_lwr(parent.__child_list, child, function(a, b)
|
|
|
|
|
return a.__fragment < b.__fragment
|
|
|
|
|
end, parent.__child_count)
|
|
|
|
|
end)
|
|
|
|
|
|
|
|
|
|
for sib_child_index = parent.__child_count, child_index, -1 do
|
|
|
|
|
local sib_child = parent.__child_list[sib_child_index]
|
|
|
|
|
@@ -1614,9 +1604,9 @@ function __update_chunk_queries(chunk)
|
|
|
|
|
|
|
|
|
|
if major_query_chunks then
|
|
|
|
|
if __query_major_matches(chunk, major_query) then
|
|
|
|
|
__assoc_list_fns.insert(major_query_chunks, chunk)
|
|
|
|
|
__assoc_list_insert(major_query_chunks, chunk)
|
|
|
|
|
else
|
|
|
|
|
__assoc_list_fns.remove(major_query_chunks, chunk)
|
|
|
|
|
__assoc_list_remove(major_query_chunks, chunk)
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
@@ -1891,7 +1881,7 @@ function __cache_query_chunks(query)
|
|
|
|
|
local query_variant_count = query_variants and query_variants.__item_count or 0
|
|
|
|
|
|
|
|
|
|
---@type evolved.assoc_list<evolved.chunk>
|
|
|
|
|
local query_chunks = __assoc_list_fns.new(4)
|
|
|
|
|
local query_chunks = __assoc_list_new(4)
|
|
|
|
|
__query_chunks[query] = query_chunks
|
|
|
|
|
|
|
|
|
|
if query_include_count > 0 then
|
|
|
|
|
@@ -1905,7 +1895,7 @@ function __cache_query_chunks(query)
|
|
|
|
|
local major_chunk = major_chunk_list[major_chunk_index]
|
|
|
|
|
|
|
|
|
|
if __query_major_matches(major_chunk, query) then
|
|
|
|
|
__assoc_list_fns.insert(query_chunks, major_chunk)
|
|
|
|
|
__assoc_list_insert(query_chunks, major_chunk)
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
@@ -1922,7 +1912,7 @@ function __cache_query_chunks(query)
|
|
|
|
|
local major_chunk = major_chunk_list[major_chunk_index]
|
|
|
|
|
|
|
|
|
|
if __query_major_matches(major_chunk, query) then
|
|
|
|
|
__assoc_list_fns.insert(query_chunks, major_chunk)
|
|
|
|
|
__assoc_list_insert(query_chunks, major_chunk)
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
@@ -3108,7 +3098,7 @@ function __purge_chunk(chunk)
|
|
|
|
|
local major = chunk.__fragment
|
|
|
|
|
local major_chunks = __major_chunks[major]
|
|
|
|
|
|
|
|
|
|
if major_chunks and __assoc_list_fns.remove(major_chunks, chunk) == 0 then
|
|
|
|
|
if major_chunks and __assoc_list_remove(major_chunks, chunk) == 0 then
|
|
|
|
|
__major_chunks[major] = nil
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
@@ -3117,7 +3107,7 @@ function __purge_chunk(chunk)
|
|
|
|
|
local minor = chunk.__fragment_list[chunk_fragment_index]
|
|
|
|
|
local minor_chunks = __minor_chunks[minor]
|
|
|
|
|
|
|
|
|
|
if minor_chunks and __assoc_list_fns.remove(minor_chunks, chunk) == 0 then
|
|
|
|
|
if minor_chunks and __assoc_list_remove(minor_chunks, chunk) == 0 then
|
|
|
|
|
__minor_chunks[minor] = nil
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
@@ -3335,8 +3325,8 @@ function __clear_entity_one(entity)
|
|
|
|
|
if chunk then
|
|
|
|
|
__detach_entity(chunk, place)
|
|
|
|
|
|
|
|
|
|
entity_chunks[entity_primary] = false
|
|
|
|
|
entity_places[entity_primary] = 0
|
|
|
|
|
entity_chunks[entity_primary] = nil
|
|
|
|
|
entity_places[entity_primary] = nil
|
|
|
|
|
|
|
|
|
|
__structural_changes = __structural_changes + 1
|
|
|
|
|
end
|
|
|
|
|
@@ -3402,8 +3392,8 @@ function __destroy_entity_one(entity)
|
|
|
|
|
if chunk then
|
|
|
|
|
__detach_entity(chunk, place)
|
|
|
|
|
|
|
|
|
|
entity_chunks[entity_primary] = false
|
|
|
|
|
entity_places[entity_primary] = 0
|
|
|
|
|
entity_chunks[entity_primary] = nil
|
|
|
|
|
entity_places[entity_primary] = nil
|
|
|
|
|
|
|
|
|
|
__structural_changes = __structural_changes + 1
|
|
|
|
|
end
|
|
|
|
|
@@ -4115,8 +4105,8 @@ function __chunk_remove(old_chunk, ...)
|
|
|
|
|
for old_place = 1, old_entity_count do
|
|
|
|
|
local entity = old_entity_list[old_place]
|
|
|
|
|
local entity_primary = entity % 2 ^ 20
|
|
|
|
|
entity_chunks[entity_primary] = false
|
|
|
|
|
entity_places[entity_primary] = 0
|
|
|
|
|
entity_chunks[entity_primary] = nil
|
|
|
|
|
entity_places[entity_primary] = nil
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
__detach_all_entities(old_chunk)
|
|
|
|
|
@@ -4178,8 +4168,8 @@ function __chunk_clear(chunk)
|
|
|
|
|
for place = 1, chunk_entity_count do
|
|
|
|
|
local entity = chunk_entity_list[place]
|
|
|
|
|
local entity_primary = entity % 2 ^ 20
|
|
|
|
|
entity_chunks[entity_primary] = false
|
|
|
|
|
entity_places[entity_primary] = 0
|
|
|
|
|
entity_chunks[entity_primary] = nil
|
|
|
|
|
entity_places[entity_primary] = nil
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
__detach_all_entities(chunk)
|
|
|
|
|
@@ -5226,11 +5216,11 @@ function __evolved_set(entity, fragment, component)
|
|
|
|
|
local old_chunk = entity_chunks[entity_primary]
|
|
|
|
|
local old_place = entity_places[entity_primary]
|
|
|
|
|
|
|
|
|
|
local new_chunk = __chunk_with_fragment(old_chunk or nil, fragment)
|
|
|
|
|
local new_chunk = __chunk_with_fragment(old_chunk, fragment)
|
|
|
|
|
|
|
|
|
|
__evolved_defer()
|
|
|
|
|
|
|
|
|
|
if old_chunk and old_chunk == new_chunk then
|
|
|
|
|
if old_chunk == new_chunk then
|
|
|
|
|
local old_component_indices = old_chunk.__component_indices
|
|
|
|
|
local old_component_storages = old_chunk.__component_storages
|
|
|
|
|
|
|
|
|
|
@@ -5450,11 +5440,16 @@ function __evolved_remove(entity, ...)
|
|
|
|
|
local old_chunk = entity_chunks[entity_primary]
|
|
|
|
|
local old_place = entity_places[entity_primary]
|
|
|
|
|
|
|
|
|
|
local new_chunk = __chunk_without_fragments(old_chunk or nil, ...)
|
|
|
|
|
local new_chunk = __chunk_without_fragments(old_chunk, ...)
|
|
|
|
|
|
|
|
|
|
if old_chunk == new_chunk then
|
|
|
|
|
-- nothing to remove
|
|
|
|
|
return
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
__evolved_defer()
|
|
|
|
|
|
|
|
|
|
if old_chunk and old_chunk ~= new_chunk then
|
|
|
|
|
do
|
|
|
|
|
local old_fragment_list = old_chunk.__fragment_list
|
|
|
|
|
local old_fragment_count = old_chunk.__fragment_count
|
|
|
|
|
local old_component_indices = old_chunk.__component_indices
|
|
|
|
|
@@ -5516,8 +5511,8 @@ function __evolved_remove(entity, ...)
|
|
|
|
|
do
|
|
|
|
|
__detach_entity(old_chunk, old_place)
|
|
|
|
|
|
|
|
|
|
entity_chunks[entity_primary] = new_chunk or false
|
|
|
|
|
entity_places[entity_primary] = new_chunk and new_chunk.__entity_count or 0
|
|
|
|
|
entity_chunks[entity_primary] = new_chunk
|
|
|
|
|
entity_places[entity_primary] = new_chunk and new_chunk.__entity_count
|
|
|
|
|
|
|
|
|
|
__structural_changes = __structural_changes + 1
|
|
|
|
|
end
|
|
|
|
|
@@ -6126,8 +6121,7 @@ function __evolved_debug_mode(yesno)
|
|
|
|
|
__debug_mode = yesno
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
---@param no_shrink boolean?
|
|
|
|
|
function __evolved_collect_garbage(no_shrink)
|
|
|
|
|
function __evolved_collect_garbage()
|
|
|
|
|
if __defer_depth > 0 then
|
|
|
|
|
__defer_call_hook(__evolved_collect_garbage)
|
|
|
|
|
return
|
|
|
|
|
@@ -6191,16 +6185,16 @@ function __evolved_collect_garbage(no_shrink)
|
|
|
|
|
local postorder_chunk_entity_count = postorder_chunk.__entity_count
|
|
|
|
|
local postorder_chunk_entity_capacity = postorder_chunk.__entity_capacity
|
|
|
|
|
|
|
|
|
|
local can_be_purged =
|
|
|
|
|
local should_be_purged =
|
|
|
|
|
postorder_chunk_child_count == 0 and
|
|
|
|
|
postorder_chunk_entity_count == 0
|
|
|
|
|
|
|
|
|
|
local can_be_shrunk =
|
|
|
|
|
local should_be_shrunk =
|
|
|
|
|
postorder_chunk_entity_count < postorder_chunk_entity_capacity
|
|
|
|
|
|
|
|
|
|
if can_be_purged then
|
|
|
|
|
if should_be_purged then
|
|
|
|
|
__purge_chunk(postorder_chunk)
|
|
|
|
|
elseif can_be_shrunk and not no_shrink then
|
|
|
|
|
elseif should_be_shrunk then
|
|
|
|
|
__shrink_chunk(postorder_chunk, 0)
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
@@ -6216,31 +6210,63 @@ function __evolved_collect_garbage(no_shrink)
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
if not no_shrink then
|
|
|
|
|
for table_pool_tag = 1, __table_pool_tag.__count do
|
|
|
|
|
local table_pool_reserve = __table_pool_reserve[table_pool_tag]
|
|
|
|
|
for table_pool_tag = 1, __table_pool_tag.__count do
|
|
|
|
|
local table_pool_reserve = __table_pool_reserve[table_pool_tag]
|
|
|
|
|
|
|
|
|
|
---@type evolved.table_pool
|
|
|
|
|
local new_table_pool = __lua_table_new(table_pool_reserve)
|
|
|
|
|
---@type evolved.table_pool
|
|
|
|
|
local new_table_pool = __lua_table_new(table_pool_reserve)
|
|
|
|
|
|
|
|
|
|
for table_pool_index = 1, table_pool_reserve do
|
|
|
|
|
new_table_pool[table_pool_index] = {}
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
new_table_pool.__size = table_pool_reserve
|
|
|
|
|
|
|
|
|
|
__tagged_table_pools[table_pool_tag] = new_table_pool
|
|
|
|
|
for table_pool_index = 1, table_pool_reserve do
|
|
|
|
|
new_table_pool[table_pool_index] = {}
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
do
|
|
|
|
|
__entity_chunks = __list_fns.dup(__entity_chunks, __acquired_count)
|
|
|
|
|
__entity_places = __list_fns.dup(__entity_places, __acquired_count)
|
|
|
|
|
new_table_pool.__size = table_pool_reserve
|
|
|
|
|
|
|
|
|
|
__tagged_table_pools[table_pool_tag] = new_table_pool
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
do
|
|
|
|
|
---@type table<integer, evolved.chunk>
|
|
|
|
|
local new_entity_chunks = {}
|
|
|
|
|
|
|
|
|
|
for entity_primary, entity_chunk in __lua_next, __entity_chunks do
|
|
|
|
|
new_entity_chunks[entity_primary] = entity_chunk
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
do
|
|
|
|
|
__defer_points = __list_fns.dup(__defer_points, __defer_depth)
|
|
|
|
|
__defer_bytecode = __list_fns.dup(__defer_bytecode, __defer_length)
|
|
|
|
|
__entity_chunks = new_entity_chunks
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
do
|
|
|
|
|
---@type table<integer, integer>
|
|
|
|
|
local new_entity_places = {}
|
|
|
|
|
|
|
|
|
|
for entity_primary, entity_place in __lua_next, __entity_places do
|
|
|
|
|
new_entity_places[entity_primary] = entity_place
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
__entity_places = new_entity_places
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
do
|
|
|
|
|
---@type integer[]
|
|
|
|
|
local new_defer_points = __lua_table_new(__defer_depth)
|
|
|
|
|
|
|
|
|
|
__lua_table_move(
|
|
|
|
|
__defer_points, 1, __defer_depth,
|
|
|
|
|
1, new_defer_points)
|
|
|
|
|
|
|
|
|
|
__defer_points = new_defer_points
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
do
|
|
|
|
|
---@type any[]
|
|
|
|
|
local new_defer_bytecode = __lua_table_new(__defer_length)
|
|
|
|
|
|
|
|
|
|
__lua_table_move(
|
|
|
|
|
__defer_bytecode, 1, __defer_length,
|
|
|
|
|
1, new_defer_bytecode)
|
|
|
|
|
|
|
|
|
|
__defer_bytecode = new_defer_bytecode
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
__evolved_commit()
|
|
|
|
|
@@ -6746,7 +6772,7 @@ end
|
|
|
|
|
---@return evolved.builder builder
|
|
|
|
|
function __builder_mt:clear()
|
|
|
|
|
self.__chunk = nil
|
|
|
|
|
__lua_table_clear(self.__component_table, true, false)
|
|
|
|
|
__lua_table_clear(self.__component_table)
|
|
|
|
|
return self
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
@@ -6823,7 +6849,7 @@ function __builder_mt:include(...)
|
|
|
|
|
local include_count = include_list and #include_list or 0
|
|
|
|
|
|
|
|
|
|
if include_count == 0 then
|
|
|
|
|
include_list = __list_fns.new(argument_count)
|
|
|
|
|
include_list = __list_new(argument_count)
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
for argument_index = 1, argument_count do
|
|
|
|
|
@@ -6848,7 +6874,7 @@ function __builder_mt:exclude(...)
|
|
|
|
|
local exclude_count = exclude_list and #exclude_list or 0
|
|
|
|
|
|
|
|
|
|
if exclude_count == 0 then
|
|
|
|
|
exclude_list = __list_fns.new(argument_count)
|
|
|
|
|
exclude_list = __list_new(argument_count)
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
for argument_index = 1, argument_count do
|
|
|
|
|
@@ -6873,7 +6899,7 @@ function __builder_mt:variant(...)
|
|
|
|
|
local variant_count = variant_list and #variant_list or 0
|
|
|
|
|
|
|
|
|
|
if variant_count == 0 then
|
|
|
|
|
variant_list = __list_fns.new(argument_count)
|
|
|
|
|
variant_list = __list_new(argument_count)
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
for argument_index = 1, argument_count do
|
|
|
|
|
@@ -6898,7 +6924,7 @@ function __builder_mt:require(...)
|
|
|
|
|
local require_count = require_list and #require_list or 0
|
|
|
|
|
|
|
|
|
|
if require_count == 0 then
|
|
|
|
|
require_list = __list_fns.new(argument_count)
|
|
|
|
|
require_list = __list_new(argument_count)
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
for argument_index = 1, argument_count do
|
|
|
|
|
@@ -7130,17 +7156,17 @@ __evolved_set(__DISABLED, __TAG)
|
|
|
|
|
__evolved_set(__DISABLED, __UNIQUE)
|
|
|
|
|
__evolved_set(__DISABLED, __EXPLICIT)
|
|
|
|
|
|
|
|
|
|
__evolved_set(__INCLUDES, __DEFAULT, __list_fns.new())
|
|
|
|
|
__evolved_set(__INCLUDES, __DUPLICATE, __list_fns.dup)
|
|
|
|
|
__evolved_set(__INCLUDES, __DEFAULT, __list_new())
|
|
|
|
|
__evolved_set(__INCLUDES, __DUPLICATE, __list_dup)
|
|
|
|
|
|
|
|
|
|
__evolved_set(__EXCLUDES, __DEFAULT, __list_fns.new())
|
|
|
|
|
__evolved_set(__EXCLUDES, __DUPLICATE, __list_fns.dup)
|
|
|
|
|
__evolved_set(__EXCLUDES, __DEFAULT, __list_new())
|
|
|
|
|
__evolved_set(__EXCLUDES, __DUPLICATE, __list_dup)
|
|
|
|
|
|
|
|
|
|
__evolved_set(__VARIANTS, __DEFAULT, __list_fns.new())
|
|
|
|
|
__evolved_set(__VARIANTS, __DUPLICATE, __list_fns.dup)
|
|
|
|
|
__evolved_set(__VARIANTS, __DEFAULT, __list_new())
|
|
|
|
|
__evolved_set(__VARIANTS, __DUPLICATE, __list_dup)
|
|
|
|
|
|
|
|
|
|
__evolved_set(__REQUIRES, __DEFAULT, __list_fns.new())
|
|
|
|
|
__evolved_set(__REQUIRES, __DUPLICATE, __list_fns.dup)
|
|
|
|
|
__evolved_set(__REQUIRES, __DEFAULT, __list_new())
|
|
|
|
|
__evolved_set(__REQUIRES, __DUPLICATE, __list_dup)
|
|
|
|
|
|
|
|
|
|
__evolved_set(__ON_SET, __UNIQUE)
|
|
|
|
|
__evolved_set(__ON_ASSIGN, __UNIQUE)
|
|
|
|
|
@@ -7169,11 +7195,11 @@ local function __insert_query(query)
|
|
|
|
|
|
|
|
|
|
if not major_queries then
|
|
|
|
|
---@type evolved.assoc_list<evolved.query>
|
|
|
|
|
major_queries = __assoc_list_fns.new(4)
|
|
|
|
|
major_queries = __assoc_list_new(4)
|
|
|
|
|
__major_queries[query_major] = major_queries
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
__assoc_list_fns.insert(major_queries, query)
|
|
|
|
|
__assoc_list_insert(major_queries, query)
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
for query_variant_index = 1, query_variant_count do
|
|
|
|
|
@@ -7184,11 +7210,11 @@ local function __insert_query(query)
|
|
|
|
|
|
|
|
|
|
if not major_queries then
|
|
|
|
|
---@type evolved.assoc_list<evolved.query>
|
|
|
|
|
major_queries = __assoc_list_fns.new(4)
|
|
|
|
|
major_queries = __assoc_list_new(4)
|
|
|
|
|
__major_queries[query_variant] = major_queries
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
__assoc_list_fns.insert(major_queries, query)
|
|
|
|
|
__assoc_list_insert(major_queries, query)
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
@@ -7207,7 +7233,7 @@ local function __remove_query(query)
|
|
|
|
|
local query_major = query_include_list[query_include_count]
|
|
|
|
|
local major_queries = __major_queries[query_major]
|
|
|
|
|
|
|
|
|
|
if major_queries and __assoc_list_fns.remove(major_queries, query) == 0 then
|
|
|
|
|
if major_queries and __assoc_list_remove(major_queries, query) == 0 then
|
|
|
|
|
__major_queries[query_major] = nil
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
@@ -7218,7 +7244,7 @@ local function __remove_query(query)
|
|
|
|
|
if query_include_count == 0 or query_variant > query_include_list[query_include_count] then
|
|
|
|
|
local major_queries = __major_queries[query_variant]
|
|
|
|
|
|
|
|
|
|
if major_queries and __assoc_list_fns.remove(major_queries, query) == 0 then
|
|
|
|
|
if major_queries and __assoc_list_remove(major_queries, query) == 0 then
|
|
|
|
|
__major_queries[query_variant] = nil
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
@@ -7242,10 +7268,10 @@ __evolved_set(__INCLUDES, __ON_SET, function(query, _, include_list)
|
|
|
|
|
|
|
|
|
|
if include_count > 0 then
|
|
|
|
|
---@type evolved.assoc_list<evolved.fragment>
|
|
|
|
|
local sorted_includes = __assoc_list_fns.new(include_count)
|
|
|
|
|
local sorted_includes = __assoc_list_new(include_count)
|
|
|
|
|
|
|
|
|
|
__assoc_list_fns.move(include_list, 1, include_count, sorted_includes)
|
|
|
|
|
__assoc_list_fns.sort(sorted_includes)
|
|
|
|
|
__assoc_list_move(include_list, 1, include_count, sorted_includes)
|
|
|
|
|
__assoc_list_sort(sorted_includes)
|
|
|
|
|
|
|
|
|
|
__sorted_includes[query] = sorted_includes
|
|
|
|
|
else
|
|
|
|
|
@@ -7280,10 +7306,10 @@ __evolved_set(__EXCLUDES, __ON_SET, function(query, _, exclude_list)
|
|
|
|
|
|
|
|
|
|
if exclude_count > 0 then
|
|
|
|
|
---@type evolved.assoc_list<evolved.fragment>
|
|
|
|
|
local sorted_excludes = __assoc_list_fns.new(exclude_count)
|
|
|
|
|
local sorted_excludes = __assoc_list_new(exclude_count)
|
|
|
|
|
|
|
|
|
|
__assoc_list_fns.move(exclude_list, 1, exclude_count, sorted_excludes)
|
|
|
|
|
__assoc_list_fns.sort(sorted_excludes)
|
|
|
|
|
__assoc_list_move(exclude_list, 1, exclude_count, sorted_excludes)
|
|
|
|
|
__assoc_list_sort(sorted_excludes)
|
|
|
|
|
|
|
|
|
|
__sorted_excludes[query] = sorted_excludes
|
|
|
|
|
else
|
|
|
|
|
@@ -7318,10 +7344,10 @@ __evolved_set(__VARIANTS, __ON_SET, function(query, _, variant_list)
|
|
|
|
|
|
|
|
|
|
if variant_count > 0 then
|
|
|
|
|
---@type evolved.assoc_list<evolved.fragment>
|
|
|
|
|
local sorted_variants = __assoc_list_fns.new(variant_count)
|
|
|
|
|
local sorted_variants = __assoc_list_new(variant_count)
|
|
|
|
|
|
|
|
|
|
__assoc_list_fns.move(variant_list, 1, variant_count, sorted_variants)
|
|
|
|
|
__assoc_list_fns.sort(sorted_variants)
|
|
|
|
|
__assoc_list_move(variant_list, 1, variant_count, sorted_variants)
|
|
|
|
|
__assoc_list_sort(sorted_variants)
|
|
|
|
|
|
|
|
|
|
__sorted_variants[query] = sorted_variants
|
|
|
|
|
else
|
|
|
|
|
@@ -7354,10 +7380,10 @@ __evolved_set(__REQUIRES, __ON_SET, function(fragment, _, require_list)
|
|
|
|
|
|
|
|
|
|
if require_count > 0 then
|
|
|
|
|
---@type evolved.assoc_list<evolved.fragment>
|
|
|
|
|
local sorted_requires = __assoc_list_fns.new(require_count)
|
|
|
|
|
local sorted_requires = __assoc_list_new(require_count)
|
|
|
|
|
|
|
|
|
|
__assoc_list_fns.move(require_list, 1, require_count, sorted_requires)
|
|
|
|
|
__assoc_list_fns.sort(sorted_requires)
|
|
|
|
|
__assoc_list_move(require_list, 1, require_count, sorted_requires)
|
|
|
|
|
__assoc_list_sort(sorted_requires)
|
|
|
|
|
|
|
|
|
|
__sorted_requires[fragment] = sorted_requires
|
|
|
|
|
else
|
|
|
|
|
@@ -7387,11 +7413,11 @@ local function __add_subsystem(subsystem)
|
|
|
|
|
|
|
|
|
|
if not group_subsystems then
|
|
|
|
|
---@type evolved.assoc_list<evolved.system>
|
|
|
|
|
group_subsystems = __assoc_list_fns.new(4)
|
|
|
|
|
group_subsystems = __assoc_list_new(4)
|
|
|
|
|
__group_subsystems[subsystem_group] = group_subsystems
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
__assoc_list_fns.insert(group_subsystems, subsystem)
|
|
|
|
|
__assoc_list_insert(group_subsystems, subsystem)
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
@@ -7402,7 +7428,7 @@ local function __remove_subsystem(subsystem)
|
|
|
|
|
if subsystem_group then
|
|
|
|
|
local group_subsystems = __group_subsystems[subsystem_group]
|
|
|
|
|
|
|
|
|
|
if group_subsystems and __assoc_list_fns.remove(group_subsystems, subsystem) == 0 then
|
|
|
|
|
if group_subsystems and __assoc_list_remove(group_subsystems, subsystem) == 0 then
|
|
|
|
|
__group_subsystems[subsystem_group] = nil
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|