mirror of
https://github.com/Ukendio/jecs.git
synced 2025-04-25 01:20:04 +00:00
Remove hard coded behaviour
This commit is contained in:
parent
7d48063d20
commit
33192b7a6f
1 changed files with 18 additions and 76 deletions
92
lib/init.lua
92
lib/init.lua
|
@ -338,8 +338,6 @@ function World.query(world: World, ...: i53): (() -> (number, ...any)) | () -> (
|
|||
local queryLength = #components
|
||||
local firstArchetypeMap = getSmallestMap(world.componentIndex, components)
|
||||
|
||||
local a, b, c, d, e, f, g, h = ...
|
||||
|
||||
if not firstArchetypeMap then
|
||||
return noop()
|
||||
end
|
||||
|
@ -349,81 +347,25 @@ function World.query(world: World, ...: i53): (() -> (number, ...any)) | () -> (
|
|||
local columns = archetype.columns
|
||||
local archetypeRecords = archetype.records
|
||||
local indices = {}
|
||||
if queryLength == 1 then
|
||||
indices = {
|
||||
columns[archetypeRecords[a]],
|
||||
}
|
||||
elseif queryLength == 2 then
|
||||
indices = {
|
||||
columns[archetypeRecords[a]],
|
||||
columns[archetypeRecords[b]]
|
||||
}
|
||||
elseif queryLength == 3 then
|
||||
indices = {
|
||||
columns[archetypeRecords[a]],
|
||||
columns[archetypeRecords[b]],
|
||||
columns[archetypeRecords[c]]
|
||||
}
|
||||
elseif queryLength == 4 then
|
||||
indices = {
|
||||
columns[archetypeRecords[a]],
|
||||
columns[archetypeRecords[b]],
|
||||
columns[archetypeRecords[c]],
|
||||
columns[archetypeRecords[d]]
|
||||
}
|
||||
elseif queryLength == 5 then
|
||||
indices = {
|
||||
columns[archetypeRecords[a]],
|
||||
columns[archetypeRecords[b]],
|
||||
columns[archetypeRecords[c]],
|
||||
columns[archetypeRecords[d]],
|
||||
columns[archetypeRecords[e]]
|
||||
}
|
||||
elseif queryLength == 6 then
|
||||
indices = {
|
||||
columns[archetypeRecords[a]],
|
||||
columns[archetypeRecords[b]],
|
||||
columns[archetypeRecords[c]],
|
||||
columns[archetypeRecords[d]],
|
||||
columns[archetypeRecords[e]],
|
||||
columns[archetypeRecords[f]],
|
||||
}
|
||||
elseif queryLength == 7 then
|
||||
indices = {
|
||||
columns[archetypeRecords[a]],
|
||||
columns[archetypeRecords[b]],
|
||||
columns[archetypeRecords[c]],
|
||||
columns[archetypeRecords[d]],
|
||||
columns[archetypeRecords[e]],
|
||||
columns[archetypeRecords[f]],
|
||||
columns[archetypeRecords[g]],
|
||||
}
|
||||
elseif queryLength == 8 then
|
||||
indices = {
|
||||
columns[archetypeRecords[a]],
|
||||
columns[archetypeRecords[b]],
|
||||
columns[archetypeRecords[c]],
|
||||
columns[archetypeRecords[d]],
|
||||
columns[archetypeRecords[e]],
|
||||
columns[archetypeRecords[f]],
|
||||
columns[archetypeRecords[g]],
|
||||
}
|
||||
else
|
||||
for i, componentId in components do
|
||||
indices[i] = columns[archetypeRecords[componentId]]
|
||||
end
|
||||
end
|
||||
|
||||
local i = 0
|
||||
for _ in indices do
|
||||
i += 1
|
||||
end
|
||||
if queryLength == i then
|
||||
table.insert(compatibleArchetypes, {
|
||||
archetype = archetype,
|
||||
indices = indices
|
||||
})
|
||||
local skip = false
|
||||
for i, componentId in components do
|
||||
local data = columns[archetypeRecords[componentId]]
|
||||
if not data then
|
||||
skip = true
|
||||
break
|
||||
end
|
||||
indices[i] = data
|
||||
end
|
||||
|
||||
if skip then
|
||||
continue
|
||||
end
|
||||
|
||||
table.insert(compatibleArchetypes, {
|
||||
archetype = archetype,
|
||||
indices = indices
|
||||
})
|
||||
end
|
||||
|
||||
local lastArchetype, compatibleArchetype = next(compatibleArchetypes)
|
||||
|
|
Loading…
Reference in a new issue