mirror of
https://github.com/Ukendio/jecs.git
synced 2025-07-15 10:49:17 +00:00
Update hook retrieval
This commit is contained in:
parent
f6731069aa
commit
9ae32bcce8
1 changed files with 35 additions and 18 deletions
|
@ -1,28 +1,46 @@
|
||||||
--!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(
|
||||||
world: PatchedWorld,
|
world: PatchedWorld,
|
||||||
query: any,
|
description: {
|
||||||
callback: (<T, a>(jecs.Entity<T>, jecs.Id<a>, value: a?) -> ())?
|
query: any,
|
||||||
|
callback: (<T, a>(jecs.Entity<T>, jecs.Id<a>, value: a?) -> ())?
|
||||||
|
}
|
||||||
)
|
)
|
||||||
query = query:cached()
|
local query = description.query:cached()
|
||||||
|
local callback = description.callback
|
||||||
|
|
||||||
local archetypes = {}
|
local archetypes = {}
|
||||||
local terms = query.ids
|
local terms = query.ids
|
||||||
|
@ -46,8 +64,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 +85,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