mirror of
https://github.com/Ukendio/jecs.git
synced 2025-08-04 11:19:17 +00:00
Compare commits
3 commits
6b85195c1a
...
96dc0e4ac3
Author | SHA1 | Date | |
---|---|---|---|
|
96dc0e4ac3 | ||
|
a6ae67250c | ||
|
9ae32bcce8 |
1 changed files with 29 additions and 15 deletions
|
@ -1,20 +1,35 @@
|
||||||
--!strict
|
--!strict
|
||||||
local jecs = require("@jecs")
|
local jecs = require("@jecs")
|
||||||
|
|
||||||
|
|
||||||
|
type Description<T...> = jecs.Query<T...>
|
||||||
|
|
||||||
|
type ObserverArm = (<a>(
|
||||||
|
PatchedWorld,
|
||||||
|
{
|
||||||
|
query: jecs.Query<a>,
|
||||||
|
callback: ((jecs.Entity) -> ())?
|
||||||
|
}
|
||||||
|
) -> () -> () -> (jecs.Entity)) & (<a, b>(
|
||||||
|
PatchedWorld,
|
||||||
|
{
|
||||||
|
query: jecs.Query<a, b>,
|
||||||
|
callback: ((jecs.Entity) -> ())?
|
||||||
|
}
|
||||||
|
) -> () -> () -> (jecs.Entity)) & (<a, b, c>(
|
||||||
|
PatchedWorld,
|
||||||
|
{
|
||||||
|
query: jecs.Query<a, b, c>,
|
||||||
|
callback: ((jecs.Entity) -> ())?
|
||||||
|
}
|
||||||
|
) -> () -> () -> (jecs.Entity))
|
||||||
|
|
||||||
export type PatchedWorld = jecs.World & {
|
export type PatchedWorld = jecs.World & {
|
||||||
added: <T>(PatchedWorld, jecs.Id<T>, <e>(e: jecs.Entity<e>, id: jecs.Id<T>, value: T?) -> ()) -> () -> (),
|
added: <T>(PatchedWorld, jecs.Id<T>, <e>(e: jecs.Entity<e>, id: jecs.Id<T>, value: T?) -> ()) -> () -> (),
|
||||||
removed: <T>(PatchedWorld, jecs.Id<T>, (e: jecs.Entity, id: jecs.Id) -> ()) -> () -> (),
|
removed: <T>(PatchedWorld, jecs.Id<T>, (e: jecs.Entity, id: jecs.Id) -> ()) -> () -> (),
|
||||||
changed: <T>(PatchedWorld, jecs.Id<T>, <e>(e: jecs.Entity<e>, id: jecs.Id<T>, value: T) -> ()) -> () -> (),
|
changed: <T>(PatchedWorld, jecs.Id<T>, <e>(e: jecs.Entity<e>, id: jecs.Id<T>, value: T) -> ()) -> () -> (),
|
||||||
observer: <T...>(
|
observer: ObserverArm & any,
|
||||||
PatchedWorld,
|
monitor: ObserverArm & any
|
||||||
jecs.Query<T...>,
|
|
||||||
(<a>(jecs.Entity, jecs.Id<a>, a) -> ())?
|
|
||||||
) -> () -> (jecs.Entity),
|
|
||||||
monitor: (
|
|
||||||
PatchedWorld,
|
|
||||||
any,
|
|
||||||
(<a>(jecs.Entity, jecs.Id<a>) -> ())?
|
|
||||||
) -> ()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
local function observers_new(
|
local function observers_new(
|
||||||
|
@ -46,8 +61,7 @@ local function observers_new(
|
||||||
id: jecs.Id<a>,
|
id: jecs.Id<a>,
|
||||||
value: a?
|
value: a?
|
||||||
)
|
)
|
||||||
local r = jecs.entity_index_try_get_fast(
|
local r = entity_index.sparse_array[jecs.ECS_ID(entity)]
|
||||||
entity_index, entity :: any) :: jecs.Record
|
|
||||||
|
|
||||||
local archetype = r.archetype
|
local archetype = r.archetype
|
||||||
|
|
||||||
|
@ -68,9 +82,9 @@ local function observers_new(
|
||||||
return function()
|
return function()
|
||||||
local row = i
|
local row = i
|
||||||
return function()
|
return function()
|
||||||
if row == 0 then
|
if row == 0 then
|
||||||
i = 0
|
i = 0
|
||||||
table.clear(entities)
|
table.clear(entities)
|
||||||
end
|
end
|
||||||
local entity = entities[row]
|
local entity = entities[row]
|
||||||
row -= 1
|
row -= 1
|
||||||
|
|
Loading…
Reference in a new issue