mirror of
https://github.com/Keyslam-Group/Concord.git
synced 2025-12-06 21:24:55 -05:00
Fixed the love.run loop and moved it into its own file. Fixed examples
This commit is contained in:
parent
afe6573b18
commit
42213fcdf9
8 changed files with 208 additions and 3 deletions
4
.gitignore
vendored
4
.gitignore
vendored
|
|
@ -37,6 +37,4 @@ luac.out
|
||||||
*.app
|
*.app
|
||||||
*.i*86
|
*.i*86
|
||||||
*.x86_64
|
*.x86_64
|
||||||
*.hex
|
*.hex
|
||||||
|
|
||||||
*.lua
|
|
||||||
55
concord/run.lua
Normal file
55
concord/run.lua
Normal file
|
|
@ -0,0 +1,55 @@
|
||||||
|
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
|
||||||
10
conf.lua
Normal file
10
conf.lua
Normal file
|
|
@ -0,0 +1,10 @@
|
||||||
|
function love.conf(t)
|
||||||
|
t.identity = "Concord Example"
|
||||||
|
t.version = "11.0"
|
||||||
|
t.console = true
|
||||||
|
|
||||||
|
t.window.vsync = false
|
||||||
|
t.window.width = 720
|
||||||
|
t.window.height = 720
|
||||||
|
end
|
||||||
|
|
||||||
10
examples/baseLayout/main.lua
Normal file
10
examples/baseLayout/main.lua
Normal file
|
|
@ -0,0 +1,10 @@
|
||||||
|
local PATH = (...):gsub('%.[^%.]+$', '')
|
||||||
|
|
||||||
|
local Concord = require("concord").init({
|
||||||
|
useEvents = true
|
||||||
|
})
|
||||||
|
|
||||||
|
local C = require(PATH..".src.components")
|
||||||
|
local S = require(PATH..".src.systems")
|
||||||
|
|
||||||
|
local a =5
|
||||||
5
examples/baseLayout/src/components/init.lua
Normal file
5
examples/baseLayout/src/components/init.lua
Normal file
|
|
@ -0,0 +1,5 @@
|
||||||
|
local PATH = (...):gsub('%.init$', '')
|
||||||
|
|
||||||
|
return {
|
||||||
|
|
||||||
|
}
|
||||||
5
examples/baseLayout/src/systems/init.lua
Normal file
5
examples/baseLayout/src/systems/init.lua
Normal file
|
|
@ -0,0 +1,5 @@
|
||||||
|
local PATH = (...):gsub('%.init$', '')
|
||||||
|
|
||||||
|
return {
|
||||||
|
|
||||||
|
}
|
||||||
118
examples/simpleDrawing/init.lua
Normal file
118
examples/simpleDrawing/init.lua
Normal file
|
|
@ -0,0 +1,118 @@
|
||||||
|
local Concord = require("concord").init({
|
||||||
|
useEvents = true
|
||||||
|
})
|
||||||
|
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
|
||||||
|
e.y = y
|
||||||
|
end)
|
||||||
|
|
||||||
|
local Rectangle = Component(function(e, w, h)
|
||||||
|
e.w = w
|
||||||
|
e.h = h
|
||||||
|
end)
|
||||||
|
|
||||||
|
local Circle = Component(function(e, r)
|
||||||
|
e.r = r
|
||||||
|
end)
|
||||||
|
|
||||||
|
local Color = Component(function(e, r, g, b, a)
|
||||||
|
e.r = r
|
||||||
|
e.g = g
|
||||||
|
e.b = b
|
||||||
|
e.a = a
|
||||||
|
end)
|
||||||
|
|
||||||
|
local RectangleRenderer = System({Position, Rectangle})
|
||||||
|
function RectangleRenderer:draw()
|
||||||
|
local e
|
||||||
|
for i = 1, self.pool.size do
|
||||||
|
e = self.pool:get(i)
|
||||||
|
|
||||||
|
local position = e:get(Position)
|
||||||
|
local rectangle = e:get(Rectangle)
|
||||||
|
local color = e:get(Color)
|
||||||
|
|
||||||
|
love.graphics.setColor(255, 255, 255)
|
||||||
|
if color then
|
||||||
|
love.graphics.setColor(color.r, color.g, color.b, color.a)
|
||||||
|
end
|
||||||
|
|
||||||
|
love.graphics.rectangle("fill", position.x, position.y, rectangle.w, rectangle.h)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
local CircleRenderer = System({Position, Circle})
|
||||||
|
function CircleRenderer:draw()
|
||||||
|
local e
|
||||||
|
for i = 1, self.pool.size do
|
||||||
|
e = self.pool:get(i)
|
||||||
|
|
||||||
|
local position = e:get(Position)
|
||||||
|
local circle = e:get(Circle)
|
||||||
|
local color = e:get(Color)
|
||||||
|
|
||||||
|
love.graphics.setColor(255, 255, 255)
|
||||||
|
if color then
|
||||||
|
love.graphics.setColor(color.r, color.g, color.b, color.a)
|
||||||
|
end
|
||||||
|
|
||||||
|
love.graphics.circle("fill", position.x, position.y, circle.r)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
local RandomRemover = System({})
|
||||||
|
|
||||||
|
function RandomRemover:init()
|
||||||
|
self.time = 0
|
||||||
|
end
|
||||||
|
|
||||||
|
function RandomRemover:update(dt)
|
||||||
|
self.time = self.time + dt
|
||||||
|
|
||||||
|
if self.time >= 0.25 then
|
||||||
|
self.time = 0
|
||||||
|
|
||||||
|
if self.pool.size > 0 then
|
||||||
|
local i = love.math.random(1, self.pool.size)
|
||||||
|
|
||||||
|
self.pool:get(i):destroy()
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
love.window.setTitle(love.timer.getFPS())
|
||||||
|
end
|
||||||
|
|
||||||
|
Game:addSystem(RandomRemover(), "update")
|
||||||
|
Game:addSystem(RectangleRenderer(), "draw")
|
||||||
|
Game:addSystem(CircleRenderer(), "draw")
|
||||||
|
|
||||||
|
for i = 1, 100 do
|
||||||
|
local e = Entity()
|
||||||
|
e:give(Position, love.math.random(0, 700), love.math.random(0, 700))
|
||||||
|
e:give(Rectangle, love.math.random(5, 20), love.math.random(5, 20))
|
||||||
|
|
||||||
|
if love.math.random(0, 1) == 0 then
|
||||||
|
e:give(Color, love.math.random(), love.math.random(), love.math.random(), 1)
|
||||||
|
end
|
||||||
|
|
||||||
|
Game:addEntity(e)
|
||||||
|
end
|
||||||
|
|
||||||
|
for i = 1, 100 do
|
||||||
|
local e = Entity()
|
||||||
|
e:give(Position, love.math.random(0, 700), love.math.random(0, 700))
|
||||||
|
e:give(Circle, love.math.random(5, 20))
|
||||||
|
|
||||||
|
if love.math.random(0, 1) == 0 then
|
||||||
|
e:give(Color, love.math.random(), love.math.random(), love.math.random(), 1)
|
||||||
|
end
|
||||||
|
|
||||||
|
Game:addEntity(e)
|
||||||
|
end
|
||||||
4
main.lua
Normal file
4
main.lua
Normal file
|
|
@ -0,0 +1,4 @@
|
||||||
|
local file = "examples.simpleDrawing"
|
||||||
|
-- local file = "examples.baseLayout.main"
|
||||||
|
|
||||||
|
require(file)
|
||||||
Loading…
Add table
Add a link
Reference in a new issue