diff --git a/jecs.luau b/jecs.luau index 1aed04f5..1b0ac082 100644 --- a/jecs.luau +++ b/jecs.luau @@ -168,7 +168,7 @@ local function _STRIP_GENERATION(e: i53): i24 end 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 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 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 -- ECS_PAIR_SECOND gets the relationship / pred / LOW bits 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 local function archetype_move(entity_index: EntityIndex, to: Archetype, dst_row: i24, from: Archetype, src_row: i24) diff --git a/test/tests.luau b/test/tests.luau index 12d60b13..70ce8c0d 100644 --- a/test/tests.luau +++ b/test/tests.luau @@ -59,6 +59,7 @@ local function debug_world_inspect(world: World) records = records, row = row, tuple = tuple, + columns = columns } end @@ -1205,25 +1206,38 @@ TEST("world:delete", function() end) TEST("world:target", function() - do - CASE("nth index") + do CASE("nth index") local world = world_new() local A = world:component() + world:set(A, jecs.Name, "A") local B = world:component() + world:set(B, jecs.Name, "B") local C = world:component() + world:set(C, jecs.Name, "C") local D = world:component() + world:set(D, jecs.Name, "D") + local E = world:component() + world:set(E, jecs.Name, "E") local e = world:entity() world:add(e, pair(A, B)) 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, D)) world:add(e, pair(C, D)) 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, 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, 1) == D) CHECK(world:target(e, C, 0) == D)