mirror of
https://github.com/bakpakin/tiny-ecs.git
synced 2026-07-21 23:56:50 -06:00
Remove tiny.activate and tiny.deactivate.
This commit is contained in:
+13
-22
@@ -1,24 +1,15 @@
|
||||
local tiny = require "tiny"
|
||||
print("tiny version: " .. tiny._VERSION)
|
||||
-- Taken from answer at http://stackoverflow.com/questions/640642/how-do-you-copy-a-lua-table-by-value
|
||||
local function deep_copy(o, seen)
|
||||
seen = seen or {}
|
||||
if o == nil then return nil end
|
||||
if seen[o] then return seen[o] end
|
||||
|
||||
local no
|
||||
if type(o) == 'table' then
|
||||
no = {}
|
||||
seen[o] = no
|
||||
|
||||
for k, v in next, o, nil do
|
||||
no[deep_copy(k, seen)] = deep_copy(v, seen)
|
||||
local function deep_copy(x)
|
||||
if type(x) == 'table' then
|
||||
local nx = {}
|
||||
for k, v in next, x, nil do
|
||||
nx[deep_copy(k)] = deep_copy(v)
|
||||
end
|
||||
setmetatable(no, deep_copy(getmetatable(o), seen))
|
||||
else -- number, string, boolean, etc
|
||||
no = o
|
||||
return nx
|
||||
else
|
||||
return x
|
||||
end
|
||||
return no
|
||||
end
|
||||
|
||||
local entityTemplate1 = {
|
||||
@@ -138,15 +129,15 @@ describe('tiny-ecs:', function()
|
||||
assert.equals(0, world:getSystemCount())
|
||||
end)
|
||||
|
||||
it("Disable and Enable Systems", function()
|
||||
world:deactivate(moveSystem)
|
||||
world:deactivate(oneTimeSystem)
|
||||
it("Deactivate and Activate Systems", function()
|
||||
moveSystem.active = false
|
||||
oneTimeSystem.active = false
|
||||
world:update(1)
|
||||
assert.equals(world:getSystemCount(), 2)
|
||||
assert.equals(timePassed, 0)
|
||||
assert.equals(entity1.xform.x, entityTemplate1.xform.x)
|
||||
world:activate(moveSystem)
|
||||
world:activate(oneTimeSystem)
|
||||
moveSystem.active = true
|
||||
oneTimeSystem.active = true
|
||||
world:update(1)
|
||||
assert.equals(timePassed, 1)
|
||||
assert.are_not.equal(entity1.xform.x, entityTemplate1.xform.x)
|
||||
|
||||
@@ -52,12 +52,12 @@ local tiny_remove
|
||||
function tiny.requireAll(...)
|
||||
local components = {...}
|
||||
local len = #components
|
||||
return function(_, e)
|
||||
return function(system, e)
|
||||
local c
|
||||
for i = 1, len do
|
||||
c = components[i]
|
||||
if type(c) == 'function' then
|
||||
if not c(_, e) then
|
||||
if not c(system, e) then
|
||||
return false
|
||||
end
|
||||
elseif e[c] == nil then
|
||||
@@ -74,12 +74,12 @@ end
|
||||
function tiny.requireOne(...)
|
||||
local components = {...}
|
||||
local len = #components
|
||||
return function(_, e)
|
||||
return function(system, e)
|
||||
local c
|
||||
for i = 1, len do
|
||||
c = components[i]
|
||||
if type(c) == 'function' then
|
||||
if c(_, e) then
|
||||
if c(system, e) then
|
||||
return true
|
||||
end
|
||||
elseif e[c] ~= nil then
|
||||
@@ -116,9 +116,7 @@ end
|
||||
-- but one can write their own filters as well.
|
||||
-- @param table A table to be used as a System, or `nil` to create a new System.
|
||||
function tiny.system(table)
|
||||
if table == nil then
|
||||
table = {}
|
||||
end
|
||||
table = table or {}
|
||||
table[systemTableKey] = true
|
||||
return table
|
||||
end
|
||||
@@ -164,9 +162,7 @@ end
|
||||
-- @param table A table to be used as a System, or `nil` to create a new
|
||||
-- Processing System.
|
||||
function tiny.processingSystem(table)
|
||||
if table == nil then
|
||||
table = {}
|
||||
end
|
||||
table = table or {}
|
||||
table[systemTableKey] = true
|
||||
table.update = processingSystemUpdate
|
||||
return table
|
||||
@@ -207,9 +203,7 @@ end
|
||||
-- @param table A table to be used as a System, or `nil` to create a new
|
||||
-- Processing System.
|
||||
function tiny.sortedSystem(table)
|
||||
if table == nil then
|
||||
table = {}
|
||||
end
|
||||
table = table or {}
|
||||
table[systemTableKey] = true
|
||||
table.update = processingSystemUpdate
|
||||
table.onModify = sortedSystemOnModify
|
||||
@@ -599,24 +593,4 @@ function tiny.setSystemIndex(world, system, index)
|
||||
end
|
||||
end
|
||||
|
||||
--- Activate a System in the World.
|
||||
-- Activated Systems will be update whenever tiny.update(world, dt) is called.
|
||||
-- @param world
|
||||
-- @param system System to activate. The System must already be added to the
|
||||
-- World.
|
||||
function tiny.activate(world, system)
|
||||
system.active = true
|
||||
end
|
||||
|
||||
--- Deactivates a System in the World.
|
||||
-- Deactivated Systems must be update manually, and will not update when the
|
||||
-- rest of World updates. They will, however, process new Entities added while
|
||||
-- the System is deactivated.
|
||||
-- @param world
|
||||
-- @param system System to deactivate. The System must already be added to the
|
||||
-- World.
|
||||
function tiny.deactivate(world, system)
|
||||
system.active = false
|
||||
end
|
||||
|
||||
return tiny
|
||||
|
||||
Reference in New Issue
Block a user