kill a regression

This commit is contained in:
HowManySmall 2024-05-04 16:28:36 -06:00
parent 354f100dd1
commit c7113d6bc9

View file

@ -125,7 +125,7 @@ local function hash(arr): string | number
return table.concat(arr, "_") return table.concat(arr, "_")
end end
local function createArchetypeRecords(componentIndex: ComponentIndex, to: Archetype, from: Archetype?) local function createArchetypeRecords(componentIndex: ComponentIndex, to: Archetype, _from: Archetype?)
local destinationIds = to.types local destinationIds = to.types
local records = to.records local records = to.records
local id = to.id local id = to.id
@ -295,12 +295,11 @@ local function archetypeTraverseAdd(world: World, componentId: i53, from: Archet
end end
local function ensureRecord(entityIndex, entityId: i53): Record local function ensureRecord(entityIndex, entityId: i53): Record
local id = entityId local record = entityIndex[entityId]
local record = entityIndex[id]
if not record then if not record then
record = {} record = {}
entityIndex[id] = record entityIndex[entityId] = record
end end
return record :: Record return record :: Record
@ -395,8 +394,10 @@ function World.get(world: World, entityId: i53, a: i53, b: i53?, c: i53?, d: i53
end end
end end
-- the less creation the better
local function actualNoOperation() end
local function noop(_self: Query, ...: i53): () -> (number, ...any) local function noop(_self: Query, ...: i53): () -> (number, ...any)
return function() end :: any return actualNoOperation :: any
end end
local EmptyQuery = { local EmptyQuery = {
@ -409,6 +410,11 @@ setmetatable(EmptyQuery, EmptyQuery)
export type Query = typeof(EmptyQuery) export type Query = typeof(EmptyQuery)
function World.query(world: World, ...: i53): Query function World.query(world: World, ...: i53): Query
-- breaking?
if (...) == nil then
error("Missing components")
end
local compatibleArchetypes = {} local compatibleArchetypes = {}
local length = 0 local length = 0
@ -416,10 +422,6 @@ function World.query(world: World, ...: i53): Query
local archetypes = world.archetypes local archetypes = world.archetypes
local queryLength = #components local queryLength = #components
if queryLength == 0 then
error("Missing components")
end
local firstArchetypeMap local firstArchetypeMap
local componentIndex = world.componentIndex local componentIndex = world.componentIndex
@ -466,19 +468,21 @@ function World.query(world: World, ...: i53): Query
preparedQuery.__index = preparedQuery preparedQuery.__index = preparedQuery
function preparedQuery:without(...) function preparedQuery:without(...)
local withoutComponents = {...} local components = {...}
for index = #compatibleArchetypes, 1, -1 do for i = #compatibleArchetypes, 1, -1 do
local archetype = compatibleArchetypes[index][1] local archetype = compatibleArchetypes[i][1]
local records = archetype.records local records = archetype.records
local shouldRemove = false local shouldRemove = false
for _, componentId in withoutComponents do
for _, componentId in components do
if records[componentId] then if records[componentId] then
shouldRemove = true shouldRemove = true
break break
end end
end end
if shouldRemove then if shouldRemove then
table.remove(compatibleArchetypes, index) table.remove(compatibleArchetypes, i)
end end
end end
@ -557,8 +561,8 @@ function World.query(world: World, ...: i53): Query
columns[tr[8]][row] columns[tr[8]][row]
end end
for index in components do for i in components do
queryOutput[index] = tr[index][row] queryOutput[i] = tr[i][row]
end end
return entityId, unpack(queryOutput, 1, queryLength) return entityId, unpack(queryOutput, 1, queryLength)