Skip to content

Commit

Permalink
lint/format files (#138)
Browse files Browse the repository at this point in the history
Update README.md

Update README.md
  • Loading branch information
Ughuuu committed Jul 3, 2024
1 parent 0ff33c9 commit 9630e6b
Show file tree
Hide file tree
Showing 17 changed files with 133 additions and 68 deletions.
14 changes: 7 additions & 7 deletions Cargo.lock

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

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ publish = false
crate-type = ["cdylib"]

[features]
default = ["single-dim3", "serde-serialize", "parallel", "simd-stable"]
default = ["single-dim2", "serde-serialize", "parallel", "simd-stable"]
dim2 = []
dim3 = []
single = []
Expand Down
23 changes: 17 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,23 @@

Godot Rapier Physics is a 2D and 3D physics drop-in replacement for the [Godot game engine](https://github.com/godotengine/godot) that adds stability through [rapier](https://github.com/dimforge/rapier) and fluids through [salva](https://github.com/dimforge/salva).

# Performance

Creating objects until FPS drops below 30. Running on a macbook m2 pro. Everything is run inside the godot editor using the [Godot Physics Tests](https://github.com/fabriceci/Godot-Physics-Tests) repository.

Each cell shows max shape count. Higher number is better.

Shape|Godot 2D|Godot 3D|Rapier 2D (C++)|Rapier 2D (Rust)|Rapier 3D (Rust)|Jolt 3D
-|-|-|-|-|-|-
Sphere|5000|3300|8800|5000|4200|8000
Box|3500|3200|7700|4500|4000|7200
Capsule|4500|2700|8000|4500|3700|7400
Convex Polygon|3500|3100|6500|4000|4000|8000

# Note

This plugin was recently rewritten from C++ to Rust. There are still some things missing from what it had originally and performance is slower than it used to be. This is to be considered beta and still work in progress.

# Installation

- Automatic (Recommended): Download the plugin from the official [Godot Asset Store](https://godotengine.org/asset-library/asset/2267) using the `AssetLib` tab in Godot:
Expand All @@ -41,12 +58,6 @@ After installing, go to `Advanced Settings` -> `Physics` -> `2D` or `3D`. Change
<img src="docs/rapier-vid.gif"/>
</p>

# Note

This plugin was recently rewritten from c++ to rust. There are still some things missing from what it had originally and may have some new bugs that it didn't have before.

The reason it was rewritten is to do easier cross platform determinism part and exports to web.

# Limitations

- SeparationRayShape2D, ConcavePolygonShape3D, HeightMapShape3D, 3D joints.
Expand Down
4 changes: 4 additions & 0 deletions src/bodies/rapier_area.rs
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,7 @@ impl RapierArea {
}
}

#[allow(clippy::too_many_arguments)]
pub fn on_body_enter(
&mut self,
collider_handle: ColliderHandle,
Expand Down Expand Up @@ -213,6 +214,7 @@ impl RapierArea {
}
}

#[allow(clippy::too_many_arguments)]
pub fn on_body_exit(
&mut self,
collider_handle: ColliderHandle,
Expand Down Expand Up @@ -266,6 +268,7 @@ impl RapierArea {
}
}

#[allow(clippy::too_many_arguments)]
pub fn on_area_enter(
&mut self,
collider_handle: ColliderHandle,
Expand Down Expand Up @@ -309,6 +312,7 @@ impl RapierArea {
}
}

#[allow(clippy::too_many_arguments)]
pub fn on_area_exit(
&mut self,
collider_handle: ColliderHandle,
Expand Down
2 changes: 2 additions & 0 deletions src/bodies/rapier_body.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ use godot::classes::physics_server_2d::*;
use godot::classes::physics_server_3d::*;
use godot::prelude::*;
use hashbrown::hash_set::HashSet;
#[cfg(feature = "dim3")]
use rapier::dynamics::LockedAxes;
use rapier::geometry::ColliderHandle;
use rapier::math::Real;
Expand Down Expand Up @@ -730,6 +731,7 @@ impl RapierBody {
!self.contacts.is_empty()
}

#[allow(clippy::too_many_arguments)]
pub fn add_contact(
&mut self,
local_pos: Vector,
Expand Down
6 changes: 4 additions & 2 deletions src/bodies/rapier_collision_object.rs
Original file line number Diff line number Diff line change
Expand Up @@ -370,8 +370,10 @@ impl RapierCollisionObject {
self.space = Rid::Invalid;
return;
}
let mut user_data = UserData::default();
user_data.part1 = self.rid.to_u64();
let user_data = UserData {
part1: self.rid.to_u64(),
..Default::default()
};
let position = vector_to_rapier(self.transform.origin);
let angle = transform_rotation_rapier(&self.transform);
if self.mode == BodyMode::STATIC {
Expand Down
2 changes: 0 additions & 2 deletions src/fluids/rapier_fluid.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ use crate::types::Vector;
//#[derive(Serialize, Deserialize, Debug)]
pub struct RapierFluid {
rid: Rid,
enabled: bool,
density: f64,
space: Rid,
effects: Array<Gd<Resource>>,
Expand All @@ -21,7 +20,6 @@ impl RapierFluid {
pub fn new(rid: Rid) -> Self {
Self {
rid,
enabled: true,
density: 1.0,
space: Rid::Invalid,
effects: Array::default(),
Expand Down
11 changes: 8 additions & 3 deletions src/rapier_wrapper/body.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,11 @@ impl PhysicsEngine {
rigid_body = RigidBodyBuilder::fixed().build();
}
}
// let default values better
let activation = rigid_body.activation_mut();
let default_activation = RigidBodyActivation::default();
activation.angular_threshold = default_activation.angular_threshold;
activation.normalized_linear_threshold = default_activation.normalized_linear_threshold;
activation.time_until_sleep = 0.5;
set_rigid_body_properties_internal(&mut rigid_body, pos, rot, true);
rigid_body.user_data = user_data.get_data();
physics_world
Expand Down Expand Up @@ -367,8 +371,8 @@ impl PhysicsEngine {
activation.angular_threshold = default_activation.angular_threshold;
activation.normalized_linear_threshold =
default_activation.normalized_linear_threshold;
activation.time_until_sleep = 0.5;
}
// TODO: Check if is requiered
if !can_sleep && body.is_sleeping() {
body.wake_up(true);
}
Expand All @@ -391,6 +395,7 @@ impl PhysicsEngine {
}
}

#[allow(clippy::too_many_arguments)]
pub fn body_set_mass_properties(
&mut self,
world_handle: WorldHandle,
Expand Down Expand Up @@ -438,7 +443,7 @@ impl PhysicsEngine {
//collider.set_density(colliders_len_inv)
}
}
let props = MassProperties::new(Point { coords: _local_com }, mass, inertia);
let _props = MassProperties::new(Point { coords: _local_com }, mass, inertia);
//body.set_additional_mass_properties(props, true);
if force_update {
body.recompute_mass_properties_from_colliders(
Expand Down
4 changes: 4 additions & 0 deletions src/rapier_wrapper/joint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ use rapier::prelude::*;
use crate::rapier_wrapper::prelude::*;
impl PhysicsEngine {
#[cfg(feature = "dim2")]
#[allow(clippy::too_many_arguments)]
pub fn joint_create_revolute(
&mut self,
world_handle: WorldHandle,
Expand Down Expand Up @@ -34,6 +35,7 @@ impl PhysicsEngine {
ImpulseJointHandle::invalid()
}

#[allow(clippy::too_many_arguments)]
pub fn joint_change_revolute_params(
&mut self,
world_handle: WorldHandle,
Expand Down Expand Up @@ -64,6 +66,7 @@ impl PhysicsEngine {
}
}

#[allow(clippy::too_many_arguments)]
pub fn joint_create_prismatic(
&mut self,
world_handle: WorldHandle,
Expand All @@ -86,6 +89,7 @@ impl PhysicsEngine {
ImpulseJointHandle::invalid()
}

#[allow(clippy::too_many_arguments)]
pub fn joint_create_spring(
&mut self,
world_handle: WorldHandle,
Expand Down
10 changes: 6 additions & 4 deletions src/rapier_wrapper/physics_world.rs
Original file line number Diff line number Diff line change
Expand Up @@ -110,10 +110,12 @@ impl PhysicsWorld {
space: &mut RapierSpace,
physics_collision_objects: &mut PhysicsCollisionObjects,
) {
let mut integration_parameters = IntegrationParameters::default();
integration_parameters.length_unit = settings.length_unit;
integration_parameters.dt = settings.dt;
integration_parameters.max_ccd_substeps = settings.max_ccd_substeps;
let mut integration_parameters = IntegrationParameters {
length_unit: settings.length_unit,
dt: settings.dt,
max_ccd_substeps: settings.max_ccd_substeps,
..Default::default()
};
if let Some(iterations) = NonZeroUsize::new(settings.num_solver_iterations) {
integration_parameters.num_solver_iterations = iterations;
}
Expand Down
24 changes: 13 additions & 11 deletions src/rapier_wrapper/query.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ pub struct QueryExcludedInfo {
pub query_exclude_body: i64,
}
impl PhysicsEngine {
#[allow(clippy::too_many_arguments)]
pub fn intersect_ray(
&self,
world_handle: WorldHandle,
Expand Down Expand Up @@ -143,6 +144,7 @@ impl PhysicsEngine {
result
}

#[allow(clippy::too_many_arguments)]
pub fn intersect_point(
&self,
world_handle: WorldHandle,
Expand All @@ -156,7 +158,7 @@ impl PhysicsEngine {
space: &RapierSpace,
) -> usize {
let mut cpt_hit = 0;
if hit_info_length <= 0 {
if hit_info_length == 0 {
return cpt_hit;
}
if let Some(physics_world) = self.get_world(world_handle) {
Expand Down Expand Up @@ -229,10 +231,10 @@ impl PhysicsEngine {
let shared_shape2 = scale_shape(raw_shared_shape2, shape_info2);
let shape_transform1 = shape_info1.transform;
let shape_transform2 = shape_info2.transform;
let mut shape_cast_options = ShapeCastOptions::default();
shape_cast_options.max_time_of_impact = 1.0;
shape_cast_options.compute_impact_geometry_on_penetration = true;
shape_cast_options.stop_at_penetration = true;
let shape_cast_options = ShapeCastOptions {
max_time_of_impact: 1.0,
..Default::default()
};
let toi_result = parry::query::cast_shapes(
&shape_transform1,
&shape_vel1,
Expand Down Expand Up @@ -261,6 +263,7 @@ impl PhysicsEngine {
result
}

#[allow(clippy::too_many_arguments)]
pub fn shape_casting(
&self,
world_handle: WorldHandle,
Expand Down Expand Up @@ -297,12 +300,10 @@ impl PhysicsEngine {
)
};
filter.predicate = Some(&predicate);
let mut shape_cast_options = ShapeCastOptions::default();
//shape_cast_options.max_time_of_impact = Real::MAX;
shape_cast_options.max_time_of_impact = 1.0;
shape_cast_options.compute_impact_geometry_on_penetration = true;
shape_cast_options.stop_at_penetration = true;
shape_cast_options.target_distance = 0.0;
let shape_cast_options = ShapeCastOptions {
max_time_of_impact: 1.0,
..Default::default()
};
if let Some((collider_handle, hit)) =
physics_world.physics_objects.query_pipeline.cast_shape(
&physics_world.physics_objects.rigid_body_set,
Expand Down Expand Up @@ -341,6 +342,7 @@ impl PhysicsEngine {
result
}

#[allow(clippy::too_many_arguments)]
pub fn intersect_aabb(
&self,
world_handle: WorldHandle,
Expand Down
3 changes: 1 addition & 2 deletions src/rapier_wrapper/shape.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,7 @@ impl PhysicsEngine {
pub fn shape_create_halfspace(&mut self, normal: Vector<Real>, distance: Real) -> ShapeHandle {
let shape = SharedShape::halfspace(UnitVector::new_normalize(normal));
let shape_position = Isometry::new(normal * distance, ANG_ZERO);
let mut shapes_vec = Vec::new();
shapes_vec.push((shape_position, shape));
let shapes_vec = vec![(shape_position, shape)];
let shape_compound = SharedShape::compound(shapes_vec);
self.insert_shape(shape_compound)
}
Expand Down
Loading

0 comments on commit 9630e6b

Please sign in to comment.