Compare commits

..

1 commit

Author SHA1 Message Date
PepeElToro41
5bf0d80ca4
Merge f912866fcb into 51b09549db 2025-08-20 17:36:24 -06:00
2 changed files with 6 additions and 33 deletions

View file

@ -2120,13 +2120,15 @@ 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
r.archetype.columns_map[id][r.row] = value columns_map[id][row] = value
if on_add then if on_add then
on_add(entity, id, value :: any) on_add(entity, id, value :: any)
end end
@ -2156,10 +2158,12 @@ 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]
@ -2170,7 +2174,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
r.archetype.columns_map[id][r.row] = value columns_map[id][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,37 +331,6 @@ 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()