mirror of
https://github.com/Ukendio/jecs.git
synced 2025-04-24 17:10:03 +00:00
Swap entity index for last row (#6)
This commit is contained in:
parent
8ef960dad6
commit
dc73c03d74
2 changed files with 20 additions and 10 deletions
12
lib/init.lua
12
lib/init.lua
|
@ -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
|
||||
|
|
|
@ -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()
|
||||
|
|
Loading…
Reference in a new issue