mirror of
https://github.com/Ukendio/jecs.git
synced 2025-08-04 11:19:17 +00:00
Compare commits
4 commits
17034d97d3
...
7e638a372e
Author | SHA1 | Date | |
---|---|---|---|
|
7e638a372e | ||
|
ad5ed3b5ea | ||
|
362490d25e | ||
|
96bed9bd7e |
2 changed files with 101 additions and 16 deletions
42
jecs.luau
42
jecs.luau
|
@ -2174,7 +2174,7 @@ local function world_new()
|
||||||
local function inner_entity_index_try_get_any(entity: number): Record?
|
local function inner_entity_index_try_get_any(entity: number): Record?
|
||||||
local r = eindex_sparse_array[ECS_ENTITY_T_LO(entity)]
|
local r = eindex_sparse_array[ECS_ENTITY_T_LO(entity)]
|
||||||
|
|
||||||
if not r then
|
if not r or r.dense == 0 then
|
||||||
return nil
|
return nil
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -2566,26 +2566,38 @@ 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 any = eindex_dense_array[dense]
|
local any = eindex_dense_array[dense]
|
||||||
if dense <= alive_count then
|
if any ~= entity then
|
||||||
if any ~= entity then
|
if alive_count <= dense then
|
||||||
error("Entity ID is already in use with a different generation")
|
local e_swap = eindex_dense_array[dense]
|
||||||
else
|
local r_swap = inner_entity_index_try_get_any(e_swap :: number) :: Record
|
||||||
return entity
|
|
||||||
|
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
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
local e_swap = eindex_dense_array[dense]
|
|
||||||
local r_swap = inner_entity_index_try_get_any(e_swap :: number) :: Record
|
|
||||||
alive_count += 1
|
|
||||||
entity_index.alive_count = alive_count
|
|
||||||
r_swap.dense = dense
|
|
||||||
r.dense = alive_count
|
|
||||||
eindex_dense_array[dense] = e_swap
|
|
||||||
eindex_dense_array[alive_count] = entity
|
|
||||||
|
|
||||||
return entity
|
return entity
|
||||||
else
|
else
|
||||||
for i = eindex_max_id + 1, index do
|
for i = eindex_max_id + 1, index do
|
||||||
|
|
|
@ -885,7 +885,64 @@ TEST("world:each()", function()
|
||||||
end
|
end
|
||||||
end)
|
end)
|
||||||
|
|
||||||
|
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()
|
||||||
|
@ -895,11 +952,27 @@ TEST("world:range()", function()
|
||||||
|
|
||||||
local e1 = server:entity()
|
local e1 = server:entity()
|
||||||
CHECK((e1::number)< 1000)
|
CHECK((e1::number)< 1000)
|
||||||
|
server:delete(e1)
|
||||||
local e2 = client:entity(e1)
|
local e2 = client:entity(e1)
|
||||||
CHECK(e2 == e1)
|
CHECK(e2 == e1)
|
||||||
client:delete(e1)
|
local A = client:component()
|
||||||
|
client:set(e2, A, true)
|
||||||
|
CHECK(client:get(e2, A))
|
||||||
|
|
||||||
|
client:delete(e2)
|
||||||
|
local e3 = client:entity()
|
||||||
|
CHECK(ECS_ID(e3::number) == 1000)
|
||||||
|
|
||||||
|
local e1v1 = server:entity()
|
||||||
|
local e4 = client:entity(e1v1)
|
||||||
|
CHECK(ECS_ID(e4::number) == e1)
|
||||||
|
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