mirror of
https://github.com/Ukendio/jecs.git
synced 2025-08-05 19:49:17 +00:00
Compare commits
2 commits
d0af80577b
...
01821f0a7b
Author | SHA1 | Date | |
---|---|---|---|
|
01821f0a7b | ||
|
6922019ed9 |
2 changed files with 12 additions and 49 deletions
35
jecs.luau
35
jecs.luau
|
@ -772,39 +772,24 @@ 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 not dense or dense == 0 then
|
if dense and r.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]
|
|
||||||
if any == entity then
|
|
||||||
if alive_count > dense then
|
|
||||||
r.dense = dense
|
|
||||||
return entity
|
|
||||||
end
|
|
||||||
local e_swap = dense_array[alive_count]
|
|
||||||
local r_swap = sparse_array[alive_count]
|
|
||||||
r_swap.dense = dense
|
|
||||||
r.dense = alive_count
|
|
||||||
dense_array[alive_count] = entity
|
|
||||||
dense_array[dense] = e_swap
|
|
||||||
return entity
|
|
||||||
end
|
|
||||||
|
|
||||||
-- assert(any ~= 0) should never happen
|
local e_swap = dense_array[dense]
|
||||||
|
local r_swap = entity_index_try_get_any(entity_index, e_swap) :: ecs_record_t
|
||||||
local e_swap = dense_array[alive_count]
|
|
||||||
local r_swap = sparse_array[alive_count]
|
|
||||||
|
|
||||||
if dense <= alive_count then
|
|
||||||
alive_count += 1
|
alive_count += 1
|
||||||
entity_index.alive_count = alive_count
|
entity_index.alive_count = alive_count
|
||||||
end
|
|
||||||
|
|
||||||
r_swap.dense = dense
|
r_swap.dense = dense
|
||||||
r.dense = alive_count
|
r.dense = alive_count
|
||||||
dense_array[alive_count] = any
|
|
||||||
dense_array[dense] = e_swap
|
dense_array[dense] = e_swap
|
||||||
return any
|
dense_array[alive_count] = entity
|
||||||
|
return entity
|
||||||
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,35 +659,13 @@ 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