Skip to content

Commit

Permalink
Initial commit (#167)
Browse files Browse the repository at this point in the history
  • Loading branch information
Ukendio authored Dec 26, 2024
1 parent eaafd27 commit 0f2e0eb
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 5 deletions.
6 changes: 3 additions & 3 deletions jecs.luau
Original file line number Diff line number Diff line change
Expand Up @@ -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?
Expand Down Expand Up @@ -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)
Expand Down
18 changes: 16 additions & 2 deletions test/tests.luau
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ local function debug_world_inspect(world: World)
records = records,
row = row,
tuple = tuple,
columns = columns
}
end

Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit 0f2e0eb

Please sign in to comment.