mirror of
https://github.com/Ukendio/jecs.git
synced 2025-07-09 08:09:18 +00:00
Fix bug to allow deletion outside partitioned range
This commit is contained in:
parent
eed1b6179e
commit
29350e6ec3
2 changed files with 25 additions and 4 deletions
|
@ -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 or r.dense == 0 then
|
if not r then
|
||||||
return nil
|
return nil
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -2589,7 +2589,7 @@ local function world_new()
|
||||||
return entity
|
return entity
|
||||||
else
|
else
|
||||||
for i = eindex_max_id + 1, index do
|
for i = eindex_max_id + 1, index do
|
||||||
eindex_sparse_array[i]= { dense = i } :: Record
|
eindex_sparse_array[i] = { dense = i } :: Record
|
||||||
eindex_dense_array[i] = i
|
eindex_dense_array[i] = i
|
||||||
end
|
end
|
||||||
entity_index.max_id = index
|
entity_index.max_id = index
|
||||||
|
@ -2911,7 +2911,6 @@ local function world_new()
|
||||||
|
|
||||||
local e_swap = dense_array[i_swap]
|
local e_swap = dense_array[i_swap]
|
||||||
local r_swap = inner_entity_index_try_get_any(e_swap :: number) :: Record
|
local r_swap = inner_entity_index_try_get_any(e_swap :: number) :: Record
|
||||||
|
|
||||||
r_swap.dense = dense
|
r_swap.dense = dense
|
||||||
record.archetype = nil :: any
|
record.archetype = nil :: any
|
||||||
record.row = nil :: any
|
record.row = nil :: any
|
||||||
|
|
|
@ -659,7 +659,6 @@ TEST("world:delete()", function()
|
||||||
CHECK(not world:has(id1, Health))
|
CHECK(not world:has(id1, Health))
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
do CASE "delete children"
|
do CASE "delete children"
|
||||||
local world = jecs.world()
|
local world = jecs.world()
|
||||||
|
|
||||||
|
@ -846,6 +845,16 @@ TEST("world:delete()", function()
|
||||||
CHECK(not world:contains(bob))
|
CHECK(not world:contains(bob))
|
||||||
CHECK(not world:contains(alice))
|
CHECK(not world:contains(alice))
|
||||||
end
|
end
|
||||||
|
|
||||||
|
do CASE "deleted entity should not be able to be operated on"
|
||||||
|
local world = jecs.world()
|
||||||
|
local e = world:entity()
|
||||||
|
local A = world:component()
|
||||||
|
world:set(e, A, true)
|
||||||
|
world:delete(e)
|
||||||
|
world:set(e, A, true)
|
||||||
|
CHECK(world:has(e, A) == false)
|
||||||
|
end
|
||||||
end)
|
end)
|
||||||
|
|
||||||
TEST("world:each()", function()
|
TEST("world:each()", function()
|
||||||
|
@ -877,6 +886,19 @@ TEST("world:each()", function()
|
||||||
end)
|
end)
|
||||||
|
|
||||||
TEST("world:range()", function()
|
TEST("world:range()", function()
|
||||||
|
do CASE "delete outside partitioned range"
|
||||||
|
local server = jecs.world()
|
||||||
|
local client = jecs.world()
|
||||||
|
|
||||||
|
server:range(0, 1000)
|
||||||
|
client:range(1000, 5000)
|
||||||
|
|
||||||
|
local e1 = server:entity()
|
||||||
|
CHECK((e1::number)< 1000)
|
||||||
|
local e2 = client:entity(e1)
|
||||||
|
CHECK(e2 == e1)
|
||||||
|
client:delete(e1)
|
||||||
|
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)
|
||||||
|
|
Loading…
Reference in a new issue