From 627ca789065bfcbce53a51887be4e8f8fb20d26b Mon Sep 17 00:00:00 2001 From: sanine Date: Fri, 24 Mar 2023 19:19:21 -0500 Subject: add pausing --- honey/ecs.lua | 29 ++++++++++++++++------------- 1 file changed, 16 insertions(+), 13 deletions(-) (limited to 'honey/ecs.lua') diff --git a/honey/ecs.lua b/honey/ecs.lua index d611b37..b7806f9 100644 --- a/honey/ecs.lua +++ b/honey/ecs.lua @@ -195,23 +195,26 @@ function Level.reconfigureAllEntities(self) end -function Level.update(self, dt) +function Level.update(self, dt, paused) + local paused = paused or false for _, system in ipairs(self.systems) do - if system.preUpdate then - system:preUpdate() - end - if system.prepareEntity then + if (not paused) or (paused and system.nopause) then + if system.preUpdate then + system:preUpdate() + end + if system.prepareEntity then + for id in pairs(system.entities) do + local entity = self.entities[id] + system:prepareEntity(entity) + end + end for id in pairs(system.entities) do local entity = self.entities[id] - system:prepareEntity(entity) + system:update(entity, dt) + end + if system.postUpdate then + system:postUpdate() end - end - for id in pairs(system.entities) do - local entity = self.entities[id] - system:update(entity, dt) - end - if system.postUpdate then - system:postUpdate() end end end -- cgit v1.2.1