From e5553bb81c93cd76456d07d3a1d7e8bb1b249b6e Mon Sep 17 00:00:00 2001 From: sanine-a Date: Thu, 23 Mar 2023 13:35:37 -0500 Subject: implement skeleton of physics system --- honey/ecs.lua | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) (limited to 'honey/ecs.lua') diff --git a/honey/ecs.lua b/honey/ecs.lua index 23bb0ba..d611b37 100644 --- a/honey/ecs.lua +++ b/honey/ecs.lua @@ -123,6 +123,9 @@ function Level.addSystem(self, system) system.entities = {} table.insert(self.systems, system) table.sort(self.systems, systemLt) + if system.setup then + system.setup(system) + end end @@ -131,7 +134,7 @@ local function addEntityToSystem(system, id, entity) if system.entities[id] then return end if system.onAddEntity then - system.onAddEntity(id, entity) + system:onAddEntity(id, entity) end system.entities[id] = true end @@ -142,7 +145,7 @@ local function removeEntityFromSystem(system, id, entity) if not system.entities[id] then return end if system.onRemoveEntity then - system.onRemoveEntity(id, entity) + system:onRemoveEntity(id, entity) end system.entities[id] = nil end @@ -195,20 +198,20 @@ end function Level.update(self, dt) for _, system in ipairs(self.systems) do if system.preUpdate then + system:preUpdate() + end + if system.prepareEntity then for id in pairs(system.entities) do local entity = self.entities[id] - system.preUpdate(entity) + system:prepareEntity(entity) end end for id in pairs(system.entities) do local entity = self.entities[id] - system.update(entity, dt) + system:update(entity, dt) end if system.postUpdate then - for id in pairs(system.entities) do - local entity = self.entities[id] - system.postUpdate(entity) - end + system:postUpdate() end end end -- cgit v1.2.1