Skip to content

Commit

Permalink
Update bitflags to 2.4
Browse files Browse the repository at this point in the history
  • Loading branch information
Aceeri committed Aug 25, 2023
1 parent 2b9e2ed commit 2ead912
Show file tree
Hide file tree
Showing 9 changed files with 64 additions and 60 deletions.
2 changes: 1 addition & 1 deletion bevy_rapier2d/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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}
Expand Down
2 changes: 1 addition & 1 deletion bevy_rapier2d_f64/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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}
Expand Down
2 changes: 1 addition & 1 deletion bevy_rapier3d/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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}
Expand Down
2 changes: 1 addition & 1 deletion bevy_rapier3d_f64/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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}
Expand Down
14 changes: 8 additions & 6 deletions src/dynamics/rigid_body.rs
Original file line number Diff line number Diff line change
Expand Up @@ -240,27 +240,29 @@ 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.
const TRANSLATION_LOCKED_Y = 1 << 1;
/// 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.
const ROTATION_LOCKED_Y = 1 << 4;
/// 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();
}
}

Expand Down
70 changes: 36 additions & 34 deletions src/geometry/collider.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}
}
Expand All @@ -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,
}
}
Expand All @@ -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;
Expand Down Expand Up @@ -245,17 +241,19 @@ impl Default for ActiveCollisionTypes {

impl From<ActiveCollisionTypes> 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.
Expand Down Expand Up @@ -410,12 +408,14 @@ impl From<SolverGroups> 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.
Expand All @@ -427,17 +427,19 @@ bitflags::bitflags! {

impl From<ActiveHooks> 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;
Expand All @@ -449,7 +451,7 @@ bitflags::bitflags! {

impl From<ActiveEvents> 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.")
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/geometry/collider_impl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -403,7 +403,7 @@ impl Collider {
heights: Vec<R>,
scale: impl AsPrecise<Out = Vect>,
) -> 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()
}

Expand All @@ -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()
}
Expand Down
18 changes: 9 additions & 9 deletions src/render/mod.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use crate::plugin::RapierContext;
use crate::prelude::*;
use bevy::prelude::*;
use bevy::transform::TransformSystem;
use rapier::math::{Point, Real};
Expand Down Expand Up @@ -126,11 +127,12 @@ impl<'world, 'state, 'a, 'b> DebugRenderBackend for BevyLinesRenderBackend<'worl
b: Point<Real>,
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]),
)
}
Expand All @@ -143,13 +145,11 @@ impl<'world, 'state, 'a, 'b> DebugRenderBackend for BevyLinesRenderBackend<'worl
b: Point<Real>,
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]))
}
}

Expand Down
10 changes: 5 additions & 5 deletions src/utils/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ pub fn iso_to_transform(iso: &Isometry<Real>, 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()
}
}
Expand All @@ -25,11 +25,11 @@ pub fn iso_to_transform(iso: &Isometry<Real>, physics_scale: Real) -> Transform
/// The translation is multiplied by the `physics_scale`.
#[cfg(feature = "dim3")]
pub fn iso_to_transform(iso: &Isometry<Real>, 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()
}
}
Expand Down

0 comments on commit 2ead912

Please sign in to comment.