Skip to content

Commit

Permalink
Minor improvements.
Browse files Browse the repository at this point in the history
  • Loading branch information
GeReV committed Nov 30, 2020
1 parent 9ee80c4 commit 98bf452
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 40 deletions.
4 changes: 2 additions & 2 deletions src/background.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ const BACKGROUND_PASS_GREEN_FRAG: &str =
include_str!("../assets/shaders/background_pass_green.frag");
const BACKGROUND_PASS_BLUE_FRAG: &str = include_str!("../assets/shaders/background_pass_blue.frag");

const KERNEL0BRACKETS_REAL_XY_IM_ZW: [f32; 2] = [0.411259, -0.548794];
const _KERNEL0BRACKETS_REAL_XY_IM_ZW: [f32; 2] = [0.411259, -0.548794];
const KERNEL0_REAL_X_IM_Y_REAL_Z_IM_W: [[f32; 4]; 17] = [
[
/*XY: Non Bracketed*/ 0.014096, -0.022658, /*Bracketed WZ:*/ 0.055991, 0.004413,
Expand Down Expand Up @@ -66,7 +66,7 @@ const KERNEL0_REAL_X_IM_Y_REAL_Z_IM_W: [[f32; 4]; 17] = [
/*XY: Non Bracketed*/ 0.014096, -0.022658, /*Bracketed WZ:*/ 0.055991, 0.004413,
],
];
const KERNEL1WEIGHTS_REAL_X_IM_Y: [f32; 2] = [0.513282, 4.561110];
const _KERNEL1WEIGHTS_REAL_X_IM_Y: [f32; 2] = [0.513282, 4.561110];
const KERNEL1_REAL_X_IM_Y_REAL_Z_IM_W: [[f32; 4]; 17] = [
[
/*XY: Non Bracketed*/ 0.000115, 0.009116, /*Bracketed WZ:*/ 0.000000, 0.051147,
Expand Down
4 changes: 2 additions & 2 deletions src/config_window.rs
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ impl ConfigWindow {
fn save(&self, path: &Path) -> std::io::Result<()> {
use winapi::um::winuser::GetSystemMetrics;

let mut config = Config::default();
let config = Config::default();

// Remove previous cache.
if let Some(previous_background) = config.cached_background() {
Expand All @@ -143,7 +143,7 @@ impl ConfigWindow {
}
}

config.set_background(path);
let _ = config.set_background(path);

let image = image::open(path).unwrap();

Expand Down
36 changes: 8 additions & 28 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,28 +28,14 @@ use crate::config_window::ConfigWindow;
use crate::debug::failure_to_string;
#[cfg(feature = "debug")]
use crate::debug_ui::DebugUi;
use crate::droplets::Droplets;
use crate::quad::Quad;

use failure::err_msg;
use nalgebra as na;
use nalgebra::{Isometry2, Vector2};
use ncollide2d::pipeline::{
CollisionGroups, CollisionObjectSlabHandle, CollisionWorld, GeometricQueryType,
};
use ncollide2d::query::Proximity;
use ncollide2d::shape::{Ball, ShapeHandle};

use crate::render_gl::ColorBuffer;

use glutin::dpi::{PhysicalSize, Size};
use glutin::event_loop::EventLoop;
use glutin::window::Fullscreen;
use glutin::{Context, ContextWrapper, GlRequest, PossiblyCurrent};
use render_gl::buffer::*;
use resources::Resources;
use glutin::event::{Event, WindowEvent};
use glutin::event_loop::{ControlFlow, EventLoop};
use glutin::platform::windows::WindowBuilderExtWindows;
use glutin::window::{Fullscreen, WindowBuilder};
use glutin::{ContextBuilder, GlRequest};
use std::env;
use std::path::Path;
use std::rc::Rc;
use std::str::FromStr;
use std::time::{Duration, Instant};
use winapi::shared::windef::HWND;
Expand Down Expand Up @@ -81,7 +67,7 @@ fn main() {
}
}
"/c" => {
let (_, hwnd) = arg.split_at(3);
let (_, _hwnd) = arg.split_at(3);

// Configuration
ConfigWindow::init();
Expand All @@ -99,12 +85,6 @@ fn run(
max_droplet_count: usize,
droplet_size_range: (f32, f32),
) -> Result<(), failure::Error> {
use glutin::event::{Event, WindowEvent};
use glutin::event_loop::{ControlFlow, EventLoop};
use glutin::platform::windows::{RawContextExt, WindowBuilderExtWindows, WindowExtWindows};
use glutin::window::WindowBuilder;
use glutin::ContextBuilder;

let event_loop = EventLoop::new();

let mut wb = WindowBuilder::new().with_title("Rain");
Expand Down Expand Up @@ -138,7 +118,7 @@ fn run(
use glutin::platform::windows::{RawContextExt, WindowExtWindows};

let hwnd = window.hwnd();
let mut cb = ContextBuilder::new().with_gl(GlRequest::Latest);
let cb = ContextBuilder::new().with_gl(GlRequest::Latest);

cb.build_raw_context(hwnd).unwrap()
};
Expand Down
12 changes: 4 additions & 8 deletions src/rain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,10 @@
use crate::config::Config;
use crate::droplets::Droplets;
use crate::quad::Quad;
use crate::render_gl;
use crate::render_gl::buffer::ArrayBuffer;
use crate::render_gl::{
ColorBuffer, Error, FrameBuffer, Program, Shader, Texture, TextureLoadOptions, Viewport,
};
use image::GenericImageView;
use nalgebra as na;
use nalgebra::{Matrix4, Orthographic3, Point3, Translation3, Vector2, Vector3, Vector4};
use ncollide2d::na::Isometry2;
Expand Down Expand Up @@ -54,7 +52,6 @@ fn load_shader(gl: &gl::Gl, vert_source: &str, frag_source: &str, debug_name: &s
pub struct Rain {
gl: gl::Gl,

max_droplet_count: usize,
droplet_size_range: (f32, f32),

updates: Vec<(CollisionObjectSlabHandle, CollisionObjectSlabHandle)>,
Expand Down Expand Up @@ -100,14 +97,14 @@ impl Rain {
window_size: (u32, u32),
config: &Config,
) -> Result<Self, failure::Error> {
let mut droplets: Droplets = Droplets::with_capacity(max_droplet_count);
let droplets: Droplets = Droplets::with_capacity(max_droplet_count);

let world = CollisionWorld::new(2.0);

let collision_group = CollisionGroups::new();
let contacts_query = GeometricQueryType::Proximity(0.0);

let mut viewport = Viewport::for_window(window_size.0 as i32, window_size.1 as i32);
let viewport = Viewport::for_window(window_size.0 as i32, window_size.1 as i32);

viewport.set_used(&gl);

Expand All @@ -116,7 +113,7 @@ impl Rain {
.inverse()
.to_homogeneous();

let mut projection_matrix: Matrix4<f32> = Orthographic3::new(
let projection_matrix: Matrix4<f32> = Orthographic3::new(
0.0,
window_size.0 as f32,
0.0,
Expand All @@ -136,7 +133,7 @@ impl Rain {
let mut options = TextureLoadOptions::from_res_rgb(path.to_str().unwrap());
options.gen_mipmaps = true;

let mut image = image::open(&path)
let image = image::open(&path)
.or_else(|_| image::open(&fallback_background))
.unwrap();

Expand Down Expand Up @@ -183,7 +180,6 @@ impl Rain {
Ok(Rain {
gl: gl.clone(),

max_droplet_count,
droplet_size_range,

updates: Vec::<(CollisionObjectSlabHandle, CollisionObjectSlabHandle)>::new(),
Expand Down

0 comments on commit 98bf452

Please sign in to comment.