From 53d0760fc44b73e9472fc2039d477d0d03d82bef Mon Sep 17 00:00:00 2001 From: ishanjain28 Date: Fri, 13 Mar 2020 16:24:39 +0530 Subject: [PATCH] Fixed a minor issue --- src/main.rs | 68 ++++++++++++++++++++++++++++++++++++++++------------- 1 file changed, 52 insertions(+), 16 deletions(-) diff --git a/src/main.rs b/src/main.rs index 52d32e5..bd6daa1 100644 --- a/src/main.rs +++ b/src/main.rs @@ -49,7 +49,7 @@ fn main() -> Result<(), String> { //println!("{:?} {:?} {:?}", texture.query(), texture.color_mod(), texture.alpha_mod()); - let mut active_demo: Box = Box::new(demos::SimpleRectangle); + let mut active_demo: &dyn Demo = &demos::SimpleRectangle; // TODO: Should update when window is unfocus since the project window retains // data from overlapped window // TODO: Maybe consider using condition variable to make loop {} not run at full @@ -66,25 +66,61 @@ fn main() -> Result<(), String> { } => return Ok(()), Event::KeyUp { keycode, .. } => { match keycode { - Some(Keycode::S) => active_demo.save_as_ppm(&buffer, width, height), - Some(Keycode::Num1) => active_demo = Box::new(demos::SimpleRectangle), - Some(Keycode::Num2) => { - active_demo = Box::new(demos::LinearGradientRectangle) + Some(Keycode::S) => { + active_demo.save_as_ppm(&buffer, width, height); + should_update = false; + } + Some(Keycode::Num1) => { + active_demo = &demos::SimpleRectangle; + should_update = true; + } + Some(Keycode::Num2) => { + active_demo = &demos::LinearGradientRectangle; + should_update = true; + } + Some(Keycode::Num3) => { + active_demo = &demos::SimpleSphere; + should_update = true; + } + Some(Keycode::Num4) => { + active_demo = &demos::SurfaceNormalSphere; + should_update = true; + } + Some(Keycode::Num5) => { + active_demo = &demos::HitableSphere; + should_update = true; + } + Some(Keycode::Num6) => { + active_demo = &demos::SimpleAntialiasing; + should_update = true; + } + Some(Keycode::Num7) => { + active_demo = &demos::DiffuseMaterials; + should_update = true; + } + Some(Keycode::Num8) => { + active_demo = &demos::Materials; + should_update = true; + } + Some(Keycode::Num9) => { + active_demo = &demos::DielectricMaterial; + should_update = true; + } + Some(Keycode::Num0) => { + active_demo = &demos::PositionableCamera; + should_update = true; + } + Some(Keycode::Minus) => { + active_demo = &demos::DefocusBlur; + should_update = true; + } + Some(Keycode::Equals) => { + active_demo = &demos::FinalScene; + should_update = true; } - Some(Keycode::Num3) => active_demo = Box::new(demos::SimpleSphere), - Some(Keycode::Num4) => active_demo = Box::new(demos::SurfaceNormalSphere), - Some(Keycode::Num5) => active_demo = Box::new(demos::HitableSphere), - Some(Keycode::Num6) => active_demo = Box::new(demos::SimpleAntialiasing), - Some(Keycode::Num7) => active_demo = Box::new(demos::DiffuseMaterials), - Some(Keycode::Num8) => active_demo = Box::new(demos::Materials), - Some(Keycode::Num9) => active_demo = Box::new(demos::DielectricMaterial), - Some(Keycode::Num0) => active_demo = Box::new(demos::PositionableCamera), - Some(Keycode::Minus) => active_demo = Box::new(demos::DefocusBlur), - Some(Keycode::Equals) => active_demo = Box::new(demos::FinalScene), None => unreachable!(), _ => (), }; - should_update = true; } Event::Window { win_event: WindowEvent::Resized(w, h),