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