mirror of
https://github.com/BlackMATov/evolved.lua.git
synced 2026-01-04 17:20:58 +07:00
little reduce copy-paste in multi api
This commit is contained in:
@@ -521,7 +521,7 @@ do
|
||||
|
||||
assert(evo.insert(e, f1, 42))
|
||||
assert(evo.insert(e, f2, 43))
|
||||
evo.remove(e, f1, f2)
|
||||
evo.remove(e, f1, f2, f2)
|
||||
assert(remove_count == 3)
|
||||
assert(last_removed_component == 43)
|
||||
|
||||
|
||||
438
evolved.lua
438
evolved.lua
@@ -1093,17 +1093,16 @@ local function __chunk_assign(chunk, fragment, ...)
|
||||
return chunk_entity_count
|
||||
end
|
||||
|
||||
---@param chunk evolved.chunk
|
||||
---@param old_chunk evolved.chunk
|
||||
---@param fragment evolved.fragment
|
||||
---@param ... any component arguments
|
||||
---@return integer inserted_count
|
||||
---@nodiscard
|
||||
local function __chunk_insert(chunk, fragment, ...)
|
||||
local function __chunk_insert(old_chunk, fragment, ...)
|
||||
if __defer_depth <= 0 then
|
||||
error('batched chunk operations should be deferred', 2)
|
||||
end
|
||||
|
||||
local old_chunk = chunk
|
||||
local new_chunk = __chunk_with_fragment(old_chunk, fragment)
|
||||
|
||||
if old_chunk == new_chunk then
|
||||
@@ -1219,11 +1218,11 @@ local function __chunk_insert(chunk, fragment, ...)
|
||||
return old_entity_count
|
||||
end
|
||||
|
||||
---@param chunk evolved.chunk
|
||||
---@param old_chunk evolved.chunk
|
||||
---@param ... evolved.fragment fragments
|
||||
---@return integer removed_count
|
||||
---@nodiscard
|
||||
local function __chunk_remove(chunk, ...)
|
||||
local function __chunk_remove(old_chunk, ...)
|
||||
if __defer_depth <= 0 then
|
||||
error('batched chunk operations should be deferred', 2)
|
||||
end
|
||||
@@ -1234,8 +1233,7 @@ local function __chunk_remove(chunk, ...)
|
||||
return 0
|
||||
end
|
||||
|
||||
local old_chunk = chunk
|
||||
local new_chunk = __chunk_without_fragments(chunk, ...)
|
||||
local new_chunk = __chunk_without_fragments(old_chunk, ...)
|
||||
|
||||
if old_chunk == new_chunk then
|
||||
return 0
|
||||
@@ -1246,23 +1244,19 @@ local function __chunk_remove(chunk, ...)
|
||||
|
||||
local old_fragment_set = old_chunk.__fragment_set
|
||||
local old_component_count = old_chunk.__component_count
|
||||
local old_component_indices = chunk.__component_indices
|
||||
local old_component_storages = chunk.__component_storages
|
||||
local old_component_indices = old_chunk.__component_indices
|
||||
local old_component_storages = old_chunk.__component_storages
|
||||
|
||||
if old_chunk.__has_remove_hooks then
|
||||
local removed_set = __acquire_table(__TABLE_POOL_TAG__FRAGMENT_SET)
|
||||
|
||||
for i = 1, fragment_count do
|
||||
local fragment = select(i, ...)
|
||||
|
||||
if not removed_set[fragment] and old_fragment_set[fragment] and __fragment_has_remove_hook(fragment) then
|
||||
removed_set[fragment] = true
|
||||
|
||||
local old_component_index = old_component_indices[fragment]
|
||||
|
||||
if old_component_index then
|
||||
local old_component_storage = old_component_storages[old_component_index]
|
||||
|
||||
for old_place = 1, old_entity_count do
|
||||
local entity = old_entities[old_place]
|
||||
local old_component = old_component_storage[old_place]
|
||||
@@ -1460,11 +1454,11 @@ local function __chunk_destroy(chunk)
|
||||
return chunk_entity_count
|
||||
end
|
||||
|
||||
---@param chunk evolved.chunk
|
||||
---@param old_chunk evolved.chunk
|
||||
---@param fragments evolved.fragment[]
|
||||
---@param components evolved.component[]
|
||||
---@return integer set_count
|
||||
local function __chunk_multi_set(chunk, fragments, components)
|
||||
local function __chunk_multi_set(old_chunk, fragments, components)
|
||||
if __defer_depth <= 0 then
|
||||
error('batched chunk operations should be deferred', 2)
|
||||
end
|
||||
@@ -1475,8 +1469,7 @@ local function __chunk_multi_set(chunk, fragments, components)
|
||||
return 0
|
||||
end
|
||||
|
||||
local old_chunk = chunk
|
||||
local new_chunk = __chunk_with_fragment_list(chunk, fragments)
|
||||
local new_chunk = __chunk_with_fragment_list(old_chunk, fragments)
|
||||
|
||||
if not new_chunk then
|
||||
return 0
|
||||
@@ -1491,17 +1484,20 @@ local function __chunk_multi_set(chunk, fragments, components)
|
||||
local old_component_storages = old_chunk.__component_storages
|
||||
local old_component_fragments = old_chunk.__component_fragments
|
||||
|
||||
local old_chunk_has_defaults_or_constructs = old_chunk.__has_defaults_or_constructs
|
||||
local old_chunk_has_set_or_assign_hooks = old_chunk.__has_set_or_assign_hooks
|
||||
|
||||
if old_chunk == new_chunk then
|
||||
for i = 1, fragment_count do
|
||||
local fragment = fragments[i]
|
||||
if chunk.__has_set_or_assign_hooks and __fragment_has_set_or_assign_hooks(fragment) then
|
||||
if old_chunk_has_set_or_assign_hooks and __fragment_has_set_or_assign_hooks(fragment) then
|
||||
local old_component_index = old_component_indices[fragment]
|
||||
if old_component_index then
|
||||
local old_component_storage = old_component_storages[old_component_index]
|
||||
if chunk.__has_defaults_or_constructs and __fragment_has_default_or_construct(fragment) then
|
||||
|
||||
local new_component = components[i]
|
||||
|
||||
if new_component == nil then
|
||||
if new_component == nil and old_chunk_has_defaults_or_constructs then
|
||||
new_component = evolved.get(fragment, evolved.DEFAULT)
|
||||
end
|
||||
|
||||
@@ -1515,20 +1511,6 @@ local function __chunk_multi_set(chunk, fragments, components)
|
||||
old_component_storage[place] = new_component
|
||||
__fragment_call_set_and_assign_hooks(entity, fragment, new_component, old_component)
|
||||
end
|
||||
else
|
||||
local new_component = components[i]
|
||||
|
||||
if new_component == nil then
|
||||
new_component = true
|
||||
end
|
||||
|
||||
for place = 1, old_entity_count do
|
||||
local entity = old_entities[place]
|
||||
local old_component = old_component_storage[place]
|
||||
old_component_storage[place] = new_component
|
||||
__fragment_call_set_and_assign_hooks(entity, fragment, new_component, old_component)
|
||||
end
|
||||
end
|
||||
else
|
||||
for place = 1, old_entity_count do
|
||||
local entity = old_entities[place]
|
||||
@@ -1539,10 +1521,10 @@ local function __chunk_multi_set(chunk, fragments, components)
|
||||
local old_component_index = old_component_indices[fragment]
|
||||
if old_component_index then
|
||||
local old_component_storage = old_component_storages[old_component_index]
|
||||
if chunk.__has_defaults_or_constructs and __fragment_has_default_or_construct(fragment) then
|
||||
|
||||
local new_component = components[i]
|
||||
|
||||
if new_component == nil then
|
||||
if new_component == nil and old_chunk_has_defaults_or_constructs then
|
||||
new_component = evolved.get(fragment, evolved.DEFAULT)
|
||||
end
|
||||
|
||||
@@ -1553,17 +1535,6 @@ local function __chunk_multi_set(chunk, fragments, components)
|
||||
for place = 1, old_entity_count do
|
||||
old_component_storage[place] = new_component
|
||||
end
|
||||
else
|
||||
local new_component = components[i]
|
||||
|
||||
if new_component == nil then
|
||||
new_component = true
|
||||
end
|
||||
|
||||
for place = 1, old_entity_count do
|
||||
old_component_storage[place] = new_component
|
||||
end
|
||||
end
|
||||
else
|
||||
-- nothing
|
||||
end
|
||||
@@ -1576,6 +1547,10 @@ local function __chunk_multi_set(chunk, fragments, components)
|
||||
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_assign_hooks = new_chunk.__has_set_or_assign_hooks
|
||||
local new_chunk_has_set_or_insert_hooks = new_chunk.__has_set_or_insert_hooks
|
||||
|
||||
do
|
||||
new_chunk.__entity_count = new_entity_count + old_entity_count
|
||||
|
||||
@@ -1599,14 +1574,14 @@ local function __chunk_multi_set(chunk, fragments, components)
|
||||
for i = 1, fragment_count do
|
||||
local fragment = fragments[i]
|
||||
if inserted_set[fragment] or old_fragment_set[fragment] then
|
||||
if new_chunk.__has_set_or_assign_hooks and __fragment_has_set_or_assign_hooks(fragment) then
|
||||
if new_chunk_has_set_or_assign_hooks and __fragment_has_set_or_assign_hooks(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]
|
||||
if new_chunk.__has_defaults_or_constructs and __fragment_has_default_or_construct(fragment) then
|
||||
|
||||
local new_component = components[i]
|
||||
|
||||
if new_component == nil then
|
||||
if new_component == nil and new_chunk_has_defaults_or_constructs then
|
||||
new_component = evolved.get(fragment, evolved.DEFAULT)
|
||||
end
|
||||
|
||||
@@ -1620,20 +1595,6 @@ local function __chunk_multi_set(chunk, fragments, components)
|
||||
new_component_storage[new_place] = new_component
|
||||
__fragment_call_set_and_assign_hooks(entity, fragment, new_component, old_component)
|
||||
end
|
||||
else
|
||||
local new_component = components[i]
|
||||
|
||||
if new_component == nil then
|
||||
new_component = true
|
||||
end
|
||||
|
||||
for new_place = new_entity_count + 1, new_entity_count + old_entity_count do
|
||||
local entity = new_entities[new_place]
|
||||
local old_component = new_component_storage[new_place]
|
||||
new_component_storage[new_place] = new_component
|
||||
__fragment_call_set_and_assign_hooks(entity, fragment, new_component, old_component)
|
||||
end
|
||||
end
|
||||
else
|
||||
for new_place = new_entity_count + 1, new_entity_count + old_entity_count do
|
||||
local entity = new_entities[new_place]
|
||||
@@ -1644,10 +1605,10 @@ local function __chunk_multi_set(chunk, fragments, components)
|
||||
local new_component_index = new_component_indices[fragment]
|
||||
if new_component_index then
|
||||
local new_component_storage = new_component_storages[new_component_index]
|
||||
if new_chunk.__has_defaults_or_constructs and __fragment_has_default_or_construct(fragment) then
|
||||
|
||||
local new_component = components[i]
|
||||
|
||||
if new_component == nil then
|
||||
if new_component == nil and new_chunk_has_defaults_or_constructs then
|
||||
new_component = evolved.get(fragment, evolved.DEFAULT)
|
||||
end
|
||||
|
||||
@@ -1658,31 +1619,20 @@ local function __chunk_multi_set(chunk, fragments, components)
|
||||
for new_place = new_entity_count + 1, new_entity_count + old_entity_count do
|
||||
new_component_storage[new_place] = new_component
|
||||
end
|
||||
else
|
||||
local new_component = components[i]
|
||||
|
||||
if new_component == nil then
|
||||
new_component = true
|
||||
end
|
||||
|
||||
for new_place = new_entity_count + 1, new_entity_count + old_entity_count do
|
||||
new_component_storage[new_place] = new_component
|
||||
end
|
||||
end
|
||||
else
|
||||
-- nothing
|
||||
end
|
||||
end
|
||||
else
|
||||
inserted_set[fragment] = true
|
||||
if new_chunk.__has_set_or_insert_hooks and __fragment_has_set_or_insert_hooks(fragment) then
|
||||
if new_chunk_has_set_or_insert_hooks and __fragment_has_set_or_insert_hooks(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]
|
||||
if new_chunk.__has_defaults_or_constructs and __fragment_has_default_or_construct(fragment) then
|
||||
|
||||
local new_component = components[i]
|
||||
|
||||
if new_component == nil then
|
||||
if new_component == nil and new_chunk_has_defaults_or_constructs then
|
||||
new_component = evolved.get(fragment, evolved.DEFAULT)
|
||||
end
|
||||
|
||||
@@ -1695,19 +1645,6 @@ local function __chunk_multi_set(chunk, fragments, components)
|
||||
new_component_storage[new_place] = new_component
|
||||
__fragment_call_set_and_insert_hooks(entity, fragment, new_component)
|
||||
end
|
||||
else
|
||||
local new_component = components[i]
|
||||
|
||||
if new_component == nil then
|
||||
new_component = true
|
||||
end
|
||||
|
||||
for new_place = new_entity_count + 1, new_entity_count + old_entity_count do
|
||||
local entity = new_entities[new_place]
|
||||
new_component_storage[new_place] = new_component
|
||||
__fragment_call_set_and_insert_hooks(entity, fragment, new_component)
|
||||
end
|
||||
end
|
||||
else
|
||||
for new_place = new_entity_count + 1, new_entity_count + old_entity_count do
|
||||
local entity = new_entities[new_place]
|
||||
@@ -1718,10 +1655,10 @@ local function __chunk_multi_set(chunk, fragments, components)
|
||||
local new_component_index = new_component_indices[fragment]
|
||||
if new_component_index then
|
||||
local new_component_storage = new_component_storages[new_component_index]
|
||||
if new_chunk.__has_defaults_or_constructs and __fragment_has_default_or_construct(fragment) then
|
||||
|
||||
local new_component = components[i]
|
||||
|
||||
if new_component == nil then
|
||||
if new_component == nil and new_chunk_has_defaults_or_constructs then
|
||||
new_component = evolved.get(fragment, evolved.DEFAULT)
|
||||
end
|
||||
|
||||
@@ -1732,17 +1669,6 @@ local function __chunk_multi_set(chunk, fragments, components)
|
||||
for new_place = new_entity_count + 1, new_entity_count + old_entity_count do
|
||||
new_component_storage[new_place] = new_component
|
||||
end
|
||||
else
|
||||
local new_component = components[i]
|
||||
|
||||
if new_component == nil then
|
||||
new_component = true
|
||||
end
|
||||
|
||||
for new_place = new_entity_count + 1, new_entity_count + old_entity_count do
|
||||
new_component_storage[new_place] = new_component
|
||||
end
|
||||
end
|
||||
else
|
||||
-- nothing
|
||||
end
|
||||
@@ -1803,17 +1729,20 @@ local function __chunk_multi_assign(chunk, fragments, components)
|
||||
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
|
||||
if chunk.__has_set_or_assign_hooks and __fragment_has_set_or_assign_hooks(fragment) then
|
||||
if chunk_has_set_or_assign_hooks and __fragment_has_set_or_assign_hooks(fragment) then
|
||||
local component_index = chunk_component_indices[fragment]
|
||||
if component_index then
|
||||
local component_storage = chunk_component_storages[component_index]
|
||||
if chunk.__has_defaults_or_constructs and __fragment_has_default_or_construct(fragment) then
|
||||
|
||||
local new_component = components[i]
|
||||
|
||||
if new_component == nil then
|
||||
if new_component == nil and chunk_has_defaults_or_constructs then
|
||||
new_component = evolved.get(fragment, evolved.DEFAULT)
|
||||
end
|
||||
|
||||
@@ -1827,20 +1756,6 @@ local function __chunk_multi_assign(chunk, fragments, components)
|
||||
component_storage[place] = new_component
|
||||
__fragment_call_set_and_assign_hooks(entity, fragment, new_component, old_component)
|
||||
end
|
||||
else
|
||||
local new_component = components[i]
|
||||
|
||||
if new_component == nil then
|
||||
new_component = true
|
||||
end
|
||||
|
||||
for place = 1, chunk_entity_count do
|
||||
local entity = chunk_entities[place]
|
||||
local old_component = component_storage[place]
|
||||
component_storage[place] = new_component
|
||||
__fragment_call_set_and_assign_hooks(entity, fragment, new_component, old_component)
|
||||
end
|
||||
end
|
||||
else
|
||||
for place = 1, chunk_entity_count do
|
||||
local entity = chunk_entities[place]
|
||||
@@ -1851,10 +1766,10 @@ local function __chunk_multi_assign(chunk, fragments, components)
|
||||
local component_index = chunk_component_indices[fragment]
|
||||
if component_index then
|
||||
local component_storage = chunk_component_storages[component_index]
|
||||
if chunk.__has_defaults_or_constructs and __fragment_has_default_or_construct(fragment) then
|
||||
|
||||
local new_component = components[i]
|
||||
|
||||
if new_component == nil then
|
||||
if new_component == nil and chunk_has_defaults_or_constructs then
|
||||
new_component = evolved.get(fragment, evolved.DEFAULT)
|
||||
end
|
||||
|
||||
@@ -1865,17 +1780,6 @@ local function __chunk_multi_assign(chunk, fragments, components)
|
||||
for place = 1, chunk_entity_count do
|
||||
component_storage[place] = new_component
|
||||
end
|
||||
else
|
||||
local new_component = components[i]
|
||||
|
||||
if new_component == nil then
|
||||
new_component = true
|
||||
end
|
||||
|
||||
for place = 1, chunk_entity_count do
|
||||
component_storage[place] = new_component
|
||||
end
|
||||
end
|
||||
else
|
||||
-- nothing
|
||||
end
|
||||
@@ -1886,11 +1790,11 @@ local function __chunk_multi_assign(chunk, fragments, components)
|
||||
return chunk_entity_count
|
||||
end
|
||||
|
||||
---@param chunk evolved.chunk
|
||||
---@param old_chunk evolved.chunk
|
||||
---@param fragments evolved.fragment[]
|
||||
---@param components evolved.component[]
|
||||
---@return integer inserted_count
|
||||
local function __chunk_multi_insert(chunk, fragments, components)
|
||||
local function __chunk_multi_insert(old_chunk, fragments, components)
|
||||
if __defer_depth <= 0 then
|
||||
error('batched chunk operations should be deferred', 2)
|
||||
end
|
||||
@@ -1901,8 +1805,7 @@ local function __chunk_multi_insert(chunk, fragments, components)
|
||||
return 0
|
||||
end
|
||||
|
||||
local old_chunk = chunk
|
||||
local new_chunk = __chunk_with_fragment_list(chunk, fragments)
|
||||
local new_chunk = __chunk_with_fragment_list(old_chunk, fragments)
|
||||
|
||||
if not new_chunk or old_chunk == new_chunk then
|
||||
return 0
|
||||
@@ -1922,6 +1825,9 @@ local function __chunk_multi_insert(chunk, fragments, components)
|
||||
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
|
||||
|
||||
do
|
||||
new_chunk.__entity_count = new_entity_count + old_entity_count
|
||||
|
||||
@@ -1946,14 +1852,14 @@ local function __chunk_multi_insert(chunk, fragments, components)
|
||||
local fragment = fragments[i]
|
||||
if not inserted_set[fragment] and not old_fragment_set[fragment] then
|
||||
inserted_set[fragment] = true
|
||||
if new_chunk.__has_set_or_insert_hooks and __fragment_has_set_or_insert_hooks(fragment) then
|
||||
if new_chunk_has_set_or_insert_hooks and __fragment_has_set_or_insert_hooks(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]
|
||||
if new_chunk.__has_defaults_or_constructs and __fragment_has_default_or_construct(fragment) then
|
||||
|
||||
local new_component = components[i]
|
||||
|
||||
if new_component == nil then
|
||||
if new_component == nil and new_chunk_has_defaults_or_constructs then
|
||||
new_component = evolved.get(fragment, evolved.DEFAULT)
|
||||
end
|
||||
|
||||
@@ -1966,19 +1872,6 @@ local function __chunk_multi_insert(chunk, fragments, components)
|
||||
new_component_storage[new_place] = new_component
|
||||
__fragment_call_set_and_insert_hooks(entity, fragment, new_component)
|
||||
end
|
||||
else
|
||||
local new_component = components[i]
|
||||
|
||||
if new_component == nil then
|
||||
new_component = true
|
||||
end
|
||||
|
||||
for new_place = new_entity_count + 1, new_entity_count + old_entity_count do
|
||||
local entity = new_entities[new_place]
|
||||
new_component_storage[new_place] = new_component
|
||||
__fragment_call_set_and_insert_hooks(entity, fragment, new_component)
|
||||
end
|
||||
end
|
||||
else
|
||||
for new_place = new_entity_count + 1, new_entity_count + old_entity_count do
|
||||
local entity = new_entities[new_place]
|
||||
@@ -1989,10 +1882,10 @@ local function __chunk_multi_insert(chunk, fragments, components)
|
||||
local new_component_index = new_component_indices[fragment]
|
||||
if new_component_index then
|
||||
local new_component_storage = new_component_storages[new_component_index]
|
||||
if new_chunk.__has_defaults_or_constructs and __fragment_has_default_or_construct(fragment) then
|
||||
|
||||
local new_component = components[i]
|
||||
|
||||
if new_component == nil then
|
||||
if new_component == nil and new_chunk_has_defaults_or_constructs then
|
||||
new_component = evolved.get(fragment, evolved.DEFAULT)
|
||||
end
|
||||
|
||||
@@ -2003,17 +1896,6 @@ local function __chunk_multi_insert(chunk, fragments, components)
|
||||
for new_place = new_entity_count + 1, new_entity_count + old_entity_count do
|
||||
new_component_storage[new_place] = new_component
|
||||
end
|
||||
else
|
||||
local new_component = components[i]
|
||||
|
||||
if new_component == nil then
|
||||
new_component = true
|
||||
end
|
||||
|
||||
for new_place = new_entity_count + 1, new_entity_count + old_entity_count do
|
||||
new_component_storage[new_place] = new_component
|
||||
end
|
||||
end
|
||||
else
|
||||
-- nothing
|
||||
end
|
||||
@@ -2046,10 +1928,10 @@ local function __chunk_multi_insert(chunk, fragments, components)
|
||||
return old_entity_count
|
||||
end
|
||||
|
||||
---@param chunk evolved.chunk
|
||||
---@param old_chunk evolved.chunk
|
||||
---@param fragments evolved.fragment[]
|
||||
---@return integer removed_count
|
||||
local function __chunk_multi_remove(chunk, fragments)
|
||||
local function __chunk_multi_remove(old_chunk, fragments)
|
||||
if __defer_depth <= 0 then
|
||||
error('batched chunk operations should be deferred', 2)
|
||||
end
|
||||
@@ -2060,8 +1942,7 @@ local function __chunk_multi_remove(chunk, fragments)
|
||||
return 0
|
||||
end
|
||||
|
||||
local old_chunk = chunk
|
||||
local new_chunk = __chunk_without_fragment_list(chunk, fragments)
|
||||
local new_chunk = __chunk_without_fragment_list(old_chunk, fragments)
|
||||
|
||||
if old_chunk == new_chunk then
|
||||
return 0
|
||||
@@ -2080,15 +1961,11 @@ local function __chunk_multi_remove(chunk, fragments)
|
||||
|
||||
for i = 1, fragment_count do
|
||||
local fragment = fragments[i]
|
||||
|
||||
if not removed_set[fragment] and old_fragment_set[fragment] and __fragment_has_remove_hook(fragment) then
|
||||
removed_set[fragment] = true
|
||||
|
||||
local old_component_index = old_component_indices[fragment]
|
||||
|
||||
if old_component_index then
|
||||
local old_component_storage = old_component_storages[old_component_index]
|
||||
|
||||
for old_place = 1, old_entity_count do
|
||||
local entity = old_entities[old_place]
|
||||
local old_component = old_component_storage[old_place]
|
||||
@@ -2223,9 +2100,10 @@ local function __spawn_entity_at(entity, chunk, fragments, components)
|
||||
local chunk_has_set_or_insert_hooks = chunk.__has_set_or_insert_hooks
|
||||
|
||||
local place = chunk_entity_count + 1
|
||||
chunk_entities[place] = entity
|
||||
chunk.__entity_count = place
|
||||
|
||||
chunk_entities[place] = entity
|
||||
|
||||
if chunk_has_defaults_or_constructs then
|
||||
for i = 1, chunk_component_count do
|
||||
local fragment = chunk_component_fragments[i]
|
||||
@@ -2335,9 +2213,10 @@ local function __spawn_entity_with(entity, chunk, fragments, components)
|
||||
local chunk_has_set_or_insert_hooks = chunk.__has_set_or_insert_hooks
|
||||
|
||||
local place = chunk_entity_count + 1
|
||||
chunk_entities[place] = entity
|
||||
chunk.__entity_count = place
|
||||
|
||||
chunk_entities[place] = entity
|
||||
|
||||
if chunk_has_defaults_or_constructs then
|
||||
for i = 1, #fragments do
|
||||
local fragment = fragments[i]
|
||||
@@ -3642,10 +3521,12 @@ function evolved.set(entity, fragment, ...)
|
||||
end
|
||||
else
|
||||
local new_entities = new_chunk.__entities
|
||||
local new_entity_count = new_chunk.__entity_count
|
||||
|
||||
local new_component_indices = new_chunk.__component_indices
|
||||
local new_component_storages = new_chunk.__component_storages
|
||||
|
||||
local new_place = new_chunk.__entity_count + 1
|
||||
local new_place = new_entity_count + 1
|
||||
new_chunk.__entity_count = new_place
|
||||
|
||||
new_entities[new_place] = entity
|
||||
@@ -3816,10 +3697,12 @@ function evolved.insert(entity, fragment, ...)
|
||||
|
||||
do
|
||||
local new_entities = new_chunk.__entities
|
||||
local new_entity_count = new_chunk.__entity_count
|
||||
|
||||
local new_component_indices = new_chunk.__component_indices
|
||||
local new_component_storages = new_chunk.__component_storages
|
||||
|
||||
local new_place = new_chunk.__entity_count + 1
|
||||
local new_place = new_entity_count + 1
|
||||
new_chunk.__entity_count = new_place
|
||||
|
||||
new_entities[new_place] = entity
|
||||
@@ -3922,9 +3805,12 @@ function evolved.remove(entity, ...)
|
||||
local old_component_storages = old_chunk.__component_storages
|
||||
|
||||
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, ...)
|
||||
if old_fragment_set[fragment] then
|
||||
if not removed_set[fragment] and old_fragment_set[fragment] then
|
||||
removed_set[fragment] = true
|
||||
local old_component_index = old_component_indices[fragment]
|
||||
if old_component_index then
|
||||
local old_component_storage = old_component_storages[old_component_index]
|
||||
@@ -3935,15 +3821,19 @@ function evolved.remove(entity, ...)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
__release_table(__TABLE_POOL_TAG__FRAGMENT_SET, removed_set)
|
||||
end
|
||||
|
||||
if new_chunk then
|
||||
local new_entities = new_chunk.__entities
|
||||
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_chunk.__entity_count + 1
|
||||
local new_place = new_entity_count + 1
|
||||
new_chunk.__entity_count = new_place
|
||||
|
||||
new_entities[new_place] = entity
|
||||
@@ -4004,16 +3894,16 @@ function evolved.clear(entity)
|
||||
__defer()
|
||||
|
||||
do
|
||||
local fragment_list = chunk.__fragment_list
|
||||
local component_indices = chunk.__component_indices
|
||||
local component_storages = chunk.__component_storages
|
||||
|
||||
if chunk.__has_remove_hooks then
|
||||
for i = 1, #fragment_list do
|
||||
local fragment = fragment_list[i]
|
||||
local component_index = component_indices[fragment]
|
||||
local chunk_fragment_list = chunk.__fragment_list
|
||||
local chunk_fragment_count = chunk.__fragment_count
|
||||
local chunk_component_indices = chunk.__component_indices
|
||||
local chunk_component_storages = chunk.__component_storages
|
||||
for i = 1, chunk_fragment_count do
|
||||
local fragment = chunk_fragment_list[i]
|
||||
local component_index = chunk_component_indices[fragment]
|
||||
if component_index then
|
||||
local component_storage = component_storages[component_index]
|
||||
local component_storage = chunk_component_storages[component_index]
|
||||
local old_component = component_storage[place]
|
||||
__fragment_call_remove_hook(entity, fragment, old_component)
|
||||
else
|
||||
@@ -4063,16 +3953,16 @@ function evolved.destroy(entity)
|
||||
__defer()
|
||||
|
||||
do
|
||||
local fragment_list = chunk.__fragment_list
|
||||
local component_indices = chunk.__component_indices
|
||||
local component_storages = chunk.__component_storages
|
||||
|
||||
if chunk.__has_remove_hooks then
|
||||
for i = 1, #fragment_list do
|
||||
local fragment = fragment_list[i]
|
||||
local component_index = component_indices[fragment]
|
||||
local chunk_fragment_list = chunk.__fragment_list
|
||||
local chunk_fragment_count = chunk.__fragment_count
|
||||
local chunk_component_indices = chunk.__component_indices
|
||||
local chunk_component_storages = chunk.__component_storages
|
||||
for i = 1, chunk_fragment_count do
|
||||
local fragment = chunk_fragment_list[i]
|
||||
local component_index = chunk_component_indices[fragment]
|
||||
if component_index then
|
||||
local component_storage = component_storages[component_index]
|
||||
local component_storage = chunk_component_storages[component_index]
|
||||
local old_component = component_storage[place]
|
||||
__fragment_call_remove_hook(entity, fragment, old_component)
|
||||
else
|
||||
@@ -4140,18 +4030,19 @@ function evolved.multi_set(entity, fragments, components)
|
||||
local old_component_indices = old_chunk.__component_indices
|
||||
local old_component_storages = old_chunk.__component_storages
|
||||
|
||||
local old_chunk_has_defaults_or_constructs = old_chunk.__has_defaults_or_constructs
|
||||
local old_chunk_has_set_or_assign_hooks = old_chunk.__has_set_or_assign_hooks
|
||||
|
||||
for i = 1, fragment_count do
|
||||
local fragment = fragments[i]
|
||||
if old_fragment_set[fragment] then
|
||||
local old_component_index = old_component_indices[fragment]
|
||||
|
||||
if old_component_index then
|
||||
local old_component_storage = old_component_storages[old_component_index]
|
||||
|
||||
if old_chunk.__has_defaults_or_constructs then
|
||||
local new_component = components[i]
|
||||
|
||||
if new_component == nil then
|
||||
if new_component == nil and old_chunk_has_defaults_or_constructs then
|
||||
new_component = evolved.get(fragment, evolved.DEFAULT)
|
||||
end
|
||||
|
||||
@@ -4159,7 +4050,7 @@ function evolved.multi_set(entity, fragments, components)
|
||||
new_component = true
|
||||
end
|
||||
|
||||
if old_chunk.__has_set_or_assign_hooks then
|
||||
if old_chunk_has_set_or_assign_hooks then
|
||||
local old_component = old_component_storage[old_place]
|
||||
old_component_storage[old_place] = new_component
|
||||
__fragment_call_set_and_assign_hooks(entity, fragment, new_component, old_component)
|
||||
@@ -4167,22 +4058,7 @@ function evolved.multi_set(entity, fragments, components)
|
||||
old_component_storage[old_place] = new_component
|
||||
end
|
||||
else
|
||||
local new_component = components[i]
|
||||
|
||||
if new_component == nil then
|
||||
new_component = true
|
||||
end
|
||||
|
||||
if old_chunk.__has_set_or_assign_hooks then
|
||||
local old_component = old_component_storage[old_place]
|
||||
old_component_storage[old_place] = new_component
|
||||
__fragment_call_set_and_assign_hooks(entity, fragment, new_component, old_component)
|
||||
else
|
||||
old_component_storage[old_place] = new_component
|
||||
end
|
||||
end
|
||||
else
|
||||
if old_chunk.__has_set_or_assign_hooks then
|
||||
if old_chunk_has_set_or_assign_hooks then
|
||||
__fragment_call_set_and_assign_hooks(entity, fragment)
|
||||
end
|
||||
end
|
||||
@@ -4190,12 +4066,18 @@ function evolved.multi_set(entity, fragments, components)
|
||||
end
|
||||
else
|
||||
local new_entities = new_chunk.__entities
|
||||
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_assign_hooks = new_chunk.__has_set_or_assign_hooks
|
||||
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 __EMPTY_FRAGMENT_SET
|
||||
|
||||
local new_place = new_chunk.__entity_count + 1
|
||||
local new_place = new_entity_count + 1
|
||||
new_chunk.__entity_count = new_place
|
||||
|
||||
new_entities[new_place] = entity
|
||||
@@ -4224,14 +4106,12 @@ function evolved.multi_set(entity, fragments, components)
|
||||
local fragment = fragments[i]
|
||||
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]
|
||||
|
||||
if new_chunk.__has_defaults_or_constructs then
|
||||
local new_component = components[i]
|
||||
|
||||
if new_component == nil then
|
||||
if new_component == nil and new_chunk_has_defaults_or_constructs then
|
||||
new_component = evolved.get(fragment, evolved.DEFAULT)
|
||||
end
|
||||
|
||||
@@ -4239,7 +4119,7 @@ function evolved.multi_set(entity, fragments, components)
|
||||
new_component = true
|
||||
end
|
||||
|
||||
if new_chunk.__has_set_or_assign_hooks then
|
||||
if new_chunk_has_set_or_assign_hooks then
|
||||
local old_component = new_component_storage[new_place]
|
||||
new_component_storage[new_place] = new_component
|
||||
__fragment_call_set_and_assign_hooks(entity, fragment, new_component, old_component)
|
||||
@@ -4247,37 +4127,19 @@ function evolved.multi_set(entity, fragments, components)
|
||||
new_component_storage[new_place] = new_component
|
||||
end
|
||||
else
|
||||
local new_component = components[i]
|
||||
|
||||
if new_component == nil then
|
||||
new_component = true
|
||||
end
|
||||
|
||||
if new_chunk.__has_set_or_assign_hooks then
|
||||
local old_component = new_component_storage[new_place]
|
||||
new_component_storage[new_place] = new_component
|
||||
__fragment_call_set_and_assign_hooks(entity, fragment, new_component, old_component)
|
||||
else
|
||||
new_component_storage[new_place] = new_component
|
||||
end
|
||||
end
|
||||
else
|
||||
if new_chunk.__has_set_or_assign_hooks then
|
||||
if new_chunk_has_set_or_assign_hooks then
|
||||
__fragment_call_set_and_assign_hooks(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]
|
||||
|
||||
if new_chunk.__has_defaults_or_constructs then
|
||||
local new_component = components[i]
|
||||
|
||||
if new_component == nil then
|
||||
if new_component == nil and new_chunk_has_defaults_or_constructs then
|
||||
new_component = evolved.get(fragment, evolved.DEFAULT)
|
||||
end
|
||||
|
||||
@@ -4287,24 +4149,11 @@ function evolved.multi_set(entity, fragments, components)
|
||||
|
||||
new_component_storage[new_place] = new_component
|
||||
|
||||
if new_chunk.__has_set_or_insert_hooks then
|
||||
if new_chunk_has_set_or_insert_hooks then
|
||||
__fragment_call_set_and_insert_hooks(entity, fragment, new_component)
|
||||
end
|
||||
else
|
||||
local new_component = components[i]
|
||||
|
||||
if new_component == nil then
|
||||
new_component = true
|
||||
end
|
||||
|
||||
new_component_storage[new_place] = new_component
|
||||
|
||||
if new_chunk.__has_set_or_insert_hooks then
|
||||
__fragment_call_set_and_insert_hooks(entity, fragment, new_component)
|
||||
end
|
||||
end
|
||||
else
|
||||
if new_chunk.__has_set_or_insert_hooks then
|
||||
if new_chunk_has_set_or_insert_hooks then
|
||||
__fragment_call_set_and_insert_hooks(entity, fragment)
|
||||
end
|
||||
end
|
||||
@@ -4360,22 +4209,23 @@ function evolved.multi_assign(entity, fragments, components)
|
||||
__defer()
|
||||
|
||||
do
|
||||
local fragment_set = chunk.__fragment_set
|
||||
local component_indices = chunk.__component_indices
|
||||
local component_storages = chunk.__component_storages
|
||||
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 fragment_set[fragment] then
|
||||
local component_index = component_indices[fragment]
|
||||
|
||||
if chunk_fragment_set[fragment] then
|
||||
local component_index = chunk_component_indices[fragment]
|
||||
if component_index then
|
||||
local component_storage = component_storages[component_index]
|
||||
local component_storage = chunk_component_storages[component_index]
|
||||
|
||||
if chunk.__has_defaults_or_constructs then
|
||||
local new_component = components[i]
|
||||
|
||||
if new_component == nil then
|
||||
if new_component == nil and chunk_has_defaults_or_constructs then
|
||||
new_component = evolved.get(fragment, evolved.DEFAULT)
|
||||
end
|
||||
|
||||
@@ -4383,7 +4233,7 @@ function evolved.multi_assign(entity, fragments, components)
|
||||
new_component = true
|
||||
end
|
||||
|
||||
if chunk.__has_set_or_assign_hooks then
|
||||
if chunk_has_set_or_assign_hooks then
|
||||
local old_component = component_storage[place]
|
||||
component_storage[place] = new_component
|
||||
__fragment_call_set_and_assign_hooks(entity, fragment, new_component, old_component)
|
||||
@@ -4391,22 +4241,7 @@ function evolved.multi_assign(entity, fragments, components)
|
||||
component_storage[place] = new_component
|
||||
end
|
||||
else
|
||||
local new_component = components[i]
|
||||
|
||||
if new_component == nil then
|
||||
new_component = true
|
||||
end
|
||||
|
||||
if chunk.__has_set_or_assign_hooks then
|
||||
local old_component = component_storage[place]
|
||||
component_storage[place] = new_component
|
||||
__fragment_call_set_and_assign_hooks(entity, fragment, new_component, old_component)
|
||||
else
|
||||
component_storage[place] = new_component
|
||||
end
|
||||
end
|
||||
else
|
||||
if chunk.__has_set_or_assign_hooks then
|
||||
if chunk_has_set_or_assign_hooks then
|
||||
__fragment_call_set_and_assign_hooks(entity, fragment)
|
||||
end
|
||||
end
|
||||
@@ -4461,12 +4296,17 @@ function evolved.multi_insert(entity, fragments, components)
|
||||
|
||||
do
|
||||
local new_entities = new_chunk.__entities
|
||||
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 __EMPTY_FRAGMENT_SET
|
||||
|
||||
local new_place = new_chunk.__entity_count + 1
|
||||
local new_place = new_entity_count + 1
|
||||
new_chunk.__entity_count = new_place
|
||||
|
||||
new_entities[new_place] = entity
|
||||
@@ -4495,16 +4335,13 @@ function evolved.multi_insert(entity, fragments, components)
|
||||
local fragment = fragments[i]
|
||||
if not inserted_set[fragment] and not old_fragment_set[fragment] then
|
||||
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]
|
||||
|
||||
if new_chunk.__has_defaults_or_constructs then
|
||||
local new_component = components[i]
|
||||
|
||||
if new_component == nil then
|
||||
if new_component == nil and new_chunk_has_defaults_or_constructs then
|
||||
new_component = evolved.get(fragment, evolved.DEFAULT)
|
||||
end
|
||||
|
||||
@@ -4514,24 +4351,11 @@ function evolved.multi_insert(entity, fragments, components)
|
||||
|
||||
new_component_storage[new_place] = new_component
|
||||
|
||||
if new_chunk.__has_set_or_insert_hooks then
|
||||
if new_chunk_has_set_or_insert_hooks then
|
||||
__fragment_call_set_and_insert_hooks(entity, fragment, new_component)
|
||||
end
|
||||
else
|
||||
local new_component = components[i]
|
||||
|
||||
if new_component == nil then
|
||||
new_component = true
|
||||
end
|
||||
|
||||
new_component_storage[new_place] = new_component
|
||||
|
||||
if new_chunk.__has_set_or_insert_hooks then
|
||||
__fragment_call_set_and_insert_hooks(entity, fragment, new_component)
|
||||
end
|
||||
end
|
||||
else
|
||||
if new_chunk.__has_set_or_insert_hooks then
|
||||
if new_chunk_has_set_or_insert_hooks then
|
||||
__fragment_call_set_and_insert_hooks(entity, fragment)
|
||||
end
|
||||
end
|
||||
@@ -4614,11 +4438,13 @@ function evolved.multi_remove(entity, fragments)
|
||||
|
||||
if new_chunk then
|
||||
local new_entities = new_chunk.__entities
|
||||
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_chunk.__entity_count + 1
|
||||
local new_place = new_entity_count + 1
|
||||
new_chunk.__entity_count = new_place
|
||||
|
||||
new_entities[new_place] = entity
|
||||
|
||||
Reference in New Issue
Block a user