diff --git a/Cargo.lock b/Cargo.lock index 98ae5b7..aee47b4 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -52,9 +52,9 @@ dependencies = [ [[package]] name = "ahash" -version = "0.8.6" +version = "0.8.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "91429305e9f0a25f6205c5b8e0d2db09e0708a7a6df0f42212bb56c32c8ac97a" +checksum = "77c3a9648d43b9cd48db467b3f87fdd6e146bcc88ab0180006cef2179fe11d01" dependencies = [ "cfg-if", "getrandom", @@ -255,7 +255,7 @@ dependencies = [ [[package]] name = "blue_engine" -version = "0.5.0" +version = "0.5.1" dependencies = [ "android_logger", "anyhow", @@ -497,12 +497,6 @@ dependencies = [ "cfg-if", ] -[[package]] -name = "cty" -version = "0.2.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b365fabc795046672053e29c954733ec3b05e4be654ab130fe8f1f94d7051f35" - [[package]] name = "cursor-icon" version = "1.1.0" @@ -796,12 +790,12 @@ dependencies = [ [[package]] name = "gethostname" -version = "0.3.0" +version = "0.4.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bb65d4ba3173c56a500b555b532f72c42e8d1fe64962b518897f8959fae2c177" +checksum = "0176e0459c2e4a1fe232f984bca6890e681076abb9934f6cea7c326f3fc47818" dependencies = [ "libc", - "winapi", + "windows-targets 0.48.5", ] [[package]] @@ -1216,9 +1210,9 @@ checksum = "2dffe52ecf27772e601905b7522cb4ef790d2cc203488bbd0e2fe85fcb74566d" [[package]] name = "memmap2" -version = "0.9.0" +version = "0.9.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "deaba38d7abf1d4cca21cc89e932e542ba2b9258664d2a9ef0e61512039c9375" +checksum = "45fd3a57831bf88bc63f8cebc0cf956116276e97fef3966103e96416209f7c92" dependencies = [ "libc", ] @@ -1282,9 +1276,9 @@ dependencies = [ [[package]] name = "naga" -version = "0.14.1" +version = "0.14.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6cd05939c491da968a42986204b7431678be21fdcd4b10cc84997ba130ada5a4" +checksum = "ae585df4b6514cf8842ac0f1ab4992edc975892704835b549cf818dc0191249e" dependencies = [ "bit-set", "bitflags 2.4.1", @@ -1347,6 +1341,7 @@ dependencies = [ "log", "ndk-sys", "num_enum", + "raw-window-handle 0.5.2", "raw-window-handle 0.6.0", "thiserror", ] @@ -1691,12 +1686,9 @@ checksum = "63e935c45e09cc6dcf00d2f0b2d630a58f4095320223d47fc68918722f0538b6" [[package]] name = "raw-window-handle" -version = "0.5.0" +version = "0.5.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ed7e3d950b66e19e0c372f3fa3fbbcf85b1746b571f74e0c2af6042a5c93420a" -dependencies = [ - "cty", -] +checksum = "f2ff9a1f06a88b01621b7ae906ef0211290d1c8a168a15542486a8f61c0833b9" [[package]] name = "raw-window-handle" @@ -1852,9 +1844,9 @@ checksum = "d29ab0c6d3fc0ee92fe66e2d99f700eab17a8d57d1c1d3b748380fb20baa78cd" [[package]] name = "sctk-adwaita" -version = "0.7.0" +version = "0.8.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1729a30a469de249c6effc17ec8d039b0aa29b3af79b819b7f51cb6ab8046a90" +checksum = "82b2eaf3a5b264a521b988b2e73042e742df700c4f962cde845d1541adb46550" dependencies = [ "ab_glyph", "log", @@ -2365,7 +2357,7 @@ dependencies = [ "naga", "parking_lot", "profiling", - "raw-window-handle 0.5.0", + "raw-window-handle 0.5.2", "smallvec", "static_assertions", "wasm-bindgen", @@ -2390,7 +2382,7 @@ dependencies = [ "naga", "parking_lot", "profiling", - "raw-window-handle 0.5.0", + "raw-window-handle 0.5.2", "rustc-hash", "smallvec", "thiserror", @@ -2401,9 +2393,9 @@ dependencies = [ [[package]] name = "wgpu-hal" -version = "0.18.0" +version = "0.18.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1e30b9a8155c83868e82a8c5d3ce899de6c3961d2ef595de8fc168a1677fc2d8" +checksum = "b84ecc802da3eb67b4cf3dd9ea6fe45bbb47ef13e6c49c5c3240868a9cc6cdd9" dependencies = [ "android_system_properties", "arrayvec", @@ -2431,7 +2423,7 @@ dependencies = [ "parking_lot", "profiling", "range-alloc", - "raw-window-handle 0.5.0", + "raw-window-handle 0.5.2", "renderdoc-sys", "rustc-hash", "smallvec", @@ -2494,15 +2486,6 @@ dependencies = [ "winapi", ] -[[package]] -name = "winapi-wsapoll" -version = "0.1.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "44c17110f57155602a80dca10be03852116403c9ff3cd25b079d666f2aa3df6e" -dependencies = [ - "winapi", -] - [[package]] name = "winapi-x86_64-pc-windows-gnu" version = "0.4.0" @@ -2720,11 +2703,11 @@ checksum = "ed94fce61571a4006852b7389a063ab983c02eb1bb37b47f8272ce92d06d9538" [[package]] name = "winit" -version = "0.29.4" +version = "0.29.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d25d662bb83b511acd839534bb2d88521b0bbc81440969cb077d23c4db9e62c7" +checksum = "0dc1a7ae1076890701c7dd71ea35b2aebaf9aeb7b8868ac2d33b1c7e8ef93c00" dependencies = [ - "ahash 0.8.6", + "ahash 0.8.7", "android-activity", "atomic-waker", "bitflags 2.4.1", @@ -2745,6 +2728,7 @@ dependencies = [ "once_cell", "orbclient", "percent-encoding", + "raw-window-handle 0.5.2", "raw-window-handle 0.6.0", "redox_syscall 0.3.5", "rustix 0.38.25", @@ -2788,29 +2772,24 @@ dependencies = [ [[package]] name = "x11rb" -version = "0.12.0" +version = "0.13.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b1641b26d4dec61337c35a1b1aaf9e3cba8f46f0b43636c609ab0291a648040a" +checksum = "f8f25ead8c7e4cba123243a6367da5d3990e0d3affa708ea19dce96356bd9f1a" dependencies = [ "as-raw-xcb-connection", "gethostname", "libc", - "libloading 0.7.3", - "nix", + "libloading 0.8.0", "once_cell", - "winapi", - "winapi-wsapoll", + "rustix 0.38.25", "x11rb-protocol", ] [[package]] name = "x11rb-protocol" -version = "0.12.0" +version = "0.13.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "82d6c3f9a0fb6701fab8f6cea9b0c0bd5d6876f1f89f7fada07e558077c344bc" -dependencies = [ - "nix", -] +checksum = "e63e71c4b8bd9ffec2c963173a4dc4cbde9ee96961d4fcb4429db9929b606c34" [[package]] name = "xcursor" @@ -2848,18 +2827,18 @@ checksum = "d2d7d3948613f75c98fd9328cfdcc45acc4d360655289d0a7d4ec931392200a3" [[package]] name = "zerocopy" -version = "0.7.26" +version = "0.7.32" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e97e415490559a91254a2979b4829267a57d2fcd741a98eee8b722fb57289aa0" +checksum = "74d4d3961e53fa4c9a25a8637fc2bfaf2595b3d3ae34875568a5cf64787716be" dependencies = [ "zerocopy-derive", ] [[package]] name = "zerocopy-derive" -version = "0.7.26" +version = "0.7.32" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dd7e48ccf166952882ca8bd778a43502c64f33bf94c12ebe2a7f08e5a0f6689f" +checksum = "9ce1b18ccd8e73a9321186f97e46f9f04b778851177567b1975109d26a08d2a6" dependencies = [ "proc-macro2", "quote", diff --git a/Cargo.toml b/Cargo.toml index 3314083..541e6c8 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "blue_engine" -version = "0.5.0" +version = "0.5.1" authors = ["Elham Aryanpur "] edition = "2021" description = "General-Purpose, Easy-to-use, Fast, and Portable graphics engine" @@ -22,11 +22,11 @@ NON_FILL_POLYGON_MODE = [] [dependencies] image = { version = "0.24" } futures = "0.3" -winit = { version = "0.29" } +winit = { version = "0.29.8", features = ["rwh_05"] } +wgpu = { version = "0.18" } bytemuck = { version = "1.14", features = ["derive"] } winit_input_helper = "0.15" anyhow = "1.0" -wgpu = { version = "0.18" } downcast = "0.11" nalgebra-glm = "0.18" # debug logs diff --git a/src/render.rs b/src/render.rs index 6feab49..3053500 100644 --- a/src/render.rs +++ b/src/render.rs @@ -40,9 +40,8 @@ impl Renderer { backends, ..Default::default() }); - #[cfg(not(feature = "android"))] - let surface = Some(unsafe { instance.create_surface(&window) }?); + let surface = Some(unsafe { instance.create_surface(&window)? }); #[cfg(feature = "android")] let surface = None; diff --git a/src/window.rs b/src/window.rs index 11012ed..4e8d3d4 100644 --- a/src/window.rs +++ b/src/window.rs @@ -118,20 +118,6 @@ impl Engine { // The main loop event_loop.run(move |events, window_target| { - // updates the data on what events happened before the frame start - input.update(&events); - - plugins.iter_mut().for_each(|i| { - i.update_events( - &mut renderer, - &window, - &mut objects, - &events, - &input, - &mut camera, - ); - }); - match events { Event::WindowEvent { ref event, @@ -150,8 +136,62 @@ impl Engine { .update_view_projection(&mut renderer) .expect("Couldn't set the resize to camera in renderer"); } + WindowEvent::RedrawRequested => { + let pre_render = renderer + .pre_render(&objects, &camera) + .expect("Couldn't get pre render data"); + if pre_render.is_some() { + let (mut encoder, view, frame) = pre_render.unwrap(); + + update_function( + &mut renderer, + &mut window, + &mut objects, + &input, + &mut camera, + &mut plugins, + ); + + plugins.iter_mut().for_each(|i| { + i.update( + &mut renderer, + &window, + &mut objects, + &mut camera, + &input, + &mut encoder, + &view, + ); + }); + + camera + .update_view_projection(&mut renderer) + .expect("Couldn't update camera"); + objects.iter_mut().for_each(|i| { + if i.1.changed { + i.1.update(&mut renderer).expect("Couldn't update objects"); + } + }); + + match renderer.render(encoder, frame) { + Ok(_) => {} + // Recreate the swap_chain if lost + Err(wgpu::SurfaceError::Lost) => renderer.resize(renderer.size), + // The system is out of memory, we should probably quit + Err(wgpu::SurfaceError::OutOfMemory) => { + window_target.exit(); + } + // All other errors (Outdated, Timeout) should be resolved by the next frame + Err(e) => eprintln!("{:?}", e), + } + } + + _device_event = DeviceEvent::MouseMotion { delta: (0.0, 0.0) }; + window.request_redraw(); + } _ => {} }, + #[cfg(feature = "android")] Event::Resumed => { let surface = unsafe { renderer.instance.create_surface(&window) }; @@ -170,65 +210,26 @@ impl Engine { } Event::DeviceEvent { event, .. } => _device_event = event, - Event::NewEvents(new_events) => { - let pre_render = renderer - .pre_render(&objects, &camera) - .expect("Couldn't get pre render data"); - if pre_render.is_some() { - let (mut encoder, view, frame) = pre_render.unwrap(); - - #[cfg(not(feature = "gui"))] - update_function( + + Event::NewEvents(_new_events) => { + // updates the data on what events happened before the frame start + input.update(&events); + + plugins.iter_mut().for_each(|i| { + i.update_events( &mut renderer, - &mut window, + &window, &mut objects, + &events, &input, &mut camera, - &mut plugins, ); - - plugins.iter_mut().for_each(|i| { - i.update( - &mut renderer, - &window, - &mut objects, - &mut camera, - &input, - &mut encoder, - &view, - ); - }); - - camera - .update_view_projection(&mut renderer) - .expect("Couldn't update camera"); - objects.iter_mut().for_each(|i| { - if i.1.changed { - i.1.update(&mut renderer).expect("Couldn't update objects"); - } - }); - - let ren = renderer.render(encoder, frame); - - match ren { - Ok(_) => {} - // Recreate the swap_chain if lost - Err(wgpu::SurfaceError::Lost) => renderer.resize(renderer.size), - // The system is out of memory, we should probably quit - Err(wgpu::SurfaceError::OutOfMemory) => { - window_target.exit(); - } - // All other errors (Outdated, Timeout) should be resolved by the next frame - Err(e) => eprintln!("{:?}", e), - } - } - - _device_event = DeviceEvent::MouseMotion { delta: (0.0, 0.0) }; - window.request_redraw(); + }); } + _ => (), } - }); + })?; //logic(&mut renderer, WindowCallbackEvents::After, &window); Ok(())