Fix bulk_insert with moving archetypes (#272)
Some checks failed
analysis / Run Luau Analyze (push) Has been cancelled
deploy-docs / build (push) Has been cancelled
publish-npm / publish (push) Has been cancelled
unit-testing / Run Luau Tests (push) Has been cancelled
deploy-docs / Deploy (push) Has been cancelled

* Fix bulk_insert with moving archetypes

* Reword message
This commit is contained in:
dai 2025-08-21 21:32:11 +02:00 committed by GitHub
parent 51b09549db
commit 0874e426af
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 33 additions and 6 deletions

View file

@ -2110,15 +2110,13 @@ local function ecs_bulk_insert(world: world, entity: i53, ids: { i53 }, values:
local dst_types = ids local dst_types = ids
local to = archetype_ensure(world, dst_types) local to = archetype_ensure(world, dst_types)
new_entity(entity, r, to) new_entity(entity, r, to)
local row = r.row
local columns_map = to.columns_map
for i, id in ids do for i, id in ids do
local value = values[i] local value = values[i]
local cdr = component_index[id] local cdr = component_index[id]
local on_add = cdr.on_add local on_add = cdr.on_add
if value then if value then
columns_map[id][row] = value r.archetype.columns_map[id][r.row] = value
if on_add then if on_add then
on_add(entity, id, value :: any) on_add(entity, id, value :: any)
end end
@ -2148,12 +2146,10 @@ local function ecs_bulk_insert(world: world, entity: i53, ids: { i53 }, values:
end end
local to = archetype_ensure(world, dst_types) local to = archetype_ensure(world, dst_types)
local columns_map = to.columns_map
if from ~= to then if from ~= to then
entity_move(entity_index, entity, r, to) entity_move(entity_index, entity, r, to)
end end
local row = r.row
for i, set in emplaced do for i, set in emplaced do
local id = ids[i] local id = ids[i]
@ -2164,7 +2160,7 @@ local function ecs_bulk_insert(world: world, entity: i53, ids: { i53 }, values:
local on_add = idr.on_add local on_add = idr.on_add
if value ~= nil then if value ~= nil then
columns_map[id][row] = value r.archetype.columns_map[id][r.row] = value
local on_change = idr.on_change local on_change = idr.on_change
local hook = if set then on_change else on_add local hook = if set then on_change else on_add
if hook then if hook then

View file

@ -331,6 +331,37 @@ TEST("bulk", function()
CHECK(world:has(e, c1, c2, c3)) CHECK(world:has(e, c1, c2, c3))
CHECK(count == 3) CHECK(count == 3)
end end
do CASE "Should bulk add with hooks moving archetypes without previous"
local world = jecs.world()
local c1, c2, c3 = world:component(), world:component(), world:component()
world:added(c1, function(e)
world:set(e, c3, "hello")
end)
local e = world:entity()
jecs.bulk_insert(world, e, {c1,c2}, {true, 123})
CHECK(world:get(e, c1) == true)
CHECK(world:get(e, c2) == 123)
CHECK(world:get(e, c3) == "hello")
end
do CASE "Should bulk add with hooks moving archetypes with previous"
local world = jecs.world()
local c1, c2, c3 = world:component(), world:component(), world:component()
world:added(c1, function(e)
world:set(e, c3, "hello")
end)
local e = world:entity()
world:add(e, world:entity())
jecs.bulk_insert(world, e, {c1,c2}, {true, 123})
CHECK(world:get(e, c1) == true)
CHECK(world:get(e, c2) == 123)
CHECK(world:get(e, c3) == "hello")
end
end) end)
TEST("repro", function() TEST("repro", function()