by noelwelsh · 2y ago · 0 comments
Firstly, the overall quality is high and seeing this attention being paid to the project's organization is another good sign.
Documentation is not great. The Bevy book runs out of content very quickly. The "Cheat Book" has additional useful information: https://bevy-cheatbook.github.io/. With these plus the examples I've been able to figure out everything I need, but it's slow going.
I'm not 100% sold on ECS. It loses a lot of type safety and there doesn't seem to be any way to ensure cleanup of entities and their components.
As for the ECS, I've absolutely felt that: the flexibility of the polymorphism created by "just add another component!" can be both chaotic and freeing. Can you say more about what you're looking for with entity cleanup? I haven't heard that complaint before and want to make sure I understand what you mean.
What I think would be useful is essentially an arena allocator associated with a state. So any components and entities created when a state is active would be removed when that state is exited. Otherwise it seems that one must do manual GC, which is error-prone and will almost certainly lead to slow leaks over time.
[0]: https://docs.rs/bevy/latest/bevy/ecs/prelude/struct.State.ht...
I'll chew on solutions here: we might be able to get away with a nice well-documented convention in user-space code, or we may need to add a small extension to the internals to make this more robust.
I could see an efficient version of that being a nice thing to have built in, though. It’s definitely a very common thing.
I'm glad it pays off! Seeing them come together makes my day every time, even when I'm writing half of it.
For type safety, entities define mapping of types [components are types]. The whole point of ECS is effectively managing types and ensuring correctly typed data is operated on.
It's been ~2 years, but my main reason was wanting to write plain rust, vice using a DSL.
I was under the impression that bevy's Query system is type safe.
[1] https://zig.news/kristoff/struct-of-arrays-soa-in-zig-easy-i...
Granted, this is annoying and not a particularly great solution, but it would serve to give you a reminder for when you forget. I don't mean to diminish from your overall point either, it's a valid and good one I think.
I have this vague thought that Rust needs a different kind of type system.
Standard type systems[0] basically rely on references between values[1]. I seem to read about numerous Rust systems that don't use references for various reasons. Usually the borrow checker gets in the way or they want a different memory layout[2]. This makes me think that what's needed is a type system that allows constraints to be expressed between values without requiring a reference between them. I don't know what this type system looks like, though.
[0]: Rust's type system is a fairly standard type system from an academic POV. The novelty is that it's the first language with traction to use a linear / affine type system, but these are relatively well studied in academia.
[1]: The theory is not formulated this way, but the representation they compile into is a bunch of references.
[2]: ECS, as I understand it, is not a reaction to Rust's type system but an architecture driven by memory layout, parallelism, and breaking-out-of-OO-hierarchy concerns. However the net result is the same.
I should note that this is a problem with most game engines, not something unique to Bevy. For example, Unity is infamous for requiring arcane combinations of components to avoid silent failures.
I’m not sure what you mean by cleanup entities. Whenever i load a level i put it under a root entity and just despawn the root when im done.