Merge branch 'master' of gitlab.com:berniecodewiz/mandelwow
authorBernie Innocenti <bernie@codewiz.org>
Tue, 31 Mar 2020 15:44:46 +0000 (00:44 +0900)
committerBernie Innocenti <bernie@codewiz.org>
Tue, 31 Mar 2020 15:44:46 +0000 (00:44 +0900)
lib.rs
main.rs
screenshot.rs [new file with mode: 0644]
timer.rs

diff --git a/lib.rs b/lib.rs
index 24ef697840c82b47f266cf512ed8310939f7f831..296f5b92787e6a500ecc70067a0077ba3d9b32ac 100644 (file)
--- a/lib.rs
+++ b/lib.rs
@@ -2,6 +2,7 @@ pub mod bounding_box;
 pub mod cube;
 pub mod mandelwow;
 pub mod shaded_cube;
+pub mod screenshot;
 pub mod sound;
 pub mod support;
 pub mod text;
@@ -12,17 +13,3 @@ pub use crate::cube::Cube;
 pub use crate::shaded_cube::ShadedCube;
 pub use crate::text::Text;
 pub use crate::timer::Timer;
-
-#[cfg(feature = "image")]
-pub fn screenshot(display : &glium::Display) {
-    let image: glium::texture::RawImage2d<'_, u8> = display.read_front_buffer().unwrap();
-    let image = image::ImageBuffer::from_raw(image.width, image.height, image.data.into_owned()).unwrap();
-    let image = image::DynamicImage::ImageRgba8(image).flipv().to_rgb();
-    let image = image::DynamicImage::ImageRgb8(image);
-    let mut output = std::fs::File::create(&std::path::Path::new("screenshot.png")).unwrap();
-    image.write_to(&mut output, image::ImageFormat::PNG).unwrap();
-}
-
-#[cfg(not(feature = "image"))]
-pub fn screenshot(_ : &glium::Display) {
-}
diff --git a/main.rs b/main.rs
index d6cd210c2cfa406151f3784f91536fc7192cc070..3b07180313e4ce50ef1be991610dc4782157b761 100644 (file)
--- a/main.rs
+++ b/main.rs
@@ -72,6 +72,7 @@ impl World {
         println!("xstep={} ystep={:?}", sea_xstep, sea_zstep);
 
         let mut sea = [[Vector3::zero(); SEA_ZSIZE]; SEA_XSIZE];
+        #[allow(clippy::needless_range_loop)]
         for x in 0..SEA_XSIZE {
             for z in 0..SEA_ZSIZE {
                 sea[x][z] = Vector3 {
@@ -85,11 +86,11 @@ impl World {
         World {
             mandelwow_program,
             mandelwow_bbox: BoundingBox::new(
-                display, &mandelwow_bounds, bounding_box_program.clone()),
+                display, &mandelwow_bounds, bounding_box_program),
             mandelwow_bounds,
             bounding_box_enabled: true,
 
-            shaded_cube: ShadedCube::new(display, shaded_program.clone()),
+            shaded_cube: ShadedCube::new(display, shaded_program),
             text: text::Text::new(display),
             sea,
 
@@ -248,17 +249,14 @@ fn main() {
             emscripten_GetProcAddress(addr.into_raw() as *const _) as *const _
         });
     gl.glGetInternalformativ(0, 0, 0, 0, 0);
-    */
+*/
 
     let mut soundplayer = sound::start();
 
     let event_loop = glutin::event_loop::EventLoop::new();
-    //let fullscreen = Some(glutin::window::Fullscreen::Borderless(event_loop.primary_monitor()));
     let window = glutin::window::WindowBuilder::new()
         //.with_dimensions(1280, 720)
-        //.with_fullscreen(fullscreen);
-        ;
-    //.with_title("MandelWow");
+        .with_title("MandelWow");
     let context = glutin::ContextBuilder::new()
         //.with_gl_profile(glutin::GlProfile::Core)
         //.with_gl(glutin::GlRequest::Specific(glutin::Api::WebGl, (2, 0)))
@@ -276,7 +274,7 @@ fn main() {
 
     let mut timer = Timer::new();
     let mut camera = support::camera::CameraState::new();
-    let _fullscreen = true;
+    let mut fullscreen = true;
 
     event_loop.run(move |event, _, control_flow| {
         let t = timer.t;
@@ -288,7 +286,7 @@ fn main() {
 
         camera.update();
 
-        *control_flow = ControlFlow::WaitUntil(Instant::now() + Duration::from_nanos(16666667));
+        *control_flow = ControlFlow::WaitUntil(Instant::now() + Duration::from_nanos(16_666_667));
         match event {
             Event::NewEvents(cause) => {
                 match cause {
@@ -297,60 +295,43 @@ fn main() {
                     },
                     _ => {}
                 }
-            } _ => (),
-        }
-        if let Event::WindowEvent { event, .. } = event {
-            camera.process_input(&event);
-            match event {
-                WindowEvent::CloseRequested => *control_flow = ControlFlow::Exit,
-                WindowEvent::KeyboardInput { input, .. } => {
-                    if input.state == event::ElementState::Pressed {
-                        if let Some(key) = input.virtual_keycode {
-                            match key {
-                                VirtualKeyCode::Escape | VirtualKeyCode::Q => {
-                                    *control_flow = ControlFlow::Exit;
+            }
+            Event::WindowEvent { event, .. } => {
+                camera.process_input(&event);
+                match event {
+                    WindowEvent::CloseRequested => *control_flow = ControlFlow::Exit,
+                    WindowEvent::KeyboardInput { input, .. } => {
+                        if input.state == event::ElementState::Pressed {
+                            if let Some(key) = input.virtual_keycode {
+                                match key {
+                                    VirtualKeyCode::Escape | VirtualKeyCode::Q => {
+                                        *control_flow = ControlFlow::Exit;
+                                    }
+                                    VirtualKeyCode::B => world.bounding_box_enabled ^= true,
+                                    VirtualKeyCode::P => timer.pause ^= true,
+                                    VirtualKeyCode::PageUp => timer.t += 0.1,
+                                    VirtualKeyCode::PageDown => timer.t -= 0.2,
+                                    VirtualKeyCode::F10 => screenshot::take_screenshot(&display),
+                                    VirtualKeyCode::F11 | VirtualKeyCode::Return => {
+                                        fullscreen ^= true;
+                                        let fs = if fullscreen {
+                                            let monitor_handle = display.gl_window().window()
+                                                .available_monitors().next().unwrap();
+                                            Some(glium::glutin::window::Fullscreen::Borderless(monitor_handle))
+                                        } else {
+                                            None
+                                        };
+                                        display.gl_window().window().set_fullscreen(fs);
+                                    }
+                                    _ => (),
                                 }
-                                _ => (),
                             }
                         }
                     }
+                    _ => (),
                 }
-                /*
-                KeyboardInput { input: glutin::KeyboardInput { state: Pressed, virtual_keycode: Some(VirtualKeyCode::Escape), .. } } |
-                KeyboardInput { input: glutin::KeyboardInput { state: Pressed, virtual_keycode: Some(VirtualKeyCode::Q), .. } } => {
-                    *control_flow = ControlFlow::Exit;
-                },
-                KeyboardInput { state: Pressed, virtual_keycode: Some(VirtualKeyCode::B) } => {
-                    bounding_box_enabled ^= true;
-                },
-                KeyboardInput { state: Pressed, virtual_keycode: Some(VirtualKeyCode::P) } => {
-                    timer.pause ^= true;
-                },
-                KeyboardInput { state: Pressed, virtual_keycode: Some(VirtualKeyCode::PageUp) } => {
-                    timer.t += 0.01;
-                },
-                KeyboardInput { state: Pressed, virtual_keycode: Some(VirtualKeyCode::PageDown) } => {
-                    timer.t -= 0.01;
-                },
-                KeyboardInput { state: Pressed, virtual_keycode: Some(VirtualKeyCode::F10) } => {
-                    screenshot(&display);
-                },
-                KeyboardInput { state: Pressed, virtual_keycode: Some(VirtualKeyCode::F11) } => {
-                    fullscreen ^= true;
-                    if fullscreen {
-                        // Not implemented on Linux
-                        glutin::WindowBuilder::new()
-                            .with_fullscreen(glutin::get_primary_monitor())
-                            .with_depth_buffer(24)
-                            .rebuild_glium(&display).unwrap();
-                    } else {
-                        glutin::WindowBuilder::new()
-                            .rebuild_glium(&display).unwrap();
-                    }
-                },
-                */
-                _ => (),
-            }
+            },
+            _ => (),
         }
 
         timer.update();
diff --git a/screenshot.rs b/screenshot.rs
new file mode 100644 (file)
index 0000000..19f2b13
--- /dev/null
@@ -0,0 +1,13 @@
+#[cfg(feature = "image")]
+pub fn take_screenshot(display : &glium::Display) {
+    let image: glium::texture::RawImage2d<'_, u8> = display.read_front_buffer().unwrap();
+    let image = image::ImageBuffer::from_raw(image.width, image.height, image.data.into_owned()).unwrap();
+    let image = image::DynamicImage::ImageRgba8(image).flipv().to_rgb();
+    let image = image::DynamicImage::ImageRgb8(image);
+    let mut output = std::fs::File::create(&std::path::Path::new("screenshot.png")).unwrap();
+    image.write_to(&mut output, image::ImageFormat::PNG).unwrap();
+}
+
+#[cfg(not(feature = "image"))]
+pub fn take_screenshot(_ : &glium::Display) {
+}
index 8434a69976afeaecb2449d9636eb8700eb199ddb..afbfd1ab6183346636f6b6a0358fe09b82798d14 100644 (file)
--- a/timer.rs
+++ b/timer.rs
@@ -9,6 +9,7 @@ type Rocket = rust_rocket::Rocket;
 #[cfg(not(feature = "editor"))]
 type Rocket = ();
 
+#[cfg(feature = "editor")]
 const BPS: f32 = 10.0;
 
 #[derive(Debug)]