use amethyst_core::{
ecs::{Entities, Join, ReadExpect, ReadStorage, System, WriteStorage},
transform::components::{Parent, Transform},
};
use crate::{conversors, objects::*, servers::*};
pub struct PhysicsSyncTransformFromSystem<N: crate::PtReal> {
phantom_data: std::marker::PhantomData<N>,
}
impl<N: crate::PtReal> PhysicsSyncTransformFromSystem<N> {
pub fn new() -> PhysicsSyncTransformFromSystem<N> {
PhysicsSyncTransformFromSystem {
phantom_data: std::marker::PhantomData,
}
}
}
impl<'s, N: crate::PtReal> System<'s> for PhysicsSyncTransformFromSystem<N> {
#[allow(clippy::type_complexity)]
type SystemData = (
Entities<'s>,
ReadExpect<'s, PhysicsWorld<N>>,
WriteStorage<'s, Transform>,
ReadStorage<'s, PhysicsHandle<PhysicsRigidBodyTag>>,
ReadStorage<'s, Parent>,
);
fn run(
&mut self,
(entities, physics_world, mut transforms, bodies, parents): Self::SystemData,
) {
let transf_mask = transforms.mask().clone();
for (entity, rb, _, _) in (&entities, &bodies, &transf_mask, !&parents).join() {
if let Some(transform) = transforms.get_mut(entity) {
let body_transform = physics_world.rigid_body_server().transform(rb.get());
transform.set_isometry(conversors::transf_conversor::from_physics(&body_transform));
}
}
}
}