Fix clippy and enable clippy on CI
This commit is contained in:
committed by
Sébastien Crozet
parent
aef873f20e
commit
da92e5c283
@@ -35,6 +35,7 @@ impl Default for OrbitCamera {
|
||||
// Adapted from the 3D orbit camera from bevy-orbit-controls
|
||||
pub struct OrbitCameraPlugin;
|
||||
impl OrbitCameraPlugin {
|
||||
#[allow(clippy::type_complexity)]
|
||||
fn update_transform_system(
|
||||
mut query: Query<(&OrbitCamera, &mut Transform), (Changed<OrbitCamera>, With<Camera>)>,
|
||||
) {
|
||||
|
||||
@@ -46,6 +46,7 @@ impl Default for OrbitCamera {
|
||||
|
||||
pub struct OrbitCameraPlugin;
|
||||
impl OrbitCameraPlugin {
|
||||
#[allow(clippy::type_complexity)]
|
||||
fn update_transform_system(
|
||||
mut query: Query<(&OrbitCamera, &mut Transform), (Changed<OrbitCamera>, With<Camera>)>,
|
||||
) {
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
#![allow(clippy::unnecessary_cast)] // Casts are needed for switching between f32/f64.
|
||||
|
||||
use crate::harness::Harness;
|
||||
use bevy::gizmos::gizmos::Gizmos;
|
||||
use bevy::prelude::*;
|
||||
@@ -36,8 +38,8 @@ impl<'a> DebugRenderBackend for BevyLinesRenderBackend<'a> {
|
||||
#[cfg(feature = "dim2")]
|
||||
fn draw_line(&mut self, _: DebugRenderObject, a: Point<Real>, b: Point<Real>, color: [f32; 4]) {
|
||||
self.gizmos.line(
|
||||
[a.x as f32, a.y as f32, 1.0e-8 as f32].into(),
|
||||
[b.x as f32, b.y as f32, 1.0e-8 as f32].into(),
|
||||
[a.x as f32, a.y as f32, 1.0e-8].into(),
|
||||
[b.x as f32, b.y as f32, 1.0e-8].into(),
|
||||
Color::hsla(color[0], color[1], color[2], color[3]),
|
||||
)
|
||||
}
|
||||
|
||||
@@ -253,7 +253,7 @@ impl GraphicsManager {
|
||||
// }
|
||||
// }
|
||||
|
||||
let nodes = self.b2sn.entry(handle).or_insert_with(Vec::new);
|
||||
let nodes = self.b2sn.entry(handle).or_default();
|
||||
|
||||
nodes.append(&mut new_nodes.clone());
|
||||
|
||||
@@ -276,10 +276,7 @@ impl GraphicsManager {
|
||||
.copied()
|
||||
.unwrap_or(self.ground_color);
|
||||
let color = self.c2color.get(&handle).copied().unwrap_or(color);
|
||||
let mut nodes = std::mem::replace(
|
||||
self.b2sn.entry(collider_parent).or_insert(vec![]),
|
||||
Vec::new(),
|
||||
);
|
||||
let mut nodes = std::mem::take(self.b2sn.entry(collider_parent).or_default());
|
||||
self.add_shape(
|
||||
commands,
|
||||
meshes,
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
#![allow(clippy::unnecessary_cast)] // Casts are needed for switching between f32/f64.
|
||||
|
||||
use crate::{
|
||||
physics::{PhysicsEvents, PhysicsState},
|
||||
TestbedGraphics,
|
||||
@@ -22,6 +24,12 @@ pub struct RunState {
|
||||
pub time: f32,
|
||||
}
|
||||
|
||||
impl Default for RunState {
|
||||
fn default() -> Self {
|
||||
Self::new()
|
||||
}
|
||||
}
|
||||
|
||||
impl RunState {
|
||||
#[cfg(feature = "parallel")]
|
||||
pub fn new() -> Self {
|
||||
@@ -33,7 +41,7 @@ impl RunState {
|
||||
.unwrap();
|
||||
|
||||
Self {
|
||||
thread_pool: thread_pool,
|
||||
thread_pool,
|
||||
num_threads,
|
||||
timestep_id: 0,
|
||||
time: 0.0,
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
#![allow(clippy::too_many_arguments)]
|
||||
|
||||
extern crate nalgebra as na;
|
||||
|
||||
#[macro_use]
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
#![allow(clippy::unnecessary_cast)] // Casts are needed for switching between f32/f64.
|
||||
|
||||
use bevy::prelude::*;
|
||||
use bevy::render::mesh::{Indices, VertexAttributeValues};
|
||||
|
||||
|
||||
@@ -86,6 +86,12 @@ pub struct PhysicsState {
|
||||
pub hooks: Box<dyn PhysicsHooks>,
|
||||
}
|
||||
|
||||
impl Default for PhysicsState {
|
||||
fn default() -> Self {
|
||||
Self::new()
|
||||
}
|
||||
}
|
||||
|
||||
impl PhysicsState {
|
||||
pub fn new() -> Self {
|
||||
Self {
|
||||
@@ -113,7 +119,7 @@ pub struct PhysicsEvents {
|
||||
|
||||
impl PhysicsEvents {
|
||||
pub fn poll_all(&self) {
|
||||
while let Ok(_) = self.collision_events.try_recv() {}
|
||||
while let Ok(_) = self.contact_force_events.try_recv() {}
|
||||
while self.collision_events.try_recv().is_ok() {}
|
||||
while self.contact_force_events.try_recv().is_ok() {}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
#![allow(clippy::bad_bit_mask)] // otherwsie clippy complains because of TestbedStateFlags::NONE which is 0.
|
||||
|
||||
use std::env;
|
||||
use std::mem;
|
||||
use std::num::NonZeroUsize;
|
||||
@@ -107,6 +109,8 @@ pub enum RapierSolverType {
|
||||
StandardPgs,
|
||||
}
|
||||
|
||||
pub type SimulationBuilders = Vec<(&'static str, fn(&mut Testbed))>;
|
||||
|
||||
#[derive(Resource)]
|
||||
pub struct TestbedState {
|
||||
pub running: RunMode,
|
||||
@@ -135,7 +139,7 @@ pub struct TestbedState {
|
||||
}
|
||||
|
||||
#[derive(Resource)]
|
||||
struct SceneBuilders(Vec<(&'static str, fn(&mut Testbed))>);
|
||||
struct SceneBuilders(SimulationBuilders);
|
||||
|
||||
#[cfg(feature = "other-backends")]
|
||||
struct OtherBackends {
|
||||
@@ -237,7 +241,7 @@ impl TestbedApp {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn from_builders(default: usize, builders: Vec<(&'static str, fn(&mut Testbed))>) -> Self {
|
||||
pub fn from_builders(default: usize, builders: SimulationBuilders) -> Self {
|
||||
let mut res = TestbedApp::new_empty();
|
||||
res.state
|
||||
.action_flags
|
||||
@@ -247,7 +251,7 @@ impl TestbedApp {
|
||||
res
|
||||
}
|
||||
|
||||
pub fn set_builders(&mut self, builders: Vec<(&'static str, fn(&mut Testbed))>) {
|
||||
pub fn set_builders(&mut self, builders: SimulationBuilders) {
|
||||
self.state.example_names = builders.iter().map(|e| e.0).collect();
|
||||
self.builders = SceneBuilders(builders)
|
||||
}
|
||||
@@ -280,7 +284,7 @@ impl TestbedApp {
|
||||
use std::io::{BufWriter, Write};
|
||||
// Don't enter the main loop. We will just step the simulation here.
|
||||
let mut results = Vec::new();
|
||||
let builders = mem::replace(&mut self.builders.0, Vec::new());
|
||||
let builders = mem::take(&mut self.builders.0);
|
||||
let backend_names = self.state.backend_names.clone();
|
||||
|
||||
for builder in builders {
|
||||
@@ -423,8 +427,7 @@ impl TestbedApp {
|
||||
|
||||
impl<'a, 'b, 'c, 'd, 'e, 'f> TestbedGraphics<'a, 'b, 'c, 'd, 'e, 'f> {
|
||||
pub fn set_body_color(&mut self, body: RigidBodyHandle, color: [f32; 3]) {
|
||||
self.graphics
|
||||
.set_body_color(&mut self.materials, body, color);
|
||||
self.graphics.set_body_color(self.materials, body, color);
|
||||
}
|
||||
|
||||
pub fn add_body(
|
||||
@@ -466,7 +469,7 @@ impl<'a, 'b, 'c, 'd, 'e, 'f> TestbedGraphics<'a, 'b, 'c, 'd, 'e, 'f> {
|
||||
}
|
||||
|
||||
pub fn keys(&self) -> &Input<KeyCode> {
|
||||
&*self.keys
|
||||
self.keys
|
||||
}
|
||||
}
|
||||
|
||||
@@ -497,7 +500,7 @@ impl<'a, 'b, 'c, 'd, 'e, 'f> Testbed<'a, 'b, 'c, 'd, 'e, 'f> {
|
||||
}
|
||||
|
||||
pub fn harness_mut(&mut self) -> &mut Harness {
|
||||
&mut self.harness
|
||||
self.harness
|
||||
}
|
||||
|
||||
pub fn set_world(
|
||||
@@ -1110,30 +1113,30 @@ fn update_testbed(
|
||||
// Handle inputs
|
||||
{
|
||||
let graphics_context = TestbedGraphics {
|
||||
graphics: &mut *graphics,
|
||||
graphics: &mut graphics,
|
||||
commands: &mut commands,
|
||||
meshes: &mut *meshes,
|
||||
materials: &mut *materials,
|
||||
components: &mut gfx_components,
|
||||
camera_transform: *cameras.single().1,
|
||||
camera: &mut cameras.single_mut().2,
|
||||
keys: &*keys,
|
||||
keys: &keys,
|
||||
};
|
||||
|
||||
let mut testbed = Testbed {
|
||||
graphics: Some(graphics_context),
|
||||
state: &mut *state,
|
||||
harness: &mut *harness,
|
||||
state: &mut state,
|
||||
harness: &mut harness,
|
||||
#[cfg(feature = "other-backends")]
|
||||
other_backends: &mut *other_backends,
|
||||
plugins: &mut *plugins,
|
||||
other_backends: &mut other_backends,
|
||||
plugins: &mut plugins,
|
||||
};
|
||||
|
||||
testbed.handle_common_events(&*keys);
|
||||
testbed.update_character_controller(&*keys);
|
||||
testbed.handle_common_events(&keys);
|
||||
testbed.update_character_controller(&keys);
|
||||
#[cfg(feature = "dim3")]
|
||||
{
|
||||
testbed.update_vehicle_controller(&*keys);
|
||||
testbed.update_vehicle_controller(&keys);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1144,7 +1147,7 @@ fn update_testbed(
|
||||
|
||||
for plugin in &mut plugins.0 {
|
||||
plugin.update_ui(
|
||||
&mut ui_context,
|
||||
&ui_context,
|
||||
harness,
|
||||
&mut graphics,
|
||||
&mut commands,
|
||||
@@ -1190,10 +1193,10 @@ fn update_testbed(
|
||||
.set(TestbedActionFlags::EXAMPLE_CHANGED, false);
|
||||
clear(&mut commands, &mut state, &mut graphics, &mut plugins);
|
||||
harness.clear_callbacks();
|
||||
for plugin in (*plugins).0.iter_mut() {
|
||||
for plugin in plugins.0.iter_mut() {
|
||||
plugin.clear_graphics(&mut graphics, &mut commands);
|
||||
}
|
||||
(*plugins).0.clear();
|
||||
plugins.0.clear();
|
||||
|
||||
if state.selected_example != prev_example {
|
||||
harness.physics.integration_parameters = IntegrationParameters::default();
|
||||
@@ -1219,16 +1222,16 @@ fn update_testbed(
|
||||
components: &mut gfx_components,
|
||||
camera_transform: *cameras.single().1,
|
||||
camera: &mut cameras.single_mut().2,
|
||||
keys: &*keys,
|
||||
keys: &keys,
|
||||
};
|
||||
|
||||
let mut testbed = Testbed {
|
||||
graphics: Some(graphics_context),
|
||||
state: &mut *state,
|
||||
harness: &mut *harness,
|
||||
state: &mut state,
|
||||
harness: &mut harness,
|
||||
#[cfg(feature = "other-backends")]
|
||||
other_backends: &mut *other_backends,
|
||||
plugins: &mut *plugins,
|
||||
other_backends: &mut other_backends,
|
||||
plugins: &mut plugins,
|
||||
};
|
||||
|
||||
builders.0[selected_example].1(&mut testbed);
|
||||
@@ -1371,7 +1374,7 @@ fn update_testbed(
|
||||
components: &mut gfx_components,
|
||||
camera_transform: *cameras.single().1,
|
||||
camera: &mut cameras.single_mut().2,
|
||||
keys: &*keys,
|
||||
keys: &keys,
|
||||
};
|
||||
harness.step_with_graphics(Some(&mut testbed_graphics));
|
||||
|
||||
@@ -1425,8 +1428,8 @@ fn update_testbed(
|
||||
for (camera, camera_pos, _) in cameras.iter_mut() {
|
||||
highlight_hovered_body(
|
||||
&mut *materials,
|
||||
&mut *graphics,
|
||||
&mut *state,
|
||||
&mut graphics,
|
||||
&mut state,
|
||||
&harness.physics,
|
||||
window,
|
||||
camera,
|
||||
|
||||
@@ -44,22 +44,18 @@ pub fn update_ui(
|
||||
}
|
||||
|
||||
ui.horizontal(|ui| {
|
||||
if ui.button("<").clicked() {
|
||||
if state.selected_example > 0 {
|
||||
state.selected_example -= 1;
|
||||
state
|
||||
.action_flags
|
||||
.set(TestbedActionFlags::EXAMPLE_CHANGED, true)
|
||||
}
|
||||
if ui.button("<").clicked() && state.selected_example > 0 {
|
||||
state.selected_example -= 1;
|
||||
state
|
||||
.action_flags
|
||||
.set(TestbedActionFlags::EXAMPLE_CHANGED, true)
|
||||
}
|
||||
|
||||
if ui.button(">").clicked() {
|
||||
if state.selected_example + 1 < state.example_names.len() {
|
||||
state.selected_example += 1;
|
||||
state
|
||||
.action_flags
|
||||
.set(TestbedActionFlags::EXAMPLE_CHANGED, true)
|
||||
}
|
||||
if ui.button(">").clicked() && state.selected_example + 1 < state.example_names.len() {
|
||||
state.selected_example += 1;
|
||||
state
|
||||
.action_flags
|
||||
.set(TestbedActionFlags::EXAMPLE_CHANGED, true)
|
||||
}
|
||||
|
||||
let mut changed = false;
|
||||
|
||||
Reference in New Issue
Block a user