From 2aa701e92d7bcb45da1c00f96168cdacbe1cecb2 Mon Sep 17 00:00:00 2001 From: tommy-xr Date: Sat, 15 Jun 2024 07:20:28 -0700 Subject: [PATCH] refactor: fail compilation on warnings (#23) --- runtime/functor-runtime-common/Cargo.toml | 4 ++++ .../src/geometry/cylinder.rs | 3 ++- .../src/geometry/mesh.rs | 9 +++------ .../src/geometry/mod.rs | 2 -- .../src/geometry/sphere.rs | 1 + runtime/functor-runtime-common/src/lib.rs | 6 ++++-- .../src/material/basic_material.rs | 4 ++-- .../src/material/mod.rs | 3 ++- runtime/functor-runtime-common/src/scene3d.rs | 2 +- runtime/functor-runtime-common/src/shader.rs | 1 - .../src/shader_program.rs | 2 +- runtime/functor-runtime-desktop/Cargo.toml | 4 ++++ .../src/hot_reload_game.rs | 8 +++----- runtime/functor-runtime-desktop/src/main.rs | 18 ++++++------------ .../src/static_game.rs | 19 +++++-------------- 15 files changed, 38 insertions(+), 48 deletions(-) diff --git a/runtime/functor-runtime-common/Cargo.toml b/runtime/functor-runtime-common/Cargo.toml index ba14a8d..cddfddb 100644 --- a/runtime/functor-runtime-common/Cargo.toml +++ b/runtime/functor-runtime-common/Cargo.toml @@ -3,6 +3,10 @@ name = "functor_runtime_common" version = "0.1.0" edition = "2021" +[features] +# Treat warnings as a buld error +strict = [] + # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] diff --git a/runtime/functor-runtime-common/src/geometry/cylinder.rs b/runtime/functor-runtime-common/src/geometry/cylinder.rs index 9a44159..ea342d5 100644 --- a/runtime/functor-runtime-common/src/geometry/cylinder.rs +++ b/runtime/functor-runtime-common/src/geometry/cylinder.rs @@ -1,6 +1,6 @@ use std::f32::consts::PI; -use cgmath::{vec2, vec3, Vector2, Vector3}; +use cgmath::{Vector2, Vector3}; use super::mesh::{self, Mesh}; @@ -9,6 +9,7 @@ pub struct Cylinder; #[derive(Debug, Clone, Copy)] struct Vertex { position: Vector3, + #[allow(dead_code)] normal: Vector3, tex_coords: Vector2, } diff --git a/runtime/functor-runtime-common/src/geometry/mesh.rs b/runtime/functor-runtime-common/src/geometry/mesh.rs index b938e1e..b65a3c0 100644 --- a/runtime/functor-runtime-common/src/geometry/mesh.rs +++ b/runtime/functor-runtime-common/src/geometry/mesh.rs @@ -1,10 +1,8 @@ -use glow::{Buffer, HasContext, VertexArray}; -use once_cell::sync::OnceCell; +use glow::{HasContext, VertexArray}; use super::Geometry; struct HydratedContext { - vbo: Buffer, vao: VertexArray, triangle_count: i32, } @@ -25,7 +23,7 @@ pub fn create(vertices: Vec) -> Mesh { impl Geometry for Mesh { fn draw(&mut self, gl: &glow::Context) { if self.hydrated_context.is_none() { - let (vbo, vao) = unsafe { + let vao = unsafe { let vertices_u8: &[u8] = core::slice::from_raw_parts( self.vertices.as_ptr() as *const u8, self.vertices.len() * core::mem::size_of::(), @@ -62,12 +60,11 @@ impl Geometry for Mesh { // VAOs requires a call to glBindVertexArray anyways so we generally don't unbind VAOs (nor VBOs) when it's not directly necessary. gl.bind_buffer(glow::ARRAY_BUFFER, None); gl.bind_vertex_array(None); - (vbo, vao) + vao }; self.hydrated_context = Some(HydratedContext { vao, - vbo, triangle_count: (self.vertices.len() / 5) as i32, }); } diff --git a/runtime/functor-runtime-common/src/geometry/mod.rs b/runtime/functor-runtime-common/src/geometry/mod.rs index 7f0a514..c9e386b 100644 --- a/runtime/functor-runtime-common/src/geometry/mod.rs +++ b/runtime/functor-runtime-common/src/geometry/mod.rs @@ -1,5 +1,3 @@ -use glow::*; - pub trait Geometry { fn draw(&mut self, gl: &glow::Context); } diff --git a/runtime/functor-runtime-common/src/geometry/sphere.rs b/runtime/functor-runtime-common/src/geometry/sphere.rs index 585d664..3ec96e7 100644 --- a/runtime/functor-runtime-common/src/geometry/sphere.rs +++ b/runtime/functor-runtime-common/src/geometry/sphere.rs @@ -9,6 +9,7 @@ pub struct Sphere; #[derive(Debug, Clone, Copy)] struct Vertex { position: Vector3, + #[allow(dead_code)] normal: Vector3, tex_coords: Vector2, } diff --git a/runtime/functor-runtime-common/src/lib.rs b/runtime/functor-runtime-common/src/lib.rs index c9f257f..7fc7218 100644 --- a/runtime/functor-runtime-common/src/lib.rs +++ b/runtime/functor-runtime-common/src/lib.rs @@ -1,7 +1,9 @@ -use cgmath::Rad; -use serde::*; +#![cfg_attr(feature = "strict", deny(warnings))] + use std::any::Any; +#[cfg(target_arch = "wasm32")] +use serde::*; #[cfg(target_arch = "wasm32")] use wasm_bindgen::prelude::*; diff --git a/runtime/functor-runtime-common/src/material/basic_material.rs b/runtime/functor-runtime-common/src/material/basic_material.rs index 69625bc..d4165d3 100644 --- a/runtime/functor-runtime-common/src/material/basic_material.rs +++ b/runtime/functor-runtime-common/src/material/basic_material.rs @@ -1,7 +1,5 @@ use cgmath::Matrix4; -use std::sync::OnceLock; - use crate::shader_program::ShaderProgram; use crate::shader_program::UniformLocation; use crate::RenderContext; @@ -95,6 +93,8 @@ impl Material for BasicMaterial { _skinning_data: &[Matrix4], ) -> bool { unsafe { + // TODO: Find another approach to do this - maybe a shader repository? + #[allow(static_mut_refs)] if let Some((shader, uniforms)) = &SHADER_PROGRAM { let p = shader; p.use_program(ctx.gl); diff --git a/runtime/functor-runtime-common/src/material/mod.rs b/runtime/functor-runtime-common/src/material/mod.rs index 74f18e0..4922c8d 100644 --- a/runtime/functor-runtime-common/src/material/mod.rs +++ b/runtime/functor-runtime-common/src/material/mod.rs @@ -12,7 +12,7 @@ pub trait Material { ) -> bool; fn draw_transparent( &self, - ctx: &RenderContext, + _ctx: &RenderContext, _projection_matrix: &Matrix4, _view_matrix: &Matrix4, _world_matrix: &Matrix4, @@ -26,6 +26,7 @@ mod basic_material; mod color_material; pub use basic_material::*; +#[allow(unused_imports)] pub use color_material::*; use crate::RenderContext; diff --git a/runtime/functor-runtime-common/src/scene3d.rs b/runtime/functor-runtime-common/src/scene3d.rs index 20518b0..f94f2c4 100644 --- a/runtime/functor-runtime-common/src/scene3d.rs +++ b/runtime/functor-runtime-common/src/scene3d.rs @@ -1,7 +1,7 @@ use cgmath::{vec3, Matrix4, SquareMatrix}; use serde::{Deserialize, Serialize}; -use fable_library_rust::{List_, NativeArray_::Array}; +use fable_library_rust::NativeArray_::Array; use crate::{ geometry::{self, Geometry}, diff --git a/runtime/functor-runtime-common/src/shader.rs b/runtime/functor-runtime-common/src/shader.rs index 45881c0..99cb96a 100644 --- a/runtime/functor-runtime-common/src/shader.rs +++ b/runtime/functor-runtime-common/src/shader.rs @@ -23,7 +23,6 @@ impl Shader { let shader; unsafe { - let mut success = 0; let shader_source = convert(shader_contents, opengl_version); shader = gl .create_shader(gl_shader_type) diff --git a/runtime/functor-runtime-common/src/shader_program.rs b/runtime/functor-runtime-common/src/shader_program.rs index 4b7df48..f5779a3 100644 --- a/runtime/functor-runtime-common/src/shader_program.rs +++ b/runtime/functor-runtime-common/src/shader_program.rs @@ -20,7 +20,6 @@ impl ShaderProgram { fragment_shader: &Shader, ) -> ShaderProgram { unsafe { - let mut success = 0; let program_id = gl.create_program().expect("Cannot create program"); gl.attach_shader(program_id, vertex_shader.shader_id); gl.attach_shader(program_id, fragment_shader.shader_id); @@ -52,6 +51,7 @@ impl ShaderProgram { } } + #[allow(dead_code)] pub fn set_uniform_vec3( &self, gl: &glow::Context, diff --git a/runtime/functor-runtime-desktop/Cargo.toml b/runtime/functor-runtime-desktop/Cargo.toml index 65762f6..d8428d9 100644 --- a/runtime/functor-runtime-desktop/Cargo.toml +++ b/runtime/functor-runtime-desktop/Cargo.toml @@ -3,6 +3,10 @@ name = "functor-runtime-desktop" version = "0.1.0" edition = "2021" +[features] +# Treat warnings as a buld error +strict = ["functor_runtime_common/strict"] + [[bin]] name = "functor-runner" path = "src/main.rs" diff --git a/runtime/functor-runtime-desktop/src/hot_reload_game.rs b/runtime/functor-runtime-desktop/src/hot_reload_game.rs index 78f04b2..ddde8d1 100644 --- a/runtime/functor-runtime-desktop/src/hot_reload_game.rs +++ b/runtime/functor-runtime-desktop/src/hot_reload_game.rs @@ -1,5 +1,4 @@ use notify::{event, RecursiveMode, Watcher}; -use std::env; use std::path::Path; use std::sync::atomic::{AtomicBool, Ordering}; use std::sync::Arc; @@ -10,7 +9,7 @@ use tempfile::tempdir; use functor_runtime_common::{FrameTime, OpaqueState, Scene3D}; use libloading::{Library, Symbol}; -use crate::game::{self, Game}; +use crate::game::Game; pub struct HotReloadGame { // Utils for constructing the next lib path @@ -37,12 +36,11 @@ impl Game for HotReloadGame { } } - fn render(&mut self, frameTime: FrameTime) -> Scene3D { - // println!("Rendering"); + fn render(&mut self, frame_time: FrameTime) -> Scene3D { unsafe { let render_func: Symbol Scene3D> = self.library.as_ref().unwrap().get(b"test_render").unwrap(); - render_func(frameTime) + render_func(frame_time) } } diff --git a/runtime/functor-runtime-desktop/src/main.rs b/runtime/functor-runtime-desktop/src/main.rs index 598f742..cfbdab3 100644 --- a/runtime/functor-runtime-desktop/src/main.rs +++ b/runtime/functor-runtime-desktop/src/main.rs @@ -1,19 +1,13 @@ +#![cfg_attr(feature = "strict", deny(warnings))] + use std::env; -use std::path::{Path, PathBuf}; -use std::sync::atomic::{AtomicBool, Ordering}; -use std::sync::Arc; use std::time::Instant; use cgmath::Matrix4; use cgmath::{perspective, vec3, Deg, Point3}; -use functor_runtime_common::geometry::Geometry; -use functor_runtime_common::material::BasicMaterial; -use functor_runtime_common::{FrameTime, Scene3D, SceneObject}; -use glfw::{init, RenderContext}; +use functor_runtime_common::FrameTime; use glow::*; use hot_reload_game::HotReloadGame; -use libloading::{library_filename, Library, Symbol}; -use notify::{event, RecursiveMode, Watcher}; use static_game::StaticGame; use crate::game::Game; @@ -25,7 +19,7 @@ mod game; mod hot_reload_game; mod static_game; -use clap::{Parser, Subcommand}; +use clap::Parser; #[derive(Parser, Debug, Clone)] #[command(author, version, about, long_about = None)] @@ -118,8 +112,6 @@ pub fn main() { gl.clear(glow::COLOR_BUFFER_BIT | glow::DEPTH_BUFFER_BIT); let radius = 5.0; - let camX = glfw.get_time().sin() as f32 * radius; - let camZ = glfw.get_time().cos() as f32 * radius; let view_matrix: Matrix4 = Matrix4::look_at_rh( Point3::new(0.0, 0.0, -1.0 * radius), Point3::new(0.0, 0.0, 0.0), @@ -144,4 +136,6 @@ pub fn main() { window.swap_buffers(); } } + + game.quit(); } diff --git a/runtime/functor-runtime-desktop/src/static_game.rs b/runtime/functor-runtime-desktop/src/static_game.rs index b7645ed..4602c68 100644 --- a/runtime/functor-runtime-desktop/src/static_game.rs +++ b/runtime/functor-runtime-desktop/src/static_game.rs @@ -1,32 +1,23 @@ -use notify::{event, RecursiveMode, Watcher}; -use std::env; -use std::path::Path; -use std::sync::atomic::{AtomicBool, Ordering}; -use std::sync::Arc; -use std::thread::JoinHandle; -use std::{fs, process}; -use tempfile::tempdir; - -use functor_runtime_common::{FrameTime, OpaqueState, Scene3D}; +use functor_runtime_common::{FrameTime, Scene3D}; use libloading::{Library, Symbol}; -use crate::game::{self, Game}; +use crate::game::Game; pub struct StaticGame { library: Library, } impl Game for StaticGame { - fn check_hot_reload(&mut self, frame_time: FrameTime) { + fn check_hot_reload(&mut self, _frame_time: FrameTime) { // Noop - nothing to do } - fn render(&mut self, frameTime: FrameTime) -> Scene3D { + fn render(&mut self, frame_time: FrameTime) -> Scene3D { // println!("Rendering"); unsafe { let render_func: Symbol Scene3D> = self.library.get(b"test_render").unwrap(); - render_func(frameTime) + render_func(frame_time) } }