Sync to upstream Jecs 0.6.0-rc.1-nightly.20250508T001059Z
This commit is contained in:
parent
ee45df6586
commit
8cd41f3043
8 changed files with 74 additions and 90 deletions
|
@ -6,9 +6,9 @@ type Observer<T...> = {
|
||||||
}
|
}
|
||||||
|
|
||||||
export type PatchedWorld = jecs.World & {
|
export type PatchedWorld = jecs.World & {
|
||||||
added: (PatchedWorld, jecs.Id, (e: jecs.Entity, id: jecs.Id, value: any) -> ()) -> (),
|
added: <T>(PatchedWorld, jecs.Id<T>, (e: jecs.Entity, id: jecs.Id, value: T) -> ()) -> () -> (),
|
||||||
removed: (PatchedWorld, jecs.Id, (e: jecs.Entity, id: jecs.Id) -> ()) -> (),
|
removed: <T>(PatchedWorld, jecs.Id<T>, (e: jecs.Entity, id: jecs.Id) -> ()) -> () -> (),
|
||||||
changed: (PatchedWorld, jecs.Id, (e: jecs.Entity, id: jecs.Id) -> ()) -> (),
|
changed: <T>(PatchedWorld, jecs.Id<T>, (e: jecs.Entity, id: jecs.Id, value: T) -> ()) -> () -> (),
|
||||||
observer: (PatchedWorld, Observer<any>) -> (),
|
observer: (PatchedWorld, Observer<any>) -> (),
|
||||||
monitor: (PatchedWorld, Observer<any>) -> (),
|
monitor: (PatchedWorld, Observer<any>) -> (),
|
||||||
}
|
}
|
||||||
|
@ -70,6 +70,7 @@ local function join(world, component)
|
||||||
sparse_array[entity] = nil
|
sparse_array[entity] = nil
|
||||||
dense_array[max_id] = nil
|
dense_array[max_id] = nil
|
||||||
values[max_id] = nil
|
values[max_id] = nil
|
||||||
|
max_id -= 1
|
||||||
end)
|
end)
|
||||||
|
|
||||||
world:changed(component, function(entity, id, value)
|
world:changed(component, function(entity, id, value)
|
||||||
|
@ -89,62 +90,6 @@ local function join(world, component)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
local function query_changed(world, component)
|
|
||||||
assert(jecs.IS_PAIR(component) == false)
|
|
||||||
local callerid = debug.info(2, "sl")
|
|
||||||
|
|
||||||
local tracker = world.trackers[callerid]
|
|
||||||
if not tracker then
|
|
||||||
local records = {}
|
|
||||||
local connections = {}
|
|
||||||
tracker = {
|
|
||||||
records = records,
|
|
||||||
connections = connections
|
|
||||||
}
|
|
||||||
world.trackers[callerid] = tracker
|
|
||||||
|
|
||||||
table.insert(connections, world:added(component, function(entity, id, v)
|
|
||||||
tracker[entity] = {
|
|
||||||
new = v
|
|
||||||
}
|
|
||||||
end))
|
|
||||||
table.insert(connections, world:changed(component, function(entity, id, v)
|
|
||||||
local record = tracker[entity]
|
|
||||||
record.old = record.new
|
|
||||||
record.new = v
|
|
||||||
end))
|
|
||||||
|
|
||||||
table.insert(connections, world:removed(component, function(entity, id)
|
|
||||||
local record = tracker[entity]
|
|
||||||
record.old = record.new
|
|
||||||
record.new = nil
|
|
||||||
end))
|
|
||||||
end
|
|
||||||
|
|
||||||
local entity = nil
|
|
||||||
local record = nil
|
|
||||||
return function()
|
|
||||||
entity, record = next(tracker, entity)
|
|
||||||
if entity == nil then
|
|
||||||
return
|
|
||||||
end
|
|
||||||
return entity, record
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
local function spy_on_world_delete(world)
|
|
||||||
local world_delete = world.delete
|
|
||||||
world.delete = function(world, entity)
|
|
||||||
world_delete(world, entity)
|
|
||||||
for _, tracker in world.trackers do
|
|
||||||
tracker.records[entity] = nil
|
|
||||||
for _, connection in tracker.connections do
|
|
||||||
connection()
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
local function monitors_new(world, description)
|
local function monitors_new(world, description)
|
||||||
local query = description.query
|
local query = description.query
|
||||||
local callback = description.callback
|
local callback = description.callback
|
||||||
|
@ -192,18 +137,23 @@ local function monitors_new(world, description)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
local function observers_add(world: jecs.World & { [string]: any }): PatchedWorld
|
local function observers_add(world: jecs.World): PatchedWorld
|
||||||
type Signal = { [jecs.Entity]: { (...any) -> () } }
|
type Signal = { [jecs.Entity]: { (...any) -> () } }
|
||||||
|
|
||||||
|
local world_mut = world :: jecs.World & {[string]: any}
|
||||||
|
|
||||||
local signals = {
|
local signals = {
|
||||||
added = {} :: Signal,
|
added = {} :: Signal,
|
||||||
emplaced = {} :: Signal,
|
emplaced = {} :: Signal,
|
||||||
removed = {} :: Signal
|
removed = {} :: Signal
|
||||||
}
|
}
|
||||||
|
|
||||||
world.added = function(_, component, fn)
|
world_mut.added = function<T>(
|
||||||
|
_: jecs.World,
|
||||||
|
component: jecs.Id<T>,
|
||||||
|
fn: (e: jecs.Entity, id: jecs.Id, value: T) -> ()
|
||||||
|
)
|
||||||
local listeners = signals.added[component]
|
local listeners = signals.added[component]
|
||||||
local component_index = world.component_index :: jecs.ComponentIndex
|
|
||||||
assert(component_index[component] == nil, "You cannot use hooks on components you intend to use this signal with")
|
|
||||||
if not listeners then
|
if not listeners then
|
||||||
listeners = {}
|
listeners = {}
|
||||||
signals.added[component] = listeners
|
signals.added[component] = listeners
|
||||||
|
@ -213,7 +163,16 @@ local function observers_add(world: jecs.World & { [string]: any }): PatchedWorl
|
||||||
listener(entity, id, value)
|
listener(entity, id, value)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
world:set(component, jecs.OnAdd, on_add)
|
local idr = world.component_index[component]
|
||||||
|
if idr then
|
||||||
|
local idr_hook_existing = idr.hooks.on_add
|
||||||
|
if idr_hook_existing then
|
||||||
|
table.insert(listeners, idr_hook_existing)
|
||||||
|
end
|
||||||
|
idr.hooks.on_add = on_add :: any
|
||||||
|
else
|
||||||
|
world:set(component, jecs.OnAdd, on_add)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
table.insert(listeners, fn)
|
table.insert(listeners, fn)
|
||||||
return function()
|
return function()
|
||||||
|
@ -224,10 +183,12 @@ local function observers_add(world: jecs.World & { [string]: any }): PatchedWorl
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
world.changed = function(_, component, fn)
|
world_mut.changed = function<T>(
|
||||||
|
_: jecs.World,
|
||||||
|
component: jecs.Id<T>,
|
||||||
|
fn: (e: jecs.Entity, id: jecs.Id, value: T) -> ()
|
||||||
|
)
|
||||||
local listeners = signals.emplaced[component]
|
local listeners = signals.emplaced[component]
|
||||||
local component_index = world.component_index :: jecs.ComponentIndex
|
|
||||||
assert(component_index[component] == nil, "You cannot use hooks on components you intend to use this signal with")
|
|
||||||
if not listeners then
|
if not listeners then
|
||||||
listeners = {}
|
listeners = {}
|
||||||
signals.emplaced[component] = listeners
|
signals.emplaced[component] = listeners
|
||||||
|
@ -236,7 +197,16 @@ local function observers_add(world: jecs.World & { [string]: any }): PatchedWorl
|
||||||
listener(entity, id, value)
|
listener(entity, id, value)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
world:set(component, jecs.OnChange, on_change)
|
local idr = world.component_index[component]
|
||||||
|
if idr then
|
||||||
|
local idr_hook_existing = idr.hooks.on_change
|
||||||
|
if idr_hook_existing then
|
||||||
|
table.insert(listeners, idr_hook_existing)
|
||||||
|
end
|
||||||
|
idr.hooks.on_change = on_change :: any
|
||||||
|
else
|
||||||
|
world:set(component, jecs.OnChange, on_change)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
table.insert(listeners, fn)
|
table.insert(listeners, fn)
|
||||||
return function()
|
return function()
|
||||||
|
@ -247,10 +217,12 @@ local function observers_add(world: jecs.World & { [string]: any }): PatchedWorl
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
world.removed = function(_, component, fn)
|
world_mut.removed = function<T>(
|
||||||
|
_: jecs.World,
|
||||||
|
component: jecs.Id<T>,
|
||||||
|
fn: (e: jecs.Entity, id: jecs.Id) -> ()
|
||||||
|
)
|
||||||
local listeners = signals.removed[component]
|
local listeners = signals.removed[component]
|
||||||
local component_index = world.component_index :: jecs.ComponentIndex
|
|
||||||
assert(component_index[component] == nil, "You cannot use hooks on components you intend to use this signal with")
|
|
||||||
if not listeners then
|
if not listeners then
|
||||||
listeners = {}
|
listeners = {}
|
||||||
signals.removed[component] = listeners
|
signals.removed[component] = listeners
|
||||||
|
@ -259,7 +231,16 @@ local function observers_add(world: jecs.World & { [string]: any }): PatchedWorl
|
||||||
listener(entity, id, value)
|
listener(entity, id, value)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
world:set(component, jecs.OnRemove, on_remove)
|
local idr = world.component_index[component]
|
||||||
|
if idr then
|
||||||
|
local idr_hook_existing = idr.hooks.on_remove
|
||||||
|
if idr_hook_existing then
|
||||||
|
table.insert(listeners, idr_hook_existing)
|
||||||
|
end
|
||||||
|
idr.hooks.on_remove = on_remove :: any
|
||||||
|
else
|
||||||
|
world:set(component, jecs.OnRemove, on_remove)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
table.insert(listeners, fn)
|
table.insert(listeners, fn)
|
||||||
return function()
|
return function()
|
||||||
|
@ -270,15 +251,15 @@ local function observers_add(world: jecs.World & { [string]: any }): PatchedWorl
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
world.signals = signals
|
world_mut.signals = signals
|
||||||
|
|
||||||
world.observer = observers_new
|
world_mut.observer = observers_new
|
||||||
|
|
||||||
world.monitor = monitors_new
|
world_mut.monitor = monitors_new
|
||||||
|
|
||||||
world.trackers = {}
|
world_mut.trackers = {}
|
||||||
|
|
||||||
return world :: PatchedWorld
|
return world_mut :: PatchedWorld
|
||||||
end
|
end
|
||||||
|
|
||||||
return observers_add
|
return observers_add
|
||||||
|
|
|
@ -1,2 +1,2 @@
|
||||||
modified = ["jecs.luau"]
|
modified = ["addons/observers.luau", "jecs.luau"]
|
||||||
version = "0.5.5-nightly.20250429T001100Z"
|
version = "0.6.0-rc.1-nightly.20250508T001059Z"
|
||||||
|
|
|
@ -2403,9 +2403,9 @@ export type ComponentRecord = {
|
||||||
flags: number,
|
flags: number,
|
||||||
size: number,
|
size: number,
|
||||||
hooks: {
|
hooks: {
|
||||||
on_add: ((entity: Entity) -> ())?,
|
on_add: (<T>(entity: Entity, id: Entity<T>, value: T) -> ())?,
|
||||||
on_set: ((entity: Entity, data: any) -> ())?,
|
on_change: (<T>(entity: Entity, id: Entity<T>, value: T) -> ())?,
|
||||||
on_remove: ((entity: Entity) -> ())?,
|
on_remove: ((entity: Entity, id: Entity) -> ())?,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
export type ComponentIndex = Map<Id, ComponentRecord>
|
export type ComponentIndex = Map<Id, ComponentRecord>
|
||||||
|
|
|
@ -3,7 +3,7 @@ includes = ["init.luau", "pesde.toml", "README.md", "CHANGELOG.md", "LICENSE", "
|
||||||
license = "MIT"
|
license = "MIT"
|
||||||
name = "marked/jecs_nightly"
|
name = "marked/jecs_nightly"
|
||||||
repository = "https://git.devmarked.win/marked/jecs-nightly"
|
repository = "https://git.devmarked.win/marked/jecs-nightly"
|
||||||
version = "0.5.5-nightly.20250429T001100Z"
|
version = "0.6.0-rc.1-nightly.20250508T001059Z"
|
||||||
|
|
||||||
[indices]
|
[indices]
|
||||||
default = "https://github.com/pesde-pkg/index"
|
default = "https://github.com/pesde-pkg/index"
|
||||||
|
|
|
@ -3,7 +3,7 @@ includes = ["init.luau", "pesde.toml", "README.md", "CHANGELOG.md", "LICENSE", "
|
||||||
license = "MIT"
|
license = "MIT"
|
||||||
name = "marked/jecs_nightly"
|
name = "marked/jecs_nightly"
|
||||||
repository = "https://git.devmarked.win/marked/jecs-nightly"
|
repository = "https://git.devmarked.win/marked/jecs-nightly"
|
||||||
version = "0.5.5-nightly.20250429T001100Z"
|
version = "0.6.0-rc.1-nightly.20250508T001059Z"
|
||||||
|
|
||||||
[indices]
|
[indices]
|
||||||
default = "https://github.com/pesde-pkg/index"
|
default = "https://github.com/pesde-pkg/index"
|
||||||
|
|
|
@ -1,2 +1,2 @@
|
||||||
passed = true
|
passed = true
|
||||||
timestamp = "20250507T001102Z"
|
timestamp = "20250508T001102Z"
|
||||||
|
|
|
@ -1,6 +1,9 @@
|
||||||
[38;1m7.2[0m [33;1mus[0m [38;1m 2[0m [33;1mkB[0m[38;1m│[0m [38;1mdelete children of entity[0m
|
[38;1m7.2[0m [33;1mus[0m [38;1m 3[0m [33;1mkB[0m[38;1m│[0m [38;1mdelete children of entity[0m
|
||||||
[38;1m9.6[0m [33;1mus[0m [38;1m 1[0m [33;1mkB[0m[38;1m│[0m [38;1mremove friends of entity[0m
|
[38;1m9.0[0m [33;1mus[0m [38;1m 1[0m [33;1mkB[0m[38;1m│[0m [38;1mremove friends of entity[0m
|
||||||
[38;1m347[0m [32;1mns[0m [38;1m 0[0m [32;1m B[0m[38;1m│[0m [38;1msimple deletion of entity[0m
|
[38;1m393[0m [32;1mns[0m [38;1m 0[0m [32;1m B[0m[38;1m│[0m [38;1msimple deletion of entity[0m
|
||||||
|
[37;1mrepro[0m
|
||||||
|
[38;5;208mNONE[0m[38;1m│[0m [38;1m[0m
|
||||||
|
|
||||||
[37;1mworld:add()[0m
|
[37;1mworld:add()[0m
|
||||||
[32;1mPASS[0m[38;1m│[0m [38;1midempotent[0m
|
[32;1mPASS[0m[38;1m│[0m [38;1midempotent[0m
|
||||||
[32;1mPASS[0m[38;1m│[0m [38;1marchetype move[0m
|
[32;1mPASS[0m[38;1m│[0m [38;1marchetype move[0m
|
||||||
|
@ -118,5 +121,5 @@
|
||||||
[32;1mPASS[0m[38;1m│[0m [38;1m#2[0m
|
[32;1mPASS[0m[38;1m│[0m [38;1m#2[0m
|
||||||
[32;1mPASS[0m[38;1m│[0m [38;1m#3[0m
|
[32;1mPASS[0m[38;1m│[0m [38;1m#3[0m
|
||||||
|
|
||||||
[38;1m73/73 test cases passed in 32.637 ms.[0m
|
[38;1m74/74 test cases passed in 32.600 ms.[0m
|
||||||
[32;1m0 fails[0m
|
[32;1m0 fails[0m
|
||||||
|
|
|
@ -5,4 +5,4 @@ license = "MIT"
|
||||||
name = "mark-marks/jecs-nightly"
|
name = "mark-marks/jecs-nightly"
|
||||||
realm = "shared"
|
realm = "shared"
|
||||||
registry = "https://github.com/UpliftGames/wally-index"
|
registry = "https://github.com/UpliftGames/wally-index"
|
||||||
version = "0.5.5-nightly.20250429T001100Z"
|
version = "0.6.0-rc.1-nightly.20250508T001059Z"
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue