Rename functions

This commit is contained in:
Ukendio 2024-05-14 17:52:41 +02:00
parent 6710e3cdcb
commit e86b4c7f4c
2 changed files with 41 additions and 41 deletions

View file

@ -75,7 +75,7 @@ local function addFlags(isPair: boolean)
return typeFlags return typeFlags
end end
local function newId(source: number, target: number) local function ECS_COMBINE(source: number, target: number): i53
local e = source * 2^28 + target * ECS_ID_FLAGS_MASK local e = source * 2^28 + target * ECS_ID_FLAGS_MASK
return e return e
end end
@ -96,7 +96,7 @@ local function ECS_GENERATION(e: i53)
return e % ECS_GENERATION_MASK return e % ECS_GENERATION_MASK
end end
local function ECS_ID(e: i53) local function ECS_ENTITY_T_LO(e: i53)
e //= 0x10 e //= 0x10
return e // ECS_ENTITY_MASK return e // ECS_ENTITY_MASK
end end
@ -104,51 +104,51 @@ end
local function ECS_GENERATION_INC(e: i53) local function ECS_GENERATION_INC(e: i53)
local id, generation, flags = separate(e) local id, generation, flags = separate(e)
return newId(id, generation + 1) + flags return ECS_COMBINE(id, generation + 1) + flags
end end
-- gets the high ID -- gets the high ID
local function ECS_PAIR_FIRST(entity: i53): i24 local function ECS_ENTITY_T_HI(entity: i53): i24
entity //= 0x10 entity //= 0x10
local first = entity % ECS_ENTITY_MASK local first = entity % ECS_ENTITY_MASK
return first return first
end end
-- gets the low ID local function ECS_PAIR(pred: number, obj: number)
local ECS_PAIR_SECOND = ECS_ID local first
local second: number = WILDCARD
local function ECS_PAIR(first: number, second: number) if pred == WILDCARD then
local target = WILDCARD first = obj
local relation elseif obj == WILDCARD then
first = pred
if first == WILDCARD then
relation = second
elseif second == WILDCARD then
relation = first
else else
relation = second first = obj
target = ECS_PAIR_SECOND(first) second = ECS_ENTITY_T_LO(pred)
end end
return newId( return ECS_COMBINE(
ECS_PAIR_SECOND(relation), target) + addFlags(--[[isPair]] true) ECS_ENTITY_T_LO(first), second) + addFlags(--[[isPair]] true)
end end
local function getAlive(entityIndex: EntityIndex, id: i53) local function getAlive(entityIndex: EntityIndex, id: i53)
return entityIndex.dense[id] return entityIndex.dense[id]
end end
local function ecs_get_source(entityIndex, e) -- ECS_PAIR_FIRST, gets the relationship target / obj / HIGH bits
local function ECS_PAIR_RELATION(entityIndex, e)
assert(ECS_IS_PAIR(e)) assert(ECS_IS_PAIR(e))
return getAlive(entityIndex, ECS_PAIR_FIRST(e)) return getAlive(entityIndex, ECS_ENTITY_T_HI(e))
end
local function ecs_get_target(entityIndex, e)
assert(ECS_IS_PAIR(e))
return getAlive(entityIndex, ECS_PAIR_SECOND(e))
end end
local function nextEntityId(entityIndex, index: i24) -- ECS_PAIR_SECOND gets the relationship / pred / LOW bits
local id = newId(index, 0) local function ECS_PAIR_OBJECT(entityIndex, e)
assert(ECS_IS_PAIR(e))
return getAlive(entityIndex, ECS_ENTITY_T_LO(e))
end
local function nextEntityId(entityIndex, index: i24): i53
local id = ECS_COMBINE(index, 0)
entityIndex.sparse[id] = { entityIndex.sparse[id] = {
dense = index dense = index
} :: Record } :: Record
@ -267,14 +267,14 @@ local function archetypeOf(world: World, types: {i24}, prev: Archetype?): Archet
columns[i] = {} columns[i] = {}
if ECS_IS_PAIR(componentId) then if ECS_IS_PAIR(componentId) then
local first = ecs_get_source(entityIndex, componentId) local pred = ECS_PAIR_RELATION(entityIndex, componentId)
local second = ecs_get_target(entityIndex, componentId) local obj = ECS_PAIR_OBJECT(entityIndex, componentId)
local firstPair = ECS_PAIR(first, WILDCARD) local first = ECS_PAIR(pred, WILDCARD)
local secondPair = ECS_PAIR(WILDCARD, second) local second = ECS_PAIR(WILDCARD, obj)
createArchetypeRecord(componentIndex, id, firstPair, i) createArchetypeRecord(componentIndex, id, first, i)
createArchetypeRecord(componentIndex, id, secondPair, i) createArchetypeRecord(componentIndex, id, second, i)
records[firstPair] = i records[first] = i
records[secondPair] = i records[second] = i
end end
end end
@ -783,13 +783,13 @@ return table.freeze({
w = WILDCARD, w = WILDCARD,
Rest = REST, Rest = REST,
ECS_ID = ECS_ID,
IS_PAIR = ECS_IS_PAIR, IS_PAIR = ECS_IS_PAIR,
ECS_ID = ECS_ENTITY_T_LO,
ECS_PAIR = ECS_PAIR, ECS_PAIR = ECS_PAIR,
ECS_GENERATION_INC = ECS_GENERATION_INC, ECS_GENERATION_INC = ECS_GENERATION_INC,
ECS_GENERATION = ECS_GENERATION, ECS_GENERATION = ECS_GENERATION,
ecs_get_target = ecs_get_target, ECS_PAIR_RELATION = ECS_PAIR_RELATION,
ecs_get_source = ecs_get_source, ECS_PAIR_OBJECT = ECS_PAIR_OBJECT,
pair = ECS_PAIR, pair = ECS_PAIR,
getAlive = getAlive, getAlive = getAlive,

View file

@ -5,8 +5,8 @@ local ECS_GENERATION_INC = jecs.ECS_GENERATION_INC
local IS_PAIR = jecs.IS_PAIR local IS_PAIR = jecs.IS_PAIR
local ECS_PAIR = jecs.ECS_PAIR local ECS_PAIR = jecs.ECS_PAIR
local getAlive = jecs.getAlive local getAlive = jecs.getAlive
local ecs_get_source = jecs.ecs_get_source local ECS_PAIR_RELATION = jecs.ECS_PAIR_RELATION
local ecs_get_target = jecs.ecs_get_target local ECS_PAIR_OBJECT = jecs.ECS_PAIR_OBJECT
local TEST, CASE, CHECK, FINISH, SKIP = testkit.test() local TEST, CASE, CHECK, FINISH, SKIP = testkit.test()
@ -189,8 +189,8 @@ TEST("world", function()
local pair = ECS_PAIR(e2, e3) local pair = ECS_PAIR(e2, e3)
CHECK(IS_PAIR(pair) == true) CHECK(IS_PAIR(pair) == true)
CHECK(ecs_get_source(world.entityIndex, pair) == e2) CHECK(ECS_PAIR_RELATION(world.entityIndex, pair) == e2)
CHECK(ecs_get_target(world.entityIndex, pair) == e3) CHECK(ECS_PAIR_OBJECT(world.entityIndex, pair) == e3)
end end
do CASE "should allow querying for relations" do CASE "should allow querying for relations"