#![warn(missing_docs)]
#![forbid(unsafe_code)]
#![warn(
clippy::nursery,
clippy::pedantic,
clippy::unwrap_used,
nonstandard_style,
rustdoc::broken_intra_doc_links
)]
#![allow(
clippy::default_trait_access,
clippy::module_name_repetitions,
clippy::redundant_pub_crate
)]
pub use components::*;
pub use config::*;
mod components;
mod config;
mod systems;
use bevy::{log, prelude::*, time::common_conditions::on_timer};
use std::time::Duration;
use systems::{
points::update_points,
sticks::{handle_stick_constraints, update_sticks},
};
pub mod prelude {
pub use crate::{components::*, config::*, VerletPlugin};
}
#[derive(Debug, Copy, Clone, Default)]
pub struct VerletPlugin {
pub time_step: Option<f64>,
}
impl Plugin for VerletPlugin {
fn build(&self, app: &mut App) {
app.init_resource::<VerletConfig>();
let system_set = (update_points, update_sticks, handle_stick_constraints).chain();
if let Some(step) = self.time_step {
app.add_systems(
FixedUpdate,
system_set.run_if(on_timer(Duration::from_secs_f64(step))),
);
} else {
app.add_systems(FixedUpdate, system_set);
}
#[cfg(feature = "debug")]
{
app.add_systems(PostUpdate, systems::debug::debug_draw_sticks);
}
app.register_type::<VerletPoint>()
.register_type::<VerletLocked>()
.register_type::<VerletStick>()
.register_type::<VerletStickMaxTension>();
log::info!("Loaded verlet plugin");
}
}
impl VerletPlugin {
#[must_use]
#[inline]
pub const fn new(time_step: f64) -> Self {
Self {
time_step: Some(time_step),
}
}
}