5 ms·
Can't wait to use `player!.0.<>->move^([]->^t, Box<&loc, g*>)` to move player characters!
by Angius 6y ago
Can't wait to use `player!.0.<>->move^([]->^t, Box<&loc, g*>)` to move player characters!
- _cart 6y agoWe've heavily invested in legibility and ergonomics in Bevy. I'd argue that our ECS is top tier in ergonomics and legibility across all engines / languages. Here is a gist of a fully self-contained Bevy App for player movement. Feel free to compare that to _any_ other engine / framework: https://gist.github.com/cart/96b1d39cd04274da566dbf28bf87c2a8 https://gist.github.com/cart/96b1d39cd04274da566dbf28bf87c2a...
- linkdd 6y agoI'm a Rust newbie, could you explain how a function got a method "system"? Is there some macro at work here?
- _cart 6y agoFunctions are "types" just like everything else in rust. And you can implement traits (which can add methods) on any type. So its just "normal" rust code to add a function call to a function of a certain type. This enables us to (statically) extract information from the type signature of the function and use it to populate the relevant values using the ECS. We also use this type information to automatically (and safely) parallelize system execution based on what ECS resources are accessed (and if they are mutated). We do (internally) use macros to implement our IntoSystem trait for all relevant function types, but there are no macros in user-facing code.
- linkdd 6y agoI see, that's interesting and it seems powerful. But I would never use such a feature, it increases the code mental load (what you should know before being able to read the code). From one codebase to another, I can't even keep the same assumptions.
- _cart 6y agoYeah implementing traits for functions is rarely advisable. However in this one very specific case (what amounts to dependency injection) it gives us very nice clarity and ergonomics. I'll take that over the macros everyone else is using in this context, or the expensive "runtime reflection" other languages might use to do the same thing. At least its still "normal" static rust code.
- Matthias247 6y agoOne can do that with extension traits, which offer some kind of extension functions. I guess here a Bevy trait is implemented on `fn (commands: Commands)`
- Angius 6y agoBevy's syntax does look tame, it was more of a jab at Rust syntax. I swear, people behind Rust would replace every single textual keyword with a symbol if they could.