Skip to content

Commit

Permalink
Add test for querying more than 8 components
Browse files Browse the repository at this point in the history
  • Loading branch information
Ukendio committed Jul 30, 2024
1 parent 6d9122c commit 24f9f58
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 7 deletions.
13 changes: 6 additions & 7 deletions src/init.luau
Original file line number Diff line number Diff line change
Expand Up @@ -739,7 +739,7 @@ do
local lastArchetype: number
local archetype: Archetype
local queryOutput: { any }
local queryLength: number

local entities: { number }
local i: number

Expand Down Expand Up @@ -768,7 +768,6 @@ do
end

queryOutput = {}
queryLength = #ids

entities = archetype.entities
i = #entities
Expand Down Expand Up @@ -810,7 +809,7 @@ do
e = columns[records[E]]
f = columns[records[F]]
g = columns[records[G]]
elseif H then
elseif not I then
a = columns[records[A]]
b = columns[records[B]]
c = columns[records[D]]
Expand Down Expand Up @@ -873,7 +872,7 @@ do
e = columns[records[E]]
f = columns[records[F]]
g = columns[records[G]]
elseif H then
elseif not I then
a = columns[records[A]]
b = columns[records[B]]
c = columns[records[D]]
Expand Down Expand Up @@ -919,7 +918,7 @@ do
e[row],
f[row],
g[row]
elseif H then
elseif not I then
return entityId,
a[row],
b[row],
Expand Down Expand Up @@ -1108,12 +1107,12 @@ do

for id in firstArchetypeMap.cache do
local compatibleArchetype = archetypes[id]
local archetypeRecords = compatibleArchetype.records
local tr = compatibleArchetype.records

local skip = false

for i, componentId in components do
local index = archetypeRecords[componentId]
local index = tr[componentId]
if not index then
skip = true
break
Expand Down
26 changes: 26 additions & 0 deletions test/tests.luau
Original file line number Diff line number Diff line change
Expand Up @@ -283,6 +283,32 @@ TEST("world:query()", function()
CHECK(counter == 0)
end

do CASE "query more than 8 components"
local world = jecs.World.new()
local components = {}

for i = 1, 9 do
local id = world:component()
components[i] = id
end
local e = world:entity()
for i, id in components do
world:set(e, id, 13^i)
end

for entity, a, b, c, d, e, f, g, h, i in world:query(unpack(components)) do
CHECK(a == 13^1)
CHECK(b == 13^2)
CHECK(c == 13^3)
CHECK(d == 13^4)
CHECK(e == 13^5)
CHECK(f == 13^6)
CHECK(g == 13^7)
CHECK(h == 13^8)
CHECK(i == 13^9)
end
end

do CASE "should be able to get next results"
local world = jecs.World.new() :: World
world:component()
Expand Down

0 comments on commit 24f9f58

Please sign in to comment.