mirror of
https://github.com/Ukendio/jecs.git
synced 2025-09-14 04:29:18 +00:00
Fix bulk_insert
not ensuring that archetype ids are sorted (#277)
* Fix bulk_insert not ensuring archetype ids are sorted * Add test case
This commit is contained in:
parent
af093713b4
commit
d8b2d36c52
2 changed files with 17 additions and 1 deletions
|
@ -2050,7 +2050,9 @@ local function ecs_bulk_insert(world: world, entity: i53, ids: { i53 }, values:
|
||||||
local from = r.archetype
|
local from = r.archetype
|
||||||
local component_index = world.component_index
|
local component_index = world.component_index
|
||||||
if not from then
|
if not from then
|
||||||
local dst_types = ids
|
local dst_types = table.clone(ids)
|
||||||
|
table.sort(dst_types)
|
||||||
|
|
||||||
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 ROOT_ARCHETYPE = world.ROOT_ARCHETYPE
|
local ROOT_ARCHETYPE = world.ROOT_ARCHETYPE
|
||||||
|
|
|
@ -330,6 +330,20 @@ TEST("bulk", function()
|
||||||
CHECK(world:get(e, c2) == 123)
|
CHECK(world:get(e, c2) == 123)
|
||||||
CHECK(world:get(e, c3) == "hello")
|
CHECK(world:get(e, c3) == "hello")
|
||||||
end
|
end
|
||||||
|
|
||||||
|
do CASE "Should ensure archetype ids are sorted"
|
||||||
|
local world = jecs.world()
|
||||||
|
local c1, c2, c3 = world:component(), world:component(), world:component()
|
||||||
|
|
||||||
|
local e = world:entity()
|
||||||
|
jecs.bulk_insert(world, e, { c2, c1 }, { 2, 1 })
|
||||||
|
jecs.bulk_insert(world, e, { c1 }, { 1 })
|
||||||
|
world:set(e, c3, 3)
|
||||||
|
|
||||||
|
CHECK(world:get(e, c1) == 1)
|
||||||
|
CHECK(world:get(e, c2) == 2)
|
||||||
|
CHECK(world:get(e, c3) == 3)
|
||||||
|
end
|
||||||
end)
|
end)
|
||||||
|
|
||||||
TEST("repro", function()
|
TEST("repro", function()
|
||||||
|
|
Loading…
Reference in a new issue