fix: remove dup fragments events

This commit is contained in:
BlackMATov
2025-01-18 05:15:32 +07:00
parent 9cbb808a10
commit 738a4fd7b1
2 changed files with 17 additions and 4 deletions

View File

@@ -1249,7 +1249,7 @@ do
local q = evo.id()
evo.insert(q, evo.INCLUDES, f1, f2)
assert(evo.batch_remove(q, f2, f3) == 3)
assert(evo.batch_remove(q, f2, f3, f3) == 3)
assert(entity_sum == e2 + e3 * 2 + e4 * 2)
assert(component_sum == 43 + 45 + 46 + 48 + 49)

View File

@@ -1143,6 +1143,12 @@ local function __chunk_remove(chunk, ...)
error('batched chunk operations should be deferred', 2)
end
local fragment_count = select('#', ...)
if fragment_count == 0 then
return 0
end
local old_chunk = chunk
local new_chunk = __chunk_without_fragments(chunk, ...)
@@ -1153,17 +1159,24 @@ local function __chunk_remove(chunk, ...)
local old_entities = old_chunk.__entities
local old_size = #old_entities
local old_fragment_set = old_chunk.__fragment_set
local old_component_indices = chunk.__component_indices
local old_component_storages = chunk.__component_storages
if old_chunk.__has_remove_hooks then
local old_fragment_set = old_chunk.__fragment_set
for i = 1, select('#', ...) do
local removed_set = __acquire_table(__TABLE_POOL_TAG__FRAGMENT_SET, 0, fragment_count)
for i = 1, fragment_count do
local fragment = select(i, ...)
if old_fragment_set[fragment] and __fragment_has_remove_hook(fragment) then
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_size do
local entity = old_entities[old_place]
local old_component = old_component_storage[old_place]