mirror of
https://github.com/Ukendio/jecs.git
synced 2025-04-24 17:10:03 +00:00
Fix indentations
This commit is contained in:
parent
74ac6e1821
commit
b3d9ffd0bd
1 changed files with 449 additions and 480 deletions
107
src/init.luau
107
src/init.luau
|
@ -18,7 +18,7 @@ type GraphEdge = {
|
|||
to: Archetype?,
|
||||
prev: GraphEdge?,
|
||||
next: GraphEdge?,
|
||||
id: number
|
||||
id: number,
|
||||
}
|
||||
|
||||
type GraphEdges = Map<i53, GraphEdge>
|
||||
|
@ -27,7 +27,7 @@ type GraphNode = {
|
|||
add: GraphEdges,
|
||||
remove: GraphEdges,
|
||||
add_ref: GraphEdge?,
|
||||
remove_ref: GraphEdge?
|
||||
remove_ref: GraphEdge?,
|
||||
}
|
||||
|
||||
export type Archetype = {
|
||||
|
@ -42,12 +42,12 @@ export type Archetype = {
|
|||
type Record = {
|
||||
archetype: Archetype,
|
||||
row: number,
|
||||
dense: i24
|
||||
dense: i24,
|
||||
}
|
||||
|
||||
type EntityIndex = {
|
||||
dense: Map<i24, i53>,
|
||||
sparse: Map<i53, Record>
|
||||
sparse: Map<i53, Record>,
|
||||
}
|
||||
|
||||
type ArchetypeRecord = {
|
||||
|
@ -205,9 +205,7 @@ local function entity_index_new_id(entityIndex: EntityIndex, index: i24): i53
|
|||
return id
|
||||
end
|
||||
|
||||
local function archetype_move(entity_index: EntityIndex, to: Archetype,
|
||||
dst_row: i24, from: Archetype, src_row: i24)
|
||||
|
||||
local function archetype_move(entity_index: EntityIndex, to: Archetype, dst_row: i24, from: Archetype, src_row: i24)
|
||||
local src_columns = from.columns
|
||||
local dst_columns = to.columns
|
||||
local dst_entities = to.entities
|
||||
|
@ -287,8 +285,7 @@ local function hash(arr: { number }): string
|
|||
return table.concat(arr, "_")
|
||||
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
|
||||
-- Keeping the function as small as possible to enable inlining
|
||||
local records
|
||||
|
@ -305,9 +302,7 @@ do
|
|||
return columns[tr.column][row]
|
||||
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]
|
||||
if not record then
|
||||
return nil
|
||||
|
@ -394,9 +389,7 @@ local function world_has(world: World, entity: number, ...: i53): boolean
|
|||
return true
|
||||
end
|
||||
|
||||
local function world_target(world: World, entity: i53,
|
||||
relation: i24, index: number): i24?
|
||||
|
||||
local function world_target(world: World, entity: i53, relation: i24, index: number): i24?
|
||||
local record = world.entityIndex.sparse[entity]
|
||||
local archetype = record.archetype
|
||||
if not archetype then
|
||||
|
@ -454,7 +447,8 @@ local function id_record_ensure(world: World, id: number): IdRecord
|
|||
|
||||
local is_tag = not world_has_one_inline(world, relation, EcsComponent)
|
||||
|
||||
flags = bit32.bor(flags,
|
||||
flags = bit32.bor(
|
||||
flags,
|
||||
if on_add then ECS_ID_HAS_ON_ADD else 0,
|
||||
if on_remove then ECS_ID_HAS_ON_REMOVE else 0,
|
||||
if on_set then ECS_ID_HAS_ON_SET else 0,
|
||||
|
@ -607,8 +601,7 @@ local function find_archetype_without(world: World, node: Archetype, id: i53): A
|
|||
return archetype_ensure(world, dst)
|
||||
end
|
||||
|
||||
local function archetype_init_edge(archetype: Archetype,
|
||||
edge: GraphEdge, id: i53, to: Archetype)
|
||||
local function archetype_init_edge(archetype: Archetype, edge: GraphEdge, id: i53, to: Archetype)
|
||||
edge.from = archetype
|
||||
edge.to = to
|
||||
edge.id = id
|
||||
|
@ -666,29 +659,21 @@ local function init_edge_for_remove(world, archetype, edge, id, to)
|
|||
end
|
||||
end
|
||||
|
||||
local function create_edge_for_add(world: World, node: Archetype,
|
||||
edge: GraphEdge, id: i53): Archetype
|
||||
|
||||
local function create_edge_for_add(world: World, node: Archetype, edge: GraphEdge, id: i53): Archetype
|
||||
local to = find_archetype_with(world, node, id)
|
||||
init_edge_for_add(world, node, edge, id, to)
|
||||
return to
|
||||
end
|
||||
|
||||
local function create_edge_for_remove(world: World, node: Archetype,
|
||||
edge: GraphEdge, id: i53): Archetype
|
||||
|
||||
local function create_edge_for_remove(world: World, node: Archetype, edge: GraphEdge, id: i53): Archetype
|
||||
local to = find_archetype_without(world, node, id)
|
||||
init_edge_for_remove(world, node, edge, id, to)
|
||||
return to
|
||||
end
|
||||
|
||||
|
||||
local function archetype_traverse_add(world: World, id: i53,
|
||||
from: Archetype): Archetype
|
||||
|
||||
local function archetype_traverse_add(world: World, id: i53, from: Archetype): Archetype
|
||||
from = from or world.ROOT_ARCHETYPE
|
||||
local edge = archetype_ensure_edge(
|
||||
world, from.node.add, id)
|
||||
local edge = archetype_ensure_edge(world, from.node.add, id)
|
||||
|
||||
local to = edge.to
|
||||
if not to then
|
||||
|
@ -701,8 +686,7 @@ end
|
|||
local function archetype_traverse_remove(world: World, id: i53, from: Archetype): Archetype
|
||||
from = from or world.ROOT_ARCHETYPE
|
||||
|
||||
local edge = archetype_ensure_edge(
|
||||
world, from.node.add, id)
|
||||
local edge = archetype_ensure_edge(world, from.node.add, id)
|
||||
|
||||
local to = edge.to
|
||||
if not to then
|
||||
|
@ -850,9 +834,7 @@ local function world_clear(world: World, entity: i53)
|
|||
entity_move(world.entityIndex, entity, record, ROOT_ARCHETYPE)
|
||||
end
|
||||
|
||||
local function archetype_fast_delete_last(columns: { Column },
|
||||
column_count: number, types: { i53 }, entity: i53)
|
||||
|
||||
local function archetype_fast_delete_last(columns: { Column }, column_count: number, types: { i53 }, entity: i53)
|
||||
for i, column in columns do
|
||||
if column ~= NULL_ARRAY then
|
||||
column[column_count] = nil
|
||||
|
@ -860,9 +842,7 @@ local function archetype_fast_delete_last(columns: { Column },
|
|||
end
|
||||
end
|
||||
|
||||
local function archetype_fast_delete(columns: { Column },
|
||||
column_count: number, row, types, entity)
|
||||
|
||||
local function archetype_fast_delete(columns: { Column }, column_count: number, row, types, entity)
|
||||
for i, column in columns do
|
||||
if column ~= NULL_ARRAY then
|
||||
column[row] = column[column_count]
|
||||
|
@ -882,9 +862,7 @@ local function archetype_disconnect_edge(edge: GraphEdge)
|
|||
end
|
||||
end
|
||||
|
||||
local function archetype_remove_edge(edges: Map<i53, GraphEdge>,
|
||||
id: i53, edge: GraphEdge)
|
||||
|
||||
local function archetype_remove_edge(edges: Map<i53, GraphEdge>, id: i53, edge: GraphEdge)
|
||||
archetype_disconnect_edge(edge)
|
||||
edges[id] = nil
|
||||
end
|
||||
|
@ -960,9 +938,7 @@ end
|
|||
|
||||
local world_delete: (world: World, entity: i53, destruct: boolean?) -> ()
|
||||
do
|
||||
local function archetype_delete(world: World,
|
||||
archetype: Archetype, row: number, destruct: boolean?)
|
||||
|
||||
local function archetype_delete(world: World, archetype: Archetype, row: number, destruct: boolean?)
|
||||
local entityIndex = world.entityIndex
|
||||
local columns = archetype.columns
|
||||
local types = archetype.types
|
||||
|
@ -1044,15 +1020,15 @@ do
|
|||
if idr_t then
|
||||
for archetype_id in idr_t.cache do
|
||||
local children = {}
|
||||
local idr_o_archetype = archetypes[archetype_id]
|
||||
local idr_t_archetype = archetypes[archetype_id]
|
||||
|
||||
local idr_o_types = idr_o_archetype.types
|
||||
local idr_t_types = idr_t_archetype.types
|
||||
|
||||
for _, child in idr_o_archetype.entities do
|
||||
for _, child in idr_t_archetype.entities do
|
||||
table.insert(children, child)
|
||||
end
|
||||
|
||||
for _, id in idr_o_types do
|
||||
for _, id in idr_t_types do
|
||||
if not ECS_IS_PAIR(id) then
|
||||
continue
|
||||
end
|
||||
|
@ -1081,7 +1057,6 @@ do
|
|||
|
||||
record.archetype = nil :: any
|
||||
entityIndex.sparse[entity] = nil
|
||||
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -1089,7 +1064,6 @@ local function world_contains(world: World, entity): boolean
|
|||
return world.entityIndex.sparse[entity] ~= nil
|
||||
end
|
||||
|
||||
|
||||
local function NOOP() end
|
||||
|
||||
local function ARM(query, ...)
|
||||
|
@ -1598,7 +1572,9 @@ if _G.__JECS_DEBUG then
|
|||
-- error but stack trace always starts at first callsite outside of this file
|
||||
local function throw(msg: string)
|
||||
local s = 1
|
||||
repeat s += 1 until debug.info(s, "s") ~= debug.info(1, "s")
|
||||
repeat
|
||||
s += 1
|
||||
until debug.info(s, "s") ~= debug.info(1, "s")
|
||||
if warn then
|
||||
error(msg, s)
|
||||
else
|
||||
|
@ -1649,14 +1625,14 @@ if _G.__JECS_DEBUG then
|
|||
|
||||
World.set = function(world: World, entity: i53, id: i53, value: any): ()
|
||||
local is_tag = ID_IS_TAG(world, id)
|
||||
if (is_tag and value == nil) then
|
||||
if is_tag and value == nil then
|
||||
world_add(world, entity, id)
|
||||
local _1 = get_name(world, entity)
|
||||
local _2 = get_name(world, id)
|
||||
local why = "cannot set component value to nil"
|
||||
throw(why)
|
||||
return
|
||||
elseif (value ~= nil and is_tag) then
|
||||
elseif value ~= nil and is_tag then
|
||||
world_add(world, entity, id)
|
||||
local _1 = get_name(world, entity)
|
||||
local _2 = get_name(world, id)
|
||||
|
@ -1684,8 +1660,7 @@ if _G.__JECS_DEBUG then
|
|||
if value ~= nil then
|
||||
local _1 = get_name(world, entity)
|
||||
local _2 = get_name(world, id)
|
||||
throw("You provided a value when none was expected. "
|
||||
..`Did you mean to use "world:add({_1}, {_2})"`)
|
||||
throw("You provided a value when none was expected. " .. `Did you mean to use "world:add({_1}, {_2})"`)
|
||||
return
|
||||
end
|
||||
|
||||
|
@ -1710,7 +1685,8 @@ if _G.__JECS_DEBUG then
|
|||
end
|
||||
throw(
|
||||
`cannot get (#{i}) component {name} value because it is a tag.`
|
||||
..`\n[jecs] note: If this was intentional, use "world:has({_1}, {name}) instead"`)
|
||||
.. `\n[jecs] note: If this was intentional, use "world:has({_1}, {name}) instead"`
|
||||
)
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -1722,15 +1698,15 @@ if _G.__JECS_DEBUG then
|
|||
local _1 = get_name(world, entity)
|
||||
local _2 = get_name(world, relation)
|
||||
|
||||
throw("We have changed the function call to require an index parameter,"
|
||||
..` please use world:target({_1}, {_2}, 0)`)
|
||||
throw(
|
||||
"We have changed the function call to require an index parameter,"
|
||||
.. ` please use world:target({_1}, {_2}, 0)`
|
||||
)
|
||||
end
|
||||
return world_target(world, entity, relation, index)
|
||||
end
|
||||
|
||||
World.remove = function()
|
||||
|
||||
end
|
||||
World.remove = function() end
|
||||
end
|
||||
|
||||
function World.new()
|
||||
|
@ -1853,14 +1829,7 @@ export type World = {
|
|||
& (<A, B>(self: World, Id<A>, Id<B>) -> Query<A, B>)
|
||||
& (<A, B, C>(self: World, Id<A>, Id<B>, Id<C>) -> Query<A, B, C>)
|
||||
& (<A, B, C, D>(self: World, Id<A>, Id<B>, Id<C>, Id<D>) -> Query<A, B, C, D>)
|
||||
& (<A, B, C, D, E>(
|
||||
self: World,
|
||||
Id<A>,
|
||||
Id<B>,
|
||||
Id<C>,
|
||||
Id<D>,
|
||||
Id<E>
|
||||
) -> Query<A, B, C, D, E>)
|
||||
& (<A, B, C, D, E>(self: World, Id<A>, Id<B>, Id<C>, Id<D>, Id<E>) -> Query<A, B, C, D, E>)
|
||||
& (<A, B, C, D, E, F>(
|
||||
self: World,
|
||||
Id<A>,
|
||||
|
|
Loading…
Reference in a new issue