Skip to content

Commit

Permalink
clippy
Browse files Browse the repository at this point in the history
  • Loading branch information
Uriopass committed Feb 3, 2024
1 parent 0abecfc commit 87c5b42
Show file tree
Hide file tree
Showing 13 changed files with 48 additions and 54 deletions.
2 changes: 1 addition & 1 deletion engine/src/framework.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ async fn run<S: State>(el: EventLoop<()>, window: Arc<Window>) {
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")]
Expand Down
14 changes: 7 additions & 7 deletions engine/src/gfx.rs
Original file line number Diff line number Diff line change
@@ -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,
Expand Down Expand Up @@ -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<String, String>,
pub(crate) defines_changed: bool,
Expand Down Expand Up @@ -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")
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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()
}
Expand Down Expand Up @@ -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),
);
}

Expand Down
2 changes: 1 addition & 1 deletion engine/src/passes/background.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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"),
Expand Down
20 changes: 10 additions & 10 deletions engine/src/passes/pbr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ use wgpu::{
VertexState,
};

pub struct PBR {
pub struct Pbr {
pub environment_cube: Texture,
environment_uniform: Uniform<Vec4>,
environment_bg: BindGroup,
Expand All @@ -27,7 +27,7 @@ pub struct PBR {
}

#[derive(Copy, Clone, Debug, PartialEq, Eq, Hash)]
enum PBRPipeline {
enum PbrPipeline {
Environment,
DiffuseIrradiance,
SpecularPrefilter,
Expand All @@ -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")
Expand Down Expand Up @@ -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];
Expand All @@ -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 {
Expand Down Expand Up @@ -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];
Expand Down Expand Up @@ -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 =
Expand Down Expand Up @@ -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]);
Expand Down Expand Up @@ -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]);
Expand Down
8 changes: 2 additions & 6 deletions engine/src/pipelines.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<ShaderPath, CompiledModule>,
pub(crate) shader_watcher: FastMap<ShaderPath, (Vec<ShaderPath>, Option<SystemTime>)>,
Expand All @@ -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(
Expand Down
6 changes: 3 additions & 3 deletions engine/src/texture.rs
Original file line number Diff line number Diff line change
Expand Up @@ -742,7 +742,7 @@ impl MipmapGenerator {
entries: &[
BindGroupEntry {
binding: 0,
resource: wgpu::BindingResource::TextureView(&src),
resource: wgpu::BindingResource::TextureView(src),
},
BindGroupEntry {
binding: 1,
Expand All @@ -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),
Expand All @@ -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);
}
Expand Down
4 changes: 2 additions & 2 deletions geom/src/heightmap.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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)]
Expand Down
2 changes: 1 addition & 1 deletion goryak/src/window.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
4 changes: 2 additions & 2 deletions native_app/src/newgui/hud/time_controls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down Expand Up @@ -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);
});
});
});
Expand Down
2 changes: 1 addition & 1 deletion prototypes/src/prototypes/building.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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: {}",
Expand Down
12 changes: 6 additions & 6 deletions prototypes/src/types/geom.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,15 @@ pub struct LuaVec3(pub Vec3);
#[repr(transparent)]
pub struct LuaColor(pub Color);

impl Into<Vec2> for LuaVec2 {
fn into(self) -> Vec2 {
self.0
impl From<LuaVec2> for Vec2 {
fn from(v: LuaVec2) -> Self {
v.0
}
}

impl Into<Vec3> for LuaVec3 {
fn into(self) -> Vec3 {
self.0
impl From<LuaVec3> for Vec3 {
fn from(v: LuaVec3) -> Self {
v.0
}
}

Expand Down
18 changes: 8 additions & 10 deletions prototypes/src/types/time.rs
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ impl RecTimeInterval {
if t_day >= self.end_seconds {
return d + SECONDS_PER_DAY;
}
return d;
d
}
}

Expand Down Expand Up @@ -462,7 +462,7 @@ impl<'lua> FromLua<'lua> for Tick {
for kv in t.pairs::<String, Number>() {
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",
Expand Down Expand Up @@ -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),
};
Expand Down Expand Up @@ -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()),
}),
}
}
}
Expand Down
8 changes: 4 additions & 4 deletions simulation/src/map/electricity_cache.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
};
Expand Down Expand Up @@ -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;
};
Expand Down

0 comments on commit 87c5b42

Please sign in to comment.