Add function to update systems indepenently of Worlds for, say, rendering.

This commit is contained in:
bakpakin
2015-03-24 18:01:21 +08:00
parent db69cbca1d
commit 17592be9dc
+20 -14
View File
@@ -326,6 +326,25 @@ function World:remove(...)
end end
end end
-- World:updateSystem(system, dt)
function World:updateSystem(system, dt)
local preupdate = system.preupdate
local update = system.update
local systemEntities = self.systemEntities
if preupdate then
preupdate(dt)
end
if update then
local entities = self.entities
local eids = systemEntities[system.id]
for eid in pairs(eids) do
update(entities[eid], dt)
end
end
end
-- World:update() -- World:update()
-- Updates the World, frees Entities that have been marked for freeing, adds -- Updates the World, frees Entities that have been marked for freeing, adds
@@ -418,20 +437,7 @@ function World:update(dt)
-- Iterate through Systems IN ORDER -- Iterate through Systems IN ORDER
for _, s in ipairs(self.systems) do for _, s in ipairs(self.systems) do
if s.active then if s.active then
self:updateSystem(s, dt)
local preupdate = s.preupdate
local update = s.update
if preupdate then
preupdate(dt)
end
if update then
local eids = systemEntities[s.id]
for eid in pairs(eids) do
update(entities[eid], dt)
end
end
end end
end end
end end