diff --git a/examples/assemblageTest/init.lua b/examples/assemblageTest/init.lua index 730129b..444d37b 100644 --- a/examples/assemblageTest/init.lua +++ b/examples/assemblageTest/init.lua @@ -1,13 +1,11 @@ -local Concord = require("lib").init({ - useEvents = true -}) +local Concord = require("lib") + local Entity = Concord.entity local Component = Concord.component local System = Concord.system local Assemblage = Concord.assemblage local Game = Concord.instance() -Concord.addInstance(Game) local Legs = Component(function(e, legCount) e.legCount = legCount or 0 diff --git a/examples/baseLayout/main.lua b/examples/baseLayout/main.lua index ed6e30d..b4785c2 100644 --- a/examples/baseLayout/main.lua +++ b/examples/baseLayout/main.lua @@ -1,8 +1,6 @@ local PATH = (...):gsub('%.[^%.]+$', '') -local Concord = require("lib").init({ - useEvents = true -}) +local Concord = require("lib") local C = require(PATH..".src.components") -local S = require(PATH..".src.systems") \ No newline at end of file +local S = require(PATH..".src.systems") diff --git a/examples/simpleDrawing/init.lua b/examples/simpleDrawing/init.lua index 8cc0426..5eca907 100644 --- a/examples/simpleDrawing/init.lua +++ b/examples/simpleDrawing/init.lua @@ -1,12 +1,10 @@ -local Concord = require("lib").init({ - useEvents = true -}) +local Concord = require("lib") + local Entity = Concord.entity local Component = Concord.component local System = Concord.system local Game = Concord.instance() -Concord.addInstance(Game) local Position = Component(function(e, x, y) e.x = x @@ -118,3 +116,12 @@ for _ = 1, 100 do Game:addEntity(e) end + + +function love.update(dt) + Game:emit("update", dt) +end + +function love.draw() + Game:emit("draw") +end diff --git a/lib/init.lua b/lib/init.lua index 61eb5e8..528dd91 100644 --- a/lib/init.lua +++ b/lib/init.lua @@ -2,8 +2,6 @@ local PATH = (...):gsub('%.init$', '') -local Type = require(PATH..".type") - local Concord = { _VERSION = "1.0", _DESCRIPTION = "A feature-complete ECS library", @@ -33,46 +31,10 @@ local Concord = { ]] } ---- Initializes the library with some optional settings --- @param settings Table of settings: { --- useEvents Flag to overwrite love.run and use events. Defaults to false --- } --- @return Concord -function Concord.init(settings) - Concord.entity = require(PATH..".entity") - Concord.component = require(PATH..".component") - Concord.system = require(PATH..".system") - Concord.instance = require(PATH..".instance") - Concord.assemblage = require(PATH..".assemblage") - - if settings and settings.useEvents then - Concord.instances = {} - - Concord.addInstance = function(instance) - if not Type.isInstance(instance) then - error("bad argument #1 to 'Concord.addInstance' (Instance expected, got "..type(instance)..")", 2) - end - - table.insert(Concord.instances, instance) - end - - Concord.removeInstance = function(instance) - if not Type.isInstance(instance) then - error("bad argument #1 to 'Concord.addInstance' (Instance expected, got "..type(instance)..")", 2) - end - - for i, _instance in ipairs(Concord.instances) do - if (instance == _instance) then - table.remove(Concord.instances, i) - break - end - end - end - - love.run = require(PATH..".run") - end - - return Concord -end +Concord.entity = require(PATH..".entity") +Concord.component = require(PATH..".component") +Concord.system = require(PATH..".system") +Concord.instance = require(PATH..".instance") +Concord.assemblage = require(PATH..".assemblage") return Concord diff --git a/lib/run.lua b/lib/run.lua deleted file mode 100644 index 5ad1ce7..0000000 --- a/lib/run.lua +++ /dev/null @@ -1,55 +0,0 @@ -local PATH = (...):gsub('%.[^%.]+$', '') - -local Concord = require(PATH) - -return function() - if love.math then - love.math.setRandomSeed(os.time()) - love.timer.step() - end - - for _, instance in ipairs(Concord.instances) do - instance:emit("load", arg) - end - - if love.timer then love.timer.step() end - - local dt = 0 - - return function() - if love.event then - love.event.pump() - for name, a, b, c, d, e, f in love.event.poll() do - for _, instance in ipairs(Concord.instances) do - instance:emit(name, a, b, c, d, e, f) - end - - if name == "quit" then - return a or 0 - end - end - end - - if love.timer then - love.timer.step() - dt = love.timer.getDelta() - end - - for _, instance in ipairs(Concord.instances) do - instance:emit("update", dt) - end - - if love.graphics and love.graphics.isActive() then - love.graphics.clear(love.graphics.getBackgroundColor()) - love.graphics.origin() - - for _, instance in ipairs(Concord.instances) do - instance:emit("draw") - end - - love.graphics.present() - end - - if love.timer then love.timer.sleep(0.001) end - end -end \ No newline at end of file diff --git a/lib/type.lua b/lib/type.lua index 80d14b0..ba52b02 100644 --- a/lib/type.lua +++ b/lib/type.lua @@ -1,3 +1,5 @@ +-- Type + local Type = {} function Type.isComponent(t)