use std::fmt::Debug;
use std::marker;
use std::ops::Mul;
use cgmath::{BaseFloat, EuclideanSpace, InnerSpace, Rotation, VectorSpace, Zero};
use core::{next_frame_integration, next_frame_pose, ApplyAngular, BodyPose, ForceAccumulator,
Inertia, Mass, NextFrame, Velocity};
use specs::{Fetch, Join, ReadStorage, System, WriteStorage};
use physics::resources::DeltaTime;
pub struct NextFrameSetupSystem<P, R, I, A> {
m: marker::PhantomData<(P, R, I, A)>,
}
impl<P, R, I, A> NextFrameSetupSystem<P, R, I, A>
where
P: EuclideanSpace,
P::Scalar: BaseFloat,
P::Diff: VectorSpace + InnerSpace + Debug,
R: Rotation<P> + ApplyAngular<P::Scalar, A>,
I: Inertia<Orientation = R> + Mul<A, Output = A>,
A: Mul<P::Scalar, Output = A> + Zero + Clone + Copy,
{
pub fn new() -> Self {
Self {
m: marker::PhantomData,
}
}
}
impl<'a, P, R, I, A> System<'a> for NextFrameSetupSystem<P, R, I, A>
where
P: EuclideanSpace + Send + Sync + 'static,
P::Scalar: BaseFloat + Send + Sync + 'static,
P::Diff: VectorSpace + InnerSpace + Debug + Send + Sync + 'static,
R: Rotation<P> + ApplyAngular<P::Scalar, A> + Send + Sync + 'static,
I: Inertia<Orientation = R> + Mul<A, Output = A> + Send + Sync + 'static,
A: Mul<P::Scalar, Output = A> + Zero + Clone + Copy + Send + Sync + 'static,
{
type SystemData = (
Fetch<'a, DeltaTime<P::Scalar>>,
ReadStorage<'a, Mass<P::Scalar, I>>,
WriteStorage<'a, NextFrame<Velocity<P::Diff, A>>>,
ReadStorage<'a, BodyPose<P, R>>,
WriteStorage<'a, NextFrame<BodyPose<P, R>>>,
WriteStorage<'a, ForceAccumulator<P::Diff, A>>,
);
fn run(&mut self, data: Self::SystemData) {
let (time, masses, mut next_velocities, poses, mut next_poses, mut forces) = data;
next_frame_integration(
(&mut next_velocities, &next_poses, &mut forces, &masses).join(),
time.delta_seconds,
);
next_frame_pose(
(&next_velocities, &poses, &mut next_poses).join(),
time.delta_seconds,
);
}
}