Swap entity index for last row (#6)

This commit is contained in:
Marcus 2024-04-30 16:05:31 +02:00 committed by GitHub
parent 8ef960dad6
commit dc73c03d74
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
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()