From 314e9cd4c96f30f47b6c02eefbadf063e1a58025 Mon Sep 17 00:00:00 2001 From: sanine Date: Fri, 24 Mar 2023 20:45:41 -0500 Subject: fix ecs removing --- honey/ecs.lua | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) (limited to 'honey/ecs.lua') diff --git a/honey/ecs.lua b/honey/ecs.lua index b7806f9..3632f34 100644 --- a/honey/ecs.lua +++ b/honey/ecs.lua @@ -152,8 +152,8 @@ end function Level.addEntity(self, entity) - table.insert(self.entities, entity) local id = self.nextId + self.entities[id] = entity self.nextId = id + 1 for _, system in ipairs(self.systems) do @@ -181,6 +181,7 @@ end function Level.removeEntity(self, id) local entity = self.entities[id] + if not entity then error("bad id: "..tostring(id)) end for _, system in ipairs(self.systems) do removeEntityFromSystem(system, id, entity) end @@ -205,12 +206,16 @@ function Level.update(self, dt, paused) if system.prepareEntity then for id in pairs(system.entities) do local entity = self.entities[id] - system:prepareEntity(entity) + if entity then + system:prepareEntity(entity) + end end end for id in pairs(system.entities) do local entity = self.entities[id] - system:update(entity, dt) + if entity then + system:update(entity, dt) + end end if system.postUpdate then system:postUpdate() -- cgit v1.2.1