diff --git a/build.rs b/build.rs index 4b5b92caff547a6b525177a43dcfe2fc5fbd5ffd..1a3f51c2c0dd7b467460cef09793974926345660 100644 --- a/build.rs +++ b/build.rs @@ -1,5 +1,5 @@ use std::env; -use std::fmt::format; + use std::fs; use std::fs::File; use std::io; @@ -59,23 +59,21 @@ fn main() -> io::Result<()> { for (index, l) in f.lines().enumerate() { let line = l?; let entries = line.split("//").map(str::trim).collect::<Vec<&str>>(); - if entries[0].len() == 0 { + if entries[0].is_empty() { continue; } let name = &entries[0][11..entries[0].len() - 12]; out += &format!( - "#[allow(non_snake_case)]\n#[allow(dead_code)]\n{}={},\n", - name, index + "#[allow(non_snake_case)]\n#[allow(dead_code)]\n{name}={index},\n" ); inputimpl += &format!( - "#[allow(non_snake_case)]\nInstructionSet::{} => vec![", - name + "#[allow(non_snake_case)]\nInstructionSet::{name} => vec![" ); - for input in entries[1].split(" ").map(str::trim) { - if input.len() == 0 { + for input in entries[1].split(' ').map(str::trim) { + if input.is_empty() { continue; } match input { @@ -86,17 +84,16 @@ fn main() -> io::Result<()> { "M2" => inputimpl += "InputTypes::Mat2,", "M3" => inputimpl += "InputTypes::Mat3,", "M4" => inputimpl += "InputTypes::Mat4,", - _ => panic!("unknown input?? [{}]", input), + _ => panic!("unknown input?? [{input}]"), } } inputimpl += "],\n"; outputimpl += &format!( - "#[allow(non_snake_case)]\nInstructionSet::{} => vec![", - name + "#[allow(non_snake_case)]\nInstructionSet::{name} => vec![" ); - for output in entries[2].split(" ").map(str::trim) { - if output.len() == 0 { + for output in entries[2].split(' ').map(str::trim) { + if output.is_empty() { continue; } match output { @@ -107,7 +104,7 @@ fn main() -> io::Result<()> { "M2" => outputimpl += "InputTypes::Mat2,", "M3" => outputimpl += "InputTypes::Mat3,", "M4" => outputimpl += "InputTypes::Mat4,", - _ => panic!("unknown output?? [{}]", output), + _ => panic!("unknown output?? [{output}]"), } } outputimpl += "],\n"; @@ -120,7 +117,7 @@ fn main() -> io::Result<()> { out += &outputimpl; out += "}"; - fs::write(&dest_path, out).unwrap(); + fs::write(dest_path, out).unwrap(); println!("cargo:rerun-if-changed=build.rs"); Ok(()) } diff --git a/src/interpreter.rs b/src/interpreter.rs index 5be2494f27066c1a561b9fb1d0da505ca8f00a77..459c5dc168c61085b76ec9110ad9719684d55b47 100644 --- a/src/interpreter.rs +++ b/src/interpreter.rs @@ -723,7 +723,7 @@ impl<'csg> Interpreter<'csg> { } } - fn clear_stacks(&mut self) -> () { + fn clear_stacks(&mut self) { self.float_stack.clear(); self.vec2_stack.clear(); self.vec3_stack.clear(); @@ -1704,6 +1704,6 @@ impl<'csg> Interpreter<'csg> { } } } - return self.pull(Inputs::Variable); + self.pull(Inputs::Variable) } } diff --git a/src/main.rs b/src/main.rs index 3882533e5a2595cdbc6b567280683fa12540fe38..3b8bdc9166953040a49466bbc1aa3f40c8ef500b 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,8 +1,8 @@ #![feature(variant_count)] use bytemuck::{Zeroable, Pod}; use cgmath::{ - Deg, EuclideanSpace, Euler, Matrix2, Matrix3, Matrix4, Point3, Rad, SquareMatrix, Vector2, - Vector3, Vector4, Zero, + Deg, EuclideanSpace, Euler, Matrix3, Matrix4, Point3, Rad, SquareMatrix, + Vector3, }; use instruction_set::InputTypes; use vulkano::command_buffer::{CopyBufferInfo, PrimaryCommandBufferAbstract}; @@ -15,7 +15,7 @@ use vulkano::descriptor_set::allocator::StandardDescriptorSetAllocator; use vulkano::descriptor_set::{PersistentDescriptorSet, WriteDescriptorSet}; use vulkano::device::{DeviceOwned, Features, QueueFlags, Queue}; use vulkano::format::Format; -use vulkano::half::f16; + use vulkano::image::view::ImageViewCreateInfo; use vulkano::image::{AttachmentImage, SampleCount}; use vulkano::memory::allocator::{MemoryAllocatePreference, MemoryUsage, StandardMemoryAllocator}; @@ -132,7 +132,7 @@ fn main() { p.queue_family_properties() .iter() .enumerate() - .position(|(i, q)| { + .position(|(_i, q)| { q.queue_flags.intersects(QueueFlags::TRANSFER) })} @@ -563,7 +563,7 @@ fn main() { button: b, .. } => { - println!("MOUSE {:?}, {:?}, {:?}", d, s, b); + println!("MOUSE {d:?}, {s:?}, {b:?}"); if b == &MouseButton::Right { looking = s == &ElementState::Pressed; } @@ -595,8 +595,8 @@ fn main() { if looking { camforward.x -= Deg(delta.1 as f32) * gstate.cursor_sensitivity * 0.3; camforward.y += Deg(delta.0 as f32) * gstate.cursor_sensitivity * 0.3; - camforward.x = camforward.x + Deg(360f32) % Deg(360f32); - camforward.y = camforward.y + Deg(360f32) % Deg(360f32); + camforward.x += Deg(360f32) % Deg(360f32); + camforward.y += Deg(360f32) % Deg(360f32); } } Event::RedrawEventsCleared => { @@ -721,7 +721,7 @@ fn main() { *sub.write().unwrap() = uniform_data; if looking { - println!("campos: {:?} camforward: {:?}", campos, camforward); + println!("campos: {campos:?} camforward: {camforward:?}"); } (pc, sub) @@ -767,8 +767,8 @@ fn main() { &descriptor_set_allocator, implicit_layout.clone(), [ - WriteDescriptorSet::buffer(0, uniform_buffer_subbuffer.clone()), - WriteDescriptorSet::buffer(1, cam_set.clone()), + WriteDescriptorSet::buffer(0, uniform_buffer_subbuffer), + WriteDescriptorSet::buffer(1, cam_set), WriteDescriptorSet::buffer(2, subbuffers.desc.clone()), WriteDescriptorSet::buffer(3, subbuffers.scene.clone()), WriteDescriptorSet::buffer(4, subbuffers.floats.clone()), @@ -790,10 +790,10 @@ fn main() { if COMPUTE_FUZZING { let mut fake_csg = vec![]; - for i in 0..(32) + for i in 0..32 { fake_csg.push( - CSG{ name: format!("fuzz_{}",i), parts: vec![ + CSG{ name: format!("fuzz_{i}"), parts: vec![ CSGPart::opcode(InstructionSet::OPMulVec3Float, vec![Inputs::Variable, Inputs::Float(0.9)]), CSGPart::opcode(InstructionSet::OPDupVec3, vec![Inputs::Variable]), CSGPart::opcode(InstructionSet::OPAddVec3Vec3, vec![Inputs::Variable, Inputs::Vec3([-0.7, (i as f64), -0.7].into())]), @@ -835,7 +835,7 @@ fn main() { //WriteDescriptorSet::buffer(9, compute_subbuffers.mat3s.clone()), //WriteDescriptorSet::buffer(10, compute_subbuffers.mat4s.clone()), //WriteDescriptorSet::buffer(11, compute_subbuffers.mats.clone()), - WriteDescriptorSet::buffer(12, compute_subbuffers.deps.clone()), + WriteDescriptorSet::buffer(12, compute_subbuffers.deps), //WriteDescriptorSet::buffer(20, compute_subbuffers.masks.clone()), WriteDescriptorSet::buffer(30, compute_result_buffer.clone()),], ) @@ -871,7 +871,7 @@ fn main() { let content = compute_result_buffer.read().unwrap(); for (val,csg) in content.iter().zip(fake_csg.iter()) { - println!("{:?}",val); + println!("{val:?}"); let expected = Interpreter::new(csg).scene(Vector3::new(1.,1.,1.)) as f32; if expected != val.f[0] { println!("ERROR: expected {}, got {}", expected, val.f[0]); @@ -886,7 +886,7 @@ fn main() { recreate_swapchain = true; return; } - Err(e) => panic!("Failed to acquire next image: {:?}", e), + Err(e) => panic!("Failed to acquire next image: {e:?}"), }; if suboptimal { @@ -1002,7 +1002,7 @@ fn main() { previous_frame_end = Some(sync::now(device.clone()).boxed()); } Err(e) => { - println!("Failed to flush future: {:?}", e); + println!("Failed to flush future: {e:?}"); previous_frame_end = Some(sync::now(device.clone()).boxed()); } } @@ -1127,9 +1127,9 @@ where depth_range: 0.0..1.0, }, ])) - .fragment_shader(implicit_fs.entry_point("main").unwrap(), implicit_fs_specs.clone()) - .task_shader(implicit_ts.entry_point("main").unwrap(), implicit_ts_specs.clone()) - .mesh_shader(implicit_ms.entry_point("main").unwrap(), implicit_ms_specs.clone()) + .fragment_shader(implicit_fs.entry_point("main").unwrap(), implicit_fs_specs) + .task_shader(implicit_ts.entry_point("main").unwrap(), implicit_ts_specs) + .mesh_shader(implicit_ms.entry_point("main").unwrap(), implicit_ms_specs) .depth_stencil_state(DepthStencilState::simple_depth_test()) .rasterization_state(RasterizationState { //front_face: Fixed(Clockwise), @@ -1137,7 +1137,7 @@ where ..RasterizationState::default() }) .multisample_state(MultisampleState { - rasterization_samples: Subpass::from(render_pass.clone(), 0) + rasterization_samples: Subpass::from(render_pass, 0) .unwrap() .num_samples() .unwrap(), @@ -1227,7 +1227,7 @@ where ).unwrap(); let commands = builder.build().unwrap(); - commands.execute(transfer_queue.clone()) + commands.execute(transfer_queue) .unwrap() .then_signal_fence_and_flush() .unwrap() @@ -1264,7 +1264,7 @@ fn object_size_dependent_setup( let mut mat2s: Vec<[[f32; 2]; 2]> = vec![Default::default()]; let mut mat3s: Vec<[[f32; 3]; 3]> = vec![Default::default()]; let mut mat4s: Vec<[[f32; 4]; 4]> = vec![Default::default()]; - let mut mats: Vec<[[f32; 4]; 4]> = vec![Default::default()]; + let mats: Vec<[[f32; 4]; 4]> = vec![Default::default()]; let mut scene: Vec<[u32; 4]> = vec![Default::default()]; let mut deps: Vec<[u8; 2]> = vec![Default::default()]; let mut desc: Vec<Description> = vec![Default::default()]; @@ -1496,16 +1496,16 @@ fn object_size_dependent_setup( } - println!("floats: {:?}", floats); - println!("vec2s: {:?}", vec2s); - println!("vec3/4s: {:?}", vec4s); - println!("mat2s: {:?}", mat2s); - println!("mat3s: {:?}", mat3s); - println!("mat4s: {:?}", mat4s); - println!("mats: {:?}", mats); - println!("scene: {:?}", scene); - println!("deps: {:?}", deps); - println!("desc: {:?}", desc); + println!("floats: {floats:?}"); + println!("vec2s: {vec2s:?}"); + println!("vec3/4s: {vec4s:?}"); + println!("mat2s: {mat2s:?}"); + println!("mat3s: {mat3s:?}"); + println!("mat4s: {mat4s:?}"); + println!("mats: {mats:?}"); + println!("scene: {scene:?}"); + println!("deps: {deps:?}"); + println!("desc: {desc:?}"); let fragment_masks_buffer = Buffer::new_slice( &allocator, @@ -1538,7 +1538,7 @@ fn object_size_dependent_setup( let csg_mat3s = gpu_buffer(mat3s, &allocator, &staging, command_allocator, queue.clone()); let csg_mat4s = gpu_buffer(mat4s, &allocator, &staging, command_allocator, queue.clone()); let csg_mats = gpu_buffer(mats, &allocator, &staging, command_allocator, queue.clone()); - let csg_deps = gpu_buffer(deps, &allocator, &staging, command_allocator, queue.clone()); + let csg_deps = gpu_buffer(deps, &allocator, &staging, command_allocator, queue); Subbuffers { masks: fragment_masks_buffer, diff --git a/src/mcsg_deserialise.rs b/src/mcsg_deserialise.rs index b81f5bdb60e0ae8049fab811c7ced612923bb643..88c750ead2a94aa71d926857d7e222442288fc11 100644 --- a/src/mcsg_deserialise.rs +++ b/src/mcsg_deserialise.rs @@ -1,6 +1,6 @@ use std::fmt::Display; -use std::io::{BufReader, Cursor, Read}; -use std::ops::{AddAssign, MulAssign, Neg}; +use std::io::{BufReader, Read}; + use std::str::Chars; use serde::de::{ @@ -8,7 +8,7 @@ use serde::de::{ Visitor, }; use serde::{forward_to_deserialize_any, Deserialize}; -use utf8::{BufReadDecoder, BufReadDecoderError}; +use utf8::{BufReadDecoder}; type Result<T> = core::result::Result<T, Error>; @@ -31,7 +31,7 @@ impl Display for Error { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { match self { Error::Message(msg) | Error::UTF8(msg) => f.write_str(msg), - _ => f.write_fmt(format_args!("Error: {:?}", self)), + _ => f.write_fmt(format_args!("Error: {self:?}")), } } } @@ -135,7 +135,7 @@ impl<'de> Deserializer<'de> { Ok(s) => { s.clone_into(&mut self.read_buf); } - Err(e) => return Err(Error::UTF8(format!("{}", e))), + Err(e) => return Err(Error::UTF8(format!("{e}"))), }; } None => return Err(Error::Eof), @@ -175,7 +175,7 @@ impl<'de> Deserializer<'de> { Ok(s) => { s.clone_into(&mut self.read_buf); } - Err(e) => return Err(Error::UTF8(format!("{}", e))), + Err(e) => return Err(Error::UTF8(format!("{e}"))), }; } None => return Err(Error::Eof), diff --git a/src/objects.rs b/src/objects.rs index 8e756cc46e1ee454f6e92a5c6cfef2c75678a008..f4ed72595bec236fb7ba3de4a9412b4167bfcbf5 100644 --- a/src/objects.rs +++ b/src/objects.rs @@ -1,20 +1,18 @@ use std::{ collections::HashMap, - default, io::{Cursor, Read}, mem, }; use bytemuck::{Pod, Zeroable}; use cgmath::{ - num_traits::float, Deg, EuclideanSpace, Euler, Matrix2, Matrix3, Matrix4, Point3, SquareMatrix, + Deg, EuclideanSpace, Euler, Matrix2, Matrix3, Matrix4, Point3, SquareMatrix, Vector2, Vector3, Vector4, }; use obj::{LoadConfig, ObjData, ObjError}; use serde::{Deserialize, Serialize}; use vulkano::{ buffer::{Buffer, BufferAllocateInfo, BufferUsage, Subbuffer}, - half::f16, pipeline::graphics::vertex_input::Vertex, }; @@ -203,7 +201,7 @@ type MCSGCSGPart = HashMap<String, String>; fn matrix3_from_string(input: &String) -> Result<Matrix3<f32>, String> { let vec = input - .split(" ") + .split(' ') .map(|s| s.parse::<f32>()) .collect::<Result<Vec<f32>, _>>() .map_err(|_| "not floats")?; @@ -214,7 +212,7 @@ fn matrix3_from_string(input: &String) -> Result<Matrix3<f32>, String> { fn vector3_from_string(input: &String) -> Result<Vector3<f32>, String> { let vec = input - .split(" ") + .split(' ') .map(|s| s.parse::<f32>()) .collect::<Result<Vec<f32>, _>>() .map_err(|_| "not floats")?; @@ -225,7 +223,7 @@ fn vector3_from_string(input: &String) -> Result<Vector3<f32>, String> { fn point3_from_string(input: &String) -> Result<Point3<f32>, String> { let vec = input - .split(" ") + .split(' ') .map(|s| s.parse::<f32>()) .collect::<Result<Vec<f32>, _>>() .map_err(|_| "not floats")?; @@ -244,20 +242,17 @@ fn get_trs(o: &HashMap<String, String>) -> Result<TRS, String> { translation: o .get("t") .map(point3_from_string) - .transpose() - .map_err(|e| e.to_string())? + .transpose()? .unwrap_or(Point3::origin()), rotation: o .get("r") .map(matrix3_from_string) - .transpose() - .map_err(|e| e.to_string())? + .transpose()? .unwrap_or(Matrix3::identity()), scale: o .get("s") .map(vector3_from_string) - .transpose() - .map_err(|e| e.to_string())? + .transpose()? .unwrap_or(Vector3 { x: 1., y: 1., @@ -268,8 +263,7 @@ fn get_trs(o: &HashMap<String, String>) -> Result<TRS, String> { fn get_color(o: &HashMap<String, String>) -> Result<Vector3<f32>, String> { Ok(o.get("color") .map(vector3_from_string) - .transpose() - .map_err(|e| e.to_string())? + .transpose()? .unwrap_or(Vector3 { x: 255., y: 255., @@ -280,8 +274,7 @@ fn get_color(o: &HashMap<String, String>) -> Result<Vector3<f32>, String> { fn get_rgb(o: &HashMap<String, String>) -> Result<Vector3<f32>, String> { Ok(o.get("rgb") .map(vector3_from_string) - .transpose() - .map_err(|e| e.to_string())? + .transpose()? .unwrap_or(Vector3 { x: 255., y: 255., @@ -293,7 +286,7 @@ fn get_f32(o: &HashMap<String, String>, tag: &str) -> Result<f32, String> { get_f32_default(o, tag, 0.) } -fn get_f32_default(o: &HashMap<String, String>, tag: &str, default: f32) -> Result<f32, String> { +fn get_f32_default(o: &HashMap<String, String>, tag: &str, _default: f32) -> Result<f32, String> { Ok(o.get(tag) .map(|c| c.parse::<f32>()) .transpose() @@ -339,7 +332,7 @@ fn get_half(o: &HashMap<String, String>) -> Result<Half, String> { } pub fn load_csg( - memory_allocator: &MemoryAllocator, + _memory_allocator: &MemoryAllocator, input: &mut dyn Read, name: String, ) -> Result<Vec<CSG>, String> { @@ -349,10 +342,10 @@ pub fn load_csg( mcsg.object .iter() .enumerate() - .map(|(i, o)| { + .map(|(_i, o)| { let name = name.clone() + "_" + o.get("name").unwrap_or(&"unknown".to_owned()); - let trs = get_trs(&o)?; - let color = get_color(&o)?; + let _trs = get_trs(o)?; + let _color = get_color(o)?; let cid = o .get("cid") @@ -371,15 +364,15 @@ pub fn load_csg( .iter() .map(|inpart| { let ty = inpart.get("type").ok_or("no type!")?.as_str(); - let mut csgpart = CSGPart::opcode(InstructionSet::OPNop, vec![]); + let csgpart = CSGPart::opcode(InstructionSet::OPNop, vec![]); match ty { "sphere" => { - let blend = get_f32(&inpart, "blend")?; - let shell = get_percentage(&inpart, "shell%")?; - let power = get_f32_default(&inpart, "power", 2.)?; - let rgb = get_rgb(&inpart)?; - let trs = get_trs(&inpart)?; - let half = get_half(&inpart)?; + let _blend = get_f32(inpart, "blend")?; + let _shell = get_percentage(inpart, "shell%")?; + let _power = get_f32_default(inpart, "power", 2.)?; + let _rgb = get_rgb(inpart)?; + let _trs = get_trs(inpart)?; + let _half = get_half(inpart)?; } _ => {} //return Err("unknown type of csg".to_owned()), }