summaryrefslogtreecommitdiff
path: root/honey/ecs.lua
diff options
context:
space:
mode:
Diffstat (limited to 'honey/ecs.lua')
-rw-r--r--honey/ecs.lua19
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