use winit::{event::{ElementState, Event, KeyEvent, WindowEvent}, event_loop::EventLoop, keyboard::{KeyCode, PhysicalKey}}; use crate::surface; pub async fn run(){ env_logger::init(); let event_loop = EventLoop::new().unwrap(); let window = winit::window::WindowBuilder::new().with_title("Hello, World!").build(&event_loop).unwrap(); let mut state = surface::State::new(&window).await; event_loop .run(move |event, control_flow| { match event { Event::WindowEvent { ref event, window_id, } if window_id == state.window().id() => { if !state.input(event) { // UPDATED! match event { WindowEvent::CloseRequested | WindowEvent::KeyboardInput { event: KeyEvent { state: ElementState::Pressed, physical_key: PhysicalKey::Code(KeyCode::Escape), .. }, .. } => control_flow.exit(), WindowEvent::Resized(physical_size) => { log::info!("physical_size: {physical_size:?}"); state.resize(*physical_size); } WindowEvent::RedrawRequested => { // This tells winit that we want another frame after this one state.window().request_redraw(); state.update(); match state.render() { Ok(_) => {} // Reconfigure the surface if it's lost or outdated Err( wgpu::SurfaceError::Lost | wgpu::SurfaceError::Outdated, ) => state.resize(state.size), // The system is out of memory, we should probably quit Err(wgpu::SurfaceError::OutOfMemory) => { log::error!("OutOfMemory"); control_flow.exit(); } // This happens when the a frame takes too long to present Err(wgpu::SurfaceError::Timeout) => { log::warn!("Surface timeout") } } } _ => {} } } } _ => {} } }) .unwrap(); }