Fix indentations

This commit is contained in:
Ukendio 2024-08-30 21:00:50 +02:00
parent 4f65be279b
commit a974132e29

View file

@ -272,7 +272,8 @@ local function hash(arr: { number }): string
return table.concat(arr, "_") return table.concat(arr, "_")
end 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 records local records
@ -289,7 +290,9 @@ do
return columns[tr.column][row] return columns[tr.column][row]
end end
function world_get(world: World, entity: 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 record = world.entityIndex.sparse[entity] local record = world.entityIndex.sparse[entity]
if not record then if not record then
return nil return nil
@ -401,7 +404,9 @@ end
-- TODO: -- TODO:
-- should have an additional `nth` parameter which selects the nth target -- should have an additional `nth` parameter which selects the nth target
-- this is important when an entity can have multiple relationships with the same target -- this is important when an entity can have multiple relationships with the same target
local function world_target(world: World, entity: i53, relation: i24--[[, nth: number]]): i24? local function world_target(world: World, entity: i53,
relation: i24--[[, nth: number]]): i24?
local record = world.entityIndex.sparse[entity] local record = world.entityIndex.sparse[entity]
local archetype = record.archetype local archetype = record.archetype
if not archetype then if not archetype then
@ -421,10 +426,7 @@ local function world_target(world: World, entity: i53, relation: i24--[[, nth: n
return ecs_pair_second(world, archetype.types[tr.column]) return ecs_pair_second(world, archetype.types[tr.column])
end end
local function id_record_ensure( local function id_record_ensure(world: World, id: number): ArchetypeMap
world: World,
id: number
): ArchetypeMap
local componentIndex = world.componentIndex local componentIndex = world.componentIndex
local idr = componentIndex[id] local idr = componentIndex[id]
@ -433,16 +435,13 @@ local function id_record_ensure(
local relation = ECS_ENTITY_T_HI(id) local relation = ECS_ENTITY_T_HI(id)
local cleanup_policy = world_target(world, relation, EcsOnDelete) local cleanup_policy = world_target(world, relation, EcsOnDelete)
local cleanup_policy_target = world_target(world, relation, local cleanup_policy_target = world_target(world, relation, EcsOnDeleteTarget)
EcsOnDeleteTarget)
if cleanup_policy == EcsDelete or cleanup_policy_target == EcsDelete then if cleanup_policy == EcsDelete or cleanup_policy_target == EcsDelete then
flags = bit32.bor(flags, ECS_ID_DELETE) flags = bit32.bor(flags, ECS_ID_DELETE)
end end
if world_has_any(world, relation, if world_has_any(world, relation, EcsOnAdd, EcsOnSet, EcsOnRemove) then
EcsOnAdd, EcsOnSet, EcsOnRemove)
then
flags = bit32.bor(flags, ECS_ID_HAS_HOOKS) flags = bit32.bor(flags, ECS_ID_HAS_HOOKS)
end end
@ -457,7 +456,7 @@ local function id_record_ensure(
idr = { idr = {
size = 0, size = 0,
cache = {}, cache = {},
flags = flags flags = flags,
} :: ArchetypeMap } :: ArchetypeMap
componentIndex[id] = idr componentIndex[id] = idr
end end
@ -754,16 +753,16 @@ local function world_clear(world: World, entity: i53)
entity_move(world.entityIndex, entity, record, ROOT_ARCHETYPE) entity_move(world.entityIndex, entity, record, ROOT_ARCHETYPE)
end end
local function archetype_fast_delete_last(columns, column_count, local function archetype_fast_delete_last(columns: { Column },
types, entity) column_count: number, types: { i53 }, entity: i53)
for i, column in columns do for i, column in columns do
column[column_count] = nil column[column_count] = nil
end end
end end
local function archetype_fast_delete(columns, column_count, local function archetype_fast_delete(columns: { Column },
row, types, entity) column_count: number, row, types, entity)
for i, column in columns do for i, column in columns do
column[row] = column[column_count] column[row] = column[column_count]
@ -771,8 +770,6 @@ local function archetype_fast_delete(columns, column_count,
end end
end end
local ERROR_DELETE_PANIC = "Tried to delete entity that has (OnDelete, Panic)"
local function archetype_delete(world: World, local function archetype_delete(world: World,
archetype: Archetype, row: number) archetype: Archetype, row: number)
@ -802,14 +799,11 @@ local function archetype_delete(world: World,
end end
if row == last then if row == last then
archetype_fast_delete_last(columns, archetype_fast_delete_last(columns, column_count, types, delete)
column_count, types, delete)
else else
archetype_fast_delete(columns, column_count, archetype_fast_delete(columns, column_count, row, types, delete)
row, types, delete)
end end
local component_index = world.componentIndex local component_index = world.componentIndex
local archetypes = world.archetypes local archetypes = world.archetypes
@ -933,8 +927,7 @@ end
type CompatibleArchetype = { archetype: Archetype, indices: { number } } type CompatibleArchetype = { archetype: Archetype, indices: { number } }
local function noop() local function noop() end
end
local function Arm(query, ...) local function Arm(query, ...)
return query return query
@ -1057,7 +1050,7 @@ do
end end
local row = i local row = i
i-=1 i -= 1
return entityId, a[row] return entityId, a[row]
end end
@ -1084,7 +1077,7 @@ do
end end
local row = i local row = i
i-=1 i -= 1
return entityId, a[row], b[row] return entityId, a[row], b[row]
end end
@ -1112,7 +1105,7 @@ do
end end
local row = i local row = i
i-=1 i -= 1
return entityId, a[row], b[row], c[row] return entityId, a[row], b[row], c[row]
end end
@ -1141,7 +1134,7 @@ do
end end
local row = i local row = i
i-=1 i -= 1
return entityId, a[row], b[row], c[row], d[row] return entityId, a[row], b[row], c[row], d[row]
end end
@ -1198,7 +1191,7 @@ do
end end
local row = i local row = i
i-=1 i -= 1
if not F then if not F then
return entityId, a[row], b[row], c[row], d[row], e[row] return entityId, a[row], b[row], c[row], d[row], e[row]
@ -1322,7 +1315,7 @@ do
return query 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
@ -1351,15 +1344,13 @@ do
local vc = columns[records[C].column] local vc = columns[records[C].column]
local vd = columns[records[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
for j, id in ids do for j, id in ids do
local tr = records[id] local tr = records[id]
queryOutput[j] = columns[tr.column][row] queryOutput[j] = columns[tr.column][row]
end end
world_query_replace_values(row, columns, world_query_replace_values(row, columns, fn(unpack(queryOutput)))
fn(unpack(queryOutput)))
end end
end end
end end
@ -1430,7 +1421,7 @@ do
with = world_query_with, with = world_query_with,
without = world_query_without, without = world_query_without,
replace = world_query_replace, replace = world_query_replace,
archetypes = world_query_archetypes archetypes = world_query_archetypes,
} :: any } :: any
setmetatable(it, it) setmetatable(it, it)
@ -1478,8 +1469,7 @@ function World.new()
entity_index_new_id(self.entityIndex, i) entity_index_new_id(self.entityIndex, i)
end end
world_add(self, EcsChildOf, world_add(self, EcsChildOf, ECS_PAIR(EcsOnDeleteTarget, EcsDelete))
ECS_PAIR(EcsOnDeleteTarget, EcsDelete))
return self return self
end end
@ -1490,19 +1480,19 @@ export type Pair = number
type Item<T...> = (self: Query<T...>) -> (Entity, T...) type Item<T...> = (self: Query<T...>) -> (Entity, T...)
export type Entity<T = nil> = number & {__T: T } export type Entity<T = nil> = number & { __T: T }
type Iter<T...> = (query: Query<T...>) -> () -> (Entity, T...) type Iter<T...> = (query: Query<T...>) -> () -> (Entity, T...)
type Query<T...> = typeof(setmetatable({}, { type Query<T...> = typeof(setmetatable({}, {
__iter = (nil :: any) :: Iter<T...> __iter = (nil :: any) :: Iter<T...>,
})) & { })) & {
iter: Iter<T...>, iter: Iter<T...>,
next: Item<T...>, next: Item<T...>,
drain: (self: Query<T...>) -> Query<T...>, drain: (self: Query<T...>) -> Query<T...>,
with: (self: Query<T...>, ...i53) -> Query<T...>, with: (self: Query<T...>, ...i53) -> Query<T...>,
without: (self: Query<T...>, ...i53) -> Query<T...>, without: (self: Query<T...>, ...i53) -> Query<T...>,
replace: (self: Query<T...>, <U...>(T...) -> (U...)) -> (), replace: (self: Query<T...>, <U...>(T...) -> U...) -> (),
archetypes: () -> { Archetype }, archetypes: () -> { Archetype },
} }
@ -1594,7 +1584,7 @@ export type World = {
Id<H>, Id<H>,
...Id<any> ...Id<any>
) -> Query<A, B, C, D, E, F, G, H>), ) -> Query<A, B, C, D, E, F, G, H>),
} }
return { return {
World = World :: { new: () -> World }, World = World :: { new: () -> World },