Skip to content

Commit

Permalink
Use Embark lints v0.2
Browse files Browse the repository at this point in the history
Switches to use our new standard template for defining shared Rust and Clippy lints for our Embark projects, EmbarkStudios/rust-ecosystem#59.

Did a couple of lint fixes from this but didn't want to make the change too intrusive so added some allow exceptions for now that can be revisited
  • Loading branch information
repi committed Mar 6, 2021
1 parent 016a12e commit b24b76b
Show file tree
Hide file tree
Showing 10 changed files with 167 additions and 81 deletions.
68 changes: 59 additions & 9 deletions physx-sys/src/lib.rs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions physx/src/aggregate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ pub trait Aggregate: Class<physx_sys::PxAggregate> + Base {
PxAggregate_addActor_mut(
self.as_mut_ptr(),
actor.as_mut_ptr(),
bvh.map(Class::as_ptr).unwrap_or(null()),
bvh.map_or(null(), Class::as_ptr),
)
}
}
Expand All @@ -157,7 +157,7 @@ pub trait Aggregate: Class<physx_sys::PxAggregate> + Base {
PxAggregate_addActor_mut(
self.as_mut_ptr(),
actor.as_mut_ptr(),
bvh.map(Class::as_ptr).unwrap_or(null()),
bvh.map_or(null(), Class::as_ptr),
)
}
}
Expand All @@ -172,7 +172,7 @@ pub trait Aggregate: Class<physx_sys::PxAggregate> + Base {
PxAggregate_addActor_mut(
self.as_mut_ptr(),
actor.as_mut_ptr(),
bvh.map(Class::as_ptr).unwrap_or(null()),
bvh.map_or(null(), Class::as_ptr),
)
}
}
Expand Down
4 changes: 1 addition & 3 deletions physx/src/articulation_base.rs
Original file line number Diff line number Diff line change
Expand Up @@ -226,9 +226,7 @@ pub trait ArticulationBase: Class<physx_sys::PxArticulationBase> + Base {
unsafe {
(PxArticulationBase_createLink_mut(
self.as_mut_ptr(),
parent
.map(|parent| parent.as_mut_ptr())
.unwrap_or(null_mut()),
parent.map_or(null_mut(), |parent| parent.as_mut_ptr()),
pose.as_ptr(),
) as *mut Self::ArticulationLink)
.as_mut()
Expand Down
47 changes: 23 additions & 24 deletions physx/src/base.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,31 +65,30 @@ pub enum ConcreteType {

impl From<u16> for ConcreteType {
fn from(val: u16) -> Self {
use ConcreteType::*;
match val {
0 => Undefined,
1 => Heightfield,
2 => ConvexMesh,
3 => TriangleMeshBvh33,
4 => TriangleMeshBvh34,
5 => RigidDynamic,
6 => RigidStatic,
7 => Shape,
8 => Material,
9 => Constraint,
10 => Aggregate,
11 => Articulation,
12 => ArticulationReducedCoordinate,
13 => ArticulationLink,
14 => ArticulationJoint,
15 => ArticulationJointReducedCoordinate,
16 => PruningStructure,
17 => BvhStructure,
18 => PhysxCoreCount,
256 => FirstPhysxExtension,
512 => FirstVehicleExtension,
1024 => FirstUserExtension,
_ => Undefined,
0 => ConcreteType::Undefined,
1 => ConcreteType::Heightfield,
2 => ConcreteType::ConvexMesh,
3 => ConcreteType::TriangleMeshBvh33,
4 => ConcreteType::TriangleMeshBvh34,
5 => ConcreteType::RigidDynamic,
6 => ConcreteType::RigidStatic,
7 => ConcreteType::Shape,
8 => ConcreteType::Material,
9 => ConcreteType::Constraint,
10 => ConcreteType::Aggregate,
11 => ConcreteType::Articulation,
12 => ConcreteType::ArticulationReducedCoordinate,
13 => ConcreteType::ArticulationLink,
14 => ConcreteType::ArticulationJoint,
15 => ConcreteType::ArticulationJointReducedCoordinate,
16 => ConcreteType::PruningStructure,
17 => ConcreteType::BvhStructure,
18 => ConcreteType::PhysxCoreCount,
256 => ConcreteType::FirstPhysxExtension,
512 => ConcreteType::FirstVehicleExtension,
1024 => ConcreteType::FirstUserExtension,
_ => ConcreteType::Undefined,
}
}
}
Expand Down
59 changes: 52 additions & 7 deletions physx/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,3 @@
// Author: Tom Olsson <[email protected]>
// Copyright © 2019, Embark Studios, all rights reserved.
// Created: 2 April 2019

#![warn(clippy::all)]
#![deny(rust_2018_idioms)]

//! # 🎳 physx
//!
//! ![Build Status](https://github.com/EmbarkStudios/physx-rs/workflows/CI/badge.svg)
Expand Down Expand Up @@ -100,6 +93,58 @@
//! license, shall be dual licensed as above, without any additional terms or
//! conditions.

// BEGIN - Embark standard lints v0.2.
// do not change or add/remove here, but one can add exceptions after this section
#![deny(unsafe_code)]
#![warn(
clippy::all,
clippy::await_holding_lock,
clippy::dbg_macro,
clippy::debug_assert_with_mut_call,
clippy::doc_markdown,
clippy::empty_enum,
clippy::enum_glob_use,
clippy::exit,
clippy::explicit_into_iter_loop,
clippy::filter_map_next,
clippy::fn_params_excessive_bools,
clippy::if_let_mutex,
clippy::imprecise_flops,
clippy::inefficient_to_string,
clippy::let_unit_value,
clippy::linkedlist,
clippy::lossy_float_literal,
clippy::macro_use_imports,
clippy::map_flatten,
clippy::map_unwrap_or,
clippy::match_on_vec_items,
clippy::match_wildcard_for_single_variants,
clippy::mem_forget,
clippy::mismatched_target_os,
clippy::needless_borrow,
clippy::needless_continue,
clippy::option_option,
clippy::pub_enum_variant_names,
clippy::ref_option_ref,
clippy::rest_pat_in_fully_bound_structs,
clippy::string_to_string,
clippy::suboptimal_flops,
clippy::todo,
clippy::unnested_or_patterns,
clippy::unused_self,
clippy::verbose_file_reads,
future_incompatible,
nonstandard_style,
rust_2018_idioms
)]
// END - Embark standard lints v0.2
// crate-specific exceptions:
#![allow(
unsafe_code, // this is a safe wrapper of unsafe code, so plenty of unsafe code in here
clippy::doc_markdown, // TODO: fixup comments and docs (though annoyingly complains about "PhysX")
clippy::pub_enum_variant_names, // TODO: revisit, will change API, remove from standard set?
)]

// Utility traits
pub mod traits;

Expand Down
1 change: 1 addition & 0 deletions physx/src/owner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ impl<T> Owner<T> {
}

/// Consumes the Owner without calling Drop and returns the raw pointer it was wrapping.
#[allow(clippy::mem_forget)]
pub fn into_ptr<S>(mut self) -> *mut S
where
T: Class<S>,
Expand Down
4 changes: 1 addition & 3 deletions physx/src/physics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -717,9 +717,7 @@ impl<Allocator: AllocatorCallback> PhysicsFoundationBuilder<Allocator> {
unsafe {
phys_PxInitExtensions(
physics.as_mut_ptr(),
pvd.as_mut()
.map(|pv| pv.as_mut_ptr())
.unwrap_or_else(null_mut),
pvd.as_mut().map_or_else(null_mut, |pv| pv.as_mut_ptr()),
)
}
} else {
Expand Down
14 changes: 7 additions & 7 deletions physx/src/scene.rs
Original file line number Diff line number Diff line change
Expand Up @@ -569,7 +569,7 @@ pub trait Scene: Class<physx_sys::PxScene> + UserData {
completion_task: Option<&mut PxBaseTask>,
scratch: Option<&mut ScratchBuffer>,
) {
let completion_task = completion_task.map(|t| t as *mut _).unwrap_or(null_mut());
let completion_task = completion_task.map_or(null_mut(), |t| t as *mut _);

let (scratch_ptr, scratch_size) = if let Some(scratch) = scratch {
scratch.as_ptr_and_size()
Expand Down Expand Up @@ -761,19 +761,19 @@ pub trait Scene: Class<physx_sys::PxScene> + UserData {
// Callbacks

/// # Safety
/// PxContactModifyCallback does not have a safe wrapper, using it requires use of physx_sys.
/// PxContactModifyCallback does not have a safe wrapper, using it requires use of [`physx_sys`].
unsafe fn set_contact_modify_callback(&mut self, callback: &mut PxContactModifyCallback) {
PxScene_setContactModifyCallback_mut(self.as_mut_ptr(), callback);
}

/// # Safety
/// PxContactModifyCallback does not have a safe wrapper, using it requires use of physx_sys.
/// PxContactModifyCallback does not have a safe wrapper, using it requires use of [`physx_sys`].
unsafe fn get_contact_modify_callback(&self) -> &PxContactModifyCallback {
&*PxScene_getContactModifyCallback(self.as_ptr())
}

/// # Safety
/// PxCCDContactModifyCallback does not have a safe wrapper, using it requires use of physx_sys.
/// PxCCDContactModifyCallback does not have a safe wrapper, using it requires use of [`physx_sys`].
unsafe fn set_ccd_contact_modify_callback(
&mut self,
callback: &mut PxCCDContactModifyCallback,
Expand All @@ -782,19 +782,19 @@ pub trait Scene: Class<physx_sys::PxScene> + UserData {
}

/// # Safety
/// PxCCDContactModifyCallback does not have a safe wrapper, using it requires use of physx_sys.
/// PxCCDContactModifyCallback does not have a safe wrapper, using it requires use of [`physx_sys`].
unsafe fn get_ccd_contact_callback(&self) -> &PxCCDContactModifyCallback {
&*PxScene_getCCDContactModifyCallback(self.as_ptr())
}

/// # Safety
/// PxBroadPhaseCallback does not have a safe wrapper, using it requires use of physx_sys.
/// PxBroadPhaseCallback does not have a safe wrapper, using it requires use of [`physx_sys`].
unsafe fn set_broad_phase_callback(&mut self, callback: &mut PxBroadPhaseCallback) {
PxScene_setBroadPhaseCallback_mut(self.as_mut_ptr(), callback);
}

/// # Safety
/// PxBroadPhaseCallback does not have a safe wrapper, using it requires use of physx_sys.
/// PxBroadPhaseCallback does not have a safe wrapper, using it requires use of [`physx_sys`].
unsafe fn get_broad_phase_callback(&self) -> &PxBroadPhaseCallback {
&*PxScene_getBroadPhaseCallback(self.as_ptr())
}
Expand Down
35 changes: 15 additions & 20 deletions physx/src/simulation_event_callback.rs
Original file line number Diff line number Diff line change
Expand Up @@ -84,21 +84,16 @@ where
OA: AdvanceCallback<L, D>,
{
unsafe {
let (collision_callback, collision_user_data) = on_collide
.map(OC::into_cb_user_data)
.unwrap_or((None, null_mut()));
let (trigger_callback, trigger_user_data) = on_trigger
.map(OT::into_cb_user_data)
.unwrap_or((None, null_mut()));
let (constraint_break_callback, constraint_break_user_data) = on_constraint_break
.map(OCB::into_cb_user_data)
.unwrap_or((None, null_mut()));
let (wake_sleep_callback, wake_sleep_user_data) = on_wake_sleep
.map(OWS::into_cb_user_data)
.unwrap_or((None, null_mut()));
let (advance_callback, advance_user_data) = on_advance
.map(OA::into_cb_user_data)
.unwrap_or((None, null_mut()));
let (collision_callback, collision_user_data) =
on_collide.map_or((None, null_mut()), OC::into_cb_user_data);
let (trigger_callback, trigger_user_data) =
on_trigger.map_or((None, null_mut()), OT::into_cb_user_data);
let (constraint_break_callback, constraint_break_user_data) =
on_constraint_break.map_or((None, null_mut()), OCB::into_cb_user_data);
let (wake_sleep_callback, wake_sleep_user_data) =
on_wake_sleep.map_or((None, null_mut()), OWS::into_cb_user_data);
let (advance_callback, advance_user_data) =
on_advance.map_or((None, null_mut()), OA::into_cb_user_data);

Owner::from_raw(
create_simulation_event_callbacks(&SimulationEventCallbackInfo {
Expand Down Expand Up @@ -239,8 +234,8 @@ trait ConstraintBreakCallbackRaw: ConstraintBreakCallback {
}
}

/// A trait for onWake() and onSleep() callbacks. Parametrized by the ArticulationLink,
/// RigidStatic, and RigidDynamic types of the scene it is in.
/// A trait for `onWake()` and `onSleep()` callbacks. Parametrized by the [`ArticulationLink`],
/// [`RigidStatic`], and [`RigidDynamic`] types of the scene it is in.
pub trait WakeSleepCallback<L: ArticulationLink, S: RigidStatic, D: RigidDynamic>: Sized {
fn on_wake_sleep(&mut self, actors: &[&ActorMap<L, S, D>], is_waking: bool);
}
Expand Down Expand Up @@ -282,10 +277,10 @@ where
}

/// A trait for the Advance Callback. onAdvance() is called during simulation, so it must
/// be thread safe, and `self` is not mutable. Parametrized by the ArticulationLink
/// and RigidDynamic types of the scene it is in.
/// be thread safe, and `self` is not mutable. Parametrized by the `ArticulationLink`
/// and `RigidDynamic` types of the scene it is in.
pub trait AdvanceCallback<L: ArticulationLink, D: RigidDynamic>: Sized {
/// All actors with PxRigidBodyFlag::eENABLE_POSE_INTEGRATION_PREVIEW set will be passed into here
/// All actors with `PxRigidBodyFlag::eENABLE_POSE_INTEGRATION_PREVIEW` set will be passed into here
/// once the simulate call has updated their position.
fn on_advance(&self, actors: &[&RigidBodyMap<L, D>], transforms: &[PxTransform]);
}
Expand Down
Loading

0 comments on commit b24b76b

Please sign in to comment.