Uniform function declarations

This commit is contained in:
Ukendio 2024-06-26 15:50:00 +02:00
parent 6b4597ab96
commit 0ff2348a6e

View file

@ -652,22 +652,18 @@ local function PreparedQuery(
return EmptyQuery return EmptyQuery
end end
local preparedQuery = {}
preparedQuery.__index = preparedQuery
local queryOutput = {} local queryOutput = {}
local i = 1 local i = 1
local length = #compatibleArchetypes
local function queryNext(): ...any local function queryNext(): ...any
local entityId = archetype.entities[i] local entityId = archetype.entities[i]
while entityId == nil do while entityId == nil do
lastArchetype += 1 lastArchetype += 1
archetype = compatibleArchetypes[lastArchetype] archetype = compatibleArchetypes[lastArchetype]
if lastArchetype > length then if not archetype then
return return
end end
i = 1 i = 1
@ -731,15 +727,7 @@ local function PreparedQuery(
return entityId, unpack(queryOutput, 1, queryLength) return entityId, unpack(queryOutput, 1, queryLength)
end end
function preparedQuery:__iter(): () -> ...any local function without(self, ...): Query
return queryNext
end
function preparedQuery:next(): ...any
return queryNext()
end
function preparedQuery:without(...: any): Query
local withoutComponents = { ... } local withoutComponents = { ... }
for i = #compatibleArchetypes, 1, -1 do for i = #compatibleArchetypes, 1, -1 do
local archetype = compatibleArchetypes[i] local archetype = compatibleArchetypes[i]
@ -766,7 +754,15 @@ local function PreparedQuery(
return self return self
end end
return setmetatable({}, preparedQuery) :: any local preparedQuery = {
__iter = function()
return queryNext
end,
next = queryNext,
without = without
}
return (setmetatable(preparedQuery, preparedQuery) :: any):: Query
end end
function World.query(world: World, ...: any): Query function World.query(world: World, ...: any): Query