mirror of
https://github.com/Ukendio/jecs.git
synced 2025-08-06 12:09:18 +00:00
Compare commits
No commits in common. "01821f0a7bd0ab0ecce02036a35a667e3ca1d2a0" and "d0af80577b2eff0cb5423d0fe92e54e5d0e5b5d3" have entirely different histories.
01821f0a7b
...
d0af80577b
2 changed files with 50 additions and 13 deletions
39
jecs.luau
39
jecs.luau
|
@ -772,24 +772,39 @@ local function world_entity(world: ecs_world_t, entity: i53?): i53
|
||||||
local r = sparse_array[index]
|
local r = sparse_array[index]
|
||||||
if r then
|
if r then
|
||||||
local dense = r.dense
|
local dense = r.dense
|
||||||
if dense and r.dense ~= 0 then
|
if not dense or dense == 0 then
|
||||||
if dense < alive_count then
|
|
||||||
return entity
|
|
||||||
end
|
|
||||||
else
|
|
||||||
r.dense = index
|
|
||||||
dense = index
|
dense = index
|
||||||
end
|
end
|
||||||
|
local any = dense_array[dense]
|
||||||
local e_swap = dense_array[dense]
|
if any == entity then
|
||||||
local r_swap = entity_index_try_get_any(entity_index, e_swap) :: ecs_record_t
|
if alive_count > dense then
|
||||||
alive_count += 1
|
r.dense = dense
|
||||||
entity_index.alive_count = alive_count
|
return entity
|
||||||
|
end
|
||||||
|
local e_swap = dense_array[alive_count]
|
||||||
|
local r_swap = sparse_array[alive_count]
|
||||||
r_swap.dense = dense
|
r_swap.dense = dense
|
||||||
r.dense = alive_count
|
r.dense = alive_count
|
||||||
dense_array[dense] = e_swap
|
|
||||||
dense_array[alive_count] = entity
|
dense_array[alive_count] = entity
|
||||||
|
dense_array[dense] = e_swap
|
||||||
return entity
|
return entity
|
||||||
|
end
|
||||||
|
|
||||||
|
-- assert(any ~= 0) should never happen
|
||||||
|
|
||||||
|
local e_swap = dense_array[alive_count]
|
||||||
|
local r_swap = sparse_array[alive_count]
|
||||||
|
|
||||||
|
if dense <= alive_count then
|
||||||
|
alive_count += 1
|
||||||
|
entity_index.alive_count = alive_count
|
||||||
|
end
|
||||||
|
|
||||||
|
r_swap.dense = dense
|
||||||
|
r.dense = alive_count
|
||||||
|
dense_array[alive_count] = any
|
||||||
|
dense_array[dense] = e_swap
|
||||||
|
return any
|
||||||
else
|
else
|
||||||
for i = max_id + 1, index do
|
for i = max_id + 1, index do
|
||||||
sparse_array[i] = { dense = i } :: ecs_record_t
|
sparse_array[i] = { dense = i } :: ecs_record_t
|
||||||
|
|
|
@ -659,13 +659,35 @@ end)
|
||||||
TEST("world:entity()", function()
|
TEST("world:entity()", function()
|
||||||
do CASE "desired id"
|
do CASE "desired id"
|
||||||
local world = jecs.world()
|
local world = jecs.world()
|
||||||
world:range(400, 1000)
|
|
||||||
local id = world:entity()
|
local id = world:entity()
|
||||||
local e = world:entity(id + 5)
|
local e = world:entity(id + 5)
|
||||||
CHECK(e == id + 5)
|
CHECK(e == id + 5)
|
||||||
CHECK(world:contains(e))
|
CHECK(world:contains(e))
|
||||||
local e2 = world:entity()
|
local e2 = world:entity()
|
||||||
CHECK(world:contains(e2))
|
CHECK(world:contains(e2))
|
||||||
|
|
||||||
|
-- world:print_entity_index()
|
||||||
|
local e3 = world:entity(275)
|
||||||
|
|
||||||
|
CHECK(e3 == 275)
|
||||||
|
CHECK(world:contains(e3))
|
||||||
|
|
||||||
|
CHECK(e3 == world:entity(e3))
|
||||||
|
|
||||||
|
world:delete(e3)
|
||||||
|
|
||||||
|
local e3v1 = world:entity(275)
|
||||||
|
CHECK(not world:contains(275))
|
||||||
|
CHECK(jecs.ECS_GENERATION(e3v1) == 1)
|
||||||
|
CHECK(jecs.ECS_ID(e3v1) == 275)
|
||||||
|
|
||||||
|
|
||||||
|
CHECK(world:contains(e3v1))
|
||||||
|
-- world:print_entity_index()
|
||||||
|
world:entity(e3)
|
||||||
|
|
||||||
|
world:entity(e3)
|
||||||
|
world:entity(275)
|
||||||
end
|
end
|
||||||
local N = 2^8
|
local N = 2^8
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue