mirror of
https://github.com/Ukendio/jecs.git
synced 2025-04-25 01:20:04 +00:00
Extract logic from ensureComponentRecord
This commit is contained in:
parent
7d2cd6219b
commit
fb3b8a5f67
1 changed files with 16 additions and 13 deletions
|
@ -264,9 +264,7 @@ end
|
||||||
|
|
||||||
local function ensureComponentRecord(
|
local function ensureComponentRecord(
|
||||||
componentIndex: ComponentIndex,
|
componentIndex: ComponentIndex,
|
||||||
archetypeId: number,
|
componentId: number
|
||||||
componentId: number,
|
|
||||||
i: number
|
|
||||||
): ArchetypeMap
|
): ArchetypeMap
|
||||||
local archetypesMap = componentIndex[componentId]
|
local archetypesMap = componentIndex[componentId]
|
||||||
|
|
||||||
|
@ -275,9 +273,6 @@ local function ensureComponentRecord(
|
||||||
componentIndex[componentId] = archetypesMap
|
componentIndex[componentId] = archetypesMap
|
||||||
end
|
end
|
||||||
|
|
||||||
archetypesMap.cache[archetypeId] = i
|
|
||||||
archetypesMap.size += 1
|
|
||||||
|
|
||||||
return archetypesMap
|
return archetypesMap
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -300,19 +295,27 @@ local function archetypeOf(world: any, types: { i24 }, prev: Archetype?): Archet
|
||||||
|
|
||||||
local records = {}
|
local records = {}
|
||||||
for i, componentId in types do
|
for i, componentId in types do
|
||||||
ensureComponentRecord(componentIndex, id, componentId, i)
|
local idr = ensureComponentRecord(componentIndex, componentId)
|
||||||
|
idr.cache[id] = i
|
||||||
records[componentId] = i
|
records[componentId] = i
|
||||||
if ECS_IS_PAIR(componentId) then
|
if ECS_IS_PAIR(componentId) then
|
||||||
local relation = ECS_PAIR_RELATION(world.entityIndex, componentId)
|
local relation = ECS_PAIR_RELATION(world.entityIndex, componentId)
|
||||||
local object = ECS_PAIR_OBJECT(world.entityIndex, componentId)
|
local object = ECS_PAIR_OBJECT(world.entityIndex, componentId)
|
||||||
|
|
||||||
local idr_r = ECS_PAIR(relation, EcsWildcard)
|
local r = ECS_PAIR(relation, EcsWildcard)
|
||||||
ensureComponentRecord(componentIndex, id, idr_r, i)
|
local idr_r = ensureComponentRecord(componentIndex, r)
|
||||||
records[idr_r] = i
|
|
||||||
|
|
||||||
local idr_t = ECS_PAIR(EcsWildcard, object)
|
local o = ECS_PAIR(EcsWildcard, object)
|
||||||
ensureComponentRecord(componentIndex, id, idr_t, i)
|
local idr_o = ensureComponentRecord(componentIndex, o)
|
||||||
records[idr_t] = i
|
|
||||||
|
records[r] = i
|
||||||
|
records[o] = i
|
||||||
|
|
||||||
|
idr_r.cache[id] = i
|
||||||
|
idr_o.cache[id] = i
|
||||||
|
|
||||||
|
idr_r.size += 1
|
||||||
|
idr_o.size += 1
|
||||||
end
|
end
|
||||||
columns[i] = {}
|
columns[i] = {}
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue