commit 3f889391869b1866d6b1506e64150c1db8d17434
parent dcdf352fa1884b74453ac54c79f871f7108ae163
Author: kel <distransient@protonmail.com>
Date: Thu, 31 Jan 2019 19:04:07 -0500
Fix lints
Diffstat:
5 files changed, 23 insertions(+), 23 deletions(-)
diff --git a/src/systems/mod.rs b/src/systems/mod.rs
@@ -4,10 +4,10 @@ mod sync_bodies_to_physics;
mod sync_colliders_to_physics;
mod sync_gravity_to_physics;
-use core::result::Result;
use amethyst::core::bundle::SystemBundle;
use amethyst::core::specs::DispatcherBuilder;
use amethyst::error::Error;
+use core::result::Result;
use crate::time_step::TimeStep;
diff --git a/src/systems/physics_stepper.rs b/src/systems/physics_stepper.rs
@@ -2,6 +2,7 @@ use crate::time_step::TimeStep;
use crate::PhysicsWorld;
use amethyst::core::Time;
use amethyst::ecs::{Read, System, WriteExpect};
+use std::f32::EPSILON;
use std::time::Instant;
/// Falloff factor for calculating the moving average step time.
@@ -91,10 +92,12 @@ impl<'a> System<'a> for PhysicsStepperSystem {
timestep
}
};
- if physical_world.timestep() != timestep && !change_timestep {
+
+ if (physical_world.timestep() - timestep).abs() < EPSILON && !change_timestep {
warn!("Physics world timestep out of sync with intended timestep! Leave me alone!!!");
change_timestep = true;
}
+
if change_timestep {
// reset average when changing timestep
self.avg_step_time = None;
diff --git a/src/systems/sync_bodies_from_physics.rs b/src/systems/sync_bodies_from_physics.rs
@@ -83,12 +83,12 @@ impl<'a> System<'a> for SyncBodiesFromPhysicsSystem {
.prepend_nonuniform_scaling(
&local_transform
.as_ref()
- .map(|tr| tr.scale().clone())
- .unwrap_or(Vector3::new(1.0, 1.0, 1.0)),
+ .map(|tr| *tr.scale())
+ .unwrap_or_else(|| Vector3::new(1.0, 1.0, 1.0)),
);
if let Some(ref mut local_transform) = local_transform {
- *local_transform.isometry_mut() = updated_body.position().clone();
+ *local_transform.isometry_mut() = updated_body.position();
}
trace!(
diff --git a/src/systems/sync_bodies_to_physics.rs b/src/systems/sync_bodies_to_physics.rs
@@ -103,22 +103,19 @@ impl<'a> System<'a> for SyncBodiesToPhysicsSystem {
trace!("Velocity and external forces applied, external forces reset to zero, for body with handle: {:?}", body.handle);
} else if modified_transforms.contains(id) || modified_physics_bodies.contains(id) {
trace!("Detected changed dynamics body with id {}", id);
- match physical_world.rigid_body_mut(body.handle.unwrap()) {
- Some(physical_body) => {
- let position: Isometry<f32> = try_convert(transform.0).unwrap();
- trace!(
- "Updating rigid body in physics world with isometry: {}",
- position
- );
- physical_body.set_position(position);
-
- physical_body.set_velocity(body.velocity);
- physical_body.apply_force(&body.external_forces);
- body.external_forces = Force::<f32>::zero();
-
- // if you changed the mass properties at all... too bad!
- }
- None => {}
+ if let Some(physical_body) = physical_world.rigid_body_mut(body.handle.unwrap()) {
+ let position: Isometry<f32> = try_convert(transform.0).unwrap();
+ trace!(
+ "Updating rigid body in physics world with isometry: {}",
+ position
+ );
+ physical_body.set_position(position);
+
+ physical_body.set_velocity(body.velocity);
+ physical_body.apply_force(&body.external_forces);
+ body.external_forces = Force::<f32>::zero();
+
+ // if you changed the mass properties at all... too bad!
}
}
}
diff --git a/src/time_step.rs b/src/time_step.rs
@@ -133,7 +133,7 @@ impl TimeStepConstraint {
///
/// Shouldn't be called from outside the `PhysicsStepperSystem`, otherwise bad things may happen.
pub fn decrease_timestep(&mut self) -> Result<f32, TimeStepChangeError> {
- if self.current_index <= 0 {
+ if self.current_index == 0 {
return Err(TimeStepChangeError::MinimumTimestepReached);
}
self.current_index -= 1;
@@ -149,7 +149,7 @@ impl TimeStepConstraint {
/// Get next smaller timestep.
pub fn smaller_timestep(&self) -> Option<f32> {
- if self.current_index <= 0 {
+ if self.current_index == 0 {
None
} else {
Some(self.time_steps[self.current_index - 1])