From eac882d60435b71ac59a93f96760e4e7079d103b Mon Sep 17 00:00:00 2001 From: BlackMATov Date: Mon, 3 Mar 2025 06:55:35 +0700 Subject: [PATCH 1/7] new evolved.fragments function --- README.md | 2 ++ develop/untests.lua | 16 ++++++++++++++++ evolved.lua | 11 +++++++++++ 3 files changed, 29 insertions(+) diff --git a/README.md b/README.md index 3bc90cf..293eac1 100644 --- a/README.md +++ b/README.md @@ -94,7 +94,9 @@ batch_multi_remove :: query, fragment[] -> integer, boolean chunk :: fragment... -> chunk?, entity[]?, integer? select :: chunk, fragment... -> component[]... + entities :: chunk -> entity[], integer +fragments :: chunk -> fragment[], integer each :: entity -> {each_state? -> fragment?, component?}, each_state? execute :: query -> {execute_state? -> chunk?, entity[]?, integer?}, execute_state? diff --git a/develop/untests.lua b/develop/untests.lua index 4a49246..cf059cf 100644 --- a/develop/untests.lua +++ b/develop/untests.lua @@ -7119,3 +7119,19 @@ do assert(evo.get(f2, evo.ON_DESTROY) == evo.DESTROY_ENTITY_POLICY) assert(evo.get(f3, evo.ON_DESTROY) == evo.REMOVE_FRAGMENT_POLICY) end + +do + local f1, f2, f3 = evo.id(3) + + local c1 = evo.chunk(f1) + local c23 = evo.chunk(f2, f3) + + assert(c1 and c23) + + assert(#evo.fragments(c1) == 1) + assert(evo.fragments(c1)[1] == f1) + + assert(#evo.fragments(c23) == 2) + assert(evo.fragments(c23)[1] == f2) + assert(evo.fragments(c23)[2] == f3) +end diff --git a/evolved.lua b/evolved.lua index 3a9ce73..5c0b0fc 100644 --- a/evolved.lua +++ b/evolved.lua @@ -635,6 +635,7 @@ local __evolved_batch_multi_remove local __evolved_chunk local __evolved_select local __evolved_entities +local __evolved_fragments local __evolved_each local __evolved_execute @@ -6443,6 +6444,14 @@ __evolved_entities = function(chunk) return chunk.__entities, chunk.__entity_count end +---@param chunk evolved.chunk +---@return evolved.fragment[] fragments +---@return integer fragment_count +---@nodiscard +__evolved_fragments = function(chunk) + return chunk.__fragment_list, chunk.__fragment_count +end + ---@param entity evolved.entity ---@return evolved.each_iterator iterator ---@return evolved.each_state? iterator_state @@ -7755,7 +7764,9 @@ evolved.batch_multi_remove = __evolved_batch_multi_remove evolved.chunk = __evolved_chunk evolved.select = __evolved_select + evolved.entities = __evolved_entities +evolved.fragments = __evolved_fragments evolved.each = __evolved_each evolved.execute = __evolved_execute From 04691e11a4ac09232ad54311c734a5d4f1cddf70 Mon Sep 17 00:00:00 2001 From: BlackMATov Date: Mon, 3 Mar 2025 07:06:31 +0700 Subject: [PATCH 2/7] little naming refactoring --- evolved.lua | 234 ++++++++++++++++++++++++++-------------------------- 1 file changed, 117 insertions(+), 117 deletions(-) diff --git a/evolved.lua b/evolved.lua index 5c0b0fc..e625550 100644 --- a/evolved.lua +++ b/evolved.lua @@ -52,9 +52,9 @@ local evolved = { ---@class (exact) evolved.chunk ---@field package __parent? evolved.chunk ----@field package __children evolved.chunk[] +---@field package __child_list evolved.chunk[] ---@field package __child_count integer ----@field package __entities evolved.entity[] +---@field package __entity_list evolved.entity[] ---@field package __entity_count integer ---@field package __fragment evolved.fragment ---@field package __fragment_set table @@ -502,11 +502,11 @@ local function __execute_iterator(execute_state) chunk_stack[chunk_stack_size] = nil chunk_stack_size = chunk_stack_size - 1 - local chunk_children = chunk.__children + local chunk_child_list = chunk.__child_list local chunk_child_count = chunk.__child_count for i = chunk_child_count, 1, -1 do - local chunk_child = chunk_children[i] + local chunk_child = chunk_child_list[i] local chunk_child_fragment = chunk_child.__fragment if not exclude_set or not exclude_set[chunk_child_fragment] then @@ -515,11 +515,11 @@ local function __execute_iterator(execute_state) end end - local chunk_entities = chunk.__entities + local chunk_entity_list = chunk.__entity_list local chunk_entity_count = chunk.__entity_count if chunk_entity_count > 0 then - return chunk, chunk_entities, chunk_entity_count + return chunk, chunk_entity_list, chunk_entity_count end end @@ -736,11 +736,11 @@ local function __trace_fragment_chunks(fragment, trace, ...) chunk_stack_size = chunk_stack_size - 1 if trace(chunk, ...) then - local chunk_children = chunk.__children + local chunk_child_list = chunk.__child_list local chunk_child_count = chunk.__child_count for i = chunk_child_count, 1, -1 do - local chunk_child = chunk_children[i] + local chunk_child = chunk_child_list[i] chunk_stack_size = chunk_stack_size + 1 chunk_stack[chunk_stack_size] = chunk_child end @@ -876,9 +876,9 @@ local function __new_chunk(chunk_parent, chunk_fragment) ---@type evolved.chunk local chunk = __lua_setmetatable({ __parent = chunk_parent, - __children = {}, + __child_list = {}, __child_count = 0, - __entities = {}, + __entity_list = {}, __entity_count = 0, __fragment = chunk_fragment, __fragment_set = chunk_fragment_set, @@ -918,7 +918,7 @@ local function __new_chunk(chunk_parent, chunk_fragment) end local child_chunk_index = chunk_parent.__child_count + 1 - chunk_parent.__children[child_chunk_index] = chunk + chunk_parent.__child_list[child_chunk_index] = chunk chunk_parent.__child_count = child_chunk_index chunk_parent.__with_fragment_edges[chunk_fragment] = chunk @@ -1324,26 +1324,26 @@ local __defer_call_hook ---@param chunk evolved.chunk ---@param place integer local function __detach_entity(chunk, place) - local entities = chunk.__entities + local entity_list = chunk.__entity_list local entity_count = chunk.__entity_count local component_count = chunk.__component_count local component_storages = chunk.__component_storages if place == entity_count then - entities[place] = nil + entity_list[place] = nil for component_index = 1, component_count do local component_storage = component_storages[component_index] component_storage[place] = nil end else - local last_entity = entities[entity_count] + local last_entity = entity_list[entity_count] local last_entity_index = last_entity % 0x100000 __entity_places[last_entity_index] = place - entities[place] = last_entity - entities[entity_count] = nil + entity_list[place] = last_entity + entity_list[entity_count] = nil for component_index = 1, component_count do local component_storage = component_storages[component_index] @@ -1358,12 +1358,12 @@ end ---@param chunk evolved.chunk local function __detach_all_entities(chunk) - local entities = chunk.__entities + local entity_list = chunk.__entity_list local component_count = chunk.__component_count local component_storages = chunk.__component_storages - __lua_table_clear(entities) + __lua_table_clear(entity_list) for component_index = 1, component_count do __lua_table_clear(component_storages[component_index]) @@ -1381,7 +1381,7 @@ local function __spawn_entity_at(entity, chunk, fragments, components) __lua_error('spawn entity operations should be deferred') end - local chunk_entities = chunk.__entities + local chunk_entity_list = chunk.__entity_list local chunk_entity_count = chunk.__entity_count local chunk_component_count = chunk.__component_count @@ -1395,7 +1395,7 @@ local function __spawn_entity_at(entity, chunk, fragments, components) local place = chunk_entity_count + 1 chunk.__entity_count = place - chunk_entities[place] = entity + chunk_entity_list[place] = entity do local entity_index = entity % 0x100000 @@ -1515,7 +1515,7 @@ local function __spawn_entity_with(entity, chunk, fragments, components) __lua_error('spawn entity operations should be deferred') end - local chunk_entities = chunk.__entities + local chunk_entity_list = chunk.__entity_list local chunk_entity_count = chunk.__entity_count local chunk_component_indices = chunk.__component_indices @@ -1527,7 +1527,7 @@ local function __spawn_entity_with(entity, chunk, fragments, components) local place = chunk_entity_count + 1 chunk.__entity_count = place - chunk_entities[place] = entity + chunk_entity_list[place] = entity do local entity_index = entity % 0x100000 @@ -1719,7 +1719,7 @@ __chunk_assign = function(chunk, fragment, ...) return 0 end - local chunk_entities = chunk.__entities + local chunk_entity_list = chunk.__entity_list local chunk_entity_count = chunk.__entity_count if chunk_entity_count == 0 then @@ -1753,7 +1753,7 @@ __chunk_assign = function(chunk, fragment, ...) if fragment_default ~= nil or fragment_construct then for place = 1, chunk_entity_count do - local entity = chunk_entities[place] + local entity = chunk_entity_list[place] local old_component = component_storage[place] local new_component = ... @@ -1776,7 +1776,7 @@ __chunk_assign = function(chunk, fragment, ...) if new_component == nil then new_component = true end for place = 1, chunk_entity_count do - local entity = chunk_entities[place] + local entity = chunk_entity_list[place] local old_component = component_storage[place] component_storage[place] = new_component @@ -1792,7 +1792,7 @@ __chunk_assign = function(chunk, fragment, ...) end else for place = 1, chunk_entity_count do - local entity = chunk_entities[place] + local entity = chunk_entity_list[place] if fragment_on_set then __defer_call_hook(fragment_on_set, entity, fragment) @@ -1849,7 +1849,7 @@ __chunk_insert = function(old_chunk, fragment, ...) return 0 end - local old_entities = old_chunk.__entities + local old_entity_list = old_chunk.__entity_list local old_entity_count = old_chunk.__entity_count if old_entity_count == 0 then @@ -1860,7 +1860,7 @@ __chunk_insert = function(old_chunk, fragment, ...) local old_component_storages = old_chunk.__component_storages local old_component_fragments = old_chunk.__component_fragments - local new_entities = new_chunk.__entities + local new_entity_list = new_chunk.__entity_list local new_entity_count = new_chunk.__entity_count local new_component_indices = new_chunk.__component_indices @@ -1883,11 +1883,11 @@ __chunk_insert = function(old_chunk, fragment, ...) end if new_entity_count == 0 then - old_chunk.__entities, new_chunk.__entities = - new_entities, old_entities + old_chunk.__entity_list, new_chunk.__entity_list = + new_entity_list, old_entity_list - old_entities, new_entities = - new_entities, old_entities + old_entity_list, new_entity_list = + new_entity_list, old_entity_list for old_ci = 1, old_component_count do local old_f = old_component_fragments[old_ci] @@ -1899,8 +1899,8 @@ __chunk_insert = function(old_chunk, fragment, ...) new_chunk.__entity_count = old_entity_count else __lua_table_move( - old_entities, 1, old_entity_count, - new_entity_count + 1, new_entities) + old_entity_list, 1, old_entity_count, + new_entity_count + 1, new_entity_list) for old_ci = 1, old_component_count do local old_f = old_component_fragments[old_ci] @@ -1918,7 +1918,7 @@ __chunk_insert = function(old_chunk, fragment, ...) local entity_places = __entity_places for new_place = new_entity_count + 1, new_entity_count + old_entity_count do - local entity = new_entities[new_place] + local entity = new_entity_list[new_place] local entity_index = entity % 0x100000 entity_chunks[entity_index] = new_chunk entity_places[entity_index] = new_place @@ -1935,7 +1935,7 @@ __chunk_insert = function(old_chunk, fragment, ...) if fragment_default ~= nil or fragment_construct then for new_place = new_entity_count + 1, new_entity_count + old_entity_count do - local entity = new_entities[new_place] + local entity = new_entity_list[new_place] local new_component = ... if fragment_construct then new_component = fragment_construct(...) end @@ -1957,7 +1957,7 @@ __chunk_insert = function(old_chunk, fragment, ...) if new_component == nil then new_component = true end for new_place = new_entity_count + 1, new_entity_count + old_entity_count do - local entity = new_entities[new_place] + local entity = new_entity_list[new_place] new_component_storage[new_place] = new_component @@ -1972,7 +1972,7 @@ __chunk_insert = function(old_chunk, fragment, ...) end else for new_place = new_entity_count + 1, new_entity_count + old_entity_count do - local entity = new_entities[new_place] + local entity = new_entity_list[new_place] if fragment_on_set then __defer_call_hook(fragment_on_set, entity, fragment) @@ -2035,7 +2035,7 @@ __chunk_remove = function(old_chunk, ...) return 0 end - local old_entities = old_chunk.__entities + local old_entity_list = old_chunk.__entity_list local old_entity_count = old_chunk.__entity_count if old_entity_count == 0 then @@ -2065,13 +2065,13 @@ __chunk_remove = function(old_chunk, ...) local old_component_storage = old_component_storages[old_component_index] for old_place = 1, old_entity_count do - local entity = old_entities[old_place] + local entity = old_entity_list[old_place] local old_component = old_component_storage[old_place] __defer_call_hook(fragment_on_remove, entity, fragment, old_component) end else for old_place = 1, old_entity_count do - local entity = old_entities[old_place] + local entity = old_entity_list[old_place] __defer_call_hook(fragment_on_remove, entity, fragment) end end @@ -2083,7 +2083,7 @@ __chunk_remove = function(old_chunk, ...) end if new_chunk then - local new_entities = new_chunk.__entities + local new_entity_list = new_chunk.__entity_list local new_entity_count = new_chunk.__entity_count local new_component_count = new_chunk.__component_count @@ -2091,11 +2091,11 @@ __chunk_remove = function(old_chunk, ...) local new_component_fragments = new_chunk.__component_fragments if new_entity_count == 0 then - old_chunk.__entities, new_chunk.__entities = - new_entities, old_entities + old_chunk.__entity_list, new_chunk.__entity_list = + new_entity_list, old_entity_list - old_entities, new_entities = - new_entities, old_entities + old_entity_list, new_entity_list = + new_entity_list, old_entity_list for new_ci = 1, new_component_count do local new_f = new_component_fragments[new_ci] @@ -2107,8 +2107,8 @@ __chunk_remove = function(old_chunk, ...) new_chunk.__entity_count = old_entity_count else __lua_table_move( - old_entities, 1, old_entity_count, - new_entity_count + 1, new_entities) + old_entity_list, 1, old_entity_count, + new_entity_count + 1, new_entity_list) for new_ci = 1, new_component_count do local new_f = new_component_fragments[new_ci] @@ -2126,7 +2126,7 @@ __chunk_remove = function(old_chunk, ...) local entity_places = __entity_places for new_place = new_entity_count + 1, new_entity_count + old_entity_count do - local entity = new_entities[new_place] + local entity = new_entity_list[new_place] local entity_index = entity % 0x100000 entity_chunks[entity_index] = new_chunk entity_places[entity_index] = new_place @@ -2139,7 +2139,7 @@ __chunk_remove = function(old_chunk, ...) local entity_places = __entity_places for old_place = 1, old_entity_count do - local entity = old_entities[old_place] + local entity = old_entity_list[old_place] local entity_index = entity % 0x100000 entity_chunks[entity_index] = nil entity_places[entity_index] = nil @@ -2160,7 +2160,7 @@ __chunk_clear = function(chunk) __lua_error('batched chunk operations should be deferred') end - local chunk_entities = chunk.__entities + local chunk_entity_list = chunk.__entity_list local chunk_entity_count = chunk.__entity_count if chunk_entity_count == 0 then @@ -2187,13 +2187,13 @@ __chunk_clear = function(chunk) local component_storage = chunk_component_storages[component_index] for place = 1, chunk_entity_count do - local entity = chunk_entities[place] + local entity = chunk_entity_list[place] local old_component = component_storage[place] __defer_call_hook(fragment_on_remove, entity, fragment, old_component) end else for place = 1, chunk_entity_count do - local entity = chunk_entities[place] + local entity = chunk_entity_list[place] __defer_call_hook(fragment_on_remove, entity, fragment) end end @@ -2206,7 +2206,7 @@ __chunk_clear = function(chunk) local entity_places = __entity_places for place = 1, chunk_entity_count do - local entity = chunk_entities[place] + local entity = chunk_entity_list[place] local entity_index = entity % 0x100000 entity_chunks[entity_index] = nil entity_places[entity_index] = nil @@ -2227,7 +2227,7 @@ __chunk_destroy = function(chunk) __lua_error('batched chunk operations should be deferred') end - local chunk_entities = chunk.__entities + local chunk_entity_list = chunk.__entity_list local chunk_entity_count = chunk.__entity_count if chunk_entity_count == 0 then @@ -2254,13 +2254,13 @@ __chunk_destroy = function(chunk) local component_storage = chunk_component_storages[component_index] for place = 1, chunk_entity_count do - local entity = chunk_entities[place] + local entity = chunk_entity_list[place] local old_component = component_storage[place] __defer_call_hook(fragment_on_remove, entity, fragment, old_component) end else for place = 1, chunk_entity_count do - local entity = chunk_entities[place] + local entity = chunk_entity_list[place] __defer_call_hook(fragment_on_remove, entity, fragment) end end @@ -2277,7 +2277,7 @@ __chunk_destroy = function(chunk) local entity_places = __entity_places for place = 1, chunk_entity_count do - local entity = chunk_entities[place] + local entity = chunk_entity_list[place] local entity_index = entity % 0x100000 if __minor_chunks[entity] then @@ -2328,7 +2328,7 @@ __chunk_multi_set = function(old_chunk, fragments, components) return 0 end - local old_entities = old_chunk.__entities + local old_entity_list = old_chunk.__entity_list local old_entity_count = old_chunk.__entity_count if old_entity_count == 0 then @@ -2375,7 +2375,7 @@ __chunk_multi_set = function(old_chunk, fragments, components) if new_component == nil then new_component = true end for place = 1, old_entity_count do - local entity = old_entities[place] + local entity = old_entity_list[place] local old_component = old_component_storage[place] old_component_storage[place] = new_component @@ -2390,7 +2390,7 @@ __chunk_multi_set = function(old_chunk, fragments, components) end else for place = 1, old_entity_count do - local entity = old_entities[place] + local entity = old_entity_list[place] if fragment_on_set then __defer_call_hook(fragment_on_set, entity, fragment) @@ -2420,7 +2420,7 @@ __chunk_multi_set = function(old_chunk, fragments, components) end end else - local new_entities = new_chunk.__entities + local new_entity_list = new_chunk.__entity_list local new_entity_count = new_chunk.__entity_count local new_component_indices = new_chunk.__component_indices @@ -2431,11 +2431,11 @@ __chunk_multi_set = function(old_chunk, fragments, components) local new_chunk_has_set_or_insert_hooks = new_chunk.__has_set_or_insert_hooks if new_entity_count == 0 then - old_chunk.__entities, new_chunk.__entities = - new_entities, old_entities + old_chunk.__entity_list, new_chunk.__entity_list = + new_entity_list, old_entity_list - old_entities, new_entities = - new_entities, old_entities + old_entity_list, new_entity_list = + new_entity_list, old_entity_list for old_ci = 1, old_component_count do local old_f = old_component_fragments[old_ci] @@ -2447,8 +2447,8 @@ __chunk_multi_set = function(old_chunk, fragments, components) new_chunk.__entity_count = old_entity_count else __lua_table_move( - old_entities, 1, old_entity_count, - new_entity_count + 1, new_entities) + old_entity_list, 1, old_entity_count, + new_entity_count + 1, new_entity_list) for old_ci = 1, old_component_count do local old_f = old_component_fragments[old_ci] @@ -2466,7 +2466,7 @@ __chunk_multi_set = function(old_chunk, fragments, components) local entity_places = __entity_places for new_place = new_entity_count + 1, new_entity_count + old_entity_count do - local entity = new_entities[new_place] + local entity = new_entity_list[new_place] local entity_index = entity % 0x100000 entity_chunks[entity_index] = new_chunk entity_places[entity_index] = new_place @@ -2507,7 +2507,7 @@ __chunk_multi_set = function(old_chunk, fragments, components) if new_component == nil then new_component = true end for new_place = new_entity_count + 1, new_entity_count + old_entity_count do - local entity = new_entities[new_place] + local entity = new_entity_list[new_place] local old_component = new_component_storage[new_place] new_component_storage[new_place] = new_component @@ -2522,7 +2522,7 @@ __chunk_multi_set = function(old_chunk, fragments, components) end else for new_place = new_entity_count + 1, new_entity_count + old_entity_count do - local entity = new_entities[new_place] + local entity = new_entity_list[new_place] if fragment_on_set then __defer_call_hook(fragment_on_set, entity, fragment) @@ -2580,7 +2580,7 @@ __chunk_multi_set = function(old_chunk, fragments, components) if new_component == nil then new_component = true end for new_place = new_entity_count + 1, new_entity_count + old_entity_count do - local entity = new_entities[new_place] + local entity = new_entity_list[new_place] new_component_storage[new_place] = new_component @@ -2594,7 +2594,7 @@ __chunk_multi_set = function(old_chunk, fragments, components) end else for new_place = new_entity_count + 1, new_entity_count + old_entity_count do - local entity = new_entities[new_place] + local entity = new_entity_list[new_place] if fragment_on_set then __defer_call_hook(fragment_on_set, entity, fragment) @@ -2652,7 +2652,7 @@ __chunk_multi_assign = function(chunk, fragments, components) return 0 end - local chunk_entities = chunk.__entities + local chunk_entity_list = chunk.__entity_list local chunk_entity_count = chunk.__entity_count if chunk_entity_count == 0 then @@ -2697,7 +2697,7 @@ __chunk_multi_assign = function(chunk, fragments, components) if new_component == nil then new_component = true end for place = 1, chunk_entity_count do - local entity = chunk_entities[place] + local entity = chunk_entity_list[place] local old_component = component_storage[place] component_storage[place] = new_component @@ -2712,7 +2712,7 @@ __chunk_multi_assign = function(chunk, fragments, components) end else for place = 1, chunk_entity_count do - local entity = chunk_entities[place] + local entity = chunk_entity_list[place] if fragment_on_set then __defer_call_hook(fragment_on_set, entity, fragment) @@ -2767,7 +2767,7 @@ __chunk_multi_insert = function(old_chunk, fragments, components) return 0 end - local old_entities = old_chunk.__entities + local old_entity_list = old_chunk.__entity_list local old_entity_count = old_chunk.__entity_count if old_entity_count == 0 then @@ -2779,7 +2779,7 @@ __chunk_multi_insert = function(old_chunk, fragments, components) local old_component_storages = old_chunk.__component_storages local old_component_fragments = old_chunk.__component_fragments - local new_entities = new_chunk.__entities + local new_entity_list = new_chunk.__entity_list local new_entity_count = new_chunk.__entity_count local new_component_indices = new_chunk.__component_indices @@ -2789,11 +2789,11 @@ __chunk_multi_insert = function(old_chunk, fragments, components) local new_chunk_has_set_or_insert_hooks = new_chunk.__has_set_or_insert_hooks if new_entity_count == 0 then - old_chunk.__entities, new_chunk.__entities = - new_entities, old_entities + old_chunk.__entity_list, new_chunk.__entity_list = + new_entity_list, old_entity_list - old_entities, new_entities = - new_entities, old_entities + old_entity_list, new_entity_list = + new_entity_list, old_entity_list for old_ci = 1, old_component_count do local old_f = old_component_fragments[old_ci] @@ -2805,8 +2805,8 @@ __chunk_multi_insert = function(old_chunk, fragments, components) new_chunk.__entity_count = old_entity_count else __lua_table_move( - old_entities, 1, old_entity_count, - new_entity_count + 1, new_entities) + old_entity_list, 1, old_entity_count, + new_entity_count + 1, new_entity_list) for old_ci = 1, old_component_count do local old_f = old_component_fragments[old_ci] @@ -2824,7 +2824,7 @@ __chunk_multi_insert = function(old_chunk, fragments, components) local entity_places = __entity_places for new_place = new_entity_count + 1, new_entity_count + old_entity_count do - local entity = new_entities[new_place] + local entity = new_entity_list[new_place] local entity_index = entity % 0x100000 entity_chunks[entity_index] = new_chunk entity_places[entity_index] = new_place @@ -2868,7 +2868,7 @@ __chunk_multi_insert = function(old_chunk, fragments, components) if new_component == nil then new_component = true end for new_place = new_entity_count + 1, new_entity_count + old_entity_count do - local entity = new_entities[new_place] + local entity = new_entity_list[new_place] new_component_storage[new_place] = new_component @@ -2882,7 +2882,7 @@ __chunk_multi_insert = function(old_chunk, fragments, components) end else for new_place = new_entity_count + 1, new_entity_count + old_entity_count do - local entity = new_entities[new_place] + local entity = new_entity_list[new_place] if fragment_on_set then __defer_call_hook(fragment_on_set, entity, fragment) @@ -2939,7 +2939,7 @@ __chunk_multi_remove = function(old_chunk, fragments) return 0 end - local old_entities = old_chunk.__entities + local old_entity_list = old_chunk.__entity_list local old_entity_count = old_chunk.__entity_count if old_entity_count == 0 then @@ -2969,13 +2969,13 @@ __chunk_multi_remove = function(old_chunk, fragments) local old_component_storage = old_component_storages[old_component_index] for old_place = 1, old_entity_count do - local entity = old_entities[old_place] + local entity = old_entity_list[old_place] local old_component = old_component_storage[old_place] __defer_call_hook(fragment_on_remove, entity, fragment, old_component) end else for place = 1, old_entity_count do - local entity = old_entities[place] + local entity = old_entity_list[place] __defer_call_hook(fragment_on_remove, entity, fragment) end end @@ -2987,7 +2987,7 @@ __chunk_multi_remove = function(old_chunk, fragments) end if new_chunk then - local new_entities = new_chunk.__entities + local new_entity_list = new_chunk.__entity_list local new_entity_count = new_chunk.__entity_count local new_component_count = new_chunk.__component_count @@ -2995,11 +2995,11 @@ __chunk_multi_remove = function(old_chunk, fragments) local new_component_fragments = new_chunk.__component_fragments if new_entity_count == 0 then - old_chunk.__entities, new_chunk.__entities = - new_entities, old_entities + old_chunk.__entity_list, new_chunk.__entity_list = + new_entity_list, old_entity_list - old_entities, new_entities = - new_entities, old_entities + old_entity_list, new_entity_list = + new_entity_list, old_entity_list for new_ci = 1, new_component_count do local new_f = new_component_fragments[new_ci] @@ -3011,8 +3011,8 @@ __chunk_multi_remove = function(old_chunk, fragments) new_chunk.__entity_count = old_entity_count else __lua_table_move( - old_entities, 1, old_entity_count, - new_entity_count + 1, new_entities) + old_entity_list, 1, old_entity_count, + new_entity_count + 1, new_entity_list) for new_ci = 1, new_component_count do local new_f = new_component_fragments[new_ci] @@ -3030,7 +3030,7 @@ __chunk_multi_remove = function(old_chunk, fragments) local entity_places = __entity_places for new_place = new_entity_count + 1, new_entity_count + old_entity_count do - local entity = new_entities[new_place] + local entity = new_entity_list[new_place] local entity_index = entity % 0x100000 entity_chunks[entity_index] = new_chunk entity_places[entity_index] = new_place @@ -3043,7 +3043,7 @@ __chunk_multi_remove = function(old_chunk, fragments) local entity_places = __entity_places for old_place = 1, old_entity_count do - local entity = old_entities[old_place] + local entity = old_entity_list[old_place] local entity_index = entity % 0x100000 entity_chunks[entity_index] = nil entity_places[entity_index] = nil @@ -3078,8 +3078,8 @@ local function __system_process(system) if query and execute then __defer() do - for chunk, entities, entity_count in __evolved_execute(query) do - local success, result = __lua_pcall(execute, chunk, entities, entity_count) + for chunk, entity_list, entity_count in __evolved_execute(query) do + local success, result = __lua_pcall(execute, chunk, entity_list, entity_count) if not success then __commit() @@ -4624,7 +4624,7 @@ __evolved_set = function(entity, fragment, ...) end end else - local new_entities = new_chunk.__entities + local new_entity_list = new_chunk.__entity_list local new_entity_count = new_chunk.__entity_count local new_component_indices = new_chunk.__component_indices @@ -4633,7 +4633,7 @@ __evolved_set = function(entity, fragment, ...) local new_place = new_entity_count + 1 new_chunk.__entity_count = new_place - new_entities[new_place] = entity + new_entity_list[new_place] = entity if old_chunk then local old_component_count = old_chunk.__component_count @@ -4867,7 +4867,7 @@ __evolved_insert = function(entity, fragment, ...) __defer() do - local new_entities = new_chunk.__entities + local new_entity_list = new_chunk.__entity_list local new_entity_count = new_chunk.__entity_count local new_component_indices = new_chunk.__component_indices @@ -4876,7 +4876,7 @@ __evolved_insert = function(entity, fragment, ...) local new_place = new_entity_count + 1 new_chunk.__entity_count = new_place - new_entities[new_place] = entity + new_entity_list[new_place] = entity if old_chunk then local old_component_count = old_chunk.__component_count @@ -5034,7 +5034,7 @@ __evolved_remove = function(entity, ...) end if new_chunk then - local new_entities = new_chunk.__entities + local new_entity_list = new_chunk.__entity_list local new_entity_count = new_chunk.__entity_count local new_component_count = new_chunk.__component_count @@ -5044,7 +5044,7 @@ __evolved_remove = function(entity, ...) local new_place = new_entity_count + 1 new_chunk.__entity_count = new_place - new_entities[new_place] = entity + new_entity_list[new_place] = entity for new_ci = 1, new_component_count do local new_f = new_component_fragments[new_ci] @@ -5324,7 +5324,7 @@ __evolved_multi_set = function(entity, fragments, components) end end else - local new_entities = new_chunk.__entities + local new_entity_list = new_chunk.__entity_list local new_entity_count = new_chunk.__entity_count local new_component_indices = new_chunk.__component_indices @@ -5339,7 +5339,7 @@ __evolved_multi_set = function(entity, fragments, components) local new_place = new_entity_count + 1 new_chunk.__entity_count = new_place - new_entities[new_place] = entity + new_entity_list[new_place] = entity if old_chunk then local old_component_count = old_chunk.__component_count @@ -5638,7 +5638,7 @@ __evolved_multi_insert = function(entity, fragments, components) __defer() do - local new_entities = new_chunk.__entities + local new_entity_list = new_chunk.__entity_list local new_entity_count = new_chunk.__entity_count local new_component_indices = new_chunk.__component_indices @@ -5652,7 +5652,7 @@ __evolved_multi_insert = function(entity, fragments, components) local new_place = new_entity_count + 1 new_chunk.__entity_count = new_place - new_entities[new_place] = entity + new_entity_list[new_place] = entity if old_chunk then local old_component_count = old_chunk.__component_count @@ -5817,7 +5817,7 @@ __evolved_multi_remove = function(entity, fragments) end if new_chunk then - local new_entities = new_chunk.__entities + local new_entity_list = new_chunk.__entity_list local new_entity_count = new_chunk.__entity_count local new_component_count = new_chunk.__component_count @@ -5827,7 +5827,7 @@ __evolved_multi_remove = function(entity, fragments) local new_place = new_entity_count + 1 new_chunk.__entity_count = new_place - new_entities[new_place] = entity + new_entity_list[new_place] = entity for new_ci = 1, new_component_count do local new_f = new_component_fragments[new_ci] @@ -6329,7 +6329,7 @@ end ---@param ... evolved.fragment fragments ---@return evolved.chunk? chunk ----@return evolved.entity[]? entities +---@return evolved.entity[]? entity_list ---@return integer? entity_count ---@nodiscard __evolved_chunk = function(...) @@ -6360,7 +6360,7 @@ __evolved_chunk = function(...) or __chunk_with_fragment(chunk, child_fragment) end - return chunk, chunk.__entities, chunk.__entity_count + return chunk, chunk.__entity_list, chunk.__entity_count end ---@param chunk evolved.chunk @@ -6437,11 +6437,11 @@ __evolved_select = function(chunk, ...) end ---@param chunk evolved.chunk ----@return evolved.entity[] entities +---@return evolved.entity[] entity_list ---@return integer entity_count ---@nodiscard __evolved_entities = function(chunk) - return chunk.__entities, chunk.__entity_count + return chunk.__entity_list, chunk.__entity_count end ---@param chunk evolved.chunk From f5ccd775a0b67e3d3640ab878f637d52e67bf3c3 Mon Sep 17 00:00:00 2001 From: BlackMATov Date: Mon, 3 Mar 2025 22:07:22 +0700 Subject: [PATCH 3/7] create component storages in one place --- evolved.lua | 25 ++++++++++++++++++------- 1 file changed, 18 insertions(+), 7 deletions(-) diff --git a/evolved.lua b/evolved.lua index e625550..a5eac89 100644 --- a/evolved.lua +++ b/evolved.lua @@ -36,7 +36,7 @@ local evolved = { ---@alias evolved.system evolved.id ---@alias evolved.component any ----@alias evolved.component_storage evolved.component[] +---@alias evolved.storage evolved.component[] ---@alias evolved.default evolved.component ---@alias evolved.construct fun(...: any): evolved.component @@ -62,7 +62,7 @@ local evolved = { ---@field package __fragment_count integer ---@field package __component_count integer ---@field package __component_indices table ----@field package __component_storages evolved.component_storage[] +---@field package __component_storages evolved.storage[] ---@field package __component_fragments evolved.fragment[] ---@field package __with_fragment_edges table ---@field package __without_fragment_edges table @@ -674,6 +674,7 @@ end ---@param ... any component arguments ---@return evolved.component +---@nodiscard local function __component_list(...) local argument_count = __lua_select('#', ...) @@ -690,8 +691,17 @@ local function __component_list(...) return argument_list end +---@param fragment evolved.fragment +---@return evolved.storage +---@nodiscard +---@diagnostic disable-next-line: unused-local +local function __component_storage(fragment) + return {} +end + ---@param ... any component arguments ---@return evolved.component +---@nodiscard local function __component_construct(fragment, ...) ---@type evolved.default, evolved.construct local default, construct = __evolved_get(fragment, __DEFAULT, __CONSTRUCT) @@ -812,7 +822,7 @@ function __chunk_component_indices_mt.__tostring(self) return __lua_string_format('{%s}', __lua_table_concat(items, ', ')) end ----@param self evolved.component_storage[] +---@param self evolved.storage[] function __chunk_component_storages_mt.__tostring(self) local items = {} ---@type string[] @@ -839,6 +849,7 @@ end ---@param chunk_parent? evolved.chunk ---@param chunk_fragment evolved.fragment ---@return evolved.chunk +---@nodiscard local function __new_chunk(chunk_parent, chunk_fragment) ---@type table local chunk_fragment_set = __lua_setmetatable({}, __chunk_fragment_set_mt) @@ -855,7 +866,7 @@ local function __new_chunk(chunk_parent, chunk_fragment) ---@type table local chunk_component_indices = __lua_setmetatable({}, __chunk_component_indices_mt) - ---@type evolved.component_storage[] + ---@type evolved.storage[] local chunk_component_storages = __lua_setmetatable({}, __chunk_component_storages_mt) ---@type evolved.fragment[] @@ -909,7 +920,7 @@ local function __new_chunk(chunk_parent, chunk_fragment) if not __evolved_has(parent_fragment, __TAG) then chunk_component_count = chunk_component_count + 1 - local component_storage = {} + local component_storage = __component_storage(parent_fragment) local component_storage_index = chunk_component_count chunk_component_indices[parent_fragment] = component_storage_index chunk_component_storages[component_storage_index] = component_storage @@ -932,7 +943,7 @@ local function __new_chunk(chunk_parent, chunk_fragment) if not __evolved_has(chunk_fragment, __TAG) then chunk_component_count = chunk_component_count + 1 - local component_storage = {} + local component_storage = __component_storage(chunk_fragment) local component_storage_index = chunk_component_count chunk_component_indices[chunk_fragment] = component_storage_index chunk_component_storages[component_storage_index] = component_storage @@ -6365,7 +6376,7 @@ end ---@param chunk evolved.chunk ---@param ... evolved.fragment fragments ----@return evolved.component_storage ... component_storages +---@return evolved.storage ... storages ---@nodiscard __evolved_select = function(chunk, ...) local fragment_count = __lua_select('#', ...) From c2aaf94227e7b0bbdb26eef20eed813f8e64cdc4 Mon Sep 17 00:00:00 2001 From: BlackMATov Date: Tue, 4 Mar 2025 11:53:56 +0700 Subject: [PATCH 4/7] assoc lists for major/minor chunks --- evolved.lua | 55 ++++++++++++++++++++++++++++++++--------------------- 1 file changed, 33 insertions(+), 22 deletions(-) diff --git a/evolved.lua b/evolved.lua index a5eac89..03ed9fb 100644 --- a/evolved.lua +++ b/evolved.lua @@ -102,8 +102,8 @@ local __defer_length = 0 ---@type integer local __defer_bytecode = {} ---@type any[] local __root_chunks = {} ---@type table -local __major_chunks = {} ---@type table -local __minor_chunks = {} ---@type table +local __major_chunks = {} ---@type table +local __minor_chunks = {} ---@type table local __entity_chunks = {} ---@type table local __entity_places = {} ---@type table @@ -505,7 +505,7 @@ local function __execute_iterator(execute_state) local chunk_child_list = chunk.__child_list local chunk_child_count = chunk.__child_count - for i = chunk_child_count, 1, -1 do + for i = 1, chunk_child_count do local chunk_child = chunk_child_list[i] local chunk_child_fragment = chunk_child.__fragment @@ -733,10 +733,15 @@ local function __trace_fragment_chunks(fragment, trace, ...) local chunk_stack = __acquire_table(__table_pool_tag.chunk_stack) local chunk_stack_size = 0 - for i = 1, #major_chunks do - local major_chunk = major_chunks[i] - chunk_stack_size = chunk_stack_size + 1 - chunk_stack[chunk_stack_size] = major_chunk + do + local major_chunk_list = major_chunks.__item_list + local major_chunk_count = major_chunks.__item_count + + __lua_table_move( + major_chunk_list, 1, major_chunk_count, + chunk_stack_size + 1, chunk_stack) + + chunk_stack_size = chunk_stack_size + major_chunk_count end while chunk_stack_size > 0 do @@ -749,11 +754,11 @@ local function __trace_fragment_chunks(fragment, trace, ...) local chunk_child_list = chunk.__child_list local chunk_child_count = chunk.__child_count - for i = chunk_child_count, 1, -1 do - local chunk_child = chunk_child_list[i] - chunk_stack_size = chunk_stack_size + 1 - chunk_stack[chunk_stack_size] = chunk_child - end + __lua_table_move( + chunk_child_list, 1, chunk_child_count, + chunk_stack_size + 1, chunk_stack) + + chunk_stack_size = chunk_stack_size + chunk_child_count end end @@ -966,11 +971,11 @@ local function __new_chunk(chunk_parent, chunk_fragment) local major_chunks = __major_chunks[major_fragment] if not major_chunks then - major_chunks = {} + major_chunks = __assoc_list_new(4) __major_chunks[major_fragment] = major_chunks end - major_chunks[#major_chunks + 1] = chunk + __assoc_list_insert(major_chunks, chunk) end for i = 1, chunk_fragment_count do @@ -978,11 +983,11 @@ local function __new_chunk(chunk_parent, chunk_fragment) local minor_chunks = __minor_chunks[minor_fragment] if not minor_chunks then - minor_chunks = {} + minor_chunks = __assoc_list_new(4) __minor_chunks[minor_fragment] = minor_chunks end - minor_chunks[#minor_chunks + 1] = chunk + __assoc_list_insert(minor_chunks, chunk) end return chunk @@ -1665,14 +1670,17 @@ local function __purge_fragment(fragment, policy) local purged_count = 0 + local minor_chunk_list = minor_chunks.__item_list + local minor_chunk_count = minor_chunks.__item_count + if policy == __DESTROY_ENTITY_POLICY then - for minor_chunk_index = #minor_chunks, 1, -1 do - local minor_chunk = minor_chunks[minor_chunk_index] + for minor_chunk_index = minor_chunk_count, 1, -1 do + local minor_chunk = minor_chunk_list[minor_chunk_index] purged_count = purged_count + __chunk_destroy(minor_chunk) end elseif policy == __REMOVE_FRAGMENT_POLICY then - for minor_chunk_index = #minor_chunks, 1, -1 do - local minor_chunk = minor_chunks[minor_chunk_index] + for minor_chunk_index = minor_chunk_count, 1, -1 do + local minor_chunk = minor_chunk_list[minor_chunk_index] purged_count = purged_count + __chunk_remove(minor_chunk, fragment) end else @@ -6530,8 +6538,11 @@ __evolved_execute = function(query) local chunk_stack = __acquire_table(__table_pool_tag.chunk_stack) local chunk_stack_size = 0 - for major_fragment_chunk_index = 1, #major_fragment_chunks do - local major_fragment_chunk = major_fragment_chunks[major_fragment_chunk_index] + local major_fragment_chunk_list = major_fragment_chunks.__item_list + local major_fragment_chunk_count = major_fragment_chunks.__item_count + + for major_fragment_chunk_index = 1, major_fragment_chunk_count do + local major_fragment_chunk = major_fragment_chunk_list[major_fragment_chunk_index] local is_major_fragment_chunk_matched = true From 00dc5e6b45be25a9b026d82922aaabea3f301371 Mon Sep 17 00:00:00 2001 From: BlackMATov Date: Thu, 6 Mar 2025 23:02:57 +0700 Subject: [PATCH 5/7] dont sort empty and one element assoc lists --- evolved.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/evolved.lua b/evolved.lua index 03ed9fb..aa507f5 100644 --- a/evolved.lua +++ b/evolved.lua @@ -360,7 +360,7 @@ end local function __assoc_list_sort(al, comp) local al_item_count = al.__item_count - if al_item_count == 0 then + if al_item_count < 2 then return end From cd4da397ccc74b8c9c62a62b88e99bcc2b95b80c Mon Sep 17 00:00:00 2001 From: BlackMATov Date: Fri, 7 Mar 2025 15:22:50 +0700 Subject: [PATCH 6/7] include chunk stack size to execute states --- develop/untests.lua | 49 +++++++++++++++++++++++++++++++++++++++++++++ evolved.lua | 40 ++++++++++++++++++++++-------------- 2 files changed, 74 insertions(+), 15 deletions(-) diff --git a/develop/untests.lua b/develop/untests.lua index cf059cf..c46d198 100644 --- a/develop/untests.lua +++ b/develop/untests.lua @@ -7135,3 +7135,52 @@ do assert(evo.fragments(c23)[1] == f2) assert(evo.fragments(c23)[2] == f3) end + +do + local f0, f1, f2, f3 = evo.id(4) + + local e1 = evo.entity():set(f0, 0):set(f1, 1):build() + local e12 = evo.entity():set(f0, 0):set(f1, 2):set(f2, 3):build() + local e123 = evo.entity():set(f0, 0):set(f1, 4):set(f2, 5):set(f3, 6):build() + + evo.entity():set(f1, 41):build() + evo.entity():set(f1, 42):set(f2, 43):build() + + do + local q1 = evo.query():include(f0, f1):build() + + local iter, state = evo.execute(q1) + + local chunk, entity_list = iter(state) + assert(entity_list and #entity_list == 1) + assert(chunk == evo.chunk(f0, f1) and entity_list[1] == e1) + + chunk, entity_list = iter(state) + assert(entity_list and #entity_list == 1) + assert(chunk == evo.chunk(f0, f1, f2) and entity_list[1] == e12) + + chunk, entity_list = iter(state) + assert(entity_list and #entity_list == 1) + assert(chunk == evo.chunk(f0, f1, f2, f3) and entity_list[1] == e123) + + chunk, entity_list = iter(state) + assert(not chunk and not entity_list) + end + + do + local q1 = evo.query():include(f0, f1):exclude(f3):build() + + local iter, state = evo.execute(q1) + + local chunk, entity_list = iter(state) + assert(entity_list and #entity_list == 1) + assert(chunk == evo.chunk(f0, f1) and entity_list[1] == e1) + + chunk, entity_list = iter(state) + assert(entity_list and #entity_list == 1) + assert(chunk == evo.chunk(f0, f1, f2) and entity_list[1] == e12) + + chunk, entity_list = iter(state) + assert(not chunk and not entity_list) + end +end diff --git a/evolved.lua b/evolved.lua index aa507f5..1c338b4 100644 --- a/evolved.lua +++ b/evolved.lua @@ -80,7 +80,8 @@ local evolved = { ---@class (exact) evolved.execute_state ---@field package [1] integer structural_changes ---@field package [2] evolved.chunk[] chunk_stack ----@field package [3] table? exclude_set +---@field package [3] integer chunk_stack_size +---@field package [4] table? exclude_set ---@alias evolved.each_iterator fun(state: evolved.each_state?): evolved.fragment?, evolved.component? ---@alias evolved.execute_iterator fun(state: evolved.execute_state?): evolved.chunk?, evolved.entity[]?, integer? @@ -488,14 +489,13 @@ local function __execute_iterator(execute_state) local structural_changes = execute_state[1] local chunk_stack = execute_state[2] - local exclude_set = execute_state[3] + local chunk_stack_size = execute_state[3] + local exclude_set = execute_state[4] if structural_changes ~= __structural_changes then __lua_error('structural changes are prohibited during iteration') end - local chunk_stack_size = #chunk_stack - while chunk_stack_size > 0 do local chunk = chunk_stack[chunk_stack_size] @@ -505,20 +505,29 @@ local function __execute_iterator(execute_state) local chunk_child_list = chunk.__child_list local chunk_child_count = chunk.__child_count - for i = 1, chunk_child_count do - local chunk_child = chunk_child_list[i] - local chunk_child_fragment = chunk_child.__fragment + if exclude_set then + for i = 1, chunk_child_count do + local chunk_child = chunk_child_list[i] + local chunk_child_fragment = chunk_child.__fragment - if not exclude_set or not exclude_set[chunk_child_fragment] then - chunk_stack_size = chunk_stack_size + 1 - chunk_stack[chunk_stack_size] = chunk_child + if not exclude_set[chunk_child_fragment] then + chunk_stack_size = chunk_stack_size + 1 + chunk_stack[chunk_stack_size] = chunk_child + end end + else + __lua_table_move( + chunk_child_list, 1, chunk_child_count, + chunk_stack_size + 1, chunk_stack) + + chunk_stack_size = chunk_stack_size + chunk_child_count end local chunk_entity_list = chunk.__entity_list local chunk_entity_count = chunk.__entity_count if chunk_entity_count > 0 then + execute_state[3] = chunk_stack_size return chunk, chunk_entity_list, chunk_entity_count end end @@ -1008,8 +1017,8 @@ local function __chunk_with_fragment(chunk, fragment) end do - local with_fragment_chunk = chunk.__with_fragment_edges[fragment] - if with_fragment_chunk then return with_fragment_chunk end + local with_fragment_edge = chunk.__with_fragment_edges[fragment] + if with_fragment_edge then return with_fragment_edge end end if fragment < chunk.__fragment then @@ -6546,12 +6555,12 @@ __evolved_execute = function(query) local is_major_fragment_chunk_matched = true - if query_include_list and query_include_count > 1 then + if is_major_fragment_chunk_matched and query_include_list and query_include_count > 1 then is_major_fragment_chunk_matched = __chunk_has_all_fragment_list( major_fragment_chunk, query_include_list, query_include_count - 1) end - if query_exclude_list and query_exclude_count > 0 then + if is_major_fragment_chunk_matched and query_exclude_list and query_exclude_count > 0 then is_major_fragment_chunk_matched = not __chunk_has_any_fragment_list( major_fragment_chunk, query_exclude_list, query_exclude_count) end @@ -6567,7 +6576,8 @@ __evolved_execute = function(query) execute_state[1] = __structural_changes execute_state[2] = chunk_stack - execute_state[3] = query_exclude_set + execute_state[3] = chunk_stack_size + execute_state[4] = query_exclude_set return __execute_iterator, execute_state end From 835103c891bfa0fed67ab88ec7fd9be5d460f26e Mon Sep 17 00:00:00 2001 From: BlackMATov Date: Fri, 7 Mar 2025 16:21:19 +0700 Subject: [PATCH 7/7] decrease list sizes calculations --- evolved.lua | 22 ++++++++++------------ 1 file changed, 10 insertions(+), 12 deletions(-) diff --git a/evolved.lua b/evolved.lua index 1c338b4..256dbc4 100644 --- a/evolved.lua +++ b/evolved.lua @@ -1037,11 +1037,10 @@ end ---@param chunk? evolved.chunk ---@param fragment_list evolved.fragment[] +---@param fragment_count integer ---@return evolved.chunk? ---@nodiscard -local function __chunk_with_fragment_list(chunk, fragment_list) - local fragment_count = #fragment_list - +local function __chunk_with_fragment_list(chunk, fragment_list, fragment_count) if fragment_count == 0 then return chunk end @@ -1111,11 +1110,10 @@ end ---@param chunk? evolved.chunk ---@param fragment_list evolved.fragment[] +---@param fragment_count integer ---@return evolved.chunk? ---@nodiscard -local function __chunk_without_fragment_list(chunk, fragment_list) - local fragment_count = #fragment_list - +local function __chunk_without_fragment_list(chunk, fragment_list, fragment_count) if fragment_count == 0 then return chunk end @@ -2350,7 +2348,7 @@ __chunk_multi_set = function(old_chunk, fragments, components) return 0 end - local new_chunk = __chunk_with_fragment_list(old_chunk, fragments) + local new_chunk = __chunk_with_fragment_list(old_chunk, fragments, fragment_count) if not new_chunk then return 0 @@ -2789,7 +2787,7 @@ __chunk_multi_insert = function(old_chunk, fragments, components) return 0 end - local new_chunk = __chunk_with_fragment_list(old_chunk, fragments) + local new_chunk = __chunk_with_fragment_list(old_chunk, fragments, fragment_count) if not new_chunk or old_chunk == new_chunk then return 0 @@ -2961,7 +2959,7 @@ __chunk_multi_remove = function(old_chunk, fragments) return 0 end - local new_chunk = __chunk_without_fragment_list(old_chunk, fragments) + local new_chunk = __chunk_without_fragment_list(old_chunk, fragments, fragment_count) if old_chunk == new_chunk then return 0 @@ -5286,7 +5284,7 @@ __evolved_multi_set = function(entity, fragments, components) local old_chunk = entity_chunks[entity_index] local old_place = entity_places[entity_index] - local new_chunk = __chunk_with_fragment_list(old_chunk, fragments) + local new_chunk = __chunk_with_fragment_list(old_chunk, fragments, fragment_count) if not new_chunk then return false, false @@ -5657,7 +5655,7 @@ __evolved_multi_insert = function(entity, fragments, components) local old_chunk = entity_chunks[entity_index] local old_place = entity_places[entity_index] - local new_chunk = __chunk_with_fragment_list(old_chunk, fragments) + local new_chunk = __chunk_with_fragment_list(old_chunk, fragments, fragment_count) if not new_chunk or old_chunk == new_chunk then return false, false @@ -5802,7 +5800,7 @@ __evolved_multi_remove = function(entity, fragments) local old_chunk = entity_chunks[entity_index] local old_place = entity_places[entity_index] - local new_chunk = __chunk_without_fragment_list(old_chunk, fragments) + local new_chunk = __chunk_without_fragment_list(old_chunk, fragments, fragment_count) if old_chunk == new_chunk then return true, false