diff options
author | sanine-a <sanine.not@pm.me> | 2023-03-23 13:35:37 -0500 |
---|---|---|
committer | sanine-a <sanine.not@pm.me> | 2023-03-23 13:35:37 -0500 |
commit | e5553bb81c93cd76456d07d3a1d7e8bb1b249b6e (patch) | |
tree | a92801deaba55c85dd4f52636ab4f616e8483796 /honey/ecs.lua | |
parent | f4346b8f06653dbc1e0c346d88f5f83ca8a7b876 (diff) |
implement skeleton of physics system
Diffstat (limited to 'honey/ecs.lua')
-rw-r--r-- | honey/ecs.lua | 19 |
1 files changed, 11 insertions, 8 deletions
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 |