From abffdb4bbef39e8fc2dc0a0dcb499547f4573441 Mon Sep 17 00:00:00 2001 From: BlackMATov Date: Thu, 20 Mar 2025 03:58:53 +0700 Subject: [PATCH 01/12] remove evolved.assign/insert --- README.md | 2 - evolved.lua | 495 ++++++---------------------------------------------- 2 files changed, 50 insertions(+), 447 deletions(-) diff --git a/README.md b/README.md index ecb9480..4e9d2f3 100644 --- a/README.md +++ b/README.md @@ -78,8 +78,6 @@ has_any :: chunk | entity, fragment... -> boolean get :: entity, fragment... -> component... set :: entity, fragment, any... -> boolean, boolean -assign :: entity, fragment, any... -> boolean, boolean -insert :: entity, fragment, any... -> boolean, boolean remove :: entity, fragment... -> boolean, boolean clear :: entity... -> boolean, boolean destroy :: entity... -> boolean, boolean diff --git a/evolved.lua b/evolved.lua index af60996..10eaed0 100644 --- a/evolved.lua +++ b/evolved.lua @@ -656,8 +656,6 @@ local __evolved_has_any local __evolved_get local __evolved_set -local __evolved_assign -local __evolved_insert local __evolved_remove local __evolved_clear local __evolved_destroy @@ -1508,8 +1506,6 @@ end --- local __defer_set -local __defer_assign -local __defer_insert local __defer_remove local __defer_clear local __defer_destroy @@ -3496,8 +3492,6 @@ end ---@enum evolved.defer_op local __defer_op = { set = 1, - assign = 2, - insert = 3, remove = 4, clear = 5, destroy = 6, @@ -3606,158 +3600,6 @@ __defer_ops[__defer_op.set] = function(bytes, index) return 3 + argument_count end ----@param entity evolved.entity ----@param fragment evolved.fragment ----@param ... any component arguments -__defer_assign = function(entity, fragment, ...) - local length = __defer_length - local bytecode = __defer_bytecode - - local argument_count = __lua_select('#', ...) - - bytecode[length + 1] = __defer_op.assign - bytecode[length + 2] = entity - bytecode[length + 3] = fragment - bytecode[length + 4] = argument_count - - if argument_count == 0 then - -- nothing - elseif argument_count == 1 then - local a1 = ... - bytecode[length + 5] = a1 - elseif argument_count == 2 then - local a1, a2 = ... - bytecode[length + 5] = a1 - bytecode[length + 6] = a2 - elseif argument_count == 3 then - local a1, a2, a3 = ... - bytecode[length + 5] = a1 - bytecode[length + 6] = a2 - bytecode[length + 7] = a3 - elseif argument_count == 4 then - local a1, a2, a3, a4 = ... - bytecode[length + 5] = a1 - bytecode[length + 6] = a2 - bytecode[length + 7] = a3 - bytecode[length + 8] = a4 - else - local a1, a2, a3, a4 = ... - bytecode[length + 5] = a1 - bytecode[length + 6] = a2 - bytecode[length + 7] = a3 - bytecode[length + 8] = a4 - for i = 5, argument_count do - bytecode[length + 4 + i] = __lua_select(i, ...) - end - end - - __defer_length = length + 4 + argument_count -end - -__defer_ops[__defer_op.assign] = function(bytes, index) - local entity = bytes[index + 0] - local fragment = bytes[index + 1] - local argument_count = bytes[index + 2] - - if argument_count == 0 then - __evolved_assign(entity, fragment) - elseif argument_count == 1 then - local a1 = bytes[index + 3] - __evolved_assign(entity, fragment, a1) - elseif argument_count == 2 then - local a1, a2 = bytes[index + 3], bytes[index + 4] - __evolved_assign(entity, fragment, a1, a2) - elseif argument_count == 3 then - local a1, a2, a3 = bytes[index + 3], bytes[index + 4], bytes[index + 5] - __evolved_assign(entity, fragment, a1, a2, a3) - elseif argument_count == 4 then - local a1, a2, a3, a4 = bytes[index + 3], bytes[index + 4], bytes[index + 5], bytes[index + 6] - __evolved_assign(entity, fragment, a1, a2, a3, a4) - else - local a1, a2, a3, a4 = bytes[index + 3], bytes[index + 4], bytes[index + 5], bytes[index + 6] - __evolved_assign(entity, fragment, a1, a2, a3, a4, - __lua_table_unpack(bytes, index + 7, index + 2 + argument_count)) - end - - return 3 + argument_count -end - ----@param entity evolved.entity ----@param fragment evolved.fragment ----@param ... any component arguments -__defer_insert = function(entity, fragment, ...) - local length = __defer_length - local bytecode = __defer_bytecode - - local argument_count = __lua_select('#', ...) - - bytecode[length + 1] = __defer_op.insert - bytecode[length + 2] = entity - bytecode[length + 3] = fragment - bytecode[length + 4] = argument_count - - if argument_count == 0 then - -- nothing - elseif argument_count == 1 then - local a1 = ... - bytecode[length + 5] = a1 - elseif argument_count == 2 then - local a1, a2 = ... - bytecode[length + 5] = a1 - bytecode[length + 6] = a2 - elseif argument_count == 3 then - local a1, a2, a3 = ... - bytecode[length + 5] = a1 - bytecode[length + 6] = a2 - bytecode[length + 7] = a3 - elseif argument_count == 4 then - local a1, a2, a3, a4 = ... - bytecode[length + 5] = a1 - bytecode[length + 6] = a2 - bytecode[length + 7] = a3 - bytecode[length + 8] = a4 - else - local a1, a2, a3, a4 = ... - bytecode[length + 5] = a1 - bytecode[length + 6] = a2 - bytecode[length + 7] = a3 - bytecode[length + 8] = a4 - for i = 5, argument_count do - bytecode[length + 4 + i] = __lua_select(i, ...) - end - end - - __defer_length = length + 4 + argument_count -end - -__defer_ops[__defer_op.insert] = function(bytes, index) - local entity = bytes[index + 0] - local fragment = bytes[index + 1] - local argument_count = bytes[index + 2] - - if argument_count == 0 then - __evolved_insert(entity, fragment) - elseif argument_count == 1 then - local a1 = bytes[index + 3] - __evolved_insert(entity, fragment, a1) - elseif argument_count == 2 then - local a1, a2 = bytes[index + 3], bytes[index + 4] - __evolved_insert(entity, fragment, a1, a2) - elseif argument_count == 3 then - local a1, a2, a3 = bytes[index + 3], bytes[index + 4], bytes[index + 5] - __evolved_insert(entity, fragment, a1, a2, a3) - elseif argument_count == 4 then - local a1, a2, a3, a4 = bytes[index + 3], bytes[index + 4], bytes[index + 5], bytes[index + 6] - __evolved_insert(entity, fragment, a1, a2, a3, a4) - else - local a1, a2, a3, a4 = bytes[index + 3], bytes[index + 4], bytes[index + 5], bytes[index + 6] - __evolved_insert(entity, fragment, a1, a2, a3, a4, - __lua_table_unpack(bytes, index + 7, index + 2 + argument_count)) - end - - return 3 + argument_count -end - ---@param entity evolved.entity ---@param ... evolved.fragment fragments __defer_remove = function(entity, ...) @@ -5436,241 +5278,6 @@ __evolved_set = function(entity, fragment, ...) return true, false end ----@param entity evolved.entity ----@param fragment evolved.fragment ----@param ... any component arguments ----@return boolean is_assigned ----@return boolean is_deferred -__evolved_assign = function(entity, fragment, ...) - if __defer_depth > 0 then - __defer_assign(entity, fragment, ...) - return false, true - end - - if __debug_mode then - __debug_fns.validate_fragment(fragment) - end - - local entity_index = entity % 0x100000 - - if __freelist_ids[entity_index] ~= entity then - return false, false - end - - local entity_chunks = __entity_chunks - local entity_places = __entity_places - - local chunk = entity_chunks[entity_index] - local place = entity_places[entity_index] - - if not chunk or not chunk.__fragment_set[fragment] then - return false, false - end - - ---@type evolved.set_hook?, evolved.assign_hook? - local fragment_on_set, fragment_on_assign - - if chunk.__has_set_or_assign_hooks then - fragment_on_set, fragment_on_assign = __evolved_get(fragment, - __ON_SET, __ON_ASSIGN) - end - - __evolved_defer() - - do - local component_indices = chunk.__component_indices - local component_storages = chunk.__component_storages - - local component_index = component_indices[fragment] - - if component_index then - local component_storage = component_storages[component_index] - - if chunk.__has_defaults_or_constructs then - local new_component = __component_construct(fragment, ...) - - if fragment_on_set or fragment_on_assign then - local old_component = component_storage[place] - - component_storage[place] = new_component - - if fragment_on_set then - __defer_call_hook(fragment_on_set, entity, fragment, new_component, old_component) - end - - if fragment_on_assign then - __defer_call_hook(fragment_on_assign, entity, fragment, new_component, old_component) - end - else - component_storage[place] = new_component - end - else - local new_component = ... - - if new_component == nil then - new_component = true - end - - if fragment_on_set or fragment_on_assign then - local old_component = component_storage[place] - - component_storage[place] = new_component - - if fragment_on_set then - __defer_call_hook(fragment_on_set, entity, fragment, new_component, old_component) - end - - if fragment_on_assign then - __defer_call_hook(fragment_on_assign, entity, fragment, new_component, old_component) - end - else - component_storage[place] = new_component - end - end - else - if fragment_on_set then - __defer_call_hook(fragment_on_set, entity, fragment) - end - - if fragment_on_assign then - __defer_call_hook(fragment_on_assign, entity, fragment) - end - end - end - - __evolved_commit() - return true, false -end - ----@param entity evolved.entity ----@param fragment evolved.fragment ----@param ... any component arguments ----@return boolean is_inserted ----@return boolean is_deferred -__evolved_insert = function(entity, fragment, ...) - if __defer_depth > 0 then - __defer_insert(entity, fragment, ...) - return false, true - end - - if __debug_mode then - __debug_fns.validate_fragment(fragment) - end - - local entity_index = entity % 0x100000 - - if __freelist_ids[entity_index] ~= entity then - return false, false - end - - local entity_chunks = __entity_chunks - local entity_places = __entity_places - - local old_chunk = entity_chunks[entity_index] - local old_place = entity_places[entity_index] - - local new_chunk = __chunk_with_fragment(old_chunk, fragment) - - if not new_chunk or old_chunk == new_chunk then - return false, false - end - - ---@type evolved.set_hook?, evolved.insert_hook? - local fragment_on_set, fragment_on_insert - - if new_chunk.__has_set_or_insert_hooks then - fragment_on_set, fragment_on_insert = __evolved_get(fragment, - __ON_SET, __ON_INSERT) - end - - __evolved_defer() - - do - local new_entity_list = new_chunk.__entity_list - local new_entity_count = new_chunk.__entity_count - - local new_component_indices = new_chunk.__component_indices - local new_component_storages = new_chunk.__component_storages - - local new_place = new_entity_count + 1 - new_chunk.__entity_count = new_place - - new_entity_list[new_place] = entity - - if old_chunk then - local old_component_count = old_chunk.__component_count - local old_component_storages = old_chunk.__component_storages - local old_component_fragments = old_chunk.__component_fragments - - for old_ci = 1, old_component_count do - local old_f = old_component_fragments[old_ci] - local old_cs = old_component_storages[old_ci] - local new_ci = new_component_indices[old_f] - local new_cs = new_component_storages[new_ci] - new_cs[new_place] = old_cs[old_place] - end - - __detach_entity(old_chunk, old_place) - end - - do - entity_chunks[entity_index] = new_chunk - entity_places[entity_index] = new_place - - __structural_changes = __structural_changes + 1 - end - - do - local new_component_index = new_component_indices[fragment] - - if new_component_index then - local new_component_storage = new_component_storages[new_component_index] - - if new_chunk.__has_defaults_or_constructs then - local new_component = __component_construct(fragment, ...) - - new_component_storage[new_place] = new_component - - if fragment_on_set then - __defer_call_hook(fragment_on_set, entity, fragment, new_component) - end - - if fragment_on_insert then - __defer_call_hook(fragment_on_insert, entity, fragment, new_component) - end - else - local new_component = ... - - if new_component == nil then - new_component = true - end - - new_component_storage[new_place] = new_component - - if fragment_on_set then - __defer_call_hook(fragment_on_set, entity, fragment, new_component) - end - - if fragment_on_insert then - __defer_call_hook(fragment_on_insert, entity, fragment, new_component) - end - end - else - if fragment_on_set then - __defer_call_hook(fragment_on_set, entity, fragment) - end - - if fragment_on_insert then - __defer_call_hook(fragment_on_insert, entity, fragment) - end - end - end - end - - __evolved_commit() - return true, false -end - ---@param entity evolved.entity ---@param ... evolved.fragment fragments ---@return boolean is_removed @@ -8330,15 +7937,15 @@ local function __update_fragment_hooks(fragment) __trace_fragment_chunks(fragment, __update_chunk_caches_trace, fragment) end -assert(__evolved_insert(__ON_SET, __ON_INSERT, __update_fragment_hooks)) -assert(__evolved_insert(__ON_ASSIGN, __ON_INSERT, __update_fragment_hooks)) -assert(__evolved_insert(__ON_INSERT, __ON_INSERT, __update_fragment_hooks)) -assert(__evolved_insert(__ON_REMOVE, __ON_INSERT, __update_fragment_hooks)) +assert(__evolved_set(__ON_SET, __ON_INSERT, __update_fragment_hooks)) +assert(__evolved_set(__ON_ASSIGN, __ON_INSERT, __update_fragment_hooks)) +assert(__evolved_set(__ON_INSERT, __ON_INSERT, __update_fragment_hooks)) +assert(__evolved_set(__ON_REMOVE, __ON_INSERT, __update_fragment_hooks)) -assert(__evolved_insert(__ON_SET, __ON_REMOVE, __update_fragment_hooks)) -assert(__evolved_insert(__ON_ASSIGN, __ON_REMOVE, __update_fragment_hooks)) -assert(__evolved_insert(__ON_INSERT, __ON_REMOVE, __update_fragment_hooks)) -assert(__evolved_insert(__ON_REMOVE, __ON_REMOVE, __update_fragment_hooks)) +assert(__evolved_set(__ON_SET, __ON_REMOVE, __update_fragment_hooks)) +assert(__evolved_set(__ON_ASSIGN, __ON_REMOVE, __update_fragment_hooks)) +assert(__evolved_set(__ON_INSERT, __ON_REMOVE, __update_fragment_hooks)) +assert(__evolved_set(__ON_REMOVE, __ON_REMOVE, __update_fragment_hooks)) --- --- @@ -8413,14 +8020,14 @@ local function __update_fragment_constructs(fragment) __trace_fragment_chunks(fragment, __update_chunk_caches_trace, fragment) end -assert(__evolved_insert(__TAG, __ON_INSERT, __update_fragment_tags)) -assert(__evolved_insert(__TAG, __ON_REMOVE, __update_fragment_tags)) +assert(__evolved_set(__TAG, __ON_INSERT, __update_fragment_tags)) +assert(__evolved_set(__TAG, __ON_REMOVE, __update_fragment_tags)) -assert(__evolved_insert(__DEFAULT, __ON_INSERT, __update_fragment_defaults)) -assert(__evolved_insert(__DEFAULT, __ON_REMOVE, __update_fragment_defaults)) +assert(__evolved_set(__DEFAULT, __ON_INSERT, __update_fragment_defaults)) +assert(__evolved_set(__DEFAULT, __ON_REMOVE, __update_fragment_defaults)) -assert(__evolved_insert(__CONSTRUCT, __ON_INSERT, __update_fragment_constructs)) -assert(__evolved_insert(__CONSTRUCT, __ON_REMOVE, __update_fragment_constructs)) +assert(__evolved_set(__CONSTRUCT, __ON_INSERT, __update_fragment_constructs)) +assert(__evolved_set(__CONSTRUCT, __ON_REMOVE, __update_fragment_constructs)) --- --- @@ -8428,35 +8035,35 @@ assert(__evolved_insert(__CONSTRUCT, __ON_REMOVE, __update_fragment_constructs)) --- --- -assert(__evolved_insert(__TAG, __NAME, 'TAG')) +assert(__evolved_set(__TAG, __NAME, 'TAG')) -assert(__evolved_insert(__NAME, __NAME, 'NAME')) -assert(__evolved_insert(__DEFAULT, __NAME, 'DEFAULT')) -assert(__evolved_insert(__CONSTRUCT, __NAME, 'CONSTRUCT')) +assert(__evolved_set(__NAME, __NAME, 'NAME')) +assert(__evolved_set(__DEFAULT, __NAME, 'DEFAULT')) +assert(__evolved_set(__CONSTRUCT, __NAME, 'CONSTRUCT')) -assert(__evolved_insert(__INCLUDES, __NAME, 'INCLUDES')) -assert(__evolved_insert(__EXCLUDES, __NAME, 'EXCLUDES')) +assert(__evolved_set(__INCLUDES, __NAME, 'INCLUDES')) +assert(__evolved_set(__EXCLUDES, __NAME, 'EXCLUDES')) -assert(__evolved_insert(__ON_SET, __NAME, 'ON_SET')) -assert(__evolved_insert(__ON_ASSIGN, __NAME, 'ON_ASSIGN')) -assert(__evolved_insert(__ON_INSERT, __NAME, 'ON_INSERT')) -assert(__evolved_insert(__ON_REMOVE, __NAME, 'ON_REMOVE')) +assert(__evolved_set(__ON_SET, __NAME, 'ON_SET')) +assert(__evolved_set(__ON_ASSIGN, __NAME, 'ON_ASSIGN')) +assert(__evolved_set(__ON_INSERT, __NAME, 'ON_INSERT')) +assert(__evolved_set(__ON_REMOVE, __NAME, 'ON_REMOVE')) -assert(__evolved_insert(__PHASE, __NAME, 'PHASE')) -assert(__evolved_insert(__GROUP, __NAME, 'GROUP')) -assert(__evolved_insert(__AFTER, __NAME, 'AFTER')) +assert(__evolved_set(__PHASE, __NAME, 'PHASE')) +assert(__evolved_set(__GROUP, __NAME, 'GROUP')) +assert(__evolved_set(__AFTER, __NAME, 'AFTER')) -assert(__evolved_insert(__QUERY, __NAME, 'QUERY')) -assert(__evolved_insert(__EXECUTE, __NAME, 'EXECUTE')) +assert(__evolved_set(__QUERY, __NAME, 'QUERY')) +assert(__evolved_set(__EXECUTE, __NAME, 'EXECUTE')) -assert(__evolved_insert(__PROLOGUE, __NAME, 'PROLOGUE')) -assert(__evolved_insert(__EPILOGUE, __NAME, 'EPILOGUE')) +assert(__evolved_set(__PROLOGUE, __NAME, 'PROLOGUE')) +assert(__evolved_set(__EPILOGUE, __NAME, 'EPILOGUE')) -assert(__evolved_insert(__DISABLED, __NAME, 'DISABLED')) +assert(__evolved_set(__DISABLED, __NAME, 'DISABLED')) -assert(__evolved_insert(__DESTROY_POLICY, __NAME, 'DESTROY_POLICY')) -assert(__evolved_insert(__DESTROY_POLICY_DESTROY_ENTITY, __NAME, 'DESTROY_POLICY_DESTROY_ENTITY')) -assert(__evolved_insert(__DESTROY_POLICY_REMOVE_FRAGMENT, __NAME, 'DESTROY_POLICY_REMOVE_FRAGMENT')) +assert(__evolved_set(__DESTROY_POLICY, __NAME, 'DESTROY_POLICY')) +assert(__evolved_set(__DESTROY_POLICY_DESTROY_ENTITY, __NAME, 'DESTROY_POLICY_DESTROY_ENTITY')) +assert(__evolved_set(__DESTROY_POLICY_REMOVE_FRAGMENT, __NAME, 'DESTROY_POLICY_REMOVE_FRAGMENT')) --- --- @@ -8464,14 +8071,14 @@ assert(__evolved_insert(__DESTROY_POLICY_REMOVE_FRAGMENT, __NAME, 'DESTROY_POLIC --- --- -assert(__evolved_insert(__TAG, __TAG)) +assert(__evolved_set(__TAG, __TAG)) -assert(__evolved_insert(__INCLUDES, __CONSTRUCT, __component_list)) -assert(__evolved_insert(__EXCLUDES, __CONSTRUCT, __component_list)) +assert(__evolved_set(__INCLUDES, __CONSTRUCT, __component_list)) +assert(__evolved_set(__EXCLUDES, __CONSTRUCT, __component_list)) -assert(__evolved_insert(__AFTER, __CONSTRUCT, __component_list)) +assert(__evolved_set(__AFTER, __CONSTRUCT, __component_list)) -assert(__evolved_insert(__DISABLED, __TAG)) +assert(__evolved_set(__DISABLED, __TAG)) --- --- @@ -8481,7 +8088,7 @@ assert(__evolved_insert(__DISABLED, __TAG)) ---@param query evolved.query ---@param include_list evolved.fragment[] -assert(__evolved_insert(__INCLUDES, __ON_SET, function(query, _, include_list) +assert(__evolved_set(__INCLUDES, __ON_SET, function(query, _, include_list) local include_count = #include_list if include_count == 0 then @@ -8500,7 +8107,7 @@ assert(__evolved_insert(__INCLUDES, __ON_SET, function(query, _, include_list) __query_sorted_includes[query] = sorted_includes end)) -assert(__evolved_insert(__INCLUDES, __ON_REMOVE, function(query) +assert(__evolved_set(__INCLUDES, __ON_REMOVE, function(query) __query_sorted_includes[query] = nil end)) @@ -8512,7 +8119,7 @@ end)) ---@param query evolved.query ---@param exclude_list evolved.fragment[] -assert(__evolved_insert(__EXCLUDES, __ON_SET, function(query, _, exclude_list) +assert(__evolved_set(__EXCLUDES, __ON_SET, function(query, _, exclude_list) local exclude_count = #exclude_list if exclude_count == 0 then @@ -8531,7 +8138,7 @@ assert(__evolved_insert(__EXCLUDES, __ON_SET, function(query, _, exclude_list) __query_sorted_excludes[query] = sorted_excludes end)) -assert(__evolved_insert(__EXCLUDES, __ON_REMOVE, function(query) +assert(__evolved_set(__EXCLUDES, __ON_REMOVE, function(query) __query_sorted_excludes[query] = nil end)) @@ -8544,7 +8151,7 @@ end)) ---@param group evolved.group ---@param new_phase evolved.phase ---@param old_phase? evolved.phase -assert(__evolved_insert(__PHASE, __ON_SET, function(group, _, new_phase, old_phase) +assert(__evolved_set(__PHASE, __ON_SET, function(group, _, new_phase, old_phase) if new_phase == old_phase then return end @@ -8573,7 +8180,7 @@ end)) ---@param group evolved.group ---@param old_phase evolved.phase -assert(__evolved_insert(__PHASE, __ON_REMOVE, function(group, _, old_phase) +assert(__evolved_set(__PHASE, __ON_REMOVE, function(group, _, old_phase) local old_phase_groups = __phase_groups[old_phase] if old_phase_groups then @@ -8594,7 +8201,7 @@ end)) ---@param system evolved.system ---@param new_group evolved.group ---@param old_group? evolved.group -assert(__evolved_insert(__GROUP, __ON_SET, function(system, _, new_group, old_group) +assert(__evolved_set(__GROUP, __ON_SET, function(system, _, new_group, old_group) if new_group == old_group then return end @@ -8623,7 +8230,7 @@ end)) ---@param system evolved.system ---@param old_group evolved.group -assert(__evolved_insert(__GROUP, __ON_REMOVE, function(system, _, old_group) +assert(__evolved_set(__GROUP, __ON_REMOVE, function(system, _, old_group) local old_group_systems = __group_systems[old_group] if old_group_systems then @@ -8643,7 +8250,7 @@ end)) ---@param group evolved.group ---@param new_after_list evolved.group[] -assert(__evolved_insert(__AFTER, __ON_SET, function(group, _, new_after_list) +assert(__evolved_set(__AFTER, __ON_SET, function(group, _, new_after_list) local new_after_count = #new_after_list if new_after_count == 0 then @@ -8662,7 +8269,7 @@ assert(__evolved_insert(__AFTER, __ON_SET, function(group, _, new_after_list) end)) ---@param group evolved.group -assert(__evolved_insert(__AFTER, __ON_REMOVE, function(group) +assert(__evolved_set(__AFTER, __ON_REMOVE, function(group) __group_dependencies[group] = nil end)) @@ -8724,8 +8331,6 @@ evolved.has_all = __evolved_has_all evolved.has_any = __evolved_has_any evolved.set = __evolved_set -evolved.assign = __evolved_assign -evolved.insert = __evolved_insert evolved.remove = __evolved_remove evolved.clear = __evolved_clear evolved.destroy = __evolved_destroy From de07afb382d7c50ba69c4e1373e9ca7640557d64 Mon Sep 17 00:00:00 2001 From: BlackMATov Date: Thu, 20 Mar 2025 04:17:31 +0700 Subject: [PATCH 02/12] fix tests after the evolved.assign/insert removing --- develop/untests.lua | 926 +++++++++++++++++++++----------------------- 1 file changed, 431 insertions(+), 495 deletions(-) diff --git a/develop/untests.lua b/develop/untests.lua index 0d57966..8ae11f1 100644 --- a/develop/untests.lua +++ b/develop/untests.lua @@ -120,7 +120,7 @@ do assert(c1 == nil and c2 == nil) end - assert(evo.insert(e, f1, 41)) + assert(evo.set(e, f1, 41)) do assert(evo.has(e, f1)) @@ -137,7 +137,7 @@ do assert(c1 == 41 and c2 == nil) end - assert(evo.insert(e, f2, 42)) + assert(evo.set(e, f2, 42)) do assert(evo.has(e, f1)) @@ -159,12 +159,9 @@ do local f1, f2 = evo.id(2) local e = evo.id() - assert(evo.insert(e, f1, 41)) - assert(not evo.insert(e, f1, 42)) + assert(evo.set(e, f1, 41)) - assert(evo.insert(e, f2, 42)) - assert(not evo.insert(e, f1, 42)) - assert(not evo.insert(e, f2, 41)) + assert(evo.set(e, f2, 42)) do assert(evo.has_all(e, f1, f2)) @@ -178,8 +175,8 @@ do do local e = evo.id() - assert(evo.insert(e, f1, 41)) - assert(evo.insert(e, f2, 42)) + assert(evo.set(e, f1, 41)) + assert(evo.set(e, f2, 42)) evo.remove(e, f1) @@ -192,8 +189,8 @@ do do local e = evo.id() - assert(evo.insert(e, f1, 41)) - assert(evo.insert(e, f2, 42)) + assert(evo.set(e, f1, 41)) + assert(evo.set(e, f2, 42)) evo.remove(e, f2) @@ -206,8 +203,8 @@ do do local e = evo.id() - assert(evo.insert(e, f1, 41)) - assert(evo.insert(e, f2, 42)) + assert(evo.set(e, f1, 41)) + assert(evo.set(e, f2, 42)) evo.remove(e, f1, f2) @@ -222,22 +219,22 @@ do local f1, f2 = evo.id(2) local e1, e2 = evo.id(2) - assert(evo.insert(e1, f1, 41)) - assert(evo.insert(e2, f2, 42)) + assert(evo.set(e1, f1, 41)) + assert(evo.set(e2, f2, 42)) do assert(evo.get(e1, f1) == 41 and evo.get(e1, f2) == nil) assert(evo.get(e2, f2) == 42 and evo.get(e2, f1) == nil) end - assert(evo.insert(e1, f2, 43)) + assert(evo.set(e1, f2, 43)) do assert(evo.get(e1, f1) == 41 and evo.get(e1, f2) == 43) assert(evo.get(e2, f2) == 42 and evo.get(e2, f1) == nil) end - assert(evo.insert(e2, f1, 44)) + assert(evo.set(e2, f1, 44)) do assert(evo.get(e1, f1) == 41 and evo.get(e1, f2) == 43) @@ -251,10 +248,10 @@ do do local e1, e2 = evo.id(2) - assert(evo.insert(e1, f1, 41)) - assert(evo.insert(e1, f2, 43)) - assert(evo.insert(e2, f1, 44)) - assert(evo.insert(e2, f2, 42)) + assert(evo.set(e1, f1, 41)) + assert(evo.set(e1, f2, 43)) + assert(evo.set(e2, f1, 44)) + assert(evo.set(e2, f2, 42)) do assert(evo.get(e1, f1) == 41 and evo.get(e1, f2) == 43) @@ -281,10 +278,10 @@ do local f1, f2 = evo.id(2) local e1, e2 = evo.id(2) - assert(evo.insert(e1, f1, 41)) - assert(evo.insert(e1, f2, 43)) - assert(evo.insert(e2, f1, 44)) - assert(evo.insert(e2, f2, 42)) + assert(evo.set(e1, f1, 41)) + assert(evo.set(e1, f2, 43)) + assert(evo.set(e2, f1, 44)) + assert(evo.set(e2, f2, 42)) evo.clear(e1) @@ -306,18 +303,16 @@ do local e = evo.id() - assert(not evo.assign(e, f1, 41)) assert(evo.get(e, f1) == nil) - assert(evo.insert(e, f1, 41)) - assert(evo.assign(e, f1, 42)) + assert(evo.set(e, f1, 41)) + assert(evo.set(e, f1, 42)) assert(evo.get(e, f1) == 42) - assert(not evo.assign(e, f2, 43)) assert(evo.get(e, f2) == nil) - assert(evo.insert(e, f2, 43)) - assert(evo.assign(e, f2, 44)) + assert(evo.set(e, f2, 43)) + assert(evo.set(e, f2, 44)) assert(evo.get(e, f2) == 44) end @@ -397,20 +392,20 @@ do local e = evo.id() - evo.insert(e, f1, 43, 1) - evo.insert(e, f2, false) - evo.insert(e, f3, 43) - evo.insert(e, f4, 43) + evo.set(e, f1, 43, 1) + evo.set(e, f2, false) + evo.set(e, f3, 43) + evo.set(e, f4, 43) assert(evo.get(e, f1) == 42) assert(evo.get(e, f2) == false) assert(evo.get(e, f3) == true) assert(evo.get(e, f4) == false) - evo.assign(e, f1, 42, 2) - evo.assign(e, f2, true) - evo.assign(e, f3, 43) - evo.assign(e, f4, 43) + evo.set(e, f1, 42, 2) + evo.set(e, f2, true) + evo.set(e, f3, 43) + evo.set(e, f4, 43) assert(evo.get(e, f1) == 40) assert(evo.get(e, f2) == true) @@ -486,7 +481,7 @@ do last_remove_old_component = old_component end) - assert(evo.insert(e, f, 21)) + assert(evo.set(e, f, 21)) assert(set_count == 1) assert(assign_count == 0) assert(insert_count == 1) @@ -495,7 +490,7 @@ do assert(last_set_new_component == 21) assert(last_insert_new_component == 21) - assert(evo.assign(e, f, 42)) + assert(evo.set(e, f, 42)) assert(set_count == 2) assert(assign_count == 1) assert(insert_count == 1) @@ -505,7 +500,7 @@ do assert(last_assign_new_component == 42) assert(last_assign_old_component == 21) - assert(evo.assign(e, f, 43)) + assert(evo.set(e, f, 43)) assert(set_count == 3) assert(assign_count == 2) assert(insert_count == 1) @@ -570,24 +565,24 @@ do last_removed_component = component end) - assert(evo.insert(e, f1, 42)) + assert(evo.set(e, f1, 42)) evo.remove(e, f1, f2) assert(remove_count == 1) assert(last_removed_component == 42) - assert(evo.insert(e, f1, 42)) - assert(evo.insert(e, f2, 43)) + assert(evo.set(e, f1, 42)) + assert(evo.set(e, f2, 43)) evo.remove(e, f1, f2, f2) assert(remove_count == 3) assert(last_removed_component == 43) - assert(evo.insert(e, f1, 44)) - assert(evo.insert(e, f2, 45)) + assert(evo.set(e, f1, 44)) + assert(evo.set(e, f2, 45)) evo.clear(e) assert(remove_count == 5) - assert(evo.insert(e, f1, 46)) - assert(evo.insert(e, f2, 47)) + assert(evo.set(e, f1, 46)) + assert(evo.set(e, f2, 47)) evo.destroy(e) assert(remove_count == 7) end @@ -596,7 +591,7 @@ do local f = evo.id() local e = evo.id() - assert(evo.insert(e, f, 42)) + assert(evo.set(e, f, 42)) assert(evo.has(e, f)) assert(evo.is_alive(e)) @@ -612,7 +607,7 @@ do local e = evo.id() assert(evo.is_empty(e)) - evo.insert(e, f, 42) + evo.set(e, f, 42) assert(not evo.is_empty(e)) evo.clear(e) @@ -623,7 +618,7 @@ do local e = evo.id() assert(evo.is_empty(e)) - evo.insert(e, f, 42) + evo.set(e, f, 42) assert(not evo.is_empty(e)) evo.destroy(e) @@ -637,15 +632,15 @@ do local _ = evo.id() local e1 = evo.id() - assert(evo.insert(e1, f1, 41)) + assert(evo.set(e1, f1, 41)) local e2 = evo.id() - assert(evo.insert(e2, f1, 42)) - assert(evo.insert(e2, f2, 43)) + assert(evo.set(e2, f1, 42)) + assert(evo.set(e2, f2, 43)) local e2b = evo.id() - assert(evo.insert(e2b, f1, 44)) - assert(evo.insert(e2b, f2, 45)) + assert(evo.set(e2b, f1, 44)) + assert(evo.set(e2b, f2, 45)) do local chunk, entities = evo.chunk(f1) @@ -682,15 +677,15 @@ do local e1, e2, e3, e4 = evo.id(4) - assert(evo.insert(e1, f3, 44)) + assert(evo.set(e1, f3, 44)) - assert(evo.insert(e2, f1, 45)) - assert(evo.insert(e2, f2, 46)) - assert(evo.insert(e2, f3, 47)) + assert(evo.set(e2, f1, 45)) + assert(evo.set(e2, f2, 46)) + assert(evo.set(e2, f3, 47)) - assert(evo.insert(e3, f1, 45)) - assert(evo.insert(e3, f2, 46)) - assert(evo.insert(e3, f3, 47)) + assert(evo.set(e3, f1, 45)) + assert(evo.set(e3, f2, 46)) + assert(evo.set(e3, f3, 47)) assert(evo.defer()) assert(not evo.defer()) @@ -698,10 +693,9 @@ do evo.set(e1, f1) evo.set(e1, f2, 43) evo.remove(e2, f1, f2) - evo.assign(e2, f3, 48) + evo.set(e2, f3, 48) evo.clear(e3) - evo.insert(e3, f1, 48) - evo.insert(e3, f1, 49) + evo.set(e3, f1, 48) evo.destroy(e4) assert(evo.get(e1, f1) == nil) @@ -742,7 +736,7 @@ do ---@param component evolved.component evo.set(f1, evo.ON_SET, function(entity, fragment, component) assert(fragment == f1) - evo.insert(entity, f2, component * 2) + evo.set(entity, f2, component * 2) end) ---@param entity evolved.entity @@ -797,7 +791,7 @@ do ---@param component evolved.component evo.set(f1, evo.ON_INSERT, function(entity, fragment, component) assert(fragment == f1) - evo.insert(entity, f2, component * 2) + evo.set(entity, f2, component * 2) end) ---@param entity evolved.entity @@ -812,7 +806,7 @@ do do local e = evo.id() - assert(evo.insert(e, f1, 21)) + assert(evo.set(e, f1, 21)) assert(evo.get(e, f1) == 21) assert(evo.get(e, f2) == 42) @@ -823,7 +817,7 @@ do do local e = evo.id() - assert(evo.insert(e, f1, 21)) + assert(evo.set(e, f1, 21)) assert(evo.get(e, f1) == 21) assert(evo.get(e, f2) == 42) @@ -834,7 +828,7 @@ do do local e = evo.id() - assert(evo.insert(e, f1, 21)) + assert(evo.set(e, f1, 21)) assert(evo.get(e, f1) == 21) assert(evo.get(e, f2) == 42) @@ -849,30 +843,30 @@ do local f1, f2, f3, f4 = evo.id(4) local e1 = evo.id() - assert(evo.insert(e1, f1, 41)) + assert(evo.set(e1, f1, 41)) local e2 = evo.id() - assert(evo.insert(e2, f1, 42)) - assert(evo.insert(e2, f2, 43)) + assert(evo.set(e2, f1, 42)) + assert(evo.set(e2, f2, 43)) local e3 = evo.id() - assert(evo.insert(e3, f1, 44)) - assert(evo.insert(e3, f2, 45)) - assert(evo.insert(e3, f3, 46)) + assert(evo.set(e3, f1, 44)) + assert(evo.set(e3, f2, 45)) + assert(evo.set(e3, f3, 46)) local e4 = evo.id() - assert(evo.insert(e4, f1, 47)) - assert(evo.insert(e4, f2, 48)) - assert(evo.insert(e4, f3, 49)) - assert(evo.insert(e4, f4, 50)) + assert(evo.set(e4, f1, 47)) + assert(evo.set(e4, f2, 48)) + assert(evo.set(e4, f3, 49)) + assert(evo.set(e4, f4, 50)) local e5 = evo.id() - assert(evo.insert(e5, f2, 51)) - assert(evo.insert(e5, f3, 52)) - assert(evo.insert(e5, f4, 53)) + assert(evo.set(e5, f2, 51)) + assert(evo.set(e5, f3, 52)) + assert(evo.set(e5, f4, 53)) local q = evo.id() - evo.insert(q, evo.INCLUDES, f1, f2) + evo.set(q, evo.INCLUDES, f1, f2) assert(evo.batch_assign(q, f1, 60) == 3) @@ -909,30 +903,30 @@ do end) local e1 = evo.id() - assert(evo.insert(e1, f1, 41)) + assert(evo.set(e1, f1, 41)) local e2 = evo.id() - assert(evo.insert(e2, f1, 42)) - assert(evo.insert(e2, f2, 43)) + assert(evo.set(e2, f1, 42)) + assert(evo.set(e2, f2, 43)) local e3 = evo.id() - assert(evo.insert(e3, f1, 44)) - assert(evo.insert(e3, f2, 45)) - assert(evo.insert(e3, f3, 46)) + assert(evo.set(e3, f1, 44)) + assert(evo.set(e3, f2, 45)) + assert(evo.set(e3, f3, 46)) local e4 = evo.id() - assert(evo.insert(e4, f1, 47)) - assert(evo.insert(e4, f2, 48)) - assert(evo.insert(e4, f3, 49)) - assert(evo.insert(e4, f4, 50)) + assert(evo.set(e4, f1, 47)) + assert(evo.set(e4, f2, 48)) + assert(evo.set(e4, f3, 49)) + assert(evo.set(e4, f4, 50)) local e5 = evo.id() - assert(evo.insert(e5, f2, 51)) - assert(evo.insert(e5, f3, 52)) - assert(evo.insert(e5, f4, 53)) + assert(evo.set(e5, f2, 51)) + assert(evo.set(e5, f3, 52)) + assert(evo.set(e5, f4, 53)) local q = evo.id() - evo.insert(q, evo.INCLUDES, f1, f2) + evo.set(q, evo.INCLUDES, f1, f2) assert(evo.batch_assign(q, f1, 60) == 3) @@ -967,30 +961,30 @@ do local f1, f2, f3, f4 = evo.id(4) local e1 = evo.id() - assert(evo.insert(e1, f1, 41)) + assert(evo.set(e1, f1, 41)) local e2 = evo.id() - assert(evo.insert(e2, f1, 42)) - assert(evo.insert(e2, f2, 43)) + assert(evo.set(e2, f1, 42)) + assert(evo.set(e2, f2, 43)) local e3 = evo.id() - assert(evo.insert(e3, f1, 44)) - assert(evo.insert(e3, f2, 45)) - assert(evo.insert(e3, f3, 46)) + assert(evo.set(e3, f1, 44)) + assert(evo.set(e3, f2, 45)) + assert(evo.set(e3, f3, 46)) local e4 = evo.id() - assert(evo.insert(e4, f1, 47)) - assert(evo.insert(e4, f2, 48)) - assert(evo.insert(e4, f3, 49)) - assert(evo.insert(e4, f4, 50)) + assert(evo.set(e4, f1, 47)) + assert(evo.set(e4, f2, 48)) + assert(evo.set(e4, f3, 49)) + assert(evo.set(e4, f4, 50)) local e5 = evo.id() - assert(evo.insert(e5, f2, 51)) - assert(evo.insert(e5, f3, 52)) - assert(evo.insert(e5, f4, 53)) + assert(evo.set(e5, f2, 51)) + assert(evo.set(e5, f3, 52)) + assert(evo.set(e5, f4, 53)) local q = evo.id() - evo.insert(q, evo.INCLUDES, f1, f2) + evo.set(q, evo.INCLUDES, f1, f2) assert(evo.batch_clear(q) == 3) @@ -1037,30 +1031,30 @@ do end) local e1 = evo.id() - assert(evo.insert(e1, f1, 41)) + assert(evo.set(e1, f1, 41)) local e2 = evo.id() - assert(evo.insert(e2, f1, 42)) - assert(evo.insert(e2, f2, 43)) + assert(evo.set(e2, f1, 42)) + assert(evo.set(e2, f2, 43)) local e3 = evo.id() - assert(evo.insert(e3, f1, 44)) - assert(evo.insert(e3, f2, 45)) - assert(evo.insert(e3, f3, 46)) + assert(evo.set(e3, f1, 44)) + assert(evo.set(e3, f2, 45)) + assert(evo.set(e3, f3, 46)) local e4 = evo.id() - assert(evo.insert(e4, f1, 47)) - assert(evo.insert(e4, f2, 48)) - assert(evo.insert(e4, f3, 49)) - assert(evo.insert(e4, f4, 50)) + assert(evo.set(e4, f1, 47)) + assert(evo.set(e4, f2, 48)) + assert(evo.set(e4, f3, 49)) + assert(evo.set(e4, f4, 50)) local e5 = evo.id() - assert(evo.insert(e5, f2, 51)) - assert(evo.insert(e5, f3, 52)) - assert(evo.insert(e5, f4, 53)) + assert(evo.set(e5, f2, 51)) + assert(evo.set(e5, f3, 52)) + assert(evo.set(e5, f4, 53)) local q = evo.id() - evo.insert(q, evo.INCLUDES, f1, f2) + evo.set(q, evo.INCLUDES, f1, f2) assert(evo.batch_clear(q) == 3) assert(entity_sum == e2 * 2 + e3 * 3 + e4 * 4) @@ -1085,30 +1079,30 @@ do local f1, f2, f3, f4 = evo.id(4) local e1 = evo.id() - assert(evo.insert(e1, f1, 41)) + assert(evo.set(e1, f1, 41)) local e2 = evo.id() - assert(evo.insert(e2, f1, 42)) - assert(evo.insert(e2, f2, 43)) + assert(evo.set(e2, f1, 42)) + assert(evo.set(e2, f2, 43)) local e3 = evo.id() - assert(evo.insert(e3, f1, 44)) - assert(evo.insert(e3, f2, 45)) - assert(evo.insert(e3, f3, 46)) + assert(evo.set(e3, f1, 44)) + assert(evo.set(e3, f2, 45)) + assert(evo.set(e3, f3, 46)) local e4 = evo.id() - assert(evo.insert(e4, f1, 47)) - assert(evo.insert(e4, f2, 48)) - assert(evo.insert(e4, f3, 49)) - assert(evo.insert(e4, f4, 50)) + assert(evo.set(e4, f1, 47)) + assert(evo.set(e4, f2, 48)) + assert(evo.set(e4, f3, 49)) + assert(evo.set(e4, f4, 50)) local e5 = evo.id() - assert(evo.insert(e5, f2, 51)) - assert(evo.insert(e5, f3, 52)) - assert(evo.insert(e5, f4, 53)) + assert(evo.set(e5, f2, 51)) + assert(evo.set(e5, f3, 52)) + assert(evo.set(e5, f4, 53)) local q = evo.id() - evo.insert(q, evo.INCLUDES, f1, f2) + evo.set(q, evo.INCLUDES, f1, f2) assert(evo.batch_destroy(q) == 3) @@ -1155,30 +1149,30 @@ do end) local e1 = evo.id() - assert(evo.insert(e1, f1, 41)) + assert(evo.set(e1, f1, 41)) local e2 = evo.id() - assert(evo.insert(e2, f1, 42)) - assert(evo.insert(e2, f2, 43)) + assert(evo.set(e2, f1, 42)) + assert(evo.set(e2, f2, 43)) local e3 = evo.id() - assert(evo.insert(e3, f1, 44)) - assert(evo.insert(e3, f2, 45)) - assert(evo.insert(e3, f3, 46)) + assert(evo.set(e3, f1, 44)) + assert(evo.set(e3, f2, 45)) + assert(evo.set(e3, f3, 46)) local e4 = evo.id() - assert(evo.insert(e4, f1, 47)) - assert(evo.insert(e4, f2, 48)) - assert(evo.insert(e4, f3, 49)) - assert(evo.insert(e4, f4, 50)) + assert(evo.set(e4, f1, 47)) + assert(evo.set(e4, f2, 48)) + assert(evo.set(e4, f3, 49)) + assert(evo.set(e4, f4, 50)) local e5 = evo.id() - assert(evo.insert(e5, f2, 51)) - assert(evo.insert(e5, f3, 52)) - assert(evo.insert(e5, f4, 53)) + assert(evo.set(e5, f2, 51)) + assert(evo.set(e5, f3, 52)) + assert(evo.set(e5, f4, 53)) local q = evo.id() - evo.insert(q, evo.INCLUDES, f1, f2) + evo.set(q, evo.INCLUDES, f1, f2) assert(evo.batch_destroy(q) == 3) assert(entity_sum == e2 * 2 + e3 * 3 + e4 * 4) @@ -1203,30 +1197,30 @@ do local f1, f2, f3, f4 = evo.id(4) local e1 = evo.id() - assert(evo.insert(e1, f1, 41)) + assert(evo.set(e1, f1, 41)) local e2 = evo.id() - assert(evo.insert(e2, f1, 42)) - assert(evo.insert(e2, f2, 43)) + assert(evo.set(e2, f1, 42)) + assert(evo.set(e2, f2, 43)) local e3 = evo.id() - assert(evo.insert(e3, f1, 44)) - assert(evo.insert(e3, f2, 45)) - assert(evo.insert(e3, f3, 46)) + assert(evo.set(e3, f1, 44)) + assert(evo.set(e3, f2, 45)) + assert(evo.set(e3, f3, 46)) local e4 = evo.id() - assert(evo.insert(e4, f1, 47)) - assert(evo.insert(e4, f2, 48)) - assert(evo.insert(e4, f3, 49)) - assert(evo.insert(e4, f4, 50)) + assert(evo.set(e4, f1, 47)) + assert(evo.set(e4, f2, 48)) + assert(evo.set(e4, f3, 49)) + assert(evo.set(e4, f4, 50)) local e5 = evo.id() - assert(evo.insert(e5, f2, 51)) - assert(evo.insert(e5, f3, 52)) - assert(evo.insert(e5, f4, 53)) + assert(evo.set(e5, f2, 51)) + assert(evo.set(e5, f3, 52)) + assert(evo.set(e5, f4, 53)) local q = evo.id() - evo.insert(q, evo.INCLUDES, f1, f2) + evo.set(q, evo.INCLUDES, f1, f2) assert(evo.batch_remove(q, f2, f3) == 3) @@ -1276,30 +1270,30 @@ do end) local e1 = evo.id() - assert(evo.insert(e1, f1, 41)) + assert(evo.set(e1, f1, 41)) local e2 = evo.id() - assert(evo.insert(e2, f1, 42)) - assert(evo.insert(e2, f2, 43)) + assert(evo.set(e2, f1, 42)) + assert(evo.set(e2, f2, 43)) local e3 = evo.id() - assert(evo.insert(e3, f1, 44)) - assert(evo.insert(e3, f2, 45)) - assert(evo.insert(e3, f3, 46)) + assert(evo.set(e3, f1, 44)) + assert(evo.set(e3, f2, 45)) + assert(evo.set(e3, f3, 46)) local e4 = evo.id() - assert(evo.insert(e4, f1, 47)) - assert(evo.insert(e4, f2, 48)) - assert(evo.insert(e4, f3, 49)) - assert(evo.insert(e4, f4, 50)) + assert(evo.set(e4, f1, 47)) + assert(evo.set(e4, f2, 48)) + assert(evo.set(e4, f3, 49)) + assert(evo.set(e4, f4, 50)) local e5 = evo.id() - assert(evo.insert(e5, f2, 51)) - assert(evo.insert(e5, f3, 52)) - assert(evo.insert(e5, f4, 53)) + assert(evo.set(e5, f2, 51)) + assert(evo.set(e5, f3, 52)) + assert(evo.set(e5, f4, 53)) local q = evo.id() - evo.insert(q, evo.INCLUDES, f1, f2) + evo.set(q, evo.INCLUDES, f1, f2) assert(evo.batch_remove(q, f2, f3, f3) == 3) assert(entity_sum == e2 + e3 * 2 + e4 * 2) @@ -1334,24 +1328,24 @@ do local f1, f2, f3, f4 = evo.id(4) local e1 = evo.id() - assert(evo.insert(e1, f1, 41)) + assert(evo.set(e1, f1, 41)) local e2 = evo.id() - assert(evo.insert(e2, f1, 42)) - assert(evo.insert(e2, f2, 43)) + assert(evo.set(e2, f1, 42)) + assert(evo.set(e2, f2, 43)) local e3 = evo.id() - assert(evo.insert(e3, f1, 44)) - assert(evo.insert(e3, f2, 45)) - assert(evo.insert(e3, f3, 46)) + assert(evo.set(e3, f1, 44)) + assert(evo.set(e3, f2, 45)) + assert(evo.set(e3, f3, 46)) local e4 = evo.id() - assert(evo.insert(e4, f2, 48)) - assert(evo.insert(e4, f3, 49)) - assert(evo.insert(e4, f4, 50)) + assert(evo.set(e4, f2, 48)) + assert(evo.set(e4, f3, 49)) + assert(evo.set(e4, f4, 50)) local q = evo.id() - evo.insert(q, evo.INCLUDES, f2) + evo.set(q, evo.INCLUDES, f2) assert(evo.batch_insert(q, f1, 60) == 1) @@ -1379,24 +1373,24 @@ do end) local e1 = evo.id() - assert(evo.insert(e1, f1, 41)) + assert(evo.set(e1, f1, 41)) local e2 = evo.id() - assert(evo.insert(e2, f1, 42)) - assert(evo.insert(e2, f2, 43)) + assert(evo.set(e2, f1, 42)) + assert(evo.set(e2, f2, 43)) local e3 = evo.id() - assert(evo.insert(e3, f1, 44)) - assert(evo.insert(e3, f2, 45)) - assert(evo.insert(e3, f3, 46)) + assert(evo.set(e3, f1, 44)) + assert(evo.set(e3, f2, 45)) + assert(evo.set(e3, f3, 46)) local e4 = evo.id() - assert(evo.insert(e4, f2, 48)) - assert(evo.insert(e4, f3, 49)) - assert(evo.insert(e4, f4, 50)) + assert(evo.set(e4, f2, 48)) + assert(evo.set(e4, f3, 49)) + assert(evo.set(e4, f4, 50)) local q = evo.id() - evo.insert(q, evo.INCLUDES, f2) + evo.set(q, evo.INCLUDES, f2) entity_sum = 0 component_sum = 0 @@ -1422,24 +1416,24 @@ do local f1, f2, f3, f4 = evo.id(4) local e1 = evo.id() - assert(evo.insert(e1, f1, 41)) + assert(evo.set(e1, f1, 41)) local e2 = evo.id() - assert(evo.insert(e2, f1, 42)) - assert(evo.insert(e2, f2, 43)) + assert(evo.set(e2, f1, 42)) + assert(evo.set(e2, f2, 43)) local e3 = evo.id() - assert(evo.insert(e3, f1, 44)) - assert(evo.insert(e3, f2, 45)) - assert(evo.insert(e3, f3, 46)) + assert(evo.set(e3, f1, 44)) + assert(evo.set(e3, f2, 45)) + assert(evo.set(e3, f3, 46)) local e4 = evo.id() - assert(evo.insert(e4, f2, 48)) - assert(evo.insert(e4, f3, 49)) - assert(evo.insert(e4, f4, 50)) + assert(evo.set(e4, f2, 48)) + assert(evo.set(e4, f3, 49)) + assert(evo.set(e4, f4, 50)) local q = evo.id() - evo.insert(q, evo.INCLUDES, f2) + evo.set(q, evo.INCLUDES, f2) assert(evo.batch_set(q, f1, 60) == 3) @@ -1467,24 +1461,24 @@ do end) local e1 = evo.id() - assert(evo.insert(e1, f1, 41)) + assert(evo.set(e1, f1, 41)) local e2 = evo.id() - assert(evo.insert(e2, f1, 42)) - assert(evo.insert(e2, f2, 43)) + assert(evo.set(e2, f1, 42)) + assert(evo.set(e2, f2, 43)) local e3 = evo.id() - assert(evo.insert(e3, f1, 44)) - assert(evo.insert(e3, f2, 45)) - assert(evo.insert(e3, f3, 46)) + assert(evo.set(e3, f1, 44)) + assert(evo.set(e3, f2, 45)) + assert(evo.set(e3, f3, 46)) local e4 = evo.id() - assert(evo.insert(e4, f2, 48)) - assert(evo.insert(e4, f3, 49)) - assert(evo.insert(e4, f4, 50)) + assert(evo.set(e4, f2, 48)) + assert(evo.set(e4, f3, 49)) + assert(evo.set(e4, f4, 50)) local q = evo.id() - evo.insert(q, evo.INCLUDES, f2) + evo.set(q, evo.INCLUDES, f2) entity_sum = 0 component_sum = 0 @@ -1626,64 +1620,22 @@ do local e = evo.id() last_set_entity = 0 - assert(evo.insert(e, f1)) + assert(evo.set(e, f1)) assert(last_set_entity == e) assert(evo.has(e, f1) and not evo.has(e, f2)) assert(evo.get(e, f1) == nil and evo.get(e, f2) == nil) - do - last_set_entity = 0 - assert(not evo.insert(e, f1)) - assert(last_set_entity == 0) - assert(evo.has(e, f1) and not evo.has(e, f2)) - assert(evo.get(e, f1) == nil and evo.get(e, f2) == nil) - end - last_set_entity = 0 - assert(evo.insert(e, f2, 42)) + assert(evo.set(e, f2, 42)) assert(last_set_entity == e) assert(evo.has(e, f1) and evo.has(e, f2)) assert(evo.get(e, f1) == nil and evo.get(e, f2) == nil) - do - last_set_entity = 0 - assert(not evo.insert(e, f1)) - assert(last_set_entity == 0) - assert(evo.has(e, f1) and evo.has(e, f2)) - assert(evo.get(e, f1) == nil and evo.get(e, f2) == nil) - - last_set_entity = 0 - assert(not evo.insert(e, f2, 42)) - assert(last_set_entity == 0) - assert(evo.has(e, f1) and evo.has(e, f2)) - assert(evo.get(e, f1) == nil and evo.get(e, f2) == nil) - end - last_set_entity = 0 - assert(evo.insert(e, f3, 43)) + assert(evo.set(e, f3, 43)) assert(last_set_entity == e) assert(evo.has(e, f1) and evo.has(e, f2) and evo.has(e, f3)) assert(evo.get(e, f1) == nil and evo.get(e, f2) == nil and evo.get(e, f3) == 43) - - do - last_set_entity = 0 - assert(not evo.insert(e, f1)) - assert(last_set_entity == 0) - assert(evo.has(e, f1) and evo.has(e, f2) and evo.has(e, f3)) - assert(evo.get(e, f1) == nil and evo.get(e, f2) == nil and evo.get(e, f3) == 43) - - last_set_entity = 0 - assert(not evo.insert(e, f2, 42)) - assert(last_set_entity == 0) - assert(evo.has(e, f1) and evo.has(e, f2)) - assert(evo.get(e, f1) == nil and evo.get(e, f2) == nil and evo.get(e, f3) == 43) - - last_set_entity = 0 - assert(not evo.insert(e, f3, 44)) - assert(last_set_entity == 0) - assert(evo.has(e, f1) and evo.has(e, f2) and evo.has(e, f3)) - assert(evo.get(e, f1) == nil and evo.get(e, f2) == nil and evo.get(e, f3) == 43) - end end do @@ -1691,17 +1643,12 @@ do do last_assign_entity = 0 - assert(not evo.assign(e, f1)) - assert(last_assign_entity == 0) - assert(not evo.has(e, f1) and not evo.has(e, f2)) - assert(evo.get(e, f1) == nil and evo.get(e, f2) == nil) - - assert(evo.insert(e, f1)) + assert(evo.set(e, f1)) assert(evo.has(e, f1) and not evo.has(e, f2)) assert(evo.get(e, f1) == nil and evo.get(e, f2) == nil) last_assign_entity = 0 - assert(evo.assign(e, f1)) + assert(evo.set(e, f1)) assert(last_assign_entity == e) assert(evo.has(e, f1) and not evo.has(e, f2)) assert(evo.get(e, f1) == nil and evo.get(e, f2) == nil) @@ -1709,17 +1656,12 @@ do do last_assign_entity = 0 - assert(not evo.assign(e, f2, 43)) - assert(last_assign_entity == 0) - assert(evo.has(e, f1) and not evo.has(e, f2)) - assert(evo.get(e, f1) == nil and evo.get(e, f2) == nil) - - assert(evo.insert(e, f2, 43)) + assert(evo.set(e, f2, 43)) assert(evo.has(e, f1) and evo.has(e, f2)) assert(evo.get(e, f1) == nil and evo.get(e, f2) == nil) last_assign_entity = 0 - assert(evo.assign(e, f2, 44)) + assert(evo.set(e, f2, 44)) assert(last_assign_entity == e) assert(evo.has(e, f1) and evo.has(e, f2)) assert(evo.get(e, f1) == nil and evo.get(e, f2) == nil) @@ -1727,17 +1669,12 @@ do do last_assign_entity = 0 - assert(not evo.assign(e, f3, 44)) - assert(last_assign_entity == 0) - assert(evo.has(e, f1) and evo.has(e, f2) and not evo.has(e, f3)) - assert(evo.get(e, f1) == nil and evo.get(e, f2) == nil and evo.get(e, f3) == nil) - - assert(evo.insert(e, f3, 44)) + assert(evo.set(e, f3, 44)) assert(evo.has(e, f1) and evo.has(e, f2) and evo.has(e, f3)) assert(evo.get(e, f1) == nil and evo.get(e, f2) == nil and evo.get(e, f3) == 44) last_assign_entity = 0 - assert(evo.assign(e, f3, 45)) + assert(evo.set(e, f3, 45)) assert(last_assign_entity == e) assert(evo.has(e, f1) and evo.has(e, f2) and evo.has(e, f3)) assert(evo.get(e, f1) == nil and evo.get(e, f2) == nil and evo.get(e, f3) == 45) @@ -1747,7 +1684,7 @@ do do do local e = evo.id() - assert(evo.insert(e, f1, 41)) + assert(evo.set(e, f1, 41)) last_remove_entity = 0 assert(evo.remove(e, f1)) @@ -1758,8 +1695,8 @@ do do local e = evo.id() - assert(evo.insert(e, f1, 41)) - assert(evo.insert(e, f2, 42)) + assert(evo.set(e, f1, 41)) + assert(evo.set(e, f2, 42)) last_remove_entity = 0 assert(evo.remove(e, f1, f2)) @@ -1770,9 +1707,9 @@ do do local e = evo.id() - assert(evo.insert(e, f1, 41)) - assert(evo.insert(e, f2, 42)) - assert(evo.insert(e, f3, 43)) + assert(evo.set(e, f1, 41)) + assert(evo.set(e, f2, 42)) + assert(evo.set(e, f3, 43)) last_remove_entity = 0 assert(evo.remove(e, f1, f2, f3)) @@ -1782,9 +1719,9 @@ do do local e = evo.id() - assert(evo.insert(e, f1, 41)) - assert(evo.insert(e, f2, 42)) - assert(evo.insert(e, f3, 43)) + assert(evo.set(e, f1, 41)) + assert(evo.set(e, f2, 42)) + assert(evo.set(e, f3, 43)) last_remove_entity = 0 assert(evo.remove(e, f3)) @@ -1801,7 +1738,7 @@ do do do local e = evo.id() - assert(evo.insert(e, f1, 41)) + assert(evo.set(e, f1, 41)) last_remove_entity = 0 assert(evo.clear(e) and evo.is_alive(e)) @@ -1812,8 +1749,8 @@ do do local e = evo.id() - assert(evo.insert(e, f1, 41)) - assert(evo.insert(e, f2, 42)) + assert(evo.set(e, f1, 41)) + assert(evo.set(e, f2, 42)) last_remove_entity = 0 assert(evo.clear(e) and evo.is_alive(e)) @@ -1824,9 +1761,9 @@ do do local e = evo.id() - assert(evo.insert(e, f1, 41)) - assert(evo.insert(e, f2, 42)) - assert(evo.insert(e, f3, 43)) + assert(evo.set(e, f1, 41)) + assert(evo.set(e, f2, 42)) + assert(evo.set(e, f3, 43)) last_remove_entity = 0 assert(evo.clear(e) and evo.is_alive(e)) @@ -1839,7 +1776,7 @@ do do do local e = evo.id() - assert(evo.insert(e, f1, 41)) + assert(evo.set(e, f1, 41)) last_remove_entity = 0 assert(evo.destroy(e) and not evo.is_alive(e)) @@ -1850,8 +1787,8 @@ do do local e = evo.id() - assert(evo.insert(e, f1, 41)) - assert(evo.insert(e, f2, 42)) + assert(evo.set(e, f1, 41)) + assert(evo.set(e, f2, 42)) last_remove_entity = 0 assert(evo.destroy(e) and not evo.is_alive(e)) @@ -1862,9 +1799,9 @@ do do local e = evo.id() - assert(evo.insert(e, f1, 41)) - assert(evo.insert(e, f2, 42)) - assert(evo.insert(e, f3, 43)) + assert(evo.set(e, f1, 41)) + assert(evo.set(e, f2, 42)) + assert(evo.set(e, f3, 43)) last_remove_entity = 0 assert(evo.destroy(e) and not evo.is_alive(e)) @@ -1893,7 +1830,7 @@ do do local e = evo.id() - assert(evo.insert(e, f1, 41)) + assert(evo.set(e, f1, 41)) assert(evo.batch_assign(q, f1, 50) == 0) assert(evo.has(e, f1)) @@ -1902,13 +1839,13 @@ do do local e1 = evo.id() - assert(evo.insert(e1, f1, 41)) - assert(evo.insert(e1, f2, 42)) + assert(evo.set(e1, f1, 41)) + assert(evo.set(e1, f2, 42)) local e2 = evo.id() - assert(evo.insert(e2, f1, 41)) - assert(evo.insert(e2, f2, 42)) - assert(evo.insert(e2, f3, 43)) + assert(evo.set(e2, f1, 41)) + assert(evo.set(e2, f2, 42)) + assert(evo.set(e2, f3, 43)) assert(evo.batch_assign(q, f1, 50) == 2) assert(evo.has(e1, f1) and evo.has(e1, f2) and not evo.has(e1, f3)) @@ -1936,16 +1873,16 @@ do do local e1 = evo.id() - assert(evo.insert(e1, f1, 41)) - assert(evo.insert(e1, f2, 42)) + assert(evo.set(e1, f1, 41)) + assert(evo.set(e1, f2, 42)) local e2 = evo.id() - assert(evo.insert(e2, f1, 41)) + assert(evo.set(e2, f1, 41)) local e3 = evo.id() - assert(evo.insert(e3, f1, 41)) - assert(evo.insert(e3, f2, 42)) - assert(evo.insert(e3, f3, 43)) + assert(evo.set(e3, f1, 41)) + assert(evo.set(e3, f2, 42)) + assert(evo.set(e3, f3, 43)) assert(evo.batch_insert(q, f3, 50) == 1) @@ -1983,16 +1920,16 @@ do do local e1 = evo.id() - assert(evo.insert(e1, f1, 41)) - assert(evo.insert(e1, f2, 42)) + assert(evo.set(e1, f1, 41)) + assert(evo.set(e1, f2, 42)) local e2 = evo.id() - assert(evo.insert(e2, f1, 41)) + assert(evo.set(e2, f1, 41)) local e3 = evo.id() - assert(evo.insert(e3, f1, 41)) - assert(evo.insert(e3, f2, 42)) - assert(evo.insert(e3, f3, 43)) + assert(evo.set(e3, f1, 41)) + assert(evo.set(e3, f2, 42)) + assert(evo.set(e3, f3, 43)) assert(evo.batch_remove(q, f1) == 2) @@ -2034,16 +1971,16 @@ do do local e1 = evo.id() - assert(evo.insert(e1, f1, 41)) - assert(evo.insert(e1, f2, 42)) + assert(evo.set(e1, f1, 41)) + assert(evo.set(e1, f2, 42)) local e2 = evo.id() - assert(evo.insert(e2, f1, 41)) + assert(evo.set(e2, f1, 41)) local e3 = evo.id() - assert(evo.insert(e3, f1, 41)) - assert(evo.insert(e3, f2, 42)) - assert(evo.insert(e3, f3, 43)) + assert(evo.set(e3, f1, 41)) + assert(evo.set(e3, f2, 42)) + assert(evo.set(e3, f3, 43)) assert(evo.batch_clear(q) == 2) @@ -2079,16 +2016,16 @@ do do local e1 = evo.id() - assert(evo.insert(e1, f1, 41)) - assert(evo.insert(e1, f2, 42)) + assert(evo.set(e1, f1, 41)) + assert(evo.set(e1, f2, 42)) local e2 = evo.id() - assert(evo.insert(e2, f1, 41)) + assert(evo.set(e2, f1, 41)) local e3 = evo.id() - assert(evo.insert(e3, f1, 41)) - assert(evo.insert(e3, f2, 42)) - assert(evo.insert(e3, f3, 43)) + assert(evo.set(e3, f1, 41)) + assert(evo.set(e3, f2, 42)) + assert(evo.set(e3, f3, 43)) assert(evo.batch_destroy(q) == 2) @@ -2120,7 +2057,7 @@ do evo.set(q, evo.INCLUDES, f1) local e1 = evo.id() - assert(evo.insert(e1, f1, 41)) + assert(evo.set(e1, f1, 41)) do assert(evo.defer()) @@ -2156,7 +2093,7 @@ do evo.set(q, evo.INCLUDES, f1) local e1 = evo.id() - assert(evo.insert(e1, f1, 41)) + assert(evo.set(e1, f1, 41)) do assert(evo.defer()) @@ -2192,7 +2129,7 @@ do evo.set(q, evo.INCLUDES, f1) local e1 = evo.id() - assert(evo.insert(e1, f1, 41)) + assert(evo.set(e1, f1, 41)) do assert(evo.defer()) @@ -2228,7 +2165,7 @@ do evo.set(q, evo.INCLUDES, f1) local e1 = evo.id() - assert(evo.insert(e1, f1, 41)) + assert(evo.set(e1, f1, 41)) do assert(evo.defer()) @@ -2251,7 +2188,7 @@ do evo.set(q, evo.INCLUDES, f1) local e1 = evo.id() - assert(evo.insert(e1, f1, 41)) + assert(evo.set(e1, f1, 41)) do assert(evo.defer()) @@ -2276,7 +2213,7 @@ do evo.set(q, evo.INCLUDES, f1) local e1 = evo.id() - assert(evo.insert(e1, f1, 41)) + assert(evo.set(e1, f1, 41)) do assert(evo.defer()) @@ -2302,10 +2239,10 @@ do evo.set(q, evo.INCLUDES, f2) local e1 = evo.id() - assert(evo.insert(e1, f1, 41)) + assert(evo.set(e1, f1, 41)) local e2 = evo.id() - assert(evo.insert(e2, f2, 42)) + assert(evo.set(e2, f2, 42)) do local iter, state = evo.execute(q) @@ -2327,12 +2264,12 @@ do evo.set(q, evo.INCLUDES, f1) local e1 = evo.id() - assert(evo.insert(e1, f1, 41)) - assert(evo.insert(e1, f2, 42)) + assert(evo.set(e1, f1, 41)) + assert(evo.set(e1, f2, 42)) local e2 = evo.id() - assert(evo.insert(e2, f1, 43)) - assert(evo.insert(e2, f3, 44)) + assert(evo.set(e2, f1, 43)) + assert(evo.set(e2, f3, 44)) do local entity_sum = 0 @@ -2358,11 +2295,11 @@ do evo.set(q, evo.EXCLUDES, f2) local e1 = evo.id() - assert(evo.insert(e1, f1, 41)) + assert(evo.set(e1, f1, 41)) local e2 = evo.id() - assert(evo.insert(e2, f1, 43)) - assert(evo.insert(e2, f2, 44)) + assert(evo.set(e2, f1, 43)) + assert(evo.set(e2, f2, 44)) do local iter, state = evo.execute(q) @@ -2399,11 +2336,11 @@ do local q = evo.id() local e1 = evo.id() - assert(evo.insert(e1, f1, 41)) + assert(evo.set(e1, f1, 41)) local e2 = evo.id() - assert(evo.insert(e2, f1, 43)) - assert(evo.insert(e2, f2, 44)) + assert(evo.set(e2, f1, 43)) + assert(evo.set(e2, f2, 44)) do local iter, state = evo.execute(q) @@ -2442,7 +2379,7 @@ do do local e = evo.id() - assert(evo.insert(e, f1, 41)) + assert(evo.set(e, f1, 41)) local iter, state = evo.each(e) local fragment, component = iter(state) @@ -2454,8 +2391,8 @@ do do local e = evo.id() - assert(evo.insert(e, f1, 41)) - assert(evo.insert(e, f2, 42)) + assert(evo.set(e, f1, 41)) + assert(evo.set(e, f2, 42)) do local iter, state = evo.each(e) @@ -2488,8 +2425,8 @@ do evo.set(s, evo.TAG) local e = evo.id() - assert(evo.insert(e, f1)) - assert(evo.insert(e, s)) + assert(evo.set(e, f1)) + assert(evo.set(e, s)) do local iter, state = evo.each(e) @@ -2645,10 +2582,10 @@ do local e2 = evo.entity():set(f1, 42):set(f1, 41):build() assert(f1_assign_count == 0 and f1_insert_count == 2) - assert(evo.assign(e1, f1, 42)) + assert(evo.set(e1, f1, 42)) assert(f1_assign_count == 1 and f1_insert_count == 2) - assert(evo.assign(e2, f1, 42)) + assert(evo.set(e2, f1, 42)) assert(f1_assign_count == 2 and f1_insert_count == 2) assert(evo.get(e1, f1) == 42 and evo.get(e2, f1) == 42) @@ -3160,7 +3097,7 @@ do insert_entity_sum, insert_component_sum = 0, 0 local e = evo.id() - assert(evo.insert(e, f1, 41)) + assert(evo.set(e, f1, 41)) assert(evo.multi_assign(e, { f1, f1 }, { 42, 43 })) assert(assign_entity_sum == e + e and assign_component_sum == 42 + 43) @@ -3181,7 +3118,7 @@ do remove_entity_sum, remove_component_sum = 0, 0 local e = evo.id() - assert(evo.insert(e, f1, 41)) + assert(evo.set(e, f1, 41)) assert(evo.multi_remove(e, { f1, f1 })) assert(remove_entity_sum == e and remove_component_sum == 41) @@ -5111,7 +5048,7 @@ do assert(evo.set(e, f1)) assert(evo.set(e, f2, 22)) - assert(evo.assign(e, f2)) + assert(evo.set(e, f2)) assert(evo.get(e, f1) == true and evo.get(e, f2) == true) @@ -5120,8 +5057,7 @@ do assert(not evo.has_all(e, f1, f2) and not evo.has_any(e, f1, f2)) assert(not evo.set(e, f1, 11)) - assert(not evo.assign(e, f1, 11)) - assert(not evo.insert(e, f1, 11)) + assert(not evo.set(e, f1, 11)) assert(evo.remove(e, f1)) assert(evo.clear(e)) @@ -5316,12 +5252,12 @@ do end do local e1 = evo.id() - evo.insert(e1, f0) - evo.insert(e1, f1, 1) - evo.insert(e1, f2, 1, 2) - evo.insert(e1, f3, 1, 2, 3) - evo.insert(e1, f4, 1, 2, 3, 4) - evo.insert(e1, f5, 1, 2, 3, 4, 5) + evo.set(e1, f0) + evo.set(e1, f1, 1) + evo.set(e1, f2, 1, 2) + evo.set(e1, f3, 1, 2, 3) + evo.set(e1, f4, 1, 2, 3, 4) + evo.set(e1, f5, 1, 2, 3, 4, 5) assert(evo.get(e1, f0) == 42) assert(evo.get(e1, f1) == 1) assert(evo.get(e1, f2) == 1 + 2) @@ -5332,12 +5268,12 @@ do do local e1 = evo.id() evo.multi_insert(e1, { f0, f1, f2, f3, f4, f5 }) - evo.assign(e1, f0) - evo.assign(e1, f1, 1) - evo.assign(e1, f2, 1, 2) - evo.assign(e1, f3, 1, 2, 3) - evo.assign(e1, f4, 1, 2, 3, 4) - evo.assign(e1, f5, 1, 2, 3, 4, 5) + evo.set(e1, f0) + evo.set(e1, f1, 1) + evo.set(e1, f2, 1, 2) + evo.set(e1, f3, 1, 2, 3) + evo.set(e1, f4, 1, 2, 3, 4) + evo.set(e1, f5, 1, 2, 3, 4, 5) assert(evo.get(e1, f0) == 42) assert(evo.get(e1, f1) == 1) assert(evo.get(e1, f2) == 1 + 2) @@ -5414,18 +5350,18 @@ do do local e1, e2 = evo.id(2) assert(evo.defer()) - evo.insert(e1, f0) - evo.insert(e1, f1, 1) - evo.insert(e1, f2, 1, 2) - evo.insert(e1, f3, 1, 2, 3) - evo.insert(e1, f4, 1, 2, 3, 4) - evo.insert(e1, f5, 1, 2, 3, 4, 5) - evo.insert(e2, f0) - evo.insert(e2, f1, 1) - evo.insert(e2, f2, 1, 2) - evo.insert(e2, f3, 1, 2, 3) - evo.insert(e2, f4, 1, 2, 3, 4) - evo.insert(e2, f5, 1, 2, 3, 4, 5) + evo.set(e1, f0) + evo.set(e1, f1, 1) + evo.set(e1, f2, 1, 2) + evo.set(e1, f3, 1, 2, 3) + evo.set(e1, f4, 1, 2, 3, 4) + evo.set(e1, f5, 1, 2, 3, 4, 5) + evo.set(e2, f0) + evo.set(e2, f1, 1) + evo.set(e2, f2, 1, 2) + evo.set(e2, f3, 1, 2, 3) + evo.set(e2, f4, 1, 2, 3, 4) + evo.set(e2, f5, 1, 2, 3, 4, 5) assert(evo.commit()) assert(evo.get(e1, f0) == 42) assert(evo.get(e1, f1) == 1) @@ -5445,18 +5381,18 @@ do evo.multi_insert(e1, { f0, f1, f2, f3, f4, f5 }) evo.multi_insert(e2, { f0, f1, f2, f3, f4, f5 }) assert(evo.defer()) - evo.assign(e1, f0) - evo.assign(e1, f1, 1) - evo.assign(e1, f2, 1, 2) - evo.assign(e1, f3, 1, 2, 3) - evo.assign(e1, f4, 1, 2, 3, 4) - evo.assign(e1, f5, 1, 2, 3, 4, 5) - evo.assign(e2, f0) - evo.assign(e2, f1, 1) - evo.assign(e2, f2, 1, 2) - evo.assign(e2, f3, 1, 2, 3) - evo.assign(e2, f4, 1, 2, 3, 4) - evo.assign(e2, f5, 1, 2, 3, 4, 5) + evo.set(e1, f0) + evo.set(e1, f1, 1) + evo.set(e1, f2, 1, 2) + evo.set(e1, f3, 1, 2, 3) + evo.set(e1, f4, 1, 2, 3, 4) + evo.set(e1, f5, 1, 2, 3, 4, 5) + evo.set(e2, f0) + evo.set(e2, f1, 1) + evo.set(e2, f2, 1, 2) + evo.set(e2, f3, 1, 2, 3) + evo.set(e2, f4, 1, 2, 3, 4) + evo.set(e2, f5, 1, 2, 3, 4, 5) assert(evo.commit()) assert(evo.get(e1, f0) == 42) assert(evo.get(e1, f1) == 1) @@ -5818,7 +5754,7 @@ do assert(evo.get(e, f1) == c) do - local s, d = evo.assign(e, f2, c) + local s, d = evo.set(e, f2, c) assert(s and not d) end end) @@ -5829,7 +5765,7 @@ do assert(evo.get(e, f1) == c) do - local s, d = evo.insert(e, f2, c) + local s, d = evo.set(e, f2, c) assert(s and not d) end end) @@ -5923,12 +5859,12 @@ do local e = evo.id() - assert(evo.insert(e, f1, 41)) + assert(evo.set(e, f1, 41)) assert(evo.get(e, f1) == 41) assert(evo.get(e, f2) == 41) assert(assign_count == 0 and insert_count == 2 and remove_count == 0) - assert(evo.assign(e, f1, 51)) + assert(evo.set(e, f1, 51)) assert(evo.get(e, f1) == 51) assert(evo.get(e, f2) == 51) assert(assign_count == 2 and insert_count == 2 and remove_count == 0) @@ -5969,7 +5905,7 @@ do local e = evo.id() - assert(evo.insert(e, f1, 51)) + assert(evo.set(e, f1, 51)) assert(evo.get(e, f1) == 51) assert(evo.get(e, f2) == 51) assert(assign_count == 0 and insert_count == 2 and remove_count == 0) @@ -5985,7 +5921,7 @@ do local e = evo.id() - assert(evo.insert(e, f1, 51)) + assert(evo.set(e, f1, 51)) assert(evo.get(e, f1) == 51) assert(evo.get(e, f2) == 51) assert(assign_count == 0 and insert_count == 2 and remove_count == 0) @@ -6152,7 +6088,7 @@ do insert_count = 0 remove_count = 0 - assert(evo.insert(e1, f0) and evo.insert(e2, f0)) + assert(evo.set(e1, f0) and evo.set(e2, f0)) assert(evo.batch_insert(q0, f1, 41)) assert(assign_count == 0 and insert_count == 2 and remove_count == 0) @@ -6169,7 +6105,7 @@ do assert(evo.batch_clear(q0)) assert(assign_count == 2 and insert_count == 4 and remove_count == 4) - assert(evo.insert(e1, f0) and evo.insert(e2, f0)) + assert(evo.set(e1, f0) and evo.set(e2, f0)) assert(evo.batch_insert(q0, f1, 51)) assert(assign_count == 2 and insert_count == 6 and remove_count == 4) @@ -6259,7 +6195,7 @@ do insert_count = 0 remove_count = 0 - assert(evo.insert(e1, f0) and evo.insert(e2, f0)) + assert(evo.set(e1, f0) and evo.set(e2, f0)) assert(evo.batch_multi_insert(q0, { f1, f2 }, { 41, 42 })) assert(assign_count == 0 and insert_count == 4 and remove_count == 0) @@ -6291,19 +6227,19 @@ do end) local e1 = evo.id() - assert(evo.insert(e1, f1, 41)) + assert(evo.set(e1, f1, 41)) local e12 = evo.id() - assert(evo.insert(e12, f1, 41)) - assert(evo.insert(e12, f2, 42)) + assert(evo.set(e12, f1, 41)) + assert(evo.set(e12, f2, 42)) local e35 = evo.id() - assert(evo.insert(e35, f3, 43)) - assert(evo.insert(e35, f5, 45)) + assert(evo.set(e35, f3, 43)) + assert(evo.set(e35, f5, 45)) local e34 = evo.id() - assert(evo.insert(e34, f3, 43)) - assert(evo.insert(e34, f4, 44)) + assert(evo.set(e34, f3, 43)) + assert(evo.set(e34, f4, 44)) evo.set(f1, evo.ON_ASSIGN, function() assign_count = assign_count + 1 @@ -6315,16 +6251,16 @@ do assert(assign_count == 0) - assert(evo.assign(e1, f1, 41)) + assert(evo.set(e1, f1, 41)) assert(assign_count == 1) - assert(evo.assign(e12, f1, 42)) + assert(evo.set(e12, f1, 42)) assert(assign_count == 2) - assert(evo.assign(e34, f3, 43)) + assert(evo.set(e34, f3, 43)) assert(assign_count == 3) - assert(evo.assign(e35, f3, 43)) + assert(evo.set(e35, f3, 43)) assert(assign_count == 4) end @@ -6344,7 +6280,7 @@ do assert(evo.set(e123, f1, 41) and evo.set(e123, f2, 42) and evo.set(e123, f3, 43)) assert(set_count == 5) - assert(evo.assign(e123, f1, 41) and evo.assign(e123, f2, 42) and evo.assign(e123, f3, 43)) + assert(evo.set(e123, f1, 41) and evo.set(e123, f2, 42) and evo.set(e123, f3, 43)) assert(set_count == 8) do @@ -6388,14 +6324,14 @@ do local f1, f2 = evo.id(2) local e1 = evo.id() - assert(evo.insert(e1, f1, 41)) - assert(evo.insert(e1, f2, 42)) + assert(evo.set(e1, f1, 41)) + assert(evo.set(e1, f2, 42)) evo.set(f1, evo.DEFAULT, 51) evo.set(f2, evo.CONSTRUCT, function() return 52 end) - assert(evo.assign(e1, f1)) - assert(evo.assign(e1, f2)) + assert(evo.set(e1, f1)) + assert(evo.set(e1, f2)) assert(evo.get(e1, f1) == 51) assert(evo.get(e1, f2) == 52) @@ -6405,17 +6341,17 @@ do local f1, f2 = evo.id(2) local e1 = evo.id() - assert(evo.insert(e1, f1, 41)) + assert(evo.set(e1, f1, 41)) local e2 = evo.id() - assert(evo.insert(e2, f1, 41)) - assert(evo.insert(e2, f2, 42)) + assert(evo.set(e2, f1, 41)) + assert(evo.set(e2, f2, 42)) assert(evo.get(e1, f1) == 41) assert(evo.get(e2, f1) == 41) assert(evo.get(e2, f2) == 42) - assert(evo.insert(f1, evo.TAG)) + assert(evo.set(f1, evo.TAG)) assert(evo.get(e1, f1) == nil) assert(evo.get(e2, f1) == nil) assert(evo.get(e2, f2) == 42) @@ -6425,12 +6361,12 @@ do assert(evo.get(e2, f1) == true) assert(evo.get(e2, f2) == 42) - assert(evo.insert(f2, evo.TAG)) + assert(evo.set(f2, evo.TAG)) assert(evo.get(e1, f1) == true) assert(evo.get(e2, f1) == true) assert(evo.get(e2, f2) == nil) - assert(evo.insert(f2, evo.DEFAULT, 42)) + assert(evo.set(f2, evo.DEFAULT, 42)) assert(evo.remove(f2, evo.TAG)) assert(evo.get(e1, f1) == true) assert(evo.get(e2, f1) == true) @@ -6701,7 +6637,7 @@ do end assert(evo.remove(e12a, f1) and evo.remove(e12b, f1)) - assert(evo.insert(e1a, f2, 7) and evo.insert(e1b, f2, 8)) + assert(evo.set(e1a, f2, 7) and evo.set(e1b, f2, 8)) do local c1_es, c1_ec = evo.entities(c1) @@ -7246,7 +7182,7 @@ do assert(matched_entity_count > 0) end - assert(evo.assign(qe12, evo.EXCLUDES)) + assert(evo.set(qe12, evo.EXCLUDES)) do local matched_chunk_count = 0 @@ -7263,7 +7199,7 @@ do assert(matched_entity_count > 0) end - assert(evo.insert(qe12, evo.INCLUDES, f1, f2)) + assert(evo.set(qe12, evo.INCLUDES, f1, f2)) do local iter, state = evo.execute(qe12) @@ -7278,8 +7214,8 @@ end do local f1, f2 = evo.id(2) - assert(evo.insert(f1, evo.NAME, 'f1')) - assert(evo.insert(f2, evo.NAME, 'f2')) + assert(evo.set(f1, evo.NAME, 'f1')) + assert(evo.set(f2, evo.NAME, 'f2')) local old_c1 = assert(evo.chunk(f1)) local old_c12 = assert(evo.chunk(f1, f2)) @@ -7352,8 +7288,8 @@ do local f1 = evo.id() local e1, e2 = evo.id(2) - assert(evo.insert(e1, f1, f1)) - assert(evo.insert(e2, f1, f1)) + assert(evo.set(e1, f1, f1)) + assert(evo.set(e2, f1, f1)) assert(evo.clear(e1, e2)) @@ -7365,11 +7301,11 @@ do local f1 = evo.id() local e1, e2, e3, e4, e5 = evo.id(5) - assert(evo.insert(e1, f1, f1)) - assert(evo.insert(e2, f1, f1)) - assert(evo.insert(e3, f1, f1)) - assert(evo.insert(e4, f1, f1)) - assert(evo.insert(e5, f1, f1)) + assert(evo.set(e1, f1, f1)) + assert(evo.set(e2, f1, f1)) + assert(evo.set(e3, f1, f1)) + assert(evo.set(e4, f1, f1)) + assert(evo.set(e5, f1, f1)) assert(evo.clear(e1, e2, e3, e4, e5)) @@ -7386,9 +7322,9 @@ do local f1 = evo.id() local e1, e2, e3 = evo.id(3) - assert(evo.insert(e1, f1, f1)) - assert(evo.insert(e2, f1, f1)) - assert(evo.insert(e3, f1, f1)) + assert(evo.set(e1, f1, f1)) + assert(evo.set(e2, f1, f1)) + assert(evo.set(e3, f1, f1)) assert(evo.defer()) do @@ -7408,11 +7344,11 @@ do local f1 = evo.id() local e1, e2, e3, e4, e5 = evo.id(5) - assert(evo.insert(e1, f1, f1)) - assert(evo.insert(e2, f1, f1)) - assert(evo.insert(e3, f1, f1)) - assert(evo.insert(e4, f1, f1)) - assert(evo.insert(e5, f1, f1)) + assert(evo.set(e1, f1, f1)) + assert(evo.set(e2, f1, f1)) + assert(evo.set(e3, f1, f1)) + assert(evo.set(e4, f1, f1)) + assert(evo.set(e5, f1, f1)) assert(evo.defer()) do @@ -7438,8 +7374,8 @@ do local f1 = evo.id() local e1, e2 = evo.id(2) - assert(evo.insert(e1, f1, f1)) - assert(evo.insert(e2, f1, f1)) + assert(evo.set(e1, f1, f1)) + assert(evo.set(e2, f1, f1)) assert(evo.destroy(e1, e2)) @@ -7451,11 +7387,11 @@ do local f1 = evo.id() local e1, e2, e3, e4, e5 = evo.id(5) - assert(evo.insert(e1, f1, f1)) - assert(evo.insert(e2, f1, f1)) - assert(evo.insert(e3, f1, f1)) - assert(evo.insert(e4, f1, f1)) - assert(evo.insert(e5, f1, f1)) + assert(evo.set(e1, f1, f1)) + assert(evo.set(e2, f1, f1)) + assert(evo.set(e3, f1, f1)) + assert(evo.set(e4, f1, f1)) + assert(evo.set(e5, f1, f1)) assert(evo.destroy(e1, e2, e3, e4, e5)) @@ -7472,9 +7408,9 @@ do local f1 = evo.id() local e1, e2, e3 = evo.id(3) - assert(evo.insert(e1, f1, f1)) - assert(evo.insert(e2, f1, f1)) - assert(evo.insert(e3, f1, f1)) + assert(evo.set(e1, f1, f1)) + assert(evo.set(e2, f1, f1)) + assert(evo.set(e3, f1, f1)) assert(evo.defer()) do @@ -7494,11 +7430,11 @@ do local f1 = evo.id() local e1, e2, e3, e4, e5 = evo.id(5) - assert(evo.insert(e1, f1, f1)) - assert(evo.insert(e2, f1, f1)) - assert(evo.insert(e3, f1, f1)) - assert(evo.insert(e4, f1, f1)) - assert(evo.insert(e5, f1, f1)) + assert(evo.set(e1, f1, f1)) + assert(evo.set(e2, f1, f1)) + assert(evo.set(e3, f1, f1)) + assert(evo.set(e4, f1, f1)) + assert(evo.set(e5, f1, f1)) assert(evo.defer()) do @@ -7522,8 +7458,8 @@ end do local f1 = evo.id() local e1, e2 = evo.id(2) - assert(evo.insert(e1, f1, f1)) - assert(evo.insert(e2, f1, f1)) + assert(evo.set(e1, f1, f1)) + assert(evo.set(e2, f1, f1)) assert(evo.clear(e1, e2, e1, e1)) assert(evo.is_alive(e1) and evo.is_empty(e1)) assert(evo.is_alive(e2) and evo.is_empty(e2)) @@ -7532,8 +7468,8 @@ end do local f1 = evo.id() local e1, e2 = evo.id(2) - assert(evo.insert(e1, f1, f1)) - assert(evo.insert(e2, f1, f1)) + assert(evo.set(e1, f1, f1)) + assert(evo.set(e2, f1, f1)) assert(evo.destroy(e1, e2, e1, e1)) assert(not evo.is_alive(e1) and evo.is_empty(e1)) assert(not evo.is_alive(e2) and evo.is_empty(e2)) @@ -7543,12 +7479,12 @@ do local f1, f2 = evo.id(2) local q1, q2 = evo.id(2) - assert(evo.insert(q1, evo.INCLUDES, f1)) - assert(evo.insert(q2, evo.INCLUDES, f2)) + assert(evo.set(q1, evo.INCLUDES, f1)) + assert(evo.set(q2, evo.INCLUDES, f2)) local e1, e2 = evo.id(2) - assert(evo.insert(e1, f1, f1)) - assert(evo.insert(e2, f2, f2)) + assert(evo.set(e1, f1, f1)) + assert(evo.set(e2, f2, f2)) assert(evo.batch_clear() == 0) @@ -7565,12 +7501,12 @@ do local f1, f2 = evo.id(2) local q1, q2 = evo.id(2) - assert(evo.insert(q1, evo.INCLUDES, f1)) - assert(evo.insert(q2, evo.INCLUDES, f2)) + assert(evo.set(q1, evo.INCLUDES, f1)) + assert(evo.set(q2, evo.INCLUDES, f2)) local e1, e2 = evo.id(2) - assert(evo.insert(e1, f1, f1)) - assert(evo.insert(e2, f2, f2)) + assert(evo.set(e1, f1, f1)) + assert(evo.set(e2, f2, f2)) assert(evo.defer()) do @@ -7588,12 +7524,12 @@ do local f1, f2 = evo.id(2) local q1, q2 = evo.id(2) - assert(evo.insert(q1, evo.INCLUDES, f1)) - assert(evo.insert(q2, evo.INCLUDES, f2)) + assert(evo.set(q1, evo.INCLUDES, f1)) + assert(evo.set(q2, evo.INCLUDES, f2)) local e1, e2 = evo.id(2) - assert(evo.insert(e1, f1, f1)) - assert(evo.insert(e2, f2, f2)) + assert(evo.set(e1, f1, f1)) + assert(evo.set(e2, f2, f2)) assert(evo.batch_destroy() == 0) @@ -7610,12 +7546,12 @@ do local f1, f2 = evo.id(2) local q1, q2 = evo.id(2) - assert(evo.insert(q1, evo.INCLUDES, f1)) - assert(evo.insert(q2, evo.INCLUDES, f2)) + assert(evo.set(q1, evo.INCLUDES, f1)) + assert(evo.set(q2, evo.INCLUDES, f2)) local e1, e2 = evo.id(2) - assert(evo.insert(e1, f1, f1)) - assert(evo.insert(e2, f2, f2)) + assert(evo.set(e1, f1, f1)) + assert(evo.set(e2, f2, f2)) assert(evo.defer()) do @@ -7711,7 +7647,7 @@ do assert(evo.is_empty_any(d1, e1, e2, d2, e3, d1)) local f1, f2 = evo.id(2) - assert(evo.insert(f1, f1) and evo.insert(f2, f2)) + assert(evo.set(f1, f1) and evo.set(f2, f2)) assert(not evo.is_empty(f1)) assert(not evo.is_empty_all(f1)) @@ -8055,7 +7991,7 @@ do assert(evo.is_empty_all(e1a, e1b, e12a, e12b)) end - assert(evo.insert(e1a, f1, 1) and evo.insert(e1b, f1, 2)) + assert(evo.set(e1a, f1, 1) and evo.set(e1b, f1, 2)) assert(evo.multi_insert(e12a, { f1, f2 }, { 3, 4 }) and evo.multi_insert(e12b, { f1, f2 }, { 5, 6 })) do From 04dcedc6185e27272ea9e14cd309baafad0e47b7 Mon Sep 17 00:00:00 2001 From: BlackMATov Date: Thu, 20 Mar 2025 04:21:46 +0700 Subject: [PATCH 03/12] remove evolved.multi_assign/insert, evolved.batch_multi_assing/insert --- README.md | 4 - evolved.lua | 816 ---------------------------------------------------- 2 files changed, 820 deletions(-) diff --git a/README.md b/README.md index 4e9d2f3..03e188e 100644 --- a/README.md +++ b/README.md @@ -83,8 +83,6 @@ clear :: entity... -> boolean, boolean destroy :: entity... -> boolean, boolean multi_set :: entity, fragment[], component[]? -> boolean, boolean -multi_assign :: entity, fragment[], component[]? -> boolean, boolean -multi_insert :: entity, fragment[], component[]? -> boolean, boolean multi_remove :: entity, fragment[] -> boolean, boolean batch_set :: chunk | query, fragment, any... -> integer, boolean @@ -95,8 +93,6 @@ batch_clear :: chunk | query... -> integer, boolean batch_destroy :: chunk | query... -> integer, boolean batch_multi_set :: chunk | query, fragment[], component[]? -> integer, boolean -batch_multi_assign :: chunk | query, fragment[], component[]? -> integer, boolean -batch_multi_insert :: chunk | query, fragment[], component[]? -> integer, boolean batch_multi_remove :: chunk | query, fragment[] -> integer, boolean chunk :: fragment, fragment... -> chunk, entity[], integer diff --git a/evolved.lua b/evolved.lua index 10eaed0..4b31559 100644 --- a/evolved.lua +++ b/evolved.lua @@ -661,8 +661,6 @@ local __evolved_clear local __evolved_destroy local __evolved_multi_set -local __evolved_multi_assign -local __evolved_multi_insert local __evolved_multi_remove local __evolved_batch_set @@ -673,8 +671,6 @@ local __evolved_batch_clear local __evolved_batch_destroy local __evolved_batch_multi_set -local __evolved_batch_multi_assign -local __evolved_batch_multi_insert local __evolved_batch_multi_remove local __evolved_chunk @@ -1511,8 +1507,6 @@ local __defer_clear local __defer_destroy local __defer_multi_set -local __defer_multi_assign -local __defer_multi_insert local __defer_multi_remove local __defer_batch_set @@ -1523,8 +1517,6 @@ local __defer_batch_clear local __defer_batch_destroy local __defer_batch_multi_set -local __defer_batch_multi_assign -local __defer_batch_multi_insert local __defer_batch_multi_remove local __defer_spawn_entity_at @@ -1848,8 +1840,6 @@ local __chunk_clear local __chunk_destroy local __chunk_multi_set -local __chunk_multi_assign -local __chunk_multi_insert local __chunk_multi_remove --- @@ -2903,291 +2893,6 @@ __chunk_multi_set = function(old_chunk, fragments, fragment_count, components) return old_entity_count end ----@param chunk evolved.chunk ----@param fragments evolved.fragment[] ----@param fragment_count integer ----@param components evolved.component[] ----@return integer assigned_count -__chunk_multi_assign = function(chunk, fragments, fragment_count, components) - if __defer_depth <= 0 then - __error_fmt('batched chunk operations should be deferred') - end - - if fragment_count == 0 then - return 0 - end - - if not __chunk_has_any_fragment_list(chunk, fragments, fragment_count) then - return 0 - end - - local chunk_entity_list = chunk.__entity_list - local chunk_entity_count = chunk.__entity_count - - if chunk_entity_count == 0 then - return 0 - end - - local chunk_fragment_set = chunk.__fragment_set - local chunk_component_indices = chunk.__component_indices - local chunk_component_storages = chunk.__component_storages - - local chunk_has_defaults_or_constructs = chunk.__has_defaults_or_constructs - local chunk_has_set_or_assign_hooks = chunk.__has_set_or_assign_hooks - - for i = 1, fragment_count do - local fragment = fragments[i] - - if chunk_fragment_set[fragment] then - ---@type evolved.default? - local fragment_default - - ---@type evolved.set_hook?, evolved.assign_hook? - local fragment_on_set, fragment_on_assign - - do - if chunk_has_defaults_or_constructs then - fragment_default = __evolved_get(fragment, __DEFAULT) - end - - if chunk_has_set_or_assign_hooks then - fragment_on_set, fragment_on_assign = __evolved_get(fragment, __ON_SET, __ON_ASSIGN) - end - end - - if fragment_on_set or fragment_on_assign then - local component_index = chunk_component_indices[fragment] - - if component_index then - local component_storage = chunk_component_storages[component_index] - - local new_component = components[i] - if new_component == nil then new_component = fragment_default end - if new_component == nil then new_component = true end - - for place = 1, chunk_entity_count do - local entity = chunk_entity_list[place] - local old_component = component_storage[place] - - component_storage[place] = new_component - - if fragment_on_set then - __defer_call_hook(fragment_on_set, entity, fragment, new_component, old_component) - end - - if fragment_on_assign then - __defer_call_hook(fragment_on_assign, entity, fragment, new_component, old_component) - end - end - else - for place = 1, chunk_entity_count do - local entity = chunk_entity_list[place] - - if fragment_on_set then - __defer_call_hook(fragment_on_set, entity, fragment) - end - - if fragment_on_assign then - __defer_call_hook(fragment_on_assign, entity, fragment) - end - end - end - else - local component_index = chunk_component_indices[fragment] - - if component_index then - local component_storage = chunk_component_storages[component_index] - - local new_component = components[i] - if new_component == nil then new_component = fragment_default end - if new_component == nil then new_component = true end - - for place = 1, chunk_entity_count do - component_storage[place] = new_component - end - else - -- nothing - end - end - end - end - - return chunk_entity_count -end - ----@param old_chunk evolved.chunk ----@param fragments evolved.fragment[] ----@param fragment_count integer ----@param components evolved.component[] ----@return integer inserted_count -__chunk_multi_insert = function(old_chunk, fragments, fragment_count, components) - if __defer_depth <= 0 then - __error_fmt('batched chunk operations should be deferred') - end - - if fragment_count == 0 then - return 0 - end - - local new_chunk = __chunk_with_fragment_list(old_chunk, fragments, fragment_count) - - if not new_chunk or old_chunk == new_chunk then - return 0 - end - - local old_entity_list = old_chunk.__entity_list - local old_entity_count = old_chunk.__entity_count - - if old_entity_count == 0 then - return 0 - end - - local old_fragment_set = old_chunk.__fragment_set - local old_component_count = old_chunk.__component_count - local old_component_storages = old_chunk.__component_storages - local old_component_fragments = old_chunk.__component_fragments - - local new_entity_list = new_chunk.__entity_list - local new_entity_count = new_chunk.__entity_count - - local new_component_indices = new_chunk.__component_indices - local new_component_storages = new_chunk.__component_storages - - local new_chunk_has_defaults_or_constructs = new_chunk.__has_defaults_or_constructs - local new_chunk_has_set_or_insert_hooks = new_chunk.__has_set_or_insert_hooks - - if new_entity_count == 0 then - old_chunk.__entity_list, new_chunk.__entity_list = - new_entity_list, old_entity_list - - 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] - local new_ci = new_component_indices[old_f] - old_component_storages[old_ci], new_component_storages[new_ci] = - new_component_storages[new_ci], old_component_storages[old_ci] - end - - new_chunk.__entity_count = old_entity_count - else - __lua_table_move( - 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] - local old_cs = old_component_storages[old_ci] - local new_ci = new_component_indices[old_f] - local new_cs = new_component_storages[new_ci] - __lua_table_move(old_cs, 1, old_entity_count, new_entity_count + 1, new_cs) - end - - new_chunk.__entity_count = new_entity_count + old_entity_count - end - - do - local entity_chunks = __entity_chunks - local entity_places = __entity_places - - for new_place = new_entity_count + 1, new_entity_count + old_entity_count do - local entity = new_entity_list[new_place] - local entity_index = entity % 0x100000 - entity_chunks[entity_index] = new_chunk - entity_places[entity_index] = new_place - end - - __detach_all_entities(old_chunk) - end - - ---@type table - local inserted_set = __acquire_table(__table_pool_tag.fragment_set) - - for i = 1, fragment_count do - local fragment = fragments[i] - - if not inserted_set[fragment] and not old_fragment_set[fragment] then - inserted_set[fragment] = true - - ---@type evolved.default? - local fragment_default - - ---@type evolved.set_hook?, evolved.insert_hook? - local fragment_on_set, fragment_on_insert - - do - if new_chunk_has_defaults_or_constructs then - fragment_default = __evolved_get(fragment, __DEFAULT) - end - - if new_chunk_has_set_or_insert_hooks then - fragment_on_set, fragment_on_insert = __evolved_get(fragment, __ON_SET, __ON_INSERT) - end - end - - if fragment_on_set or fragment_on_insert then - local new_component_index = new_component_indices[fragment] - - if new_component_index then - local new_component_storage = new_component_storages[new_component_index] - - local new_component = components[i] - if new_component == nil then new_component = fragment_default end - 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_entity_list[new_place] - - new_component_storage[new_place] = new_component - - if fragment_on_set then - __defer_call_hook(fragment_on_set, entity, fragment, new_component) - end - - if fragment_on_insert then - __defer_call_hook(fragment_on_insert, entity, fragment, new_component) - end - end - else - for new_place = new_entity_count + 1, new_entity_count + old_entity_count do - local entity = new_entity_list[new_place] - - if fragment_on_set then - __defer_call_hook(fragment_on_set, entity, fragment) - end - - if fragment_on_insert then - __defer_call_hook(fragment_on_insert, entity, fragment) - end - end - end - else - local new_component_index = new_component_indices[fragment] - - if new_component_index then - local new_component_storage = new_component_storages[new_component_index] - - local new_component = components[i] - if new_component == nil then new_component = fragment_default end - if new_component == nil then new_component = true end - - for new_place = new_entity_count + 1, new_entity_count + old_entity_count do - new_component_storage[new_place] = new_component - end - else - -- nothing - end - end - end - end - - __release_table(__table_pool_tag.fragment_set, inserted_set) - - __structural_changes = __structural_changes + 1 - return old_entity_count -end - ---@param old_chunk evolved.chunk ---@param fragments evolved.fragment[] ---@param fragment_count integer @@ -3497,8 +3202,6 @@ local __defer_op = { destroy = 6, multi_set = 7, - multi_assign = 8, - multi_insert = 9, multi_remove = 10, batch_set = 11, @@ -3509,8 +3212,6 @@ local __defer_op = { batch_destroy = 16, batch_multi_set = 17, - batch_multi_assign = 18, - batch_multi_insert = 19, batch_multi_remove = 20, spawn_entity_at = 21, @@ -3851,76 +3552,6 @@ __defer_ops[__defer_op.multi_set] = function(bytes, index) return 3 end ----@param entity evolved.entity ----@param fragments evolved.fragment[] ----@param fragment_count integer ----@param components evolved.component[] ----@param component_count integer -__defer_multi_assign = function(entity, fragments, fragment_count, components, component_count) - ---@type evolved.fragment[] - local fragment_list = __acquire_table(__table_pool_tag.fragment_list) - __lua_table_move(fragments, 1, fragment_count, 1, fragment_list) - - ---@type evolved.component[] - local component_list = __acquire_table(__table_pool_tag.component_list) - __lua_table_move(components, 1, component_count, 1, component_list) - - local length = __defer_length - local bytecode = __defer_bytecode - - bytecode[length + 1] = __defer_op.multi_assign - bytecode[length + 2] = entity - bytecode[length + 3] = fragment_list - bytecode[length + 4] = component_list - - __defer_length = length + 4 -end - -__defer_ops[__defer_op.multi_assign] = function(bytes, index) - local entity = bytes[index + 0] - local fragments = bytes[index + 1] - local components = bytes[index + 2] - __evolved_multi_assign(entity, fragments, components) - __release_table(__table_pool_tag.fragment_list, fragments) - __release_table(__table_pool_tag.component_list, components) - return 3 -end - ----@param entity evolved.entity ----@param fragments evolved.fragment[] ----@param fragment_count integer ----@param components evolved.component[] ----@param component_count integer -__defer_multi_insert = function(entity, fragments, fragment_count, components, component_count) - ---@type evolved.fragment[] - local fragment_list = __acquire_table(__table_pool_tag.fragment_list) - __lua_table_move(fragments, 1, fragment_count, 1, fragment_list) - - ---@type evolved.component[] - local component_list = __acquire_table(__table_pool_tag.component_list) - __lua_table_move(components, 1, component_count, 1, component_list) - - local length = __defer_length - local bytecode = __defer_bytecode - - bytecode[length + 1] = __defer_op.multi_insert - bytecode[length + 2] = entity - bytecode[length + 3] = fragment_list - bytecode[length + 4] = component_list - - __defer_length = length + 4 -end - -__defer_ops[__defer_op.multi_insert] = function(bytes, index) - local entity = bytes[index + 0] - local fragments = bytes[index + 1] - local components = bytes[index + 2] - __evolved_multi_insert(entity, fragments, components) - __release_table(__table_pool_tag.fragment_list, fragments) - __release_table(__table_pool_tag.component_list, components) - return 3 -end - ---@param entity evolved.entity ---@param fragments evolved.fragment[] ---@param fragment_count integer @@ -4425,76 +4056,6 @@ __defer_ops[__defer_op.batch_multi_set] = function(bytes, index) return 3 end ----@param chunk_or_query evolved.chunk | evolved.query ----@param fragments evolved.fragment[] ----@param fragment_count integer ----@param components evolved.component[] ----@param component_count integer -__defer_batch_multi_assign = function(chunk_or_query, fragments, fragment_count, components, component_count) - ---@type evolved.fragment[] - local fragment_list = __acquire_table(__table_pool_tag.fragment_list) - __lua_table_move(fragments, 1, fragment_count, 1, fragment_list) - - ---@type evolved.component[] - local component_list = __acquire_table(__table_pool_tag.component_list) - __lua_table_move(components, 1, component_count, 1, component_list) - - local length = __defer_length - local bytecode = __defer_bytecode - - bytecode[length + 1] = __defer_op.batch_multi_assign - bytecode[length + 2] = chunk_or_query - bytecode[length + 3] = fragment_list - bytecode[length + 4] = component_list - - __defer_length = length + 4 -end - -__defer_ops[__defer_op.batch_multi_assign] = function(bytes, index) - local chunk_or_query = bytes[index + 0] - local fragments = bytes[index + 1] - local components = bytes[index + 2] - __evolved_batch_multi_assign(chunk_or_query, fragments, components) - __release_table(__table_pool_tag.fragment_list, fragments) - __release_table(__table_pool_tag.component_list, components) - return 3 -end - ----@param chunk_or_query evolved.chunk | evolved.query ----@param fragments evolved.fragment[] ----@param fragment_count integer ----@param components evolved.component[] ----@param component_count integer -__defer_batch_multi_insert = function(chunk_or_query, fragments, fragment_count, components, component_count) - ---@type evolved.fragment[] - local fragment_list = __acquire_table(__table_pool_tag.fragment_list) - __lua_table_move(fragments, 1, fragment_count, 1, fragment_list) - - ---@type evolved.component[] - local component_list = __acquire_table(__table_pool_tag.component_list) - __lua_table_move(components, 1, component_count, 1, component_list) - - local length = __defer_length - local bytecode = __defer_bytecode - - bytecode[length + 1] = __defer_op.batch_multi_insert - bytecode[length + 2] = chunk_or_query - bytecode[length + 3] = fragment_list - bytecode[length + 4] = component_list - - __defer_length = length + 4 -end - -__defer_ops[__defer_op.batch_multi_insert] = function(bytes, index) - local chunk_or_query = bytes[index + 0] - local fragments = bytes[index + 1] - local components = bytes[index + 2] - __evolved_batch_multi_insert(chunk_or_query, fragments, components) - __release_table(__table_pool_tag.fragment_list, fragments) - __release_table(__table_pool_tag.component_list, components) - return 3 -end - ---@param chunk_or_query evolved.chunk | evolved.query ---@param fragments evolved.fragment[] ---@param fragment_count integer @@ -5798,259 +5359,6 @@ __evolved_multi_set = function(entity, fragments, components) return true, false end ----@param entity evolved.entity ----@param fragments evolved.fragment[] ----@param components? evolved.component[] ----@return boolean is_any_assigned ----@return boolean is_deferred -__evolved_multi_assign = function(entity, fragments, components) - local fragment_count = #fragments - - if fragment_count == 0 then - return false, false - end - - if not components then - components = __safe_tbls.__EMPTY_COMPONENT_LIST - end - - if __defer_depth > 0 then - __defer_multi_assign(entity, fragments, fragment_count, components, #components) - return false, true - end - - if __debug_mode then - __debug_fns.validate_fragment_list(fragments, fragment_count) - end - - local entity_index = entity % 0x100000 - - if __freelist_ids[entity_index] ~= entity then - return false, false - end - - local entity_chunks = __entity_chunks - local entity_places = __entity_places - - local chunk = entity_chunks[entity_index] - local place = entity_places[entity_index] - - if not chunk or not __chunk_has_any_fragment_list(chunk, fragments, fragment_count) then - return false, false - end - - __evolved_defer() - - do - local chunk_fragment_set = chunk.__fragment_set - local chunk_component_indices = chunk.__component_indices - local chunk_component_storages = chunk.__component_storages - - local chunk_has_defaults_or_constructs = chunk.__has_defaults_or_constructs - local chunk_has_set_or_assign_hooks = chunk.__has_set_or_assign_hooks - - for i = 1, fragment_count do - local fragment = fragments[i] - - if chunk_fragment_set[fragment] then - ---@type evolved.set_hook?, evolved.assign_hook? - local fragment_on_set, fragment_on_assign - - if chunk_has_set_or_assign_hooks then - fragment_on_set, fragment_on_assign = __evolved_get(fragment, __ON_SET, __ON_ASSIGN) - end - - local component_index = chunk_component_indices[fragment] - - if component_index then - local component_storage = chunk_component_storages[component_index] - - local new_component = components[i] - - if chunk_has_defaults_or_constructs and new_component == nil then - new_component = __evolved_get(fragment, __DEFAULT) - end - - if new_component == nil then - new_component = true - end - - if fragment_on_set or fragment_on_assign then - local old_component = component_storage[place] - - component_storage[place] = new_component - - if fragment_on_set then - __defer_call_hook(fragment_on_set, entity, fragment, new_component, old_component) - end - - if fragment_on_assign then - __defer_call_hook(fragment_on_assign, entity, fragment, new_component, old_component) - end - else - component_storage[place] = new_component - end - else - if fragment_on_set then - __defer_call_hook(fragment_on_set, entity, fragment) - end - - if fragment_on_assign then - __defer_call_hook(fragment_on_assign, entity, fragment) - end - end - end - end - end - - __evolved_commit() - return true, false -end - ----@param entity evolved.entity ----@param fragments evolved.fragment[] ----@param components? evolved.component[] ----@return boolean is_any_inserted ----@return boolean is_deferred -__evolved_multi_insert = function(entity, fragments, components) - local fragment_count = #fragments - - if fragment_count == 0 then - return false, false - end - - if not components then - components = __safe_tbls.__EMPTY_COMPONENT_LIST - end - - if __defer_depth > 0 then - __defer_multi_insert(entity, fragments, fragment_count, components, #components) - return false, true - end - - if __debug_mode then - __debug_fns.validate_fragment_list(fragments, fragment_count) - end - - local entity_index = entity % 0x100000 - - if __freelist_ids[entity_index] ~= entity then - return false, false - end - - local entity_chunks = __entity_chunks - local entity_places = __entity_places - - local old_chunk = entity_chunks[entity_index] - local old_place = entity_places[entity_index] - - 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 - end - - __evolved_defer() - - do - local new_entity_list = new_chunk.__entity_list - local new_entity_count = new_chunk.__entity_count - - local new_component_indices = new_chunk.__component_indices - local new_component_storages = new_chunk.__component_storages - - local new_chunk_has_defaults_or_constructs = new_chunk.__has_defaults_or_constructs - local new_chunk_has_set_or_insert_hooks = new_chunk.__has_set_or_insert_hooks - - local old_fragment_set = old_chunk and old_chunk.__fragment_set or __safe_tbls.__EMPTY_FRAGMENT_SET - - local new_place = new_entity_count + 1 - new_chunk.__entity_count = new_place - - new_entity_list[new_place] = entity - - if old_chunk then - local old_component_count = old_chunk.__component_count - local old_component_storages = old_chunk.__component_storages - local old_component_fragments = old_chunk.__component_fragments - - for old_ci = 1, old_component_count do - local old_f = old_component_fragments[old_ci] - local old_cs = old_component_storages[old_ci] - local new_ci = new_component_indices[old_f] - local new_cs = new_component_storages[new_ci] - new_cs[new_place] = old_cs[old_place] - end - - __detach_entity(old_chunk, old_place) - end - - do - entity_chunks[entity_index] = new_chunk - entity_places[entity_index] = new_place - - __structural_changes = __structural_changes + 1 - end - - ---@type table - local inserted_set = __acquire_table(__table_pool_tag.fragment_set) - - for i = 1, fragment_count do - local fragment = fragments[i] - - if not inserted_set[fragment] and not old_fragment_set[fragment] then - inserted_set[fragment] = true - - ---@type evolved.set_hook?, evolved.insert_hook? - local fragment_on_set, fragment_on_insert - - if new_chunk_has_set_or_insert_hooks then - fragment_on_set, fragment_on_insert = __evolved_get(fragment, __ON_SET, __ON_INSERT) - end - - local new_component_index = new_component_indices[fragment] - - if new_component_index then - local new_component_storage = new_component_storages[new_component_index] - - local new_component = components[i] - - if new_chunk_has_defaults_or_constructs and new_component == nil then - new_component = __evolved_get(fragment, __DEFAULT) - end - - if new_component == nil then - new_component = true - end - - new_component_storage[new_place] = new_component - - if fragment_on_set then - __defer_call_hook(fragment_on_set, entity, fragment, new_component) - end - - if fragment_on_insert then - __defer_call_hook(fragment_on_insert, entity, fragment, new_component) - end - else - if fragment_on_set then - __defer_call_hook(fragment_on_set, entity, fragment) - end - - if fragment_on_insert then - __defer_call_hook(fragment_on_insert, entity, fragment) - end - end - end - end - - __release_table(__table_pool_tag.fragment_set, inserted_set) - end - - __evolved_commit() - return true, false -end - ---@param entity evolved.entity ---@param fragments evolved.fragment[] ---@return boolean is_all_removed @@ -6539,126 +5847,6 @@ __evolved_batch_multi_set = function(chunk_or_query, fragments, components) return set_count, false end ----@param chunk_or_query evolved.chunk | evolved.query ----@param fragments evolved.fragment[] ----@param components? evolved.component[] ----@return integer assigned_count ----@return boolean is_deferred -__evolved_batch_multi_assign = function(chunk_or_query, fragments, components) - local fragment_count = #fragments - - if fragment_count == 0 then - return 0, false - end - - if not components then - components = __safe_tbls.__EMPTY_COMPONENT_LIST - end - - if __defer_depth > 0 then - __defer_batch_multi_assign(chunk_or_query, fragments, fragment_count, components, #components) - return 0, true - end - - if __debug_mode then - __debug_fns.validate_fragment_list(fragments, fragment_count) - end - - local assigned_count = 0 - - __evolved_defer() - do - if __lua_type(chunk_or_query) ~= 'number' then - ---@cast chunk_or_query -evolved.query - local chunk = chunk_or_query --[[@as evolved.chunk]] - - assigned_count = assigned_count + __chunk_multi_assign(chunk, fragments, fragment_count, components) - else - ---@cast chunk_or_query -evolved.chunk - local query = chunk_or_query --[[@as evolved.query]] - - ---@type evolved.chunk[] - local chunk_list = __acquire_table(__table_pool_tag.chunk_stack) - local chunk_count = 0 - - for chunk in __evolved_execute(query) do - chunk_count = chunk_count + 1 - chunk_list[chunk_count] = chunk - end - - for chunk_index = 1, chunk_count do - local chunk = chunk_list[chunk_index] - assigned_count = assigned_count + __chunk_multi_assign(chunk, fragments, fragment_count, components) - end - - __release_table(__table_pool_tag.chunk_stack, chunk_list) - end - end - __evolved_commit() - - return assigned_count, false -end - ----@param chunk_or_query evolved.chunk | evolved.query ----@param fragments evolved.fragment[] ----@param components? evolved.component[] ----@return integer inserted_count ----@return boolean is_deferred -__evolved_batch_multi_insert = function(chunk_or_query, fragments, components) - local fragment_count = #fragments - - if fragment_count == 0 then - return 0, false - end - - if not components then - components = __safe_tbls.__EMPTY_COMPONENT_LIST - end - - if __defer_depth > 0 then - __defer_batch_multi_insert(chunk_or_query, fragments, fragment_count, components, #components) - return 0, true - end - - if __debug_mode then - __debug_fns.validate_fragment_list(fragments, fragment_count) - end - - local inserted_count = 0 - - __evolved_defer() - do - if __lua_type(chunk_or_query) ~= 'number' then - ---@cast chunk_or_query -evolved.query - local chunk = chunk_or_query --[[@as evolved.chunk]] - - inserted_count = inserted_count + __chunk_multi_insert(chunk, fragments, fragment_count, components) - else - ---@cast chunk_or_query -evolved.chunk - local query = chunk_or_query --[[@as evolved.query]] - - ---@type evolved.chunk[] - local chunk_list = __acquire_table(__table_pool_tag.chunk_stack) - local chunk_count = 0 - - for chunk in __evolved_execute(query) do - chunk_count = chunk_count + 1 - chunk_list[chunk_count] = chunk - end - - for chunk_index = 1, chunk_count do - local chunk = chunk_list[chunk_index] - inserted_count = inserted_count + __chunk_multi_insert(chunk, fragments, fragment_count, components) - end - - __release_table(__table_pool_tag.chunk_stack, chunk_list) - end - end - __evolved_commit() - - return inserted_count, false -end - ---@param chunk_or_query evolved.chunk | evolved.query ---@param fragments evolved.fragment[] ---@return integer removed_count @@ -8336,8 +7524,6 @@ evolved.clear = __evolved_clear evolved.destroy = __evolved_destroy evolved.multi_set = __evolved_multi_set -evolved.multi_assign = __evolved_multi_assign -evolved.multi_insert = __evolved_multi_insert evolved.multi_remove = __evolved_multi_remove evolved.batch_set = __evolved_batch_set @@ -8348,8 +7534,6 @@ evolved.batch_clear = __evolved_batch_clear evolved.batch_destroy = __evolved_batch_destroy evolved.batch_multi_set = __evolved_batch_multi_set -evolved.batch_multi_assign = __evolved_batch_multi_assign -evolved.batch_multi_insert = __evolved_batch_multi_insert evolved.batch_multi_remove = __evolved_batch_multi_remove evolved.chunk = __evolved_chunk From a02b32150c53b3ed7f041e6a3a83cffb3eab017b Mon Sep 17 00:00:00 2001 From: BlackMATov Date: Thu, 20 Mar 2025 04:55:02 +0700 Subject: [PATCH 04/12] fix tests after the evolved.multi_assign/insert, evolved.batch_multi_assing/insert removing --- develop/untests.lua | 251 +++++++++++++++++++++----------------------- 1 file changed, 122 insertions(+), 129 deletions(-) diff --git a/develop/untests.lua b/develop/untests.lua index 8ae11f1..90b2b57 100644 --- a/develop/untests.lua +++ b/develop/untests.lua @@ -2614,30 +2614,27 @@ do do local e = evo.id() - assert(not evo.multi_insert(e, {})) - assert(not evo.multi_insert(e, {}, {})) - assert(not evo.multi_insert(e, {}, { 41 })) + assert(not evo.multi_set(e, {})) + assert(not evo.multi_set(e, {}, {})) + assert(not evo.multi_set(e, {}, { 41 })) assert(evo.is_alive(e) and evo.is_empty(e)) - assert(evo.multi_insert(e, { f1 })) + assert(evo.multi_set(e, { f1 })) assert(evo.has(e, f1) and evo.get(e, f1) == true) - assert(not evo.multi_insert(e, { f1 })) - assert(evo.has(e, f1) and evo.get(e, f1) == true) - - assert(evo.multi_insert(e, { f2 }, { 42, 43 })) + assert(evo.multi_set(e, { f2 }, { 42, 43 })) assert(evo.has(e, f1) and evo.get(e, f1) == true) assert(evo.has(e, f2) and evo.get(e, f2) == 42) end do local e = evo.id() - assert(evo.multi_insert(e, { f1, f2 }, { 41 })) + assert(evo.multi_set(e, { f1, f2 }, { 41 })) assert(evo.has(e, f1) and evo.get(e, f1) == 41) assert(evo.has(e, f2) and evo.get(e, f2) == true) - assert(evo.multi_insert(e, { f1, f3 }, { 20, 43 })) - assert(evo.has(e, f1) and evo.get(e, f1) == 41) + assert(evo.multi_set(e, { f1, f3 }, { 20, 43 })) + assert(evo.has(e, f1) and evo.get(e, f1) == 20) assert(evo.has(e, f2) and evo.get(e, f2) == true) assert(evo.has(e, f3) and evo.get(e, f3) == 43) end @@ -2648,16 +2645,16 @@ do do local e1 = evo.id() - assert(evo.multi_insert(e1, { f1, f2 }, { 41, 42 })) + assert(evo.multi_set(e1, { f1, f2 }, { 41, 42 })) assert(evo.has(e1, f1) and evo.get(e1, f1) == 41) assert(evo.has(e1, f2) and evo.get(e1, f2) == 42) local e2 = evo.id() - assert(evo.multi_insert(e2, { f1, f2 }, { 43, 44 })) + assert(evo.multi_set(e2, { f1, f2 }, { 43, 44 })) assert(evo.has(e2, f1) and evo.get(e2, f1) == 43) assert(evo.has(e2, f2) and evo.get(e2, f2) == 44) - assert(evo.multi_insert(e1, { f3 })) + assert(evo.multi_set(e1, { f3 })) do local chunk, entities = evo.chunk(f1, f2) assert(entities and #entities == 1 and entities[1] == e2) @@ -2669,15 +2666,15 @@ do local e1, e2 = evo.id(2) evo.defer() do - evo.multi_insert(e1, { f1, f2 }, { 41, 42 }) - evo.multi_insert(e2, { f2, f2 }, { 43, 44 }) + evo.multi_set(e1, { f1, f2 }, { 41, 42 }) + evo.multi_set(e2, { f2, f2 }, { 43, 44 }) end assert(evo.is_alive(e1) and evo.is_empty(e1)) assert(evo.is_alive(e2) and evo.is_empty(e2)) assert(evo.commit()) assert(evo.has(e1, f1) and evo.get(e1, f1) == 41) assert(evo.has(e1, f2) and evo.get(e1, f2) == 42) - assert(evo.has(e2, f2) and evo.get(e2, f2) == 43) + assert(evo.has(e2, f2) and evo.get(e2, f2) == 44) end end @@ -2709,43 +2706,37 @@ do do local e = evo.id() - assert(evo.multi_insert(e, { f1, f2 }, { 41, 42 })) + assert(evo.multi_set(e, { f1, f2 }, { 41, 42 })) assert(last_set_entity == e and last_set_component == 42) end do local e = evo.id() - assert(evo.multi_insert(e, { f1, f2, f3 }, { 41, 42, 43 })) + assert(evo.multi_set(e, { f1, f2, f3 }, { 41, 42, 43 })) assert(last_set_entity == e and last_set_component == nil) end end do - local f1, f2, f3 = evo.id(3) + local f1, f2 = evo.id(2) do local e = evo.id() - assert(not evo.multi_assign(e, {})) - assert(not evo.multi_assign(e, {}, {})) - assert(not evo.multi_assign(e, {}, { 41 })) + assert(not evo.multi_set(e, {})) + assert(not evo.multi_set(e, {}, {})) + assert(not evo.multi_set(e, {}, { 41 })) assert(evo.is_alive(e) and evo.is_empty(e)) - assert(evo.multi_insert(e, { f1 }, { 21 })) - assert(evo.multi_assign(e, { f1, f2 }, { 41, 42 })) - assert(not evo.multi_assign(e, { f2 }, { 42 })) + assert(evo.multi_set(e, { f1 }, { 21 })) + assert(evo.multi_set(e, { f1 }, { 41 })) assert(evo.has(e, f1) and evo.get(e, f1) == 41) assert(not evo.has(e, f2) and evo.get(e, f2) == nil) - assert(not evo.multi_assign(e, { f3 }, { 43 })) - assert(evo.has(e, f1) and evo.get(e, f1) == 41) - assert(not evo.has(e, f2) and evo.get(e, f2) == nil) - assert(not evo.has(e, f3) and evo.get(e, f3) == nil) - - assert(evo.multi_insert(e, { f2 }, { 22 })) - assert(evo.multi_assign(e, { f2 })) + assert(evo.multi_set(e, { f2 }, { 22 })) + assert(evo.multi_set(e, { f2 })) assert(evo.has(e, f1) and evo.get(e, f1) == 41) assert(evo.has(e, f2) and evo.get(e, f2) == true) - assert(evo.multi_assign(e, { f2 }, { 42, 43 })) + assert(evo.multi_set(e, { f2 }, { 42, 43 })) assert(evo.has(e, f1) and evo.get(e, f1) == 41) assert(evo.has(e, f2) and evo.get(e, f2) == 42) end @@ -2754,11 +2745,11 @@ do local e1, e2 = evo.id(2) evo.defer() do - evo.multi_insert(e1, { f1, f2 }, { 21, 22 }) - evo.multi_assign(e1, { f1, f2 }, { 41, 42 }) + evo.multi_set(e1, { f1, f2 }, { 21, 22 }) + evo.multi_set(e1, { f1, f2 }, { 41, 42 }) - evo.multi_insert(e2, { f1, f2 }, { 31, 32 }) - evo.multi_assign(e2, { f1, f2 }, { 51, 52 }) + evo.multi_set(e2, { f1, f2 }, { 31, 32 }) + evo.multi_set(e2, { f1, f2 }, { 51, 52 }) end assert(evo.is_alive(e1) and evo.is_empty(e1)) assert(evo.is_alive(e2) and evo.is_empty(e2)) @@ -2798,23 +2789,20 @@ do do local e = evo.id() - assert(not evo.multi_assign(e, { f1, f2 }, { 41, 42 })) - assert(last_set_entity == 0 and last_set_component == 0) - - assert(evo.multi_insert(e, { f1, f2 }, { 21, 22 })) + assert(evo.multi_set(e, { f1, f2 }, { 21, 22 })) assert(last_set_entity == e and last_set_component == 22) - assert(evo.multi_assign(e, { f1, f2 }, { 41, 42 })) + assert(evo.multi_set(e, { f1, f2 }, { 41, 42 })) assert(last_set_entity == e and last_set_component == 42) end do local e = evo.id() - assert(evo.multi_insert(e, { f1, f2, f3 }, { 21, 22, 23 })) + assert(evo.multi_set(e, { f1, f2, f3 }, { 21, 22, 23 })) assert(last_set_entity == e and last_set_component == nil) last_set_entity, last_set_component = 0, 0 - assert(evo.multi_assign(e, { f1, f2, f3 }, { 41, 42, 43 })) + assert(evo.multi_set(e, { f1, f2, f3 }, { 41, 42, 43 })) assert(last_set_entity == e and last_set_component == nil) assert(evo.has(e, f1) and evo.get(e, f1) == 41) assert(evo.has(e, f2) and evo.get(e, f2) == 42) @@ -2829,7 +2817,7 @@ do do local e = evo.id() - assert(evo.multi_insert(e, { f1, f2, f3 }, { 41, 42, 43 })) + assert(evo.multi_set(e, { f1, f2, f3 }, { 41, 42, 43 })) assert(evo.has_all(e, f1, f2, f3)) assert(evo.multi_remove(e, {})) @@ -2847,7 +2835,7 @@ do do local e = evo.id() - assert(evo.multi_insert(e, { f1, f2, f3 }, { 41, 42, 43 })) + assert(evo.multi_set(e, { f1, f2, f3 }, { 41, 42, 43 })) assert(evo.has_all(e, f1, f2, f3)) evo.defer() evo.multi_remove(e, { f1, f2 }) @@ -2888,7 +2876,7 @@ do assert(evo.multi_remove(e, { f1, f2 })) assert(last_remove_entity == 0 and last_remove_component == 0) - assert(evo.multi_insert(e, { f1, f2, f3 }, { 41, 42 })) + assert(evo.multi_set(e, { f1, f2, f3 }, { 41, 42 })) assert(last_remove_entity == 0 and last_remove_component == 0) assert(evo.multi_remove(e, { f1, f2 })) assert(last_remove_entity == e and last_remove_component == 42) @@ -2902,8 +2890,8 @@ do do local e1, e2 = evo.id(2) - assert(evo.multi_insert(e1, { f1, f2, f3 }, { 41, 42, 43 })) - assert(evo.multi_insert(e2, { f1, f2, f3 }, { 44, 45, 46 })) + assert(evo.multi_set(e1, { f1, f2, f3 }, { 41, 42, 43 })) + assert(evo.multi_set(e2, { f1, f2, f3 }, { 44, 45, 46 })) assert(evo.multi_remove(e1, { f1, f2 })) @@ -3098,7 +3086,7 @@ do local e = evo.id() assert(evo.set(e, f1, 41)) - assert(evo.multi_assign(e, { f1, f1 }, { 42, 43 })) + assert(evo.multi_set(e, { f1, f1 }, { 42, 43 })) assert(assign_entity_sum == e + e and assign_component_sum == 42 + 43) assert(insert_entity_sum == e and insert_component_sum == 41) @@ -3109,7 +3097,7 @@ do insert_entity_sum, insert_component_sum = 0, 0 local e = evo.id() - assert(evo.multi_insert(e, { f1, f1 }, { 41, 42 })) + assert(evo.multi_set(e, { f1, f1 }, { 41, 42 })) assert(insert_entity_sum == e and insert_component_sum == 41) end @@ -3961,14 +3949,18 @@ do do local q = evo.query():include(f1):build() - assert(evo.batch_multi_assign(q, {}) == 0) - assert(evo.batch_multi_assign(q, { f5 }) == 0) + assert(evo.batch_multi_set(q, {}) == 0) end do - local q = evo.query():include(f3):build() + local q = evo.query():include(f1, f5):build() + assert(evo.batch_multi_set(q, { f5 }) == 0) + end - assert(evo.batch_multi_assign(q, { f4 }, { 54 }) == 1) + do + local q = evo.query():include(f3, f4):build() + + assert(evo.batch_multi_set(q, { f4 }, { 54 }) == 1) assert(evo.get(e3, f3) == 33 and evo.get(e3, f4) == nil) assert(evo.get(e4, f3) == 43 and evo.get(e4, f4) == 54) end @@ -3976,15 +3968,15 @@ do do local q = evo.query():include(f2):build() - assert(evo.batch_multi_assign(q, { f1 }, { 51, 52 }) == 3) + assert(evo.batch_multi_set(q, { f1 }, { 51, 52 }) == 3) assert(evo.get(e1, f1) == 11 and evo.get(e1, f2) == nil and evo.get(e1, f3) == nil) assert(evo.get(e2, f1) == 51 and evo.get(e2, f2) == 22 and evo.get(e2, f3) == nil) assert(evo.get(e3, f1) == 51 and evo.get(e3, f2) == 32 and evo.get(e3, f3) == 33) assert(evo.get(e4, f1) == 51 and evo.get(e4, f2) == 42 and evo.get(e4, f3) == 43 and evo.get(e4, f4) == 54) - assert(evo.batch_multi_assign(q, { f2, f3 }, { 52, 53 }) == 3) + assert(evo.batch_multi_set(q, { f2, f3 }, { 52, 53 }) == 4) assert(evo.get(e1, f1) == 11 and evo.get(e1, f2) == nil and evo.get(e1, f3) == nil) - assert(evo.get(e2, f1) == 51 and evo.get(e2, f2) == 52 and evo.get(e2, f3) == nil) + assert(evo.get(e2, f1) == 51 and evo.get(e2, f2) == 52 and evo.get(e2, f3) == 53) assert(evo.get(e3, f1) == 51 and evo.get(e3, f2) == 52 and evo.get(e3, f3) == 53) assert(evo.get(e4, f1) == 51 and evo.get(e4, f2) == 52 and evo.get(e4, f3) == 53 and evo.get(e4, f4) == 54) end @@ -4008,14 +4000,14 @@ do do local q = evo.query():include(f1):build() - assert(evo.batch_multi_assign(q, {}) == 0) - assert(evo.batch_multi_assign(q, { f5 }) == 0) + assert(evo.batch_multi_set(q, {}) == 0) + assert(evo.batch_multi_set(q, { f5 }) == 0) end do - local q = evo.query():include(f3):build() + local q = evo.query():include(f3, f4):build() - assert(evo.batch_multi_assign(q, { f4 }, { 54 }) == 1) + assert(evo.batch_multi_set(q, { f4 }, { 54 }) == 1) assert(evo.get(e1, f1) == 11 and evo.get(e1, f2) == nil and evo.get(e1, f3) == nil) assert(evo.get(e2, f1) == 21 and evo.get(e2, f2) == 22 and evo.get(e2, f3) == nil) assert(evo.get(e3, f1) == 31 and evo.get(e3, f2) == 32 and evo.get(e3, f3) == nil) @@ -4025,13 +4017,13 @@ do do local q = evo.query():include(f2):build() - assert(evo.batch_multi_assign(q, { f1 }, { 51, 52 }) == 3) + assert(evo.batch_multi_set(q, { f1 }, { 51, 52 }) == 3) assert(evo.get(e1, f1) == 11 and evo.get(e1, f2) == nil and evo.get(e1, f3) == nil) assert(evo.get(e2, f1) == 51 and evo.get(e2, f2) == 22 and evo.get(e2, f3) == nil) assert(evo.get(e3, f1) == 51 and evo.get(e3, f2) == 32 and evo.get(e3, f3) == nil) assert(evo.get(e4, f1) == 51 and evo.get(e4, f2) == 42 and evo.get(e4, f3) == nil and evo.get(e4, f4) == 54) - assert(evo.batch_multi_assign(q, { f2, f3 }, { 52, 53 }) == 3) + assert(evo.batch_multi_set(q, { f2, f3 }, { 52, 53 }) == 4) assert(evo.get(e1, f1) == 11 and evo.get(e1, f2) == nil and evo.get(e1, f3) == nil) assert(evo.get(e2, f1) == 51 and evo.get(e2, f2) == 52 and evo.get(e2, f3) == nil) assert(evo.get(e3, f1) == 51 and evo.get(e3, f2) == 52 and evo.get(e3, f3) == nil) @@ -4041,14 +4033,14 @@ do do local q = evo.query():include(f1):build() - assert(evo.batch_multi_assign(q, { f1 }) == 4) + assert(evo.batch_multi_set(q, { f1 }) == 4) assert(evo.get(e1, f1) == true and evo.get(e1, f2) == nil and evo.get(e1, f3) == nil) assert(evo.get(e2, f1) == true and evo.get(e2, f2) == 52 and evo.get(e2, f3) == nil) assert(evo.get(e3, f1) == true and evo.get(e3, f2) == 52 and evo.get(e3, f3) == nil) assert(evo.get(e4, f1) == true and evo.get(e4, f2) == 52 and evo.get(e4, f3) == nil and evo.get(e4, f4) == 54) - assert(evo.batch_multi_assign(q, { f2 }) == 3) - assert(evo.get(e1, f1) == true and evo.get(e1, f2) == nil and evo.get(e1, f3) == nil) + assert(evo.batch_multi_set(q, { f2 }) == 4) + assert(evo.get(e1, f1) == true and evo.get(e1, f2) == 41 and evo.get(e1, f3) == nil) assert(evo.get(e2, f1) == true and evo.get(e2, f2) == 41 and evo.get(e2, f3) == nil) assert(evo.get(e3, f1) == true and evo.get(e3, f2) == 41 and evo.get(e3, f3) == nil) assert(evo.get(e4, f1) == true and evo.get(e4, f2) == 41 and evo.get(e4, f3) == nil and evo.get(e4, f4) == 54) @@ -4102,7 +4094,7 @@ do last_assign_new_component = 0 last_assign_old_component = 0 - assert(evo.batch_multi_assign(q, { f2 }, {}) == 1) + assert(evo.batch_multi_set(q, { f2 }, {}) == 1) assert(sum_entity == e3) assert(last_assign_entity == e3) assert(last_assign_new_component == 42) @@ -4117,7 +4109,7 @@ do last_assign_new_component = 0 last_assign_old_component = 0 - assert(evo.batch_multi_assign(q, { f1 }, { 51 }) == 3) + assert(evo.batch_multi_set(q, { f1 }, { 51 }) == 3) assert(sum_entity == e1 + e2 + e3) assert(last_assign_entity == e3) assert(last_assign_new_component == 51) @@ -4132,7 +4124,7 @@ do last_assign_new_component = 0 last_assign_old_component = 0 - assert(evo.batch_multi_assign(q, { f1, f1 }, { 61, 61 }) == 3) + assert(evo.batch_multi_set(q, { f1, f1 }, { 61, 61 }) == 3) assert(sum_entity == e1 + e2 + e3 + e1 + e2 + e3) assert(last_assign_entity == e3) assert(last_assign_new_component == 61) @@ -4140,14 +4132,14 @@ do end do - local q = evo.query():include(f1):build() + local q = evo.query():include(f1, f3):build() sum_entity = 0 last_assign_entity = 0 last_assign_new_component = 0 last_assign_old_component = 0 - assert(evo.batch_multi_assign(q, { f3 }, { 63 }) == 1) + assert(evo.batch_multi_set(q, { f3 }, { 63 }) == 1) assert(sum_entity == e3) assert(last_assign_entity == e3) assert(last_assign_new_component == nil) @@ -4166,14 +4158,13 @@ do do local q = evo.query():include(f1):build() - assert(evo.batch_multi_insert(q, {}) == 0) - assert(evo.batch_multi_insert(q, { f1 }) == 0) + assert(evo.batch_multi_set(q, {}) == 0) end do - local q = evo.query():include(f3):build() + local q = evo.query():include(f3):exclude(f4):build() - assert(evo.batch_multi_insert(q, { f4 }) == 1) + assert(evo.batch_multi_set(q, { f4 }) == 1) assert(evo.get(e3, f1) == 31 and evo.get(e3, f2) == 32 and evo.get(e3, f3) == 33 and evo.get(e3, f4) == true) assert(evo.get(e4, f1) == 41 and evo.get(e4, f2) == 42 and evo.get(e4, f3) == 43 and evo.get(e4, f4) == 44) @@ -4194,9 +4185,9 @@ do end do - local q = evo.query():include(f1):build() + local q = evo.query():include(f1):exclude(f3, f4):build() - assert(evo.batch_multi_insert(q, { f3, f4 }, { 53, 54 }) == 2) + assert(evo.batch_multi_set(q, { f3, f4 }, { 53, 54 }) == 2) assert(evo.get(e1, f1) == 11 and evo.get(e1, f2) == nil and evo.get(e1, f3) == 53 and evo.get(e1, f4) == 54) assert(evo.get(e2, f1) == 21 and evo.get(e2, f2) == 22 and evo.get(e2, f3) == 53 and evo.get(e2, f4) == 54) assert(evo.get(e3, f1) == 31 and evo.get(e3, f2) == 32 and evo.get(e3, f3) == 33 and evo.get(e3, f4) == true) @@ -4252,12 +4243,12 @@ do do local q = evo.query():include(f1):build() - assert(evo.batch_multi_insert(q, {}) == 0) + assert(evo.batch_multi_set(q, {}) == 0) end do - local q = evo.query():include(f1):build() - assert(evo.batch_multi_insert(q, { f2 }) == 1) + local q = evo.query():include(f1):exclude(f2):build() + assert(evo.batch_multi_set(q, { f2 }) == 1) assert(evo.get(e1, f1) == 11 and evo.get(e1, f2) == 41 and evo.get(e1, f3) == nil) assert(evo.get(e2, f1) == 21 and evo.get(e2, f2) == 22 and evo.get(e2, f3) == nil) @@ -4316,13 +4307,13 @@ do local e3 = evo.entity():set(f1, 31):set(f2, 32):set(f3, 33):build() do - local q = evo.query():include(f1):build() + local q = evo.query():include(f1):exclude(f2):build() sum_entity = 0 last_insert_entity = 0 last_insert_component = 0 - assert(evo.batch_multi_insert(q, { f2 }) == 1) + assert(evo.batch_multi_set(q, { f2 }) == 1) assert(sum_entity == e1) assert(last_insert_entity == e1) assert(last_insert_component == 42) @@ -4335,13 +4326,13 @@ do end do - local q = evo.query():include(f2):build() + local q = evo.query():include(f2):exclude(f3):build() sum_entity = 0 last_insert_entity = 0 last_insert_component = 0 - assert(evo.batch_multi_insert(q, { f3 }) == 2) + assert(evo.batch_multi_set(q, { f3 }) == 2) assert(sum_entity == e1 + e2) assert(last_insert_entity == e1) assert(last_insert_component == nil) @@ -4360,7 +4351,7 @@ do last_insert_entity = 0 last_insert_component = 0 - assert(evo.batch_multi_insert(q, { f3, f4, f5, f5 }, { 53, 54, 55, 65 }) == 3) + assert(evo.batch_multi_set(q, { f3, f4, f5, f5 }, { 53, 54, 55, 65 }) == 3) assert(sum_entity == e1 + e2 + e3 + e1 + e2 + e3) assert(last_insert_entity == e1) assert(last_insert_component == 55) @@ -4370,9 +4361,9 @@ do assert(evo.get(e1, f1) == 11 and evo.get(e1, f2) == 42 and evo.get(e1, f3) == nil) assert(evo.get(e2, f1) == 21 and evo.get(e2, f2) == 22 and evo.get(e2, f3) == nil) assert(evo.get(e3, f1) == 31 and evo.get(e3, f2) == 32 and evo.get(e3, f3) == nil) - assert(evo.get(e1, f4) == 54 and evo.get(e1, f5) == 55) - assert(evo.get(e2, f4) == 54 and evo.get(e2, f5) == 55) - assert(evo.get(e3, f4) == 54 and evo.get(e3, f5) == 55) + assert(evo.get(e1, f4) == 54 and evo.get(e1, f5) == 65) + assert(evo.get(e2, f4) == 54 and evo.get(e2, f5) == 65) + assert(evo.get(e3, f4) == 54 and evo.get(e3, f5) == 65) end end @@ -4746,16 +4737,18 @@ do assert(evo.defer()) do - local q = evo.query():include(f1):build() do - local n, d = evo.batch_multi_insert(q, { f2 }, { 42 }) + local q = evo.query():include(f1):exclude(f2):build() + local n, d = evo.batch_multi_set(q, { f2 }, { 42 }) assert(n == 0 and d == true) end do - local n, d = evo.batch_multi_assign(q, { f3 }, { 43 }) + local q = evo.query():include(f1, f3):build() + local n, d = evo.batch_multi_set(q, { f3 }, { 43 }) assert(n == 0 and d == true) end do + local q = evo.query():include(f1):build() local n, d = evo.batch_multi_remove(q, { f1 }) assert(n == 0 and d == true) end @@ -5062,8 +5055,8 @@ do assert(evo.clear(e)) assert(not evo.multi_set(e, { f1 }, { 11 })) - assert(not evo.multi_assign(e, { f1 }, { 11 })) - assert(not evo.multi_insert(e, { f1 }, { 11 })) + assert(not evo.multi_set(e, { f1 }, { 11 })) + assert(not evo.multi_set(e, { f1 }, { 11 })) assert(evo.multi_remove(e, { f1 })) end @@ -5120,9 +5113,9 @@ do assert(last_assign_f2_new_component == 42 and last_assign_f2_old_component == 22) assert(last_insert_f3_new_component == nil) - assert(evo.multi_assign(e, { f1, f2, f3 }, { 11, 22, 33 })) + assert(evo.multi_set(e, { f1, f2, f3 }, { 11, 22, 33 })) assert(evo.get(e, f1) == 11 and evo.get(e, f2) == 22 and evo.get(e, f3) == nil) - assert(evo.multi_assign(e, { f1, f2, f3 }, {})) + assert(evo.multi_set(e, { f1, f2, f3 }, {})) assert(evo.get(e, f1) == true and evo.get(e, f2) == 42 and evo.get(e, f3) == nil) end @@ -5147,8 +5140,8 @@ do last_insert_f2_new_component = 0 - assert(evo.multi_insert(e, { f2, f2 }, { nil, 22 })) - assert(evo.get(e, f2) == 42) + assert(evo.multi_set(e, { f2, f2 }, { nil, 22 })) + assert(evo.get(e, f2) == 22) assert(last_insert_f2_new_component == 42) end end @@ -5161,11 +5154,11 @@ do do local e = evo.id() - assert(evo.multi_insert(e, { f1, f2 })) + assert(evo.multi_set(e, { f1, f2 })) assert(evo.get(e, f1) == 41 and evo.get(e, f2) == true) - assert(evo.multi_assign(e, { f1, f2 }, { 11, 22 })) + assert(evo.multi_set(e, { f1, f2 }, { 11, 22 })) assert(evo.get(e, f1) == 11 and evo.get(e, f2) == 22) - assert(evo.multi_assign(e, { f1, f2 })) + assert(evo.multi_set(e, { f1, f2 })) assert(evo.get(e, f1) == 41 and evo.get(e, f2) == true) end end @@ -5267,7 +5260,7 @@ do end do local e1 = evo.id() - evo.multi_insert(e1, { f0, f1, f2, f3, f4, f5 }) + evo.multi_set(e1, { f0, f1, f2, f3, f4, f5 }) evo.set(e1, f0) evo.set(e1, f1, 1) evo.set(e1, f2, 1, 2) @@ -5283,11 +5276,11 @@ do end do local e1, e2, e3, e4, e5 = evo.id(5) - evo.multi_insert(e1, { f1, f2, f3, f4, f5 }) - evo.multi_insert(e2, { f1, f2, f3, f4, f5 }) - evo.multi_insert(e3, { f1, f2, f3, f4, f5 }) - evo.multi_insert(e4, { f1, f2, f3, f4, f5 }) - evo.multi_insert(e5, { f1, f2, f3, f4, f5 }) + evo.multi_set(e1, { f1, f2, f3, f4, f5 }) + evo.multi_set(e2, { f1, f2, f3, f4, f5 }) + evo.multi_set(e3, { f1, f2, f3, f4, f5 }) + evo.multi_set(e4, { f1, f2, f3, f4, f5 }) + evo.multi_set(e5, { f1, f2, f3, f4, f5 }) evo.remove(e1, f0, f1) evo.remove(e2, f0, f1, f2) evo.remove(e3, f0, f1, f2, f3) @@ -5378,8 +5371,8 @@ do end do local e1, e2 = evo.id(2) - evo.multi_insert(e1, { f0, f1, f2, f3, f4, f5 }) - evo.multi_insert(e2, { f0, f1, f2, f3, f4, f5 }) + evo.multi_set(e1, { f0, f1, f2, f3, f4, f5 }) + evo.multi_set(e2, { f0, f1, f2, f3, f4, f5 }) assert(evo.defer()) evo.set(e1, f0) evo.set(e1, f1, 1) @@ -5409,11 +5402,11 @@ do end do local e1, e2, e3, e4, e5 = evo.id(5) - evo.multi_insert(e1, { f1, f2, f3, f4, f5 }) - evo.multi_insert(e2, { f1, f2, f3, f4, f5 }) - evo.multi_insert(e3, { f1, f2, f3, f4, f5 }) - evo.multi_insert(e4, { f1, f2, f3, f4, f5 }) - evo.multi_insert(e5, { f1, f2, f3, f4, f5 }) + evo.multi_set(e1, { f1, f2, f3, f4, f5 }) + evo.multi_set(e2, { f1, f2, f3, f4, f5 }) + evo.multi_set(e3, { f1, f2, f3, f4, f5 }) + evo.multi_set(e4, { f1, f2, f3, f4, f5 }) + evo.multi_set(e5, { f1, f2, f3, f4, f5 }) assert(evo.defer()) evo.remove(e1, f1) evo.remove(e2, f1, f2) @@ -5882,12 +5875,12 @@ do local e = evo.id() - assert(evo.multi_insert(e, { f1 }, { 41 })) + assert(evo.multi_set(e, { f1 }, { 41 })) assert(evo.get(e, f1) == 41) assert(evo.get(e, f2) == 41) assert(assign_count == 0 and insert_count == 2 and remove_count == 0) - assert(evo.multi_assign(e, { f1 }, { 51 })) + assert(evo.multi_set(e, { f1 }, { 51 })) assert(evo.get(e, f1) == 51) assert(evo.get(e, f2) == 51) assert(assign_count == 2 and insert_count == 2 and remove_count == 0) @@ -6003,7 +5996,7 @@ do remove_count = 0 local e = evo.id() - assert(evo.multi_insert(e, { f1, f2 }, { 41, 42 })) + assert(evo.multi_set(e, { f1, f2 }, { 41, 42 })) assert(assign_count == 0 and insert_count == 2 and remove_count == 0) end @@ -6014,8 +6007,8 @@ do remove_count = 0 local e = evo.id() - assert(evo.multi_insert(e, { f1, f2 }, { 41, 42 })) - assert(evo.multi_assign(e, { f1, f2 }, { 51, 52 })) + assert(evo.multi_set(e, { f1, f2 }, { 41, 42 })) + assert(evo.multi_set(e, { f1, f2 }, { 51, 52 })) assert(evo.multi_remove(e, { f1, f2 })) assert(assign_count == 2 and insert_count == 2 and remove_count == 2) @@ -6027,8 +6020,8 @@ do remove_count = 0 local e = evo.id() - assert(evo.multi_insert(e, { f1, f2 }, { 41, 42 })) - assert(evo.multi_assign(e, { f1, f2 }, { 51, 52 })) + assert(evo.multi_set(e, { f1, f2 }, { 41, 42 })) + assert(evo.multi_set(e, { f1, f2 }, { 51, 52 })) assert(evo.clear(e)) assert(assign_count == 2 and insert_count == 2 and remove_count == 2) @@ -6040,8 +6033,8 @@ do remove_count = 0 local e = evo.id() - assert(evo.multi_insert(e, { f1, f2 }, { 41, 42 })) - assert(evo.multi_assign(e, { f1, f2 }, { 51, 52 })) + assert(evo.multi_set(e, { f1, f2 }, { 41, 42 })) + assert(evo.multi_set(e, { f1, f2 }, { 51, 52 })) assert(evo.destroy(e)) assert(assign_count == 2 and insert_count == 2 and remove_count == 2) @@ -6197,10 +6190,10 @@ do assert(evo.set(e1, f0) and evo.set(e2, f0)) - assert(evo.batch_multi_insert(q0, { f1, f2 }, { 41, 42 })) + assert(evo.batch_multi_set(q0, { f1, f2 }, { 41, 42 })) assert(assign_count == 0 and insert_count == 4 and remove_count == 0) - assert(evo.batch_multi_assign(q0, { f1, f2 }, { 51, 52 })) + assert(evo.batch_multi_set(q0, { f1, f2 }, { 51, 52 })) assert(assign_count == 4 and insert_count == 4 and remove_count == 0) assert(evo.batch_multi_remove(q0, { f1, f2 })) @@ -7992,7 +7985,7 @@ do end assert(evo.set(e1a, f1, 1) and evo.set(e1b, f1, 2)) - assert(evo.multi_insert(e12a, { f1, f2 }, { 3, 4 }) and evo.multi_insert(e12b, { f1, f2 }, { 5, 6 })) + assert(evo.multi_set(e12a, { f1, f2 }, { 3, 4 }) and evo.multi_set(e12b, { f1, f2 }, { 5, 6 })) do assert(evo.is_alive_all(e1a, e1b, e12a, e12b)) @@ -8041,7 +8034,7 @@ do assert(evo.get(e12a, f2) == 4 and evo.get(e12b, f2) == 6) end - assert(4 == evo.batch_multi_assign(c12, { f1 }, { 7 })) + assert(4 == evo.batch_multi_set(c12, { f1 }, { 7 })) do local c12_es, c12_ec = evo.entities(c12) @@ -8063,7 +8056,7 @@ do assert(evo.get(e12a, f1) == 7 and evo.get(e12b, f1) == 7) end - assert(4 == evo.batch_multi_insert(c1, { f2 }, { 8 })) + assert(4 == evo.batch_multi_set(c1, { f2 }, { 8 })) do local c12_es, c12_ec = evo.entities(c12) From 923d44acfe659add632bef1faf550863b30250ea Mon Sep 17 00:00:00 2001 From: BlackMATov Date: Thu, 20 Mar 2025 05:12:48 +0700 Subject: [PATCH 05/12] remove evolved.batch_assign/insert --- README.md | 2 - evolved.lua | 260 ---------------------------------------------------- 2 files changed, 262 deletions(-) diff --git a/README.md b/README.md index 03e188e..1f9fd8c 100644 --- a/README.md +++ b/README.md @@ -86,8 +86,6 @@ multi_set :: entity, fragment[], component[]? -> boolean, boolean multi_remove :: entity, fragment[] -> boolean, boolean batch_set :: chunk | query, fragment, any... -> integer, boolean -batch_assign :: chunk | query, fragment, any... -> integer, boolean -batch_insert :: chunk | query, fragment, any... -> integer, boolean batch_remove :: chunk | query, fragment... -> integer, boolean batch_clear :: chunk | query... -> integer, boolean batch_destroy :: chunk | query... -> integer, boolean diff --git a/evolved.lua b/evolved.lua index 4b31559..63da514 100644 --- a/evolved.lua +++ b/evolved.lua @@ -664,8 +664,6 @@ local __evolved_multi_set local __evolved_multi_remove local __evolved_batch_set -local __evolved_batch_assign -local __evolved_batch_insert local __evolved_batch_remove local __evolved_batch_clear local __evolved_batch_destroy @@ -1510,8 +1508,6 @@ local __defer_multi_set local __defer_multi_remove local __defer_batch_set -local __defer_batch_assign -local __defer_batch_insert local __defer_batch_remove local __defer_batch_clear local __defer_batch_destroy @@ -3205,8 +3201,6 @@ local __defer_op = { multi_remove = 10, batch_set = 11, - batch_assign = 12, - batch_insert = 13, batch_remove = 14, batch_clear = 15, batch_destroy = 16, @@ -3654,158 +3648,6 @@ __defer_ops[__defer_op.batch_set] = function(bytes, index) return 3 + argument_count end ----@param chunk_or_query evolved.chunk | evolved.query ----@param fragment evolved.fragment ----@param ... any component arguments -__defer_batch_assign = function(chunk_or_query, fragment, ...) - local length = __defer_length - local bytecode = __defer_bytecode - - local argument_count = __lua_select('#', ...) - - bytecode[length + 1] = __defer_op.batch_assign - bytecode[length + 2] = chunk_or_query - bytecode[length + 3] = fragment - bytecode[length + 4] = argument_count - - if argument_count == 0 then - -- nothing - elseif argument_count == 1 then - local a1 = ... - bytecode[length + 5] = a1 - elseif argument_count == 2 then - local a1, a2 = ... - bytecode[length + 5] = a1 - bytecode[length + 6] = a2 - elseif argument_count == 3 then - local a1, a2, a3 = ... - bytecode[length + 5] = a1 - bytecode[length + 6] = a2 - bytecode[length + 7] = a3 - elseif argument_count == 4 then - local a1, a2, a3, a4 = ... - bytecode[length + 5] = a1 - bytecode[length + 6] = a2 - bytecode[length + 7] = a3 - bytecode[length + 8] = a4 - else - local a1, a2, a3, a4 = ... - bytecode[length + 5] = a1 - bytecode[length + 6] = a2 - bytecode[length + 7] = a3 - bytecode[length + 8] = a4 - for i = 5, argument_count do - bytecode[length + 4 + i] = __lua_select(i, ...) - end - end - - __defer_length = length + 4 + argument_count -end - -__defer_ops[__defer_op.batch_assign] = function(bytes, index) - local chunk_or_query = bytes[index + 0] - local fragment = bytes[index + 1] - local argument_count = bytes[index + 2] - - if argument_count == 0 then - __evolved_batch_assign(chunk_or_query, fragment) - elseif argument_count == 1 then - local a1 = bytes[index + 3] - __evolved_batch_assign(chunk_or_query, fragment, a1) - elseif argument_count == 2 then - local a1, a2 = bytes[index + 3], bytes[index + 4] - __evolved_batch_assign(chunk_or_query, fragment, a1, a2) - elseif argument_count == 3 then - local a1, a2, a3 = bytes[index + 3], bytes[index + 4], bytes[index + 5] - __evolved_batch_assign(chunk_or_query, fragment, a1, a2, a3) - elseif argument_count == 4 then - local a1, a2, a3, a4 = bytes[index + 3], bytes[index + 4], bytes[index + 5], bytes[index + 6] - __evolved_batch_assign(chunk_or_query, fragment, a1, a2, a3, a4) - else - local a1, a2, a3, a4 = bytes[index + 3], bytes[index + 4], bytes[index + 5], bytes[index + 6] - __evolved_batch_assign(chunk_or_query, fragment, a1, a2, a3, a4, - __lua_table_unpack(bytes, index + 7, index + 2 + argument_count)) - end - - return 3 + argument_count -end - ----@param chunk_or_query evolved.chunk | evolved.query ----@param fragment evolved.fragment ----@param ... any component arguments -__defer_batch_insert = function(chunk_or_query, fragment, ...) - local length = __defer_length - local bytecode = __defer_bytecode - - local argument_count = __lua_select('#', ...) - - bytecode[length + 1] = __defer_op.batch_insert - bytecode[length + 2] = chunk_or_query - bytecode[length + 3] = fragment - bytecode[length + 4] = argument_count - - if argument_count == 0 then - -- nothing - elseif argument_count == 1 then - local a1 = ... - bytecode[length + 5] = a1 - elseif argument_count == 2 then - local a1, a2 = ... - bytecode[length + 5] = a1 - bytecode[length + 6] = a2 - elseif argument_count == 3 then - local a1, a2, a3 = ... - bytecode[length + 5] = a1 - bytecode[length + 6] = a2 - bytecode[length + 7] = a3 - elseif argument_count == 4 then - local a1, a2, a3, a4 = ... - bytecode[length + 5] = a1 - bytecode[length + 6] = a2 - bytecode[length + 7] = a3 - bytecode[length + 8] = a4 - else - local a1, a2, a3, a4 = ... - bytecode[length + 5] = a1 - bytecode[length + 6] = a2 - bytecode[length + 7] = a3 - bytecode[length + 8] = a4 - for i = 5, argument_count do - bytecode[length + 4 + i] = __lua_select(i, ...) - end - end - - __defer_length = length + 4 + argument_count -end - -__defer_ops[__defer_op.batch_insert] = function(bytes, index) - local chunk_or_query = bytes[index + 0] - local fragment = bytes[index + 1] - local argument_count = bytes[index + 2] - - if argument_count == 0 then - __evolved_batch_insert(chunk_or_query, fragment) - elseif argument_count == 1 then - local a1 = bytes[index + 3] - __evolved_batch_insert(chunk_or_query, fragment, a1) - elseif argument_count == 2 then - local a1, a2 = bytes[index + 3], bytes[index + 4] - __evolved_batch_insert(chunk_or_query, fragment, a1, a2) - elseif argument_count == 3 then - local a1, a2, a3 = bytes[index + 3], bytes[index + 4], bytes[index + 5] - __evolved_batch_insert(chunk_or_query, fragment, a1, a2, a3) - elseif argument_count == 4 then - local a1, a2, a3, a4 = bytes[index + 3], bytes[index + 4], bytes[index + 5], bytes[index + 6] - __evolved_batch_insert(chunk_or_query, fragment, a1, a2, a3, a4) - else - local a1, a2, a3, a4 = bytes[index + 3], bytes[index + 4], bytes[index + 5], bytes[index + 6] - __evolved_batch_insert(chunk_or_query, fragment, a1, a2, a3, a4, - __lua_table_unpack(bytes, index + 7, index + 2 + argument_count)) - end - - return 3 + argument_count -end - ---@param chunk_or_query evolved.chunk | evolved.query ---@param ... evolved.fragment fragments __defer_batch_remove = function(chunk_or_query, ...) @@ -5520,106 +5362,6 @@ __evolved_batch_set = function(chunk_or_query, fragment, ...) return set_count, false end ----@param chunk_or_query evolved.chunk | evolved.query ----@param fragment evolved.fragment ----@param ... any component arguments ----@return integer assigned_count ----@return boolean is_deferred -__evolved_batch_assign = function(chunk_or_query, fragment, ...) - if __defer_depth > 0 then - __defer_batch_assign(chunk_or_query, fragment, ...) - return 0, true - end - - if __debug_mode then - __debug_fns.validate_fragment(fragment) - end - - local assigned_count = 0 - - __evolved_defer() - do - if __lua_type(chunk_or_query) ~= 'number' then - ---@cast chunk_or_query -evolved.query - local chunk = chunk_or_query --[[@as evolved.chunk]] - - assigned_count = assigned_count + __chunk_assign(chunk, fragment, ...) - else - ---@cast chunk_or_query -evolved.chunk - local query = chunk_or_query --[[@as evolved.query]] - - ---@type evolved.chunk[] - local chunk_list = __acquire_table(__table_pool_tag.chunk_stack) - local chunk_count = 0 - - for chunk in __evolved_execute(query) do - chunk_count = chunk_count + 1 - chunk_list[chunk_count] = chunk - end - - for chunk_index = 1, chunk_count do - local chunk = chunk_list[chunk_index] - assigned_count = assigned_count + __chunk_assign(chunk, fragment, ...) - end - - __release_table(__table_pool_tag.chunk_stack, chunk_list) - end - end - __evolved_commit() - - return assigned_count, false -end - ----@param chunk_or_query evolved.chunk | evolved.query ----@param fragment evolved.fragment ----@param ... any component arguments ----@return integer inserted_count ----@return boolean is_deferred -__evolved_batch_insert = function(chunk_or_query, fragment, ...) - if __defer_depth > 0 then - __defer_batch_insert(chunk_or_query, fragment, ...) - return 0, true - end - - if __debug_mode then - __debug_fns.validate_fragment(fragment) - end - - local inserted_count = 0 - - __evolved_defer() - do - if __lua_type(chunk_or_query) ~= 'number' then - ---@cast chunk_or_query -evolved.query - local chunk = chunk_or_query --[[@as evolved.chunk]] - - inserted_count = inserted_count + __chunk_insert(chunk, fragment, ...) - else - ---@cast chunk_or_query -evolved.chunk - local query = chunk_or_query --[[@as evolved.query]] - - ---@type evolved.chunk[] - local chunk_list = __acquire_table(__table_pool_tag.chunk_stack) - local chunk_count = 0 - - for chunk in __evolved_execute(query) do - chunk_count = chunk_count + 1 - chunk_list[chunk_count] = chunk - end - - for chunk_index = 1, chunk_count do - local chunk = chunk_list[chunk_index] - inserted_count = inserted_count + __chunk_insert(chunk, fragment, ...) - end - - __release_table(__table_pool_tag.chunk_stack, chunk_list) - end - end - __evolved_commit() - - return inserted_count, false -end - ---@param chunk_or_query evolved.chunk | evolved.query ---@param ... evolved.fragment fragments ---@return integer removed_count @@ -7527,8 +7269,6 @@ evolved.multi_set = __evolved_multi_set evolved.multi_remove = __evolved_multi_remove evolved.batch_set = __evolved_batch_set -evolved.batch_assign = __evolved_batch_assign -evolved.batch_insert = __evolved_batch_insert evolved.batch_remove = __evolved_batch_remove evolved.batch_clear = __evolved_batch_clear evolved.batch_destroy = __evolved_batch_destroy From 34c00d8c9addb0b4a605e92bd7485d1892824a4a Mon Sep 17 00:00:00 2001 From: BlackMATov Date: Thu, 20 Mar 2025 05:13:15 +0700 Subject: [PATCH 06/12] fix tests after the evolved.batch_assign/insert removing --- develop/untests.lua | 123 +++++++++++++++++++++++++------------------- 1 file changed, 69 insertions(+), 54 deletions(-) diff --git a/develop/untests.lua b/develop/untests.lua index 90b2b57..a293987 100644 --- a/develop/untests.lua +++ b/develop/untests.lua @@ -868,7 +868,7 @@ do local q = evo.id() evo.set(q, evo.INCLUDES, f1, f2) - assert(evo.batch_assign(q, f1, 60) == 3) + assert(evo.batch_set(q, f1, 60) == 3) assert(evo.get(e1, f1) == 41 and evo.get(e1, f3) == nil) assert(evo.get(e2, f1) == 60 and evo.get(e2, f3) == nil) @@ -876,7 +876,8 @@ do assert(evo.get(e4, f1) == 60 and evo.get(e4, f3) == 49) assert(evo.get(e5, f1) == nil and evo.get(e5, f3) == 52) - assert(evo.batch_assign(q, f3, 70) == 2) + evo.set(q, evo.INCLUDES, f1, f2, f3) + assert(evo.batch_set(q, f3, 70) == 2) assert(evo.get(e1, f1) == 41 and evo.get(e1, f3) == nil) assert(evo.get(e2, f1) == 60 and evo.get(e2, f3) == nil) @@ -928,7 +929,7 @@ do local q = evo.id() evo.set(q, evo.INCLUDES, f1, f2) - assert(evo.batch_assign(q, f1, 60) == 3) + assert(evo.batch_set(q, f1, 60) == 3) assert(entity_sum == e2 + e3 + e4) assert(component_sum == 42 + 44 + 47 + 60 + 60 + 60) @@ -941,7 +942,8 @@ do assert(evo.get(e4, f1) == 60 and evo.get(e4, f3) == 49) assert(evo.get(e5, f1) == nil and evo.get(e5, f3) == 52) - assert(evo.batch_assign(q, f3, 70) == 2) + evo.set(q, evo.INCLUDES, f1, f2, f3) + assert(evo.batch_set(q, f3, 70) == 2) assert(entity_sum == e3 + e4) assert(component_sum == 46 + 49 + 70 + 70) @@ -1318,8 +1320,8 @@ do assert(evo.get(e1, f1) == 11 and evo.get(e1, f2) == nil) assert(evo.get(e2, f1) == 21 and evo.get(e2, f2) == 22) - local q = evo.query():include(f1):build() - assert(evo.batch_insert(q, f2) == 1) + local q = evo.query():include(f1):exclude(f2):build() + assert(evo.batch_set(q, f2) == 1) assert(evo.get(e1, f1) == 11 and evo.get(e1, f2) == 42) assert(evo.get(e2, f1) == 21 and evo.get(e2, f2) == 22) @@ -1346,8 +1348,9 @@ do local q = evo.id() evo.set(q, evo.INCLUDES, f2) + evo.set(q, evo.EXCLUDES, f1) - assert(evo.batch_insert(q, f1, 60) == 1) + assert(evo.batch_set(q, f1, 60) == 1) assert(evo.get(e1, f1) == 41) assert(evo.get(e2, f1) == 42) @@ -1391,10 +1394,11 @@ do local q = evo.id() evo.set(q, evo.INCLUDES, f2) + evo.set(q, evo.EXCLUDES, f1) entity_sum = 0 component_sum = 0 - assert(evo.batch_insert(q, f1, 60) == 1) + assert(evo.batch_set(q, f1, 60) == 1) assert(entity_sum == e4) assert(component_sum == 60) @@ -1403,9 +1407,11 @@ do assert(evo.get(e3, f1) == 44) assert(evo.get(e4, f1) == 60) + evo.set(q, evo.EXCLUDES) + entity_sum = 0 component_sum = 0 - assert(evo.batch_insert(q, f5, 70) == 3) + assert(evo.batch_set(q, f5, 70) == 3) assert(entity_sum == e2 + e3 + e4) assert(component_sum == 70 * 3) end @@ -1823,7 +1829,7 @@ do do local e = evo.id() - assert(evo.batch_assign(q, f1, 50) == 0) + assert(evo.batch_set(q, f1, 50) == 0) assert(not evo.has(e, f1)) assert(evo.get(e, f1) == nil) end @@ -1832,7 +1838,7 @@ do local e = evo.id() assert(evo.set(e, f1, 41)) - assert(evo.batch_assign(q, f1, 50) == 0) + assert(evo.batch_set(q, f1, 50) == 0) assert(evo.has(e, f1)) assert(evo.get(e, f1) == nil) end @@ -1847,13 +1853,15 @@ do assert(evo.set(e2, f2, 42)) assert(evo.set(e2, f3, 43)) - assert(evo.batch_assign(q, f1, 50) == 2) + assert(evo.batch_set(q, f1, 50) == 2) assert(evo.has(e1, f1) and evo.has(e1, f2) and not evo.has(e1, f3)) assert(evo.has(e2, f1) and evo.has(e2, f2) and evo.has(e2, f3)) assert(evo.get(e1, f1) == nil and evo.get(e1, f2) == nil) assert(evo.get(e2, f1) == nil and evo.get(e2, f2) == nil and evo.get(e2, f3) == 43) - assert(evo.batch_assign(q, f3, 51) == 1) + evo.set(q, evo.INCLUDES, f1, f2, f3) + assert(evo.batch_set(q, f3, 51) == 1) + assert(evo.has(e1, f1) and evo.has(e1, f2) and not evo.has(e1, f3)) assert(evo.has(e2, f1) and evo.has(e2, f2) and evo.has(e2, f3)) assert(evo.get(e1, f1) == nil and evo.get(e1, f2) == nil) @@ -1884,7 +1892,8 @@ do assert(evo.set(e3, f2, 42)) assert(evo.set(e3, f3, 43)) - assert(evo.batch_insert(q, f3, 50) == 1) + evo.set(q, evo.EXCLUDES, f3) + assert(evo.batch_set(q, f3, 50) == 1) assert(evo.has(e1, f1) and evo.has(e1, f2) and evo.has(e1, f3)) assert(evo.get(e1, f1) == nil and evo.get(e1, f2) == nil and evo.get(e1, f3) == 50) @@ -2099,7 +2108,7 @@ do assert(evo.defer()) do - local c, d = evo.batch_assign(q, f1, 42) + local c, d = evo.batch_set(q, f1, 42) assert(c == 0 and d == true) end assert(evo.get(e1, f1) == 41) @@ -2112,7 +2121,8 @@ do assert(evo.defer()) do - local c, d = evo.batch_assign(q, f2, 43) + evo.set(q, evo.INCLUDES, f1, f2) + local c, d = evo.batch_set(q, f2, 43) assert(c == 0 and d == true) end assert(evo.get(e1, f2) == nil) @@ -2135,7 +2145,8 @@ do assert(evo.defer()) do - local c, d = evo.batch_insert(q, f1, 42) + evo.set(q, evo.EXCLUDES, f1) + local c, d = evo.batch_set(q, f1, 42) assert(c == 0 and d == true) end assert(evo.get(e1, f1) == 41) @@ -2148,7 +2159,8 @@ do assert(evo.defer()) do - local c, d = evo.batch_insert(q, f2, 43) + evo.set(q, evo.EXCLUDES) + local c, d = evo.batch_set(q, f2, 43) assert(c == 0 and d == true) end assert(evo.get(e1, f2) == nil) @@ -4829,25 +4841,27 @@ do local q = evo.query():include(f1):build() - assert(evo.batch_insert(q, f2) == 2) + assert(evo.set(q, evo.EXCLUDES, f2)) + assert(evo.batch_set(q, f2) == 2) assert(evo.get(e1a, f1) == 11 and evo.get(e1a, f2) == 42) assert(evo.get(e1b, f1) == 11 and evo.get(e1b, f2) == 42) assert(evo.get(e2a, f1) == 11 and evo.get(e2a, f2) == 22) assert(evo.get(e2b, f1) == 11 and evo.get(e2b, f2) == 22) - assert(evo.batch_assign(q, f2) == 4) + assert(evo.set(q, evo.EXCLUDES)) + assert(evo.batch_set(q, f2) == 4) assert(evo.get(e1a, f1) == 11 and evo.get(e1a, f2) == 42) assert(evo.get(e1b, f1) == 11 and evo.get(e1b, f2) == 42) assert(evo.get(e2a, f1) == 11 and evo.get(e2a, f2) == 42) assert(evo.get(e2b, f1) == 11 and evo.get(e2b, f2) == 42) - assert(evo.batch_assign(q, f1) == 4) + assert(evo.batch_set(q, f1) == 4) assert(evo.get(e1a, f1) == true and evo.get(e1a, f2) == 42) assert(evo.get(e1b, f1) == true and evo.get(e1b, f2) == 42) assert(evo.get(e2a, f1) == true and evo.get(e2a, f2) == 42) assert(evo.get(e2b, f1) == true and evo.get(e2b, f2) == 42) - assert(evo.batch_insert(q, f3) == 4) + assert(evo.batch_set(q, f3) == 4) assert(evo.get(e1a, f1) == true and evo.get(e1a, f2) == 42 and evo.get(e1a, f3) == true) assert(evo.get(e1b, f1) == true and evo.get(e1b, f2) == 42 and evo.get(e1b, f3) == true) assert(evo.get(e2a, f1) == true and evo.get(e2a, f2) == 42 and evo.get(e2a, f3) == true) @@ -4874,13 +4888,13 @@ do do local q = evo.query():include(fc):build() - evo.batch_insert(q, evo.ON_ASSIGN, function(e, f, c) + evo.batch_set(q, evo.ON_ASSIGN, function(e, f, c) assert(f == f1 or f == f2 or f == f3 or f == f4) sum_entity = sum_entity + e last_assign_entity = e last_assign_component = c end) - evo.batch_insert(q, evo.ON_INSERT, function(e, f, c) + evo.batch_set(q, evo.ON_INSERT, function(e, f, c) assert(f == f1 or f == f2 or f == f3 or f == f4) sum_entity = sum_entity + e last_insert_entity = e @@ -4895,13 +4909,13 @@ do local e2b = evo.entity():set(f1, 11):set(f2, 22):build() do - local q = evo.query():include(f1):build() + local q = evo.query():include(f1):exclude(f2):build() sum_entity = 0 last_insert_entity = 0 last_insert_component = 0 - assert(evo.batch_insert(q, f2) == 2) + assert(evo.batch_set(q, f2) == 2) assert(evo.get(e1a, f1) == 11 and evo.get(e1a, f2) == 42) assert(evo.get(e1b, f1) == 11 and evo.get(e1b, f2) == 42) assert(evo.get(e2a, f1) == 11 and evo.get(e2a, f2) == 22) @@ -4919,7 +4933,7 @@ do last_insert_entity = 0 last_insert_component = 0 - assert(evo.batch_insert(q, f3) == 4) + assert(evo.batch_set(q, f3) == 4) assert(evo.has_all(e1a, f1, f2, f3) and evo.has_all(e1b, f1, f2, f3)) assert(evo.has_all(e2a, f1, f2, f3) and evo.has_all(e2b, f1, f2, f3)) assert(evo.get(e1a, f1) == 11 and evo.get(e1a, f2) == 42 and evo.get(e1a, f3) == nil) @@ -4935,7 +4949,7 @@ do last_insert_entity = 0 last_insert_component = 0 - assert(evo.batch_insert(q, f4) == 4) + assert(evo.batch_set(q, f4) == 4) assert(evo.has_all(e1a, f1, f2, f3, f4) and evo.has_all(e1b, f1, f2, f3, f4)) assert(evo.has_all(e2a, f1, f2, f3, f4) and evo.has_all(e2b, f1, f2, f3, f4)) assert(evo.get(e1a, f1) == 11 and evo.get(e1a, f2) == 42 and evo.get(e1a, f3) == nil and evo.get(e1a, f4) == true) @@ -4951,7 +4965,7 @@ do last_assign_entity = 0 last_assign_component = 0 - assert(evo.batch_assign(q, f2) == 4) + assert(evo.batch_set(q, f2) == 4) assert(sum_entity == e1a + e1b + e2a + e2b) assert(last_assign_entity == e1b) assert(last_assign_component == 42) @@ -4960,7 +4974,7 @@ do last_assign_entity = 0 last_assign_component = 0 - assert(evo.batch_assign(q, f1) == 4) + assert(evo.batch_set(q, f1) == 4) assert(sum_entity == e1a + e1b + e2a + e2b) assert(last_assign_entity == e1b) assert(last_assign_component == true) @@ -5530,24 +5544,24 @@ do local e1 = evo.entity():set(fa):build() local e2 = evo.entity():set(fa):build() assert(evo.defer()) - evo.batch_insert(q0, f0) + evo.batch_set(q0, f0) assert(evo.commit()) assert(evo.get(e1, f0) == 42) assert(evo.get(e2, f0) == 42) assert(evo.defer()) - evo.batch_insert(q0, f1, 1) + evo.batch_set(q0, f1, 1) assert(evo.commit()) assert(evo.get(e1, f1) == 1) assert(evo.get(e2, f1) == 1) assert(evo.defer()) - evo.batch_insert(q0, f2, 1, 2) + evo.batch_set(q0, f2, 1, 2) assert(evo.commit()) assert(evo.get(e1, f1) == 1) assert(evo.get(e1, f2) == 1 + 2) assert(evo.get(e2, f1) == 1) assert(evo.get(e2, f2) == 1 + 2) assert(evo.defer()) - evo.batch_insert(q0, f3, 1, 2, 3) + evo.batch_set(q0, f3, 1, 2, 3) assert(evo.commit()) assert(evo.get(e1, f1) == 1) assert(evo.get(e1, f2) == 1 + 2) @@ -5556,7 +5570,7 @@ do assert(evo.get(e2, f2) == 1 + 2) assert(evo.get(e2, f3) == 1 + 2 + 3) assert(evo.defer()) - evo.batch_insert(q0, f4, 1, 2, 3, 4) + evo.batch_set(q0, f4, 1, 2, 3, 4) assert(evo.commit()) assert(evo.get(e1, f1) == 1) assert(evo.get(e1, f2) == 1 + 2) @@ -5567,7 +5581,7 @@ do assert(evo.get(e2, f3) == 1 + 2 + 3) assert(evo.get(e2, f4) == 1 + 2 + 3 + 4) assert(evo.defer()) - evo.batch_insert(q0, f5, 1, 2, 3, 4, 5) + evo.batch_set(q0, f5, 1, 2, 3, 4, 5) assert(evo.commit()) assert(evo.get(e1, f1) == 1) assert(evo.get(e1, f2) == 1 + 2) @@ -5584,22 +5598,22 @@ do local e1 = evo.entity():set(fa):build() local e2 = evo.entity():set(fa):build() assert(evo.defer()) - evo.batch_insert(q0, f0, 0) - evo.batch_assign(q0, f0) + evo.batch_set(q0, f0, 0) + evo.batch_set(q0, f0) assert(evo.commit()) assert(evo.get(e1, f0) == 42) assert(evo.get(e2, f0) == 42) assert(evo.defer()) - evo.batch_insert(q0, f1, 0) - evo.batch_assign(q0, f1, 1) + evo.batch_set(q0, f1, 0) + evo.batch_set(q0, f1, 1) assert(evo.commit()) assert(evo.get(e1, f0) == 42) assert(evo.get(e2, f0) == 42) assert(evo.get(e1, f1) == 1) assert(evo.get(e2, f1) == 1) assert(evo.defer()) - evo.batch_insert(q0, f2, 0, 0) - evo.batch_assign(q0, f2, 1, 2) + evo.batch_set(q0, f2, 0, 0) + evo.batch_set(q0, f2, 1, 2) assert(evo.commit()) assert(evo.get(e1, f0) == 42) assert(evo.get(e2, f0) == 42) @@ -5608,8 +5622,8 @@ do assert(evo.get(e2, f1) == 1) assert(evo.get(e2, f2) == 1 + 2) assert(evo.defer()) - evo.batch_insert(q0, f3, 0, 0, 0) - evo.batch_assign(q0, f3, 1, 2, 3) + evo.batch_set(q0, f3, 0, 0, 0) + evo.batch_set(q0, f3, 1, 2, 3) assert(evo.commit()) assert(evo.get(e1, f0) == 42) assert(evo.get(e2, f0) == 42) @@ -5620,8 +5634,8 @@ do assert(evo.get(e2, f2) == 1 + 2) assert(evo.get(e2, f3) == 1 + 2 + 3) assert(evo.defer()) - evo.batch_insert(q0, f4, 0, 0, 0, 0) - evo.batch_assign(q0, f4, 1, 2, 3, 4) + evo.batch_set(q0, f4, 0, 0, 0, 0) + evo.batch_set(q0, f4, 1, 2, 3, 4) assert(evo.commit()) assert(evo.get(e1, f0) == 42) assert(evo.get(e2, f0) == 42) @@ -6083,23 +6097,23 @@ do assert(evo.set(e1, f0) and evo.set(e2, f0)) - assert(evo.batch_insert(q0, f1, 41)) + assert(evo.batch_set(q0, f1, 41)) assert(assign_count == 0 and insert_count == 2 and remove_count == 0) - assert(evo.batch_assign(q0, f1, 51)) + assert(evo.batch_set(q0, f1, 51)) assert(assign_count == 2 and insert_count == 2 and remove_count == 0) assert(evo.batch_remove(q0, f1)) assert(assign_count == 2 and insert_count == 2 and remove_count == 2) - assert(evo.batch_insert(q0, f1, 51)) + assert(evo.batch_set(q0, f1, 51)) assert(assign_count == 2 and insert_count == 4 and remove_count == 2) assert(evo.batch_clear(q0)) assert(assign_count == 2 and insert_count == 4 and remove_count == 4) assert(evo.set(e1, f0) and evo.set(e2, f0)) - assert(evo.batch_insert(q0, f1, 51)) + assert(evo.batch_set(q0, f1, 51)) assert(assign_count == 2 and insert_count == 6 and remove_count == 4) assert(evo.batch_destroy(q0)) @@ -6387,7 +6401,7 @@ do assert(evo.components(c1, f1)[1] == 1 and evo.components(c1, f1)[2] == 11) end - assert(evo.batch_insert(q1, f2, 2) == 2) + assert(evo.batch_set(q1, f2, 2) == 2) do local c1, c1_es = evo.chunk(f1) @@ -6410,7 +6424,8 @@ do assert(evo.components(c1, f1)[1] == 111 and evo.components(c1, f1)[2] == 1111) end - assert(evo.batch_insert(q1, f2, 22) == 2) + assert(evo.set(q1, evo.EXCLUDES, f2)) + assert(evo.batch_set(q1, f2, 22) == 2) do local c1, c1_es = evo.chunk(f1) @@ -7947,7 +7962,7 @@ do assert(evo.get(e12a, f2) == 7 and evo.get(e12b, f2) == 7) end - assert(4 == evo.batch_assign(c12, f2, 8)) + assert(4 == evo.batch_set(c12, f2, 8)) do local c12_es, c12_ec = evo.entities(c12) @@ -7967,7 +7982,7 @@ do assert(evo.get(e12a, f1) == 3 and evo.get(e12b, f1) == 5) end - assert(4 == evo.batch_insert(c1, f2, 9)) + assert(4 == evo.batch_set(c1, f2, 9)) do local c12_es, c12_ec = evo.entities(c12) From 0b3e9fdc480ef4fbdb7decf68a0dd9c5fe988003 Mon Sep 17 00:00:00 2001 From: BlackMATov Date: Thu, 20 Mar 2025 05:35:39 +0700 Subject: [PATCH 07/12] merge chunk_assign and chunk_insert --- evolved.lua | 473 ++++++++++++++++++++++++---------------------------- 1 file changed, 216 insertions(+), 257 deletions(-) diff --git a/evolved.lua b/evolved.lua index 63da514..f9f3fa1 100644 --- a/evolved.lua +++ b/evolved.lua @@ -1829,8 +1829,6 @@ end --- local __chunk_set -local __chunk_assign -local __chunk_insert local __chunk_remove local __chunk_clear local __chunk_destroy @@ -1935,164 +1933,19 @@ end --- --- ----@param chunk evolved.chunk +---@param old_chunk evolved.chunk ---@param fragment evolved.fragment ---@param ... any component arguments ---@return integer set_count ---@nodiscard -__chunk_set = function(chunk, fragment, ...) - if __defer_depth <= 0 then - __error_fmt('batched chunk operations should be deferred') - end - - if chunk.__fragment_set[fragment] then - return __chunk_assign(chunk, fragment, ...) - else - return __chunk_insert(chunk, fragment, ...) - end -end - ----@param chunk evolved.chunk ----@param fragment evolved.fragment ----@param ... any component arguments ----@return integer assigned_count ----@nodiscard -__chunk_assign = function(chunk, fragment, ...) - if __defer_depth <= 0 then - __error_fmt('batched chunk operations should be deferred') - end - - if not chunk.__fragment_set[fragment] then - return 0 - end - - local chunk_entity_list = chunk.__entity_list - local chunk_entity_count = chunk.__entity_count - - if chunk_entity_count == 0 then - return 0 - end - - local chunk_component_indices = chunk.__component_indices - local chunk_component_storages = chunk.__component_storages - - ---@type evolved.default?, evolved.construct? - local fragment_default, fragment_construct - - ---@type evolved.set_hook?, evolved.assign_hook? - local fragment_on_set, fragment_on_assign - - do - if chunk.__has_defaults_or_constructs then - fragment_default, fragment_construct = __evolved_get(fragment, __DEFAULT, __CONSTRUCT) - end - - if chunk.__has_set_or_assign_hooks then - fragment_on_set, fragment_on_assign = __evolved_get(fragment, __ON_SET, __ON_ASSIGN) - end - end - - if fragment_on_set or fragment_on_assign then - local component_index = chunk_component_indices[fragment] - - if component_index then - local component_storage = chunk_component_storages[component_index] - - if fragment_default ~= nil or fragment_construct then - for place = 1, chunk_entity_count do - local entity = chunk_entity_list[place] - local old_component = component_storage[place] - - local new_component = ... - if fragment_construct then new_component = fragment_construct(...) end - if new_component == nil then new_component = fragment_default end - if new_component == nil then new_component = true end - - component_storage[place] = new_component - - if fragment_on_set then - __defer_call_hook(fragment_on_set, entity, fragment, new_component, old_component) - end - - if fragment_on_assign then - __defer_call_hook(fragment_on_assign, entity, fragment, new_component, old_component) - end - end - else - local new_component = ... - if new_component == nil then new_component = true end - - for place = 1, chunk_entity_count do - local entity = chunk_entity_list[place] - local old_component = component_storage[place] - - component_storage[place] = new_component - - if fragment_on_set then - __defer_call_hook(fragment_on_set, entity, fragment, new_component, old_component) - end - - if fragment_on_assign then - __defer_call_hook(fragment_on_assign, entity, fragment, new_component, old_component) - end - end - end - else - for place = 1, chunk_entity_count do - local entity = chunk_entity_list[place] - - if fragment_on_set then - __defer_call_hook(fragment_on_set, entity, fragment) - end - - if fragment_on_assign then - __defer_call_hook(fragment_on_assign, entity, fragment) - end - end - end - else - local component_index = chunk_component_indices[fragment] - - if component_index then - local component_storage = chunk_component_storages[component_index] - - if fragment_default ~= nil or fragment_construct then - for place = 1, chunk_entity_count do - local new_component = ... - if fragment_construct then new_component = fragment_construct(...) end - if new_component == nil then new_component = fragment_default end - if new_component == nil then new_component = true end - component_storage[place] = new_component - end - else - local new_component = ... - if new_component == nil then new_component = true end - - for place = 1, chunk_entity_count do - component_storage[place] = new_component - end - end - else - -- nothing - end - end - - return chunk_entity_count -end - ----@param old_chunk evolved.chunk ----@param fragment evolved.fragment ----@param ... any component arguments ----@return integer inserted_count ----@nodiscard -__chunk_insert = function(old_chunk, fragment, ...) +__chunk_set = function(old_chunk, fragment, ...) if __defer_depth <= 0 then __error_fmt('batched chunk operations should be deferred') end local new_chunk = __chunk_with_fragment(old_chunk, fragment) - if not new_chunk or old_chunk == new_chunk then + if not new_chunk then return 0 end @@ -2104,160 +1957,265 @@ __chunk_insert = function(old_chunk, fragment, ...) end local old_component_count = old_chunk.__component_count + local old_component_indices = old_chunk.__component_indices local old_component_storages = old_chunk.__component_storages local old_component_fragments = old_chunk.__component_fragments - local new_entity_list = new_chunk.__entity_list - local new_entity_count = new_chunk.__entity_count + if old_chunk == new_chunk then + ---@type evolved.default?, evolved.construct? + local fragment_default, fragment_construct - local new_component_indices = new_chunk.__component_indices - local new_component_storages = new_chunk.__component_storages + ---@type evolved.set_hook?, evolved.assign_hook? + local fragment_on_set, fragment_on_assign - ---@type evolved.default?, evolved.construct? - local fragment_default, fragment_construct + do + if old_chunk.__has_defaults_or_constructs then + fragment_default, fragment_construct = __evolved_get(fragment, __DEFAULT, __CONSTRUCT) + end - ---@type evolved.set_hook?, evolved.insert_hook? - local fragment_on_set, fragment_on_insert - - do - if new_chunk.__has_defaults_or_constructs then - fragment_default, fragment_construct = __evolved_get(fragment, __DEFAULT, __CONSTRUCT) + if old_chunk.__has_set_or_assign_hooks then + fragment_on_set, fragment_on_assign = __evolved_get(fragment, __ON_SET, __ON_ASSIGN) + end end - if new_chunk.__has_set_or_insert_hooks then - fragment_on_set, fragment_on_insert = __evolved_get(fragment, __ON_SET, __ON_INSERT) - end - end + if fragment_on_set or fragment_on_assign then + local old_component_index = old_component_indices[fragment] - if new_entity_count == 0 then - old_chunk.__entity_list, new_chunk.__entity_list = - new_entity_list, old_entity_list + if old_component_index then + local old_component_storage = old_component_storages[old_component_index] - old_entity_list, new_entity_list = - new_entity_list, old_entity_list + if fragment_default ~= nil or fragment_construct then + for place = 1, old_entity_count do + local entity = old_entity_list[place] + local old_component = old_component_storage[place] - for old_ci = 1, old_component_count do - local old_f = old_component_fragments[old_ci] - local new_ci = new_component_indices[old_f] - old_component_storages[old_ci], new_component_storages[new_ci] = - new_component_storages[new_ci], old_component_storages[old_ci] - end + local new_component = ... + if fragment_construct then new_component = fragment_construct(...) end + if new_component == nil then new_component = fragment_default end + if new_component == nil then new_component = true end - new_chunk.__entity_count = old_entity_count - else - __lua_table_move( - old_entity_list, 1, old_entity_count, - new_entity_count + 1, new_entity_list) + old_component_storage[place] = new_component - for old_ci = 1, old_component_count do - local old_f = old_component_fragments[old_ci] - local old_cs = old_component_storages[old_ci] - local new_ci = new_component_indices[old_f] - local new_cs = new_component_storages[new_ci] - __lua_table_move(old_cs, 1, old_entity_count, new_entity_count + 1, new_cs) - end - - new_chunk.__entity_count = new_entity_count + old_entity_count - end - - do - local entity_chunks = __entity_chunks - local entity_places = __entity_places - - for new_place = new_entity_count + 1, new_entity_count + old_entity_count do - local entity = new_entity_list[new_place] - local entity_index = entity % 0x100000 - entity_chunks[entity_index] = new_chunk - entity_places[entity_index] = new_place - end - - __detach_all_entities(old_chunk) - end - - if fragment_on_set or fragment_on_insert then - local new_component_index = new_component_indices[fragment] - - if new_component_index then - local new_component_storage = new_component_storages[new_component_index] - - 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_entity_list[new_place] + if fragment_on_set then + __defer_call_hook(fragment_on_set, entity, fragment, new_component, old_component) + end + if fragment_on_assign then + __defer_call_hook(fragment_on_assign, entity, fragment, new_component, old_component) + end + end + else local new_component = ... - if fragment_construct then new_component = fragment_construct(...) end - if new_component == nil then new_component = fragment_default end if new_component == nil then new_component = true end - new_component_storage[new_place] = new_component + for place = 1, old_entity_count do + local entity = old_entity_list[place] + local old_component = old_component_storage[place] - if fragment_on_set then - __defer_call_hook(fragment_on_set, entity, fragment, new_component) - end + old_component_storage[place] = new_component - if fragment_on_insert then - __defer_call_hook(fragment_on_insert, entity, fragment, new_component) + if fragment_on_set then + __defer_call_hook(fragment_on_set, entity, fragment, new_component, old_component) + end + + if fragment_on_assign then + __defer_call_hook(fragment_on_assign, entity, fragment, new_component, old_component) + end end end else - local new_component = ... - 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_entity_list[new_place] - - new_component_storage[new_place] = new_component + for place = 1, old_entity_count do + local entity = old_entity_list[place] if fragment_on_set then - __defer_call_hook(fragment_on_set, entity, fragment, new_component) + __defer_call_hook(fragment_on_set, entity, fragment) end - if fragment_on_insert then - __defer_call_hook(fragment_on_insert, entity, fragment, new_component) + if fragment_on_assign then + __defer_call_hook(fragment_on_assign, entity, fragment) end end end else + local old_component_index = old_component_indices[fragment] + + if old_component_index then + local old_component_storage = old_component_storages[old_component_index] + + if fragment_default ~= nil or fragment_construct then + for place = 1, old_entity_count do + local new_component = ... + if fragment_construct then new_component = fragment_construct(...) end + if new_component == nil then new_component = fragment_default end + if new_component == nil then new_component = true end + old_component_storage[place] = new_component + end + else + local new_component = ... + if new_component == nil then new_component = true end + + for place = 1, old_entity_count do + old_component_storage[place] = new_component + end + end + else + -- nothing + end + end + else + local new_entity_list = new_chunk.__entity_list + local new_entity_count = new_chunk.__entity_count + + local new_component_indices = new_chunk.__component_indices + local new_component_storages = new_chunk.__component_storages + + ---@type evolved.default?, evolved.construct? + local fragment_default, fragment_construct + + ---@type evolved.set_hook?, evolved.insert_hook? + local fragment_on_set, fragment_on_insert + + do + if new_chunk.__has_defaults_or_constructs then + fragment_default, fragment_construct = __evolved_get(fragment, __DEFAULT, __CONSTRUCT) + end + + if new_chunk.__has_set_or_insert_hooks then + fragment_on_set, fragment_on_insert = __evolved_get(fragment, __ON_SET, __ON_INSERT) + end + end + + if new_entity_count == 0 then + old_chunk.__entity_list, new_chunk.__entity_list = + new_entity_list, old_entity_list + + 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] + local new_ci = new_component_indices[old_f] + old_component_storages[old_ci], new_component_storages[new_ci] = + new_component_storages[new_ci], old_component_storages[old_ci] + end + + new_chunk.__entity_count = old_entity_count + else + __lua_table_move( + 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] + local old_cs = old_component_storages[old_ci] + local new_ci = new_component_indices[old_f] + local new_cs = new_component_storages[new_ci] + __lua_table_move(old_cs, 1, old_entity_count, new_entity_count + 1, new_cs) + end + + new_chunk.__entity_count = new_entity_count + old_entity_count + end + + do + local entity_chunks = __entity_chunks + local entity_places = __entity_places + for new_place = new_entity_count + 1, new_entity_count + old_entity_count do local entity = new_entity_list[new_place] - - if fragment_on_set then - __defer_call_hook(fragment_on_set, entity, fragment) - end - - if fragment_on_insert then - __defer_call_hook(fragment_on_insert, entity, fragment) - end + local entity_index = entity % 0x100000 + entity_chunks[entity_index] = new_chunk + entity_places[entity_index] = new_place end + + __detach_all_entities(old_chunk) end - else - local new_component_index = new_component_indices[fragment] - if new_component_index then - local new_component_storage = new_component_storages[new_component_index] + if fragment_on_set or fragment_on_insert then + local new_component_index = new_component_indices[fragment] - if fragment_default ~= nil or fragment_construct then - for new_place = new_entity_count + 1, new_entity_count + old_entity_count do + if new_component_index then + local new_component_storage = new_component_storages[new_component_index] + + 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_entity_list[new_place] + + local new_component = ... + if fragment_construct then new_component = fragment_construct(...) end + if new_component == nil then new_component = fragment_default end + if new_component == nil then new_component = true end + + new_component_storage[new_place] = new_component + + if fragment_on_set then + __defer_call_hook(fragment_on_set, entity, fragment, new_component) + end + + if fragment_on_insert then + __defer_call_hook(fragment_on_insert, entity, fragment, new_component) + end + end + else local new_component = ... - if fragment_construct then new_component = fragment_construct(...) end - if new_component == nil then new_component = fragment_default end if new_component == nil then new_component = true end - new_component_storage[new_place] = new_component + + for new_place = new_entity_count + 1, new_entity_count + old_entity_count do + local entity = new_entity_list[new_place] + + new_component_storage[new_place] = new_component + + if fragment_on_set then + __defer_call_hook(fragment_on_set, entity, fragment, new_component) + end + + if fragment_on_insert then + __defer_call_hook(fragment_on_insert, entity, fragment, new_component) + end + end end else - local new_component = ... - if new_component == nil then new_component = true end - for new_place = new_entity_count + 1, new_entity_count + old_entity_count do - new_component_storage[new_place] = new_component + local entity = new_entity_list[new_place] + + if fragment_on_set then + __defer_call_hook(fragment_on_set, entity, fragment) + end + + if fragment_on_insert then + __defer_call_hook(fragment_on_insert, entity, fragment) + end end end else - -- nothing + local new_component_index = new_component_indices[fragment] + + if new_component_index then + local new_component_storage = new_component_storages[new_component_index] + + if fragment_default ~= nil or fragment_construct then + for new_place = new_entity_count + 1, new_entity_count + old_entity_count do + local new_component = ... + if fragment_construct then new_component = fragment_construct(...) end + if new_component == nil then new_component = fragment_default end + if new_component == nil then new_component = true end + new_component_storage[new_place] = new_component + end + else + local new_component = ... + if new_component == nil then new_component = true end + + for new_place = new_entity_count + 1, new_entity_count + old_entity_count do + new_component_storage[new_place] = new_component + end + end + else + -- nothing + end end + + __structural_changes = __structural_changes + 1 end - __structural_changes = __structural_changes + 1 return old_entity_count end @@ -2755,6 +2713,7 @@ __chunk_multi_set = function(old_chunk, fragments, fragment_count, components) if fragment_on_set or fragment_on_assign then local new_component_index = new_component_indices[fragment] + if new_component_index then local new_component_storage = new_component_storages[new_component_index] From 1b87f7d6baf28d63825cab571de63dfb115468f4 Mon Sep 17 00:00:00 2001 From: BlackMATov Date: Thu, 20 Mar 2025 05:42:40 +0700 Subject: [PATCH 08/12] restore defer_op indices --- evolved.lua | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/evolved.lua b/evolved.lua index f9f3fa1..74b9e96 100644 --- a/evolved.lua +++ b/evolved.lua @@ -3152,27 +3152,27 @@ end ---@enum evolved.defer_op local __defer_op = { set = 1, - remove = 4, - clear = 5, - destroy = 6, + remove = 2, + clear = 3, + destroy = 4, - multi_set = 7, - multi_remove = 10, + multi_set = 5, + multi_remove = 6, - batch_set = 11, - batch_remove = 14, - batch_clear = 15, - batch_destroy = 16, + batch_set = 7, + batch_remove = 8, + batch_clear = 9, + batch_destroy = 10, - batch_multi_set = 17, - batch_multi_remove = 20, + batch_multi_set = 11, + batch_multi_remove = 12, - spawn_entity_at = 21, - spawn_entity_with = 22, + spawn_entity_at = 13, + spawn_entity_with = 14, - call_hook = 23, + call_hook = 15, - __count = 23, + __count = 15, } ---@type table From e951f215b1502b877a4fd748d7ddd453b4fab804 Mon Sep 17 00:00:00 2001 From: BlackMATov Date: Thu, 20 Mar 2025 05:46:07 +0700 Subject: [PATCH 09/12] restore benchmarks --- develop/all.lua | 4 +-- develop/unbench.lua | 80 ++++++++++++++++++++++----------------------- 2 files changed, 42 insertions(+), 42 deletions(-) diff --git a/develop/all.lua b/develop/all.lua index 7d7536f..49a0913 100644 --- a/develop/all.lua +++ b/develop/all.lua @@ -1,4 +1,4 @@ require 'develop.example' --- require 'develop.unbench' +require 'develop.unbench' require 'develop.untests' --- require 'develop.usbench' +require 'develop.usbench' diff --git a/develop/unbench.lua b/develop/unbench.lua index 8266781..1a97149 100644 --- a/develop/unbench.lua +++ b/develop/unbench.lua @@ -236,11 +236,11 @@ basics.describe_bench(string.format('create and destroy %d entities with 1 compo ---@param entities evolved.id[] function(entities) local id = evo.id - local insert = evo.insert + local set = evo.set for i = 1, N do local e = id() - insert(e, F1) + set(e, F1) entities[i] = e end @@ -253,12 +253,12 @@ basics.describe_bench(string.format('create and destroy %d entities with 2 compo ---@param entities evolved.id[] function(entities) local id = evo.id - local insert = evo.insert + local set = evo.set for i = 1, N do local e = id() - insert(e, F1) - insert(e, F2) + set(e, F1) + set(e, F2) entities[i] = e end @@ -271,13 +271,13 @@ basics.describe_bench(string.format('create and destroy %d entities with 3 compo ---@param entities evolved.id[] function(entities) local id = evo.id - local insert = evo.insert + local set = evo.set for i = 1, N do local e = id() - insert(e, F1) - insert(e, F2) - insert(e, F3) + set(e, F1) + set(e, F2) + set(e, F3) entities[i] = e end @@ -290,14 +290,14 @@ basics.describe_bench(string.format('create and destroy %d entities with 4 compo ---@param entities evolved.id[] function(entities) local id = evo.id - local insert = evo.insert + local set = evo.set for i = 1, N do local e = id() - insert(e, F1) - insert(e, F2) - insert(e, F3) - insert(e, F4) + set(e, F1) + set(e, F2) + set(e, F3) + set(e, F4) entities[i] = e end @@ -310,15 +310,15 @@ basics.describe_bench(string.format('create and destroy %d entities with 5 compo ---@param entities evolved.id[] function(entities) local id = evo.id - local insert = evo.insert + local set = evo.set for i = 1, N do local e = id() - insert(e, F1) - insert(e, F2) - insert(e, F3) - insert(e, F4) - insert(e, F5) + set(e, F1) + set(e, F2) + set(e, F3) + set(e, F4) + set(e, F5) entities[i] = e end @@ -333,12 +333,12 @@ basics.describe_bench(string.format('create and destroy %d entities with 1 compo ---@param entities evolved.id[] function(entities) local id = evo.id - local insert = evo.insert + local set = evo.set evo.defer() for i = 1, N do local e = id() - insert(e, F1) + set(e, F1) entities[i] = e end evo.commit() @@ -352,13 +352,13 @@ basics.describe_bench(string.format('create and destroy %d entities with 2 compo ---@param entities evolved.id[] function(entities) local id = evo.id - local insert = evo.insert + local set = evo.set evo.defer() for i = 1, N do local e = id() - insert(e, F1) - insert(e, F2) + set(e, F1) + set(e, F2) entities[i] = e end evo.commit() @@ -372,14 +372,14 @@ basics.describe_bench(string.format('create and destroy %d entities with 3 compo ---@param entities evolved.id[] function(entities) local id = evo.id - local insert = evo.insert + local set = evo.set evo.defer() for i = 1, N do local e = id() - insert(e, F1) - insert(e, F2) - insert(e, F3) + set(e, F1) + set(e, F2) + set(e, F3) entities[i] = e end evo.commit() @@ -393,15 +393,15 @@ basics.describe_bench(string.format('create and destroy %d entities with 4 compo ---@param entities evolved.id[] function(entities) local id = evo.id - local insert = evo.insert + local set = evo.set evo.defer() for i = 1, N do local e = id() - insert(e, F1) - insert(e, F2) - insert(e, F3) - insert(e, F4) + set(e, F1) + set(e, F2) + set(e, F3) + set(e, F4) entities[i] = e end evo.commit() @@ -415,16 +415,16 @@ basics.describe_bench(string.format('create and destroy %d entities with 5 compo ---@param entities evolved.id[] function(entities) local id = evo.id - local insert = evo.insert + local set = evo.set evo.defer() for i = 1, N do local e = id() - insert(e, F1) - insert(e, F2) - insert(e, F3) - insert(e, F4) - insert(e, F5) + set(e, F1) + set(e, F2) + set(e, F3) + set(e, F4) + set(e, F5) entities[i] = e end evo.commit() From 50541e83f4ef210f07d7e76e3b8cbb24f6b2bd99 Mon Sep 17 00:00:00 2001 From: BlackMATov Date: Thu, 20 Mar 2025 05:49:09 +0700 Subject: [PATCH 10/12] update roadmap --- ROADMAP.md | 1 + 1 file changed, 1 insertion(+) diff --git a/ROADMAP.md b/ROADMAP.md index c3b68d7..b70e6c1 100644 --- a/ROADMAP.md +++ b/ROADMAP.md @@ -4,6 +4,7 @@ - validate operation sources in the debug mode - should set/assign/insert return a constructed component? +- can we pass systems and groups to the process function? ## After first release From 40b66038207c93674013463bbf668d9298118b72 Mon Sep 17 00:00:00 2001 From: BlackMATov Date: Thu, 20 Mar 2025 06:34:53 +0700 Subject: [PATCH 11/12] little optimization of evolved.set --- evolved.lua | 24 ++++++++++++++++-------- 1 file changed, 16 insertions(+), 8 deletions(-) diff --git a/evolved.lua b/evolved.lua index 74b9e96..b00b666 100644 --- a/evolved.lua +++ b/evolved.lua @@ -4485,17 +4485,17 @@ __evolved_set = function(entity, fragment, ...) local new_chunk = __chunk_with_fragment(old_chunk, fragment) - ---@type evolved.set_hook?, evolved.assign_hook?, evolved.insert_hook? - local fragment_on_set, fragment_on_assign, fragment_on_insert - - if new_chunk.__has_set_or_assign_hooks or new_chunk.__has_set_or_insert_hooks then - fragment_on_set, fragment_on_assign, fragment_on_insert = __evolved_get(fragment, - __ON_SET, __ON_ASSIGN, __ON_INSERT) - end - __evolved_defer() if old_chunk == new_chunk then + ---@type evolved.set_hook?, evolved.assign_hook? + local fragment_on_set, fragment_on_assign + + if old_chunk.__has_set_or_assign_hooks then + fragment_on_set, fragment_on_assign = __evolved_get(fragment, + __ON_SET, __ON_ASSIGN) + end + local old_component_indices = old_chunk.__component_indices local old_component_storages = old_chunk.__component_storages @@ -4555,6 +4555,14 @@ __evolved_set = function(entity, fragment, ...) end end else + ---@type evolved.set_hook?, evolved.insert_hook? + local fragment_on_set, fragment_on_insert + + if new_chunk.__has_set_or_insert_hooks then + fragment_on_set, fragment_on_insert = __evolved_get(fragment, + __ON_SET, __ON_INSERT) + end + local new_entity_list = new_chunk.__entity_list local new_entity_count = new_chunk.__entity_count From 9b228df7eac9ff8aa67d2121d092f0c8ca6064f0 Mon Sep 17 00:00:00 2001 From: BlackMATov Date: Thu, 20 Mar 2025 23:06:12 +0700 Subject: [PATCH 12/12] little operations cleanup --- evolved.lua | 108 ++++++++++++++++++---------------------------------- 1 file changed, 36 insertions(+), 72 deletions(-) diff --git a/evolved.lua b/evolved.lua index b00b666..2e3c9b9 100644 --- a/evolved.lua +++ b/evolved.lua @@ -1962,20 +1962,15 @@ __chunk_set = function(old_chunk, fragment, ...) local old_component_fragments = old_chunk.__component_fragments if old_chunk == new_chunk then - ---@type evolved.default?, evolved.construct? - local fragment_default, fragment_construct + local old_chunk_has_defaults_or_constructs = old_chunk.__has_defaults_or_constructs + local old_chunk_has_set_or_assign_hooks = old_chunk.__has_set_or_assign_hooks - ---@type evolved.set_hook?, evolved.assign_hook? - local fragment_on_set, fragment_on_assign + ---@type evolved.default?, evolved.construct?, evolved.set_hook?, evolved.assign_hook? + local fragment_default, fragment_construct, fragment_on_set, fragment_on_assign - do - if old_chunk.__has_defaults_or_constructs then - fragment_default, fragment_construct = __evolved_get(fragment, __DEFAULT, __CONSTRUCT) - end - - if old_chunk.__has_set_or_assign_hooks then - fragment_on_set, fragment_on_assign = __evolved_get(fragment, __ON_SET, __ON_ASSIGN) - end + if old_chunk_has_defaults_or_constructs or old_chunk_has_set_or_assign_hooks then + fragment_default, fragment_construct, fragment_on_set, fragment_on_assign = __evolved_get(fragment, + __DEFAULT, __CONSTRUCT, __ON_SET, __ON_ASSIGN) end if fragment_on_set or fragment_on_assign then @@ -2069,20 +2064,15 @@ __chunk_set = function(old_chunk, fragment, ...) local new_component_indices = new_chunk.__component_indices local new_component_storages = new_chunk.__component_storages - ---@type evolved.default?, evolved.construct? - local fragment_default, fragment_construct + local new_chunk_has_defaults_or_constructs = new_chunk.__has_defaults_or_constructs + local new_chunk_has_set_or_insert_hooks = new_chunk.__has_set_or_insert_hooks - ---@type evolved.set_hook?, evolved.insert_hook? - local fragment_on_set, fragment_on_insert + ---@type evolved.default?, evolved.construct?, evolved.set_hook?, evolved.insert_hook? + local fragment_default, fragment_construct, fragment_on_set, fragment_on_insert - do - if new_chunk.__has_defaults_or_constructs then - fragment_default, fragment_construct = __evolved_get(fragment, __DEFAULT, __CONSTRUCT) - end - - if new_chunk.__has_set_or_insert_hooks then - fragment_on_set, fragment_on_insert = __evolved_get(fragment, __ON_SET, __ON_INSERT) - end + if new_chunk_has_defaults_or_constructs or new_chunk_has_set_or_insert_hooks then + fragment_default, fragment_construct, fragment_on_set, fragment_on_insert = __evolved_get(fragment, + __DEFAULT, __CONSTRUCT, __ON_SET, __ON_INSERT) end if new_entity_count == 0 then @@ -2374,12 +2364,11 @@ __chunk_clear = function(chunk) return 0 end - local chunk_component_indices = chunk.__component_indices - local chunk_component_storages = chunk.__component_storages - if chunk.__has_remove_hooks then local chunk_fragment_list = chunk.__fragment_list local chunk_fragment_count = chunk.__fragment_count + local chunk_component_indices = chunk.__component_indices + local chunk_component_storages = chunk.__component_storages for chunk_fragment_index = 1, chunk_fragment_count do local fragment = chunk_fragment_list[chunk_fragment_index] @@ -2441,12 +2430,11 @@ __chunk_destroy = function(chunk) return 0 end - local chunk_component_indices = chunk.__component_indices - local chunk_component_storages = chunk.__component_storages - if chunk.__has_remove_hooks then local chunk_fragment_list = chunk.__fragment_list local chunk_fragment_count = chunk.__fragment_count + local chunk_component_indices = chunk.__component_indices + local chunk_component_storages = chunk.__component_storages for chunk_fragment_index = 1, chunk_fragment_count do local fragment = chunk_fragment_list[chunk_fragment_index] @@ -2554,27 +2542,19 @@ __chunk_multi_set = function(old_chunk, fragments, fragment_count, components) local old_component_storages = old_chunk.__component_storages local old_component_fragments = old_chunk.__component_fragments - local old_chunk_has_defaults_or_constructs = old_chunk.__has_defaults_or_constructs - local old_chunk_has_set_or_assign_hooks = old_chunk.__has_set_or_assign_hooks - if old_chunk == new_chunk then + local old_chunk_has_defaults_or_constructs = old_chunk.__has_defaults_or_constructs + local old_chunk_has_set_or_assign_hooks = old_chunk.__has_set_or_assign_hooks + for i = 1, fragment_count do local fragment = fragments[i] - ---@type evolved.default? - local fragment_default + ---@type evolved.default?, evolved.set_hook?, evolved.assign_hook? + local fragment_default, fragment_on_set, fragment_on_assign - ---@type evolved.set_hook?, evolved.assign_hook? - local fragment_on_set, fragment_on_assign - - do - if old_chunk_has_defaults_or_constructs then - fragment_default = __evolved_get(fragment, __DEFAULT) - end - - if old_chunk_has_set_or_assign_hooks then - fragment_on_set, fragment_on_assign = __evolved_get(fragment, __ON_SET, __ON_ASSIGN) - end + if old_chunk_has_defaults_or_constructs or old_chunk_has_set_or_assign_hooks then + fragment_default, fragment_on_set, fragment_on_assign = __evolved_get(fragment, + __DEFAULT, __ON_SET, __ON_ASSIGN) end if fragment_on_set or fragment_on_assign then @@ -2695,20 +2675,12 @@ __chunk_multi_set = function(old_chunk, fragments, fragment_count, components) local fragment = fragments[i] if inserted_set[fragment] or old_fragment_set[fragment] then - ---@type evolved.default? - local fragment_default + ---@type evolved.default?, evolved.set_hook?, evolved.assign_hook? + local fragment_default, fragment_on_set, fragment_on_assign - ---@type evolved.set_hook?, evolved.assign_hook? - local fragment_on_set, fragment_on_assign - - do - if new_chunk_has_defaults_or_constructs then - fragment_default = __evolved_get(fragment, __DEFAULT) - end - - if new_chunk_has_set_or_assign_hooks then - fragment_on_set, fragment_on_assign = __evolved_get(fragment, __ON_SET, __ON_ASSIGN) - end + if new_chunk_has_defaults_or_constructs or new_chunk_has_set_or_assign_hooks then + fragment_default, fragment_on_set, fragment_on_assign = __evolved_get(fragment, + __DEFAULT, __ON_SET, __ON_ASSIGN) end if fragment_on_set or fragment_on_assign then @@ -2768,20 +2740,12 @@ __chunk_multi_set = function(old_chunk, fragments, fragment_count, components) else inserted_set[fragment] = true - ---@type evolved.default? - local fragment_default + ---@type evolved.default?, evolved.set_hook?, evolved.insert_hook? + local fragment_default, fragment_on_set, fragment_on_insert - ---@type evolved.set_hook?, evolved.insert_hook? - local fragment_on_set, fragment_on_insert - - do - if new_chunk_has_defaults_or_constructs then - fragment_default = __evolved_get(fragment, __DEFAULT) - end - - if new_chunk_has_set_or_insert_hooks then - fragment_on_set, fragment_on_insert = __evolved_get(fragment, __ON_SET, __ON_INSERT) - end + if new_chunk_has_defaults_or_constructs or new_chunk_has_set_or_insert_hooks then + fragment_default, fragment_on_set, fragment_on_insert = __evolved_get(fragment, + __DEFAULT, __ON_SET, __ON_INSERT) end if fragment_on_set or fragment_on_insert then