Swap entity index for last row

This commit is contained in:
Ukendio 2024-04-30 16:05:01 +02:00
parent 8ef960dad6
commit 35dba3c276
2 changed files with 20 additions and 10 deletions

View file

@ -70,11 +70,13 @@ local function transitionArchetype(
column[#column] = nil
end
destinationEntities[destinationRow] = sourceEntities[sourceRow]
local moveAway = #sourceEntities
sourceEntities[sourceRow] = sourceEntities[moveAway]
sourceEntities[moveAway] = nil
entityIndex[destinationEntities[destinationRow]].row = sourceRow
destinationEntities[destinationRow] = sourceEntities[sourceRow]
entityIndex[sourceEntities[sourceRow]].row = destinationRow
local movedAway = #sourceEntities
sourceEntities[sourceRow] = sourceEntities[movedAway]
entityIndex[sourceEntities[movedAway]].row = sourceRow
sourceEntities[movedAway] = nil
end
local function archetypeAppend(entity: i53, archetype: Archetype): i24

View file

@ -84,12 +84,20 @@ return function()
end)
it("should remove component", function()
local id = world:entity()
world:set(id, A, true)
world:set(id, B, 1000)
world:remove(id, A, false)
local Tag = world:entity()
local entities = {}
for i = 1, 10 do
local entity = world:entity()
entities[i] = entity
world:set(entity, Tag)
end
expect(world:get(id, A)).to.equal(nil)
for i = 1, 10 do
local entity = entities[i]
expect(world:get(entity, Tag)).to.equal(nil)
world:remove(entity, Tag)
end
end)
it("should override component data", function()