mirror of
https://github.com/Ukendio/jecs.git
synced 2025-04-25 09:30:03 +00:00
update
This commit is contained in:
parent
d6b6caf07a
commit
5219ace134
1 changed files with 14 additions and 18 deletions
32
lib/init.lua
32
lib/init.lua
|
@ -75,30 +75,27 @@ local function addFlags(isPair: boolean)
|
||||||
return typeFlags
|
return typeFlags
|
||||||
end
|
end
|
||||||
|
|
||||||
local function newId(source: number, target: number)
|
local function newId(source: number, target: number): number
|
||||||
local e = source * 2^28 + target * ECS_ID_FLAGS_MASK
|
return ((source * 2^28) + target) * ECS_ID_FLAGS_MASK
|
||||||
return e
|
|
||||||
end
|
end
|
||||||
|
|
||||||
local function ECS_IS_PAIR(e: number)
|
local function ECS_IS_PAIR(e: number): boolean
|
||||||
return (e % 2^4) // FLAGS_PAIR ~= 0
|
return ( (e % 2^4) // FLAGS_PAIR ) ~= 0
|
||||||
end
|
end
|
||||||
|
|
||||||
function separate(entity: number)
|
local function separate(entity: number): (number, number, number)
|
||||||
local _typeFlags = entity % 0x10
|
local type_flags = entity % 0x10
|
||||||
entity //= ECS_ID_FLAGS_MASK
|
local entity = entity // ECS_ID_FLAGS_MASK
|
||||||
return entity // ECS_ENTITY_MASK, entity % ECS_GENERATION_MASK, _typeFlags
|
return new_entity // ECS_ENTITY_MASK, new_entity % ECS_GENERATION_MASK, type_flags
|
||||||
end
|
end
|
||||||
|
|
||||||
-- HIGH 24 bits LOW 24 bits
|
-- HIGH 24 bits LOW 24 bits
|
||||||
local function ECS_GENERATION(e: i53)
|
local function ECS_GENERATION(e: i53)
|
||||||
e //= 0x10
|
return (e // 0x10) % ECS_GENERATION_MASK
|
||||||
return e % ECS_GENERATION_MASK
|
|
||||||
end
|
end
|
||||||
|
|
||||||
local function ECS_ID(e: i53)
|
local function ECS_ID(e: i53)
|
||||||
e //= 0x10
|
return (e // 0x10) // ECS_ENTITY_MASK
|
||||||
return e // ECS_ENTITY_MASK
|
|
||||||
end
|
end
|
||||||
|
|
||||||
local function ECS_GENERATION_INC(e: i53)
|
local function ECS_GENERATION_INC(e: i53)
|
||||||
|
@ -109,15 +106,13 @@ end
|
||||||
|
|
||||||
-- gets the high ID
|
-- gets the high ID
|
||||||
local function ECS_PAIR_FIRST(entity: i53): i24
|
local function ECS_PAIR_FIRST(entity: i53): i24
|
||||||
entity //= 0x10
|
return (entity // 0x10) % ECS_ENTITY_MASK
|
||||||
local first = entity % ECS_ENTITY_MASK
|
|
||||||
return first
|
|
||||||
end
|
end
|
||||||
|
|
||||||
-- gets the low ID
|
-- gets the low ID
|
||||||
local ECS_PAIR_SECOND = ECS_ID
|
local ECS_PAIR_SECOND = ECS_ID
|
||||||
|
|
||||||
local function ECS_PAIR(first: number, second: number)
|
local function ECS_PAIR(first: number, second: number):
|
||||||
local target = WILDCARD
|
local target = WILDCARD
|
||||||
local relation
|
local relation
|
||||||
|
|
||||||
|
@ -132,6 +127,7 @@ local function ECS_PAIR(first: number, second: number)
|
||||||
|
|
||||||
return newId(
|
return newId(
|
||||||
ECS_PAIR_SECOND(relation), target) + addFlags(--[[isPair]] true)
|
ECS_PAIR_SECOND(relation), target) + addFlags(--[[isPair]] true)
|
||||||
|
)
|
||||||
end
|
end
|
||||||
|
|
||||||
local function getAlive(entityIndex: EntityIndex, id: i53)
|
local function getAlive(entityIndex: EntityIndex, id: i53)
|
||||||
|
@ -147,7 +143,7 @@ local function ecs_get_target(entityIndex, e)
|
||||||
return getAlive(entityIndex, ECS_PAIR_SECOND(e))
|
return getAlive(entityIndex, ECS_PAIR_SECOND(e))
|
||||||
end
|
end
|
||||||
|
|
||||||
local function nextEntityId(entityIndex, index: i24)
|
local function nextEntityId(entityIndex, index: i24): i53
|
||||||
local id = newId(index, 0)
|
local id = newId(index, 0)
|
||||||
entityIndex.sparse[id] = {
|
entityIndex.sparse[id] = {
|
||||||
dense = index
|
dense = index
|
||||||
|
|
Loading…
Reference in a new issue