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