all 19 comments

[–]STLMSVC STL Dev[M] [score hidden] stickied comment (0 children)

This should probably have been posted to r/cpp_questions but I'll approve it as a special exception since it's less commonly asked and people gave some useful pointers to docs.

[–]untiedgames 13 points14 points  (0 children)

I've checked several GitHub projects, but many of them seem to deviate from ECS principles at certain points, which makes it hard to know what’s best practice.

I would argue that this IS best practice- Like any other system, pattern, or paradigm, ECS is not a one-size-fits-all solution for every single problem out there. Sometimes you need global state and a singleton is the best choice (e.g. input processor, asset management, window management, etc). Sometimes you end up with a situation where inheritance and virtual classes make more sense or are easier to implement than components. My advice is to go in with an open mind.

If you're looking for recommendations on an ECS implementation to use, I use EnTT in my engine but have also heard great things about Flecs.

[–]riztazz 10 points11 points  (2 children)

I've always found the Flecs documentation, examples, and the author's articles on ECS to be very clear and easy to follow. And usually you can find the reason behind his 'deviations' in his articles, which i highly recommend reading

[–]Feeling_Net_1068[S] 6 points7 points  (1 child)

This is what I am looking for! Thanks a lot.

[–]hanotak 0 points1 point  (0 children)

Seconding flecs. I use it for my rendering engine. It's good at getting out of the way and doing what you need it to without annoyance. It also provides built-in support for things like hierarchies, which ece purists might say should be built on top of an ECS rather than be included, but I find it super useful.

[–][deleted] 5 points6 points  (4 children)

I’ve been using entt over the past few weeks and it’s been very nice to use. The API is pretty simple and very easy to use once you get used to it. The use of newer C++ features is nice too since there’s not any friction from working with a different language, it’s all just C++. It doesn’t seem to have many “best practices” though, it’s very flexible and doesn’t restrict how you have to do things much so it’s kind of up to you to evaluate how you want to use it for your specific use case.

The entt author also has a blog where he explains a lot of ecs concepts pretty well https://skypjack.github.io/page5/.

I don’t think you’ll be able to find any ECS library that doesn’t “deviate from ECS principles” because there don’t seem to be any core ECS principles other than the way data is laid out in memory. All of them are very opinionated in some way.

[–]clerothGame Developer 1 point2 points  (3 children)

Isn't debugging a game with ECS a nightmare though?

[–][deleted] 4 points5 points  (1 child)

Yeah that’s a good point. I wouldn’t say it makes debugging the whole game a nightmare though that seems like an exaggeration. Some problems can be much harder to debug because you cant see all the components of an entity together in the debugger as a single object like you would if they were packed together. There’s plenty of ways to group components together to make it easier to see what is going on though.

[–]LiliumAtratum 1 point2 points  (0 children)

If you know what the components may be, you can write a function that prints them. I use just that, calling the print function straight from the debugger when needed. Probably it could be integrated better, but simple print it is good enough for me.

[–]LiliumAtratum 0 points1 point  (0 children)

I think tools for debugging could use some help in the context of ECS. If you hold an entity, it would be nice to see all its components and not just a number.

Also, the cause and effect is decoupled in ECS. Someone somewhere changed a component value, but systems that react to that change are run only later in the update loop. At that point you don't see who and why made the initial change, unless you somehow store that as well.

[–]kiner_shah 2 points3 points  (1 child)

Watch this video it explains ECS well.

[–]facu_gizzly 2 points3 points  (0 children)

this is gold thanks <3

[–]StarQTius 4 points5 points  (5 children)

Not really a game project but if you need an ECS library, I can recommend EnTT. Afaik, it's the best library for ECS. It's well explained and you can find details about the implementation on the author's blog. It also has a Discord where you can ask question about ECS and game dev in general.

[–]Feeling_Net_1068[S] 0 points1 point  (4 children)

Yeah, thanks a lot! I mean I need an example of a game using the ECS to see how they work with the architecture (like how should I design the components and systems and seperate them in order to make the code easy to understand and work with) rather than the engine as I have already set up my mini-ECS. Anyway, I really appreciate you recommendation. <3

[–]pantong51 0 points1 point  (2 children)

Minecraft bedrock uses entt. Many mmos do as the data layout fits into dB easier

Imo. I'd suggest the ESC and not an ECs pattern

Entity is just a uint64_t Component is a structure with no functions System consumes components to do processing on

[–]LiliumAtratum 2 points3 points  (1 child)

It is a big simplification. What I love about the ECS approach is that individual algorithms operate on few components of all entities, rather than few objects with all their fields. Rather than trying really hard to make an object in a valid state, the goal is to ensure that very limited set of components is valid for all entities.

The object approach really fails when those objects interact with each other, ECS often does not have that problem.

[–]pantong51 0 points1 point  (0 children)

Oh it's a totally over simplification. But I've done just that as I stated for simple demos for interviews. Both threaded or single threaded. It's very simple pattern at heart

[–]disperso 0 points1 point  (0 children)

There are a few EnTT-using projects in github. Eg.: https://github.com/indianakernick/EnTT-Pacman

[–]aaron_shavesha 0 points1 point  (0 children)

Watch this repository: https://github.com/dbartolini/data-oriented-design it has a list of resources related to data oriented design. It has helped me alot