ECS is a pattern to manage composable logic and shared behavior. very very loosely like splitting logic in to class level and object level.
Hands-On Rust: Effective Learning Through 2D Game Development and Play
21–30 of 83 posts
Re: Hands-On Rust: Effective Learning Through 2D Game Development and Play
#22Earlier quoted context omitted.
ECS is for me the natural way to design games. I wouldn't even know to design them any other way. I started game dev with love2d which is a pretty minimalist framework. When I participated in a game jam, I needed a very flexible system that would allow for quick prototyping and would handle many different entities. I ended up writing something which I later realized would be an ECS system. It worked great and I would…
ECS and OOP are sides of the same coin, although apparently it is only visible to those that read SIGPLAN papers. "Component Software: Beyond Object-Oriented Programming" https://www.amazon.com/-/en/Clemens-Szyperski/dp/0201745720 One of the first publications on the matter.
Re: Hands-On Rust: Effective Learning Through 2D Game Development and Play
#23is there a promo code for Latin-american countries?
Re: Hands-On Rust: Effective Learning Through 2D Game Development and Play
#24However, being completely new to Rust I find that the author doesn't spend enough time discussing the language, it's syntax and nuances. It is hard to talk both about rust alongside video game design techniques.
I put it down after reading 1/4th of it. I'm planning to spend some time on a book that focuses on the language first and then get back to it ;)
Re: Hands-On Rust: Effective Learning Through 2D Game Development and Play
#25Earlier quoted context omitted.
(Author here) Bob makes some good points, so I'd like to share my $0.02 on the ECS debate. The posters below who point out that a lot of Rust setups use ECS to avoid mutability issues are correct (although internally Bevy is an ECS that maps its own node graph) - and that certainly helps - but it's not the whole picture. I think it's important to separate the EC from the S in ECS. Entity-Component storage is basicall…
> Composition over inheritance (especially in Rust, which doesn't really have inheritance - although you can fake it with traits) This does not require ECS, you can happily have something like struct Entity { components: Vec >, } (Nor do I think this is a good way of setting up a traditional roguelike) > Replication; if you want to replicate state across multiple nodes, a good ECS can really help you I'm not sure wha…
You absolutely can have an entity structure containing a vector of dynamic component types. It can get quite messy when you start having a lot of component types. When your entity runs, it has to look at the data in its components. That either means that component is a big enum (no need for dyn and Box there), or component is a trait and you're going to be doing a bunch of dynamic casting to find out what components an entity has when it ticks. Either can work (as can having an Option for each component type, which replaces the dynamic cast with an `if let`). Ultimately, there's not a lot of difference between an entity iterating its components and calling methods on components (or branching based on the components it has) and running a query to retrieve the components you want and acting on them. It's not that different from a NoSQL database (everything in a node graph) vs. a relational database (tables keyed to an identifier) - both work, each has their strengths and weaknesses. (I also really didn't want to try and teach dynamic casting early in the book!)
Some specific points from your reply:
By "replication", I meant network replication. You can get the same benefits by tracking changes within an entity/component, but it's really handy when a single storage system does that for you. Not that useful to a traditional single-player roguelike, but a nice tool to have.
> Yes, but that's not what a turn based tile based game is. Generally you want to iterate over things in order - gravity (if a roguelike has such a thing) gets applied on the player's turn, and only for the player. If you step over a ledge you don't wait for the "gravity" system to kick in and apply gravity to all entities, it is resolved in the same instant for only the entity that has just moved
That very much depends upon what you're creating. (Nox Futura is a Dwarf Fortress like). In the gravity example, it was solved by remembering to exclude the Flying component from the gravity query. The roguelike example in Hands-on Rust actually runs the player and monsters in different phases, but re-uses a lot of systems in the process. Matching on the turn state and executing systems isn't all that different to matching on the turn state and running tick functions on the entities included in that turn - especially if you have an energy cost/initiative type system breaking out the moves (the tutorial I created does this). Both Hands-on Rust and the tutorial effectively use message-passing for chaining events together.
> if anything I could see issues arising from the fact that you basically have dynamic typing when it comes to what behaviors an entity has
You have the exact same problem with a dynamic vector of components.
> If you're not doing query-based ECS with systems there's also no particular reason to not use vecs of components within entity structs.
It mostly boils down to preference. I find Query easier to work with than having each entity iterate a component list, query the type of each component and then act accordingly.
> As a final note, in the excerpt about items you have this justification for not using an enum instead of components:
Again, we're solving the same problem in similar ways. There's really not a whole lot of difference between matching the enum and iterating MultiEffect and querying if an entity has components. Either way, you have code that says "oh, it explodes" and makes a boom.
In other words, we both prefer different ways to accomplish exactly the same thing. Neither of us is right or wrong, there's plenty of ways to skin a cat. Hands-on Rust is as much about teaching Rust and gamedev in general as it is roguelikes in particular; if you want a big, working roguelike - the tutorial ( https://bfnightly.bracketproductions.com/ ) does that.
Re: Hands-On Rust: Effective Learning Through 2D Game Development and Play
#26The book sounds awesome to get your hands dirty with Rust :) is there a promo code for Latin-american countries?
Re: Hands-On Rust: Effective Learning Through 2D Game Development and Play
#27Re: Hands-On Rust: Effective Learning Through 2D Game Development and Play
#28The book sounds awesome to get your hands dirty with Rust :) is there a promo code for Latin-american countries?
I'm not sure what promos are active right now (I just got back from vacation). It will be included in the November Thanksgiving sales. You could also email support@pragprog.com - they would be able to help.
Re: Hands-On Rust: Effective Learning Through 2D Game Development and Play
#29I don't think most non-rust programmers know what ECS is. ECS is a pattern to manage composable logic and shared behavior. very very loosely like splitting logic in to class level and object level.
Re: Hands-On Rust: Effective Learning Through 2D Game Development and Play
#30I don't think most non-rust programmers know what ECS is. ECS is a pattern to manage composable logic and shared behavior. very very loosely like splitting logic in to class level and object level.
Lots of game developers know what ECS is. It existed before rust gamedev became a major thing. Unity even has an (experimental to be clear) ECS engine you can use to replace traditional monobehavior style objects.