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

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

View file

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