All about Entity Component System

OOP + composition can accomplish anything ECS can.

You can always do the same things in another way, but the selling point is how easy it is with ECS to allow your uniform code handle non uniform data that you will not see with just compositions. As soon as you create structures to search for arbitrary sets of components, you have already made an ECS, the tricky part is making a fast one.

it runs in a loop

It is true that things run in a loop, as most things does. This is how rendering, physics, etc are all handled. It is a powerful pattern to reconcile each frame so that it is not fragile to one-off errors that cascade onto other parts of your game. Interrupt-driven logic flows are often very susceptible to these things.

2 Likes

Iā€™ll stick to event-driven stuff thanks. like I said below it works if you, wellā€¦ do it right. lol.

idk Iā€™ve never had a problem with this using any other method. Functional OR OOP with composition. if you know how to use it properly itā€™s not really a problem.

Iā€™m going to try to provide a pseudo-example for ya, since I also questioned this method of design at first as well. Hopefully this can clear things up a bit

As you stated, a magazine component would likely be pointless in your scenario as is, that being just guns.
Where benefits start arising is if you have anything more.

In standard OOP design, youā€™d have a gun, melee, and grenade classes.

That can result in a lot of, even if minor, overlapping functions/code/etc., and in the end running slower and/or being less organized and, in turn, harder to debug

With ECS designs, you could just have some components that combine to make the 3 aforementioned classes:
HasLimitedUses: Can be used to define how many uses an item has, reload time, use rate, capacity, and if you have some system like Apocalypse Rising games where ammo type matters per tool, this can take care of that too.
HasAttack: Takes care of all throwables and ranged projectiles alike. You can define projectile velocity, accuracy, range, etc. here
You can also use the above attributes for melee as well, its as simple as tuning projectile speed down, projectile size up, and then the rest to your hearts desire.
Explodes: (IDK what to name this, trying to speedrun this reply) Defines fuse time/impact, explosion range, dmg, etc.

Now, on top of what the OOP option would have given, you can have pretty much any thrown item without making a new class, guns with explosive rounds without having to bog down the base gun class or make a new one- this also applies to explosive melee if youā€™re into that- and anything else you can think of with that simple collection of 3 components.

In the end, this is little more functional than the OOP example, difference being it lets you expand more, easier, and with less need for optimizations.

If you have any more specific questions I can try to answer them, but I myself am new to using these (I want to make a factorio esque game, so performance and expandability is of HIGH priority)

2 Likes

Iā€™ll stick to event-driven stuff thanks. like I said below it works if you, wellā€¦ do it right. lol.

ECS can and should be event driven, not sure where you got the idea that it cant or shouldnā€™t.
OOP, Procedural, and ECS are all Programming Paradigms, where as events and the like are Design Patterns, none are exclusive to any other (Yes, you can use OOP, ECS, and Procedural simultaneously, its just a matter of when and where these things are appropriate.)

idk Iā€™ve never had a problem with this using any other method. Functional OR OOP with composition. if you know how to use it properly itā€™s not really a problem.

Yeah, itā€™s mostly down to eeking out every bit of performance and looking more clean. Any paradigm is performant enough in most cases. Its only ā€œnecessaryā€ to use ECS in cases where you have WAY more than usual going on, and want to still remain running that smooth 60fps

On the topic of which one looks better/has greater readability, thatā€™s up for debate, although ECS does have the advantage of not requiring you to jump around any more than 1 time (From object to component), where as OOP can become a hellscape of inheritance (This is admittedly just down to a skill issue of whoever makes said hellscape)

In the end itā€™s mostly just preference. There are still people out there who prefer Procedural Programming over any other paradigm.

2 Likes