mirror of
https://github.com/Ukendio/jecs.git
synced 2025-08-04 11:19:17 +00:00
Compare commits
4 commits
3da92e56d1
...
43f9e7bc72
Author | SHA1 | Date | |
---|---|---|---|
|
43f9e7bc72 | ||
|
37f1e5be52 | ||
|
d6e288555e | ||
|
74c6a35352 |
4 changed files with 19 additions and 26 deletions
|
@ -74,11 +74,12 @@ return function(world: types.World)
|
|||
local removed = map.removed
|
||||
|
||||
if removed then
|
||||
for i, e in removed do
|
||||
if not world:contains(e) then
|
||||
for _, entity in removed do
|
||||
entity = ecs_map_get(world, entity)
|
||||
if not world:contains(entity) then
|
||||
continue
|
||||
end
|
||||
world:remove(e, id)
|
||||
world:remove(entity, id)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -159,7 +159,7 @@ return function(world: ty.World)
|
|||
set_n += 1
|
||||
set_ids[set_n] = e
|
||||
set_values[set_n] = v or true
|
||||
elseif not world:contains(e) then
|
||||
elseif world:contains(e) then
|
||||
removed_n += 1
|
||||
removed_ids[removed_n] = e
|
||||
end
|
||||
|
|
|
@ -52,6 +52,9 @@ A tool for inspecting entity lifetimes
|
|||
#### [jecs_observers](https://github.com/Ukendio/jecs/blob/main/addons/observers.luau)
|
||||
Observers for queries and signals for components
|
||||
|
||||
### [hammer](https://github.com/Mark-Marks/hammer)
|
||||
A set of utilities for Jecs
|
||||
|
||||
### Schedulers
|
||||
|
||||
#### [lockstep scheduler](https://gist.github.com/1Axen/6d4f78b3454cf455e93794505588354b)
|
||||
|
|
|
@ -7,24 +7,13 @@ local observers_add = require("@addons/observers")
|
|||
TEST("addons/observers", function()
|
||||
local world = observers_add(jecs.world())
|
||||
|
||||
local Test = world:component() :: jecs.Id<number>
|
||||
type Q<T...> = () -> (jecs.Entity, T...)
|
||||
local query:
|
||||
(<A>(jecs.World, jecs.Id<A>) -> Q<A>)
|
||||
& (<A, B>(jecs.World, jecs.Id<A>, jecs.Id<B>) -> Q<A, B>)
|
||||
& (<A, B, C>(jecs.World, jecs.Id<A>, jecs.Id<B>, jecs.Id<C>) -> Q<A, B, C>)
|
||||
= 1 :: never
|
||||
for e, a in query(world, Test) do
|
||||
|
||||
end
|
||||
|
||||
do CASE "Should work even if set after the component has been used"
|
||||
local A = world:component()
|
||||
|
||||
world:set(world:entity(), A, 2)
|
||||
local ran = true
|
||||
local ran = false
|
||||
world:added(A, function()
|
||||
ran = false
|
||||
ran = true
|
||||
end)
|
||||
|
||||
local entity = world:entity()
|
||||
|
@ -38,16 +27,16 @@ TEST("addons/observers", function()
|
|||
|
||||
local count = 1
|
||||
local function counter()
|
||||
count += 2
|
||||
count += 1
|
||||
end
|
||||
|
||||
world:set(A, jecs.OnAdd, counter)
|
||||
world:added(A, counter)
|
||||
world:set(world:entity(), A, false)
|
||||
CHECK(count == 3)
|
||||
CHECK(count == (1 + 2))
|
||||
world:set(world:entity(), A, false)
|
||||
|
||||
CHECK(count == 5)
|
||||
CHECK(count == (1 + (2 * 2)))
|
||||
end
|
||||
|
||||
do CASE "Ensure ordering between signals and observers"
|
||||
|
@ -56,7 +45,7 @@ TEST("addons/observers", function()
|
|||
|
||||
local count = 1
|
||||
local function counter()
|
||||
count += 2
|
||||
count += 1
|
||||
end
|
||||
|
||||
world:observer(world:query(A, B), counter)
|
||||
|
@ -77,7 +66,7 @@ TEST("addons/observers", function()
|
|||
|
||||
local count = 1
|
||||
local function counter()
|
||||
count += 2
|
||||
count += 1
|
||||
end
|
||||
|
||||
world:observer(world:query(A), counter)
|
||||
|
@ -97,7 +86,7 @@ TEST("addons/observers", function()
|
|||
local A = world:component()
|
||||
local count = 1
|
||||
local function counter()
|
||||
count += 2
|
||||
count += 1
|
||||
end
|
||||
|
||||
world:monitor(world:query(A), counter)
|
||||
|
@ -118,10 +107,10 @@ TEST("addons/observers", function()
|
|||
|
||||
local callcount = 1
|
||||
world:added(A, function(entity)
|
||||
callcount += 2
|
||||
callcount += 1
|
||||
end)
|
||||
world:added(A, function(entity)
|
||||
callcount += 2
|
||||
callcount += 1
|
||||
end)
|
||||
|
||||
local e = world:entity()
|
||||
|
@ -129,7 +118,7 @@ TEST("addons/observers", function()
|
|||
|
||||
world:add(e2, jecs.pair(A, e))
|
||||
world:add(e, jecs.pair(A, e2))
|
||||
CHECK(callcount == 5)
|
||||
CHECK(callcount == 1 + 2 * 2)
|
||||
end
|
||||
end)
|
||||
|
||||
|
|
Loading…
Reference in a new issue