5 ms·
ECS is one of those things you "get religion" about, especially as a game developer. Like, "Oh, I've been fighting the class hierarchy and overcomplicating my c
by bitwize 8y ago
ECS is one of those things you "get religion" about, especially as a game developer. Like, "Oh, I've been fighting the class hierarchy and overcomplicating my code for so long... it doesn't have to be this way!" I've written about this as well, whilst developing my own game: https://nullawesome.tumblr.com/post/146127692039/entities-and-components-in-nullawesome https://nullawesome.tumblr.com/post/146127692039/entities-an...
- reificator 8y ago> ECS is one of those things you "get religion" about, especially as a game developer. That's what worries me to be honest. I'm right there with you that ECS is just the right way, but whenever I can't come up with good arguments against my choices I feel like I'm blinded by faith. My main argument for why I wouldn't use ECS in a greenfield game project is that a lot of existing tools don't play nice with it. That's about it.
- skypjack 8y agoTo be honest I use composition over inheritance because it fits better with my mental patterns. I've nothing against OOP in general and I'm pretty sure we can have code with good performance also without a component-based model. The fact is just that I'm not as good at designing things with OOP in mind as I'm when I design them with components in mind. But this is me, not a golden rule.
- skocznymroczny 8y agoI like a good balance of composition and inheritance, but I feel like the current hype for ECS is a bit overwhelming. I noticed many beginners are confused and try to shoehorn ECS into EVERY aspect of their game project, as in "OOP/inheritance is lava" way. Also I see people obsessing about performance of ECS vs OOP, when it's not relevant for most of the indie game projects that have a much smaller scope than a high-end AAA game projcet.
- skypjack 8y agoI agree that component-based models should not be taken as all-about-performance solutions. I'm using ECS as the core of some software of mine but of course OOP is still present around to treat other aspects and problems that don't fit well with ECS in general. I mean, such an architectural patter solves a specific problem in an elegant way, but it doesn't solve everything in let's say a game. Try to put everything into components is a common mistake that leads to poor code sometimes. However, for those part where it fits, I like to use this architectural pattern because it's closer to the way I think and thus easier to work with for me.
- HelloNurse 8y agoBut deep down, it is a performance principle: luxuries like pointers, virtual functions etc. are suitable for complicated but rarely executed code, while important loops should access arrays of components (or something very close) without unnecessary cache misses. If memory accesses were as cheap as 40 years ago, inheritance vs. composition would be a lofty debate about elegance and architecture and programming language semantics and taste; now it has become a much more practical and detailed tradeoff between difficult design and bad performance.
- reificator 8y ago> if memory accesses were as cheap as 40 years ago To clarify for readers not familiar with the motivations here: Memory access is in fact cheaper than it used to be, as you might expect. The concern is that it did not get cheaper nearly as fast as processors got faster, meaning the relative cost of accessing memory became much higher when you could be doing more calculations in that time instead. Specially what allows for better performance is accessing memory in a pattern that can be predicted and prefetched. Linear access is best, because looking up a single byte in memory has approximately the same overhead as looking up a contiguous chunk of bytes. Think Wiley E. Coyote picking up train tracks from behind himself and putting them down in front. If your memory access looks like that then you are less likely to suffer from memory access bottlenecks.
- reificator 8y ago> I've nothing against OOP in general and I'm pretty sure we can have code with good performance also without a component-based model Without a component-based model, sure. But with OOP specifically (which usually just means object hierarchies) you're chasing a lot of pointers and usually (though not always) doing a lot of null checks and other branching inside loops.
- jayd16 8y agoFunctionality composition is tangential to ECS. You can choose composition over inheritance in all types of architectures.
- bitwize 8y agoComposition is only one of the reasons why it makes sense to consider ECS. Structuring your game state as pure data makes it easier to serialize, to double-buffer, and to arrange in memory how you see fit. There are non-ECS ways of doing this but ECS is the easiest way I've found to write general code that can operate the same over many different kinds of game objects.
- w0utert 8y agoI went through a very similar thing writing my own toy/hobby game-project. It started out as a classical straightforward OOP design, but once I started adding extra stuff to it like animation, a scripting engine, etc. I really started to feel a lot of inertia from the design and the awkward forced hierarchies I had built. Over time I've been incrementally flattening the design to end up with the kind of hybrid/half-way design mentioned in the article, which borrows some things from ECS, but still has distinct game objects implemented as classes. I'm not fully on-board with the (between-the-lines) assessment in the article that this is somehow inferior to, or should just be a stepping stone towards a full-blown ECS though. At least not for a simple game where performance is not really a concern. My view is that a hybrid approach can actually be better than a 'real' ECS for those kinds of cases, taking the best of both worlds. In my case I don't use any inheritance, only composition, I don't have to fight OOP, but I can still write very clear and concise code to access and manipulate properties of my game objects. It may not be cache-efficient and whatnot, but that really is no concern for my simple game at all, having at most 20 to 40 lightweight entities active at the same time. Physics updates (which could drag down performance if too inefficient) are treated like in a traditional ECS, simply advancing the full physics sim for all entities completely separate from the game objects. Looking forward to the next article!
- skypjack 8y agoGood point. I put it in wrong wording probably. I didn't want to say that it's a shitty thing, just let the reader know that it's not a great improvement in terms of performance. However, I point out also how the halfway approach already is worth it and brings in some benefits, the same you nicely described in your comments. ;-)