Use crawl context builder
This commit is contained in:
		
							parent
							
								
									7787a8b69e
								
							
						
					
					
						commit
						9d332655be
					
				
							
								
								
									
										65
									
								
								src/app.rs
								
								
								
								
							
							
						
						
									
										65
									
								
								src/app.rs
								
								
								
								
							|  | @ -1,65 +0,0 @@ | |||
| use std::sync::Arc; | ||||
| 
 | ||||
| use anyhow::Result; | ||||
| use crawl::{ | ||||
|     wgpu, | ||||
|     winit::{ | ||||
|         self, | ||||
|         dpi::PhysicalSize, | ||||
|         event::{Event, WindowEvent}, | ||||
|         event_loop::EventLoop, | ||||
|     }, | ||||
| }; | ||||
| 
 | ||||
| pub struct App<'window> { | ||||
|     title: String, | ||||
|     event_loop: EventLoop<()>, | ||||
|     render_ctx: crawl::Context<'window>, | ||||
| } | ||||
| 
 | ||||
| impl<'window> App<'window> { | ||||
|     pub async fn new(width: u32, height: u32, title: &str) -> Result<Self> { | ||||
|         log::info!("Initialising window..."); | ||||
|         let size = PhysicalSize::new(width, height); | ||||
|         let event_loop = EventLoop::new()?; | ||||
|         let window = Arc::new( | ||||
|             winit::window::WindowBuilder::new() | ||||
|                 .with_title(title) | ||||
|                 .with_inner_size(size) | ||||
|                 .build(&event_loop)?, | ||||
|         ); | ||||
| 
 | ||||
|         let render_ctx = crawl::Context::new( | ||||
|             window, | ||||
|             wgpu::Limits { | ||||
|                 max_storage_buffer_binding_size: 1 << 30, | ||||
|                 max_buffer_size: 1 << 30, | ||||
|                 ..Default::default() | ||||
|             }, | ||||
|         ) | ||||
|         .await?; | ||||
| 
 | ||||
|         Ok(Self { | ||||
|             title: title.to_owned(), | ||||
|             event_loop, | ||||
|             render_ctx, | ||||
|         }) | ||||
|     } | ||||
| 
 | ||||
|     pub fn run(mut self) -> Result<()> { | ||||
|         self.event_loop.run(|event, elwt| match event { | ||||
|             Event::WindowEvent { window_id, event } if window_id == self.render_ctx.window.id() => { | ||||
|                 if self.render_ctx.handle_window_event(&event, elwt) { | ||||
|                     return; | ||||
|                 } | ||||
| 
 | ||||
|                 if let WindowEvent::RedrawRequested = event { | ||||
|                     self.render_ctx.window.request_redraw(); | ||||
|                 } | ||||
|             } | ||||
|             _ => (), | ||||
|         })?; | ||||
| 
 | ||||
|         Ok(()) | ||||
|     } | ||||
| } | ||||
							
								
								
									
										26
									
								
								src/main.rs
								
								
								
								
							
							
						
						
									
										26
									
								
								src/main.rs
								
								
								
								
							|  | @ -1,10 +1,28 @@ | |||
| mod app; | ||||
| 
 | ||||
| use anyhow::Result; | ||||
| use app::App; | ||||
| use crawl::winit::event::{Event, WindowEvent}; | ||||
| 
 | ||||
| fn main() -> Result<()> { | ||||
|     env_logger::init(); | ||||
|     pollster::block_on(App::new(1280, 720, "Epic"))?.run()?; | ||||
|     let (mut context, event_loop) = pollster::block_on( | ||||
|         crawl::ContextBuilder::new() | ||||
|             .with_title("BEAVER") | ||||
|             .with_vsync(false) | ||||
|             .build(), | ||||
|     )?; | ||||
| 
 | ||||
|     event_loop.run(|event, elwt| match event { | ||||
|         Event::WindowEvent { window_id, event } if window_id == context.window.id() => { | ||||
|             if context.handle_window_event(&event, elwt) { | ||||
|                 return; | ||||
|             } | ||||
| 
 | ||||
|             if let WindowEvent::RedrawRequested = event { | ||||
|                 log::info!("Epic"); | ||||
|                 context.window.request_redraw(); | ||||
|             } | ||||
|         } | ||||
|         _ => (), | ||||
|     })?; | ||||
| 
 | ||||
|     Ok(()) | ||||
| } | ||||
|  |  | |||
		Loading…
	
		Reference in New Issue