Fix reordering of Systems.

This commit is contained in:
bakpakin 2015-04-25 21:37:04 +08:00
parent dc3deab725
commit dc69636f72
2 changed files with 15 additions and 2 deletions

View File

@ -197,6 +197,14 @@ describe('tiny-ecs:', function()
assert.equals(3, world:getEntityCount())
end)
it("Reorder Systems", function()
world:update(1)
world:setSystemIndex(moveSystem, 2)
world:update(1)
assert.equals(2, world:getSystemIndex(moveSystem))
assert.equals(1, world:getSystemIndex(oneTimeSystem))
end)
end)
end)

View File

@ -540,11 +540,16 @@ end
-- @param system
-- @param index
function tiny.setSystemIndex(world, system, index)
local oldIndex = world.systemIndices[system]
local systemIndices = world.systemIndices
local oldIndex = systemIndices[system]
local systems = world.systems
tremove(systems, oldIndex)
tinsert(systems, index, system)
world.systemIndices[system] = index
for i = oldIndex, index, index >= oldIndex and 1 or -1 do
systemIndices[systems[i]] = i
end
end
--- Activates Systems in the World.