Compare commits

..

2 commits

Author SHA1 Message Date
PepeElToro41
1eecaac96f
fix types (#275)
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
2025-09-09 13:12:15 +02:00
Axen
d8b2d36c52
Fix bulk_insert not ensuring that archetype ids are sorted (#277)
* Fix bulk_insert not ensuring archetype ids are sorted

* Add test case
2025-09-09 13:11:55 +02:00
2 changed files with 21 additions and 13 deletions

View file

@ -41,16 +41,8 @@ export type Iter<T...> = (query: Query<T...>) -> () -> (Entity, T...)
export type Query<T...> = typeof(setmetatable( export type Query<T...> = typeof(setmetatable(
{} :: { {} :: {
iter: Iter<T...>, iter: Iter<T...>,
with: (<a>(Query<T...>, Id<a>) -> Query<T...>) with: ((Query<T...>, ...Id) -> Query<T...>),
& (<a, b>(Query<T...>, Id<a>, Id<b>) -> Query<T...>) without: ((Query<T...>, ...Id) -> Query<T...>),
& (<a, b, c>(Query<T...>, Id<a>, Id<b>, Id<c>) -> Query<T...>)
& (<a, b, c>(Query<T...>, Id<a>, Id<b>, Id<c>) -> Query<T...>)
& (<a, b, c, d>(Query<T...>, Id<a>, Id<b>, Id<c>, Id) -> Query<T...>),
without: (<a>(Query<T...>, Id<a>) -> Query<T...>)
& (<a, b>(Query<T...>, Id<a>, Id<b>) -> Query<T...>)
& (<a, b, c>(Query<T...>, Id<a>, Id<b>, Id<c>) -> Query<T...>)
& (<a, b, c>(Query<T...>, Id<a>, Id<b>, Id<c>) -> Query<T...>)
& (<a, b, c, d>(Query<T...>, Id<a>, Id<b>, Id<c>, Id) -> Query<T...>),
archetypes: (self: Query<T...>) -> { Archetype }, archetypes: (self: Query<T...>) -> { Archetype },
cached: (self: Query<T...>) -> Query<T...>, cached: (self: Query<T...>) -> Query<T...>,
ids: { Id<any> }, ids: { Id<any> },
@ -169,9 +161,9 @@ export type World = {
observable: Map<Id, Map<Id, { Observer }>>, observable: Map<Id, Map<Id, { Observer }>>,
added: <T>(World, Entity<T>, <e>(e: Entity<e>, id: Id<T>, value: T, oldarchetype: Archetype) -> ()) -> () -> (), added: <T>(World, Entity<T>, (e: Entity, id: Id<T>, value: T, oldarchetype: Archetype) -> ()) -> () -> (),
removed: <T>(World, Entity<T>, (e: Entity, id: Id<T>) -> ()) -> () -> (), removed: <T>(World, Entity<T>, (e: Entity, id: Id<T>) -> ()) -> () -> (),
changed: <T>(World, Entity<T>, <e>(e: Entity<e>, id: Id<T>, value: T, oldarchetype: Archetype) -> ()) -> () -> (), changed: <T>(World, Entity<T>, (e: Entity, id: Id<T>, value: T, oldarchetype: Archetype) -> ()) -> () -> (),
--- Enforce a check on entities to be created within desired range --- Enforce a check on entities to be created within desired range
range: (self: World, range_begin: number, range_end: number?) -> (), range: (self: World, range_begin: number, range_end: number?) -> (),
@ -2050,7 +2042,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

View file

@ -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()