#![forbid(missing_docs)]
#![forbid(unsafe_code)]
#![warn(
clippy::nursery,
clippy::pedantic,
nonstandard_style,
rustdoc::broken_intra_doc_links
)]
#![allow(
clippy::default_trait_access,
clippy::module_name_repetitions,
clippy::redundant_pub_crate
)]
pub use {components::*, resources::*};
mod components;
mod resources;
mod systems;
use crate::verlet_time_step::VerletTimeStep;
use bevy::log;
use bevy::prelude::*;
use bevy::time::FixedTimestep;
#[cfg(feature = "debug")]
use bevy_prototype_debug_lines::DebugLinesPlugin;
pub mod prelude {
pub use crate::components::*;
pub use crate::resources::*;
pub use crate::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 = SystemSet::new()
.with_system(systems::points::update_points.label("VERLET_UPDATE_POINTS"))
.with_system(
systems::sticks::update_sticks
.label("VERLET_UPDATE_STICKS")
.after("VERLET_UPDATE_POINTS"),
)
.with_system(systems::sticks::handle_stick_constraints.after("VERLET_UPDATE_STICKS"));
let system_set = if let Some(step) = self.time_step {
app.insert_resource(VerletTimeStep::FixedDeltaTime(step));
system_set.with_run_criteria(FixedTimestep::step(step))
} else {
app.insert_resource(VerletTimeStep::DeltaTime);
system_set
};
app.add_system_set(system_set);
#[cfg(feature = "debug")]
{
app.add_plugin(DebugLinesPlugin::default());
app.add_system(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),
}
}
}