Page 1 of 1

ECS/Concord - resolved

Posted: Tue Nov 30, 2021 9:59 pm
by togFox
Edit: resolved - my code is one valid way. Leaving here for others.

Hi all - any ECS/Concord users here?
I'm new to ECS and trying to rewire my brain. Just checking if this example is the right way to DRAW entities:

Code: Select all

-- 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?

Re: ECS/Concord - resolved

Posted: Sun Dec 05, 2021 5:24 am
by Philbywhizz
I'm also learning ECS using Concord so take this info with a grain of salt.

Rather than checking e.isSquare ~= nil, I think it would be better to use the API instead

Code: Select all

if e:has("isSquare") then
  -- draw square stuff
end
It makes the code easier to read (well for me it would).

Re: ECS/Concord - resolved

Posted: Sun Dec 05, 2021 8:03 am
by togFox
Yes - I discovered :has. Thanks.

I"m loving Concord after using it for less than a week. I want to do more with it when I find a project suited for it.

Re: ECS/Concord - resolved

Posted: Sun Dec 05, 2021 9:04 am
by yetneverdone
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 ofcourse.

Re: ECS/Concord - resolved

Posted: Sun Dec 05, 2021 9:42 am
by togFox
> 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.

Other differences? Performance?

Re: ECS/Concord - resolved

Posted: Mon Dec 06, 2021 6:56 am
by yetneverdone
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.