Skip to content

Commit

Permalink
Reallocate tables
Browse files Browse the repository at this point in the history
  • Loading branch information
Ukendio committed Sep 22, 2024
1 parent eedad66 commit 95b166e
Showing 1 changed file with 18 additions and 3 deletions.
21 changes: 18 additions & 3 deletions src/init.luau
Original file line number Diff line number Diff line change
Expand Up @@ -912,8 +912,10 @@ local function archetype_destroy(world: World, archetype: Archetype)
local component_index = world.componentIndex
archetype_clear_edges(archetype)
local archetype_id = archetype.id
world.archetypes[archetype_id] = nil
world.archetypeIndex[archetype.type] = nil
if archetype ~= world.ROOT_ARCHETYPE then
world.archetypes[archetype_id] = nil
world.archetypeIndex[archetype.type] = nil
end
local records = archetype.records

for id in records do
Expand All @@ -928,11 +930,24 @@ local function archetype_destroy(world: World, archetype: Archetype)
end

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
archetype_destroy(world, archetype)
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

local world_delete: (world: World, entity: i53, destruct: boolean?) -> ()
Expand Down

0 comments on commit 95b166e

Please sign in to comment.