diff --git a/evolved.lua b/evolved.lua index af80322..2a39ecf 100644 --- a/evolved.lua +++ b/evolved.lua @@ -172,13 +172,21 @@ local __table_clear = (function() ---@param tab table return table_clear_loader and table_clear_loader() or function(tab) for i = 1, #tab do tab[i] = nil end - for k in pairs(tab) do tab[k] = nil end + for k in next, tab do tab[k] = nil end end end)() +local __assert = assert +local __error = error +local __pcall = pcall +local __select = select +local __setmetatable = setmetatable + local __table_sort = table.sort local __table_unpack = table.unpack or unpack +local __string_format = string.format + --- --- --- @@ -208,7 +216,7 @@ local function __acquire_id() local freelist_size = #freelist_ids if freelist_size == 0xFFFFF then - error('id index overflow', 2) + __error('id index overflow', 2) end local acquired_index = freelist_size + 1 @@ -229,7 +237,7 @@ local function __release_id(id) local freelist_ids = __freelist_ids if freelist_ids[acquired_index] ~= id then - error('id is not acquired or already released', 2) + __error('id is not acquired or already released', 2) end shifted_version = shifted_version == 0x7FF00000 @@ -454,7 +462,7 @@ local function __each_iterator(each_state) local fragment_index = each_state[4] if structural_changes ~= __structural_changes then - error('structural changes are prohibited during iteration', 2) + __error('structural changes are prohibited during iteration', 2) end local entity_chunk_fragment_list = entity_chunk.__fragment_list @@ -482,7 +490,7 @@ local function __execute_iterator(execute_state) local exclude_set = execute_state[3] if structural_changes ~= __structural_changes then - error('structural changes are prohibited during iteration', 2) + __error('structural changes are prohibited during iteration', 2) end local chunk_stack_size = #chunk_stack @@ -546,28 +554,6 @@ local __EXECUTE = __acquire_id() local __PROLOGUE = __acquire_id() local __EPILOGUE = __acquire_id() -evolved.TAG = __TAG - -evolved.DEFAULT = __DEFAULT -evolved.CONSTRUCT = __CONSTRUCT - -evolved.INCLUDES = __INCLUDES -evolved.EXCLUDES = __EXCLUDES - -evolved.ON_SET = __ON_SET -evolved.ON_ASSIGN = __ON_ASSIGN -evolved.ON_INSERT = __ON_INSERT -evolved.ON_REMOVE = __ON_REMOVE - -evolved.PHASE = __PHASE -evolved.AFTER = __AFTER - -evolved.QUERY = __QUERY -evolved.EXECUTE = __EXECUTE - -evolved.PROLOGUE = __PROLOGUE -evolved.EPILOGUE = __EPILOGUE - --- --- --- @@ -575,23 +561,23 @@ evolved.EPILOGUE = __EPILOGUE --- ---@type table -local __EMPTY_FRAGMENT_SET = setmetatable({}, { - __newindex = function() error('attempt to modify empty fragment set') end +local __EMPTY_FRAGMENT_SET = __setmetatable({}, { + __newindex = function() __error('attempt to modify empty fragment set') end }) ---@type evolved.fragment[] -local __EMPTY_FRAGMENT_LIST = setmetatable({}, { - __newindex = function() error('attempt to modify empty fragment list') end +local __EMPTY_FRAGMENT_LIST = __setmetatable({}, { + __newindex = function() __error('attempt to modify empty fragment list') end }) ---@type evolved.component[] -local __EMPTY_COMPONENT_LIST = setmetatable({}, { - __newindex = function() error('attempt to modify empty component list') end +local __EMPTY_COMPONENT_LIST = __setmetatable({}, { + __newindex = function() __error('attempt to modify empty component list') end }) ---@type evolved.component[] -local __EMPTY_COMPONENT_STORAGE = setmetatable({}, { - __newindex = function() error('attempt to modify empty component storage') end +local __EMPTY_COMPONENT_STORAGE = __setmetatable({}, { + __newindex = function() __error('attempt to modify empty component storage') end }) --- @@ -600,10 +586,73 @@ local __EMPTY_COMPONENT_STORAGE = setmetatable({}, { --- --- +local __evolved_id + +local __evolved_pack +local __evolved_unpack + +local __evolved_defer +local __evolved_commit + +local __evolved_is_alive +local __evolved_is_empty + +local __evolved_get +local __evolved_has +local __evolved_has_all +local __evolved_has_any + +local __evolved_set +local __evolved_assign +local __evolved_insert +local __evolved_remove +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 +local __evolved_batch_assign +local __evolved_batch_insert +local __evolved_batch_remove +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 +local __evolved_select + +local __evolved_each +local __evolved_execute + +local __evolved_process + +local __evolved_spawn_at +local __evolved_spawn_with + +local __evolved_entity +local __evolved_fragment +local __evolved_query +local __evolved_phase +local __evolved_system + +--- +--- +--- +--- +--- + ---@param ... any component arguments ---@return evolved.component local function __component_list(...) - local argument_count = select('#', ...) + local argument_count = __select('#', ...) if argument_count == 0 then return {} @@ -612,7 +661,7 @@ local function __component_list(...) local argument_list = __table_new(argument_count, 0) for argument_index = 1, argument_count do - argument_list[argument_index] = select(argument_index, ...) + argument_list[argument_index] = __select(argument_index, ...) end return argument_list @@ -622,7 +671,7 @@ end ---@return evolved.component local function __component_construct(fragment, ...) ---@type evolved.default, evolved.construct - local default, construct = evolved.get(fragment, __DEFAULT, __CONSTRUCT) + local default, construct = __evolved_get(fragment, __DEFAULT, __CONSTRUCT) local component = ... @@ -684,7 +733,7 @@ end ---@param old_component evolved.component local function __call_fragment_set_and_assign_hooks(entity, fragment, new_component, old_component) ---@type evolved.set_hook?, evolved.assign_hook? - local on_set, on_assign = evolved.get(fragment, __ON_SET, __ON_ASSIGN) + local on_set, on_assign = __evolved_get(fragment, __ON_SET, __ON_ASSIGN) if on_set then on_set(entity, fragment, new_component, old_component) end if on_assign then on_assign(entity, fragment, new_component, old_component) end end @@ -694,7 +743,7 @@ end ---@param new_component evolved.component local function __call_fragment_set_and_insert_hooks(entity, fragment, new_component) ---@type evolved.set_hook?, evolved.insert_hook? - local on_set, on_insert = evolved.get(fragment, __ON_SET, __ON_INSERT) + local on_set, on_insert = __evolved_get(fragment, __ON_SET, __ON_INSERT) if on_set then on_set(entity, fragment, new_component) end if on_insert then on_insert(entity, fragment, new_component) end end @@ -704,7 +753,7 @@ end ---@param old_component evolved.component local function __call_fragment_remove_hook(entity, fragment, old_component) ---@type evolved.remove_hook? - local on_remove = evolved.get(fragment, __ON_REMOVE) + local on_remove = __evolved_get(fragment, __ON_REMOVE) if on_remove then on_remove(entity, fragment, old_component) end end @@ -729,16 +778,16 @@ local function __new_chunk(chunk_parent, chunk_fragment) local chunk_component_fragments = {} ---@type evolved.fragment[] local has_defaults_or_constructs = (chunk_parent and chunk_parent.__has_defaults_or_constructs) - or evolved.has_any(chunk_fragment, __DEFAULT, __CONSTRUCT) + or __evolved_has_any(chunk_fragment, __DEFAULT, __CONSTRUCT) local has_set_or_assign_hooks = (chunk_parent and chunk_parent.__has_set_or_assign_hooks) - or evolved.has_any(chunk_fragment, __ON_SET, __ON_ASSIGN) + or __evolved_has_any(chunk_fragment, __ON_SET, __ON_ASSIGN) local has_set_or_insert_hooks = (chunk_parent and chunk_parent.__has_set_or_insert_hooks) - or evolved.has_any(chunk_fragment, __ON_SET, __ON_INSERT) + or __evolved_has_any(chunk_fragment, __ON_SET, __ON_INSERT) local has_remove_hooks = (chunk_parent and chunk_parent.__has_remove_hooks) - or evolved.has(chunk_fragment, __ON_REMOVE) + or __evolved_has(chunk_fragment, __ON_REMOVE) ---@type evolved.chunk local chunk = { @@ -774,7 +823,7 @@ local function __new_chunk(chunk_parent, chunk_fragment) chunk_fragment_set[parent_fragment] = true chunk_fragment_list[chunk_fragment_count] = parent_fragment - if not evolved.has(parent_fragment, __TAG) then + if not __evolved_has(parent_fragment, __TAG) then chunk_component_count = chunk_component_count + 1 local component_storage = {} local component_storage_index = chunk_component_count @@ -797,7 +846,7 @@ local function __new_chunk(chunk_parent, chunk_fragment) chunk_fragment_set[chunk_fragment] = true chunk_fragment_list[chunk_fragment_count] = chunk_fragment - if not evolved.has(chunk_fragment, __TAG) then + if not __evolved_has(chunk_fragment, __TAG) then chunk_component_count = chunk_component_count + 1 local component_storage = {} local component_storage_index = chunk_component_count @@ -937,14 +986,14 @@ end ---@return evolved.chunk? ---@nodiscard local function __chunk_without_fragments(chunk, ...) - local fragment_count = select('#', ...) + local fragment_count = __select('#', ...) if fragment_count == 0 then return chunk end for i = 1, fragment_count do - local fragment = select(i, ...) + local fragment = __select(i, ...) chunk = __chunk_without_fragment(chunk, fragment) end @@ -980,7 +1029,7 @@ end ---@return evolved.chunk? ---@nodiscard local function __chunk_fragments(...) - local fragment_count = select('#', ...) + local fragment_count = __select('#', ...) if fragment_count == 0 then return @@ -991,7 +1040,7 @@ local function __chunk_fragments(...) or __chunk_with_fragment(nil, root_fragment) for i = 2, fragment_count do - local child_fragment = select(i, ...) + local child_fragment = __select(i, ...) chunk = chunk.__with_fragment_edges[child_fragment] or __chunk_with_fragment(chunk, child_fragment) end @@ -1043,8 +1092,8 @@ end local function __chunk_has_all_fragments(chunk, ...) local fragment_set = chunk.__fragment_set - for i = 1, select('#', ...) do - local fragment = select(i, ...) + for i = 1, __select('#', ...) do + local fragment = __select(i, ...) if not fragment_set[fragment] then return false end @@ -1078,8 +1127,8 @@ end local function __chunk_has_any_fragments(chunk, ...) local fragment_set = chunk.__fragment_set - for i = 1, select('#', ...) do - local fragment = select(i, ...) + for i = 1, __select('#', ...) do + local fragment = __select(i, ...) if fragment_set[fragment] then return true end @@ -1112,7 +1161,7 @@ end ---@return evolved.component ... components ---@nodiscard local function __chunk_get_components(chunk, place, ...) - local fragment_count = select('#', ...) + local fragment_count = __select('#', ...) if fragment_count == 0 then return @@ -1163,7 +1212,7 @@ local function __chunk_get_components(chunk, place, ...) i2 and storages[i2][place], i3 and storages[i3][place], i4 and storages[i4][place], - __chunk_get_components(chunk, place, select(5, ...)) + __chunk_get_components(chunk, place, __select(5, ...)) end end @@ -1252,7 +1301,6 @@ end ---@param chunk evolved.chunk local function __detach_all_entities(chunk) local entities = chunk.__entities - local entity_count = chunk.__entity_count local component_count = chunk.__component_count local component_storages = chunk.__component_storages @@ -1272,7 +1320,7 @@ end ---@param components evolved.component[] local function __spawn_entity_at(entity, chunk, fragments, components) if __defer_depth <= 0 then - error('spawn entity operations should be deferred', 2) + __error('spawn entity operations should be deferred', 2) end local chunk_entities = chunk.__entities @@ -1296,7 +1344,7 @@ local function __spawn_entity_at(entity, chunk, fragments, components) local fragment = chunk_component_fragments[component_index] local component_storage = chunk_component_storages[component_index] - local new_component = evolved.get(fragment, __DEFAULT) + local new_component = __evolved_get(fragment, __DEFAULT) if new_component == nil then new_component = true @@ -1325,7 +1373,7 @@ local function __spawn_entity_at(entity, chunk, fragments, components) local new_component = components[i] if new_component == nil then - new_component = evolved.get(fragment, __DEFAULT) + new_component = __evolved_get(fragment, __DEFAULT) end if new_component == nil then @@ -1388,7 +1436,7 @@ end ---@param components evolved.component[] local function __spawn_entity_with(entity, chunk, fragments, components) if __defer_depth <= 0 then - error('spawn entity operations should be deferred', 2) + __error('spawn entity operations should be deferred', 2) end local chunk_entities = chunk.__entities @@ -1416,7 +1464,7 @@ local function __spawn_entity_with(entity, chunk, fragments, components) local new_component = components[i] if new_component == nil then - new_component = evolved.get(fragment, __DEFAULT) + new_component = __evolved_get(fragment, __DEFAULT) end if new_component == nil then @@ -1486,7 +1534,7 @@ end ---@nodiscard local function __chunk_assign(chunk, fragment, ...) if __defer_depth <= 0 then - error('batched chunk operations should be deferred', 2) + __error('batched chunk operations should be deferred', 2) end if not chunk.__fragment_set[fragment] then @@ -1507,11 +1555,11 @@ local function __chunk_assign(chunk, fragment, ...) do if chunk.__has_defaults_or_constructs then - fragment_default, fragment_construct = evolved.get(fragment, __DEFAULT, __CONSTRUCT) + 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) + fragment_on_set, fragment_on_assign = __evolved_get(fragment, __ON_SET, __ON_ASSIGN) end end @@ -1610,7 +1658,7 @@ end ---@nodiscard local function __chunk_insert(old_chunk, fragment, ...) if __defer_depth <= 0 then - error('batched chunk operations should be deferred', 2) + __error('batched chunk operations should be deferred', 2) end local new_chunk = __chunk_with_fragment(old_chunk, fragment) @@ -1640,11 +1688,11 @@ local function __chunk_insert(old_chunk, fragment, ...) do if new_chunk.__has_defaults_or_constructs then - fragment_default, fragment_construct = evolved.get(fragment, __DEFAULT, __CONSTRUCT) + 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) + fragment_on_set, fragment_on_insert = __evolved_get(fragment, __ON_SET, __ON_INSERT) end end @@ -1784,10 +1832,10 @@ end ---@nodiscard local function __chunk_remove(old_chunk, ...) if __defer_depth <= 0 then - error('batched chunk operations should be deferred', 2) + __error('batched chunk operations should be deferred', 2) end - local fragment_count = select('#', ...) + local fragment_count = __select('#', ...) if fragment_count == 0 then return 0 @@ -1810,13 +1858,13 @@ local function __chunk_remove(old_chunk, ...) local removed_set = __acquire_table(__TABLE_POOL_TAG__FRAGMENT_SET) for i = 1, fragment_count do - local fragment = select(i, ...) + local fragment = __select(i, ...) if not removed_set[fragment] and old_fragment_set[fragment] then removed_set[fragment] = true ---@type evolved.remove_hook? - local fragment_on_remove = evolved.get(fragment, __ON_REMOVE) + local fragment_on_remove = __evolved_get(fragment, __ON_REMOVE) if fragment_on_remove then local old_component_index = old_component_indices[fragment] @@ -1910,7 +1958,7 @@ end ---@nodiscard local function __chunk_clear(chunk) if __defer_depth <= 0 then - error('batched chunk operations should be deferred', 2) + __error('batched chunk operations should be deferred', 2) end local chunk_entities = chunk.__entities @@ -1927,7 +1975,7 @@ local function __chunk_clear(chunk) local fragment = chunk_fragment_list[fragment_index] ---@type evolved.remove_hook? - local fragment_on_remove = evolved.get(fragment, __ON_REMOVE) + local fragment_on_remove = __evolved_get(fragment, __ON_REMOVE) if fragment_on_remove then local component_index = chunk_component_indices[fragment] @@ -1971,7 +2019,7 @@ end ---@nodiscard local function __chunk_destroy(chunk) if __defer_depth <= 0 then - error('batched chunk operations should be deferred', 2) + __error('batched chunk operations should be deferred', 2) end local chunk_entities = chunk.__entities @@ -1988,7 +2036,7 @@ local function __chunk_destroy(chunk) local fragment = chunk_fragment_list[fragment_index] ---@type evolved.remove_hook? - local fragment_on_remove = evolved.get(fragment, __ON_REMOVE) + local fragment_on_remove = __evolved_get(fragment, __ON_REMOVE) if fragment_on_remove then local component_index = chunk_component_indices[fragment] @@ -2034,7 +2082,7 @@ end ---@return integer set_count local function __chunk_multi_set(old_chunk, fragments, components) if __defer_depth <= 0 then - error('batched chunk operations should be deferred', 2) + __error('batched chunk operations should be deferred', 2) end local fragment_count = #fragments @@ -2073,11 +2121,11 @@ local function __chunk_multi_set(old_chunk, fragments, components) do if old_chunk_has_defaults_or_constructs then - fragment_default = evolved.get(fragment, __DEFAULT) + 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) + fragment_on_set, fragment_on_assign = __evolved_get(fragment, __ON_SET, __ON_ASSIGN) end end @@ -2192,11 +2240,11 @@ local function __chunk_multi_set(old_chunk, fragments, components) do if new_chunk_has_defaults_or_constructs then - fragment_default = evolved.get(fragment, __DEFAULT) + 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) + fragment_on_set, fragment_on_assign = __evolved_get(fragment, __ON_SET, __ON_ASSIGN) end end @@ -2264,11 +2312,11 @@ local function __chunk_multi_set(old_chunk, fragments, components) do if new_chunk_has_defaults_or_constructs then - fragment_default = evolved.get(fragment, __DEFAULT) + 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) + fragment_on_set, fragment_on_insert = __evolved_get(fragment, __ON_SET, __ON_INSERT) end end @@ -2354,7 +2402,7 @@ end ---@return integer assigned_count local function __chunk_multi_assign(chunk, fragments, components) if __defer_depth <= 0 then - error('batched chunk operations should be deferred', 2) + __error('batched chunk operations should be deferred', 2) end local fragment_count = #fragments @@ -2389,11 +2437,11 @@ local function __chunk_multi_assign(chunk, fragments, components) do if chunk_has_defaults_or_constructs then - fragment_default = evolved.get(fragment, __DEFAULT) + 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) + fragment_on_set, fragment_on_assign = __evolved_get(fragment, __ON_SET, __ON_ASSIGN) end end @@ -2463,7 +2511,7 @@ end ---@return integer inserted_count local function __chunk_multi_insert(old_chunk, fragments, components) if __defer_depth <= 0 then - error('batched chunk operations should be deferred', 2) + __error('batched chunk operations should be deferred', 2) end local fragment_count = #fragments @@ -2542,11 +2590,11 @@ local function __chunk_multi_insert(old_chunk, fragments, components) do if new_chunk_has_defaults_or_constructs then - fragment_default = evolved.get(fragment, __DEFAULT) + 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) + fragment_on_set, fragment_on_insert = __evolved_get(fragment, __ON_SET, __ON_INSERT) end end @@ -2629,7 +2677,7 @@ end ---@return integer removed_count local function __chunk_multi_remove(old_chunk, fragments) if __defer_depth <= 0 then - error('batched chunk operations should be deferred', 2) + __error('batched chunk operations should be deferred', 2) end local fragment_count = #fragments @@ -2661,7 +2709,7 @@ local function __chunk_multi_remove(old_chunk, fragments) removed_set[fragment] = true ---@type evolved.remove_hook? - local fragment_on_remove = evolved.get(fragment, __ON_REMOVE) + local fragment_on_remove = __evolved_get(fragment, __ON_REMOVE) if fragment_on_remove then local old_component_index = old_component_indices[fragment] @@ -2758,26 +2806,26 @@ end ---@param system evolved.system local function __system_process(system) - local query, execute, prologue, epilogue = evolved.get(system, + local query, execute, prologue, epilogue = __evolved_get(system, __QUERY, __EXECUTE, __PROLOGUE, __EPILOGUE) if prologue then - local success, result = pcall(prologue) + local success, result = __pcall(prologue) if not success then - error(string.format('system prologue failed: %s', result), 2) + __error(__string_format('system prologue failed: %s', result), 2) end end if query and execute then __defer() do - for chunk, entities, entity_count in evolved.execute(query) do - local success, result = pcall(execute, chunk, entities, entity_count) + for chunk, entities, entity_count in __evolved_execute(query) do + local success, result = __pcall(execute, chunk, entities, entity_count) if not success then __commit() - error(string.format('system execution failed: %s', result), 2) + __error(__string_format('system execution failed: %s', result), 2) end end end @@ -2785,10 +2833,10 @@ local function __system_process(system) end if epilogue then - local success, result = pcall(epilogue) + local success, result = __pcall(epilogue) if not success then - error(string.format('system epilogue failed: %s', result), 2) + __error(__string_format('system epilogue failed: %s', result), 2) end end end @@ -2865,7 +2913,7 @@ local function __phase_process(phase) local cycled_system_mark = sorting_marks[cycled_system_mark_index] if cycled_system_mark == 1 then - sorting_cycle_path = string.format('%s -> %s', + sorting_cycle_path = __string_format('%s -> %s', sorting_cycle_path, cycled_system) if cycled_system == dependency then @@ -2874,7 +2922,7 @@ local function __phase_process(phase) end end - error(string.format('system sorting failed: cyclic dependency detected (%s)', + __error(__string_format('system sorting failed: cyclic dependency detected (%s)', sorting_cycle_path)) end end @@ -2954,7 +3002,7 @@ end ---@return boolean committed __commit = function() if __defer_depth <= 0 then - error('unbalanced defer/commit', 2) + __error('unbalanced defer/commit', 2) end __defer_depth = __defer_depth - 1 @@ -2990,7 +3038,7 @@ __defer_set = function(entity, fragment, ...) local length = __defer_length local bytecode = __defer_bytecode - local argument_count = select('#', ...) + local argument_count = __select('#', ...) bytecode[length + 1] = __defer_op.set bytecode[length + 2] = entity @@ -3024,7 +3072,7 @@ __defer_set = function(entity, fragment, ...) bytecode[length + 7] = a3 bytecode[length + 8] = a4 for i = 5, argument_count do - bytecode[length + 4 + i] = select(i, ...) + bytecode[length + 4 + i] = __select(i, ...) end end @@ -3036,7 +3084,7 @@ __defer_ops[__defer_op.set] = function(bytes, index) local fragment = bytes[index + 1] local argument_count = bytes[index + 2] - local set = evolved.set + local set = __evolved_set if argument_count == 0 then set(entity, fragment) @@ -3068,7 +3116,7 @@ __defer_assign = function(entity, fragment, ...) local length = __defer_length local bytecode = __defer_bytecode - local argument_count = select('#', ...) + local argument_count = __select('#', ...) bytecode[length + 1] = __defer_op.assign bytecode[length + 2] = entity @@ -3102,7 +3150,7 @@ __defer_assign = function(entity, fragment, ...) bytecode[length + 7] = a3 bytecode[length + 8] = a4 for i = 5, argument_count do - bytecode[length + 4 + i] = select(i, ...) + bytecode[length + 4 + i] = __select(i, ...) end end @@ -3114,7 +3162,7 @@ __defer_ops[__defer_op.assign] = function(bytes, index) local fragment = bytes[index + 1] local argument_count = bytes[index + 2] - local assign = evolved.assign + local assign = __evolved_assign if argument_count == 0 then assign(entity, fragment) @@ -3146,7 +3194,7 @@ __defer_insert = function(entity, fragment, ...) local length = __defer_length local bytecode = __defer_bytecode - local argument_count = select('#', ...) + local argument_count = __select('#', ...) bytecode[length + 1] = __defer_op.insert bytecode[length + 2] = entity @@ -3180,7 +3228,7 @@ __defer_insert = function(entity, fragment, ...) bytecode[length + 7] = a3 bytecode[length + 8] = a4 for i = 5, argument_count do - bytecode[length + 4 + i] = select(i, ...) + bytecode[length + 4 + i] = __select(i, ...) end end @@ -3192,7 +3240,7 @@ __defer_ops[__defer_op.insert] = function(bytes, index) local fragment = bytes[index + 1] local argument_count = bytes[index + 2] - local insert = evolved.insert + local insert = __evolved_insert if argument_count == 0 then insert(entity, fragment) @@ -3220,7 +3268,7 @@ end ---@param entity evolved.entity ---@param ... evolved.fragment fragments __defer_remove = function(entity, ...) - local fragment_count = select('#', ...) + local fragment_count = __select('#', ...) if fragment_count == 0 then return end local length = __defer_length @@ -3257,7 +3305,7 @@ __defer_remove = function(entity, ...) bytecode[length + 6] = f3 bytecode[length + 7] = f4 for i = 5, fragment_count do - bytecode[length + 3 + i] = select(i, ...) + bytecode[length + 3 + i] = __select(i, ...) end end @@ -3268,7 +3316,7 @@ __defer_ops[__defer_op.remove] = function(bytes, index) local entity = bytes[index + 0] local fragment_count = bytes[index + 1] - local remove = evolved.remove + local remove = __evolved_remove if fragment_count == 0 then -- nothing @@ -3306,7 +3354,7 @@ end __defer_ops[__defer_op.clear] = function(bytes, index) local entity = bytes[index + 0] - evolved.clear(entity) + __evolved_clear(entity) return 1 end @@ -3323,7 +3371,7 @@ end __defer_ops[__defer_op.destroy] = function(bytes, index) local entity = bytes[index + 0] - evolved.destroy(entity) + __evolved_destroy(entity) return 1 end @@ -3352,7 +3400,7 @@ __defer_ops[__defer_op.multi_set] = function(bytes, index) local entity = bytes[index + 0] local fragments = bytes[index + 1] local components = bytes[index + 2] - evolved.multi_set(entity, fragments, components) + __evolved_multi_set(entity, fragments, components) __release_table(__TABLE_POOL_TAG__FRAGMENT_LIST, fragments) __release_table(__TABLE_POOL_TAG__COMPONENT_LIST, components) return 3 @@ -3383,7 +3431,7 @@ __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) + __evolved_multi_assign(entity, fragments, components) __release_table(__TABLE_POOL_TAG__FRAGMENT_LIST, fragments) __release_table(__TABLE_POOL_TAG__COMPONENT_LIST, components) return 3 @@ -3414,7 +3462,7 @@ __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) + __evolved_multi_insert(entity, fragments, components) __release_table(__TABLE_POOL_TAG__FRAGMENT_LIST, fragments) __release_table(__TABLE_POOL_TAG__COMPONENT_LIST, components) return 3 @@ -3439,7 +3487,7 @@ end __defer_ops[__defer_op.multi_remove] = function(bytes, index) local entity = bytes[index + 0] local fragments = bytes[index + 1] - evolved.multi_remove(entity, fragments) + __evolved_multi_remove(entity, fragments) __release_table(__TABLE_POOL_TAG__FRAGMENT_LIST, fragments) return 2 end @@ -3451,7 +3499,7 @@ __defer_batch_set = function(query, fragment, ...) local length = __defer_length local bytecode = __defer_bytecode - local argument_count = select('#', ...) + local argument_count = __select('#', ...) bytecode[length + 1] = __defer_op.batch_set bytecode[length + 2] = query @@ -3485,7 +3533,7 @@ __defer_batch_set = function(query, fragment, ...) bytecode[length + 7] = a3 bytecode[length + 8] = a4 for i = 5, argument_count do - bytecode[length + 4 + i] = select(i, ...) + bytecode[length + 4 + i] = __select(i, ...) end end @@ -3497,7 +3545,7 @@ __defer_ops[__defer_op.batch_set] = function(bytes, index) local fragment = bytes[index + 1] local argument_count = bytes[index + 2] - local batch_set = evolved.batch_set + local batch_set = __evolved_batch_set if argument_count == 0 then batch_set(query, fragment) @@ -3529,7 +3577,7 @@ __defer_batch_assign = function(query, fragment, ...) local length = __defer_length local bytecode = __defer_bytecode - local argument_count = select('#', ...) + local argument_count = __select('#', ...) bytecode[length + 1] = __defer_op.batch_assign bytecode[length + 2] = query @@ -3563,7 +3611,7 @@ __defer_batch_assign = function(query, fragment, ...) bytecode[length + 7] = a3 bytecode[length + 8] = a4 for i = 5, argument_count do - bytecode[length + 4 + i] = select(i, ...) + bytecode[length + 4 + i] = __select(i, ...) end end @@ -3575,7 +3623,7 @@ __defer_ops[__defer_op.batch_assign] = function(bytes, index) local fragment = bytes[index + 1] local argument_count = bytes[index + 2] - local batch_assign = evolved.batch_assign + local batch_assign = __evolved_batch_assign if argument_count == 0 then batch_assign(query, fragment) @@ -3607,7 +3655,7 @@ __defer_batch_insert = function(query, fragment, ...) local length = __defer_length local bytecode = __defer_bytecode - local argument_count = select('#', ...) + local argument_count = __select('#', ...) bytecode[length + 1] = __defer_op.batch_insert bytecode[length + 2] = query @@ -3641,7 +3689,7 @@ __defer_batch_insert = function(query, fragment, ...) bytecode[length + 7] = a3 bytecode[length + 8] = a4 for i = 5, argument_count do - bytecode[length + 4 + i] = select(i, ...) + bytecode[length + 4 + i] = __select(i, ...) end end @@ -3653,7 +3701,7 @@ __defer_ops[__defer_op.batch_insert] = function(bytes, index) local fragment = bytes[index + 1] local argument_count = bytes[index + 2] - local batch_insert = evolved.batch_insert + local batch_insert = __evolved_batch_insert if argument_count == 0 then batch_insert(query, fragment) @@ -3681,7 +3729,7 @@ end ---@param query evolved.query ---@param ... evolved.fragment fragments __defer_batch_remove = function(query, ...) - local fragment_count = select('#', ...) + local fragment_count = __select('#', ...) if fragment_count == 0 then return end local length = __defer_length @@ -3718,7 +3766,7 @@ __defer_batch_remove = function(query, ...) bytecode[length + 6] = f3 bytecode[length + 7] = f4 for i = 5, fragment_count do - bytecode[length + 3 + i] = select(i, ...) + bytecode[length + 3 + i] = __select(i, ...) end end @@ -3729,7 +3777,7 @@ __defer_ops[__defer_op.batch_remove] = function(bytes, index) local query = bytes[index + 0] local fragment_count = bytes[index + 1] - local batch_remove = evolved.batch_remove + local batch_remove = __evolved_batch_remove if fragment_count == 0 then -- nothing @@ -3767,7 +3815,7 @@ end __defer_ops[__defer_op.batch_clear] = function(bytes, index) local query = bytes[index + 0] - evolved.batch_clear(query) + __evolved_batch_clear(query) return 1 end @@ -3784,7 +3832,7 @@ end __defer_ops[__defer_op.batch_destroy] = function(bytes, index) local query = bytes[index + 0] - evolved.batch_destroy(query) + __evolved_batch_destroy(query) return 1 end @@ -3813,7 +3861,7 @@ __defer_ops[__defer_op.batch_multi_set] = function(bytes, index) local query = bytes[index + 0] local fragments = bytes[index + 1] local components = bytes[index + 2] - evolved.batch_multi_set(query, fragments, components) + __evolved_batch_multi_set(query, fragments, components) __release_table(__TABLE_POOL_TAG__FRAGMENT_LIST, fragments) __release_table(__TABLE_POOL_TAG__COMPONENT_LIST, components) return 3 @@ -3844,7 +3892,7 @@ __defer_ops[__defer_op.batch_multi_assign] = function(bytes, index) local query = bytes[index + 0] local fragments = bytes[index + 1] local components = bytes[index + 2] - evolved.batch_multi_assign(query, fragments, components) + __evolved_batch_multi_assign(query, fragments, components) __release_table(__TABLE_POOL_TAG__FRAGMENT_LIST, fragments) __release_table(__TABLE_POOL_TAG__COMPONENT_LIST, components) return 3 @@ -3875,7 +3923,7 @@ __defer_ops[__defer_op.batch_multi_insert] = function(bytes, index) local query = bytes[index + 0] local fragments = bytes[index + 1] local components = bytes[index + 2] - evolved.batch_multi_insert(query, fragments, components) + __evolved_batch_multi_insert(query, fragments, components) __release_table(__TABLE_POOL_TAG__FRAGMENT_LIST, fragments) __release_table(__TABLE_POOL_TAG__COMPONENT_LIST, components) return 3 @@ -3900,7 +3948,7 @@ end __defer_ops[__defer_op.batch_multi_remove] = function(bytes, index) local query = bytes[index + 0] local fragments = bytes[index + 1] - evolved.batch_multi_remove(query, fragments) + __evolved_batch_multi_remove(query, fragments) __release_table(__TABLE_POOL_TAG__FRAGMENT_LIST, fragments) return 2 end @@ -3984,7 +4032,7 @@ end ---@param hook fun(...) ---@param ... any hook arguments __defer_call_hook = function(hook, ...) - local argument_count = select('#', ...) + local argument_count = __select('#', ...) local length = __defer_length local bytecode = __defer_bytecode @@ -4020,7 +4068,7 @@ __defer_call_hook = function(hook, ...) bytecode[length + 6] = a3 bytecode[length + 7] = a4 for i = 5, argument_count do - bytecode[length + 3 + i] = select(i, ...) + bytecode[length + 3 + i] = __select(i, ...) end end @@ -4135,7 +4183,7 @@ end ---@param count? integer ---@return evolved.id ... ids ---@nodiscard -function evolved.id(count) +__evolved_id = function(count) count = count or 1 if count == 0 then @@ -4160,7 +4208,7 @@ function evolved.id(count) do return __acquire_id(), __acquire_id(), __acquire_id(), __acquire_id(), - evolved.id(count - 4) + __evolved_id(count - 4) end end @@ -4168,13 +4216,13 @@ end ---@param version integer ---@return evolved.id id ---@nodiscard -function evolved.pack(index, version) +__evolved_pack = function(index, version) if index < 1 or index > 0xFFFFF then - error('id index out of range [1;0xFFFFF]', 2) + __error('id index out of range [1;0xFFFFF]', 2) end if version < 1 or version > 0x7FF then - error('id version out of range [1;0x7FF]', 2) + __error('id version out of range [1;0x7FF]', 2) end local shifted_version = version * 0x100000 @@ -4185,26 +4233,26 @@ end ---@return integer index ---@return integer version ---@nodiscard -function evolved.unpack(id) +__evolved_unpack = function(id) local index = id % 0x100000 local version = (id - index) / 0x100000 return index, version end ---@return boolean started -function evolved.defer() +__evolved_defer = function() return __defer() end ---@return boolean committed -function evolved.commit() +__evolved_commit = function() return __commit() end ---@param entity evolved.entity ---@return boolean ---@nodiscard -function evolved.is_alive(entity) +__evolved_is_alive = function(entity) local entity_index = entity % 0x100000 return __freelist_ids[entity_index] == entity @@ -4213,7 +4261,7 @@ end ---@param entity evolved.entity ---@return boolean ---@nodiscard -function evolved.is_empty(entity) +__evolved_is_empty = function(entity) local entity_index = entity % 0x100000 if __freelist_ids[entity_index] ~= entity then @@ -4227,7 +4275,7 @@ end ---@param ... evolved.fragment fragments ---@return evolved.component ... components ---@nodiscard -function evolved.get(entity, ...) +__evolved_get = function(entity, ...) local entity_index = entity % 0x100000 if __freelist_ids[entity_index] ~= entity then @@ -4248,7 +4296,7 @@ end ---@param fragment evolved.fragment ---@return boolean ---@nodiscard -function evolved.has(entity, fragment) +__evolved_has = function(entity, fragment) local entity_index = entity % 0x100000 if __freelist_ids[entity_index] ~= entity then @@ -4268,7 +4316,7 @@ end ---@param ... evolved.fragment fragments ---@return boolean ---@nodiscard -function evolved.has_all(entity, ...) +__evolved_has_all = function(entity, ...) local entity_index = entity % 0x100000 if __freelist_ids[entity_index] ~= entity then @@ -4278,7 +4326,7 @@ function evolved.has_all(entity, ...) local chunk = __entity_chunks[entity_index] if not chunk then - return select('#', ...) == 0 + return __select('#', ...) == 0 end return __chunk_has_all_fragments(chunk, ...) @@ -4288,7 +4336,7 @@ end ---@param ... evolved.fragment fragments ---@return boolean ---@nodiscard -function evolved.has_any(entity, ...) +__evolved_has_any = function(entity, ...) local entity_index = entity % 0x100000 if __freelist_ids[entity_index] ~= entity then @@ -4309,7 +4357,7 @@ end ---@param ... any component arguments ---@return boolean is_set ---@return boolean is_deferred -function evolved.set(entity, fragment, ...) +__evolved_set = function(entity, fragment, ...) if __defer_depth > 0 then __defer_set(entity, fragment, ...) return false, true @@ -4447,7 +4495,7 @@ end ---@param ... any component arguments ---@return boolean is_assigned ---@return boolean is_deferred -function evolved.assign(entity, fragment, ...) +__evolved_assign = function(entity, fragment, ...) if __defer_depth > 0 then __defer_assign(entity, fragment, ...) return false, true @@ -4521,7 +4569,7 @@ end ---@param ... any component arguments ---@return boolean is_inserted ---@return boolean is_deferred -function evolved.insert(entity, fragment, ...) +__evolved_insert = function(entity, fragment, ...) if __defer_depth > 0 then __defer_insert(entity, fragment, ...) return false, true @@ -4623,7 +4671,7 @@ end ---@param ... evolved.fragment fragments ---@return boolean is_removed ---@return boolean is_deferred -function evolved.remove(entity, ...) +__evolved_remove = function(entity, ...) if __defer_depth > 0 then __defer_remove(entity, ...) return false, true @@ -4657,8 +4705,8 @@ function evolved.remove(entity, ...) if old_chunk.__has_remove_hooks then local removed_set = __acquire_table(__TABLE_POOL_TAG__FRAGMENT_SET) - for i = 1, select('#', ...) do - local fragment = select(i, ...) + for i = 1, __select('#', ...) do + local fragment = __select(i, ...) if not removed_set[fragment] and old_fragment_set[fragment] then removed_set[fragment] = true @@ -4720,7 +4768,7 @@ end ---@param entity evolved.entity ---@return boolean is_cleared ---@return boolean is_deferred -function evolved.clear(entity) +__evolved_clear = function(entity) if __defer_depth > 0 then __defer_clear(entity) return false, true @@ -4780,7 +4828,7 @@ end ---@param entity evolved.entity ---@return boolean is_destroyed ---@return boolean is_deferred -function evolved.destroy(entity) +__evolved_destroy = function(entity) if __defer_depth > 0 then __defer_destroy(entity) return false, true @@ -4844,7 +4892,7 @@ end ---@param components? evolved.component[] ---@return boolean is_any_set ---@return boolean is_deferred -function evolved.multi_set(entity, fragments, components) +__evolved_multi_set = function(entity, fragments, components) local fragment_count = #fragments if fragment_count == 0 then @@ -4898,7 +4946,7 @@ function evolved.multi_set(entity, fragments, components) local new_component = components[i] if old_chunk_has_defaults_or_constructs and new_component == nil then - new_component = evolved.get(fragment, __DEFAULT) + new_component = __evolved_get(fragment, __DEFAULT) end if new_component == nil then @@ -4966,7 +5014,7 @@ function evolved.multi_set(entity, fragments, components) local new_component = components[i] if new_chunk_has_defaults_or_constructs and new_component == nil then - new_component = evolved.get(fragment, __DEFAULT) + new_component = __evolved_get(fragment, __DEFAULT) end if new_component == nil then @@ -4996,7 +5044,7 @@ function evolved.multi_set(entity, fragments, components) local new_component = components[i] if new_chunk_has_defaults_or_constructs and new_component == nil then - new_component = evolved.get(fragment, __DEFAULT) + new_component = __evolved_get(fragment, __DEFAULT) end if new_component == nil then @@ -5033,7 +5081,7 @@ end ---@param components? evolved.component[] ---@return boolean is_any_assigned ---@return boolean is_deferred -function evolved.multi_assign(entity, fragments, components) +__evolved_multi_assign = function(entity, fragments, components) local fragment_count = #fragments if fragment_count == 0 then @@ -5087,7 +5135,7 @@ function evolved.multi_assign(entity, fragments, components) local new_component = components[i] if chunk_has_defaults_or_constructs and new_component == nil then - new_component = evolved.get(fragment, __DEFAULT) + new_component = __evolved_get(fragment, __DEFAULT) end if new_component == nil then @@ -5119,7 +5167,7 @@ end ---@param components? evolved.component[] ---@return boolean is_any_inserted ---@return boolean is_deferred -function evolved.multi_insert(entity, fragments, components) +__evolved_multi_insert = function(entity, fragments, components) local fragment_count = #fragments if fragment_count == 0 then @@ -5204,7 +5252,7 @@ function evolved.multi_insert(entity, fragments, components) local new_component = components[i] if new_chunk_has_defaults_or_constructs and new_component == nil then - new_component = evolved.get(fragment, __DEFAULT) + new_component = __evolved_get(fragment, __DEFAULT) end if new_component == nil then @@ -5240,7 +5288,7 @@ end ---@param fragments evolved.fragment[] ---@return boolean is_all_removed ---@return boolean is_deferred -function evolved.multi_remove(entity, fragments) +__evolved_multi_remove = function(entity, fragments) local fragment_count = #fragments if fragment_count == 0 then @@ -5345,7 +5393,7 @@ end ---@param ... any component arguments ---@return integer set_count ---@return boolean is_deferred -function evolved.batch_set(query, fragment, ...) +__evolved_batch_set = function(query, fragment, ...) if __defer_depth > 0 then __defer_batch_set(query, fragment, ...) return 0, true @@ -5355,7 +5403,7 @@ function evolved.batch_set(query, fragment, ...) local chunk_list = __acquire_table(__TABLE_POOL_TAG__CHUNK_STACK) local chunk_list_size = 0 - for chunk in evolved.execute(query) do + for chunk in __evolved_execute(query) do chunk_list_size = chunk_list_size + 1 chunk_list[chunk_list_size] = chunk end @@ -5384,7 +5432,7 @@ end ---@param ... any component arguments ---@return integer assigned_count ---@return boolean is_deferred -function evolved.batch_assign(query, fragment, ...) +__evolved_batch_assign = function(query, fragment, ...) if __defer_depth > 0 then __defer_batch_assign(query, fragment, ...) return 0, true @@ -5394,7 +5442,7 @@ function evolved.batch_assign(query, fragment, ...) local chunk_list = __acquire_table(__TABLE_POOL_TAG__CHUNK_STACK) local chunk_list_size = 0 - for chunk in evolved.execute(query) do + for chunk in __evolved_execute(query) do chunk_list_size = chunk_list_size + 1 chunk_list[chunk_list_size] = chunk end @@ -5419,7 +5467,7 @@ end ---@param ... any component arguments ---@return integer inserted_count ---@return boolean is_deferred -function evolved.batch_insert(query, fragment, ...) +__evolved_batch_insert = function(query, fragment, ...) if __defer_depth > 0 then __defer_batch_insert(query, fragment, ...) return 0, true @@ -5429,7 +5477,7 @@ function evolved.batch_insert(query, fragment, ...) local chunk_list = __acquire_table(__TABLE_POOL_TAG__CHUNK_STACK) local chunk_list_size = 0 - for chunk in evolved.execute(query) do + for chunk in __evolved_execute(query) do chunk_list_size = chunk_list_size + 1 chunk_list[chunk_list_size] = chunk end @@ -5453,7 +5501,7 @@ end ---@param ... evolved.fragment fragments ---@return integer removed_count ---@return boolean is_deferred -function evolved.batch_remove(query, ...) +__evolved_batch_remove = function(query, ...) if __defer_depth > 0 then __defer_batch_remove(query, ...) return 0, true @@ -5463,7 +5511,7 @@ function evolved.batch_remove(query, ...) local chunk_list = __acquire_table(__TABLE_POOL_TAG__CHUNK_STACK) local chunk_list_size = 0 - for chunk in evolved.execute(query) do + for chunk in __evolved_execute(query) do chunk_list_size = chunk_list_size + 1 chunk_list[chunk_list_size] = chunk end @@ -5486,7 +5534,7 @@ end ---@param query evolved.query ---@return integer cleared_count ---@return boolean is_deferred -function evolved.batch_clear(query) +__evolved_batch_clear = function(query) if __defer_depth > 0 then __defer_batch_clear(query) return 0, true @@ -5496,7 +5544,7 @@ function evolved.batch_clear(query) local chunk_list = __acquire_table(__TABLE_POOL_TAG__CHUNK_STACK) local chunk_list_size = 0 - for chunk in evolved.execute(query) do + for chunk in __evolved_execute(query) do chunk_list_size = chunk_list_size + 1 chunk_list[chunk_list_size] = chunk end @@ -5519,7 +5567,7 @@ end ---@param query evolved.query ---@return integer destroyed_count ---@return boolean is_deferred -function evolved.batch_destroy(query) +__evolved_batch_destroy = function(query) if __defer_depth > 0 then __defer_batch_destroy(query) return 0, true @@ -5529,7 +5577,7 @@ function evolved.batch_destroy(query) local chunk_list = __acquire_table(__TABLE_POOL_TAG__CHUNK_STACK) local chunk_list_size = 0 - for chunk in evolved.execute(query) do + for chunk in __evolved_execute(query) do chunk_list_size = chunk_list_size + 1 chunk_list[chunk_list_size] = chunk end @@ -5554,7 +5602,7 @@ end ---@param components? evolved.component[] ---@return integer set_count ---@return boolean is_deferred -function evolved.batch_multi_set(query, fragments, components) +__evolved_batch_multi_set = function(query, fragments, components) if not components then components = __EMPTY_COMPONENT_LIST end @@ -5568,7 +5616,7 @@ function evolved.batch_multi_set(query, fragments, components) local chunk_list = __acquire_table(__TABLE_POOL_TAG__CHUNK_STACK) local chunk_list_size = 0 - for chunk in evolved.execute(query) do + for chunk in __evolved_execute(query) do chunk_list_size = chunk_list_size + 1 chunk_list[chunk_list_size] = chunk end @@ -5593,7 +5641,7 @@ end ---@param components? evolved.component[] ---@return integer assigned_count ---@return boolean is_deferred -function evolved.batch_multi_assign(query, fragments, components) +__evolved_batch_multi_assign = function(query, fragments, components) if not components then components = __EMPTY_COMPONENT_LIST end @@ -5607,7 +5655,7 @@ function evolved.batch_multi_assign(query, fragments, components) local chunk_list = __acquire_table(__TABLE_POOL_TAG__CHUNK_STACK) local chunk_list_size = 0 - for chunk in evolved.execute(query) do + for chunk in __evolved_execute(query) do chunk_list_size = chunk_list_size + 1 chunk_list[chunk_list_size] = chunk end @@ -5632,7 +5680,7 @@ end ---@param components? evolved.component[] ---@return integer inserted_count ---@return boolean is_deferred -function evolved.batch_multi_insert(query, fragments, components) +__evolved_batch_multi_insert = function(query, fragments, components) if not components then components = __EMPTY_COMPONENT_LIST end @@ -5646,7 +5694,7 @@ function evolved.batch_multi_insert(query, fragments, components) local chunk_list = __acquire_table(__TABLE_POOL_TAG__CHUNK_STACK) local chunk_list_size = 0 - for chunk in evolved.execute(query) do + for chunk in __evolved_execute(query) do chunk_list_size = chunk_list_size + 1 chunk_list[chunk_list_size] = chunk end @@ -5670,7 +5718,7 @@ end ---@param fragments evolved.fragment[] ---@return integer removed_count ---@return boolean is_deferred -function evolved.batch_multi_remove(query, fragments) +__evolved_batch_multi_remove = function(query, fragments) if __defer_depth > 0 then __defer_batch_multi_remove(query, fragments) return 0, true @@ -5680,7 +5728,7 @@ function evolved.batch_multi_remove(query, fragments) local chunk_list = __acquire_table(__TABLE_POOL_TAG__CHUNK_STACK) local chunk_list_size = 0 - for chunk in evolved.execute(query) do + for chunk in __evolved_execute(query) do chunk_list_size = chunk_list_size + 1 chunk_list[chunk_list_size] = chunk end @@ -5710,7 +5758,7 @@ end ---@return evolved.chunk? chunk ---@return evolved.entity[]? entities ---@return integer? entity_count -function evolved.chunk(...) +__evolved_chunk = function(...) local chunk = __chunk_fragments(...) if not chunk then @@ -5724,8 +5772,8 @@ end ---@param ... evolved.fragment fragments ---@return evolved.component_storage ... component_storages ---@nodiscard -function evolved.select(chunk, ...) - local fragment_count = select('#', ...) +__evolved_select = function(chunk, ...) + local fragment_count = __select('#', ...) if fragment_count == 0 then return @@ -5778,7 +5826,7 @@ function evolved.select(chunk, ...) i2 and storages[i2] or empty_component_storage, i3 and storages[i3] or empty_component_storage, i4 and storages[i4] or empty_component_storage, - evolved.select(chunk, select(5, ...)) + __evolved_select(chunk, __select(5, ...)) end end @@ -5786,7 +5834,7 @@ end ---@return evolved.each_iterator iterator ---@return evolved.each_state? iterator_state ---@nodiscard -function evolved.each(entity) +__evolved_each = function(entity) local entity_index = entity % 0x100000 if __freelist_ids[entity_index] ~= entity then @@ -5818,7 +5866,7 @@ end ---@return evolved.execute_iterator iterator ---@return evolved.execute_state? iterator_state ---@nodiscard -function evolved.execute(query) +__evolved_execute = function(query) local query_index = query % 0x100000 if __freelist_ids[query_index] ~= query then @@ -5881,15 +5929,15 @@ function evolved.execute(query) end ---@param ... evolved.phase phases -function evolved.process(...) - local phase_count = select('#', ...) +__evolved_process = function(...) + local phase_count = __select('#', ...) if phase_count == 0 then return end for i = 1, phase_count do - local phase = select(i, ...) + local phase = __select(i, ...) __phase_process(phase) end end @@ -5905,7 +5953,7 @@ end ---@param components? evolved.component[] ---@return evolved.entity entity ---@return boolean is_deferred -function evolved.spawn_at(chunk, fragments, components) +__evolved_spawn_at = function(chunk, fragments, components) if not fragments then fragments = __EMPTY_FRAGMENT_LIST end @@ -5939,7 +5987,7 @@ end ---@param components? evolved.component[] ---@return evolved.entity entity ---@return boolean is_deferred -function evolved.spawn_with(fragments, components) +__evolved_spawn_with = function(fragments, components) if not fragments then fragments = __EMPTY_FRAGMENT_LIST end @@ -5986,7 +6034,7 @@ evolved_entity_builder.__index = evolved_entity_builder ---@return evolved.entity_builder builder ---@nodiscard -function evolved.entity() +__evolved_entity = function() ---@type evolved.__entity_builder local builder = { __fragment_list = nil, @@ -5994,7 +6042,7 @@ function evolved.entity() __component_count = 0, } ---@cast builder evolved.entity_builder - return setmetatable(builder, evolved_entity_builder) + return __setmetatable(builder, evolved_entity_builder) end ---@param fragment evolved.fragment @@ -6035,10 +6083,10 @@ function evolved_entity_builder:build() self.__component_count = 0 if component_count == 0 then - return evolved.id(), false + return __evolved_id(), false end - local entity, is_deferred = evolved.spawn_with(fragment_list, component_list) + local entity, is_deferred = __evolved_spawn_with(fragment_list, component_list) __release_table(__TABLE_POOL_TAG__FRAGMENT_LIST, fragment_list) __release_table(__TABLE_POOL_TAG__COMPONENT_LIST, component_list) @@ -6068,7 +6116,7 @@ evolved_fragment_builder.__index = evolved_fragment_builder ---@return evolved.fragment_builder builder ---@nodiscard -function evolved.fragment() +__evolved_fragment = function() ---@type evolved.__fragment_builder local builder = { __tag = false, @@ -6081,7 +6129,7 @@ function evolved.fragment() __on_remove = nil, } ---@cast builder evolved.fragment_builder - return setmetatable(builder, evolved_fragment_builder) + return __setmetatable(builder, evolved_fragment_builder) end ---@return evolved.fragment_builder builder @@ -6162,7 +6210,7 @@ function evolved_fragment_builder:build() self.__on_insert = nil self.__on_remove = nil - local fragment = evolved.id() + local fragment = __evolved_id() local fragment_list = __acquire_table(__TABLE_POOL_TAG__FRAGMENT_LIST) local component_list = __acquire_table(__TABLE_POOL_TAG__COMPONENT_LIST) @@ -6217,10 +6265,10 @@ function evolved_fragment_builder:build() end if component_count == 0 then - return evolved.id(), false + return __evolved_id(), false end - local _, is_deferred = evolved.multi_set(fragment, fragment_list, component_list) + local _, is_deferred = __evolved_multi_set(fragment, fragment_list, component_list) __release_table(__TABLE_POOL_TAG__FRAGMENT_LIST, fragment_list) __release_table(__TABLE_POOL_TAG__COMPONENT_LIST, component_list) @@ -6244,20 +6292,20 @@ evolved_query_builder.__index = evolved_query_builder ---@return evolved.query_builder builder ---@nodiscard -function evolved.query() +__evolved_query = function() ---@type evolved.__query_builder local builder = { __include_list = nil, __exclude_list = nil, } ---@cast builder evolved.query_builder - return setmetatable(builder, evolved_query_builder) + return __setmetatable(builder, evolved_query_builder) end ---@param ... evolved.fragment fragments ---@return evolved.query_builder builder function evolved_query_builder:include(...) - local fragment_count = select('#', ...) + local fragment_count = __select('#', ...) if fragment_count == 0 then return self @@ -6273,7 +6321,7 @@ function evolved_query_builder:include(...) local include_list_size = #include_list for i = 1, fragment_count do - local fragment = select(i, ...) + local fragment = __select(i, ...) include_list[include_list_size + i] = fragment end @@ -6283,7 +6331,7 @@ end ---@param ... evolved.fragment fragments ---@return evolved.query_builder builder function evolved_query_builder:exclude(...) - local fragment_count = select('#', ...) + local fragment_count = __select('#', ...) if fragment_count == 0 then return self @@ -6299,7 +6347,7 @@ function evolved_query_builder:exclude(...) local exclude_list_size = #exclude_list for i = 1, fragment_count do - local fragment = select(i, ...) + local fragment = __select(i, ...) exclude_list[exclude_list_size + i] = fragment end @@ -6332,10 +6380,10 @@ function evolved_query_builder:build() end if component_count == 0 then - return evolved.id(), false + return __evolved_id(), false end - local query, is_deferred = evolved.spawn_with(fragment_list, component_list) + local query, is_deferred = __evolved_spawn_with(fragment_list, component_list) __release_table(__TABLE_POOL_TAG__FRAGMENT_LIST, fragment_list) __release_table(__TABLE_POOL_TAG__COMPONENT_LIST, component_list) @@ -6357,17 +6405,17 @@ evolved_phase_builder.__index = evolved_phase_builder ---@return evolved.phase_builder builder ---@nodiscard -function evolved.phase() +__evolved_phase = function() ---@type evolved.__phase_builder local builder = {} ---@cast builder evolved.phase_builder - return setmetatable(builder, evolved_phase_builder) + return __setmetatable(builder, evolved_phase_builder) end ---@return evolved.phase phase ---@return boolean is_deferred function evolved_phase_builder:build() - return evolved.id(), false + return __evolved_id(), false end --- @@ -6390,7 +6438,7 @@ evolved_system_builder.__index = evolved_system_builder ---@return evolved.system_builder builder ---@nodiscard -function evolved.system() +__evolved_system = function() ---@type evolved.__system_builder local builder = { __phase = nil, @@ -6401,7 +6449,7 @@ function evolved.system() __epilogue = nil, } ---@cast builder evolved.system_builder - return setmetatable(builder, evolved_system_builder) + return __setmetatable(builder, evolved_system_builder) end ---@param phase evolved.phase @@ -6413,7 +6461,7 @@ end ---@param ... evolved.system systems ---@return evolved.system_builder builder function evolved_system_builder:after(...) - local system_count = select('#', ...) + local system_count = __select('#', ...) if system_count == 0 then return self @@ -6430,7 +6478,7 @@ function evolved_system_builder:after(...) for i = 1, system_count do after_count = after_count + 1 - after[after_count] = select(i, ...) + after[after_count] = __select(i, ...) end return self @@ -6518,10 +6566,10 @@ function evolved_system_builder:build() end if component_count == 0 then - return evolved.id(), false + return __evolved_id(), false end - local system, is_deferred = evolved.spawn_with(fragment_list, component_list) + local system, is_deferred = __evolved_spawn_with(fragment_list, component_list) __release_table(__TABLE_POOL_TAG__FRAGMENT_LIST, fragment_list) __release_table(__TABLE_POOL_TAG__COMPONENT_LIST, component_list) @@ -6541,16 +6589,16 @@ local function __update_chunk_caches_trace(chunk) local chunk_parent, chunk_fragment = chunk.__parent, chunk.__fragment local has_defaults_or_constructs = (chunk_parent and chunk_parent.__has_defaults_or_constructs) - or evolved.has_any(chunk_fragment, __DEFAULT, __CONSTRUCT) + or __evolved_has_any(chunk_fragment, __DEFAULT, __CONSTRUCT) local has_set_or_assign_hooks = (chunk_parent and chunk_parent.__has_set_or_assign_hooks) - or evolved.has_any(chunk_fragment, __ON_SET, __ON_ASSIGN) + or __evolved_has_any(chunk_fragment, __ON_SET, __ON_ASSIGN) local has_set_or_insert_hooks = (chunk_parent and chunk_parent.__has_set_or_insert_hooks) - or evolved.has_any(chunk_fragment, __ON_SET, __ON_INSERT) + or __evolved_has_any(chunk_fragment, __ON_SET, __ON_INSERT) local has_remove_hooks = (chunk_parent and chunk_parent.__has_remove_hooks) - or evolved.has(chunk_fragment, __ON_REMOVE) + or __evolved_has(chunk_fragment, __ON_REMOVE) chunk.__has_defaults_or_constructs = has_defaults_or_constructs chunk.__has_set_or_assign_hooks = has_set_or_assign_hooks @@ -6565,15 +6613,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_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.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_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)) --- --- @@ -6592,7 +6640,7 @@ local function __update_chunk_tags_trace(chunk, fragment) local component_index = component_indices[fragment] - if component_index and evolved.has(fragment, __TAG) then + if component_index and __evolved_has(fragment, __TAG) then if component_index ~= component_count then local last_component_storage = component_storages[component_count] local last_component_fragment = component_fragments[component_count] @@ -6609,7 +6657,7 @@ local function __update_chunk_tags_trace(chunk, fragment) chunk.__component_count = component_count end - if not component_index and not evolved.has(fragment, __TAG) then + if not component_index and not __evolved_has(fragment, __TAG) then component_count = component_count + 1 chunk.__component_count = component_count @@ -6620,7 +6668,7 @@ local function __update_chunk_tags_trace(chunk, fragment) component_storages[storage_index] = storage component_fragments[storage_index] = fragment - local new_component = evolved.get(fragment, __DEFAULT) + local new_component = __evolved_get(fragment, __DEFAULT) if new_component == nil then new_component = true @@ -6648,14 +6696,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_insert(__TAG, __ON_INSERT, __update_fragment_tags)) +__assert(__evolved_insert(__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_insert(__DEFAULT, __ON_INSERT, __update_fragment_defaults)) +__assert(__evolved_insert(__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_insert(__CONSTRUCT, __ON_INSERT, __update_fragment_constructs)) +__assert(__evolved_insert(__CONSTRUCT, __ON_REMOVE, __update_fragment_constructs)) --- --- @@ -6663,12 +6711,12 @@ assert(evolved.insert(__CONSTRUCT, __ON_REMOVE, __update_fragment_constructs)) --- --- -assert(evolved.insert(__TAG, __TAG)) +__assert(__evolved_insert(__TAG, __TAG)) -assert(evolved.insert(__INCLUDES, __CONSTRUCT, __component_list)) -assert(evolved.insert(__EXCLUDES, __CONSTRUCT, __component_list)) +__assert(__evolved_insert(__INCLUDES, __CONSTRUCT, __component_list)) +__assert(__evolved_insert(__EXCLUDES, __CONSTRUCT, __component_list)) -assert(evolved.insert(__AFTER, __CONSTRUCT, __component_list)) +__assert(__evolved_insert(__AFTER, __CONSTRUCT, __component_list)) --- --- @@ -6678,7 +6726,7 @@ assert(evolved.insert(__AFTER, __CONSTRUCT, __component_list)) ---@param query evolved.query ---@param include_list evolved.fragment[] -assert(evolved.insert(__INCLUDES, __ON_SET, function(query, _, include_list) +__assert(__evolved_insert(__INCLUDES, __ON_SET, function(query, _, include_list) local include_list_size = #include_list if include_list_size == 0 then @@ -6697,7 +6745,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_insert(__INCLUDES, __ON_REMOVE, function(query) __query_sorted_includes[query] = nil end)) @@ -6709,7 +6757,7 @@ end)) ---@param query evolved.query ---@param exclude_list evolved.fragment[] -assert(evolved.insert(__EXCLUDES, __ON_SET, function(query, _, exclude_list) +__assert(__evolved_insert(__EXCLUDES, __ON_SET, function(query, _, exclude_list) local exclude_list_size = #exclude_list if exclude_list_size == 0 then @@ -6728,7 +6776,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_insert(__EXCLUDES, __ON_REMOVE, function(query) __query_sorted_excludes[query] = nil end)) @@ -6741,7 +6789,7 @@ end)) ---@param system evolved.system ---@param new_phase evolved.phase ---@param old_phase? evolved.phase -assert(evolved.insert(__PHASE, __ON_SET, function(system, _, new_phase, old_phase) +__assert(__evolved_insert(__PHASE, __ON_SET, function(system, _, new_phase, old_phase) if new_phase == old_phase then return end @@ -6770,7 +6818,7 @@ end)) ---@param system evolved.system ---@param old_phase evolved.phase -assert(evolved.insert(__PHASE, __ON_REMOVE, function(system, _, old_phase) +__assert(__evolved_insert(__PHASE, __ON_REMOVE, function(system, _, old_phase) local old_phase_systems = __phase_systems[old_phase] if old_phase_systems then @@ -6790,7 +6838,7 @@ end)) ---@param system evolved.system ---@param new_after_list evolved.system[] -assert(evolved.insert(__AFTER, __ON_SET, function(system, _, new_after_list) +__assert(__evolved_insert(__AFTER, __ON_SET, function(system, _, new_after_list) local new_after_list_size = #new_after_list if new_after_list_size == 0 then @@ -6809,7 +6857,7 @@ assert(evolved.insert(__AFTER, __ON_SET, function(system, _, new_after_list) end)) ---@param system evolved.system -assert(evolved.insert(__AFTER, __ON_REMOVE, function(system) +__assert(__evolved_insert(__AFTER, __ON_REMOVE, function(system) __system_dependencies[system] = nil end)) @@ -6819,4 +6867,83 @@ end)) --- --- +evolved.TAG = __TAG + +evolved.DEFAULT = __DEFAULT +evolved.CONSTRUCT = __CONSTRUCT + +evolved.INCLUDES = __INCLUDES +evolved.EXCLUDES = __EXCLUDES + +evolved.ON_SET = __ON_SET +evolved.ON_ASSIGN = __ON_ASSIGN +evolved.ON_INSERT = __ON_INSERT +evolved.ON_REMOVE = __ON_REMOVE + +evolved.PHASE = __PHASE +evolved.AFTER = __AFTER + +evolved.QUERY = __QUERY +evolved.EXECUTE = __EXECUTE + +evolved.PROLOGUE = __PROLOGUE +evolved.EPILOGUE = __EPILOGUE + +evolved.id = __evolved_id + +evolved.pack = __evolved_pack +evolved.unpack = __evolved_unpack + +evolved.defer = __evolved_defer +evolved.commit = __evolved_commit + +evolved.is_alive = __evolved_is_alive +evolved.is_empty = __evolved_is_empty + +evolved.get = __evolved_get +evolved.has = __evolved_has +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 + +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 +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 + +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 +evolved.select = __evolved_select + +evolved.each = __evolved_each +evolved.execute = __evolved_execute + +evolved.process = __evolved_process + +evolved.spawn_at = __evolved_spawn_at +evolved.spawn_with = __evolved_spawn_with + +evolved.entity = __evolved_entity +evolved.fragment = __evolved_fragment +evolved.query = __evolved_query +evolved.phase = __evolved_phase +evolved.system = __evolved_system + return evolved