mirror of
https://github.com/Ukendio/jecs.git
synced 2025-04-25 09:30:03 +00:00
Update init.lua
This commit is contained in:
parent
4978ac7856
commit
e2d1156f72
1 changed files with 17 additions and 11 deletions
24
lib/init.lua
24
lib/init.lua
|
@ -350,14 +350,20 @@ function World.get(world: World, entityId: i53, a: i53, b: i53?, c: i53?, d: i53
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
local function noop(self: Query, ...: i53): () -> (number, ...any)
|
||||||
|
|
||||||
local function noop(): any
|
|
||||||
return function()
|
return function()
|
||||||
end
|
end :: any
|
||||||
end
|
end
|
||||||
|
|
||||||
function World.query(world: World, ...: i53): any
|
local EmptyQuery = {
|
||||||
|
__iter = noop,
|
||||||
|
without = noop
|
||||||
|
}
|
||||||
|
EmptyQuery.__index = EmptyQuery
|
||||||
|
|
||||||
|
type Query = typeof(setmetatable({}, EmptyQuery))
|
||||||
|
|
||||||
|
function World.query(world: World, ...: i53): Query
|
||||||
local compatibleArchetypes = {}
|
local compatibleArchetypes = {}
|
||||||
local components = { ... }
|
local components = { ... }
|
||||||
local archetypes = world.archetypes
|
local archetypes = world.archetypes
|
||||||
|
@ -373,7 +379,7 @@ function World.query(world: World, ...: i53): any
|
||||||
for i, componentId in components do
|
for i, componentId in components do
|
||||||
local map = componentIndex[componentId]
|
local map = componentIndex[componentId]
|
||||||
if not map then
|
if not map then
|
||||||
error(tostring(componentId).." has not been added to an entity")
|
return setmetatable({}, EmptyQuery)
|
||||||
end
|
end
|
||||||
|
|
||||||
if firstArchetypeMap == nil or map.size < firstArchetypeMap.size then
|
if firstArchetypeMap == nil or map.size < firstArchetypeMap.size then
|
||||||
|
@ -409,7 +415,7 @@ function World.query(world: World, ...: i53): any
|
||||||
|
|
||||||
local lastArchetype, compatibleArchetype = next(compatibleArchetypes)
|
local lastArchetype, compatibleArchetype = next(compatibleArchetypes)
|
||||||
if not lastArchetype then
|
if not lastArchetype then
|
||||||
return noop()
|
return setmetatable({}, EmptyQuery)
|
||||||
end
|
end
|
||||||
|
|
||||||
local preparedQuery = {}
|
local preparedQuery = {}
|
||||||
|
@ -433,7 +439,7 @@ function World.query(world: World, ...: i53): any
|
||||||
|
|
||||||
lastArchetype, compatibleArchetype = next(compatibleArchetypes)
|
lastArchetype, compatibleArchetype = next(compatibleArchetypes)
|
||||||
if not lastArchetype then
|
if not lastArchetype then
|
||||||
return noop()
|
return setmetatable({}, EmptyQuery)
|
||||||
end
|
end
|
||||||
|
|
||||||
return self
|
return self
|
||||||
|
@ -518,7 +524,7 @@ function World.query(world: World, ...: i53): any
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
return setmetatable({}, preparedQuery)
|
return setmetatable({}, preparedQuery) :: any
|
||||||
end
|
end
|
||||||
|
|
||||||
function World.component(world: World)
|
function World.component(world: World)
|
||||||
|
|
Loading…
Reference in a new issue