Fix all clippy warnings

This commit is contained in:
Imbris 2021-04-26 20:12:44 -04:00 committed by Avi Weinstock
parent af1962f11c
commit ea6985e565
11 changed files with 44 additions and 41 deletions

View File

@ -5,7 +5,7 @@ use common::{
use criterion::{black_box, criterion_group, criterion_main, Criterion};
use std::sync::Arc;
use vek::*;
use veloren_voxygen::{mesh::Meshable, scene::terrain::BlocksOfInterest};
use veloren_voxygen::{mesh::terrain::generate_mesh, scene::terrain::BlocksOfInterest};
use world::{sim, World};
const CENTER: Vec2<i32> = Vec2 { x: 512, y: 512 };
@ -142,11 +142,10 @@ pub fn criterion_benchmark(c: &mut Criterion) {
let (volume, range) = sample(Vec2::new(x, y));
meshing_benches.bench_function(&format!("Terrain mesh {}, {}", x, y), move |b| {
b.iter(|| {
volume.generate_mesh(black_box((
range,
Vec2::new(8192, 8192),
&BlocksOfInterest::default(),
)))
generate_mesh(
black_box(&volume),
black_box((range, Vec2::new(8192, 8192), &BlocksOfInterest::default())),
)
})
});
}

View File

@ -34,7 +34,7 @@ enum InitState {
// Waiting on the client initialization
Client(ClientInit),
// Client initialized but still waiting on Renderer pipeline creation
Pipeline(Client),
Pipeline(Box<Client>),
}
impl InitState {
@ -136,7 +136,7 @@ impl PlayState for MainMenuState {
Some(InitMsg::Done(Ok(mut client))) => {
// Register voxygen components / resources
crate::ecs::init(client.state_mut().ecs_mut());
self.init = InitState::Pipeline(client);
self.init = InitState::Pipeline(Box::new(client));
},
Some(InitMsg::Done(Err(err))) => {
let localized_strings = global_state.i18n.read();
@ -319,7 +319,7 @@ impl PlayState for MainMenuState {
self.main_menu_ui.connected();
return PlayStateResult::Push(Box::new(CharSelectionState::new(
global_state,
std::rc::Rc::new(std::cell::RefCell::new(client)),
std::rc::Rc::new(std::cell::RefCell::new(*client)),
)));
}
}

View File

@ -224,6 +224,7 @@ fn calc_light<V: RectRasterableVol<Vox = Block> + ReadVol + Debug>(
#[allow(clippy::collapsible_if)]
#[allow(clippy::many_single_char_names)]
#[allow(clippy::type_complexity)]
#[allow(clippy::needless_range_loop)] // TODO: Pending review in #587
#[allow(clippy::or_fun_call)] // TODO: Pending review in #587
pub fn generate_mesh<'a, V: RectRasterableVol<Vox = Block> + ReadVol + Debug + 'static>(

View File

@ -24,6 +24,7 @@ impl<T: Copy + Pod> Buffer<T> {
}
}
#[allow(clippy::len_without_is_empty)]
pub fn len(&self) -> usize { self.len }
}

View File

@ -54,9 +54,9 @@ impl<V: Vertex> Mesh<V> {
self.verts.push(quad.d);
} else {
// Tri 1
self.verts.push(quad.a.clone());
self.verts.push(quad.a);
self.verts.push(quad.b);
self.verts.push(quad.c.clone());
self.verts.push(quad.c);
// Tri 2
self.verts.push(quad.c);
@ -78,9 +78,9 @@ impl<V: Vertex> Mesh<V> {
debug_assert!(index % 3 == 0);
assert!(index + 5 < self.verts.len());
// Tri 1
self.verts[index] = quad.a.clone();
self.verts[index] = quad.a;
self.verts[index + 1] = quad.b;
self.verts[index + 2] = quad.c.clone();
self.verts[index + 2] = quad.c;
// Tri 2
self.verts[index + 3] = quad.c;
@ -99,7 +99,7 @@ impl<V: Vertex> Mesh<V> {
self.verts.reserve(other.vertices().len());
for vert in other.vertices() {
self.verts.push(f(vert.clone()));
self.verts.push(f(*vert));
}
}
@ -162,10 +162,10 @@ impl<V: Vertex> Quad<V> {
let verts = [self.a, self.b, self.c, self.d];
Self {
a: verts[n % 4].clone(),
b: verts[(1 + n) % 4].clone(),
c: verts[(2 + n) % 4].clone(),
d: verts[(3 + n) % 4].clone(),
a: verts[n % 4],
b: verts[(1 + n) % 4],
c: verts[(2 + n) % 4],
d: verts[(3 + n) % 4],
}
}
}

View File

@ -19,6 +19,7 @@ impl<'a, V: Vertex> SubModel<'a, V> {
self.buf.slice(start..end)
}
#[allow(clippy::len_without_is_empty)]
pub fn len(&self) -> u32 { self.vertex_range.end - self.vertex_range.start }
}
@ -46,6 +47,7 @@ impl<V: Vertex> Model<V> {
pub(super) fn buf(&self) -> &wgpu::Buffer { &self.vbuf.buf }
#[allow(clippy::len_without_is_empty)]
pub fn len(&self) -> usize { self.vbuf.len() }
}
@ -77,5 +79,6 @@ impl<V: Vertex> DynamicModel<V> {
pub fn buf(&self) -> &wgpu::Buffer { &self.vbuf.buf }
#[allow(clippy::len_without_is_empty)]
pub fn len(&self) -> usize { self.vbuf.len() }
}

View File

@ -77,6 +77,7 @@ struct Shadow {
/// Represent two states of the renderer:
/// 1. Only interface pipelines created
/// 2. All of the pipelines have been created
#[allow(clippy::large_enum_variant)] // They are both pretty large
enum State {
// NOTE: this is used as a transient placeholder for moving things out of State temporarily
Nothing,
@ -487,7 +488,7 @@ impl Renderer {
self.swap_chain = self.device.create_swap_chain(&self.surface, &self.sc_desc);
// Resize other render targets
self.views = Self::create_rt_views(&mut self.device, (dims.x, dims.y), &self.mode)?;
self.views = Self::create_rt_views(&self.device, (dims.x, dims.y), &self.mode)?;
// Rebind views to clouds/postprocess bind groups
self.locals.rebind(
&self.device,
@ -519,7 +520,7 @@ impl Renderer {
if let (Some((point_depth, directed_depth)), ShadowMode::Map(mode)) =
(shadow_views, self.mode.shadow)
{
match ShadowMap::create_shadow_views(&mut self.device, (dims.x, dims.y), &mode) {
match ShadowMap::create_shadow_views(&self.device, (dims.x, dims.y), &mode) {
Ok((new_point_depth, new_directed_depth)) => {
*point_depth = new_point_depth;
*directed_depth = new_directed_depth;

View File

@ -545,7 +545,7 @@ impl<'pass> FirstPassDrawer<'pass> {
FigureDrawer { render_pass }
}
pub fn draw_terrain<'data: 'pass>(&mut self) -> TerrainDrawer<'_, 'pass> {
pub fn draw_terrain(&mut self) -> TerrainDrawer<'_, 'pass> {
let mut render_pass = self.render_pass.scope("terrain", self.borrow.device);
render_pass.set_pipeline(&self.pipelines.terrain.pipeline);
@ -584,7 +584,7 @@ impl<'pass> FirstPassDrawer<'pass> {
}
}
pub fn draw_fluid<'data: 'pass>(&mut self) -> FluidDrawer<'_, 'pass> {
pub fn draw_fluid(&mut self) -> FluidDrawer<'_, 'pass> {
let mut render_pass = self.render_pass.scope("fluid", self.borrow.device);
render_pass.set_pipeline(&self.pipelines.fluid.pipeline);
@ -816,7 +816,7 @@ impl<'pass_ref, 'pass: 'pass_ref> PreparedUiDrawer<'pass_ref, 'pass> {
self.render_pass.set_vertex_buffer(0, model.buf().slice(..))
}
pub fn set_scissor<'data: 'pass>(&mut self, scissor: Aabr<u16>) {
pub fn set_scissor(&mut self, scissor: Aabr<u16>) {
let Aabr { min, max } = scissor;
// TODO: Got an invalid scissor panic from wgpu,
// use this if you can reproduce
@ -840,15 +840,12 @@ fn set_quad_index_buffer<'a, V: super::super::Vertex>(
pass: &mut wgpu::RenderPass<'a>,
borrow: &RendererBorrow<'a>,
) {
match V::QUADS_INDEX {
Some(format) => {
let slice = match format {
wgpu::IndexFormat::Uint16 => borrow.quad_index_buffer_u16.buf.slice(..),
wgpu::IndexFormat::Uint32 => borrow.quad_index_buffer_u32.buf.slice(..),
};
if let Some(format) = V::QUADS_INDEX {
let slice = match format {
wgpu::IndexFormat::Uint16 => borrow.quad_index_buffer_u16.buf.slice(..),
wgpu::IndexFormat::Uint32 => borrow.quad_index_buffer_u32.buf.slice(..),
};
pass.set_index_buffer(slice, format);
},
None => {},
pass.set_index_buffer(slice, format);
}
}

View File

@ -618,15 +618,15 @@ fn create_ingame_and_shadow_pipelines(
IngameAndShadowPipelines {
ingame: IngamePipelines {
skybox,
figure,
terrain,
fluid,
sprite,
particle,
lod_terrain,
particle,
clouds,
postprocess,
skybox,
sprite,
terrain,
// player_shadow_pipeline,
},
shadow: ShadowPipelines {

View File

@ -6,7 +6,7 @@ use treeculler::Frustum;
use vek::*;
pub const NEAR_PLANE: f32 = 0.0625;
pub const FAR_PLANE: f32 = 524288.0625;
pub const FAR_PLANE: f32 = 524288.06; // excessive precision: 524288.0625
const FIRST_PERSON_INTERP_TIME: f32 = 0.1;
const THIRD_PERSON_INTERP_TIME: f32 = 0.1;

View File

@ -219,7 +219,7 @@ fn mesh_worker<V: BaseVol<Vox = Block> + RectRasterableVol + ReadVol + Debug + '
// Extract sprite locations from volume
sprite_instances: {
span!(_guard, "extract sprite_instances");
let mut instances = [Vec::new(), Vec::new(), Vec::new(), Vec::new(), Vec::new()];
let mut instances = [(); SPRITE_LOD_LEVELS].map(|()| Vec::new());
for x in 0..V::RECT_SIZE.x as i32 {
for y in 0..V::RECT_SIZE.y as i32 {
@ -250,8 +250,9 @@ fn mesh_worker<V: BaseVol<Vox = Block> + RectRasterableVol + ReadVol + Debug + '
let light = light_map(wpos);
let glow = glow_map(wpos);
for lod_level in 0..SPRITE_LOD_LEVELS {
let sprite_data = &sprite_data[&key][lod_level];
for (lod_level, sprite_data) in
instances.iter_mut().zip(&sprite_data[&key])
{
let mat = Mat4::identity()
// Scaling for different LOD resolutions
.scaled_3d(sprite_data.scale)
@ -276,7 +277,7 @@ fn mesh_worker<V: BaseVol<Vox = Block> + RectRasterableVol + ReadVol + Debug + '
glow,
page,
);
instances[lod_level].push(instance);
lod_level.push(instance);
}
}