ECS/Concord - resolved

Questions about the LÖVE API, installing LÖVE and other support related questions go here.
Forum rules
Before you make a thread asking for help, read this.
Post Reply
User avatar
togFox
Party member
Posts: 828
Joined: Sat Jan 30, 2021 9:46 am
Location: Brisbane, Oztralia

ECS/Concord - resolved

Post 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?
Last project:
https://togfox.itch.io/hwarang
A card game that brings sword fighting to life.
Current project:
Turn-based PBEM horse stable (racing) management sim: https://togfox.itch.io/horse-stable-manager
https://discord.gg/HeHgwE5nsZ
User avatar
Philbywhizz
Prole
Posts: 24
Joined: Mon May 13, 2013 3:17 am
Location: Brisbane, Australia
Contact:

Re: ECS/Concord - resolved

Post 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).
Philbywhizz.com - a blog too far...
User avatar
togFox
Party member
Posts: 828
Joined: Sat Jan 30, 2021 9:46 am
Location: Brisbane, Oztralia

Re: ECS/Concord - resolved

Post 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.
Last project:
https://togfox.itch.io/hwarang
A card game that brings sword fighting to life.
Current project:
Turn-based PBEM horse stable (racing) management sim: https://togfox.itch.io/horse-stable-manager
https://discord.gg/HeHgwE5nsZ
User avatar
yetneverdone
Party member
Posts: 448
Joined: Sat Sep 24, 2016 11:20 am
Contact:

Re: ECS/Concord - resolved

Post 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.
User avatar
togFox
Party member
Posts: 828
Joined: Sat Jan 30, 2021 9:46 am
Location: Brisbane, Oztralia

Re: ECS/Concord - resolved

Post 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?
Last project:
https://togfox.itch.io/hwarang
A card game that brings sword fighting to life.
Current project:
Turn-based PBEM horse stable (racing) management sim: https://togfox.itch.io/horse-stable-manager
https://discord.gg/HeHgwE5nsZ
User avatar
yetneverdone
Party member
Posts: 448
Joined: Sat Sep 24, 2016 11:20 am
Contact:

Re: ECS/Concord - resolved

Post 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.
Post Reply

Who is online

Users browsing this forum: Bing [Bot], Google [Bot] and 4 guests