diff --git a/engine/src/framework.rs b/engine/src/framework.rs index effc7e88..dc9182d5 100644 --- a/engine/src/framework.rs +++ b/engine/src/framework.rs @@ -51,7 +51,7 @@ async fn run(el: EventLoop<()>, window: Arc) { target.set_control_flow(ControlFlow::Poll); if let Event::WindowEvent { event, .. } = &event { - ctx.egui.handle_event(&ctx.gfx.window, &event); + ctx.egui.handle_event(&ctx.gfx.window, event); } #[cfg(feature = "yakui")] diff --git a/engine/src/gfx.rs b/engine/src/gfx.rs index 3c9acc8c..40bee113 100644 --- a/engine/src/gfx.rs +++ b/engine/src/gfx.rs @@ -1,4 +1,4 @@ -use crate::passes::{BackgroundPipeline, PBR}; +use crate::passes::{BackgroundPipeline, Pbr}; use crate::perf_counters::PerfCounters; use crate::{ bg_layout_litmesh, passes, CompiledModule, Drawable, IndexType, LampLights, Material, @@ -63,7 +63,7 @@ pub struct GfxContext { pub(crate) screen_uv_vertices: wgpu::Buffer, pub(crate) rect_indices: wgpu::Buffer, pub sun_shadowmap: Texture, - pub pbr: PBR, + pub pbr: Pbr, pub lamplights: LampLights, pub(crate) defines: FastMap, pub(crate) defines_changed: bool, @@ -330,7 +330,7 @@ impl GfxContext { Arc::new(blue_noise), ); - let pbr = PBR::new(&device, &queue); + let pbr = Pbr::new(&device, &queue); let null_texture = TextureBuilder::empty(1, 1, 1, TextureFormat::Rgba8Unorm) .with_srgb(false) .with_label("null texture") @@ -567,7 +567,7 @@ impl GfxContext { .iter_mut() .zip(self.render_params.value().sun_shadow_proj) { - let mut cpy = self.render_params.value().clone(); + let mut cpy = *self.render_params.value(); cpy.proj = mat; *uni.value_mut() = cpy; uni.upload_to_gpu(&self.queue); @@ -745,8 +745,8 @@ impl GfxContext { } } - passes::render_background(self, encs, &frame); - passes::gen_ui_blur(self, encs, &frame); + passes::render_background(self, encs, frame); + passes::gen_ui_blur(self, encs, frame); start_time.elapsed() } @@ -867,7 +867,7 @@ impl GfxContext { self.sky_bg = Texture::multi_bindgroup( &[&*starfield, &self.fbos.fog, &self.pbr.environment_cube], &self.device, - &BackgroundPipeline::bglayout_texs(&self), + &BackgroundPipeline::bglayout_texs(self), ); } diff --git a/engine/src/passes/background.rs b/engine/src/passes/background.rs index f9953a65..5e66f506 100644 --- a/engine/src/passes/background.rs +++ b/engine/src/passes/background.rs @@ -8,7 +8,7 @@ use wgpu::{ RenderPipeline, RenderPipelineDescriptor, TextureFormat, TextureView, VertexState, }; -pub fn render_background(gfx: &GfxContext, encs: &mut Encoders, frame: &&TextureView) { +pub fn render_background(gfx: &GfxContext, encs: &mut Encoders, frame: &TextureView) { profiling::scope!("bg pass"); let mut bg_pass = encs.end.begin_render_pass(&RenderPassDescriptor { label: Some("bg pass"), diff --git a/engine/src/passes/pbr.rs b/engine/src/passes/pbr.rs index 5ca71509..6e5d61ce 100644 --- a/engine/src/passes/pbr.rs +++ b/engine/src/passes/pbr.rs @@ -12,7 +12,7 @@ use wgpu::{ VertexState, }; -pub struct PBR { +pub struct Pbr { pub environment_cube: Texture, environment_uniform: Uniform, environment_bg: BindGroup, @@ -27,7 +27,7 @@ pub struct PBR { } #[derive(Copy, Clone, Debug, PartialEq, Eq, Hash)] -enum PBRPipeline { +enum PbrPipeline { Environment, DiffuseIrradiance, SpecularPrefilter, @@ -49,7 +49,7 @@ struct DiffuseParams { u8slice_impl!(SpecularParams); u8slice_impl!(DiffuseParams); -impl PBR { +impl Pbr { pub fn new(device: &Device, queue: &Queue) -> Self { let environment_cube = TextureBuilder::empty(128, 128, 6, TextureFormat::Rgba16Float) .with_label("environment cubemap") @@ -154,7 +154,7 @@ impl PBR { profiling::scope!("gfx::write_environment_cubemap"); self.environment_uniform .write_direct(&gfx.queue, &sun_pos.normalize().w(0.0)); - let pipe = gfx.get_pipeline(PBRPipeline::Environment); + let pipe = gfx.get_pipeline(PbrPipeline::Environment); for face in 0..6u32 { let view = &self.cube_views[face as usize]; @@ -177,7 +177,7 @@ impl PBR { pub fn write_diffuse_irradiance(&self, gfx: &GfxContext, enc: &mut CommandEncoder) { profiling::scope!("gfx::write_diffuse_irradiance"); - let pipe = gfx.get_pipeline(PBRPipeline::DiffuseIrradiance); + let pipe = gfx.get_pipeline(PbrPipeline::DiffuseIrradiance); self.diffuse_uniform.write_direct( &gfx.queue, &DiffuseParams { @@ -209,7 +209,7 @@ impl PBR { pub fn write_specular_prefilter(&self, gfx: &GfxContext, enc: &mut CommandEncoder) { profiling::scope!("gfx::write_specular_prefilter"); - let pipe = gfx.get_pipeline(PBRPipeline::SpecularPrefilter); + let pipe = gfx.get_pipeline(PbrPipeline::SpecularPrefilter); for mip in 0..self.specular_prefilter_cube.n_mips() { let roughness = mip as f32 / (self.specular_prefilter_cube.n_mips() - 1) as f32; let uni = &self.specular_uniforms[mip as usize]; @@ -316,14 +316,14 @@ impl PBR { } } -impl PipelineBuilder for PBRPipeline { +impl PipelineBuilder for PbrPipeline { fn build( &self, gfx: &GfxContext, mut mk_module: impl FnMut(&str) -> CompiledModule, ) -> RenderPipeline { match self { - PBRPipeline::Environment => { + PbrPipeline::Environment => { let cubemap_vert = &mk_module("to_cubemap.vert"); let cubemap_frag = &mk_module("atmosphere_cubemap.frag"); let cubemappipelayout = @@ -358,7 +358,7 @@ impl PipelineBuilder for PBRPipeline { multiview: None, }) } - PBRPipeline::DiffuseIrradiance => { + PbrPipeline::DiffuseIrradiance => { let cubemap_vert = &mk_module("to_cubemap.vert"); let cubemap_frag = &mk_module("pbr/convolute_diffuse_irradiance.frag"); let bg_layout = Texture::bindgroup_layout(&gfx.device, [TL::Cube]); @@ -396,7 +396,7 @@ impl PipelineBuilder for PBRPipeline { multiview: None, }) } - PBRPipeline::SpecularPrefilter => { + PbrPipeline::SpecularPrefilter => { let cubemap_vert = &mk_module("to_cubemap.vert"); let cubemap_frag = &mk_module("pbr/specular_prefilter.frag"); let bg_layout = Texture::bindgroup_layout(&gfx.device, [TL::Cube]); diff --git a/engine/src/pipelines.rs b/engine/src/pipelines.rs index c714e68e..8262f33d 100644 --- a/engine/src/pipelines.rs +++ b/engine/src/pipelines.rs @@ -18,6 +18,7 @@ pub trait PipelineBuilder: Hash + 'static { type ShaderPath = String; type PipelineHash = u64; +#[derive(Default)] pub struct Pipelines { pub(crate) shader_cache: FastMap, pub(crate) shader_watcher: FastMap, Option)>, @@ -28,12 +29,7 @@ pub struct Pipelines { impl Pipelines { pub fn new() -> Pipelines { - Pipelines { - shader_cache: FastMap::default(), - shader_watcher: Default::default(), - pipelines: Default::default(), - pipelines_deps: Default::default(), - } + Pipelines::default() } pub fn get_module( diff --git a/engine/src/texture.rs b/engine/src/texture.rs index 77231d33..1fa0f78b 100644 --- a/engine/src/texture.rs +++ b/engine/src/texture.rs @@ -742,7 +742,7 @@ impl MipmapGenerator { entries: &[ BindGroupEntry { binding: 0, - resource: wgpu::BindingResource::TextureView(&src), + resource: wgpu::BindingResource::TextureView(src), }, BindGroupEntry { binding: 1, @@ -755,7 +755,7 @@ impl MipmapGenerator { let mut rpass = encoder.begin_render_pass(&wgpu::RenderPassDescriptor { label: Some(&format!("mip generation for {label}")), color_attachments: &[Some(wgpu::RenderPassColorAttachment { - view: &dst, + view: dst, resolve_target: None, ops: wgpu::Operations { load: wgpu::LoadOp::Clear(wgpu::Color::WHITE), @@ -766,7 +766,7 @@ impl MipmapGenerator { timestamp_writes: None, occlusion_query_set: None, }); - rpass.set_pipeline(&pipeline); + rpass.set_pipeline(pipeline); rpass.set_bind_group(0, &bind_group, &[]); rpass.draw(0..3, 0..1); } diff --git a/geom/src/heightmap.rs b/geom/src/heightmap.rs index 42c42072..7668f108 100644 --- a/geom/src/heightmap.rs +++ b/geom/src/heightmap.rs @@ -529,7 +529,7 @@ pub fn pack_height(height: f32) -> u16 { } let height_off = height_off - HALF_HEIGHT_DIFF; - return (HALF_U16 as f32 + height_off / HALF_HEIGHT_DIFF * HALF_U16 as f32) as u16; + (HALF_U16 as f32 + height_off / HALF_HEIGHT_DIFF * HALF_U16 as f32) as u16 } fn unpack_height(height: u16) -> f32 { @@ -538,7 +538,7 @@ fn unpack_height(height: u16) -> f32 { } let height = height - HALF_U16; - return MIN_HEIGHT + HALF_HEIGHT_DIFF + height as f32 / HALF_U16 as f32 * HALF_HEIGHT_DIFF; + MIN_HEIGHT + HALF_HEIGHT_DIFF + height as f32 / HALF_U16 as f32 * HALF_HEIGHT_DIFF } #[cfg(test)] diff --git a/goryak/src/window.rs b/goryak/src/window.rs index d2231008..f7bfcc03 100644 --- a/goryak/src/window.rs +++ b/goryak/src/window.rs @@ -101,7 +101,7 @@ impl Widget for WindowBase { let mut pos = vp * 0.5 - size * 0.5 + self.off + self.resp.off.get(); let overflow = (pos + size - vp).max(Vec2::ZERO); - pos = pos - overflow; + pos -= overflow; pos = pos.max(Vec2::ZERO); ctx.layout.set_pos(child, pos); diff --git a/native_app/src/newgui/hud/time_controls.rs b/native_app/src/newgui/hud/time_controls.rs index ae5aa08a..e1641b0e 100644 --- a/native_app/src/newgui/hud/time_controls.rs +++ b/native_app/src/newgui/hud/time_controls.rs @@ -46,7 +46,7 @@ pub fn time_controls(gui: &mut Gui, uiworld: &mut UiWorld, sim: &Simulation) { }); } - let mut time_text = || { + let time_text = || { padx(5.0, || { row(|| { monospace(on_secondary_container(), format!("Day {}", time.day)); @@ -99,7 +99,7 @@ pub fn time_controls(gui: &mut Gui, uiworld: &mut UiWorld, sim: &Simulation) { l.cross_axis_alignment = CrossAxisAlignment::Stretch; l.main_axis_size = MainAxisSize::Min; l.item_spacing = tweak!(5.0); - l.show(|| time_text()); + l.show(time_text); }); }); }); diff --git a/prototypes/src/prototypes/building.rs b/prototypes/src/prototypes/building.rs index 8f4d989a..6b7baeff 100644 --- a/prototypes/src/prototypes/building.rs +++ b/prototypes/src/prototypes/building.rs @@ -98,7 +98,7 @@ impl<'a> FromLua<'a> for BuildingGen { vertical_factor: get_lua(&table, "vertical_factor")?, }), "no_walkway" => Ok(Self::NoWalkway { - door_pos: get_v2(&table, "door_pos")?.into(), + door_pos: get_v2(&table, "door_pos")?, }), _ => Err(mlua::Error::external(format!( "Unknown building gen kind: {}", diff --git a/prototypes/src/types/geom.rs b/prototypes/src/types/geom.rs index ce70a825..bb2e7029 100644 --- a/prototypes/src/types/geom.rs +++ b/prototypes/src/types/geom.rs @@ -13,15 +13,15 @@ pub struct LuaVec3(pub Vec3); #[repr(transparent)] pub struct LuaColor(pub Color); -impl Into for LuaVec2 { - fn into(self) -> Vec2 { - self.0 +impl From for Vec2 { + fn from(v: LuaVec2) -> Self { + v.0 } } -impl Into for LuaVec3 { - fn into(self) -> Vec3 { - self.0 +impl From for Vec3 { + fn from(v: LuaVec3) -> Self { + v.0 } } diff --git a/prototypes/src/types/time.rs b/prototypes/src/types/time.rs index a4af49bb..d565aa9a 100644 --- a/prototypes/src/types/time.rs +++ b/prototypes/src/types/time.rs @@ -181,7 +181,7 @@ impl RecTimeInterval { if t_day >= self.end_seconds { return d + SECONDS_PER_DAY; } - return d; + d } } @@ -462,7 +462,7 @@ impl<'lua> FromLua<'lua> for Tick { for kv in t.pairs::() { let (k, v) = kv?; - let v = parse_tick_suffix(v, &*k).ok_or_else(|| { + let v = parse_tick_suffix(v, &k).ok_or_else(|| { mlua::Error::FromLuaConversionError { from: "string", to: "Tick", @@ -521,7 +521,7 @@ fn parse_daytime(s: &str) -> Result<(DayTime, &str), DayTimeParsingError> { if rest.is_empty() { return Err(InvalidHourSuffix); } - let rest = match rest.split_once(&[':', 'h']) { + let rest = match rest.split_once([':', 'h']) { Some((_, rest)) => rest, None => return Err(InvalidHourSuffix), }; @@ -644,13 +644,11 @@ impl<'lua> FromLua<'lua> for RecTimeInterval { let end: DayTime = get_lua(&t, "end")?; Ok(RecTimeInterval::new_daysec(start.daysec(), end.daysec())) } - _ => { - return Err(mlua::Error::FromLuaConversionError { - from: value.type_name(), - to: "RecTimeInterval", - message: Some("expected string or table".into()), - }) - } + _ => Err(mlua::Error::FromLuaConversionError { + from: value.type_name(), + to: "RecTimeInterval", + message: Some("expected string or table".into()), + }), } } } diff --git a/simulation/src/map/electricity_cache.rs b/simulation/src/map/electricity_cache.rs index 26839594..fd265578 100644 --- a/simulation/src/map/electricity_cache.rs +++ b/simulation/src/map/electricity_cache.rs @@ -128,11 +128,11 @@ impl ElectricityCache { self.graph.get_mut(src).unwrap().push(*dst); self.graph.get_mut(dst).unwrap().push(*src); - let Some(src) = self.ids.get(&src) else { + let Some(src) = self.ids.get(src) else { log::error!("electricity add_edge src {:?} not found", src); return; }; - let Some(dst) = self.ids.get(&dst) else { + let Some(dst) = self.ids.get(dst) else { log::error!("electricity add_edge dst {:?} not found", dst); return; }; @@ -162,11 +162,11 @@ impl ElectricityCache { self.graph.get_mut(src).unwrap().retain(|v| v != dst); self.graph.get_mut(dst).unwrap().retain(|v| v != src); - let Some(src_net) = self.ids.get(&src) else { + let Some(src_net) = self.ids.get(src) else { log::error!("electricity remove_edge src {:?} not found", src); return; }; - let Some(dst_net) = self.ids.get(&dst) else { + let Some(dst_net) = self.ids.get(dst) else { log::error!("electricity remove_edge dst {:?} not found", dst); return; };