Swap dense indexes

This commit is contained in:
Ukendio 2024-05-05 17:32:30 +02:00
parent cbe0710c37
commit 8638c04448

View file

@ -614,34 +614,26 @@ local function archetypeDelete(entityIndex, entityId: i53, destruct: boolean)
local sparse = entityIndex.sparse local sparse = entityIndex.sparse
local dense = entityIndex.dense local dense = entityIndex.dense
local record = sparse[entityId] local record = sparse[entityId]
if not record then
return
end
local archetype = record.archetype local archetype = record.archetype
local row = record.row local row = record.row
local denseIndex = record.dense
local entities = archetype.entities local entities = archetype.entities
local last = #entities local last = #entities
local entityToMove = entities[last] local entityToMove = entities[last]
--local entityToDelete = entities[row]
entities[row] = entityToMove
entities[last] = nil
if row ~= last then if row ~= last then
local recordToMove = sparse[entityToMove] dense[record.dense] = entityToMove
if recordToMove then sparse[entityToMove] = record
recordToMove.row = row
record.dense = denseIndex
dense[denseIndex] = entityToMove
end
end end
record.archetype = nil sparse[entityId] = nil
record.row = nil dense[#dense] = nil
entityIndex.sparse[entityId] = nil
entities[row], entities[last] = entities[last], nil
local atDense = record.dense
entityIndex[atDense] = nil
local columns = archetype.columns local columns = archetype.columns
if not destruct then if not destruct then
@ -649,6 +641,8 @@ local function archetypeDelete(entityIndex, entityId: i53, destruct: boolean)
end end
destructColumns(columns, last, row) destructColumns(columns, last, row)
end end
function World.delete(world: World, entityId: i53) function World.delete(world: World, entityId: i53)