clippy suggestions
This commit is contained in:
parent
c1148ea8bc
commit
8c51f91d00
9 changed files with 33 additions and 77 deletions
|
@ -23,7 +23,7 @@ impl Projection {
|
|||
}
|
||||
|
||||
pub fn get_matrix(&self) -> cgmath::Matrix4<f32> {
|
||||
return cgmath::perspective(cgmath::Deg(self.fovy), self.aspect, self.znear, self.zfar);
|
||||
cgmath::perspective(cgmath::Deg(self.fovy), self.aspect, self.znear, self.zfar)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -50,7 +50,7 @@ impl Camera {
|
|||
|
||||
pub fn get_view_matrix(&self) -> cgmath::Matrix4<f32> {
|
||||
let (_right, up, forward) = self.get_vecs();
|
||||
return cgmath::Matrix4::look_to_rh(self.position, forward, up);
|
||||
cgmath::Matrix4::look_to_rh(self.position, forward, up)
|
||||
}
|
||||
|
||||
pub fn get_vecs(
|
||||
|
@ -67,7 +67,7 @@ impl Camera {
|
|||
cgmath::Vector3::new(pitch_cos * yaw_cos, pitch_sin, pitch_cos * yaw_sin).normalize();
|
||||
let right = cgmath::Vector3::new(-yaw_sin, 0.0, yaw_cos).normalize();
|
||||
let up = right.cross(forward);
|
||||
return (right, up, forward);
|
||||
(right, up, forward)
|
||||
}
|
||||
|
||||
pub fn update(&mut self, dt: Duration, controller: &CameraController) {
|
||||
|
@ -168,7 +168,7 @@ impl CameraController {
|
|||
window_event: Option<&WindowEvent>,
|
||||
device_event: Option<&DeviceEvent>,
|
||||
) -> bool {
|
||||
let mut handled = match window_event {
|
||||
let handled = match window_event {
|
||||
None => false,
|
||||
Some(event) => match event {
|
||||
WindowEvent::KeyboardInput {
|
||||
|
@ -185,27 +185,27 @@ impl CameraController {
|
|||
match keycode {
|
||||
VirtualKeyCode::W | VirtualKeyCode::Up => {
|
||||
self.move_forward = amount;
|
||||
return true;
|
||||
true
|
||||
}
|
||||
VirtualKeyCode::A | VirtualKeyCode::Left => {
|
||||
self.move_left = amount;
|
||||
return true;
|
||||
true
|
||||
}
|
||||
VirtualKeyCode::S | VirtualKeyCode::Down => {
|
||||
self.move_backward = amount;
|
||||
return true;
|
||||
true
|
||||
}
|
||||
VirtualKeyCode::D | VirtualKeyCode::Right => {
|
||||
self.move_right = amount;
|
||||
return true;
|
||||
true
|
||||
}
|
||||
VirtualKeyCode::Space => {
|
||||
self.move_up = amount;
|
||||
return true;
|
||||
true
|
||||
}
|
||||
VirtualKeyCode::LControl => {
|
||||
self.move_down = amount;
|
||||
return true;
|
||||
true
|
||||
}
|
||||
_ => false,
|
||||
}
|
||||
|
@ -217,7 +217,7 @@ impl CameraController {
|
|||
} else {
|
||||
self.speed /= 2.0;
|
||||
}
|
||||
return true;
|
||||
true
|
||||
}
|
||||
MouseScrollDelta::PixelDelta(PhysicalPosition { y: scroll, .. }) => {
|
||||
if *scroll > 0.0 {
|
||||
|
@ -225,7 +225,7 @@ impl CameraController {
|
|||
} else {
|
||||
self.speed /= 2.0;
|
||||
}
|
||||
return true;
|
||||
true
|
||||
}
|
||||
},
|
||||
_ => false,
|
||||
|
@ -236,15 +236,13 @@ impl CameraController {
|
|||
return true;
|
||||
}
|
||||
|
||||
handled = match device_event {
|
||||
match device_event {
|
||||
Some(DeviceEvent::MouseMotion { delta }) => {
|
||||
self.deltax += delta.0 as f32;
|
||||
self.deltay += delta.1 as f32;
|
||||
return true;
|
||||
true
|
||||
}
|
||||
_ => false,
|
||||
};
|
||||
|
||||
return handled;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -14,12 +14,12 @@ pub struct InstanceRaw {
|
|||
|
||||
impl Instance {
|
||||
pub fn to_raw(&self) -> InstanceRaw {
|
||||
return InstanceRaw {
|
||||
InstanceRaw {
|
||||
model: (cgmath::Matrix4::from_translation(self.position)
|
||||
* cgmath::Matrix4::from(self.rotation))
|
||||
.into(),
|
||||
normal: cgmath::Matrix3::from(self.rotation).into(),
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -12,11 +12,11 @@ pub struct LightUniform {
|
|||
|
||||
impl LightUniform {
|
||||
pub fn new(position: [f32; 3], color: [f32; 4]) -> Self {
|
||||
return LightUniform {
|
||||
Self {
|
||||
position,
|
||||
_padding: 0,
|
||||
color,
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -57,7 +57,7 @@ impl Material {
|
|||
label: None,
|
||||
});
|
||||
|
||||
return Self {
|
||||
Self {
|
||||
name: String::from(name),
|
||||
diffuse_texture,
|
||||
normal_texture,
|
||||
|
@ -65,7 +65,7 @@ impl Material {
|
|||
metallic_factor,
|
||||
roughness_factor,
|
||||
bind_group,
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -8,10 +8,6 @@ use crate::core::texture::Texture;
|
|||
#[folder = "res"]
|
||||
struct Asset;
|
||||
|
||||
pub fn load_binary(file_name: &str) -> Vec<u8> {
|
||||
Asset::get(file_name).unwrap().data.into_owned()
|
||||
}
|
||||
|
||||
pub fn load_string(file_name: &str) -> String {
|
||||
let binary = Asset::get(file_name).unwrap();
|
||||
std::str::from_utf8(binary.data.as_ref()).unwrap().to_owned()
|
||||
|
@ -258,7 +254,7 @@ pub async fn load_model_gltf(
|
|||
|
||||
materials.push(Material::new(
|
||||
device,
|
||||
&material.name().unwrap_or("Default Material"),
|
||||
material.name().unwrap_or("Default Material"),
|
||||
diffuse_texture,
|
||||
normal_texture,
|
||||
rm_texture,
|
||||
|
@ -336,5 +332,5 @@ fn gltf_pixels_to_wgpu(mut bytes: Vec<u8>, format: gltf::image::Format) -> Vec<u
|
|||
.collect();
|
||||
}
|
||||
|
||||
return bytes;
|
||||
bytes
|
||||
}
|
||||
|
|
|
@ -280,7 +280,7 @@ impl State {
|
|||
)
|
||||
};
|
||||
|
||||
return Self {
|
||||
Self {
|
||||
size,
|
||||
surface,
|
||||
device,
|
||||
|
@ -300,7 +300,7 @@ impl State {
|
|||
light_buffer,
|
||||
light_render_pipeline,
|
||||
light_bind_group,
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
pub fn resize(&mut self, new_size: winit::dpi::PhysicalSize<u32>) {
|
||||
|
@ -322,9 +322,9 @@ impl State {
|
|||
window_event: Option<&WindowEvent>,
|
||||
device_event: Option<&DeviceEvent>,
|
||||
) -> bool {
|
||||
return self
|
||||
self
|
||||
.camera_controller
|
||||
.process_events(window_event, device_event);
|
||||
.process_events(window_event, device_event)
|
||||
}
|
||||
|
||||
pub fn update(&mut self, dt: Duration) {
|
||||
|
@ -411,7 +411,7 @@ impl State {
|
|||
self.queue.submit(std::iter::once(encoder.finish()));
|
||||
output.present();
|
||||
|
||||
return Ok(());
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -425,7 +425,7 @@ fn create_render_pipeline(
|
|||
) -> wgpu::RenderPipeline {
|
||||
let shader = device.create_shader_module(shader);
|
||||
|
||||
return device.create_render_pipeline(&wgpu::RenderPipelineDescriptor {
|
||||
device.create_render_pipeline(&wgpu::RenderPipelineDescriptor {
|
||||
label: Some("Render Pipeline"),
|
||||
layout: Some(layout),
|
||||
vertex: wgpu::VertexState {
|
||||
|
@ -470,5 +470,5 @@ fn create_render_pipeline(
|
|||
alpha_to_coverage_enabled: false,
|
||||
},
|
||||
multiview: None,
|
||||
});
|
||||
})
|
||||
}
|
||||
|
|
|
@ -1,5 +1,4 @@
|
|||
use anyhow::*;
|
||||
use image::GenericImageView;
|
||||
|
||||
pub struct Texture {
|
||||
pub texture: wgpu::Texture,
|
||||
|
@ -52,41 +51,6 @@ impl Texture {
|
|||
}
|
||||
}
|
||||
|
||||
pub fn from_bytes(
|
||||
device: &wgpu::Device,
|
||||
queue: &wgpu::Queue,
|
||||
bytes: &[u8],
|
||||
label: &str,
|
||||
is_normal_map: bool,
|
||||
) -> Result<Self> {
|
||||
let img = image::load_from_memory(bytes)?;
|
||||
return Self::from_image(device, queue, &img, Some(label), is_normal_map);
|
||||
}
|
||||
|
||||
pub fn from_image(
|
||||
device: &wgpu::Device,
|
||||
queue: &wgpu::Queue,
|
||||
img: &image::DynamicImage,
|
||||
label: Option<&str>,
|
||||
is_normal_map: bool,
|
||||
) -> Result<Self> {
|
||||
let rgba = img.to_rgba8();
|
||||
let dimensions = img.dimensions();
|
||||
return Self::from_pixels(
|
||||
device,
|
||||
queue,
|
||||
&rgba,
|
||||
dimensions,
|
||||
4,
|
||||
if is_normal_map {
|
||||
wgpu::TextureFormat::Rgba8UnormSrgb
|
||||
} else {
|
||||
wgpu::TextureFormat::Rgba8Unorm
|
||||
},
|
||||
label,
|
||||
);
|
||||
}
|
||||
|
||||
pub fn from_pixels(
|
||||
device: &wgpu::Device,
|
||||
queue: &wgpu::Queue,
|
||||
|
@ -140,10 +104,10 @@ impl Texture {
|
|||
..Default::default()
|
||||
});
|
||||
|
||||
return Ok(Self {
|
||||
Ok(Self {
|
||||
texture,
|
||||
view,
|
||||
sampler,
|
||||
});
|
||||
})
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,5 +1,3 @@
|
|||
#![allow(clippy::needless_return)]
|
||||
|
||||
#[cfg(target_arch = "wasm32")]
|
||||
use wasm_bindgen::prelude::*;
|
||||
|
||||
|
|
|
@ -19,5 +19,5 @@ pub fn preprocess_wgsl(filename: &str) -> wgpu::ShaderSource {
|
|||
source = source.replace(whole_match, &nested_source);
|
||||
}
|
||||
|
||||
return wgpu::ShaderSource::Wgsl(source.into());
|
||||
wgpu::ShaderSource::Wgsl(source.into())
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue