diff --git a/.github/workflows/rust.yml b/.github/workflows/rust.yml index 57ecd95..0864853 100644 --- a/.github/workflows/rust.yml +++ b/.github/workflows/rust.yml @@ -60,6 +60,9 @@ jobs: runs-on: ubuntu-latest steps: - uses: actions/checkout@v3 + - uses: dtolnay/rust-toolchain@nightly + with: + components: "rustfmt" - name: Check Formatting run: cargo fmt --all -- --check diff --git a/README.md b/README.md index 921c188..68b8f87 100644 --- a/README.md +++ b/README.md @@ -27,11 +27,14 @@ If you are looking for cloth physics, please check [`bevy_silk`](https://github. ## Features -You can simply add a `VerletPoint` component on any entity with a `Transform` and the verlet physics will apply. +You can simply add a `VerletPoint` component on any entity with a +`Transform` and the verlet physics will apply. -Connect points using `VerletStick` to constrain movement (see [examples](./examples)). +Connect points using `VerletStick` to constrain movement (see +[examples](./examples)). -Lock some points by adding the `VerletLocked` component on a `VerletPoint` entity. +Lock some points by adding the `VerletLocked` component on a `VerletPoint` +entity. Customize *friction* and *gravity* with the `VerletConfig` resource. @@ -41,8 +44,8 @@ Customize *friction* and *gravity* with the `VerletConfig` resource. 1. `debug` -This feature will add a *system* drawing debug lines for every stick using bevy gizmos - +This feature will add a *system* drawing debug lines for every stick using +bevy gizmos diff --git a/src/components/mod.rs b/src/components/mod.rs index 01b6428..ba4eee7 100644 --- a/src/components/mod.rs +++ b/src/components/mod.rs @@ -1,4 +1,7 @@ -pub use {locked::*, point::*, stick::*, stick_max_tension::*}; +pub use locked::*; +pub use point::*; +pub use stick::*; +pub use stick_max_tension::*; mod locked; mod point; diff --git a/src/components/stick_max_tension.rs b/src/components/stick_max_tension.rs index 9f6f4dc..20fce36 100644 --- a/src/components/stick_max_tension.rs +++ b/src/components/stick_max_tension.rs @@ -3,10 +3,12 @@ use std::ops::Deref; /// Component adding a maximum tension to a [`VerletStick`]. /// -/// The stick will break when its size becomes bigger than its `length` multiplied by this factor +/// The stick will break when its size becomes bigger than its `length` +/// multiplied by this factor /// /// If you set it to `1.0` the stick will break almost instantly -/// If you set it to `2.0` the stick will break when stretched to twice its `length` +/// If you set it to `2.0` the stick will break when stretched to twice its +/// `length` /// /// [`VerletStick`]: crate::VerletStick #[derive(Debug, Copy, Clone, Component, Reflect)] diff --git a/src/lib.rs b/src/lib.rs index 05fe5df..56592b8 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -15,11 +15,14 @@ //! //! ## Features //! -//! You can simply add a `VerletPoint` component on any entity with a `Transform` and the verlet physics will apply. +//! You can simply add a `VerletPoint` component on any entity with a +//! `Transform` and the verlet physics will apply. //! -//! Connect points using `VerletStick` to constrain movement (see [examples](./examples)). +//! Connect points using `VerletStick` to constrain movement (see +//! [examples](./examples)). //! -//! Lock some points by adding the `VerletLocked` component on a `VerletPoint` entity. +//! Lock some points by adding the `VerletLocked` component on a `VerletPoint` +//! entity. //! //! Customize *friction* and *gravity* with the `VerletConfig` resource. //! @@ -29,8 +32,8 @@ //! //! 1. `debug` //! -//! This feature will add a *system* drawing debug lines for every stick using bevy gizmos -//! +//! This feature will add a *system* drawing debug lines for every stick using +//! bevy gizmos #![warn(missing_docs)] #![forbid(unsafe_code)] #![warn( @@ -45,16 +48,15 @@ clippy::redundant_pub_crate )] -pub use {components::*, resources::*}; +pub use components::*; +pub use resources::*; mod components; mod resources; mod systems; use crate::verlet_time_step::VerletTimeStep; -use bevy::log; -use bevy::prelude::*; -use bevy::time::common_conditions::on_fixed_timer; +use bevy::{log, prelude::*, time::common_conditions::on_fixed_timer}; use std::time::Duration; use systems::{ points::update_points, @@ -63,14 +65,13 @@ use systems::{ /// Prelude pub mod prelude { - pub use crate::components::*; - pub use crate::resources::*; - pub use crate::VerletPlugin; + pub use crate::{components::*, resources::*, VerletPlugin}; } /// Plugin for Verlet physics #[derive(Debug, Copy, Clone, Default)] pub struct VerletPlugin { - /// Custom time step in seconds for verlet physics, if set to `None` physics will run every frame + /// Custom time step in seconds for verlet physics, if set to `None` physics + /// will run every frame pub time_step: Option, } diff --git a/src/resources/config.rs b/src/resources/config.rs index 4ff6e2d..3696a1e 100644 --- a/src/resources/config.rs +++ b/src/resources/config.rs @@ -1,17 +1,21 @@ -use bevy::ecs::prelude::Resource; -use bevy::math::{Vec2, Vec3, Vec3Swizzles}; +use bevy::{ + ecs::prelude::Resource, + math::{Vec2, Vec3, Vec3Swizzles}, +}; /// Verlet physics configuration #[derive(Debug, Copy, Clone, Resource)] pub struct VerletConfig { /// Custom gravity, classic (0, -9.81, 0) is used by default pub gravity: Vec3, - /// Custom friction to apply to velocity, slowing down the simulation and reducing elasticity. + /// Custom friction to apply to velocity, slowing down the simulation and + /// reducing elasticity. /// /// Note: will be clamped between 0.0 and 1.0 pub friction: f32, /// Sets the number of sticks computation iteration. - /// The higher the value, the more precision and less elasticity for the sticks but the cost is increased + /// The higher the value, the more precision and less elasticity for the + /// sticks but the cost is increased pub sticks_computation_depth: u8, /// Enables parallel computing for points pub parallel_processing: bool, diff --git a/src/systems/points.rs b/src/systems/points.rs index 47c1f4d..31b05cc 100644 --- a/src/systems/points.rs +++ b/src/systems/points.rs @@ -1,6 +1,7 @@ -use crate::components::{VerletLocked, VerletPoint}; -use crate::resources::verlet_time_step::VerletTimeStep; -use crate::resources::VerletConfig; +use crate::{ + components::{VerletLocked, VerletPoint}, + resources::{verlet_time_step::VerletTimeStep, VerletConfig}, +}; use bevy::prelude::*; fn update_point( @@ -36,7 +37,7 @@ pub fn update_points( update_point(&mut transform, &mut point, gravity, friction); }); } else { - for (mut transform, mut point) in points_query.iter_mut() { + for (mut transform, mut point) in &mut points_query { update_point(&mut transform, &mut point, gravity, friction); } } diff --git a/src/systems/sticks.rs b/src/systems/sticks.rs index 0cadb01..943ce96 100644 --- a/src/systems/sticks.rs +++ b/src/systems/sticks.rs @@ -1,8 +1,9 @@ #![allow(clippy::needless_pass_by_value)] -use crate::components::{VerletLocked, VerletPoint, VerletStick}; -use crate::{VerletConfig, VerletStickMaxTension}; -use bevy::log; -use bevy::prelude::*; +use crate::{ + components::{VerletLocked, VerletPoint, VerletStick}, + VerletConfig, VerletStickMaxTension, +}; +use bevy::{log, prelude::*}; #[allow( clippy::type_complexity,