remove private multi api impl

This commit is contained in:
BlackMATov
2025-04-19 22:46:11 +07:00
parent da4a992bca
commit c08243f9fb

View File

@@ -730,17 +730,11 @@ local __evolved_remove
local __evolved_clear
local __evolved_destroy
local __evolved_multi_set
local __evolved_multi_remove
local __evolved_batch_set
local __evolved_batch_remove
local __evolved_batch_clear
local __evolved_batch_destroy
local __evolved_batch_multi_set
local __evolved_batch_multi_remove
local __evolved_chunk
local __evolved_entities
@@ -5128,332 +5122,6 @@ function __evolved_destroy(...)
__evolved_commit()
end
---@param entity evolved.entity
---@param fragments evolved.fragment[]
---@param components? evolved.component[]
function __evolved_multi_set(entity, fragments, components)
local fragment_count = #fragments
if fragment_count == 0 then
return
end
if not components then
components = __safe_tbls.__EMPTY_COMPONENT_LIST
end
if __debug_mode then
__debug_fns.validate_entity(entity)
__debug_fns.validate_fragment_list(fragments, fragment_count)
end
if __defer_depth > 0 then
__defer_multi_set(entity, fragments, fragment_count, components, #components)
return
end
local entity_index = entity % 0x100000
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 then
return
end
__evolved_defer()
if old_chunk == new_chunk then
local old_component_indices = old_chunk.__component_indices
local old_component_storages = old_chunk.__component_storages
local old_chunk_has_setup_hooks = old_chunk.__has_setup_hooks
local old_chunk_has_assign_hooks = old_chunk.__has_assign_hooks
for i = 1, fragment_count do
local fragment = fragments[i]
---@type evolved.default?, evolved.duplicate?, evolved.set_hook?, evolved.assign_hook?
local fragment_default, fragment_duplicate, fragment_on_set, fragment_on_assign
if old_chunk_has_setup_hooks or old_chunk_has_assign_hooks then
fragment_default, fragment_duplicate, fragment_on_set, fragment_on_assign =
__evolved_get(fragment, __DEFAULT, __DUPLICATE, __ON_SET, __ON_ASSIGN)
end
local old_component_index = old_component_indices[fragment]
if old_component_index then
local old_component_storage = old_component_storages[old_component_index]
local new_component = components[i]
if new_component == nil then new_component = fragment_default end
if new_component ~= nil and fragment_duplicate then new_component = fragment_duplicate(new_component) end
if new_component == nil then new_component = true end
if fragment_on_set or fragment_on_assign then
local old_component = old_component_storage[old_place]
old_component_storage[old_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
old_component_storage[old_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
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
local new_chunk_has_setup_hooks = new_chunk.__has_setup_hooks
local new_chunk_has_assign_hooks = new_chunk.__has_assign_hooks
local new_chunk_has_insert_hooks = new_chunk.__has_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<evolved.fragment, boolean>
local inserted_set = __acquire_table(__table_pool_tag.fragment_set)
for i = 1, fragment_count do
local fragment = fragments[i]
---@type evolved.default?, evolved.duplicate?, evolved.set_hook?, evolved.assign_hook?, evolved.insert_hook?
local fragment_default, fragment_duplicate, fragment_on_set, fragment_on_assign, fragment_on_insert
if new_chunk_has_setup_hooks or new_chunk_has_assign_hooks or new_chunk_has_insert_hooks then
fragment_default, fragment_duplicate, fragment_on_set, fragment_on_assign, fragment_on_insert =
__evolved_get(fragment, __DEFAULT, __DUPLICATE, __ON_SET, __ON_ASSIGN, __ON_INSERT)
end
if inserted_set[fragment] or old_fragment_set[fragment] 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 and fragment_duplicate then new_component = fragment_duplicate(new_component) end
if new_component == nil then new_component = true end
if fragment_on_set or fragment_on_assign then
local old_component = new_component_storage[new_place]
new_component_storage[new_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
new_component_storage[new_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
else
inserted_set[fragment] = true
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 and fragment_duplicate then new_component = fragment_duplicate(new_component) 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()
end
---@param entity evolved.entity
---@param fragments evolved.fragment[]
function __evolved_multi_remove(entity, fragments)
local fragment_count = #fragments
if fragment_count == 0 then
return
end
local entity_index = entity % 0x100000
if __freelist_ids[entity_index] ~= entity then
-- this entity is not alive, nothing to remove
return
end
if __defer_depth > 0 then
__defer_multi_remove(entity, fragments, fragment_count)
return
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_without_fragment_list(old_chunk, fragments, fragment_count)
if old_chunk == new_chunk then
return
end
__evolved_defer()
do
local old_fragment_set = old_chunk.__fragment_set
local old_component_indices = old_chunk.__component_indices
local old_component_storages = old_chunk.__component_storages
if old_chunk.__has_remove_hooks then
---@type table<evolved.fragment, boolean>
local removed_set = __acquire_table(__table_pool_tag.fragment_set)
for i = 1, fragment_count do
local fragment = fragments[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)
if fragment_on_remove then
local old_component_index = old_component_indices[fragment]
if old_component_index then
local old_component_storage = old_component_storages[old_component_index]
local old_component = old_component_storage[old_place]
__defer_call_hook(fragment_on_remove, entity, fragment, old_component)
else
__defer_call_hook(fragment_on_remove, entity, fragment)
end
end
end
end
__release_table(__table_pool_tag.fragment_set, removed_set)
end
if new_chunk then
local new_entity_list = new_chunk.__entity_list
local new_entity_count = new_chunk.__entity_count
local new_component_count = new_chunk.__component_count
local new_component_storages = new_chunk.__component_storages
local new_component_fragments = new_chunk.__component_fragments
local new_place = new_entity_count + 1
new_chunk.__entity_count = new_place
new_entity_list[new_place] = entity
for new_ci = 1, new_component_count do
local new_f = new_component_fragments[new_ci]
local new_cs = new_component_storages[new_ci]
local old_ci = old_component_indices[new_f]
local old_cs = old_component_storages[old_ci]
new_cs[new_place] = old_cs[old_place]
end
end
do
__detach_entity(old_chunk, old_place)
entity_chunks[entity_index] = new_chunk
entity_places[entity_index] = new_chunk and new_chunk.__entity_count
__structural_changes = __structural_changes + 1
end
end
__evolved_commit()
end
---@param query evolved.query
---@param fragment evolved.fragment
---@param component evolved.component
@@ -5658,97 +5326,6 @@ function __evolved_batch_destroy(...)
__evolved_commit()
end
---@param query evolved.query
---@param fragments evolved.fragment[]
---@param components? evolved.component[]
function __evolved_batch_multi_set(query, fragments, components)
local fragment_count = #fragments
if fragment_count == 0 then
return
end
if not components then
components = __safe_tbls.__EMPTY_COMPONENT_LIST
end
if __debug_mode then
__debug_fns.validate_query(query)
__debug_fns.validate_fragment_list(fragments, fragment_count)
end
if __defer_depth > 0 then
__defer_batch_multi_set(query, fragments, fragment_count, components, #components)
return
end
__evolved_defer()
do
---@type evolved.chunk[]
local chunk_list = __acquire_table(__table_pool_tag.chunk_list)
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]
__chunk_multi_set(chunk, fragments, fragment_count, components)
end
__release_table(__table_pool_tag.chunk_list, chunk_list)
end
__evolved_commit()
end
---@param query evolved.query
---@param fragments evolved.fragment[]
function __evolved_batch_multi_remove(query, fragments)
local fragment_count = #fragments
if fragment_count == 0 then
return
end
local query_index = query % 0x100000
if __freelist_ids[query_index] ~= query then
-- this query is not alive, nothing to remove
return
end
if __defer_depth > 0 then
__defer_batch_multi_remove(query, fragments, fragment_count)
return
end
__evolved_defer()
do
---@type evolved.chunk[]
local chunk_list = __acquire_table(__table_pool_tag.chunk_list)
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]
__chunk_multi_remove(chunk, fragments, fragment_count)
end
__release_table(__table_pool_tag.chunk_list, chunk_list)
end
__evolved_commit()
end
---
---
---