mirror of
https://github.com/Ukendio/jecs.git
synced 2025-08-04 11:19:17 +00:00
Compare commits
No commits in common. "4153a7cdfe10154a68364233ede430e413b93269" and "499afc20cd00e4b3eeee77fdbe501d1dc41e1173" have entirely different histories.
4153a7cdfe
...
499afc20cd
7 changed files with 7 additions and 94 deletions
|
@ -69,9 +69,6 @@ local function observers_new<T...>(
|
||||||
end
|
end
|
||||||
|
|
||||||
for _, term in terms do
|
for _, term in terms do
|
||||||
if jecs.IS_PAIR(term) then
|
|
||||||
term = jecs.ECS_PAIR_FIRST(term)
|
|
||||||
end
|
|
||||||
world:added(term, emplaced)
|
world:added(term, emplaced)
|
||||||
world:changed(term, emplaced)
|
world:changed(term, emplaced)
|
||||||
end
|
end
|
||||||
|
@ -154,7 +151,7 @@ local function monitors_new<T...>(
|
||||||
i += 1
|
i += 1
|
||||||
entities[i] = entity
|
entities[i] = entity
|
||||||
if callback ~= nil then
|
if callback ~= nil then
|
||||||
callback(entity, jecs.OnAdd)
|
callback(entity, id, value)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -167,9 +164,6 @@ local function monitors_new<T...>(
|
||||||
end
|
end
|
||||||
|
|
||||||
for _, term in terms do
|
for _, term in terms do
|
||||||
if jecs.IS_PAIR(term) then
|
|
||||||
term = jecs.ECS_PAIR_FIRST(term)
|
|
||||||
end
|
|
||||||
world:added(term, emplaced)
|
world:added(term, emplaced)
|
||||||
world:removed(term, removed)
|
world:removed(term, removed)
|
||||||
end
|
end
|
||||||
|
|
|
@ -1,11 +1,12 @@
|
||||||
local ReplicatedStorage = game:GetService("ReplicatedStorage")
|
local ReplicatedStorage = game:GetService("ReplicatedStorage")
|
||||||
local jecs = require(ReplicatedStorage.ecs)
|
local jecs = require(ReplicatedStorage.ecs)
|
||||||
local schedule = require(ReplicatedStorage.schedule)
|
local schedule = require(ReplicatedStorage.schedule)
|
||||||
|
local observers_add = require(ReplicatedStorage.observers_add)
|
||||||
|
|
||||||
local SYSTEM = schedule.SYSTEM
|
local SYSTEM = schedule.SYSTEM
|
||||||
local RUN = schedule.RUN
|
local RUN = schedule.RUN
|
||||||
require(ReplicatedStorage.components)
|
require(ReplicatedStorage.components)
|
||||||
local world = jecs.world()
|
local world = observers_add(jecs.world())
|
||||||
|
|
||||||
local systems = ReplicatedStorage.systems
|
local systems = ReplicatedStorage.systems
|
||||||
SYSTEM(world, systems.receive_replication)
|
SYSTEM(world, systems.receive_replication)
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
local jecs = require(game:GetService("ReplicatedStorage").ecs)
|
local jecs = require(game:GetService("ReplicatedStorage").ecs)
|
||||||
|
local observers_add = require("../ReplicatedStorage/observers_add")
|
||||||
|
|
||||||
export type World = typeof(jecs.world())
|
export type World = typeof(observers_add(jecs.world()))
|
||||||
export type Entity = jecs.Entity
|
export type Entity = jecs.Entity
|
||||||
export type Id<T> = jecs.Id<T>
|
export type Id<T> = jecs.Id<T>
|
||||||
export type Snapshot = {
|
export type Snapshot = {
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
{
|
{
|
||||||
"name": "@rbxts/jecs",
|
"name": "@rbxts/jecs",
|
||||||
"version": "0.9.0-rc.7",
|
"version": "0.9.0-rc.6",
|
||||||
"description": "Stupidly fast Entity Component System",
|
"description": "Stupidly fast Entity Component System",
|
||||||
"main": "jecs.luau",
|
"main": "jecs.luau",
|
||||||
"repository": {
|
"repository": {
|
||||||
|
|
|
@ -2,28 +2,11 @@ local jecs = require("@jecs")
|
||||||
local testkit = require("@testkit")
|
local testkit = require("@testkit")
|
||||||
local test = testkit.test()
|
local test = testkit.test()
|
||||||
local CASE, TEST, FINISH, CHECK = test.CASE, test.TEST, test.FINISH, test.CHECK
|
local CASE, TEST, FINISH, CHECK = test.CASE, test.TEST, test.FINISH, test.CHECK
|
||||||
local FOCUS = test.FOCUS
|
|
||||||
local ob = require("@addons/ob")
|
local ob = require("@addons/ob")
|
||||||
|
|
||||||
TEST("addons/observers", function()
|
TEST("addons/observers", function()
|
||||||
|
|
||||||
local world = jecs.world()
|
local world = jecs.world()
|
||||||
do CASE "monitors should accept pairs"
|
|
||||||
local A = world:component()
|
|
||||||
local B = world:component()
|
|
||||||
|
|
||||||
local c = 1
|
|
||||||
ob.monitor(world:query(jecs.pair(A, B)), function (_, event)
|
|
||||||
c += 1
|
|
||||||
end)
|
|
||||||
|
|
||||||
local child = world:entity()
|
|
||||||
world:add(child, jecs.pair(A, B))
|
|
||||||
CHECK(c == 2)
|
|
||||||
|
|
||||||
world:remove(child, jecs.pair(A, B))
|
|
||||||
CHECK(c == 3)
|
|
||||||
end
|
|
||||||
do CASE "Ensure ordering between signals and observers"
|
do CASE "Ensure ordering between signals and observers"
|
||||||
local A = world:component()
|
local A = world:component()
|
||||||
local B = world:component()
|
local B = world:component()
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
[package]
|
[package]
|
||||||
name = "ukendio/jecs"
|
name = "ukendio/jecs"
|
||||||
version = "0.9.0-rc.7"
|
version = "0.9.0-rc.6"
|
||||||
registry = "https://github.com/UpliftGames/wally-index"
|
registry = "https://github.com/UpliftGames/wally-index"
|
||||||
realm = "shared"
|
realm = "shared"
|
||||||
license = "MIT"
|
license = "MIT"
|
||||||
|
|
|
@ -1,66 +0,0 @@
|
||||||
local jecs = require("@jecs")
|
|
||||||
|
|
||||||
local world = jecs.world()
|
|
||||||
local pair = jecs.pair
|
|
||||||
|
|
||||||
local IsA = world:entity()
|
|
||||||
|
|
||||||
local traits = {
|
|
||||||
IsA = IsA
|
|
||||||
}
|
|
||||||
|
|
||||||
world:set(IsA, jecs.OnAdd, function(component, id)
|
|
||||||
local second = jecs.pair_second(world, id)
|
|
||||||
assert(second ~= component, "circular")
|
|
||||||
|
|
||||||
local is_tag = jecs.is_tag(world, second)
|
|
||||||
world:added(component, function(entity, _, value)
|
|
||||||
if is_tag then
|
|
||||||
world:add(entity, second)
|
|
||||||
else
|
|
||||||
world:set(entity, second, value)
|
|
||||||
end
|
|
||||||
end)
|
|
||||||
|
|
||||||
world:removed(component, function(entity)
|
|
||||||
world:remove(entity, second)
|
|
||||||
end)
|
|
||||||
|
|
||||||
if not is_tag then
|
|
||||||
world:changed(component, function(entity, _, value)
|
|
||||||
world:set(entity, second, value)
|
|
||||||
end)
|
|
||||||
end
|
|
||||||
|
|
||||||
local r = jecs.record(world, second) :: jecs.Record
|
|
||||||
local archetype = r.archetype
|
|
||||||
if not archetype then
|
|
||||||
return
|
|
||||||
end
|
|
||||||
local types = archetype.types
|
|
||||||
|
|
||||||
for _, id in types do
|
|
||||||
if jecs.is_tag(world, id) then
|
|
||||||
world:add(component, id)
|
|
||||||
else
|
|
||||||
local metadata = world:get(second, id)
|
|
||||||
if not world:has(component, id) then
|
|
||||||
world:set(component, id, metadata)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
-- jecs.bulk_insert(world, component, ids, values)
|
|
||||||
end)
|
|
||||||
|
|
||||||
local Witch = world:entity()
|
|
||||||
local Werewolf = world:entity()
|
|
||||||
|
|
||||||
local WereWitch = world:entity()
|
|
||||||
world:add(WereWitch, pair(IsA, Witch))
|
|
||||||
world:add(WereWitch, pair(IsA, Werewolf))
|
|
||||||
|
|
||||||
local e = world:entity()
|
|
||||||
world:add(e, WereWitch)
|
|
||||||
print(world:has(e, pair(IsA, Witch))) -- false
|
|
||||||
print(world:has(e, Witch)) -- true
|
|
Loading…
Reference in a new issue