game: run clippy

This commit is contained in:
SeanOMik 2024-06-28 13:25:48 -04:00
parent 96dea5b1f9
commit 2eeca335e2
Signed by: SeanOMik
GPG Key ID: FEC9E2FC15235964
15 changed files with 83 additions and 83 deletions

View File

@ -160,6 +160,10 @@ impl<E: Event> EventReader<E> {
pub fn len(&self) -> usize {
self.buf.len()
}
pub fn is_empty(&self) -> bool {
self.len() == 0
}
}
impl<E: Event> Iterator for EventReader<E> {

View File

@ -92,10 +92,7 @@ impl<T: Button> InputButtons<T> {
pub fn was_just_pressed(&self, button: T) -> bool {
let hash = Self::get_button_hash(&button);
match self.button_events.get(&hash) {
Some(button_event) => match button_event {
ButtonEvent::JustPressed(b) if button == *b => true,
_ => false,
},
Some(button_event) => matches!(button_event, ButtonEvent::JustPressed(b) if button == *b),
None => false
}
}
@ -105,11 +102,8 @@ impl<T: Button> InputButtons<T> {
/// This must be done so that a key does not stay as JustPressed between multiple ticks
pub fn update(&mut self) {
for bev in self.button_events.values_mut() {
match bev {
ButtonEvent::JustPressed(btn) => {
if let ButtonEvent::JustPressed(btn) = bev {
*bev = ButtonEvent::Pressed(btn.clone());
},
_ => {},
}
}
}

View File

@ -67,7 +67,7 @@ impl<T> AVec<T> {
#[inline(always)]
fn slot_size(&self) -> usize {
let a = self.align - 1;
mem::align_of::<T>() + (a) & !a
(mem::align_of::<T>() + (a)) & !a
}
/// # Panics

View File

@ -135,7 +135,7 @@ impl RenderGraph {
}
pub fn device(&self) -> &wgpu::Device {
&*self.device
&self.device
}
/// Add a [`Node`] to the RenderGraph.
@ -252,7 +252,7 @@ impl RenderGraph {
let mut sorted: VecDeque<RenderGraphLabelValue> = petgraph::algo::toposort(&self.node_graph, None)
.expect("RenderGraph had cycled!")
.iter()
.map(|i| self.node_graph[i.clone()].clone())
.map(|i| self.node_graph[*i].clone())
.collect();
while let Some(node_label) = sorted.pop_front() {
@ -277,14 +277,12 @@ impl RenderGraph {
let slot = self
.slots
.get(&bufwr.target_slot)
.expect(&format!(
"Failed to find slot '{:?}' for buffer write",
bufwr.target_slot
));
.unwrap_or_else(|| panic!("Failed to find slot '{:?}' for buffer write",
bufwr.target_slot));
let buf = slot
.value
.as_buffer()
.expect(&format!("Slot '{:?}' is not a buffer", bufwr.target_slot));
.unwrap_or_else(|| panic!("Slot '{:?}' is not a buffer", bufwr.target_slot));
self.queue.write_buffer(buf, bufwr.offset, &bufwr.bytes);
}
@ -302,7 +300,7 @@ impl RenderGraph {
let mut sorted: VecDeque<RenderGraphLabelValue> = petgraph::algo::toposort(&self.node_graph, None)
.expect("RenderGraph had cycled!")
.iter()
.map(|i| self.node_graph[i.clone()].clone())
.map(|i| self.node_graph[*i].clone())
.collect();
// A bit of 'encoder hot potato' is played using this.
@ -361,6 +359,7 @@ impl RenderGraph {
.and_then(|p| {
let v = p.pipeline.borrow();
#[allow(clippy::manual_map)]
match &*v {
Some(_) => Some(Ref::map(v, |p| p.as_ref().unwrap())),
None => None,
@ -527,7 +526,7 @@ impl SubGraphNode {
}
impl Node for SubGraphNode {
fn desc<'a, 'b>(&'a mut self, _: &'b mut RenderGraph) -> NodeDesc {
fn desc(&mut self, _: &mut RenderGraph) -> NodeDesc {
NodeDesc::new(NodeType::Graph, None, vec![])
}

View File

@ -161,7 +161,7 @@ impl RenderGraphPipelineInfo {
label: Some(label.to_string()),
bind_group_layouts: bind_group_layouts
.into_iter()
.map(|bgl| Rc::new(bgl))
.map(Rc::new)
.collect(),
vertex,
primitive,
@ -356,7 +356,7 @@ impl NodeDesc {
/// describes all resources the node requires for execution during the `execute` phase.
pub trait Node: 'static {
/// Retrieve a descriptor of the Node.
fn desc<'a, 'b>(&'a mut self, graph: &'b mut RenderGraph) -> NodeDesc;
fn desc(&mut self, graph: &mut RenderGraph) -> NodeDesc;
/// Prepare the node for rendering.
///

View File

@ -55,7 +55,7 @@ impl Node for BasePass {
.visibility(wgpu::ShaderStages::COMPUTE)
.buffer_dynamic_offset(false)
.contents(&[self.screen_size])
.finish_parts(&graph.device());
.finish_parts(graph.device());
let screen_size_bgl = Rc::new(screen_size_bgl);
let screen_size_bg = Rc::new(screen_size_bg);
@ -65,12 +65,12 @@ impl Node for BasePass {
.visibility(wgpu::ShaderStages::all())
.buffer_dynamic_offset(false)
.contents(&[CameraUniform::default()])
.finish_parts(&graph.device());
.finish_parts(graph.device());
let camera_bgl = Rc::new(camera_bgl);
let camera_bg = Rc::new(camera_bg);
// create the depth texture using the utility struct, then take all the required fields
let mut depth_texture = RenderTexture::create_depth_texture(&graph.device(), self.screen_size, "depth_texture");
let mut depth_texture = RenderTexture::create_depth_texture(graph.device(), self.screen_size, "depth_texture");
depth_texture.create_bind_group(&graph.device);
let dt_bg_pair = depth_texture.bindgroup_pair.unwrap();

View File

@ -10,7 +10,7 @@ pub struct InitNode {
}
impl Node for InitNode {
fn desc<'a, 'b>(&'a mut self, _: &'b mut crate::render::graph::RenderGraph) -> crate::render::graph::NodeDesc {
fn desc(&mut self, _: &mut crate::render::graph::RenderGraph) -> crate::render::graph::NodeDesc {
let mut desc = NodeDesc::new(NodeType::Node, None, vec![]);
// the slots can just be cloned since the slot attribute doesn't really matter much.
desc.slots = self.slots.clone();

View File

@ -59,7 +59,7 @@ impl Node for LightCullComputePass {
let light_index_counter_buffer =
device.create_buffer_init(&wgpu::util::BufferInitDescriptor {
label: Some("light_index_counter_buffer"),
contents: &bytemuck::cast_slice(&[0]),
contents: bytemuck::cast_slice(&[0]),
usage: wgpu::BufferUsages::STORAGE | wgpu::BufferUsages::COPY_DST,
});

View File

@ -174,12 +174,12 @@ impl MeshPass {
let material = self.material_buffers.entry(material.uuid())
.or_insert_with(|| {
debug!(uuid=material.uuid().to_string(), "Sending material to gpu");
Rc::new(Material::from_resource(&device, &queue, self.texture_bind_group_layout.clone().unwrap(), &material_ref))
Rc::new(Material::from_resource(device, queue, self.texture_bind_group_layout.clone().unwrap(), &material_ref))
});
// TODO: support material uniforms from multiple uniforms
let uni = MaterialUniform::from(&**material);
queue.write_buffer(&self.material_buffer.as_ref().unwrap(), 0, bytemuck::bytes_of(&uni));
queue.write_buffer(self.material_buffer.as_ref().unwrap(), 0, bytemuck::bytes_of(&uni));
MeshBufferStorage {
buffer_vertex: vertex_buffer,
@ -215,7 +215,7 @@ impl Node for MeshPass {
//let transform_bgl = transforms.bindgroup_layout.clone();
self.transforms = Some(transforms);
let texture_bind_group_layout = Rc::new(RenderTexture::create_layout(&device));
let texture_bind_group_layout = Rc::new(RenderTexture::create_layout(device));
self.texture_bind_group_layout = Some(texture_bind_group_layout.clone());
let (material_bgl, material_bg, material_buf, _) = BufferWrapper::builder()
@ -232,7 +232,7 @@ impl Node for MeshPass {
// load the default texture
let bytes = include_bytes!("../../default_texture.png");
self.default_texture = Some(RenderTexture::from_bytes(&device, &graph.queue, texture_bind_group_layout.clone(), bytes, "default_texture").unwrap());
self.default_texture = Some(RenderTexture::from_bytes(device, &graph.queue, texture_bind_group_layout.clone(), bytes, "default_texture").unwrap());
// get surface config format
/* let main_rt = graph.slot_value(BasePassSlots::MainRenderTarget)
@ -251,7 +251,9 @@ impl Node for MeshPass {
source: include_str!("../../shaders/base.wgsl").to_string(),
}); */
let desc = NodeDesc::new(
NodeDesc::new(
NodeType::Render,
None,
/* Some(PipelineDescriptor::Render(RenderPipelineDescriptor {
@ -296,9 +298,7 @@ impl Node for MeshPass {
vec![
(&MeshesPassSlots::Material, material_bg, Some(material_bgl)),
],
);
desc
)
}
#[instrument(skip(self, graph, world, context))]
@ -368,7 +368,7 @@ impl Node for MeshPass {
let transforms = self.transforms.as_mut().unwrap();
if transforms.needs_expand() {
debug!("Expanding transform buffers");
transforms.expand_buffers(&device);
transforms.expand_buffers(device);
}
}
@ -377,14 +377,14 @@ impl Node for MeshPass {
// if process mesh did not just create a new mesh, and the epoch
// shows that the scene has changed, verify that the mesh buffers
// dont need to be resent to the gpu.
if !self.process_mesh(&device, &queue, entity, &*mesh, mesh_han.uuid())
if !self.process_mesh(device, queue, entity, &mesh, mesh_han.uuid())
&& mesh_epoch == last_epoch {
self.check_mesh_buffers(&device, &queue, &mesh_han);
self.check_mesh_buffers(device, queue, &mesh_han);
}
let transforms = self.transforms.as_mut().unwrap();
let group = TransformGroup::EntityRes(entity, mesh_han.uuid());
let transform_id = transforms.update_or_push(&device, &queue, &render_limits,
let transform_id = transforms.update_or_push(device, queue, &render_limits,
group, interp_transform.calculate_mat4(), glam::Mat3::from_quat(interp_transform.rotation));
let material = mesh.material.as_ref().unwrap()
@ -409,15 +409,15 @@ impl Node for MeshPass {
// if process mesh did not just create a new mesh, and the epoch
// shows that the scene has changed, verify that the mesh buffers
// dont need to be resent to the gpu.
if !self.process_mesh(&device, &queue, entity, &*mesh, mesh_han.uuid())
if !self.process_mesh(device, queue, entity, &mesh, mesh_han.uuid())
&& scene_epoch == last_epoch {
self.check_mesh_buffers(&device, &queue, &mesh_han);
self.check_mesh_buffers(device, queue, &mesh_han);
}
let transforms = self.transforms.as_mut().unwrap();
let scene_mesh_group = TransformGroup::Res(scene_han.uuid(), mesh_han.uuid());
let group = TransformGroup::OwnedGroup(entity, scene_mesh_group.into());
let transform_id = transforms.update_or_push(&device, &queue, &render_limits,
let transform_id = transforms.update_or_push(device, queue, &render_limits,
group, mesh_interpo.calculate_mat4(), glam::Mat3::from_quat(mesh_interpo.rotation) );
let material = mesh.material.as_ref().unwrap()
@ -436,7 +436,7 @@ impl Node for MeshPass {
}
let transforms = self.transforms.as_mut().unwrap();
transforms.send_to_gpu(&queue);
transforms.send_to_gpu(queue);
if self.pipeline.is_none() {
let device = graph.device();
@ -537,7 +537,7 @@ impl Node for MeshPass {
let mut pass = encoder.begin_render_pass(&wgpu::RenderPassDescriptor {
label: Some("Render Pass"),
color_attachments: &[Some(wgpu::RenderPassColorAttachment {
view: &view,
view,
resolve_target: None,
ops: wgpu::Operations {
load: wgpu::LoadOp::Clear(wgpu::Color {
@ -551,7 +551,7 @@ impl Node for MeshPass {
})],
// enable depth buffer
depth_stencil_attachment: Some(wgpu::RenderPassDepthStencilAttachment {
view: &depth_view,
view: depth_view,
depth_ops: Some(wgpu::Operations {
load: wgpu::LoadOp::Clear(1.0),
store: true,
@ -560,7 +560,7 @@ impl Node for MeshPass {
}),
});
pass.set_pipeline(&pipeline);
pass.set_pipeline(pipeline);
//let material_buffer_bg = self.material_buffer.as_ref().unwrap().bindgroup();
let default_texture = self.default_texture.as_ref().unwrap();
@ -596,11 +596,11 @@ impl Node for MeshPass {
let offset = transforms.buffer_offset(job.transform_id);
pass.set_bind_group(1, bindgroup, &[ offset, ]);
pass.set_bind_group(2, &camera_bg, &[]);
pass.set_bind_group(3, &lights_bg, &[]);
pass.set_bind_group(4, &material_bg, &[]);
pass.set_bind_group(2, camera_bg, &[]);
pass.set_bind_group(3, lights_bg, &[]);
pass.set_bind_group(4, material_bg, &[]);
pass.set_bind_group(6, &light_grid_bg, &[]);
pass.set_bind_group(6, light_grid_bg, &[]);
// if this mesh uses indices, use them to draw the mesh
if let Some((idx_type, indices)) = buffers.buffer_indices.as_ref() {

View File

@ -27,9 +27,9 @@ impl TintPass {
}
impl Node for TintPass {
fn desc<'a, 'b>(
&'a mut self,
graph: &'b mut crate::render::graph::RenderGraph,
fn desc(
&mut self,
graph: &mut crate::render::graph::RenderGraph,
) -> crate::render::graph::NodeDesc {
let device = &graph.device;
@ -64,7 +64,9 @@ impl Node for TintPass {
});
let vt = graph.view_target();
let desc = NodeDesc::new(
NodeDesc::new(
NodeType::Render,
Some(PipelineDescriptor::Render(RenderPipelineDescriptor {
label: Some("tint_pass".into()),
@ -90,9 +92,7 @@ impl Node for TintPass {
multiview: None,
})),
vec![],
);
desc
)
}
fn prepare(
@ -148,7 +148,7 @@ impl Node for TintPass {
let mut pass = encoder.begin_render_pass(&wgpu::RenderPassDescriptor {
label: Some("tint_pass"),
color_attachments: &[Some(wgpu::RenderPassColorAttachment {
view: &dest_view,
view: dest_view,
resolve_target: None,
ops: wgpu::Operations {
load: wgpu::LoadOp::Load,
@ -157,7 +157,7 @@ impl Node for TintPass {
})],
depth_stencil_attachment: None,
});
pass.set_pipeline(&pipeline.as_render());
pass.set_pipeline(pipeline.as_render());
pass.set_bind_group(0, bg, &[]);
pass.draw(0..3, 0..1);

View File

@ -116,9 +116,9 @@ impl BufferWrapper {
/// match the layout of this bind group.
///
/// See [`wgpu::RenderPass::set_bind_group`](https://docs.rs/wgpu/latest/wgpu/struct.RenderPass.html#method.set_bind_group).
pub fn render_pass_bind_at<'a, 'b>(
pub fn render_pass_bind_at<'a>(
&'a self,
pass: &'b mut wgpu::RenderPass<'a>,
pass: &mut wgpu::RenderPass<'a>,
index: u32,
offsets: &[wgpu::DynamicOffset],
) {

View File

@ -74,7 +74,7 @@ impl ComputePipeline {
// they share the same shader. I tried to do it without an Rc but couldn't get past
// the borrow checker
let compiled_shader = Rc::new(device.create_shader_module(wgpu::ShaderModuleDescriptor {
label: desc.shader.label.as_ref().map(|s| s.as_str()),
label: desc.shader.label.as_deref(),
source: wgpu::ShaderSource::Wgsl(std::borrow::Cow::Borrowed(
&desc.shader.source,
)),

View File

@ -27,19 +27,19 @@ pub enum Pipeline {
Compute(ComputePipeline),
}
impl Into<RenderPipeline> for Pipeline {
fn into(self) -> RenderPipeline {
match self {
Self::Render(r) => r,
impl From<Pipeline> for RenderPipeline {
fn from(val: Pipeline) -> Self {
match val {
Pipeline::Render(r) => r,
_ => panic!("Pipeline is not a RenderPipeline"),
}
}
}
impl Into<ComputePipeline> for Pipeline {
fn into(self) -> ComputePipeline {
match self {
Self::Compute(c) => c,
impl From<Pipeline> for ComputePipeline {
fn from(val: Pipeline) -> Self {
match val {
Pipeline::Compute(c) => c,
_ => panic!("Pipeline is not a RenderPipeline"),
}
}

View File

@ -88,13 +88,13 @@ impl RenderPipeline {
// they share the same shader. I tried to do it without an Rc but couldn't get past
// the borrow checker
let vrtx_shad = Rc::new(device.create_shader_module(wgpu::ShaderModuleDescriptor {
label: desc.vertex.module.label.as_ref().map(|s| s.as_str()),
label: desc.vertex.module.label.as_deref(),
source: wgpu::ShaderSource::Wgsl(std::borrow::Cow::Borrowed(
&desc.vertex.module.source,
)),
}));
let vrtx_state = wgpu::VertexState {
module: &*vrtx_shad,
module: &vrtx_shad,
entry_point: &desc.vertex.entry_point,
buffers: &vrtx_buffs,
};
@ -104,7 +104,7 @@ impl RenderPipeline {
vrtx_shad.clone()
} else {
Rc::new(device.create_shader_module(wgpu::ShaderModuleDescriptor {
label: f.module.label.as_ref().map(|s| s.as_str()),
label: f.module.label.as_deref(),
source: wgpu::ShaderSource::Wgsl(std::borrow::Cow::Borrowed(&f.module.source)),
}))
}

View File

@ -106,16 +106,19 @@ impl<K: Hash + Eq + PartialEq + Clone, V: Clone, S: BuildHasher> CachedValMap<K,
where
F: FnMut() -> V
{
if self.latest.contains_key(&key) {
self.latest.insert(key, val_fn());
match self.latest.entry(key) {
std::collections::hash_map::Entry::Occupied(mut e) => {
e.insert(val_fn());
None
} else {
}
std::collections::hash_map::Entry::Vacant(e) => {
let val = self.dead.pop_front()
.unwrap_or_else(val_fn);
self.latest.insert(key, val.clone());
e.insert(val.clone());
Some(val)
}
}
}
/// Returns a reference to the value corresponding to the key.
pub fn get(&mut self, key: K) -> Option<&V> {
@ -217,7 +220,7 @@ impl TransformBuffers {
entry.len = 0;
let p = entry.transforms.as_ptr();
let bytes = unsafe { std::slice::from_raw_parts(p as *const u8, entry.transforms.len() * entry.transforms.align()) };
let bytes = unsafe { std::slice::from_raw_parts(p, entry.transforms.len() * entry.transforms.align()) };
queue.write_buffer(&entry.buffer, 0, bytes);
}
@ -334,9 +337,9 @@ impl TransformBuffers {
pub fn buffer_offset(&self, transform_index: TransformIndex) -> u32 {
//Self::get_buffer_offset(&self.limits, transform_index)
let transform_index = transform_index.transform_index % self.max_transform_count;
let t = transform_index as u32 * self.limits.min_uniform_buffer_offset_alignment as u32;
//debug!("offset: {t}");
t
transform_index as u32 * self.limits.min_uniform_buffer_offset_alignment
}
/// Returns a boolean indicating if the buffers need to be expanded