Live data from Hacker News

Hands-On Rust: Effective Learning Through 2D Game Development and Play

pragprog.com

41–50 of 83 posts

Re: Hands-On Rust: Effective Learning Through 2D Game Development and Play

#41
post #20

Earlier 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.

Not sure I get what you mean. As I see it, ECS has more of a relational character. Feels more like data pipeline than operations/messages on objects. I think the mental model matters the most here and that depends on how you think of objects. But then any attempt of defining OO objectively seems to be futile, there are conflicting historical and contemporary notions plus a whole bunch of jargon on top, depending on who you're asking.

As an example you could say that Scheme is more object oriented than Java or vice versa and there would be valid, typically cultural reasons for each.

In terms of ECS what kind of happens is that, yes, you have a model of an entity and can think of that as an object, but that is a projection of a set of components or a relation. You're not really talking to the entity as a whole all that much anymore. And it's not just "it satisfies this set of interfaces" either. Your systems literally define data transformations, each on a focused set of related components that matter to a system, which seems kind of the inverse of hiding data behind object interfaces.

Re: Hands-On Rust: Effective Learning Through 2D Game Development and Play

#43

I can't help but be heavily skeptical of approaches to a (traditional) roguelike that use ECS. The idea is very entrenched in the rust gamedev community, but for a turn based tile based game there's extremely little benefit and a lot of added complexity. Bob Nystrom has an excellent talk on roguelike architecture [0] and rust as a language itself doesn't prevent any of these approaches. If anything, the existence of…

ECS is entrenched in rogue development in general, at least going by r/roguelikedev. It (or at least a component architecture, if not fully blown ECS) seems to be a good fit since these style of games tend to have a lot of composition (in items, effects, behaviour). Personally, while my experience is a bit limited, I quite like the ECS style. It just makes logical sense to me as a way of composing entities from diffe…

I’ve not yet used Godot. What is the Godot style like? And are there some documents about it and example code of it?

Re: Hands-On Rust: Effective Learning Through 2D Game Development and Play

#44

I can't help but be heavily skeptical of approaches to a (traditional) roguelike that use ECS. The idea is very entrenched in the rust gamedev community, but for a turn based tile based game there's extremely little benefit and a lot of added complexity. Bob Nystrom has an excellent talk on roguelike architecture [0] and rust as a language itself doesn't prevent any of these approaches. If anything, the existence of…

I think Jonathan Blow's take is right: > ECS only starts to make sense when you are big enough to have multiple teams, with one team building the engine and the other using the engine to make the game; or you are an engine company and your customer makes the game. If that is not your situation, do not rathole. https://twitter.com/Jonathan_Blow/status/1427358365357789199 Most of the arguments I've seen for ECS in Rust…

I really like Jonathan Blow, but I sometimes wish he would substantiate these kind of claims more so an outsider could learn what he is actually saying and why. I've watched a lengthy video of his on that topic but I didn't get out anything other than "you don't need it". No concrete implementation cases where it gets in the way or how a category of problems is better modeled in a different way.

Re: Hands-On Rust: Effective Learning Through 2D Game Development and Play

#45

It's a great book but I struggled with an additional overhead of ECS library usage. Don't know if it would have been better just roll out it's own simple logic for ECS , but then it would probably double the length of the book.

Page count was a real concern. I wanted to introduce Rust newcomers to easy concurrency, and keep the data-storage side of things manageable (storing a big list of dynamic objects with traits gets messy fast and leads to a lot more borrow-checker fighting). Using an ECS let me dodge the latter bullet, at the expense of a bit of complexity. (I made sure Flappy didn't need an ECS) Bevy didn't exist when I started writi…

This concerns me a bit.. when I've made (failed) attempts to learn Rust in the past the borrow checker was always the sticking point.

Re: Hands-On Rust: Effective Learning Through 2D Game Development and Play

#46

Earlier quoted context omitted.

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.

fair, but I had to lookup what ECS was so I though I'd save others a bit of googling.

Yeah explaining it is great. Just don't want people thinking it is only a Rust thing.

Re: Hands-On Rust: Effective Learning Through 2D Game Development and Play

#47

Earlier 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…

    struct Entity {
        components: Vec>,
    }
At this point you're effectively just hand-rolling your own ECS - and perhaps being in denial about it by touting the fact that the ECS is half implemented at best - rather than eschewing an ECS outright, IMO. If you want to skip the ECS, embrace the natural typing of the language - then you don't need to build something to query and filter components, and can instead just use the language's built-in constructs:

    struct Entity {
        pub position: Option,
        pub sprite:   Option,
        pub scripts:  Vec,
        //...
    }
    
    fn render_world(entities: &[Entity]) {
        for entity in entities {
            if let Entity { position: Some(xy), sprite: Some(sprite), .. } = entity {
                // ...
            }
        }
    }
Entity may eventually become a merge hazard on larger teams, and Entity enumeration without archetype filtering may eventually become a performance hazard if done too frequently and naively, but this kind of approach can work fine for many smaller projects.

Re: Hands-On Rust: Effective Learning Through 2D Game Development and Play

#48
post #41
post #20

Earlier quoted context omitted.

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.

Not sure I get what you mean. As I see it, ECS has more of a relational character. Feels more like data pipeline than operations/messages on objects. I think the mental model matters the most here and that depends on how you think of objects. But then any attempt of defining OO objectively seems to be futile, there are conflicting historical and contemporary notions plus a whole bunch of jargon on top, depending on w…

That is when data oriented programming gets into the equation.

Classical ECS as it originally appeared on the literature is coding against interfaces, COM or Objective-C protocols style.

So yeah, one composes those interfaces together, there is no class inheritance, only composition, delegation, and a system is composed from a jungle of such components.

It is also a reason why DirectX is COM based, instead of basic Win32 calls.

Re: Hands-On Rust: Effective Learning Through 2D Game Development and Play

#49

I can't help but be heavily skeptical of approaches to a (traditional) roguelike that use ECS. The idea is very entrenched in the rust gamedev community, but for a turn based tile based game there's extremely little benefit and a lot of added complexity. Bob Nystrom has an excellent talk on roguelike architecture [0] and rust as a language itself doesn't prevent any of these approaches. If anything, the existence of…

Sorry, what is ESC?

Re: Hands-On Rust: Effective Learning Through 2D Game Development and Play

#50
post #45

Earlier quoted context omitted.

Page count was a real concern. I wanted to introduce Rust newcomers to easy concurrency, and keep the data-storage side of things manageable (storing a big list of dynamic objects with traits gets messy fast and leads to a lot more borrow-checker fighting). Using an ECS let me dodge the latter bullet, at the expense of a bit of complexity. (I made sure Flappy didn't need an ECS) Bevy didn't exist when I started writi…

This concerns me a bit.. when I've made (failed) attempts to learn Rust in the past the borrow checker was always the sticking point.

It needs a mindset change. The thing is trying to help you. It points out issues that you didn’t think about. It’s naturally difficult to think about things you’ve never had to think about before. It also turns out that architecting software in certain ways (like ECS) makes it easier to think less about borrowing.
Post reply on HN