From c3853023d05d44f8077c15b2e3e97f60be24bd47 Mon Sep 17 00:00:00 2001 From: Ukendio Date: Thu, 17 Jul 2025 18:24:32 +0200 Subject: [PATCH] Allow creating an entity with a non-zero generation below range --- jecs.luau | 35 +++++++++++++++++------------------ test/tests.luau | 9 +++++++++ 2 files changed, 26 insertions(+), 18 deletions(-) diff --git a/jecs.luau b/jecs.luau index 3bb79b0..fb5fa6d 100755 --- a/jecs.luau +++ b/jecs.luau @@ -2574,19 +2574,16 @@ local function world_new() if not dense or r.dense == 0 then r.dense = index dense = index - local any = eindex_dense_array[dense] - if any == entity then - local e_swap = eindex_dense_array[dense] - local r_swap = inner_entity_index_try_get_any(e_swap :: number) :: Record + local e_swap = eindex_dense_array[dense] + local r_swap = inner_entity_index_try_get_any(e_swap :: number) :: Record - r_swap.dense = dense - alive_count += 1 - entity_index.alive_count = alive_count - r.dense = alive_count + r_swap.dense = dense + alive_count += 1 + entity_index.alive_count = alive_count + r.dense = alive_count - eindex_dense_array[dense] = e_swap - eindex_dense_array[alive_count] = entity - end + eindex_dense_array[dense] = e_swap + eindex_dense_array[alive_count] = entity return entity end @@ -3093,6 +3090,13 @@ return { pair = (ECS_PAIR :: any) :: (first: Id

, second: Id) -> Pair, + IS_PAIR = (ECS_IS_PAIR :: any) :: (pair: Pair) -> boolean, + ECS_PAIR_FIRST = ECS_PAIR_FIRST :: (pair: Pair) -> Id

, + ECS_PAIR_SECOND = ECS_PAIR_SECOND :: (pair: Pair) -> Id, + pair_first = (ecs_pair_first :: any) :: (world: World, pair: Pair) -> Id

, + pair_second = (ecs_pair_second :: any) :: (world: World, pair: Pair) -> Id, + entity_index_get_alive = entity_index_get_alive, + -- Inwards facing API for testing ECS_ID = ECS_ENTITY_T_LO, ECS_GENERATION_INC = ECS_GENERATION_INC, @@ -3100,13 +3104,8 @@ return { ECS_ID_IS_WILDCARD = ECS_ID_IS_WILDCARD, ECS_ID_DELETE = ECS_ID_DELETE, ECS_META_RESET = ECS_META_RESET, - - IS_PAIR = (ECS_IS_PAIR :: any) :: (pair: Pair) -> boolean, - ECS_PAIR_FIRST = ECS_PAIR_FIRST :: (pair: Pair) -> Id

, - ECS_PAIR_SECOND = ECS_PAIR_SECOND :: (pair: Pair) -> Id, - pair_first = (ecs_pair_first :: any) :: (world: World, pair: Pair) -> Id

, - pair_second = (ecs_pair_second :: any) :: (world: World, pair: Pair) -> Id, - entity_index_get_alive = entity_index_get_alive, + ECS_COMBINE = ECS_COMBINE, + ECS_ENTITY_MASK = ECS_ENTITY_MASK, archetype_append_to_records = archetype_append_to_records, id_record_ensure = id_record_ensure, diff --git a/test/tests.luau b/test/tests.luau index 9fedc40..bac14da 100755 --- a/test/tests.luau +++ b/test/tests.luau @@ -24,6 +24,15 @@ type Id = jecs.Id local entity_visualiser = require("@tools/entity_visualiser") local dwi = entity_visualiser.stringify +TEST("another axen banger", function() + -- taken from jecs.luau + local world = jecs.world() + world:range(2000, 3000) + + local e0v1_id = jecs.ECS_COMBINE(1000, 1) -- id can be both within or outside the world's range + local e0v1 = world:entity(e0v1_id) + assert(world:contains(e0v1)) -- fails +end) TEST("Ensure archetype edges get cleaned", function() local A = jecs.component() local B = jecs.component()