mirror of
https://github.com/bakpakin/tiny-ecs.git
synced 2026-07-22 07:56:52 -06:00
Add function to update systems indepenently of Worlds for, say, rendering.
This commit is contained in:
@@ -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
|
||||||
|
|||||||
Reference in New Issue
Block a user