mirror of
https://github.com/Ukendio/jecs.git
synced 2025-04-25 17:40:02 +00:00
Add next method
This commit is contained in:
parent
ea110ea2a9
commit
def75e3b49
1 changed files with 76 additions and 66 deletions
142
lib/init.lua
142
lib/init.lua
|
@ -798,74 +798,84 @@ function World.query(world: World, ...): Query
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
function preparedQuery:__iter()
|
function preparedQuery:__tostring()
|
||||||
return function()
|
return "query"
|
||||||
local archetype = compatibleArchetype.archetype
|
end
|
||||||
local row: number = next(archetype.entities, lastRow) :: number
|
|
||||||
while row == nil do
|
local function iter()
|
||||||
lastArchetype, compatibleArchetype = next(compatibleArchetypes, lastArchetype)
|
local archetype = compatibleArchetype.archetype
|
||||||
if lastArchetype == nil then
|
local row: number = next(archetype.entities, lastRow) :: number
|
||||||
return
|
while row == nil do
|
||||||
end
|
lastArchetype, compatibleArchetype = next(compatibleArchetypes, lastArchetype)
|
||||||
archetype = compatibleArchetype.archetype
|
if lastArchetype == nil then
|
||||||
row = next(archetype.entities, row) :: number
|
return
|
||||||
end
|
end
|
||||||
lastRow = row
|
archetype = compatibleArchetype.archetype
|
||||||
|
row = next(archetype.entities, row) :: number
|
||||||
local entityId = archetype.entities[row :: number]
|
|
||||||
local columns = archetype.columns
|
|
||||||
local tr = compatibleArchetype.indices
|
|
||||||
|
|
||||||
if queryLength == 1 then
|
|
||||||
return entityId, columns[tr[1]][row]
|
|
||||||
elseif queryLength == 2 then
|
|
||||||
return entityId, columns[tr[1]][row], columns[tr[2]][row]
|
|
||||||
elseif queryLength == 3 then
|
|
||||||
return entityId, columns[tr[1]][row], columns[tr[2]][row], columns[tr[3]][row]
|
|
||||||
elseif queryLength == 4 then
|
|
||||||
return entityId, columns[tr[1]][row], columns[tr[2]][row], columns[tr[3]][row], columns[tr[4]][row]
|
|
||||||
elseif queryLength == 5 then
|
|
||||||
return entityId,
|
|
||||||
columns[tr[1]][row],
|
|
||||||
columns[tr[2]][row],
|
|
||||||
columns[tr[3]][row],
|
|
||||||
columns[tr[4]][row],
|
|
||||||
columns[tr[5]][row]
|
|
||||||
elseif queryLength == 6 then
|
|
||||||
return entityId,
|
|
||||||
columns[tr[1]][row],
|
|
||||||
columns[tr[2]][row],
|
|
||||||
columns[tr[3]][row],
|
|
||||||
columns[tr[4]][row],
|
|
||||||
columns[tr[5]][row],
|
|
||||||
columns[tr[6]][row]
|
|
||||||
elseif queryLength == 7 then
|
|
||||||
return entityId,
|
|
||||||
columns[tr[1]][row],
|
|
||||||
columns[tr[2]][row],
|
|
||||||
columns[tr[3]][row],
|
|
||||||
columns[tr[4]][row],
|
|
||||||
columns[tr[5]][row],
|
|
||||||
columns[tr[6]][row],
|
|
||||||
columns[tr[7]][row]
|
|
||||||
elseif queryLength == 8 then
|
|
||||||
return entityId,
|
|
||||||
columns[tr[1]][row],
|
|
||||||
columns[tr[2]][row],
|
|
||||||
columns[tr[3]][row],
|
|
||||||
columns[tr[4]][row],
|
|
||||||
columns[tr[5]][row],
|
|
||||||
columns[tr[6]][row],
|
|
||||||
columns[tr[7]][row],
|
|
||||||
columns[tr[8]][row]
|
|
||||||
end
|
|
||||||
|
|
||||||
for i in components do
|
|
||||||
queryOutput[i] = columns[tr[i]][row]
|
|
||||||
end
|
|
||||||
|
|
||||||
return entityId, unpack(queryOutput, 1, queryLength)
|
|
||||||
end
|
end
|
||||||
|
lastRow = row
|
||||||
|
|
||||||
|
local entityId = archetype.entities[row :: number]
|
||||||
|
local columns = archetype.columns
|
||||||
|
local tr = compatibleArchetype.indices
|
||||||
|
|
||||||
|
if queryLength == 1 then
|
||||||
|
return entityId, columns[tr[1]][row]
|
||||||
|
elseif queryLength == 2 then
|
||||||
|
return entityId, columns[tr[1]][row], columns[tr[2]][row]
|
||||||
|
elseif queryLength == 3 then
|
||||||
|
return entityId, columns[tr[1]][row], columns[tr[2]][row], columns[tr[3]][row]
|
||||||
|
elseif queryLength == 4 then
|
||||||
|
return entityId, columns[tr[1]][row], columns[tr[2]][row], columns[tr[3]][row], columns[tr[4]][row]
|
||||||
|
elseif queryLength == 5 then
|
||||||
|
return entityId,
|
||||||
|
columns[tr[1]][row],
|
||||||
|
columns[tr[2]][row],
|
||||||
|
columns[tr[3]][row],
|
||||||
|
columns[tr[4]][row],
|
||||||
|
columns[tr[5]][row]
|
||||||
|
elseif queryLength == 6 then
|
||||||
|
return entityId,
|
||||||
|
columns[tr[1]][row],
|
||||||
|
columns[tr[2]][row],
|
||||||
|
columns[tr[3]][row],
|
||||||
|
columns[tr[4]][row],
|
||||||
|
columns[tr[5]][row],
|
||||||
|
columns[tr[6]][row]
|
||||||
|
elseif queryLength == 7 then
|
||||||
|
return entityId,
|
||||||
|
columns[tr[1]][row],
|
||||||
|
columns[tr[2]][row],
|
||||||
|
columns[tr[3]][row],
|
||||||
|
columns[tr[4]][row],
|
||||||
|
columns[tr[5]][row],
|
||||||
|
columns[tr[6]][row],
|
||||||
|
columns[tr[7]][row]
|
||||||
|
elseif queryLength == 8 then
|
||||||
|
return entityId,
|
||||||
|
columns[tr[1]][row],
|
||||||
|
columns[tr[2]][row],
|
||||||
|
columns[tr[3]][row],
|
||||||
|
columns[tr[4]][row],
|
||||||
|
columns[tr[5]][row],
|
||||||
|
columns[tr[6]][row],
|
||||||
|
columns[tr[7]][row],
|
||||||
|
columns[tr[8]][row]
|
||||||
|
end
|
||||||
|
|
||||||
|
for i in components do
|
||||||
|
queryOutput[i] = columns[tr[i]][row]
|
||||||
|
end
|
||||||
|
|
||||||
|
return entityId, unpack(queryOutput, 1, queryLength)
|
||||||
|
end
|
||||||
|
|
||||||
|
function preparedQuery:__iter()
|
||||||
|
return iter
|
||||||
|
end
|
||||||
|
|
||||||
|
function preparedQuery:next()
|
||||||
|
return iter()
|
||||||
end
|
end
|
||||||
|
|
||||||
return setmetatable({}, preparedQuery) :: any
|
return setmetatable({}, preparedQuery) :: any
|
||||||
|
|
Loading…
Reference in a new issue