This release should require very little to no changes to user code.
Guide
The guide continues to expand with a new Learn by example section.
Tracking new design
This is what took the most time, and in the end, the new design is syntactically identical to 0.6 for most users.
The new design allows for the easy-to-use derive of 0.6 while allowing downstream crate to specify additional tracking on a component they didn't define.
Let's take an example. You have 3 crates, crateA and crateB both depend on crateC.
crateA and crateB both use a component T
that is defined in crateC. crateA cares about modification on T
but crateB and crateC don't.
With 0.6 you would have to always track T
modifications, in all three crates. The only place tracking could be defined was crateC.
With 0.7 you can omit tracking from crateB and crateC. And only track modifications in crateA.
The derive macro also allows any combination of tracking now where it only allowed a single kind of tracking in 0.6.
You can read more about tracking evolution in this post.
More convenience functions
Back in early versions all entity and component operations had to go through views.
With time I changed my mind on this and I added shortcuts to add entities or components directly from World
.
0.7 adds more of these functions like World::iter
.
#[derive(Component, Debug, PartialEq, Eq)]
struct U32(u32);
#[derive(Component, Debug, PartialEq, Eq)]
struct USIZE(usize);
let mut world = World::new();
let entity = world.add_entity((USIZE(0), U32(1)));
for (i, j) in &mut world.iter::<(&USIZE, &mut U32)>() {
// <-- SNIP -->
}
Custom Views
Custom views are easier to create and more powerful than ever.
#[derive(Borrow, BorrowInfo, IntoIter)]
struct TransformView<'v> {
pos: View<'v, Pos>,
vel: View<'v, Vel>,
}
fn main() {
// -- SNIP --
world.run(|v_transform: TransformView| {
for transform in v_transform.iter() {
transform.pos;
transform.vel;
}
});
}
Thanks @eldyer, @BoxyUwU and everyone that opened an issue or PR!