mirror of
https://github.com/BlackMATov/evolved.lua.git
synced 2025-12-14 12:10:23 +07:00
remove evolved.multi_assign/insert, evolved.batch_multi_assing/insert
This commit is contained in:
@@ -83,8 +83,6 @@ clear :: entity... -> boolean, boolean
|
|||||||
destroy :: entity... -> boolean, boolean
|
destroy :: entity... -> boolean, boolean
|
||||||
|
|
||||||
multi_set :: entity, fragment[], component[]? -> 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
|
multi_remove :: entity, fragment[] -> boolean, boolean
|
||||||
|
|
||||||
batch_set :: chunk | query, fragment, any... -> integer, 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_destroy :: chunk | query... -> integer, boolean
|
||||||
|
|
||||||
batch_multi_set :: chunk | query, fragment[], component[]? -> 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
|
batch_multi_remove :: chunk | query, fragment[] -> integer, boolean
|
||||||
|
|
||||||
chunk :: fragment, fragment... -> chunk, entity[], integer
|
chunk :: fragment, fragment... -> chunk, entity[], integer
|
||||||
|
|||||||
816
evolved.lua
816
evolved.lua
@@ -661,8 +661,6 @@ local __evolved_clear
|
|||||||
local __evolved_destroy
|
local __evolved_destroy
|
||||||
|
|
||||||
local __evolved_multi_set
|
local __evolved_multi_set
|
||||||
local __evolved_multi_assign
|
|
||||||
local __evolved_multi_insert
|
|
||||||
local __evolved_multi_remove
|
local __evolved_multi_remove
|
||||||
|
|
||||||
local __evolved_batch_set
|
local __evolved_batch_set
|
||||||
@@ -673,8 +671,6 @@ local __evolved_batch_clear
|
|||||||
local __evolved_batch_destroy
|
local __evolved_batch_destroy
|
||||||
|
|
||||||
local __evolved_batch_multi_set
|
local __evolved_batch_multi_set
|
||||||
local __evolved_batch_multi_assign
|
|
||||||
local __evolved_batch_multi_insert
|
|
||||||
local __evolved_batch_multi_remove
|
local __evolved_batch_multi_remove
|
||||||
|
|
||||||
local __evolved_chunk
|
local __evolved_chunk
|
||||||
@@ -1511,8 +1507,6 @@ local __defer_clear
|
|||||||
local __defer_destroy
|
local __defer_destroy
|
||||||
|
|
||||||
local __defer_multi_set
|
local __defer_multi_set
|
||||||
local __defer_multi_assign
|
|
||||||
local __defer_multi_insert
|
|
||||||
local __defer_multi_remove
|
local __defer_multi_remove
|
||||||
|
|
||||||
local __defer_batch_set
|
local __defer_batch_set
|
||||||
@@ -1523,8 +1517,6 @@ local __defer_batch_clear
|
|||||||
local __defer_batch_destroy
|
local __defer_batch_destroy
|
||||||
|
|
||||||
local __defer_batch_multi_set
|
local __defer_batch_multi_set
|
||||||
local __defer_batch_multi_assign
|
|
||||||
local __defer_batch_multi_insert
|
|
||||||
local __defer_batch_multi_remove
|
local __defer_batch_multi_remove
|
||||||
|
|
||||||
local __defer_spawn_entity_at
|
local __defer_spawn_entity_at
|
||||||
@@ -1848,8 +1840,6 @@ local __chunk_clear
|
|||||||
local __chunk_destroy
|
local __chunk_destroy
|
||||||
|
|
||||||
local __chunk_multi_set
|
local __chunk_multi_set
|
||||||
local __chunk_multi_assign
|
|
||||||
local __chunk_multi_insert
|
|
||||||
local __chunk_multi_remove
|
local __chunk_multi_remove
|
||||||
|
|
||||||
---
|
---
|
||||||
@@ -2903,291 +2893,6 @@ __chunk_multi_set = function(old_chunk, fragments, fragment_count, components)
|
|||||||
return old_entity_count
|
return old_entity_count
|
||||||
end
|
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<evolved.fragment, boolean>
|
|
||||||
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 old_chunk evolved.chunk
|
||||||
---@param fragments evolved.fragment[]
|
---@param fragments evolved.fragment[]
|
||||||
---@param fragment_count integer
|
---@param fragment_count integer
|
||||||
@@ -3497,8 +3202,6 @@ local __defer_op = {
|
|||||||
destroy = 6,
|
destroy = 6,
|
||||||
|
|
||||||
multi_set = 7,
|
multi_set = 7,
|
||||||
multi_assign = 8,
|
|
||||||
multi_insert = 9,
|
|
||||||
multi_remove = 10,
|
multi_remove = 10,
|
||||||
|
|
||||||
batch_set = 11,
|
batch_set = 11,
|
||||||
@@ -3509,8 +3212,6 @@ local __defer_op = {
|
|||||||
batch_destroy = 16,
|
batch_destroy = 16,
|
||||||
|
|
||||||
batch_multi_set = 17,
|
batch_multi_set = 17,
|
||||||
batch_multi_assign = 18,
|
|
||||||
batch_multi_insert = 19,
|
|
||||||
batch_multi_remove = 20,
|
batch_multi_remove = 20,
|
||||||
|
|
||||||
spawn_entity_at = 21,
|
spawn_entity_at = 21,
|
||||||
@@ -3851,76 +3552,6 @@ __defer_ops[__defer_op.multi_set] = function(bytes, index)
|
|||||||
return 3
|
return 3
|
||||||
end
|
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 entity evolved.entity
|
||||||
---@param fragments evolved.fragment[]
|
---@param fragments evolved.fragment[]
|
||||||
---@param fragment_count integer
|
---@param fragment_count integer
|
||||||
@@ -4425,76 +4056,6 @@ __defer_ops[__defer_op.batch_multi_set] = function(bytes, index)
|
|||||||
return 3
|
return 3
|
||||||
end
|
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 chunk_or_query evolved.chunk | evolved.query
|
||||||
---@param fragments evolved.fragment[]
|
---@param fragments evolved.fragment[]
|
||||||
---@param fragment_count integer
|
---@param fragment_count integer
|
||||||
@@ -5798,259 +5359,6 @@ __evolved_multi_set = function(entity, fragments, components)
|
|||||||
return true, false
|
return true, false
|
||||||
end
|
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<evolved.fragment, boolean>
|
|
||||||
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 entity evolved.entity
|
||||||
---@param fragments evolved.fragment[]
|
---@param fragments evolved.fragment[]
|
||||||
---@return boolean is_all_removed
|
---@return boolean is_all_removed
|
||||||
@@ -6539,126 +5847,6 @@ __evolved_batch_multi_set = function(chunk_or_query, fragments, components)
|
|||||||
return set_count, false
|
return set_count, false
|
||||||
end
|
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 chunk_or_query evolved.chunk | evolved.query
|
||||||
---@param fragments evolved.fragment[]
|
---@param fragments evolved.fragment[]
|
||||||
---@return integer removed_count
|
---@return integer removed_count
|
||||||
@@ -8336,8 +7524,6 @@ evolved.clear = __evolved_clear
|
|||||||
evolved.destroy = __evolved_destroy
|
evolved.destroy = __evolved_destroy
|
||||||
|
|
||||||
evolved.multi_set = __evolved_multi_set
|
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.multi_remove = __evolved_multi_remove
|
||||||
|
|
||||||
evolved.batch_set = __evolved_batch_set
|
evolved.batch_set = __evolved_batch_set
|
||||||
@@ -8348,8 +7534,6 @@ evolved.batch_clear = __evolved_batch_clear
|
|||||||
evolved.batch_destroy = __evolved_batch_destroy
|
evolved.batch_destroy = __evolved_batch_destroy
|
||||||
|
|
||||||
evolved.batch_multi_set = __evolved_batch_multi_set
|
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.batch_multi_remove = __evolved_batch_multi_remove
|
||||||
|
|
||||||
evolved.chunk = __evolved_chunk
|
evolved.chunk = __evolved_chunk
|
||||||
|
|||||||
Reference in New Issue
Block a user