mirror of
https://github.com/Ukendio/jecs.git
synced 2025-09-16 21:39:17 +00:00
Enlist starting archetypes
This commit is contained in:
parent
456713c2d5
commit
e16e4a04e4
3 changed files with 26 additions and 1 deletions
|
@ -22,6 +22,7 @@ local function observers_new<T...>(
|
|||
): Observer<T...>
|
||||
query:cached()
|
||||
|
||||
|
||||
local world = (query :: Query<T...> & { world: World }).world
|
||||
callback = callback
|
||||
|
||||
|
@ -42,6 +43,10 @@ local function observers_new<T...>(
|
|||
|
||||
local entity_index = world.entity_index :: any
|
||||
|
||||
for _, archetype in query:archetypes() do
|
||||
archetypes[archetype.id] = true
|
||||
end
|
||||
|
||||
local function emplaced<T, a>(
|
||||
entity: jecs.Entity<T>,
|
||||
id: jecs.Id<a>,
|
||||
|
@ -132,6 +137,10 @@ local function monitors_new<T...>(query: Query<T...>): Observer<T...>
|
|||
observer_on_delete.callback = function(archetype)
|
||||
archetypes[archetype.id] = nil
|
||||
end
|
||||
|
||||
for _, archetype in query:archetypes() do
|
||||
archetypes[archetype.id] = true
|
||||
end
|
||||
local entity_index = world.entity_index :: any
|
||||
|
||||
local callback_added: ((jecs.Entity) -> ())?
|
||||
|
|
|
@ -7,6 +7,23 @@ local ob = require("@addons/ob")
|
|||
|
||||
TEST("addons/ob", function()
|
||||
local world = jecs.world()
|
||||
do CASE "should match against archetypes that were already created"
|
||||
local A = world:component()
|
||||
|
||||
local e1 = world:entity()
|
||||
world:add(e1, A)
|
||||
|
||||
local monitor = ob.monitor(world:query(A))
|
||||
local c = 1
|
||||
monitor.added(function()
|
||||
c += 1
|
||||
end)
|
||||
|
||||
world:remove(e1, A)
|
||||
world:add(e1, A)
|
||||
CHECK(c==2)
|
||||
end
|
||||
|
||||
do CASE "Should support query:without()"
|
||||
local A = world:component()
|
||||
local B = world:component()
|
||||
|
|
|
@ -1365,7 +1365,6 @@ TEST("world:added", function()
|
|||
end
|
||||
|
||||
do CASE ""
|
||||
local world = jecs.world()
|
||||
local IsNearby = world:component()
|
||||
world:set(IsNearby, jecs.Name, "IsNearby")
|
||||
local person1, person2 = world:entity(), world:entity()
|
||||
|
|
Loading…
Reference in a new issue