mirror of
https://github.com/Ukendio/jecs.git
synced 2025-08-05 03:39: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]
|
||||
if r then
|
||||
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
|
||||
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[alive_count]
|
||||
local r_swap = sparse_array[alive_count]
|
||||
|
||||
if dense <= alive_count then
|
||||
local e_swap = dense_array[dense]
|
||||
local r_swap = entity_index_try_get_any(entity_index, e_swap) :: ecs_record_t
|
||||
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
|
||||
dense_array[alive_count] = entity
|
||||
return entity
|
||||
else
|
||||
for i = max_id + 1, index do
|
||||
sparse_array[i] = { dense = i } :: ecs_record_t
|
||||
|
|
|
@ -659,35 +659,13 @@ end)
|
|||
TEST("world:entity()", function()
|
||||
do CASE "desired id"
|
||||
local world = jecs.world()
|
||||
world:range(400, 1000)
|
||||
local id = world:entity()
|
||||
local e = world:entity(id + 5)
|
||||
CHECK(e == id + 5)
|
||||
CHECK(world:contains(e))
|
||||
local e2 = world:entity()
|
||||
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
|
||||
local N = 2^8
|
||||
|
||||
|
|
Loading…
Reference in a new issue