3 ms·
> is a entity, and that entities have components, and the systems operate on entities (possibly based on their components) In an object-based design, objects a
by pizza234 4y ago
> is a entity, and that entities have components, and the systems operate on entities (possibly based on their components)
In an object-based design, objects are monoliths, with fields. You get a reference to player, and each Player instance has attributes. When you work on a player, you get the Player instances as a whole.
In an ECS design, you'd create a player entity; the main differences are that the Entity is just a reference, but most importantly, you access each field (called "component") separately.
The bulk of querying is performed on components, which, importantly are all global; entities are typically retrieved starting from a component instance they own. This makes the radical difference with a traditional object-based design; example:
- in OB, you have, say, players and enemies; when you draw, you'll cycle the players, and enemies, and draw them.
- in ECS instead, you'll query something like "drawable sprite" components, and draw them
It's a very interesting design, as it forces to reason more generically. It tends to get messy very easily though, since it's harder to think in terms of location of a system (in the project).
The best book for beginners to understand ECS is (IMO) Hands-on Rust (https://pragprog.com/titles/hwrust/hands-on-rust https://pragprog.com/titles/hwrust/hands-on-rust).
> So your saying everything is a entity
Not sure about other ECSs, but Bevy has also the concept of "resources", which are globals; they're monolithic, and there's only one isntance of each type.
- tcoff91 4y agoThis makes the cache locality excellent and is great for game performance.
- meheleventyone 4y agoWith the caveat that it’s actually quite a lot of work on top of this basic concept to actually make this happen.
- brobinson 4y agoIt also makes saving and loading state a breeze... you're basically just doing a database dump/restore. Coming across ECS was one of the few "holy shit what" moments of my time as a programmer.
- bregma 4y agoAh, so what we used to call a database in third normal form, before it was rediscovered and given a different name so it could generate revenue. Of course, the term database has also been redefined to refer to commercial RDBMS products, but it does make it hard to keep up with the underlying technology whenever a new set of salepeople come along looking to make commission.
- pizza234 4y agoSarcasm is not actually correct. An ECS is not an RDBMS, because in the latter is based on row-based storage, while the former is column-based. The storage part of ECSs could actually be considered a form of columnar db. For example, locking is at column level, so you can have as many mutable accesses to a single entity (like a row) as there are columns (in reality, it's more complicated, due to access via iterators, but that's the principle).