-- define components
Concord.component("isSquare")
Concord.component("isCircle")
-- define Systems
systemDraw = Concord.system({
pool = {"drawable"}
})
function systemDraw:draw()
for _, e in ipairs(self.pool) do
if e.isSquare ~= nil then
-- use love.graphics.rectangle
end
if e.isCircle ~= nil then
-- use love.graphics.circle
end
end
end
-- Add the Systems
WORLD:addSystems(systemDraw)
-- add entities
shape1 = Concord.entity(WORLD)
:give("isSquare")
:give("drawable")
shape2 = Concord.entity(WORLD)
:give("isCircle")
:give("drawable")
Lots of code but really - is my systemDraw the right way to manage the drawing of many different types of entities?
There are different ways you can do this in Concord with ECS:
1. You can use the code you already have where a single pool will contain all the drawables
2. You can separate each type of drawables into their own pool like pool_circle, pool_rect, and so on (This is what i use in my project).
> There are advantages and disadvantages of course.
I haven't yet advanced my thinking to what the difference are. The obvious one is a large DRAW system vs lots of smaller ones but the number of lines would be almost the same. I guess many DRAW systems allows you to split across modules/files if that's your thing.
The problem with the latter approach is you cant mix the order of different pools. Lets say you want to draw a rect, then a circle above that, then another rect above that circle. The former approach easily handles that since youre iterating through all drawables linearly but the latter approach does not. To solve this, I have a layering system that handles grouping of different pools to draw them in order as desired.
On the other hand, if all your drawables with sprites are in a separate pool of its own, it would work better if youre using atlas to save a lot of drawcalls and texture switches.