mirror of
https://github.com/Ukendio/jecs.git
synced 2025-08-04 19:29:18 +00:00
Compare commits
1 commit
c2b4398a4f
...
3d366d26ec
Author | SHA1 | Date | |
---|---|---|---|
|
3d366d26ec |
4 changed files with 41 additions and 38 deletions
|
@ -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<any>
|
||||
query: jecs.Query<...jecs.Id>,
|
||||
}
|
||||
|
||||
export type PatchedWorld = jecs.World & {
|
||||
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) -> ()) -> () -> (),
|
||||
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) -> ()) -> () -> (),
|
||||
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()
|
||||
|
|
|
@ -25,6 +25,10 @@ export default defineConfig({
|
|||
},
|
||||
],
|
||||
"/learn/": [
|
||||
{
|
||||
text: "Overview",
|
||||
items: [{ text: "Overview", link: "/learn/overview" }],
|
||||
},
|
||||
{
|
||||
text: "API Reference",
|
||||
items: [
|
||||
|
|
|
@ -89,7 +89,6 @@ print(`${world.get(Position, jecs.Name)} is a Component: ${world.has(Position, j
|
|||
### Entity ranges
|
||||
Jecs reserves entity ids under a threshold (HI_COMPONENT_ID, default is 256) for components. That means that regular entities will start after this number. This number can be further specified via the `range` member function.
|
||||
|
||||
::: code-group
|
||||
```luau [luau]
|
||||
world:range(1000, 5000) -- Defines the lower and upper bounds of the entity range respectively
|
||||
|
||||
|
@ -99,13 +98,14 @@ print(e)
|
|||
-- 1000
|
||||
```
|
||||
```typescript [typescript]
|
||||
world.range(1000, 5000) // Defines the lower and upper bounds of the entity range respectively
|
||||
world.range(1000, 5000) -- Defines the lower and upper bounds of the entity range respectively
|
||||
|
||||
const e = world.entity()
|
||||
local e = world.entity()
|
||||
print(e)
|
||||
// Output:
|
||||
// 1000
|
||||
```
|
||||
```
|
||||
:::
|
||||
|
||||
### Hooks
|
||||
|
|
|
@ -32,6 +32,8 @@
|
|||
- [Awesome Entity Component System (link collection related to ECS) - Jeongseok Lee](https://github.com/jslee02/awesome-entity-component-system)
|
||||
- [Hibitset - DOCS.RS](https://docs.rs/hibitset/0.6.3/hibitset/)
|
||||
|
||||
------------------
|
||||
|
||||
## Addons
|
||||
|
||||
A collection of third-party jecs addons made by the community. If you would like to share what you're working on, [submit a pull request](/learn/contributing/pull-requests#addons)!
|
||||
|
@ -41,10 +43,10 @@ A collection of third-party jecs addons made by the community. If you would like
|
|||
#### [jabby](https://github.com/alicesaidhi/jabby)
|
||||
A jecs debugger with a string-based query language and entity editing capabilities.
|
||||
|
||||
#### [jecs_entity_visualiser](https://github.com/Ukendio/jecs/blob/main/tools/entity_visualiser.luau)
|
||||
#### [jecs_entity_visualiser](https://github.com/Ukendio/jecs/blob/main/addons/entity_visualiser.luau)
|
||||
A simple entity and component visualiser in the output
|
||||
|
||||
#### [jecs_lifetime_tracker](https://github.com/Ukendio/jecs/blob/main/tools/lifetime_tracker.luau)
|
||||
#### [jecs_lifetime_tracker](https://github.com/Ukendio/jecs/blob/main/addons/lifetime_tracker.luau)
|
||||
A tool for inspecting entity lifetimes
|
||||
|
||||
### Helpers
|
||||
|
|
Loading…
Reference in a new issue