Retrieve updated max_id

This commit is contained in:
Ukendio 2025-07-17 18:47:04 +02:00
parent c30328527a
commit fc56b6f716
2 changed files with 12 additions and 3 deletions

View file

@ -2157,13 +2157,12 @@ local function world_new()
local eindex_dense_array = {} :: { Entity } local eindex_dense_array = {} :: { Entity }
local eindex_sparse_array = {} :: { Record } local eindex_sparse_array = {} :: { Record }
local eindex_alive_count = 0 local eindex_alive_count = 0
local eindex_max_id = 0
local entity_index = { local entity_index = {
dense_array = eindex_dense_array, dense_array = eindex_dense_array,
sparse_array = eindex_sparse_array, sparse_array = eindex_sparse_array,
alive_count = eindex_alive_count, alive_count = eindex_alive_count,
max_id = eindex_max_id, max_id = 0,
} :: EntityIndex } :: EntityIndex
local component_index = {} :: ComponentIndex local component_index = {} :: ComponentIndex
@ -2605,7 +2604,7 @@ local function world_new()
return entity return entity
else else
for i = eindex_max_id + 1, index do for i = entity_index.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

View file

@ -24,6 +24,16 @@ type Id<T=unknown> = jecs.Id<T>
local entity_visualiser = require("@tools/entity_visualiser") local entity_visualiser = require("@tools/entity_visualiser")
local dwi = entity_visualiser.stringify local dwi = entity_visualiser.stringify
TEST("dai", function()
local world = jecs.world()
local C = world:component()
world:set(C, jecs.Name, "C")
CHECK(world:get(C, jecs.Name) == "C")
world:entity(2000)
CHECK(world:get(C, jecs.Name) == "C")
end)
TEST("another axen banger", function() TEST("another axen banger", function()
-- taken from jecs.luau -- taken from jecs.luau
local world = jecs.world() local world = jecs.world()