Earlier quoted context omitted.
In some ways ECS could be considered stateless, as the entity holds the game state as raw data, while the system operates on that data without holding a state of its own. How would you implement ECS, a system for tracking the state of game entities, in a stateless manner? Can you expand on that?
I'll try to explain what I mean. Suppose you want an in game character to change the displayed weapon in their inventory. Stateful way: your Inventory Manager component iterates through its private array of item entities to mark their model components as shown or hidden, then calls the dependency injected character's avatar component to update its animation state. Stateless way: you flip an integer in character's str…
EnTT: Gaming meets modern C++ 3.9 (ECS library and much more)
21–27 of 27 posts
Re: EnTT: Gaming meets modern C++ 3.9 (ECS library and much more)
#22Unpopular opinion, but I personally think ECS has no place in C/C++ game dev. Every supposed advantage is either curbed by limitations of the language (e.g. serialization) or can be implemented more logically in a stateless manner.
I can't even imagine game dev without ECS. There's more performant architectures but it's such a useful mental model for the type of rapid iteration games need that so many people are willing to put up with the drawbacks
Re: EnTT: Gaming meets modern C++ 3.9 (ECS library and much more)
#23Earlier quoted context omitted.
I'll try to explain what I mean. Suppose you want an in game character to change the displayed weapon in their inventory. Stateful way: your Inventory Manager component iterates through its private array of item entities to mark their model components as shown or hidden, then calls the dependency injected character's avatar component to update its animation state. Stateless way: you flip an integer in character's str…
The "stateful" way you present is not at all how you would approach that problem in an ECS. I think you misunderstand what ECS refers to.
Re: EnTT: Gaming meets modern C++ 3.9 (ECS library and much more)
#24Earlier quoted context omitted.
In some ways ECS could be considered stateless, as the entity holds the game state as raw data, while the system operates on that data without holding a state of its own. How would you implement ECS, a system for tracking the state of game entities, in a stateless manner? Can you expand on that?
I'll try to explain what I mean. Suppose you want an in game character to change the displayed weapon in their inventory. Stateful way: your Inventory Manager component iterates through its private array of item entities to mark their model components as shown or hidden, then calls the dependency injected character's avatar component to update its animation state. Stateless way: you flip an integer in character's str…
The latter is an anti-pattern, and you can do either with ECS.
With ECS nothing prevents you from just having the "physical" game state as the single source of truth, and having the render function for the player inventories look at it.
Re: EnTT: Gaming meets modern C++ 3.9 (ECS library and much more)
#25Earlier quoted context omitted.
I can't even imagine game dev without ECS. There's more performant architectures but it's such a useful mental model for the type of rapid iteration games need that so many people are willing to put up with the drawbacks
What are some of the more performant architectures?
https://gamedevelopment.tutsplus.com/articles/what-is-data-o...
Instead of treating each object as a collection of components, you can operate on bags of components
So say in you're modeling space invaders:
every frame:
for enemy in enemies
enemy.transform.y += 10
The CPU is hopping to a random memory address where your "transform" component is located before modifying it, over and over.Data oriented would be something like:
each frame:
for transform in transforms
if transform is enemy
transform.y += 10
if transform is player
transform += input
So you get cache locality as you're running through your transforms.Now imagine if instead of space invaders we're trying to model say blades of grass. Suddenly we go from a very cache unfriendly method to something that's cache friendly, branch prediction friendly, and easy to parallelize.
If you want to experiment with it Unity has some great examples under their new DOTS system
https://github.com/Unity-Technologies/EntityComponentSystemS...
APIs can make data oriented more ergonomic than my contrived example implies, but it's still not nearly as intuitive as ECS imo.
To me data oriented subsystems are fine, but not as a core concept for your game's architecture.
Re: EnTT: Gaming meets modern C++ 3.9 (ECS library and much more)
#26Earlier quoted context omitted.
>Or triggers to abstract away cascading updates. Triggers might be counter productive. Games usually have a fundamental concept of a game loop. Changes can be processed in the loop and side effects can be processed in the following iteration. Triggers would cause this processing to be unpredictable (or at least harder to predict). ECS provides a clean way to define the order in which systems are processed each loop.…
That's a great insight. I wonder if it'd be practical to defer them until after the causal operation was complete say translating all positions, then calling all of the triggers for the positions component. that'd keep everything in tight single purpose loops and preserve cache lines. fair enough that it'd probably make execution order harder to predict, but also in theory it would be in the realm of possibility to g…
The thing with the actual gameplay layer is your often processing mainly heterogeneous elements rather than homogeneous so all the worry and focus on cache is largely academic for most kinds of game.
Re: EnTT: Gaming meets modern C++ 3.9 (ECS library and much more)
#27Earlier quoted context omitted.
The "stateful" way you present is not at all how you would approach that problem in an ECS. I think you misunderstand what ECS refers to.
Maybe for ECS newbie, please say more on how you would approach this problem?
A physics system might change the position components while a decoupled rendering system might read that position components and the rendering details components to add draw commands.