mirror of
https://github.com/Ukendio/jecs.git
synced 2025-08-04 11:19:17 +00:00
Compare commits
7 commits
6053038cc1
...
23540e5919
Author | SHA1 | Date | |
---|---|---|---|
|
23540e5919 | ||
|
169ec09ed5 | ||
|
a9891abf6d | ||
|
6dfb428296 | ||
|
b92cf9ab76 | ||
|
5aedb5e730 | ||
|
1c524f1587 |
4 changed files with 51 additions and 21 deletions
|
@ -4,15 +4,15 @@ 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) -> ()) -> () -> (),
|
||||
observer: (
|
||||
observer: <T...>(
|
||||
PatchedWorld,
|
||||
any,
|
||||
(jecs.Entity) -> ()
|
||||
) -> (),
|
||||
jecs.Query<T...>,
|
||||
(<a>(jecs.Entity, jecs.Id<a>, a) -> ())?
|
||||
) -> () -> (jecs.Entity),
|
||||
monitor: (
|
||||
PatchedWorld,
|
||||
any,
|
||||
(jecs.Entity, jecs.Id) -> ()
|
||||
(<a>(jecs.Entity, jecs.Id<a>) -> ())?
|
||||
) -> ()
|
||||
}
|
||||
|
||||
|
@ -25,6 +25,8 @@ local function observers_new(world, query, callback)
|
|||
end
|
||||
|
||||
local entity_index = world.entity_index :: any
|
||||
local i = 0
|
||||
local entities = {}
|
||||
local function emplaced(entity, id, value)
|
||||
local r = jecs.entity_index_try_get_fast(
|
||||
entity_index, entity :: any)
|
||||
|
@ -36,7 +38,11 @@ local function observers_new(world, query, callback)
|
|||
local archetype = r.archetype
|
||||
|
||||
if jecs.query_match(query, archetype) then
|
||||
callback(entity)
|
||||
i += 1
|
||||
entities[i] = entity
|
||||
if callback ~= nil then
|
||||
callback(entity, id, value)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -44,6 +50,19 @@ local function observers_new(world, query, callback)
|
|||
world:added(term, emplaced)
|
||||
world:changed(term, emplaced)
|
||||
end
|
||||
|
||||
return function()
|
||||
local row = i
|
||||
return function()
|
||||
if row == 0 then
|
||||
i = 0
|
||||
table.clear(entities)
|
||||
end
|
||||
local entity = entities[row]
|
||||
row -= 1
|
||||
return entity
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
local function join(world, component)
|
||||
|
@ -99,7 +118,9 @@ local function monitors_new(world, query, callback)
|
|||
end
|
||||
|
||||
local entity_index = world.entity_index :: any
|
||||
local function emplaced(entity: jecs.Entity)
|
||||
local i = 0
|
||||
local entities = {}
|
||||
local function emplaced(entity, id, value)
|
||||
local r = jecs.entity_index_try_get_fast(
|
||||
entity_index, entity :: any)
|
||||
|
||||
|
@ -110,22 +131,17 @@ local function monitors_new(world, query, callback)
|
|||
local archetype = r.archetype
|
||||
|
||||
if jecs.query_match(query, archetype) then
|
||||
callback(entity, jecs.OnAdd)
|
||||
i += 1
|
||||
entities[i] = entity
|
||||
if callback ~= nil then
|
||||
callback(entity, id, value)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
local function removed(entity: jecs.Entity, component: jecs.Id)
|
||||
local r = jecs.entity_index_try_get_fast(
|
||||
entity_index, entity :: any)
|
||||
|
||||
if not r then
|
||||
return
|
||||
end
|
||||
|
||||
local archetype = r.archetype
|
||||
|
||||
if jecs.query_match(query, archetype) then
|
||||
local EcsOnRemove = jecs.OnRemove :: jecs.Id
|
||||
if callback ~= nil then
|
||||
callback(entity, EcsOnRemove)
|
||||
end
|
||||
end
|
||||
|
@ -134,6 +150,19 @@ local function monitors_new(world, query, callback)
|
|||
world:added(term, emplaced)
|
||||
world:removed(term, removed)
|
||||
end
|
||||
|
||||
return function()
|
||||
local row = i
|
||||
return function()
|
||||
if row == 0 then
|
||||
i = 0
|
||||
table.clear(entities)
|
||||
end
|
||||
local entity = entities[row]
|
||||
row -= 1
|
||||
return entity
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
local function observers_add(world: jecs.World): PatchedWorld
|
||||
|
|
1
jecs.d.ts
vendored
1
jecs.d.ts
vendored
|
@ -310,6 +310,7 @@ export declare const OnDeleteTarget: Tag;
|
|||
export declare const Delete: Tag;
|
||||
export declare const Remove: Tag;
|
||||
export declare const Name: Entity<string>;
|
||||
export declare const Exclusive: Tag;
|
||||
export declare const Rest: Entity;
|
||||
|
||||
export type ComponentRecord = {
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
{
|
||||
"name": "@rbxts/jecs",
|
||||
"version": "0.7.3",
|
||||
"version": "0.8.1",
|
||||
"description": "Stupidly fast Entity Component System",
|
||||
"main": "jecs.luau",
|
||||
"repository": {
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
[package]
|
||||
name = "ukendio/jecs"
|
||||
version = "0.7.3"
|
||||
version = "0.8.1"
|
||||
registry = "https://github.com/UpliftGames/wally-index"
|
||||
realm = "shared"
|
||||
license = "MIT"
|
||||
|
|
Loading…
Reference in a new issue