mirror of
https://github.com/Ukendio/jecs.git
synced 2025-07-08 23:59:17 +00:00
Increment alive count if under dense
Some checks failed
Some checks failed
This commit is contained in:
parent
362490d25e
commit
ad5ed3b5ea
2 changed files with 90 additions and 8 deletions
37
jecs.luau
37
jecs.luau
|
@ -2566,16 +2566,37 @@ 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]
|
||||||
|
if any == entity then
|
||||||
|
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
|
||||||
|
|
||||||
|
eindex_dense_array[dense] = e_swap
|
||||||
|
eindex_dense_array[alive_count] = entity
|
||||||
|
end
|
||||||
|
return entity
|
||||||
end
|
end
|
||||||
|
|
||||||
local e_swap = eindex_dense_array[dense]
|
local any = eindex_dense_array[dense]
|
||||||
local r_swap = inner_entity_index_try_get_any(e_swap :: number) :: Record
|
if any ~= entity then
|
||||||
alive_count += 1
|
if alive_count <= dense then
|
||||||
entity_index.alive_count = alive_count
|
local e_swap = eindex_dense_array[dense]
|
||||||
r_swap.dense = dense
|
local r_swap = inner_entity_index_try_get_any(e_swap :: number) :: Record
|
||||||
r.dense = alive_count
|
|
||||||
eindex_dense_array[dense] = e_swap
|
r_swap.dense = dense
|
||||||
eindex_dense_array[alive_count] = entity
|
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
|
||||||
|
end
|
||||||
|
|
||||||
return entity
|
return entity
|
||||||
else
|
else
|
||||||
|
|
|
@ -887,6 +887,62 @@ end)
|
||||||
|
|
||||||
FOCUS()
|
FOCUS()
|
||||||
TEST("world:range()", function()
|
TEST("world:range()", function()
|
||||||
|
|
||||||
|
do CASE "spawn entity under min range"
|
||||||
|
local world = jecs.world()
|
||||||
|
world:range(400, 1000)
|
||||||
|
CHECK(world.entity_index.alive_count == 399)
|
||||||
|
local e = world:entity(300)
|
||||||
|
CHECK(world.entity_index.alive_count == 400)
|
||||||
|
local e1 = world:entity(300)
|
||||||
|
CHECK(world.entity_index.alive_count == 400)
|
||||||
|
CHECK(e)
|
||||||
|
end
|
||||||
|
do CASE "axen"
|
||||||
|
local base = jecs.world()
|
||||||
|
base:range(1_000, 2_000)
|
||||||
|
|
||||||
|
local mirror = jecs.world()
|
||||||
|
mirror:range(3_000, 4_000)
|
||||||
|
|
||||||
|
mirror:entity() -- NOTE: this fixes the "attempt to index nil with 'dense'" error
|
||||||
|
|
||||||
|
local foo = base:entity()
|
||||||
|
local bar = mirror:entity(foo)
|
||||||
|
|
||||||
|
base:delete(base:entity()) -- Removing this line stops the error below from happening
|
||||||
|
|
||||||
|
local meow = base:entity()
|
||||||
|
mirror:delete(bar)
|
||||||
|
|
||||||
|
CHECK(jecs.ECS_ID(foo))
|
||||||
|
CHECK(jecs.ECS_ID(meow))
|
||||||
|
local mrrp = mirror:entity(meow) -- jecs, Line 785 - Entity ID is already in use with a different generation
|
||||||
|
CHECK(mrrp == meow)
|
||||||
|
end
|
||||||
|
do CASE "axen2"
|
||||||
|
local world = jecs.world()
|
||||||
|
local mirror = jecs.world()
|
||||||
|
|
||||||
|
world:range(1000, 2000)
|
||||||
|
mirror:range(3000, 4000)
|
||||||
|
|
||||||
|
local foo = world:entity() -- 1000
|
||||||
|
local foo_mirror = mirror:entity(foo) -- 1000
|
||||||
|
CHECK(foo == foo_mirror)
|
||||||
|
|
||||||
|
for index = 1, 5 do
|
||||||
|
world:entity()
|
||||||
|
end
|
||||||
|
|
||||||
|
world:delete(foo)
|
||||||
|
mirror:delete(foo_mirror)
|
||||||
|
|
||||||
|
local bar = world:entity()
|
||||||
|
local bar_mirror = mirror:entity(bar)
|
||||||
|
CHECK(bar == bar_mirror)
|
||||||
|
end
|
||||||
|
|
||||||
do CASE "delete outside partitioned range"
|
do CASE "delete outside partitioned range"
|
||||||
local server = jecs.world()
|
local server = jecs.world()
|
||||||
local client = jecs.world()
|
local client = jecs.world()
|
||||||
|
@ -902,6 +958,7 @@ TEST("world:range()", function()
|
||||||
local A = client:component()
|
local A = client:component()
|
||||||
client:set(e2, A, true)
|
client:set(e2, A, true)
|
||||||
CHECK(client:get(e2, A))
|
CHECK(client:get(e2, A))
|
||||||
|
|
||||||
client:delete(e2)
|
client:delete(e2)
|
||||||
local e3 = client:entity()
|
local e3 = client:entity()
|
||||||
CHECK(ECS_ID(e3::number) == 1000)
|
CHECK(ECS_ID(e3::number) == 1000)
|
||||||
|
@ -910,8 +967,12 @@ TEST("world:range()", function()
|
||||||
local e4 = client:entity(e1v1)
|
local e4 = client:entity(e1v1)
|
||||||
CHECK(ECS_ID(e4::number) == e1)
|
CHECK(ECS_ID(e4::number) == e1)
|
||||||
CHECK(ECS_GENERATION(e4::number) == 1)
|
CHECK(ECS_GENERATION(e4::number) == 1)
|
||||||
|
CHECK(not client:contains(e2))
|
||||||
|
CHECK(client:contains(e4))
|
||||||
end
|
end
|
||||||
|
|
||||||
do CASE "under range start"
|
do CASE "under range start"
|
||||||
|
|
||||||
local world = jecs.world()
|
local world = jecs.world()
|
||||||
world:range(400, 1000)
|
world:range(400, 1000)
|
||||||
local id = world:entity() :: number
|
local id = world:entity() :: number
|
||||||
|
|
Loading…
Reference in a new issue