From dc69636f7243303e6f845ce9eaeb705be17deca1 Mon Sep 17 00:00:00 2001 From: bakpakin Date: Sat, 25 Apr 2015 21:37:04 +0800 Subject: [PATCH] Fix reordering of Systems. --- spec/tiny_spec.lua | 8 ++++++++ tiny.lua | 9 +++++++-- 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/spec/tiny_spec.lua b/spec/tiny_spec.lua index 23bba4b..4cc9efa 100644 --- a/spec/tiny_spec.lua +++ b/spec/tiny_spec.lua @@ -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) diff --git a/tiny.lua b/tiny.lua index 0116070..3e6c1b6 100644 --- a/tiny.lua +++ b/tiny.lua @@ -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.