Skip to content

Commit 24a3a14

Browse files
authored
Update to Bevy 0.16.0-rc.1 (#670)
# Objective The first release candidate for Bevy 0.16 has been released! We should migrate our main branch to it for early adopters, and to benefit from the various new features it introduces. ## Solution Migrate to Bevy 0.16.0-rc.1. Most changes were largely mechanical or minor cleanup, but some larger changes were also required. The most notable change is that 0.16 removed the `HierarchyEvent`, so the `AncestorMarkerPlugin` had to be reworked. It now uses only observers instead of also using some systems, which significantly simplifies code and makes things more robust and schedule-free. I also replaced some `HashSet<Entity>` types with `EntityHashSet` and `HashMap<Entity>` types with `EntityHashMap`. ## Follow-Up This is only a bare-bones migration to get Avian working with the Bevy 0.16 RC. We should take advantage of the new features! Some ideas: - `no_std` support - Change `ColliderParent` to a relationship-like immutable `ColliderOf` component driven by hooks - Rework collider debug rendering to use retained gizmos - Migrate examples to the improved spawning API --- ## Migration Guide Avian now supports Bevy 0.16. The `AncestorMarkerPlugin` no longer requires a schedule or system set.
1 parent da07cc2 commit 24a3a14

File tree

62 files changed

+344
-486
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

62 files changed

+344
-486
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,7 @@ cargo run --example cubes --no-default-features --features "3d f64 parry-f64"
161161

162162
| Bevy | Avian |
163163
| ------- | ----- |
164+
| 0.16 RC | main |
164165
| 0.15 | 0.2 |
165166
| 0.14 | 0.1 |
166167

crates/avian2d/Cargo.toml

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -68,10 +68,13 @@ bench = false
6868

6969
[dependencies]
7070
avian_derive = { path = "../avian_derive", version = "0.2" }
71-
bevy = { version = "0.15", default-features = false }
72-
bevy_math = { version = "0.15" }
73-
bevy_heavy = { version = "0.1" }
74-
bevy_transform_interpolation = { version = "0.1" }
71+
bevy = { version = "0.16.0-rc.1", default-features = false, features = [
72+
"std",
73+
"bevy_log",
74+
] }
75+
bevy_math = { version = "0.16.0-rc.1" }
76+
bevy_heavy = { git = "https://github.com/Jondolf/bevy_heavy" }
77+
bevy_transform_interpolation = { git = "https://github.com/Jondolf/bevy_transform_interpolation" }
7578
libm = { version = "0.2", optional = true }
7679
parry2d = { version = "0.17", optional = true }
7780
parry2d-f64 = { version = "0.17", optional = true }
@@ -87,13 +90,16 @@ bitflags = "2.5.0"
8790
[dev-dependencies]
8891
examples_common_2d = { path = "../examples_common_2d" }
8992
benches_common_2d = { path = "../benches_common_2d" }
90-
bevy_math = { version = "0.15", features = ["approx"] }
91-
bevy_heavy = { version = "0.1", features = ["approx"] }
93+
bevy_math = { version = "0.16.0-rc.1", features = ["approx"] }
94+
bevy_heavy = { git = "https://github.com/Jondolf/bevy_heavy", features = [
95+
"approx",
96+
] }
9297
glam = { version = "0.29", features = ["bytemuck"] }
9398
approx = "0.5"
9499
bytemuck = "1.19"
95100
criterion = { version = "0.5", features = ["html_reports"] }
96-
bevy_mod_debugdump = { version = "0.12" }
101+
# TODO: Update to the latest version when it's available.
102+
# bevy_mod_debugdump = { version = "0.12" }
97103

98104
[lints]
99105
workspace = true

crates/avian2d/examples/chain_2d.rs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -71,11 +71,11 @@ fn follow_mouse(
7171
windows: Query<&Window, With<PrimaryWindow>>,
7272
camera: Query<(&Camera, &GlobalTransform)>,
7373
mut follower: Query<&mut Transform, With<FollowMouse>>,
74-
) {
74+
) -> Result {
7575
if buttons.pressed(MouseButton::Left) {
76-
let window = windows.single();
77-
let (camera, camera_transform) = camera.single();
78-
let mut follower_position = follower.single_mut();
76+
let window = windows.single()?;
77+
let (camera, camera_transform) = camera.single()?;
78+
let mut follower_position = follower.single_mut()?;
7979

8080
if let Some(cursor_world_pos) = window
8181
.cursor_position()
@@ -85,4 +85,6 @@ fn follow_mouse(
8585
cursor_world_pos.extend(follower_position.translation.z);
8686
}
8787
}
88+
89+
Ok(())
8890
}
Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
11
//! Run with:
22
//! `cargo run --example debugdump_2d > dump.dot && dot -Tsvg dump.dot > dump.svg`
33
4-
use avian2d::prelude::*;
5-
use bevy::prelude::*;
4+
// use avian2d::prelude::*;
5+
// use bevy::prelude::*;
66

77
fn main() {
8+
todo!("`bevy_mod_debugdump` is not compatible with Bevy 0.16 yet. This example will be updated when it is.");
9+
10+
/*
811
let mut app = App::new();
912
1013
app.add_plugins((PhysicsPlugins::default(), PhysicsDebugPlugin::default()));
@@ -14,5 +17,7 @@ fn main() {
1417
// - SubstepSchedule
1518
// - FixedPostUpdate
1619
// - Update
20+
1721
bevy_mod_debugdump::print_schedule_graph(&mut app, PhysicsSchedule);
22+
*/
1823
}

crates/avian2d/examples/determinism_2d.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,7 @@ fn clear_scene(
205205
) {
206206
step.0 = 0;
207207
for entity in &query {
208-
commands.entity(entity).despawn_recursive();
208+
commands.entity(entity).despawn();
209209
}
210210
}
211211

crates/avian2d/examples/dynamic_character_2d/plugin.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -136,11 +136,11 @@ fn keyboard_input(
136136
let direction = horizontal as Scalar;
137137

138138
if direction != 0.0 {
139-
movement_event_writer.send(MovementAction::Move(direction));
139+
movement_event_writer.write(MovementAction::Move(direction));
140140
}
141141

142142
if keyboard_input.just_pressed(KeyCode::Space) {
143-
movement_event_writer.send(MovementAction::Jump);
143+
movement_event_writer.write(MovementAction::Jump);
144144
}
145145
}
146146

@@ -151,11 +151,11 @@ fn gamepad_input(
151151
) {
152152
for gamepad in gamepads.iter() {
153153
if let Some(x) = gamepad.get(GamepadAxis::LeftStickX) {
154-
movement_event_writer.send(MovementAction::Move(x as Scalar));
154+
movement_event_writer.write(MovementAction::Move(x as Scalar));
155155
}
156156

157157
if gamepad.just_pressed(GamepadButton::South) {
158-
movement_event_writer.send(MovementAction::Jump);
158+
movement_event_writer.write(MovementAction::Jump);
159159
}
160160
}
161161
}

crates/avian2d/examples/kinematic_character_2d/plugin.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -150,11 +150,11 @@ fn keyboard_input(
150150
let direction = horizontal as Scalar;
151151

152152
if direction != 0.0 {
153-
movement_event_writer.send(MovementAction::Move(direction));
153+
movement_event_writer.write(MovementAction::Move(direction));
154154
}
155155

156156
if keyboard_input.just_pressed(KeyCode::Space) {
157-
movement_event_writer.send(MovementAction::Jump);
157+
movement_event_writer.write(MovementAction::Jump);
158158
}
159159
}
160160

@@ -165,11 +165,11 @@ fn gamepad_input(
165165
) {
166166
for gamepad in gamepads.iter() {
167167
if let Some(x) = gamepad.get(GamepadAxis::LeftStickX) {
168-
movement_event_writer.send(MovementAction::Move(x as Scalar));
168+
movement_event_writer.write(MovementAction::Move(x as Scalar));
169169
}
170170

171171
if gamepad.just_pressed(GamepadButton::South) {
172-
movement_event_writer.send(MovementAction::Jump);
172+
movement_event_writer.write(MovementAction::Jump);
173173
}
174174
}
175175
}

crates/avian2d/examples/one_way_platform_2d.rs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,11 @@
88

99
use avian2d::{math::*, prelude::*};
1010
use bevy::{
11-
ecs::system::{lifetimeless::Read, SystemParam},
11+
ecs::{
12+
entity::hash_set::EntityHashSet,
13+
system::{lifetimeless::Read, SystemParam},
14+
},
1215
prelude::*,
13-
utils::HashSet,
1416
};
1517
use examples_common_2d::ExampleCommonPlugin;
1618

@@ -46,7 +48,7 @@ struct JumpImpulse(Scalar);
4648
// Here we use required components, but you could also add it manually.
4749
#[derive(Clone, Eq, PartialEq, Debug, Default, Component)]
4850
#[require(ActiveCollisionHooks(|| ActiveCollisionHooks::MODIFY_CONTACTS))]
49-
pub struct OneWayPlatform(HashSet<Entity>);
51+
pub struct OneWayPlatform(EntityHashSet);
5052

5153
/// A component to control how an actor interacts with a one-way platform.
5254
#[derive(Copy, Clone, Eq, PartialEq, Debug, Default, Component, Reflect)]

crates/avian2d/examples/sensor.rs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ fn keyboard_input1(
108108
}
109109
let space = keyboard_input.pressed(KeyCode::Space);
110110
if space {
111-
movement_event_writer.send(MovementAction::Stop);
111+
movement_event_writer.write(MovementAction::Stop);
112112
return;
113113
}
114114

@@ -120,7 +120,7 @@ fn keyboard_input1(
120120
let vertical = up as i8 - down as i8;
121121
let direction = Vector::new(horizontal as Scalar, vertical as Scalar);
122122
if direction != Vector::ZERO {
123-
movement_event_writer.send(MovementAction::Velocity(direction));
123+
movement_event_writer.write(MovementAction::Velocity(direction));
124124
}
125125
}
126126
// use position offset
@@ -140,7 +140,7 @@ fn keyboard_input2(
140140
let vertical = up as i8 - down as i8;
141141
let direction = Vector::new(horizontal as Scalar, vertical as Scalar);
142142
if direction != Vector::ZERO {
143-
movement_event_writer.send(MovementAction::Offset(direction));
143+
movement_event_writer.write(MovementAction::Offset(direction));
144144
}
145145
}
146146

@@ -219,16 +219,16 @@ fn update_velocity_text(
219219
character_query: Query<(&LinearVelocity, Has<Sleeping>), With<Character>>,
220220
pressure_plate_query: Query<Has<Sleeping>, With<PressurePlate>>,
221221
mut text_query: Query<&mut Text, With<CharacterVelocityText>>,
222-
) {
223-
if let (Ok((velocity, character_sleeping)), Ok(pressure_plate_sleeping)) = (
224-
character_query.get_single(),
225-
pressure_plate_query.get_single(),
226-
) {
227-
text_query.single_mut().0 = format!(
222+
) -> Result {
223+
if let (Ok((velocity, character_sleeping)), Ok(pressure_plate_sleeping)) =
224+
(character_query.single(), pressure_plate_query.single())
225+
{
226+
text_query.single_mut()?.0 = format!(
228227
"Velocity: {:.4}, {:.4}\nCharacter sleeping:{}\nPressure plate sleeping: {}",
229228
velocity.x, velocity.y, character_sleeping, pressure_plate_sleeping
230229
);
231230
}
231+
Ok(())
232232
}
233233

234234
fn log_events(mut started: EventReader<CollisionStarted>, mut ended: EventReader<CollisionEnded>) {

crates/avian3d/Cargo.toml

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -70,10 +70,13 @@ bench = false
7070

7171
[dependencies]
7272
avian_derive = { path = "../avian_derive", version = "0.2" }
73-
bevy = { version = "0.15", default-features = false }
74-
bevy_math = { version = "0.15" }
75-
bevy_heavy = { version = "0.1" }
76-
bevy_transform_interpolation = { version = "0.1" }
73+
bevy = { version = "0.16.0-rc.1", default-features = false, features = [
74+
"std",
75+
"bevy_log",
76+
] }
77+
bevy_math = { version = "0.16.0-rc.1" }
78+
bevy_heavy = { git = "https://github.com/Jondolf/bevy_heavy" }
79+
bevy_transform_interpolation = { git = "https://github.com/Jondolf/bevy_transform_interpolation" }
7780
libm = { version = "0.2", optional = true }
7881
parry3d = { version = "0.17", optional = true }
7982
parry3d-f64 = { version = "0.17", optional = true }
@@ -89,15 +92,18 @@ bitflags = "2.5.0"
8992
[dev-dependencies]
9093
examples_common_3d = { path = "../examples_common_3d" }
9194
benches_common_3d = { path = "../benches_common_3d" }
92-
bevy = { version = "0.15", default-features = false, features = [
95+
bevy = { version = "0.16.0-rc.1", default-features = false, features = [
9396
"bevy_gltf",
9497
"animation",
9598
] }
96-
bevy_math = { version = "0.15", features = ["approx"] }
97-
bevy_heavy = { version = "0.1", features = ["approx"] }
99+
bevy_math = { version = "0.16.0-rc.1", features = ["approx"] }
100+
bevy_heavy = { git = "https://github.com/Jondolf/bevy_heavy", features = [
101+
"approx",
102+
] }
98103
approx = "0.5"
99104
criterion = { version = "0.5", features = ["html_reports"] }
100-
bevy_mod_debugdump = { version = "0.12" }
105+
# TODO: Update to the latest version when it's available.
106+
# bevy_mod_debugdump = { version = "0.12" }
101107

102108
[lints]
103109
workspace = true

0 commit comments

Comments
 (0)