mirror of
https://github.com/Ukendio/jecs.git
synced 2025-04-25 09:30:03 +00:00
Swap dense indexes
This commit is contained in:
parent
cbe0710c37
commit
8638c04448
1 changed files with 11 additions and 17 deletions
28
lib/init.lua
28
lib/init.lua
|
@ -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)
|
||||||
|
|
Loading…
Reference in a new issue