Actually remove World:change(...)

Increase version number
This commit is contained in:
bakpakin 2015-03-28 23:11:36 +08:00
parent c046bde701
commit 05d7574794
3 changed files with 12 additions and 21 deletions

View File

@ -77,7 +77,7 @@ run `lua jojotest.lua` from command line.
## TODO ## ## TODO ##
* Dynamically add and remove systems * Dynamic reordering of Systems
* More testing * More testing
* Performance testing / optimization * Performance testing / optimization
* API outside of source code * API outside of source code

View File

@ -1,5 +1,5 @@
local jojo = { local jojo = {
_VERSION = "0.0.3", _VERSION = "0.0.4",
_URL = "https://github.com/bakpakin/Jojo", _URL = "https://github.com/bakpakin/Jojo",
_DESCRIPTION = "Entity Component System for lua." _DESCRIPTION = "Entity Component System for lua."
} }
@ -36,7 +36,6 @@ local tremove = table.remove
local tconcat = table.concat local tconcat = table.concat
local pairs = pairs local pairs = pairs
local ipairs = ipairs local ipairs = ipairs
local print = print
----- Aspect ----- ----- Aspect -----
@ -183,7 +182,6 @@ function System:init(preupdate, update, aspect, add, remove)
self.preupdate = preupdate self.preupdate = preupdate
self.update = update self.update = update
self.aspect = aspect or Aspect() self.aspect = aspect or Aspect()
self.active = true
self.add = add self.add = add
self.remove = remove self.remove = remove
end end
@ -195,8 +193,6 @@ function System:__tostring()
self.update .. self.update ..
", aspect: " .. ", aspect: " ..
self.aspect .. self.aspect ..
", active: " ..
self.active ..
">" ">"
end end
@ -222,6 +218,10 @@ function World:init(...)
-- List of Systems -- List of Systems
self.systems = args self.systems = args
-- Table of Systems to whether or not they are active.
local activeSystems = {}
self.activeSystems = activeSystems
-- Table of Systems to System Indices -- Table of Systems to System Indices
local systemIndices = {} local systemIndices = {}
self.systemIndices = systemIndices self.systemIndices = systemIndices
@ -231,6 +231,7 @@ function World:init(...)
self.systemEntities = systemEntities self.systemEntities = systemEntities
for i, sys in ipairs(args) do for i, sys in ipairs(args) do
activeSystems[sys] = true
systemEntities[sys] = {} systemEntities[sys] = {}
systemIndices[sys] = i systemIndices[sys] = i
end end
@ -290,19 +291,6 @@ function World:add(...)
end end
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(...) -- World:free(...)
-- Removes Entities from the World. Entities will exit the World the next time -- 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 systems = self.systems
local systemsToAdd = self.systemsToAdd local systemsToAdd = self.systemsToAdd
local systemsToRemove = self.systemsToRemove local systemsToRemove = self.systemsToRemove
local activeSystems = self.activeSystems
-- Remove all Systems queued for removal -- Remove all Systems queued for removal
for i = #systemsToRemove, 1, -1 do for i = #systemsToRemove, 1, -1 do
@ -367,6 +356,7 @@ function World:update(dt)
end end
systemEntities[sys] = nil systemEntities[sys] = nil
activeSystems[sys] = nil
end end
-- Add Systems queued for addition -- Add Systems queued for addition
@ -380,6 +370,7 @@ function World:update(dt)
systemEntities[sys] = es systemEntities[sys] = es
tinsert(systems, sys) tinsert(systems, sys)
systemIndices[sys] = #systems systemIndices[sys] = #systems
activeSystems[sys] = true
local a = sys.aspect local a = sys.aspect
for e in pairs(entities) do for e in pairs(entities) do
@ -421,7 +412,7 @@ function World:update(dt)
-- Iterate through Systems IN ORDER -- Iterate through Systems IN ORDER
for _, s in ipairs(self.systems) do for _, s in ipairs(self.systems) do
if s.active then if activeSystems[s] then
self:updateSystem(s, dt) self:updateSystem(s, dt)
end end
end end

View File

@ -101,7 +101,7 @@ world:add(e3, e2)
world:update(19) world:update(19)
world:remove(e3, e2) world:remove(e3, e2)
e1.vel = nil e1.vel = nil
world:change(e1) world:add(e1)
world:update(11) world:update(11)
assert(e1.xform.x == 60, "e1.xform.x should be 60, but is " .. e1.xform.x) assert(e1.xform.x == 60, "e1.xform.x should be 60, but is " .. e1.xform.x)