mirror of
https://github.com/Ukendio/jecs.git
synced 2025-04-24 17:10:03 +00:00
Remove observer for now (#34)
* Add case for when component is not found in archetype * Check only destination archetype first * Omit onNotifyAdd * Remove observers
This commit is contained in:
parent
91d3fcabc3
commit
1de41447b6
2 changed files with 0 additions and 69 deletions
53
lib/init.lua
53
lib/init.lua
|
@ -654,59 +654,6 @@ function World.delete(world: World, entityId: i53)
|
|||
entityIndex[entityId] = nil
|
||||
end
|
||||
|
||||
function World.observer(world: World, ...)
|
||||
local componentIds = {...}
|
||||
local idsCount = #componentIds
|
||||
local hooks = world.hooks
|
||||
|
||||
return {
|
||||
event = function(event)
|
||||
local hook = hooks[event]
|
||||
hooks[event] = nil
|
||||
|
||||
local last, change
|
||||
return function()
|
||||
last, change = next(hook, last)
|
||||
if not last then
|
||||
return
|
||||
end
|
||||
|
||||
local matched = false
|
||||
local ids = change.ids
|
||||
|
||||
while not matched do
|
||||
local skip = false
|
||||
for _, id in ids do
|
||||
if not table.find(componentIds, id) then
|
||||
skip = true
|
||||
break
|
||||
end
|
||||
end
|
||||
|
||||
if skip then
|
||||
last, change = next(hook, last)
|
||||
ids = change.ids
|
||||
continue
|
||||
end
|
||||
|
||||
matched = true
|
||||
end
|
||||
|
||||
local queryOutput = table.create(idsCount)
|
||||
local row = change.offset
|
||||
local archetype = change.archetype
|
||||
local columns = archetype.columns
|
||||
local archetypeRecords = archetype.records
|
||||
for index, id in componentIds do
|
||||
queryOutput[index] = columns[archetypeRecords[id]][row]
|
||||
end
|
||||
|
||||
return archetype.entities[row], unpack(queryOutput, 1, idsCount)
|
||||
end
|
||||
end;
|
||||
}
|
||||
end
|
||||
|
||||
function World.__iter(world: World): () -> (number?, unknown?)
|
||||
local entityIndex = world.entityIndex
|
||||
local last
|
||||
|
|
|
@ -176,22 +176,6 @@ return function()
|
|||
expect(added).to.equal(0)
|
||||
end)
|
||||
|
||||
it("track changes", function()
|
||||
local Position = world:entity()
|
||||
|
||||
local moving = world:entity()
|
||||
world:set(moving, Position, Vector3.new(1, 2, 3))
|
||||
|
||||
local count = 0
|
||||
|
||||
for e, position in world:observer(Position).event(jecs.ON_ADD) do
|
||||
count += 1
|
||||
expect(e).to.equal(moving)
|
||||
expect(position).to.equal(Vector3.new(1, 2, 3))
|
||||
end
|
||||
expect(count).to.equal(1)
|
||||
end)
|
||||
|
||||
it("should query all matching entities", function()
|
||||
|
||||
local world = jecs.World.new()
|
||||
|
|
Loading…
Reference in a new issue