Skip to content

Commit

Permalink
Update to Bevy 0.12
Browse files Browse the repository at this point in the history
  • Loading branch information
tim-blackbird committed Nov 1, 2023
1 parent 0ea000b commit daee384
Show file tree
Hide file tree
Showing 8 changed files with 43 additions and 43 deletions.
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ opt-level = 1
codegen-units = 1

[patch.crates-io]
bevy = { git = "https://github.com/bevyengine/bevy" }
#nalgebra = { path = "../nalgebra" }
#parry2d = { path = "../parry/crates/parry2d" }
#parry3d = { path = "../parry/crates/parry3d" }
Expand Down
4 changes: 2 additions & 2 deletions bevy_rapier2d/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ headless = []
async-collider = [ "bevy/bevy_asset", "bevy/bevy_scene" ]

[dependencies]
bevy = { version = "0.11", default-features = false }
bevy = { version = "0.12.0-dev", default-features = false }
nalgebra = { version = "0.32.3", features = [ "convert-glam024" ] }
# Don't enable the default features because we don't need the ColliderSet/RigidBodySet
rapier2d = "0.17.0"
Expand All @@ -42,7 +42,7 @@ log = "0.4"
serde = { version = "1", features = [ "derive" ], optional = true}

[dev-dependencies]
bevy = { version = "0.11", default-features = false, features = ["x11"]}
bevy = { version = "0.12.0-dev", default-features = false, features = ["x11", "tonemapping_luts"]}
oorandom = "11"
approx = "0.5.1"
glam = { version = "0.24", features = [ "approx" ] }
Expand Down
4 changes: 2 additions & 2 deletions bevy_rapier2d/examples/events2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,11 @@ fn display_events(
mut collision_events: EventReader<CollisionEvent>,
mut contact_force_events: EventReader<ContactForceEvent>,
) {
for collision_event in collision_events.iter() {
for collision_event in collision_events.read() {
println!("Received collision event: {collision_event:?}");
}

for contact_force_event in contact_force_events.iter() {
for contact_force_event in contact_force_events.read() {
println!("Received contact force event: {contact_force_event:?}");
}
}
Expand Down
4 changes: 2 additions & 2 deletions bevy_rapier3d/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ headless = [ ]
async-collider = [ "bevy/bevy_asset", "bevy/bevy_scene" ]

[dependencies]
bevy = { version = "0.11", default-features = false }
bevy = { version = "0.12.0-dev", default-features = false }
nalgebra = { version = "0.32.3", features = [ "convert-glam024" ] }
# Don't enable the default features because we don't need the ColliderSet/RigidBodySet
rapier3d = "0.17"
Expand All @@ -43,7 +43,7 @@ log = "0.4"
serde = { version = "1", features = [ "derive" ], optional = true}

[dev-dependencies]
bevy = { version = "0.11", default-features = false, features = ["x11"]}
bevy = { version = "0.12.0-dev", default-features = false, features = ["x11", "tonemapping_luts"]}
approx = "0.5.1"
glam = { version = "0.24", features = [ "approx" ] }

Expand Down
4 changes: 2 additions & 2 deletions bevy_rapier3d/examples/events3.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,11 @@ fn display_events(
mut collision_events: EventReader<CollisionEvent>,
mut contact_force_events: EventReader<ContactForceEvent>,
) {
for collision_event in collision_events.iter() {
for collision_event in collision_events.read() {
println!("Received collision event: {collision_event:?}");
}

for contact_force_event in contact_force_events.iter() {
for contact_force_event in contact_force_events.read() {
println!("Received contact force event: {contact_force_event:?}");
}
}
Expand Down
2 changes: 0 additions & 2 deletions src/plugin/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -737,8 +737,6 @@ impl RapierContext {
aabb: bevy::render::primitives::Aabb,
mut callback: impl FnMut(Entity) -> bool,
) {
#[cfg(feature = "dim2")]
use bevy::math::Vec3Swizzles;
#[cfg(feature = "dim2")]
let scaled_aabb = rapier::prelude::Aabb {
mins: (aabb.min().xy() / self.physics_scale).into(),
Expand Down
30 changes: 16 additions & 14 deletions src/plugin/plugin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,13 @@ use crate::pipeline::{CollisionEvent, ContactForceEvent};
use crate::plugin::configuration::SimulationToRenderTime;
use crate::plugin::{systems, RapierConfiguration, RapierContext};
use crate::prelude::*;
use bevy::ecs::{
event::Events,
schedule::{ScheduleLabel, SystemConfigs},
system::SystemParamItem,
use bevy::{
ecs::{
event::{event_update_system, Events},
schedule::{ScheduleLabel, SystemConfigs},
system::SystemParamItem,
},
utils::intern::Interned,
};
use bevy::{prelude::*, transform::TransformSystem};
use std::marker::PhantomData;
Expand All @@ -18,7 +21,7 @@ pub type NoUserData = ();
/// This will automatically setup all the resources needed to run a physics simulation with the
/// Rapier physics engine.
pub struct RapierPhysicsPlugin<PhysicsHooks = ()> {
schedule: Box<dyn ScheduleLabel>,
schedule: Interned<dyn ScheduleLabel>,
physics_scale: f32,
default_system_setup: bool,
_phantom: PhantomData<PhysicsHooks>,
Expand Down Expand Up @@ -68,7 +71,7 @@ where

/// Adds the physics systems to the provided schedule rather than `PostUpdate`.
pub fn in_schedule(mut self, schedule: impl ScheduleLabel) -> Self {
self.schedule = Box::new(schedule);
self.schedule = schedule.intern();
self
}

Expand All @@ -88,7 +91,7 @@ where
.chain()
.in_set(RapierTransformPropagateSet),
#[cfg(all(feature = "dim3", feature = "async-collider"))]
systems::init_async_scene_colliders.after(bevy::scene::scene_spawner_system),
systems::init_async_scene_colliders,
#[cfg(all(feature = "dim3", feature = "async-collider"))]
systems::init_async_colliders,
systems::init_rigid_bodies,
Expand All @@ -107,18 +110,17 @@ where
.into_configs(),
PhysicsSet::StepSimulation => (
systems::step_simulation::<PhysicsHooks>,
Events::<CollisionEvent>::update_system
event_update_system::<CollisionEvent>
.before(systems::step_simulation::<PhysicsHooks>),
Events::<ContactForceEvent>::update_system
event_update_system::<ContactForceEvent>
.before(systems::step_simulation::<PhysicsHooks>),
)
.into_configs(),
PhysicsSet::Writeback => (
systems::update_colliding_entities,
systems::writeback_rigid_bodies,
systems::writeback_mass_properties,
Events::<MassModifiedEvent>::update_system
.after(systems::writeback_mass_properties),
event_update_system::<MassModifiedEvent>.after(systems::writeback_mass_properties),
)
.into_configs(),
}
Expand All @@ -134,7 +136,7 @@ pub struct RapierTransformPropagateSet;
impl<PhysicsHooksSystemParam> Default for RapierPhysicsPlugin<PhysicsHooksSystemParam> {
fn default() -> Self {
Self {
schedule: Box::new(PostUpdate),
schedule: PostUpdate.intern(),
physics_scale: 1.0,
default_system_setup: true,
_phantom: PhantomData,
Expand Down Expand Up @@ -205,7 +207,7 @@ where
// Add each set as necessary
if self.default_system_setup {
app.configure_sets(
self.schedule.clone(),
self.schedule,
(
PhysicsSet::SyncBackend,
PhysicsSet::StepSimulation,
Expand All @@ -219,7 +221,7 @@ where
app.add_systems(PostUpdate, (systems::sync_removals,));

app.add_systems(
self.schedule.clone(),
self.schedule,
(
Self::get_systems(PhysicsSet::SyncBackend).in_set(PhysicsSet::SyncBackend),
Self::get_systems(PhysicsSet::StepSimulation)
Expand Down
37 changes: 18 additions & 19 deletions src/plugin/systems.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ use crate::prelude::{
use crate::utils;
use bevy::ecs::system::{StaticSystemParam, SystemParamItem};
use bevy::prelude::*;
use rapier::prelude::*;
use rapier::{math::Real, prelude::*};
use std::collections::HashMap;

#[cfg(all(feature = "dim3", feature = "async-collider"))]
Expand Down Expand Up @@ -682,7 +682,7 @@ pub fn writeback_mass_properties(
let scale = context.physics_scale;

if config.physics_pipeline_active {
for entity in mass_modified.iter() {
for entity in mass_modified.read() {
if let Some(handle) = context.entity2body.get(entity).copied() {
if let Some(rb) = context.bodies.get(handle) {
if let Ok(mut mass_props) = mass_props.get_mut(**entity) {
Expand Down Expand Up @@ -1187,7 +1187,7 @@ pub fn sync_removals(
* Rigid-bodies removal detection.
*/
let context = &mut *context;
for entity in removed_bodies.iter() {
for entity in removed_bodies.read() {
if let Some(handle) = context.entity2body.remove(&entity) {
let _ = context.last_body_transform_set.remove(&handle);
context.bodies.remove(
Expand Down Expand Up @@ -1220,7 +1220,7 @@ pub fn sync_removals(
/*
* Collider removal detection.
*/
for entity in removed_colliders.iter() {
for entity in removed_colliders.read() {
if let Some(parent) = context.collider_parent(entity) {
mass_modified.send(parent.into());
}
Expand Down Expand Up @@ -1250,7 +1250,7 @@ pub fn sync_removals(
/*
* Impulse joint removal detection.
*/
for entity in removed_impulse_joints.iter() {
for entity in removed_impulse_joints.read() {
if let Some(handle) = context.entity2impulse_joint.remove(&entity) {
context.impulse_joints.remove(handle, true);
}
Expand All @@ -1266,7 +1266,7 @@ pub fn sync_removals(
/*
* Multibody joint removal detection.
*/
for entity in removed_multibody_joints.iter() {
for entity in removed_multibody_joints.read() {
if let Some(handle) = context.entity2multibody_joint.remove(&entity) {
context.multibody_joints.remove(handle, true);
}
Expand All @@ -1284,23 +1284,23 @@ pub fn sync_removals(
/*
* Marker components removal detection.
*/
for entity in removed_sensors.iter() {
for entity in removed_sensors.read() {
if let Some(handle) = context.entity2collider.get(&entity) {
if let Some(co) = context.colliders.get_mut(*handle) {
co.set_sensor(false);
}
}
}

for entity in removed_colliders_disabled.iter() {
for entity in removed_colliders_disabled.read() {
if let Some(handle) = context.entity2collider.get(&entity) {
if let Some(co) = context.colliders.get_mut(*handle) {
co.set_enabled(true);
}
}
}

for entity in removed_rigid_body_disabled.iter() {
for entity in removed_rigid_body_disabled.read() {
if let Some(handle) = context.entity2body.get(&entity) {
if let Some(rb) = context.bodies.get_mut(*handle) {
rb.set_enabled(true);
Expand All @@ -1317,7 +1317,7 @@ pub fn update_colliding_entities(
mut collision_events: EventReader<CollisionEvent>,
mut colliding_entities: Query<&mut CollidingEntities>,
) {
for event in collision_events.iter() {
for event in collision_events.read() {
match event.to_owned() {
CollisionEvent::Started(entity1, entity2, _) => {
if let Ok(mut entities) = colliding_entities.get_mut(entity1) {
Expand Down Expand Up @@ -1507,7 +1507,10 @@ mod tests {
use bevy::{
asset::AssetPlugin,
ecs::event::Events,
render::{settings::WgpuSettings, RenderPlugin},
render::{
settings::{RenderCreation, WgpuSettings},
RenderPlugin,
},
scene::ScenePlugin,
time::TimePlugin,
window::WindowPlugin,
Expand Down Expand Up @@ -1631,13 +1634,9 @@ mod tests {
#[test]
#[cfg(all(feature = "dim3", feature = "async-collider"))]
fn async_scene_collider_initializes() {
use bevy::scene::scene_spawner_system;

let mut app = App::new();
app.add_plugins(HeadlessRenderPlugin).add_systems(
Update,
init_async_scene_colliders.after(scene_spawner_system),
);
app.add_plugins(HeadlessRenderPlugin)
.add_systems(PostUpdate, init_async_scene_colliders);

let mut meshes = app.world.resource_mut::<Assets<Mesh>>();
let cube_handle = meshes.add(Cube::default().into());
Expand Down Expand Up @@ -1825,10 +1824,10 @@ mod tests {
AssetPlugin::default(),
ScenePlugin::default(),
RenderPlugin {
wgpu_settings: WgpuSettings {
render_creation: RenderCreation::Automatic(WgpuSettings {
backends: None,
..Default::default()
},
}),
},
ImagePlugin::default(),
));
Expand Down

0 comments on commit daee384

Please sign in to comment.