Fix indentation and variable names

This commit is contained in:
Ukendio 2024-08-05 17:13:00 +02:00
parent fd40993ceb
commit d302588081

View file

@ -631,7 +631,11 @@ end
local world_get: (world: World, entityId: i53, a: i53, b: i53?, c: i53?, d: i53?, e: i53?) -> (...any) local world_get: (world: World, entityId: i53, a: i53, b: i53?, c: i53?, d: i53?, e: i53?) -> (...any)
do do
-- Keeping the function as small as possible to enable inlining -- Keeping the function as small as possible to enable inlining
local function fetch(id: i24, records: { ArchetypeRecord }, columns, row): any local records
local columns
local row
local function fetch(id): any
local tr = records[id] local tr = records[id]
if not tr then if not tr then
@ -641,9 +645,8 @@ do
return columns[tr.column][row] return columns[tr.column][row]
end end
function world_get(world: World, entityId: i53, a: i53, b: i53?, c: i53?, d: i53?, e: i53?): ...any function world_get(world: World, entity: i53, a: i53, b: i53?, c: i53?, d: i53?, e: i53?): ...any
local id = entityId local record = world.entityIndex.sparse[entity]
local record = world.entityIndex.sparse[id]
if not record then if not record then
return nil return nil
end end
@ -653,49 +656,46 @@ do
return nil return nil
end end
local tr = archetype.records records = archetype.records
local columns = archetype.columns columns = archetype.columns
local row = record.row row = record.row
local va = fetch(a, tr, columns, row) local va = fetch(a)
if b == nil then if not b then
return va return va
elseif c == nil then elseif not c then
return va, fetch(b, tr, columns, row) return va, fetch(b)
elseif d == nil then elseif not d then
return va, fetch(b, tr, columns, row), fetch(c, tr, columns, row) return va, fetch(b), fetch(c)
elseif e == nil then elseif not e then
return va, fetch(b, tr, columns, row), fetch(c, tr, columns, row), fetch(d, tr, columns, row) return va, fetch(b), fetch(c), fetch(d)
else else
error("args exceeded") error("args exceeded")
end end
end end
end end
local world_has: (world: World, entity: number, ...i53) -> boolean local function world_has(world: World, entity: number, ...: i53): boolean
do local record = world.entityIndex.sparse[entity]
function world_has(world, entity, ...) if not record then
local record = world.entityIndex.sparse[entity] return false
if not record then end
return false
end
local archetype = record.archetype local archetype = record.archetype
if not archetype then if not archetype then
return false return false
end end
local tr = archetype.records local records = archetype.records
for i = 1, select("#", ...) do for i = 1, select("#", ...) do
if not tr[select(i, ...)] then if not records[select(i, ...)] then
return false return false
end
end end
return true
end end
return true
end end
type Item = () -> (number, ...any) type Item = () -> (number, ...any)
@ -776,13 +776,13 @@ do
for archetype_id in idr.cache do for archetype_id in idr.cache do
local compatibleArchetype = archetypes[archetype_id] local compatibleArchetype = archetypes[archetype_id]
local tr = compatibleArchetype.records local records = compatibleArchetype.records
local skip = false local skip = false
for i, id in ids do for i, id in ids do
local index = tr[id] local tr = records[id]
if not index then if not tr then
skip = true skip = true
break break
end end
@ -984,9 +984,9 @@ do
return entityId, a[row], b[row], c[row], d[row], e[row], f[row], g[row], h[row] return entityId, a[row], b[row], c[row], d[row], e[row], f[row], g[row], h[row]
end end
local field = archetype.records local records = archetype.records
for j, id in ids do for j, id in ids do
queryOutput[j] = columns[field[id].column][row] queryOutput[j] = columns[records[id].column][row]
end end
return entityId, unpack(queryOutput) return entityId, unpack(queryOutput)
@ -1065,108 +1065,108 @@ do
end end
local function world_query_without(query, ...) local function world_query_without(query, ...)
local N = select("#", ...) local N = select("#", ...)
for i = #compatible_archetypes, 1, -1 do for i = #compatible_archetypes, 1, -1 do
local archetype = compatible_archetypes[i] local archetype = compatible_archetypes[i]
local tr = archetype.records local records = archetype.records
local shouldRemove = false local shouldRemove = false
for j = 1, N do for j = 1, N do
local id = select(j, ...) local id = select(j, ...)
if tr[id] then if records[id] then
shouldRemove = true shouldRemove = true
break break
end end
end
if shouldRemove then
local last = #compatible_archetypes
if last ~= i then
compatible_archetypes[i] = compatible_archetypes[last]
end
compatible_archetypes[last] = nil
length -= 1
end
end
if length == 0 then
return EmptyQuery
end end
return query if shouldRemove then
local last = #compatible_archetypes
if last ~= i then
compatible_archetypes[i] = compatible_archetypes[last]
end
compatible_archetypes[last] = nil
length -= 1
end
end
if length == 0 then
return EmptyQuery
end
return query
end end
local function world_query_replace(query, fn: (...any) -> (...any)) local function world_query_replace(query, fn: (...any) -> (...any))
query_init(query) query_init(query)
for i, archetype in compatible_archetypes do for i, archetype in compatible_archetypes do
local columns = archetype.columns local columns = archetype.columns
local tr = archetype.records local records = archetype.records
for row in archetype.entities do for row in archetype.entities do
if not B then if not B then
local va = columns[tr[A].column] local va = columns[records[A].column]
local pa = fn(va[row]) local pa = fn(va[row])
va[row] = pa va[row] = pa
elseif not C then elseif not C then
local va = columns[tr[A].column] local va = columns[records[A].column]
local vb = columns[tr[B].column] local vb = columns[records[B].column]
va[row], vb[row] = fn(va[row], vb[row]) va[row], vb[row] = fn(va[row], vb[row])
elseif not D then elseif not D then
local va = columns[tr[A].column] local va = columns[records[A].column]
local vb = columns[tr[B].column] local vb = columns[records[B].column]
local vc = columns[tr[C].column] local vc = columns[records[C].column]
va[row], vb[row], vc[row] = fn(va[row], vb[row], vc[row]) va[row], vb[row], vc[row] = fn(va[row], vb[row], vc[row])
elseif not E then elseif not E then
local va = columns[tr[A].column] local va = columns[records[A].column]
local vb = columns[tr[B].column] local vb = columns[records[B].column]
local vc = columns[tr[C].column] local vc = columns[records[C].column]
local vd = columns[tr[D].column] local vd = columns[records[D].column]
va[row], vb[row], vc[row], vd[row] = fn( va[row], vb[row], vc[row], vd[row] = fn(
va[row], vb[row], vc[row], vd[row]) va[row], vb[row], vc[row], vd[row])
else else
local field = archetype.records for j, id in ids do
for j, id in ids do local tr = records[id]
queryOutput[j] = columns[field[id].column][row] queryOutput[j] = columns[tr.column][row]
end
world_query_replace_values(row, columns,
fn(unpack(queryOutput)))
end end
end world_query_replace_values(row, columns,
fn(unpack(queryOutput)))
end
end end
end
end end
local function world_query_with(query, ...) local function world_query_with(query, ...)
local N = select("#", ...) local N = select("#", ...)
for i = #compatible_archetypes, 1, -1 do for i = #compatible_archetypes, 1, -1 do
local archetype = compatible_archetypes[i] local archetype = compatible_archetypes[i]
local tr = archetype.records local records = archetype.records
local shouldRemove = false local shouldRemove = false
for j = 1, N do for j = 1, N do
local id = select(j, ...) local id = select(j, ...)
if not tr[id] then if not records[id] then
shouldRemove = true shouldRemove = true
break break
end end
end
if shouldRemove then
local last = #compatible_archetypes
if last ~= i then
compatible_archetypes[i] = compatible_archetypes[last]
end end
compatible_archetypes[last] = nil
if shouldRemove then length -= 1
local last = #compatible_archetypes end
if last ~= i then end
compatible_archetypes[i] = compatible_archetypes[last] if length == 0 then
end return EmptyQuery
compatible_archetypes[last] = nil end
length -= 1 return query
end
end
if length == 0 then
return EmptyQuery
end
return query
end end
-- Meant for directly iterating over archetypes to minimize -- Meant for directly iterating over archetypes to minimize