Fix Adding systems and items to the world inside a call to system:onAdd()

This commit is contained in:
bakpakin
2015-08-24 12:52:11 -04:00
parent a5af4b6ecd
commit 9834dfa9d6
+15 -7
View File
@@ -348,7 +348,7 @@ local worldMetaTable
-- Can optionally add default Systems and Entities. Returns the new World along
-- with default Entities and Systems.
function tiny.world(...)
local ret = {
local ret = setmetatable({
-- List of Entities to add
entitiesToAdd = {},
@@ -370,13 +370,13 @@ function tiny.world(...)
-- List of Systems
systems = {}
}
}, worldMetaTable)
tiny_add(ret, ...)
tiny_manageSystems(ret)
tiny_manageEntities(ret)
return setmetatable(ret, worldMetaTable), ...
return ret, ...
end
--- Adds an Entity to the world.
@@ -461,6 +461,9 @@ function tiny_manageSystems(world)
return
end
world.systemsToAdd = {}
world.systemsToRemove = {}
local entities = world.entities
local systems = world.systems
local system, index, filter
@@ -531,6 +534,7 @@ end
-- Adds and removes Entities that have been marked.
function tiny_manageEntities(world)
local e2a, e2r = world.entitiesToAdd, world.entitiesToRemove
-- Early exit
@@ -538,6 +542,9 @@ function tiny_manageEntities(world)
return
end
world.entitiesToAdd = {}
world.entitiesToRemove = {}
local entities = world.entities
local systems = world.systems
local entityCount = world.entityCount
@@ -696,9 +703,7 @@ end
--- Sets the index of a System in the World, and returns the old index. Changes
-- the order in which they Systems processed, because lower indexed Systems are
-- processed first. If 'index' < 0, then sets 'index' relative to the last index
-- in the World; -1 is the index of the last System, -2 is the second to last,
-- and so on. Returns the old system.index.
-- processed first. Returns the old system.index.
function tiny.setSystemIndex(world, system, index)
local oldIndex = system.index
local systems = world.systems
@@ -734,7 +739,10 @@ worldMetaTable = {
getSystemCount = tiny.getSystemCount,
getSystemIndex = tiny.getSystemIndex,
setSystemIndex = tiny.setSystemIndex
}
},
__tostring = function(self)
return "tiny-ecs_World"
end
}
return tiny