rust/hwrunner/src/main.rs
changeset 14705 19122a329774
parent 14704 12db7e435ea6
child 14709 65c971417780
--- a/rust/hwrunner/src/main.rs	Fri Mar 22 20:01:47 2019 +0300
+++ b/rust/hwrunner/src/main.rs	Fri Mar 22 20:26:29 2019 +0300
@@ -1,29 +1,14 @@
 use glutin::{
-    dpi,
-    Event,
-    WindowEvent,
-    DeviceEvent,
-    ElementState,
-    MouseButton,
-    MouseScrollDelta,
-    EventsLoop,
-    WindowedContext,
-    GlRequest,
-    GlProfile,
-    ContextTrait,
+    dpi, ContextTrait, DeviceEvent, ElementState, Event, EventsLoop, GlProfile, GlRequest,
+    MouseButton, MouseScrollDelta, WindowEvent, WindowedContext,
 };
 
-use hedgewars_engine::{
-    instance::EngineInstance,
-};
+use hedgewars_engine::instance::EngineInstance;
 
 use integral_geometry::Point;
 
 fn init(event_loop: &EventsLoop, size: dpi::LogicalSize) -> WindowedContext {
-    use glutin::{
-        ContextBuilder,
-        WindowBuilder
-    };
+    use glutin::{ContextBuilder, WindowBuilder};
 
     let window = WindowBuilder::new()
         .with_title("hwengine")
@@ -32,15 +17,17 @@
     let cxt = ContextBuilder::new()
         .with_gl(GlRequest::Latest)
         .with_gl_profile(GlProfile::Core)
-        .build_windowed(window, &event_loop).ok().unwrap();
+        .build_windowed(window, &event_loop)
+        .ok()
+        .unwrap();
 
     unsafe {
         cxt.make_current().unwrap();
         gl::load_with(|ptr| cxt.get_proc_address(ptr) as *const _);
-        
+
         if let Some(sz) = cxt.get_inner_size() {
             let phys = sz.to_physical(cxt.get_hidpi_factor());
-            
+
             gl::Viewport(0, 0, phys.width as i32, phys.height as i32);
         }
     }
@@ -54,13 +41,14 @@
     let window = init(&event_loop, dpi::LogicalSize::new(w, h));
 
     let mut engine = EngineInstance::new();
+    engine.world.create_renderer(w as u16, h as u16);
 
     let mut dragging = false;
 
     use std::time::Instant;
 
     let mut now = Instant::now();
-    
+
     let mut is_running = true;
     while is_running {
         let curr = Instant::now();
@@ -68,48 +56,44 @@
         now = curr;
         let ms = delta.as_secs() as f64 * 1000.0 + delta.subsec_millis() as f64;
         window.set_title(&format!("hwengine {:.3}ms", ms));
-        
-        event_loop.poll_events(|event| {
-            match event {
-                Event::WindowEvent { event, ..} => match event {
-                    WindowEvent::CloseRequested => {
-                        is_running = false;
-                    },
-                    WindowEvent::MouseInput { button, state, .. } => {
-                        if let MouseButton::Right = button {
-                            if let ElementState::Pressed = state {
-                                dragging = true;
-                            } else {
-                                dragging = false;
-                            }
+
+        event_loop.poll_events(|event| match event {
+            Event::WindowEvent { event, .. } => match event {
+                WindowEvent::CloseRequested => {
+                    is_running = false;
+                }
+                WindowEvent::MouseInput { button, state, .. } => {
+                    if let MouseButton::Right = button {
+                        if let ElementState::Pressed = state {
+                            dragging = true;
+                        } else {
+                            dragging = false;
                         }
                     }
-                    WindowEvent::MouseWheel { delta, .. } => {
-                        let zoom_change = match delta {
-                            MouseScrollDelta::LineDelta(x, y) => {
-                                y as f32 * 0.1f32
-                            }
-                            MouseScrollDelta::PixelDelta(delta) => {
-                                let physical = delta.to_physical(window.get_hidpi_factor());
-                                physical.y as f32 * 0.1f32
-                            }
-                        };
-                        engine.world.move_camera(Point::ZERO, zoom_change);
+                }
+                WindowEvent::MouseWheel { delta, .. } => {
+                    let zoom_change = match delta {
+                        MouseScrollDelta::LineDelta(x, y) => y as f32 * 0.1f32,
+                        MouseScrollDelta::PixelDelta(delta) => {
+                            let physical = delta.to_physical(window.get_hidpi_factor());
+                            physical.y as f32 * 0.1f32
+                        }
+                    };
+                    engine.world.move_camera(Point::ZERO, zoom_change);
+                }
+                _ => (),
+            },
+            Event::DeviceEvent { event, .. } => match event {
+                DeviceEvent::MouseMotion { delta } => {
+                    if dragging {
+                        engine
+                            .world
+                            .move_camera(Point::new(delta.0 as i32, delta.1 as i32), 0.0)
                     }
-                    _ => ()
-                },
-                Event::DeviceEvent { event, .. } => match event {
-                    DeviceEvent::MouseMotion { delta } => {
-                        if dragging {
-                            engine.world.move_camera(
-                                Point::new(delta.0 as i32, delta.1 as i32), 0.0
-                            )
-                        }
-                    }
-                    _ => {}
                 }
-                _ => ()
-            }
+                _ => {}
+            },
+            _ => (),
         });
 
         unsafe { window.make_current().unwrap() };