Lately I've been very interested in ECS, and while I've tried my best to learn it, I'm having a hard time understanding it.
Thus I was wondering if you guys could look trough the code, and point me in the right direction both design and performance wise.
I have a few snippets for some components and systems here. How they work internally can be seen in the .love.
Position component:
Code: Select all
local Component = require "modules.component"
--[[
int x*
int y*
]]
Component(
"Position",
function(entity, x, y)
-- Constructor
entity.x = x or 0
entity.y = y or 0
end,
function(entity)
-- Destructor
entity.x = nil
entity.y = nil
end
)
Code: Select all
local Component = require "modules.component"
--[[
int w*
int h*
]]
Component(
"Size",
function(entity, w, h)
-- Constructor
entity.w = w or 0
entity.h = h or 0
end,
function(entity)
-- Destructor
entity.w = nil
entity.h = nil
end
)
Code: Select all
local System = require "modules.system"
--[[
Draws a rectangle
Position
Size
]]
System(
"Rectangle",
function(entity, dt)
-- Update
end,
function(entity)
-- Draw
if entity.hasComponents({"Position", "Size"}) then
love.graphics.rectangle("fill", entity.x, entity.y, entity.w, entity.h)
end
end
)