Compare commits

...

2 commits

Author SHA1 Message Date
forgejo-actions
8d9ac83b46 Sync to upstream Jecs 0.6.0-nightly.20250520T001101Z 2025-05-20 00:11:20 +00:00
75c362f80e Sync to released Jecs 0.6.0-nightly.20250519T001113Z (#68)
Reviewed-on: #68
2025-05-19 02:11:34 +02:00
9 changed files with 46 additions and 43 deletions

View file

@ -2,7 +2,7 @@
<img src="assets/image-5.png" width=35%/>
</p>
[![License: MIT](https://img.shields.io/badge/License-MIT-blue.svg?style=for-the-badge)](LICENSE) [![Wally](https://img.shields.io/github/v/tag/ukendio/jecs?&style=for-the-badge)](https://wally.run/package/ukendio/jecs)
[![License: MIT](https://img.shields.io/badge/License-MIT-blue.svg?style=for-the-badge)](LICENSE) [![Wally](https://img.shields.io/github/v/tag/ukendio/jecs?&style=for-the-badge)](https://wally.run/package/ukendio/jecs) [![GitHub Actions Workflow Status](https://img.shields.io/github/actions/workflow/status/ukendio/jecs/unit-testing.yaml?&style=for-the-badge)](https://github.com/Ukendio/jecs/actions/workflows/unit-testing.yaml)
Just a stupidly fast Entity Component System

View file

@ -2,15 +2,20 @@ local jecs = require("@jecs")
type Observer = {
callback: (jecs.Entity) -> (),
query: jecs.Query<...jecs.Id>,
query: jecs.Query<...any>,
}
type Monitor = {
callback: (jecs.Entity, jecs.Entity) -> (),
queyr: jecs.Query<any>
}
export type PatchedWorld = jecs.World & {
added: <T>(PatchedWorld, jecs.Id<T>, (jecs.Entity, jecs.Id, T) -> ()) -> () -> (),
removed: <T>(PatchedWorld, jecs.Id<T>, (jecs.Entity, jecs.Id) -> ()) -> () -> (),
changed: <T>(PatchedWorld, jecs.Id<T>, (jecs.Entity, jecs.Id, T) -> ()) -> () -> (),
added: <T>(PatchedWorld, jecs.Id<T>, (e: jecs.Entity, id: jecs.Id, value: T) -> ()) -> () -> (),
removed: <T>(PatchedWorld, jecs.Id<T>, (e: jecs.Entity, id: jecs.Id) -> ()) -> () -> (),
changed: <T>(PatchedWorld, jecs.Id<T>, (e: jecs.Entity, id: jecs.Id, value: T) -> ()) -> () -> (),
observer: (PatchedWorld, Observer) -> (),
monitor: (PatchedWorld, Observer) -> (),
monitor: (PatchedWorld, Monitor) -> (),
}
local function observers_new(world, description)
@ -45,7 +50,6 @@ local function observers_new(world, description)
end
end
local function join(world, component)
local sparse_array = {}
local dense_array = {}
@ -163,17 +167,17 @@ 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
local idr_hook_existing = idr.hooks.on_add
if idr_hook_existing then
table.insert(listeners, idr_hook_existing)
idr.hooks.on_add = on_add
end
idr.hooks.on_add = on_add :: any
else
end
world:set(component, jecs.OnAdd, on_add)
end
end
table.insert(listeners, fn)
return function()
local n = #listeners
@ -197,17 +201,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
local idr_hook_existing = idr.hooks.on_change
if idr_hook_existing then
table.insert(listeners, idr_hook_existing)
idr.hooks.on_change = on_change
end
end
idr.hooks.on_change = on_change :: any
else
world:set(component, jecs.OnChange, on_change)
end
end
table.insert(listeners, fn)
return function()
local n = #listeners
@ -231,17 +234,17 @@ 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
local idr_hook_existing = idr.hooks.on_remove
if idr_hook_existing then
table.insert(listeners, idr_hook_existing)
idr.hooks.on_remove = on_remove
end
idr.hooks.on_remove = on_remove :: any
else
end
world:set(component, jecs.OnRemove, on_remove)
end
end
table.insert(listeners, fn)
return function()
local n = #listeners

View file

@ -1,2 +1,2 @@
modified = ["jecs.luau"]
version = "0.6.0-nightly.20250517T001101Z"
modified = ["addons/observers.luau"]
version = "0.6.0-nightly.20250520T001101Z"

View file

@ -2570,7 +2570,7 @@ export type World = {
range: (self: World, range_begin: number, range_end: number?) -> (),
--- Creates a new entity
entity: (self: World, id: Entity?) -> Entity,
entity: <T>(self: World, id: Entity<T>?) -> Entity<T>,
--- Creates a new entity located in the first 256 ids.
--- These should be used for static components for fast access.
component: <T>(self: World) -> Entity<T>,

View file

@ -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.20250517T001101Z"
version = "0.6.0-nightly.20250520T001101Z"
[indices]
default = "https://github.com/pesde-pkg/index"

View file

@ -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.20250517T001101Z"
version = "0.6.0-nightly.20250520T001101Z"
[indices]
default = "https://github.com/pesde-pkg/index"

View file

@ -1,2 +1,2 @@
passed = true
timestamp = "20250518T001104Z"
timestamp = "20250520T001103Z"

View file

@ -1,6 +1,6 @@
7.3 us  3 kB│ delete children of entity
9.3 us  1 kB│ remove friends of entity
348 ns  10  B│ simple deletion of entity
7.5 us  3 kB│ delete children of entity
9.2 us  1 kB│ remove friends of entity
347 ns  10  B│ simple deletion of entity
repro
NONE│ 
@ -121,5 +121,5 @@
PASS│ #2
PASS│ #3
74/74 test cases passed in 32.645 ms.
74/74 test cases passed in 30.716 ms.
0 fails

View file

@ -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.20250517T001101Z"
version = "0.6.0-nightly.20250520T001101Z"