mirror of
https://github.com/Ukendio/jecs.git
synced 2025-09-23 16:39:17 +00:00
Compare commits
3 commits
6863b905d8
...
c73f484560
Author | SHA1 | Date | |
---|---|---|---|
|
c73f484560 | ||
|
1eecaac96f | ||
|
d8b2d36c52 |
2 changed files with 21 additions and 13 deletions
20
jecs.luau
20
jecs.luau
|
@ -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
|
||||||
|
|
|
@ -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