diff --git a/Cargo.toml b/Cargo.toml index 8b60247..e18d5ee 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -6,3 +6,8 @@ edition = "2021" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] +anyhow = "1.0.82" +crawl = { path = "../crawl" } +env_logger = "0.11.3" +log = "0.4.21" +pollster = "0.3.0" diff --git a/src/app.rs b/src/app.rs new file mode 100644 index 0000000..9d81334 --- /dev/null +++ b/src/app.rs @@ -0,0 +1,65 @@ +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 { + 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(()) + } +} diff --git a/src/main.rs b/src/main.rs index e7a11a9..bd1171d 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,3 +1,10 @@ -fn main() { - println!("Hello, world!"); +mod app; + +use anyhow::Result; +use app::App; + +fn main() -> Result<()> { + env_logger::init(); + pollster::block_on(App::new(1280, 720, "Epic"))?.run()?; + Ok(()) }