Add optional optimization for worlds and systems

This commit is contained in:
Tjakka5 2020-01-03 23:01:04 +01:00
parent 56b5244541
commit 6aeb91d984
4 changed files with 58 additions and 57 deletions

View file

@ -9,77 +9,48 @@ require(file)
local Concord = require("src")
local Component = Concord.component
local Components = Concord.components
local System = Concord.system
local Systems = Concord.systems
local Entity = Concord.entity
local World = Concord.world
local Worlds = Concord.worlds
local Component = Concord.component
local System = Concord.system
local Entity = Concord.entity
local World = Concord.world
local test_comp_1 = Component(function(e, a)
e.a = a
end)
local test_comp_2 = Component(function(e, a)
e.a = a
end)
local test_comp_3 = Component()
local test_system_1 = System({test_comp_1})
function test_system_1:init()
self.pool.onEntityAdded = function()
print("Added to test_system 1")
end
self.pool.onEntityRemoved = function() print("Removed from test_system 1") end
end
local test_system_2 = System({test_comp_1})
local test_system_3 = System({test_comp_1})
function test_system_1:test()
print("Running test_system_1 with: " ..#self.pool)
for _, e in ipairs(self.pool) do
local newE = Entity()
newE:give(test_comp_1)
self:getWorld():addEntity(newE)
e:give(test_comp_2)
for _, _ in ipairs(self.pool) do
end
end
local test_system_2 = System({test_comp_2})
function test_system_2:init()
self.pool.onEntityAdded = function(pool, e) print("Added to test_system 2") e:remove(test_comp_1) end
self.pool.onEntityRemoved = function() print("Removed from test_system 2") end
end
function test_system_2:test()
print("Running test_system_2 with: " ..#self.pool)
for _, _ in ipairs(self.pool) do
end
end
for _, e in ipairs(self.pool) do
function test_system_3:test()
for _, _ in ipairs(self.pool) do
end
end
local world = World()
local entity = Entity(world)
entity:give(test_comp_1, 100, 100)
world:addSystems(test_system_1, test_system_2, test_system_3)
world:addSystems(test_system_1, test_system_2)
for _ = 1, 100 do
local entity = Entity(world)
entity:give(test_comp_1, 100, 100)
end
print("Iteration: 1")
world:emit("test")
print("Iteration: 2")
world:emit("test")
local start = love.timer.getTime()
for _ = 1, 1000000 do
world:emit("test")
end
local stop = love.timer.getTime()
print("Iteration: 3")
world:emit("test")
print("Time taken: " .. stop - start)