Only swap when not last row

This commit is contained in:
Ukendio 2024-05-10 15:34:27 +02:00
parent 42af0239b5
commit 88457efd1d

View file

@ -82,23 +82,27 @@ local function transitionArchetype(
column[last] = nil column[last] = nil
end end
local dense, sparse = entityIndex.dense, entityIndex.sparse local sparse = entityIndex.sparse
-- Move the entity from the source to the destination archetype. local movedAway = #sourceEntities
local atSourceRow = sourceEntities[sourceRow]
destinationEntities[destinationRow] = atSourceRow
local record = sparse[atSourceRow]
record.row = destinationRow
-- Move the entity from the source to the destination archetype.
-- Because we have swapped columns we now have to update the records -- Because we have swapped columns we now have to update the records
-- corresponding to the entities' rows that were swapped. -- corresponding to the entities' rows that were swapped.
local movedAway = #sourceEntities local e1 = sourceEntities[sourceRow]
if sourceRow ~= movedAway then local e2 = sourceEntities[movedAway]
local atMovedAway = sourceEntities[movedAway]
sourceEntities[sourceRow] = atMovedAway if sourceRow ~= movedAway then
sparse[atMovedAway].row = sourceRow sourceEntities[sourceRow] = e2
end end
sourceEntities[movedAway] = nil sourceEntities[movedAway] = nil
destinationEntities[destinationRow] = e1
local record1 = sparse[e1]
local record2 = sparse[e2]
record1.row = destinationRow
record2.row = sourceRow
end end
local function archetypeAppend(entity: number, archetype: Archetype): number local function archetypeAppend(entity: number, archetype: Archetype): number