Skip to content

Commit

Permalink
refactor: fail compilation on warnings (#23)
Browse files Browse the repository at this point in the history
  • Loading branch information
tommy-xr authored Jun 15, 2024
1 parent 005413d commit 2aa701e
Show file tree
Hide file tree
Showing 15 changed files with 38 additions and 48 deletions.
4 changes: 4 additions & 0 deletions runtime/functor-runtime-common/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
3 changes: 2 additions & 1 deletion runtime/functor-runtime-common/src/geometry/cylinder.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use std::f32::consts::PI;

use cgmath::{vec2, vec3, Vector2, Vector3};
use cgmath::{Vector2, Vector3};

use super::mesh::{self, Mesh};

Expand All @@ -9,6 +9,7 @@ pub struct Cylinder;
#[derive(Debug, Clone, Copy)]
struct Vertex {
position: Vector3<f32>,
#[allow(dead_code)]
normal: Vector3<f32>,
tex_coords: Vector2<f32>,
}
Expand Down
9 changes: 3 additions & 6 deletions runtime/functor-runtime-common/src/geometry/mesh.rs
Original file line number Diff line number Diff line change
@@ -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,
}
Expand All @@ -25,7 +23,7 @@ pub fn create(vertices: Vec<f32>) -> 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::<f32>(),
Expand Down Expand Up @@ -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,
});
}
Expand Down
2 changes: 0 additions & 2 deletions runtime/functor-runtime-common/src/geometry/mod.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
use glow::*;

pub trait Geometry {
fn draw(&mut self, gl: &glow::Context);
}
Expand Down
1 change: 1 addition & 0 deletions runtime/functor-runtime-common/src/geometry/sphere.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ pub struct Sphere;
#[derive(Debug, Clone, Copy)]
struct Vertex {
position: Vector3<f32>,
#[allow(dead_code)]
normal: Vector3<f32>,
tex_coords: Vector2<f32>,
}
Expand Down
6 changes: 4 additions & 2 deletions runtime/functor-runtime-common/src/lib.rs
Original file line number Diff line number Diff line change
@@ -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::*;

Expand Down
4 changes: 2 additions & 2 deletions runtime/functor-runtime-common/src/material/basic_material.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
use cgmath::Matrix4;

use std::sync::OnceLock;

use crate::shader_program::ShaderProgram;
use crate::shader_program::UniformLocation;
use crate::RenderContext;
Expand Down Expand Up @@ -95,6 +93,8 @@ impl Material for BasicMaterial {
_skinning_data: &[Matrix4<f32>],
) -> 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);
Expand Down
3 changes: 2 additions & 1 deletion runtime/functor-runtime-common/src/material/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ pub trait Material {
) -> bool;
fn draw_transparent(
&self,
ctx: &RenderContext,
_ctx: &RenderContext,
_projection_matrix: &Matrix4<f32>,
_view_matrix: &Matrix4<f32>,
_world_matrix: &Matrix4<f32>,
Expand All @@ -26,6 +26,7 @@ mod basic_material;
mod color_material;

pub use basic_material::*;
#[allow(unused_imports)]
pub use color_material::*;

use crate::RenderContext;
2 changes: 1 addition & 1 deletion runtime/functor-runtime-common/src/scene3d.rs
Original file line number Diff line number Diff line change
@@ -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},
Expand Down
1 change: 0 additions & 1 deletion runtime/functor-runtime-common/src/shader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion runtime/functor-runtime-common/src/shader_program.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -52,6 +51,7 @@ impl ShaderProgram {
}
}

#[allow(dead_code)]
pub fn set_uniform_vec3(
&self,
gl: &glow::Context,
Expand Down
4 changes: 4 additions & 0 deletions runtime/functor-runtime-desktop/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
8 changes: 3 additions & 5 deletions runtime/functor-runtime-desktop/src/hot_reload_game.rs
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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
Expand All @@ -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<fn(FrameTime) -> Scene3D> =
self.library.as_ref().unwrap().get(b"test_render").unwrap();
render_func(frameTime)
render_func(frame_time)
}
}

Expand Down
18 changes: 6 additions & 12 deletions runtime/functor-runtime-desktop/src/main.rs
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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)]
Expand Down Expand Up @@ -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<f32> = Matrix4::look_at_rh(
Point3::new(0.0, 0.0, -1.0 * radius),
Point3::new(0.0, 0.0, 0.0),
Expand All @@ -144,4 +136,6 @@ pub fn main() {
window.swap_buffers();
}
}

game.quit();
}
19 changes: 5 additions & 14 deletions runtime/functor-runtime-desktop/src/static_game.rs
Original file line number Diff line number Diff line change
@@ -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<fn(FrameTime) -> Scene3D> =
self.library.get(b"test_render").unwrap();
render_func(frameTime)
render_func(frame_time)
}
}

Expand Down

0 comments on commit 2aa701e

Please sign in to comment.