mirror of
https://github.com/Ukendio/jecs.git
synced 2025-04-25 09:30:03 +00:00
Only swap when not last row
This commit is contained in:
parent
42af0239b5
commit
88457efd1d
1 changed files with 15 additions and 11 deletions
26
lib/init.lua
26
lib/init.lua
|
@ -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
|
||||||
|
|
Loading…
Reference in a new issue