mirror of
https://github.com/Ukendio/jecs.git
synced 2025-08-05 03:39:17 +00:00
Compare commits
5 commits
73c316361e
...
d883a022a1
Author | SHA1 | Date | |
---|---|---|---|
|
d883a022a1 | ||
|
3ae84301f2 | ||
|
01821f0a7b | ||
|
6922019ed9 | ||
|
96bed9bd7e |
2 changed files with 42 additions and 63 deletions
34
jecs.luau
34
jecs.luau
|
@ -772,38 +772,26 @@ 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 not dense or r.dense == 0 then
|
||||||
|
r.dense = index
|
||||||
dense = index
|
dense = index
|
||||||
end
|
end
|
||||||
|
|
||||||
local any = dense_array[dense]
|
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
|
if dense <= alive_count then
|
||||||
alive_count += 1
|
return any
|
||||||
entity_index.alive_count = alive_count
|
|
||||||
end
|
end
|
||||||
|
|
||||||
|
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
|
||||||
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
|
||||||
|
dense_array[alive_count] = any
|
||||||
|
|
||||||
return any
|
return any
|
||||||
else
|
else
|
||||||
for i = max_id + 1, index do
|
for i = max_id + 1, index do
|
||||||
|
|
|
@ -634,25 +634,39 @@ TEST("world:each()", function()
|
||||||
end)
|
end)
|
||||||
|
|
||||||
TEST("world:range()", function()
|
TEST("world:range()", function()
|
||||||
do CASE ""
|
do CASE "under range start"
|
||||||
local world = jecs.world()
|
local world = jecs.world()
|
||||||
world = lifetime_tracker_add(world, {})
|
world:range(400, 1000)
|
||||||
world:range(1000, 2000)
|
local id = world:entity()
|
||||||
local e = world:entity()
|
local e = world:entity(id + 5)
|
||||||
CHECK(e == 1000)
|
CHECK(e == id + 5)
|
||||||
|
CHECK(world:contains(e))
|
||||||
|
local e2 = world:entity(399)
|
||||||
|
CHECK(world:contains(e2))
|
||||||
|
world:delete(e2)
|
||||||
|
CHECK(not world:contains(e2))
|
||||||
|
local e2v1 = world:entity(399)
|
||||||
|
CHECK(world:contains(e2v1))
|
||||||
|
CHECK(ECS_ID(e2v1) == 399)
|
||||||
|
CHECK(ECS_GENERATION(e2v1) == 1)
|
||||||
|
end
|
||||||
|
|
||||||
world:entity(1590)
|
do CASE "over range start"
|
||||||
|
local world = jecs.world()
|
||||||
|
world:range(400, 1000)
|
||||||
|
local e2 = world:entity(405)
|
||||||
|
CHECK(world:contains(e2))
|
||||||
|
world:delete(e2)
|
||||||
|
CHECK(not world:contains(e2))
|
||||||
|
local e2v1 = world:entity(405)
|
||||||
|
CHECK(world:contains(e2v1))
|
||||||
|
CHECK(ECS_ID(e2v1) == 405)
|
||||||
|
CHECK(ECS_GENERATION(e2v1) == 1)
|
||||||
|
|
||||||
CHECK(world:entity(5000) == 5000)
|
do
|
||||||
|
local _e2v1 = world:entity(405)
|
||||||
CHECK(world:contains(1590))
|
CHECK(_e2v1 == e2v1)
|
||||||
world:set(591, jecs.Name, "9888")
|
end
|
||||||
CHECK(not world:contains(591))
|
|
||||||
CHECK(world:contains(5000))
|
|
||||||
CHECK(not world:contains(988))
|
|
||||||
|
|
||||||
local e = world:entity(2000)
|
|
||||||
CHECK(e == 2000)
|
|
||||||
end
|
end
|
||||||
end)
|
end)
|
||||||
|
|
||||||
|
@ -663,31 +677,8 @@ TEST("world:entity()", function()
|
||||||
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(399)
|
||||||
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