diff --git a/jecs/addons/observers.luau b/jecs/addons/observers.luau index b725e7c..0175060 100644 --- a/jecs/addons/observers.luau +++ b/jecs/addons/observers.luau @@ -2,20 +2,15 @@ local jecs = require("@jecs") type Observer = { callback: (jecs.Entity) -> (), - query: jecs.Query<...any>, -} - -type Monitor = { - callback: (jecs.Entity, jecs.Entity) -> (), - queyr: jecs.Query + query: jecs.Query<...jecs.Id>, } export type PatchedWorld = jecs.World & { - added: (PatchedWorld, jecs.Id, (e: jecs.Entity, id: jecs.Id, value: T) -> ()) -> () -> (), - removed: (PatchedWorld, jecs.Id, (e: jecs.Entity, id: jecs.Id) -> ()) -> () -> (), - changed: (PatchedWorld, jecs.Id, (e: jecs.Entity, id: jecs.Id, value: T) -> ()) -> () -> (), + added: (PatchedWorld, jecs.Id, (jecs.Entity, jecs.Id, T) -> ()) -> () -> (), + removed: (PatchedWorld, jecs.Id, (jecs.Entity, jecs.Id) -> ()) -> () -> (), + changed: (PatchedWorld, jecs.Id, (jecs.Entity, jecs.Id, T) -> ()) -> () -> (), observer: (PatchedWorld, Observer) -> (), - monitor: (PatchedWorld, Monitor) -> (), + monitor: (PatchedWorld, Observer) -> (), } local function observers_new(world, description) @@ -50,6 +45,7 @@ local function observers_new(world, description) end end + local function join(world, component) local sparse_array = {} local dense_array = {} @@ -167,16 +163,16 @@ local function observers_add(world: jecs.World): PatchedWorld listener(entity, id, value) end end - local existing_hook = world:get(component, jecs.OnAdd) - if existing_hook then - table.insert(listeners, existing_hook) - local idr = world.component_index[component] - if idr then - idr.hooks.on_add = 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 - - world:set(component, jecs.OnAdd, on_add) end table.insert(listeners, fn) return function() @@ -201,15 +197,16 @@ local function observers_add(world: jecs.World): PatchedWorld listener(entity, id, value) end end - local existing_hook = world:get(component, jecs.OnChange) - if existing_hook then - table.insert(listeners, existing_hook) - local idr = world.component_index[component] - if idr then - idr.hooks.on_change = 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 - world:set(component, jecs.OnChange, on_change) end table.insert(listeners, fn) return function() @@ -234,16 +231,16 @@ local function observers_add(world: jecs.World): PatchedWorld listener(entity, id, value) end end - local existing_hook = world:get(component, jecs.OnRemove) - if existing_hook then - table.insert(listeners, existing_hook) - local idr = world.component_index[component] - if idr then - idr.hooks.on_remove = 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 - - world:set(component, jecs.OnRemove, on_remove) end table.insert(listeners, fn) return function() diff --git a/jecs/build.txt b/jecs/build.txt index 1ab250a..167581c 100644 --- a/jecs/build.txt +++ b/jecs/build.txt @@ -1,2 +1,2 @@ -modified = ["addons/observers.luau"] -version = "0.6.0-nightly.20250520T001101Z" +modified = ["README.md", "jecs.luau"] +version = "0.6.0-nightly.20250519T001113Z" diff --git a/jecs/pesde-rbx.toml b/jecs/pesde-rbx.toml index 50592e6..f5a17c4 100644 --- a/jecs/pesde-rbx.toml +++ b/jecs/pesde-rbx.toml @@ -3,7 +3,7 @@ includes = ["init.luau", "pesde.toml", "README.md", "CHANGELOG.md", "LICENSE", " license = "MIT" name = "marked/jecs_nightly" repository = "https://git.devmarked.win/marked/jecs-nightly" -version = "0.6.0-nightly.20250520T001101Z" +version = "0.6.0-nightly.20250519T001113Z" [indices] default = "https://github.com/pesde-pkg/index" diff --git a/jecs/pesde.toml b/jecs/pesde.toml index fd6740f..f3ddfa0 100644 --- a/jecs/pesde.toml +++ b/jecs/pesde.toml @@ -3,7 +3,7 @@ includes = ["init.luau", "pesde.toml", "README.md", "CHANGELOG.md", "LICENSE", " license = "MIT" name = "marked/jecs_nightly" repository = "https://git.devmarked.win/marked/jecs-nightly" -version = "0.6.0-nightly.20250520T001101Z" +version = "0.6.0-nightly.20250519T001113Z" [indices] default = "https://github.com/pesde-pkg/index" diff --git a/jecs/test.txt b/jecs/test.txt index e9dd3d6..f3b008a 100644 --- a/jecs/test.txt +++ b/jecs/test.txt @@ -1,2 +1,2 @@ passed = true -timestamp = "20250520T001103Z" +timestamp = "20250519T001115Z" diff --git a/jecs/test_fulllog.txt b/jecs/test_fulllog.txt index 4afdb00..2b77688 100644 --- a/jecs/test_fulllog.txt +++ b/jecs/test_fulllog.txt @@ -1,6 +1,6 @@ -7.5 us  3 kB│ delete children of entity +7.3 us  3 kB│ delete children of entity 9.2 us  1 kB│ remove friends of entity -347 ns  10  B│ simple deletion of entity +348 ns  10  B│ simple deletion of entity repro NONE│  @@ -121,5 +121,5 @@ PASS│ #2 PASS│ #3 -74/74 test cases passed in 30.716 ms. +74/74 test cases passed in 33.314 ms. 0 fails diff --git a/jecs/wally.toml b/jecs/wally.toml index d7ffcb9..2a8d02b 100644 --- a/jecs/wally.toml +++ b/jecs/wally.toml @@ -5,4 +5,4 @@ license = "MIT" name = "mark-marks/jecs-nightly" realm = "shared" registry = "https://github.com/UpliftGames/wally-index" -version = "0.6.0-nightly.20250520T001101Z" +version = "0.6.0-nightly.20250519T001113Z"