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