mirror of
https://github.com/Ukendio/jecs.git
synced 2025-04-24 17:10:03 +00:00
return an EmptyQuery when querying for components that are not tied to any entities (#12)
* Update init.lua * export Query type * replace EmptyQuery with static reference
This commit is contained in:
parent
1b1ae947d9
commit
d0fb1a1b1d
1 changed files with 5 additions and 4 deletions
|
@ -360,8 +360,9 @@ local EmptyQuery = {
|
|||
without = noop
|
||||
}
|
||||
EmptyQuery.__index = EmptyQuery
|
||||
setmetatable(EmptyQuery, EmptyQuery)
|
||||
|
||||
export type Query = typeof(setmetatable({}, EmptyQuery))
|
||||
export type Query = typeof(EmptyQuery)
|
||||
|
||||
function World.query(world: World, ...: i53): Query
|
||||
local compatibleArchetypes = {}
|
||||
|
@ -379,7 +380,7 @@ function World.query(world: World, ...: i53): Query
|
|||
for i, componentId in components do
|
||||
local map = componentIndex[componentId]
|
||||
if not map then
|
||||
return setmetatable({}, EmptyQuery)
|
||||
return EmptyQuery
|
||||
end
|
||||
|
||||
if firstArchetypeMap == nil or map.size < firstArchetypeMap.size then
|
||||
|
@ -415,7 +416,7 @@ function World.query(world: World, ...: i53): Query
|
|||
|
||||
local lastArchetype, compatibleArchetype = next(compatibleArchetypes)
|
||||
if not lastArchetype then
|
||||
return setmetatable({}, EmptyQuery)
|
||||
return EmptyQuery
|
||||
end
|
||||
|
||||
local preparedQuery = {}
|
||||
|
@ -439,7 +440,7 @@ function World.query(world: World, ...: i53): Query
|
|||
|
||||
lastArchetype, compatibleArchetype = next(compatibleArchetypes)
|
||||
if not lastArchetype then
|
||||
return setmetatable({}, EmptyQuery)
|
||||
return EmptyQuery
|
||||
end
|
||||
|
||||
return self
|
||||
|
|
Loading…
Reference in a new issue