From 2ead912da5410876ae68fe39cee267539bfac5fc Mon Sep 17 00:00:00 2001 From: Aceeri Date: Thu, 24 Aug 2023 17:54:30 -0700 Subject: [PATCH] Update bitflags to 2.4 --- bevy_rapier2d/Cargo.toml | 2 +- bevy_rapier2d_f64/Cargo.toml | 2 +- bevy_rapier3d/Cargo.toml | 2 +- bevy_rapier3d_f64/Cargo.toml | 2 +- src/dynamics/rigid_body.rs | 14 ++++--- src/geometry/collider.rs | 70 ++++++++++++++++++----------------- src/geometry/collider_impl.rs | 4 +- src/render/mod.rs | 18 ++++----- src/utils/mod.rs | 10 ++--- 9 files changed, 64 insertions(+), 60 deletions(-) diff --git a/bevy_rapier2d/Cargo.toml b/bevy_rapier2d/Cargo.toml index 47523eaf..6b02bbb4 100644 --- a/bevy_rapier2d/Cargo.toml +++ b/bevy_rapier2d/Cargo.toml @@ -37,7 +37,7 @@ bevy = { version = "0.11", 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" -bitflags = "1" +bitflags = "2.4" #bevy_prototype_debug_lines = { version = "0.6", optional = true } log = "0.4" serde = { version = "1", features = [ "derive" ], optional = true} diff --git a/bevy_rapier2d_f64/Cargo.toml b/bevy_rapier2d_f64/Cargo.toml index e3b26bf9..cf9147d5 100644 --- a/bevy_rapier2d_f64/Cargo.toml +++ b/bevy_rapier2d_f64/Cargo.toml @@ -38,7 +38,7 @@ bevy = { version = "0.11", 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-f64 = "0.17" -bitflags = "1" +bitflags = "2.4" #bevy_prototype_debug_lines = { version = "0.6", features = ["3d"], optional = true } log = "0.4" serde = { version = "1", features = [ "derive" ], optional = true} diff --git a/bevy_rapier3d/Cargo.toml b/bevy_rapier3d/Cargo.toml index 123f6e2f..8876bfc5 100644 --- a/bevy_rapier3d/Cargo.toml +++ b/bevy_rapier3d/Cargo.toml @@ -38,7 +38,7 @@ bevy = { version = "0.11", 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" -bitflags = "1" +bitflags = "2.4" #bevy_prototype_debug_lines = { version = "0.6", features = ["3d"], optional = true } log = "0.4" serde = { version = "1", features = [ "derive" ], optional = true} diff --git a/bevy_rapier3d_f64/Cargo.toml b/bevy_rapier3d_f64/Cargo.toml index 6ee7c597..756f0c98 100644 --- a/bevy_rapier3d_f64/Cargo.toml +++ b/bevy_rapier3d_f64/Cargo.toml @@ -38,7 +38,7 @@ bevy = { version = "0.11", 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-f64 = "0.17" -bitflags = "1" +bitflags = "2.4" #bevy_prototype_debug_lines = { version = "0.6", features = ["3d"], optional = true } log = "0.4" serde = { version = "1", features = [ "derive" ], optional = true} diff --git a/src/dynamics/rigid_body.rs b/src/dynamics/rigid_body.rs index 31213fa5..9ae993e2 100644 --- a/src/dynamics/rigid_body.rs +++ b/src/dynamics/rigid_body.rs @@ -240,11 +240,13 @@ impl MassProperties { } } +#[derive(Default, Component, Reflect, Copy, Clone, Ord, PartialOrd, Eq, PartialEq, Hash)] +#[reflect(Component, PartialEq)] +/// Flags affecting the behavior of the constraints solver for a given contact manifold. +pub struct LockedAxes(u8); + bitflags::bitflags! { - #[derive(Default, Component, Reflect)] - #[reflect(Component, PartialEq)] - /// Flags affecting the behavior of the constraints solver for a given contact manifold. - pub struct LockedAxes: u8 { + impl LockedAxes: u8 { /// Flag indicating that the rigid-body cannot translate along the `X` axis. const TRANSLATION_LOCKED_X = 1 << 0; /// Flag indicating that the rigid-body cannot translate along the `Y` axis. @@ -252,7 +254,7 @@ bitflags::bitflags! { /// Flag indicating that the rigid-body cannot translate along the `Z` axis. const TRANSLATION_LOCKED_Z = 1 << 2; /// Flag indicating that the rigid-body cannot translate along any direction. - const TRANSLATION_LOCKED = Self::TRANSLATION_LOCKED_X.bits | Self::TRANSLATION_LOCKED_Y.bits | Self::TRANSLATION_LOCKED_Z.bits; + const TRANSLATION_LOCKED = Self::TRANSLATION_LOCKED_X.bits() | Self::TRANSLATION_LOCKED_Y.bits() | Self::TRANSLATION_LOCKED_Z.bits(); /// Flag indicating that the rigid-body cannot rotate along the `X` axis. const ROTATION_LOCKED_X = 1 << 3; /// Flag indicating that the rigid-body cannot rotate along the `Y` axis. @@ -260,7 +262,7 @@ bitflags::bitflags! { /// Flag indicating that the rigid-body cannot rotate along the `Z` axis. const ROTATION_LOCKED_Z = 1 << 5; /// Combination of flags indicating that the rigid-body cannot rotate along any axis. - const ROTATION_LOCKED = Self::ROTATION_LOCKED_X.bits | Self::ROTATION_LOCKED_Y.bits | Self::ROTATION_LOCKED_Z.bits; + const ROTATION_LOCKED = Self::ROTATION_LOCKED_X.bits() | Self::ROTATION_LOCKED_Y.bits() | Self::ROTATION_LOCKED_Z.bits(); } } diff --git a/src/geometry/collider.rs b/src/geometry/collider.rs index 8e7245a0..d47cc377 100644 --- a/src/geometry/collider.rs +++ b/src/geometry/collider.rs @@ -148,17 +148,14 @@ impl Friction { /// Creates a `Friction` component from the given friction coefficient, and using the default /// `CoefficientCombineRule::Average` coefficient combine rule. pub const fn new(coefficient: Real) -> Self { - Self { - coefficient: coefficient, - combine_rule: CoefficientCombineRule::Average, - } + Self::coefficient(coefficient) } /// Creates a `Friction` component from the given friction coefficient, and using the default /// `CoefficientCombineRule::Average` coefficient combine rule. pub const fn coefficient(coefficient: Real) -> Self { Self { - coefficient: coefficient, + coefficient, combine_rule: CoefficientCombineRule::Average, } } @@ -181,17 +178,14 @@ impl Restitution { /// Creates a `Restitution` component from the given restitution coefficient, and using the default /// `CoefficientCombineRule::Average` coefficient combine rule. pub const fn new(coefficient: Real) -> Self { - Self { - coefficient: coefficient, - combine_rule: CoefficientCombineRule::Average, - } + Self::coefficient(coefficient) } /// Creates a `Restitution` component from the given restitution coefficient, and using the default /// `CoefficientCombineRule::Average` coefficient combine rule. pub const fn coefficient(coefficient: Real) -> Self { Self { - coefficient: coefficient, + coefficient, combine_rule: CoefficientCombineRule::Average, } } @@ -206,13 +200,15 @@ impl Default for Restitution { } } +#[derive(Component, Reflect, Debug, Copy, Clone, Ord, PartialOrd, Eq, PartialEq, Hash)] +#[reflect(Component, Hash, PartialEq)] +#[cfg_attr(feature = "serde-serialize", derive(Serialize, Deserialize))] +/// Flags affecting whether or not collision-detection happens between two colliders +/// depending on the type of rigid-bodies they are attached to. +pub struct ActiveCollisionTypes(u16); + bitflags::bitflags! { - #[derive(Component, Reflect)] - #[reflect(Component, Hash, PartialEq)] - #[cfg_attr(feature = "serde-serialize", derive(Serialize, Deserialize))] - /// Flags affecting whether or not collision-detection happens between two colliders - /// depending on the type of rigid-bodies they are attached to. - pub struct ActiveCollisionTypes: u16 { + impl ActiveCollisionTypes: u16 { /// Enable collision-detection between a collider attached to a dynamic body /// and another collider attached to a dynamic body. const DYNAMIC_DYNAMIC = 0b0000_0000_0000_0001; @@ -245,17 +241,19 @@ impl Default for ActiveCollisionTypes { impl From for rapier::geometry::ActiveCollisionTypes { fn from(collision_types: ActiveCollisionTypes) -> rapier::geometry::ActiveCollisionTypes { - rapier::geometry::ActiveCollisionTypes::from_bits(collision_types.bits) + rapier::geometry::ActiveCollisionTypes::from_bits(collision_types.bits()) .expect("Internal error: invalid active events conversion.") } } +/// A bit mask identifying groups for interaction. +#[derive(Component, Reflect, Copy, Clone, Debug, PartialEq, Eq, Hash)] +#[reflect(Component, Hash, PartialEq)] +#[cfg_attr(feature = "serde-serialize", derive(Serialize, Deserialize))] +pub struct Group(u32); + bitflags::bitflags! { - /// A bit mask identifying groups for interaction. - #[derive(Component, Reflect)] - #[reflect(Component, Hash, PartialEq)] - #[cfg_attr(feature = "serde-serialize", derive(Serialize, Deserialize))] - pub struct Group: u32 { + impl Group: u32 { /// The group n°1. const GROUP_1 = 1 << 0; /// The group n°2. @@ -410,12 +408,14 @@ impl From for InteractionGroups { } } +#[derive(Default, Component, Reflect, Debug, Copy, Clone, Ord, PartialOrd, Eq, PartialEq, Hash)] +#[reflect(Component)] +#[cfg_attr(feature = "serde-serialize", derive(Serialize, Deserialize))] +/// Flags affecting the behavior of the constraints solver for a given contact manifold. +pub struct ActiveHooks(u32); + bitflags::bitflags! { - #[derive(Default, Component, Reflect)] - #[reflect(Component)] - #[cfg_attr(feature = "serde-serialize", derive(Serialize, Deserialize))] - /// Flags affecting the behavior of the constraints solver for a given contact manifold. - pub struct ActiveHooks: u32 { + impl ActiveHooks: u32 { /// If set, Rapier will call `PhysicsHooks::filter_contact_pair` whenever relevant. const FILTER_CONTACT_PAIRS = 0b0001; /// If set, Rapier will call `PhysicsHooks::filter_intersection_pair` whenever relevant. @@ -427,17 +427,19 @@ bitflags::bitflags! { impl From for rapier::pipeline::ActiveHooks { fn from(active_hooks: ActiveHooks) -> rapier::pipeline::ActiveHooks { - rapier::pipeline::ActiveHooks::from_bits(active_hooks.bits) + rapier::pipeline::ActiveHooks::from_bits(active_hooks.bits()) .expect("Internal error: invalid active events conversion.") } } +#[derive(Default, Component, Reflect, Debug, Copy, Clone, Ord, PartialOrd, Eq, PartialEq, Hash)] +#[reflect(Component)] +#[cfg_attr(feature = "serde-serialize", derive(Serialize, Deserialize))] +/// Flags affecting the events generated for this collider. +pub struct ActiveEvents(u32); + bitflags::bitflags! { - #[derive(Default, Component, Reflect)] - #[reflect(Component)] - #[cfg_attr(feature = "serde-serialize", derive(Serialize, Deserialize))] - /// Flags affecting the events generated for this collider. - pub struct ActiveEvents: u32 { + impl ActiveEvents: u32 { /// If set, Rapier will call `EventHandler::handle_collision_event` /// whenever relevant for this collider. const COLLISION_EVENTS = 0b0001; @@ -449,7 +451,7 @@ bitflags::bitflags! { impl From for rapier::pipeline::ActiveEvents { fn from(active_events: ActiveEvents) -> rapier::pipeline::ActiveEvents { - rapier::pipeline::ActiveEvents::from_bits(active_events.bits) + rapier::pipeline::ActiveEvents::from_bits(active_events.bits()) .expect("Internal error: invalid active events conversion.") } } diff --git a/src/geometry/collider_impl.rs b/src/geometry/collider_impl.rs index 24cb8e5e..c7b5f187 100644 --- a/src/geometry/collider_impl.rs +++ b/src/geometry/collider_impl.rs @@ -403,7 +403,7 @@ impl Collider { heights: Vec, scale: impl AsPrecise, ) -> Self { - let heights = heights.into_iter().map(|v| v.as_precise().into()).collect(); + let heights = heights.into_iter().map(|v| v.as_precise()).collect(); SharedShape::heightfield(DVector::from_vec(heights), scale.as_precise().into()).into() } @@ -421,7 +421,7 @@ impl Collider { num_rows * num_cols, "Invalid number of heights provided." ); - let heights = heights.into_iter().map(|v| v.as_precise().into()).collect(); + let heights = heights.into_iter().map(|v| v.as_precise()).collect(); let heights = rapier::na::DMatrix::from_vec(num_rows, num_cols, heights); SharedShape::heightfield(heights, scale.into()).into() } diff --git a/src/render/mod.rs b/src/render/mod.rs index 64d9c75b..2e2cc4d2 100644 --- a/src/render/mod.rs +++ b/src/render/mod.rs @@ -1,4 +1,5 @@ use crate::plugin::RapierContext; +use crate::prelude::*; use bevy::prelude::*; use bevy::transform::TransformSystem; use rapier::math::{Point, Real}; @@ -126,11 +127,12 @@ impl<'world, 'state, 'a, 'b> DebugRenderBackend for BevyLinesRenderBackend<'worl b: Point, color: [f32; 4], ) { - let scale = self.physics_scale as f32; + let a = (Vect::from(a) * self.physics_scale).as_single(); + let b = (Vect::from(b) * self.physics_scale).as_single(); let color = self.object_color(object, color); self.gizmos.line( - [a.x as f32 * scale, a.y as f32 * scale, 0.0].into(), - [b.x as f32 * scale, b.y as f32 * scale, 0.0].into(), + a.extend(0.0), + b.extend(0.0), Color::hsla(color[0], color[1], color[2], color[3]), ) } @@ -143,13 +145,11 @@ impl<'world, 'state, 'a, 'b> DebugRenderBackend for BevyLinesRenderBackend<'worl b: Point, color: [f32; 4], ) { - let scale = self.physics_scale as f32; + let a = (Vect::from(a) * self.physics_scale).as_single(); + let b = (Vect::from(b) * self.physics_scale).as_single(); let color = self.object_color(object, color); - self.gizmos.line( - [a.x as f32 * scale, a.y as f32 * scale, a.z as f32 * scale].into(), - [b.x as f32 * scale, b.y as f32 * scale, b.z as f32 * scale].into(), - Color::hsla(color[0], color[1], color[2], color[3]), - ) + self.gizmos + .line(a, b, Color::hsla(color[0], color[1], color[2], color[3])) } } diff --git a/src/utils/mod.rs b/src/utils/mod.rs index b8f4b16e..dfd0bc6d 100644 --- a/src/utils/mod.rs +++ b/src/utils/mod.rs @@ -15,7 +15,7 @@ pub fn iso_to_transform(iso: &Isometry, physics_scale: Real) -> Transform let rotation = Quat::from_rotation_z(iso.rotation.angle().as_single()); Transform { translation: translation.as_single().extend(0.0), - rotation: rotation, + rotation, ..Default::default() } } @@ -25,11 +25,11 @@ pub fn iso_to_transform(iso: &Isometry, physics_scale: Real) -> Transform /// The translation is multiplied by the `physics_scale`. #[cfg(feature = "dim3")] pub fn iso_to_transform(iso: &Isometry, physics_scale: Real) -> Transform { - let translation = Vect::from(iso.translation.vector) * physics_scale; - let rotation = Rot::from(iso.rotation); + let translation = (Vect::from(iso.translation.vector) * physics_scale).as_single(); + let rotation = Rot::from(iso.rotation).as_single(); Transform { - translation: translation.as_single(), - rotation: rotation.as_single(), + translation, + rotation, ..Default::default() } }