Reallocate tables

This commit is contained in:
Ukendio 2024-09-22 16:19:31 +02:00
parent eedad66517
commit 95b166eca3

View file

@ -912,8 +912,10 @@ local function archetype_destroy(world: World, archetype: Archetype)
local component_index = world.componentIndex local component_index = world.componentIndex
archetype_clear_edges(archetype) archetype_clear_edges(archetype)
local archetype_id = archetype.id local archetype_id = archetype.id
world.archetypes[archetype_id] = nil if archetype ~= world.ROOT_ARCHETYPE then
world.archetypeIndex[archetype.type] = nil world.archetypes[archetype_id] = nil
world.archetypeIndex[archetype.type] = nil
end
local records = archetype.records local records = archetype.records
for id in records do for id in records do
@ -928,11 +930,24 @@ local function archetype_destroy(world: World, archetype: Archetype)
end end
local function world_cleanup(world) local function world_cleanup(world)
for _, archetype in world.archetypes do local archetypes = world.archetypes
for _, archetype in archetypes do
if #archetype.entities == 0 then if #archetype.entities == 0 then
archetype_destroy(world, archetype) archetype_destroy(world, archetype)
end end
end end
local new_archetypes = {}
local new_archetype_map = {}
for index, archetype in archetypes do
new_archetypes[index] = archetype
new_archetype_map[archetype.type] = archetype
end
world.archetypes = new_archetypes
world.archetypeIndex = new_archetype_map
end end
local world_delete: (world: World, entity: i53, destruct: boolean?) -> () local world_delete: (world: World, entity: i53, destruct: boolean?) -> ()