mirror of
https://github.com/Ukendio/jecs.git
synced 2025-07-20 04:59:16 +00:00
Allow creating an entity with a non-zero generation below range
This commit is contained in:
parent
7b253e1c2a
commit
c3853023d0
2 changed files with 26 additions and 18 deletions
35
jecs.luau
35
jecs.luau
|
@ -2574,19 +2574,16 @@ local function world_new()
|
||||||
if not dense or r.dense == 0 then
|
if not dense or r.dense == 0 then
|
||||||
r.dense = index
|
r.dense = index
|
||||||
dense = index
|
dense = index
|
||||||
local any = eindex_dense_array[dense]
|
local e_swap = eindex_dense_array[dense]
|
||||||
if any == entity then
|
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
|
r_swap.dense = dense
|
||||||
alive_count += 1
|
alive_count += 1
|
||||||
entity_index.alive_count = alive_count
|
entity_index.alive_count = alive_count
|
||||||
r.dense = alive_count
|
r.dense = alive_count
|
||||||
|
|
||||||
eindex_dense_array[dense] = e_swap
|
eindex_dense_array[dense] = e_swap
|
||||||
eindex_dense_array[alive_count] = entity
|
eindex_dense_array[alive_count] = entity
|
||||||
end
|
|
||||||
return entity
|
return entity
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -3093,6 +3090,13 @@ return {
|
||||||
|
|
||||||
pair = (ECS_PAIR :: any) :: <P, O>(first: Id<P>, second: Id<O>) -> Pair<P, O>,
|
pair = (ECS_PAIR :: any) :: <P, O>(first: Id<P>, second: Id<O>) -> Pair<P, O>,
|
||||||
|
|
||||||
|
IS_PAIR = (ECS_IS_PAIR :: any) :: <P, O>(pair: Pair<P, O>) -> boolean,
|
||||||
|
ECS_PAIR_FIRST = ECS_PAIR_FIRST :: <P, O>(pair: Pair<P, O>) -> Id<P>,
|
||||||
|
ECS_PAIR_SECOND = ECS_PAIR_SECOND :: <P, O>(pair: Pair<P, O>) -> Id<O>,
|
||||||
|
pair_first = (ecs_pair_first :: any) :: <P, O>(world: World, pair: Pair<P, O>) -> Id<P>,
|
||||||
|
pair_second = (ecs_pair_second :: any) :: <P, O>(world: World, pair: Pair<P, O>) -> Id<O>,
|
||||||
|
entity_index_get_alive = entity_index_get_alive,
|
||||||
|
|
||||||
-- Inwards facing API for testing
|
-- Inwards facing API for testing
|
||||||
ECS_ID = ECS_ENTITY_T_LO,
|
ECS_ID = ECS_ENTITY_T_LO,
|
||||||
ECS_GENERATION_INC = ECS_GENERATION_INC,
|
ECS_GENERATION_INC = ECS_GENERATION_INC,
|
||||||
|
@ -3100,13 +3104,8 @@ return {
|
||||||
ECS_ID_IS_WILDCARD = ECS_ID_IS_WILDCARD,
|
ECS_ID_IS_WILDCARD = ECS_ID_IS_WILDCARD,
|
||||||
ECS_ID_DELETE = ECS_ID_DELETE,
|
ECS_ID_DELETE = ECS_ID_DELETE,
|
||||||
ECS_META_RESET = ECS_META_RESET,
|
ECS_META_RESET = ECS_META_RESET,
|
||||||
|
ECS_COMBINE = ECS_COMBINE,
|
||||||
IS_PAIR = (ECS_IS_PAIR :: any) :: <P, O>(pair: Pair<P, O>) -> boolean,
|
ECS_ENTITY_MASK = ECS_ENTITY_MASK,
|
||||||
ECS_PAIR_FIRST = ECS_PAIR_FIRST :: <P, O>(pair: Pair<P, O>) -> Id<P>,
|
|
||||||
ECS_PAIR_SECOND = ECS_PAIR_SECOND :: <P, O>(pair: Pair<P, O>) -> Id<O>,
|
|
||||||
pair_first = (ecs_pair_first :: any) :: <P, O>(world: World, pair: Pair<P, O>) -> Id<P>,
|
|
||||||
pair_second = (ecs_pair_second :: any) :: <P, O>(world: World, pair: Pair<P, O>) -> Id<O>,
|
|
||||||
entity_index_get_alive = entity_index_get_alive,
|
|
||||||
|
|
||||||
archetype_append_to_records = archetype_append_to_records,
|
archetype_append_to_records = archetype_append_to_records,
|
||||||
id_record_ensure = id_record_ensure,
|
id_record_ensure = id_record_ensure,
|
||||||
|
|
|
@ -24,6 +24,15 @@ type Id<T=unknown> = jecs.Id<T>
|
||||||
local entity_visualiser = require("@tools/entity_visualiser")
|
local entity_visualiser = require("@tools/entity_visualiser")
|
||||||
local dwi = entity_visualiser.stringify
|
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()
|
TEST("Ensure archetype edges get cleaned", function()
|
||||||
local A = jecs.component()
|
local A = jecs.component()
|
||||||
local B = jecs.component()
|
local B = jecs.component()
|
||||||
|
|
Loading…
Reference in a new issue