From 05d7574794bbaa201ed1e54ba3f920643a8e0264 Mon Sep 17 00:00:00 2001 From: bakpakin Date: Sat, 28 Mar 2015 23:11:36 +0800 Subject: [PATCH] Actually remove World:change(...) Increase version number --- README.md | 2 +- jojo.lua | 29 ++++++++++------------------- jojotest.lua | 2 +- 3 files changed, 12 insertions(+), 21 deletions(-) diff --git a/README.md b/README.md index 09b7564..b79c030 100644 --- a/README.md +++ b/README.md @@ -77,7 +77,7 @@ run `lua jojotest.lua` from command line. ## TODO ## -* Dynamically add and remove systems +* Dynamic reordering of Systems * More testing * Performance testing / optimization * API outside of source code diff --git a/jojo.lua b/jojo.lua index 9486495..23eebff 100644 --- a/jojo.lua +++ b/jojo.lua @@ -1,5 +1,5 @@ local jojo = { - _VERSION = "0.0.3", + _VERSION = "0.0.4", _URL = "https://github.com/bakpakin/Jojo", _DESCRIPTION = "Entity Component System for lua." } @@ -36,7 +36,6 @@ local tremove = table.remove local tconcat = table.concat local pairs = pairs local ipairs = ipairs -local print = print ----- Aspect ----- @@ -183,7 +182,6 @@ function System:init(preupdate, update, aspect, add, remove) self.preupdate = preupdate self.update = update self.aspect = aspect or Aspect() - self.active = true self.add = add self.remove = remove end @@ -195,8 +193,6 @@ function System:__tostring() self.update .. ", aspect: " .. self.aspect .. - ", active: " .. - self.active .. ">" end @@ -222,6 +218,10 @@ function World:init(...) -- List of Systems self.systems = args + -- Table of Systems to whether or not they are active. + local activeSystems = {} + self.activeSystems = activeSystems + -- Table of Systems to System Indices local systemIndices = {} self.systemIndices = systemIndices @@ -231,6 +231,7 @@ function World:init(...) self.systemEntities = systemEntities for i, sys in ipairs(args) do + activeSystems[sys] = true systemEntities[sys] = {} systemIndices[sys] = i end @@ -290,19 +291,6 @@ function World:add(...) end end --- World:changed(...) - --- Call this function on any Entities that have changed such that they would --- now match different systems. Entities will be updated in the world the next --- time World:update(dt) is called. -function World:change(...) - local args = {...} - local status = self.status - for _, e in ipairs(args) do - status[e] = "add" - end -end - -- World:free(...) -- Removes Entities from the World. Entities will exit the World the next time @@ -349,6 +337,7 @@ function World:update(dt) local systems = self.systems local systemsToAdd = self.systemsToAdd local systemsToRemove = self.systemsToRemove + local activeSystems = self.activeSystems -- Remove all Systems queued for removal for i = #systemsToRemove, 1, -1 do @@ -367,6 +356,7 @@ function World:update(dt) end systemEntities[sys] = nil + activeSystems[sys] = nil end -- Add Systems queued for addition @@ -380,6 +370,7 @@ function World:update(dt) systemEntities[sys] = es tinsert(systems, sys) systemIndices[sys] = #systems + activeSystems[sys] = true local a = sys.aspect for e in pairs(entities) do @@ -421,7 +412,7 @@ function World:update(dt) -- Iterate through Systems IN ORDER for _, s in ipairs(self.systems) do - if s.active then + if activeSystems[s] then self:updateSystem(s, dt) end end diff --git a/jojotest.lua b/jojotest.lua index d36a541..8794bb1 100644 --- a/jojotest.lua +++ b/jojotest.lua @@ -101,7 +101,7 @@ world:add(e3, e2) world:update(19) world:remove(e3, e2) e1.vel = nil -world:change(e1) +world:add(e1) world:update(11) assert(e1.xform.x == 60, "e1.xform.x should be 60, but is " .. e1.xform.x)