Skip to content

Commit

Permalink
Rust 1.72.0
Browse files Browse the repository at this point in the history
  • Loading branch information
ManevilleF committed Aug 25, 2023
1 parent b4b0896 commit 39c78d3
Show file tree
Hide file tree
Showing 8 changed files with 51 additions and 33 deletions.
3 changes: 3 additions & 0 deletions .github/workflows/rust.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
13 changes: 8 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand All @@ -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

<!-- cargo-sync-readme end -->

Expand Down
5 changes: 4 additions & 1 deletion src/components/mod.rs
Original file line number Diff line number Diff line change
@@ -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;
Expand Down
6 changes: 4 additions & 2 deletions src/components/stick_max_tension.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)]
Expand Down
27 changes: 14 additions & 13 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
//!
Expand All @@ -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(
Expand All @@ -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,
Expand All @@ -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<f64>,
}

Expand Down
12 changes: 8 additions & 4 deletions src/resources/config.rs
Original file line number Diff line number Diff line change
@@ -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,
Expand Down
9 changes: 5 additions & 4 deletions src/systems/points.rs
Original file line number Diff line number Diff line change
@@ -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(
Expand Down Expand Up @@ -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);
}
}
Expand Down
9 changes: 5 additions & 4 deletions src/systems/sticks.rs
Original file line number Diff line number Diff line change
@@ -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,
Expand Down

0 comments on commit 39c78d3

Please sign in to comment.