diff options
author | metamuffin <metamuffin@disroot.org> | 2025-01-27 15:26:00 +0100 |
---|---|---|
committer | metamuffin <metamuffin@disroot.org> | 2025-01-27 15:26:00 +0100 |
commit | c121d94f0b27bc04ffbdca55cd0939c1401d5a2e (patch) | |
tree | 67ac9da1f994c24b9a3e8e8d2adc2e334d2e34a5 /client | |
parent | 6b5c44d58e6c6d3df360396a0897290fc603699b (diff) | |
download | weareserver-c121d94f0b27bc04ffbdca55cd0939c1401d5a2e.tar weareserver-c121d94f0b27bc04ffbdca55cd0939c1401d5a2e.tar.bz2 weareserver-c121d94f0b27bc04ffbdca55cd0939c1401d5a2e.tar.zst |
clippy: fixes and ignores
Diffstat (limited to 'client')
-rw-r--r-- | client/src/audio.rs | 10 | ||||
-rw-r--r-- | client/src/camera.rs | 6 | ||||
-rw-r--r-- | client/src/download.rs | 17 | ||||
-rw-r--r-- | client/src/interfaces/profiler.rs | 2 | ||||
-rw-r--r-- | client/src/main.rs | 1 | ||||
-rw-r--r-- | client/src/render/scene/demand_map.rs | 6 | ||||
-rw-r--r-- | client/src/render/scene/draw.rs | 2 | ||||
-rw-r--r-- | client/src/render/scene/mod.rs | 24 | ||||
-rw-r--r-- | client/src/render/scene/textures.rs | 10 | ||||
-rw-r--r-- | client/src/render/ui.rs | 48 | ||||
-rw-r--r-- | client/src/state.rs | 18 | ||||
-rw-r--r-- | client/src/window.rs | 32 |
12 files changed, 88 insertions, 88 deletions
diff --git a/client/src/audio.rs b/client/src/audio.rs index e61f333..dca9cb4 100644 --- a/client/src/audio.rs +++ b/client/src/audio.rs @@ -155,8 +155,8 @@ impl AEncoder { let mut out = [0u8; AE_FRAME_SIZE]; let mut denoise = [0f32; AE_FRAME_SIZE]; let mut raw = [0f32; AE_FRAME_SIZE]; - for i in 0..AE_FRAME_SIZE { - raw[i] = self.buffer.pop_front().unwrap() * 32768.0; + for sample in raw.iter_mut().take(AE_FRAME_SIZE) { + *sample = self.buffer.pop_front().unwrap() * 32768.0; } self.noise_rnn.process_frame(&mut denoise, &raw); for e in &mut denoise { @@ -241,11 +241,11 @@ impl ADecoder { (self.playback + JITTER_COMP) % BUFFER_SIZE }); let free_space = *channel_cursor - self.playback; - for i in 0..size.min(free_space) { + for sample in output.iter().take(size.min(free_space)) { // TODO positional audio let _ = p.pos; - self.buffer[*channel_cursor][0] += output[i]; - self.buffer[*channel_cursor][1] += output[i]; + self.buffer[*channel_cursor][0] += sample; + self.buffer[*channel_cursor][1] += sample; *channel_cursor += 1; *channel_cursor %= BUFFER_SIZE } diff --git a/client/src/camera.rs b/client/src/camera.rs index bd86e79..ea984b3 100644 --- a/client/src/camera.rs +++ b/client/src/camera.rs @@ -23,6 +23,12 @@ pub struct Camera { pub aspect: f32, } +impl Default for Camera { + fn default() -> Self { + Self::new() + } +} + impl Camera { pub fn new() -> Self { Self { diff --git a/client/src/download.rs b/client/src/download.rs index 4e2f0aa..44d613b 100644 --- a/client/src/download.rs +++ b/client/src/download.rs @@ -68,17 +68,14 @@ impl Downloader { } pub fn packet(&self, p: &Packet) -> Result<()> { let mut state = self.inner.write().unwrap(); - match p { - Packet::RespondResource(_, d) => { - let key = Resource(resource_hash(&d.0), PhantomData); - state.store.set_raw(&d.0)?; - state.need.remove(&key); - state.pending.remove(&key); - if state.have.insert(key) { - debug!("have {key}"); - } + if let Packet::RespondResource(_, d) = p { + let key = Resource(resource_hash(&d.0), PhantomData); + state.store.set_raw(&d.0)?; + state.need.remove(&key); + state.pending.remove(&key); + if state.have.insert(key) { + debug!("have {key}"); } - _ => (), } Ok(()) } diff --git a/client/src/interfaces/profiler.rs b/client/src/interfaces/profiler.rs index b6c4698..541b5c5 100644 --- a/client/src/interfaces/profiler.rs +++ b/client/src/interfaces/profiler.rs @@ -38,7 +38,7 @@ impl Widget for &mut Profiler { .num_columns(2) .show(ui, |ui| { ui.label("Backend"); - ui.label(&self.idata.adapter_info.backend.to_string()); + ui.label(self.idata.adapter_info.backend.to_string()); ui.end_row(); ui.label("Name"); ui.label(&self.idata.adapter_info.name); diff --git a/client/src/main.rs b/client/src/main.rs index 804ab44..5fa790a 100644 --- a/client/src/main.rs +++ b/client/src/main.rs @@ -15,6 +15,7 @@ along with this program. If not, see <https://www.gnu.org/licenses/>. */ #![feature(iter_array_chunks, mpmc_channel, array_chunks, new_zeroed_alloc)] +#![allow(clippy::too_many_arguments, clippy::type_complexity)] pub mod armature; pub mod audio; pub mod camera; diff --git a/client/src/render/scene/demand_map.rs b/client/src/render/scene/demand_map.rs index c27eaac..dc73142 100644 --- a/client/src/render/scene/demand_map.rs +++ b/client/src/render/scene/demand_map.rs @@ -29,6 +29,12 @@ struct DemandMapState<K, V> { needed: HashSet<K>, size_metric: usize, } +impl<K: Hash + Eq + Clone, V: Clone> Default for DemandMap<K, V> { + fn default() -> Self { + Self::new() + } +} + impl<K: Hash + Eq + Clone, V: Clone> DemandMap<K, V> { pub fn new() -> Self { Self { diff --git a/client/src/render/scene/draw.rs b/client/src/render/scene/draw.rs index 1109401..b2bf19e 100644 --- a/client/src/render/scene/draw.rs +++ b/client/src/render/scene/draw.rs @@ -53,7 +53,7 @@ impl ScenePipeline { }, })], depth_stencil_attachment: Some(RenderPassDepthStencilAttachment { - view: &depth, + view: depth, depth_ops: Some(Operations { load: LoadOp::Clear(1.), store: StoreOp::Store, diff --git a/client/src/render/scene/mod.rs b/client/src/render/scene/mod.rs index 16eecfc..7743409 100644 --- a/client/src/render/scene/mod.rs +++ b/client/src/render/scene/mod.rs @@ -293,13 +293,11 @@ impl ScenePreparer { }) { tex_albedo = Some(bg) } - } else { - if let Some((_tex, bg)) = self - .placeholder_textures - .try_get(TextureIdentityKind::Multiply) - { - tex_albedo = Some(bg) - } + } else if let Some((_tex, bg)) = self + .placeholder_textures + .try_get(TextureIdentityKind::Multiply) + { + tex_albedo = Some(bg) } let mut tex_normal = None; if let Some(normalres) = part.tex_normal { @@ -309,13 +307,11 @@ impl ScenePreparer { }) { tex_normal = Some(bg) } - } else { - if let Some((_tex, bg)) = self - .placeholder_textures - .try_get(TextureIdentityKind::Normal) - { - tex_normal = Some(bg) - } + } else if let Some((_tex, bg)) = self + .placeholder_textures + .try_get(TextureIdentityKind::Normal) + { + tex_normal = Some(bg) } let material = self.materials.try_get({ diff --git a/client/src/render/scene/textures.rs b/client/src/render/scene/textures.rs index 4f2b01c..462cb53 100644 --- a/client/src/render/scene/textures.rs +++ b/client/src/render/scene/textures.rs @@ -27,8 +27,8 @@ use std::{ use wgpu::{ AddressMode, BindGroup, BindGroupDescriptor, BindGroupEntry, BindGroupLayout, BindingResource, Color, ColorTargetState, ColorWrites, CommandEncoderDescriptor, Device, Extent3d, FilterMode, - ImageDataLayout, LoadOp, Operations, Queue, RenderPassColorAttachment, RenderPassDescriptor, - RenderPipeline, SamplerDescriptor, StoreOp, Texture, TextureAspect, TextureDescriptor, + LoadOp, Operations, Queue, RenderPassColorAttachment, RenderPassDescriptor, RenderPipeline, + SamplerDescriptor, StoreOp, TexelCopyBufferLayout, Texture, TextureAspect, TextureDescriptor, TextureDimension, TextureFormat, TextureUsages, TextureViewDescriptor, include_wgsl, }; @@ -193,7 +193,7 @@ fn create_texture( }); let bind_group = device.create_bind_group(&BindGroupDescriptor { label: None, - layout: &bgl, + layout: bgl, entries: &[ BindGroupEntry { binding: 0, @@ -246,7 +246,7 @@ fn create_texture( queue.write_texture( texture.as_image_copy(), data, - ImageDataLayout { + TexelCopyBufferLayout { bytes_per_row: Some(width * 4), rows_per_image: None, offset: 0, @@ -287,7 +287,7 @@ fn create_texture( occlusion_query_set: None, }); - rpass.set_pipeline(&mip_pipeline); + rpass.set_pipeline(mip_pipeline); rpass.set_bind_group(0, &mip_bind_group, &[]); rpass.draw(0..3, 0..1); } diff --git a/client/src/render/ui.rs b/client/src/render/ui.rs index 4de2633..29e9461 100644 --- a/client/src/render/ui.rs +++ b/client/src/render/ui.rs @@ -33,12 +33,12 @@ use wgpu::{ BindGroupLayoutDescriptor, BindGroupLayoutEntry, BindingResource, BindingType, BlendState, Buffer, BufferDescriptor, BufferUsages, ColorTargetState, ColorWrites, CommandEncoder, CompareFunction, DepthStencilState, Device, Extent3d, FilterMode, FragmentState, FrontFace, - ImageCopyTexture, ImageDataLayout, IndexFormat, LoadOp, MultisampleState, Operations, Origin3d, - PipelineCompilationOptions, PipelineLayout, PipelineLayoutDescriptor, PolygonMode, - PrimitiveState, PrimitiveTopology, PushConstantRange, Queue, RenderPassColorAttachment, - RenderPassDepthStencilAttachment, RenderPassDescriptor, RenderPipeline, - RenderPipelineDescriptor, SamplerBindingType, SamplerDescriptor, ShaderStages, StoreOp, - SurfaceConfiguration, Texture, TextureAspect, TextureDescriptor, TextureDimension, + IndexFormat, LoadOp, MultisampleState, Operations, Origin3d, PipelineCompilationOptions, + PipelineLayout, PipelineLayoutDescriptor, PolygonMode, PrimitiveState, PrimitiveTopology, + PushConstantRange, Queue, RenderPassColorAttachment, RenderPassDepthStencilAttachment, + RenderPassDescriptor, RenderPipeline, RenderPipelineDescriptor, SamplerBindingType, + SamplerDescriptor, ShaderStages, StoreOp, SurfaceConfiguration, TexelCopyBufferLayout, + TexelCopyTextureInfo, Texture, TextureAspect, TextureDescriptor, TextureDimension, TextureFormat, TextureSampleType, TextureUsages, TextureView, TextureViewDescriptor, TextureViewDimension, VertexBufferLayout, VertexState, VertexStepMode, include_wgsl, util::{DeviceExt, TextureDataOrder}, @@ -133,7 +133,7 @@ impl UiRenderer { fn create_pipeline( device: &Device, - pipeline_layout: &PipelineLayout, + layout: &PipelineLayout, format: TextureFormat, sample_count: u32, ) -> RenderPipeline { @@ -141,7 +141,7 @@ impl UiRenderer { let vert_shader = device.create_shader_module(include_wgsl!("shaders/vertex_ui.wgsl")); device.create_render_pipeline(&RenderPipelineDescriptor { label: Some("ui pipeline"), - layout: Some(&pipeline_layout), + layout: Some(layout), fragment: Some(FragmentState { module: &frag_shader, entry_point: Some("main"), @@ -241,12 +241,12 @@ impl UiRenderer { ImageData::Font(font_image) => font_image.srgba_pixels(None).collect(), }; - if let Some((_texbg, tex, texsize)) = textures.get_mut(&texid) { + if let Some((_texbg, texture, texsize)) = textures.get_mut(&texid) { let pos = delta.pos.unwrap_or([0, 0]); debug!("updating UI texture at {pos:?}"); self.queue.write_texture( - ImageCopyTexture { - texture: &tex, + TexelCopyTextureInfo { + texture, mip_level: 0, origin: Origin3d { x: pos[0] as u32, @@ -256,7 +256,7 @@ impl UiRenderer { aspect: TextureAspect::All, }, bytemuck::cast_slice::<_, u8>(&pixels), - ImageDataLayout { + TexelCopyBufferLayout { offset: 0, bytes_per_row: Some(texsize[0] * 4), rows_per_image: None, @@ -344,7 +344,7 @@ impl UiRenderer { }, })], depth_stencil_attachment: Some(RenderPassDepthStencilAttachment { - view: &depth, + view: depth, depth_ops: Some(Operations { load: LoadOp::Load, store: StoreOp::Store, @@ -356,17 +356,19 @@ impl UiRenderer { rpass.set_pipeline(&self.pipeline); - let mut raw_input = egui::RawInput::default(); - raw_input.viewport_id = surfaces.keys().next().copied().unwrap(); - raw_input.viewports = surfaces - .keys() - .map(|k| { - (*k, ViewportInfo { - native_pixels_per_point: Some(2.), - ..Default::default() + let raw_input = egui::RawInput { + viewport_id: surfaces.keys().next().copied().unwrap(), + viewports: surfaces + .keys() + .map(|k| { + (*k, ViewportInfo { + native_pixels_per_point: Some(2.), + ..Default::default() + }) }) - }) - .collect(); + .collect(), + ..Default::default() + }; let mut surfaces_closed = Vec::new(); for (viewport_id, surf) in surfaces.iter_mut() { diff --git a/client/src/state.rs b/client/src/state.rs index b260c9e..c39e13a 100644 --- a/client/src/state.rs +++ b/client/src/state.rs @@ -166,16 +166,14 @@ impl<'a> State<'a> { while let Some(p) = self.audio.pop_output() { self.network.packet_send.send(Packet::Sound(ob, Data(p)))?; } - } else { - if let Some(res) = self.prefab_index.0.get("avatar_test") { - info!("found avatar resource {res}"); - let ob = Object::new(); - self.network - .packet_send - .send(Packet::Add(ob, res.to_owned())) - .unwrap(); - self.avatar_ob = Some(ob) - } + } else if let Some(res) = self.prefab_index.0.get("avatar_test") { + info!("found avatar resource {res}"); + let ob = Object::new(); + self.network + .packet_send + .send(Packet::Add(ob, res.to_owned())) + .unwrap(); + self.avatar_ob = Some(ob) } Ok(()) diff --git a/client/src/window.rs b/client/src/window.rs index dcfb1e8..665aa01 100644 --- a/client/src/window.rs +++ b/client/src/window.rs @@ -96,18 +96,15 @@ impl ApplicationHandler for WindowState { return; } if event.state == ElementState::Pressed { - match event.physical_key { - PhysicalKey::Code(KeyCode::Escape) => { - win.set_cursor_grab(if self.lock { - CursorGrabMode::None - } else { - CursorGrabMode::Locked - }) - .unwrap(); - self.lock = !self.lock; - win.set_cursor(CursorIcon::Default); - } - _ => (), + if let PhysicalKey::Code(KeyCode::Escape) = event.physical_key { + win.set_cursor_grab(if self.lock { + CursorGrabMode::None + } else { + CursorGrabMode::Locked + }) + .unwrap(); + self.lock = !self.lock; + win.set_cursor(CursorIcon::Default); } } sta.input_state.move_dir += match event.physical_key { @@ -141,14 +138,11 @@ impl ApplicationHandler for WindowState { event: winit::event::DeviceEvent, ) { if let Some((_win, sta)) = &mut self.window { - match event { - DeviceEvent::MouseMotion { delta } => { - if self.lock { - sta.input_state.mouse_acc.x += delta.0 as f32; - sta.input_state.mouse_acc.y += delta.1 as f32; - } + if let DeviceEvent::MouseMotion { delta } = event { + if self.lock { + sta.input_state.mouse_acc.x += delta.0 as f32; + sta.input_state.mouse_acc.y += delta.1 as f32; } - _ => (), } } } |