Initial commit (#167)
Some checks are pending
Analysis / Run Luau Analyze (push) Waiting to run
Deploy VitePress site to Pages / build (push) Waiting to run
Deploy VitePress site to Pages / Deploy (push) Blocked by required conditions
Unit Testing / Run Luau Tests (push) Waiting to run

This commit is contained in:
Marcus 2024-12-26 02:06:14 +02:00 committed by GitHub
parent eaafd27280
commit 0f2e0eba76
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 19 additions and 5 deletions

View file

@ -168,7 +168,7 @@ local function _STRIP_GENERATION(e: i53): i24
end end
local function ECS_PAIR(pred: i53, obj: i53): i53 local function ECS_PAIR(pred: i53, obj: i53): i53
return ECS_COMBINE(ECS_ENTITY_T_LO(obj), ECS_ENTITY_T_LO(pred)) + FLAGS_ADD(--[[isPair]] true) :: i53 return ECS_COMBINE(ECS_ENTITY_T_LO(pred), ECS_ENTITY_T_LO(obj)) + FLAGS_ADD(--[[isPair]] true) :: i53
end end
local function entity_index_try_get_any(entity_index: EntityIndex, entity: number): Record? local function entity_index_try_get_any(entity_index: EntityIndex, entity: number): Record?
@ -242,12 +242,12 @@ end
-- ECS_PAIR_FIRST, gets the relationship target / obj / HIGH bits -- ECS_PAIR_FIRST, gets the relationship target / obj / HIGH bits
local function ecs_pair_first(world, e) local function ecs_pair_first(world, e)
return entity_index_get_alive(world.entity_index, ECS_ENTITY_T_HI(e)) return entity_index_get_alive(world.entity_index, ECS_ENTITY_T_LO(e))
end end
-- ECS_PAIR_SECOND gets the relationship / pred / LOW bits -- ECS_PAIR_SECOND gets the relationship / pred / LOW bits
local function ecs_pair_second(world, e) local function ecs_pair_second(world, e)
return entity_index_get_alive(world.entity_index, ECS_ENTITY_T_LO(e)) return entity_index_get_alive(world.entity_index, ECS_ENTITY_T_HI(e))
end 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)

View file

@ -59,6 +59,7 @@ local function debug_world_inspect(world: World)
records = records, records = records,
row = row, row = row,
tuple = tuple, tuple = tuple,
columns = columns
} }
end end
@ -1205,25 +1206,38 @@ TEST("world:delete", function()
end) end)
TEST("world:target", function() TEST("world:target", function()
do do CASE("nth index")
CASE("nth index")
local world = world_new() local world = world_new()
local A = world:component() local A = world:component()
world:set(A, jecs.Name, "A")
local B = world:component() local B = world:component()
world:set(B, jecs.Name, "B")
local C = world:component() local C = world:component()
world:set(C, jecs.Name, "C")
local D = world:component() local D = world:component()
world:set(D, jecs.Name, "D")
local E = world:component()
world:set(E, jecs.Name, "E")
local e = world:entity() local e = world:entity()
world:add(e, pair(A, B)) world:add(e, pair(A, B))
world:add(e, pair(A, C)) world:add(e, pair(A, C))
world:add(e, pair(A, D))
world:add(e, pair(A, E))
world:add(e, pair(B, C)) world:add(e, pair(B, C))
world:add(e, pair(B, D)) world:add(e, pair(B, D))
world:add(e, pair(C, D)) world:add(e, pair(C, D))
CHECK(pair(A, B) < pair(A, C)) CHECK(pair(A, B) < pair(A, C))
CHECK(pair(A, E) < pair(B, C))
local records = debug_world_inspect(world).records(e)
CHECK(jecs.pair_first(world, pair(B, C)) == B)
CHECK(records[pair(B, C)].column > records[pair(A, E)].column)
CHECK(world:target(e, A, 0) == B) CHECK(world:target(e, A, 0) == B)
CHECK(world:target(e, A, 1) == C) CHECK(world:target(e, A, 1) == C)
CHECK(world:target(e, A, 2) == D)
CHECK(world:target(e, A, 3) == E)
CHECK(world:target(e, B, 0) == C) CHECK(world:target(e, B, 0) == C)
CHECK(world:target(e, B, 1) == D) CHECK(world:target(e, B, 1) == D)
CHECK(world:target(e, C, 0) == D) CHECK(world:target(e, C, 0) == D)