tirbofish/dropbear · commit
4912b6230d8126999cfa704dfbaabf432394e323
got the blue screen to render :)
Signature present but could not be verified.
Unverified
@@ -18,4 +18,4 @@ target # be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore # and can be added to the global gitignore or merged into this file. For a more nuclear # option (not recommended) you can uncomment the following to ignore the entire idea folder. -#.idea/ +.idea/ @@ -56,7 +56,7 @@ dependencies = [ "log", "ndk", "ndk-context", - "ndk-sys 0.6.0+11769913", + "ndk-sys", "num_enum", "thiserror 1.0.69", ] @@ -350,6 +350,16 @@ dependencies = [ ] [[package]] +name = "core-foundation" +version = "0.10.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b2a6cd9ae233e7f62ba4e9353e81a88df7fc8a5987b8d445b4d90c879bd156f6" +dependencies = [ + "core-foundation-sys", + "libc", +] + +[[package]] name = "core-foundation-sys" version = "0.8.7" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -362,8 +372,8 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c07782be35f9e1140080c6b96f0d44b739e2278479f64e02fdab4e32dfd8b081" dependencies = [ "bitflags 1.3.2", - "core-foundation", - "core-graphics-types", + "core-foundation 0.9.4", + "core-graphics-types 0.1.3", "foreign-types", "libc", ] @@ -375,7 +385,18 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "45390e6114f68f718cc7a830514a96f903cccd70d02a8f6d9f643ac4ba45afaf" dependencies = [ "bitflags 1.3.2", - "core-foundation", + "core-foundation 0.9.4", + "libc", +] + +[[package]] +name = "core-graphics-types" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3d44a101f213f6c4cdc1853d4b78aef6db6bdfa3468798cc1d9912f4735013eb" +dependencies = [ + "bitflags 2.9.1", + "core-foundation 0.10.1", "libc", ] @@ -650,12 +671,6 @@ dependencies = [ ] [[package]] -name = "heck" -version = "0.5.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2304e00983f87ffb38b55b444b5e3b60a884b5d30c0fca7d82fe33449bbe55ea" - -[[package]] name = "hermit-abi" version = "0.5.2" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -859,13 +874,13 @@ dependencies = [ [[package]] name = "metal" -version = "0.31.0" +version = "0.32.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f569fb946490b5743ad69813cb19629130ce9374034abe31614a36402d18f99e" +checksum = "00c15a6f673ff72ddcc22394663290f870fb224c1bfce55734a75c414150e605" dependencies = [ "bitflags 2.9.1", "block", - "core-graphics-types", + "core-graphics-types 0.2.0", "foreign-types", "log", "objc", @@ -874,25 +889,26 @@ dependencies = [ [[package]] name = "naga" -version = "25.0.1" +version = "26.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2b977c445f26e49757f9aca3631c3b8b836942cb278d69a92e7b80d3b24da632" +checksum = "916cbc7cb27db60be930a4e2da243cf4bc39569195f22fd8ee419cd31d5b662c" dependencies = [ "arrayvec", "bit-set", "bitflags 2.9.1", + "cfg-if", "cfg_aliases", "codespan-reporting", "half", "hashbrown", "hexf-parse", "indexmap", + "libm", "log", "num-traits", "once_cell", "rustc-hash", "spirv", - "strum", "thiserror 2.0.12", "unicode-ident", ] @@ -906,7 +922,7 @@ dependencies = [ "bitflags 2.9.1", "jni-sys", "log", - "ndk-sys 0.6.0+11769913", + "ndk-sys", "num_enum", "raw-window-handle", "thiserror 1.0.69", @@ -920,15 +936,6 @@ checksum = "27b02d87554356db9e9a873add8782d4ea6e3e58ea071a9adb9a2e8ddb884a8b" [[package]] name = "ndk-sys" -version = "0.5.0+25.2.9519653" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8c196769dd60fd4f363e11d948139556a344e79d451aeb2fa2fd040738ef7691" -dependencies = [ - "jni-sys", -] - -[[package]] -name = "ndk-sys" version = "0.6.0+11769913" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ee6cda3051665f1fb8d9e08fc35c96d5a244fb1be711a03b71118828afc9a873" @@ -1616,28 +1623,6 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "6637bab7722d379c8b41ba849228d680cc12d0a45ba1fa2b48f2a30577a06731" [[package]] -name = "strum" -version = "0.26.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8fec0f0aef304996cf250b31b5a10dee7980c85da9d759361292b8bca5a18f06" -dependencies = [ - "strum_macros", -] - -[[package]] -name = "strum_macros" -version = "0.26.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4c6bee85a5a24955dc440386795aa378cd9cf82acd5f764469152d2270e581be" -dependencies = [ - "heck", - "proc-macro2", - "quote", - "rustversion", - "syn", -] - -[[package]] name = "syn" version = "2.0.104" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -2012,12 +1997,13 @@ dependencies = [ [[package]] name = "wgpu" -version = "25.0.2" +version = "26.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ec8fb398f119472be4d80bc3647339f56eb63b2a331f6a3d16e25d8144197dd9" +checksum = "70b6ff82bbf6e9206828e1a3178e851f8c20f1c9028e74dd3a8090741ccd5798" dependencies = [ "arrayvec", "bitflags 2.9.1", + "cfg-if", "cfg_aliases", "document-features", "hashbrown", @@ -2040,9 +2026,9 @@ dependencies = [ [[package]] name = "wgpu-core" -version = "25.0.2" +version = "26.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f7b882196f8368511d613c6aeec80655160db6646aebddf8328879a88d54e500" +checksum = "d5f62f1053bd28c2268f42916f31588f81f64796e2ff91b81293515017ca8bd9" dependencies = [ "arrayvec", "bit-set", @@ -2071,36 +2057,36 @@ dependencies = [ [[package]] name = "wgpu-core-deps-apple" -version = "25.0.0" +version = "26.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cfd488b3239b6b7b185c3b045c39ca6bf8af34467a4c5de4e0b1a564135d093d" +checksum = "18ae5fbde6a4cbebae38358aa73fcd6e0f15c6144b67ef5dc91ded0db125dbdf" dependencies = [ "wgpu-hal", ] [[package]] name = "wgpu-core-deps-emscripten" -version = "25.0.0" +version = "26.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f09ad7aceb3818e52539acc679f049d3475775586f3f4e311c30165cf2c00445" +checksum = "d7670e390f416006f746b4600fdd9136455e3627f5bd763abf9a65daa216dd2d" dependencies = [ "wgpu-hal", ] [[package]] name = "wgpu-core-deps-windows-linux-android" -version = "25.0.0" +version = "26.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cba5fb5f7f9c98baa7c889d444f63ace25574833df56f5b817985f641af58e46" +checksum = "720a5cb9d12b3d337c15ff0e24d3e97ed11490ff3f7506e7f3d98c68fa5d6f14" dependencies = [ "wgpu-hal", ] [[package]] name = "wgpu-hal" -version = "25.0.2" +version = "26.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f968767fe4d3d33747bbd1473ccd55bf0f6451f55d733b5597e67b5deab4ad17" +checksum = "2971a6c8b903aa9951cf3f3e4d8060904f8c8e905c11f7f5b228edf7faddb719" dependencies = [ "android_system_properties", "arrayvec", @@ -2111,7 +2097,7 @@ dependencies = [ "bytemuck", "cfg-if", "cfg_aliases", - "core-graphics-types", + "core-graphics-types 0.2.0", "glow", "glutin_wgl_sys", "gpu-alloc", @@ -2125,11 +2111,12 @@ dependencies = [ "log", "metal", "naga", - "ndk-sys 0.5.0+25.2.9519653", + "ndk-sys", "objc", "ordered-float", "parking_lot", "portable-atomic", + "portable-atomic-util", "profiling", "range-alloc", "raw-window-handle", @@ -2145,9 +2132,9 @@ dependencies = [ [[package]] name = "wgpu-types" -version = "25.0.0" +version = "26.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2aa49460c2a8ee8edba3fca54325540d904dd85b2e086ada762767e17d06e8bc" +checksum = "eca7a8d8af57c18f57d393601a1fb159ace8b2328f1b6b5f80893f7d672c9ae2" dependencies = [ "bitflags 2.9.1", "bytemuck", @@ -2523,7 +2510,7 @@ dependencies = [ "calloop", "cfg_aliases", "concurrent-queue", - "core-foundation", + "core-foundation 0.9.4", "core-graphics", "cursor-icon", "dpi", @@ -12,5 +12,5 @@ anyhow = "1.0.98" winit = { version = "0.30", features = ["android-native-activity"] } env_logger = "0.11" log = "0.4" -wgpu = "25" +wgpu = "26" pollster = "0.4" @@ -5,15 +5,15 @@ use crate::State; pub struct Graphics<'a> { pub state: &'a State, pub view: &'a TextureView, - pub encoder: &'a CommandEncoder + pub encoder: &'a mut CommandEncoder, } impl<'a> Graphics<'a> { - pub fn new(state: &'a State, view: &'a TextureView, encoder: &'a CommandEncoder) -> Self { + pub fn new(state: &'a State, view: &'a TextureView, encoder: &'a mut CommandEncoder) -> Self { Self { state, view, - encoder + encoder, } } @@ -22,6 +22,7 @@ impl<'a> Graphics<'a> { label: Some("Render Pass"), color_attachments: &[Some(wgpu::RenderPassColorAttachment { view: &self.view, + depth_slice: None, resolve_target: None, ops: wgpu::Operations { load: wgpu::LoadOp::Clear(wgpu::Color { @@ -38,4 +39,4 @@ impl<'a> Graphics<'a> { timestamp_writes: None, }); } -} +} @@ -1,5 +1,10 @@ use std::collections::{HashMap, HashSet}; -use winit::{dpi::{PhysicalPosition, Position}, event::{self, MouseButton}, event_loop::{self, ActiveEventLoop, EventLoop}, keyboard::KeyCode}; +use winit::{ + dpi::{PhysicalPosition, Position}, + event::{self, MouseButton}, + event_loop::{self, ActiveEventLoop, EventLoop}, + keyboard::KeyCode, +}; use crate::State; @@ -18,12 +23,12 @@ pub struct Manager { pressed_keys: HashSet<KeyCode>, just_pressed_keys: HashSet<KeyCode>, just_released_keys: HashSet<KeyCode>, - + pressed_mouse_buttons: HashSet<MouseButton>, just_pressed_mouse_buttons: HashSet<MouseButton>, just_released_mouse_buttons: HashSet<MouseButton>, mouse_position: PhysicalPosition<f64>, - + input_handlers: HashMap<String, Box<dyn Keyboard>>, mouse_handlers: HashMap<String, Box<dyn Mouse>>, } @@ -140,4 +145,4 @@ impl Manager { self.just_pressed_mouse_buttons.clear(); self.just_released_mouse_buttons.clear(); } -} +} @@ -2,19 +2,27 @@ pub mod graphics; pub mod input; pub mod scene; +pub use log; use log::warn; +pub use wgpu; use wgpu::{Device, Queue, Surface, SurfaceConfiguration}; pub use winit; -pub use wgpu; -pub use log; use std::sync::Arc; - -use winit::{application::ApplicationHandler, dpi::PhysicalSize, event::{KeyEvent, WindowEvent}, event_loop::{ActiveEventLoop, EventLoop}, keyboard::{KeyCode, PhysicalKey}, window::Window}; +use std::thread::current; +use winit::{ + application::ApplicationHandler, + dpi::PhysicalSize, + event::{KeyEvent, WindowEvent}, + event_loop::{ActiveEventLoop, EventLoop}, + keyboard::{KeyCode, PhysicalKey}, + window::Window, +}; use crate::graphics::Graphics; +use crate::scene::SceneImpl; -pub struct State { +pub struct State{ surface: Surface<'static>, device: Device, queue: Queue, @@ -43,18 +51,21 @@ impl State { }) .await?; - let (device, queue) = adapter.request_device(&wgpu::DeviceDescriptor { - label: None, - required_features: wgpu::Features::empty(), - required_limits: wgpu::Limits::default(), - memory_hints: Default::default(), - trace: wgpu::Trace::Off - }) - .await?; + let (device, queue) = adapter + .request_device(&wgpu::DeviceDescriptor { + label: None, + required_features: wgpu::Features::empty(), + required_limits: wgpu::Limits::default(), + memory_hints: Default::default(), + trace: wgpu::Trace::Off, + }) + .await?; let surface_caps = surface.get_capabilities(&adapter); - let surface_format = surface_caps.formats.iter() + let surface_format = surface_caps + .formats + .iter() .find(|f| f.is_srgb()) .copied() .unwrap_or(surface_caps.formats[0]); @@ -88,26 +99,23 @@ impl State { } } - fn update(&mut self) { - - } + fn update(&mut self) {} - fn render(&mut self) -> anyhow::Result<()> { + fn render(&mut self, scene_manager: &mut scene::Manager) -> anyhow::Result<()> { self.window.request_redraw(); if !self.is_surface_configured { - return Ok(()) + return Ok(()); } let output = self.surface.get_current_texture()?; - let view = output.texture.create_view(&wgpu::TextureViewDescriptor::default()); - let mut encoder = self.device.create_command_encoder(&wgpu::CommandEncoderDescriptor { label: Some("Render Encoder"), }); - let graphics = Graphics::new(self, &view, &encoder) + let mut graphics = Graphics::new(self, &view, &mut encoder); + scene_manager.render(&mut graphics); self.queue.submit(std::iter::once(encoder.finish())); output.present(); @@ -120,12 +128,11 @@ pub struct App { config: WindowConfiguration, state: Option<State>, scene_manager: scene::Manager, - input_manager: input::Manager + input_manager: input::Manager, } impl App { - pub fn new(config: WindowConfiguration - ) -> Self { + pub fn new(config: WindowConfiguration) -> Self { Self { state: None, config, @@ -135,7 +142,9 @@ impl App { } pub fn run<F>(config: WindowConfiguration, app_name: &str, setup: F) -> anyhow::Result<()> - where F: FnOnce(&mut scene::Manager, &mut input::Manager) { + where + F: FnOnce(&mut scene::Manager, &mut input::Manager), + { if cfg!(debug_assertions) { // let package_name = std::env::var("CARGO_BIN_NAME").unwrap(); let log_config = format!("dropbear_engine=debug,{}=debug,warn", app_name); @@ -146,7 +155,7 @@ impl App { let event_loop = EventLoop::with_user_event().build()?; let mut app = App::new(config); - + setup(&mut app.scene_manager, &mut app.input_manager); event_loop.run_app(&mut app)?; @@ -190,11 +199,11 @@ impl ApplicationHandler for App { WindowEvent::Resized(size) => state.resize(size.width, size.height), WindowEvent::RedrawRequested => { self.scene_manager.update(0.016); // todo: get update to be calculated properly - self.scene_manager.render(); + // self.scene_manager.render(); self.input_manager.update(); - state.render(); + state.render(&mut self.scene_manager).unwrap(); } WindowEvent::KeyboardInput { event: @@ -205,14 +214,20 @@ impl ApplicationHandler for App { }, .. } => { - self.input_manager.handle_key_input(code, key_state.is_pressed(), event_loop); - }, - WindowEvent::MouseInput { button, state: button_state, .. } => { - self.input_manager.handle_mouse_input(button, button_state.is_pressed()); - }, + self.input_manager + .handle_key_input(code, key_state.is_pressed(), event_loop); + } + WindowEvent::MouseInput { + button, + state: button_state, + .. + } => { + self.input_manager + .handle_mouse_input(button, button_state.is_pressed()); + } WindowEvent::CursorMoved { position, .. } => { self.input_manager.handle_mouse_movement(position); - }, + } _ => {} } } @@ -222,4 +237,4 @@ pub struct WindowConfiguration { pub width: u32, pub height: u32, pub title: &'static str, -} +} @@ -1,17 +1,20 @@ use std::collections::HashMap; +use crate::graphics::Graphics; pub trait Scene { fn load(&mut self); fn update(&mut self, dt: f32); - fn render(&mut self); + fn render(&mut self, graphics: &mut Graphics); fn exit(&mut self); } +pub type SceneImpl = Box<dyn Scene>; + pub struct Manager { current_scene: Option<String>, next_scene: Option<String>, scenes: HashMap<String, Box<dyn Scene>>, - scene_input_map: HashMap<String, String>, // Maps scene name to input handler name + scene_input_map: HashMap<String, String>, } impl Manager { @@ -35,11 +38,12 @@ impl Manager { } pub fn attach_input(&mut self, scene_name: &str, input_name: &str) { - self.scene_input_map.insert(scene_name.to_string(), input_name.to_string()); + self.scene_input_map + .insert(scene_name.to_string(), input_name.to_string()); } pub fn update(&mut self, dt: f32) { - // Handle scene transitions + // transition scene if let Some(next_scene_name) = self.next_scene.take() { if let Some(current_scene_name) = &self.current_scene { if let Some(scene) = self.scenes.get_mut(current_scene_name) { @@ -52,7 +56,7 @@ impl Manager { self.current_scene = Some(next_scene_name); } - // Update current scene + // update scene if let Some(scene_name) = &self.current_scene { if let Some(scene) = self.scenes.get_mut(scene_name) { scene.update(dt); @@ -60,10 +64,10 @@ impl Manager { } } - pub fn render(&mut self) { + pub fn render(&mut self, graphics: &mut Graphics) { if let Some(scene_name) = &self.current_scene { if let Some(scene) = self.scenes.get_mut(scene_name) { - scene.render(); + scene.render(graphics); } } } @@ -71,4 +75,14 @@ impl Manager { pub fn has_scene(&self) -> bool { self.current_scene.is_some() } -} + + pub fn get_current_scene(&self) -> Option<(&String, &SceneImpl)> { + if let Some(scene_name) = &self.current_scene { + if let Some(scene) = self.scenes.get(scene_name) { + return Some((scene_name, scene)) + } + return None + } + None + } +} @@ -1,24 +1,25 @@ mod scene1; -use dropbear_engine::{input, WindowConfiguration}; +use dropbear_engine::{WindowConfiguration, input}; fn main() { let config = WindowConfiguration { - width: 1280 as u32, - height: 720 as u32, - title: "Eucalyptus, built with dropbear" + width: 1280u32, + height: 720u32, + title: "Eucalyptus, built with dropbear", }; let _app = dropbear_engine::run_app!(config, |scene_manager, input_manager| { let testing_scene = scene1::TestingScene1::new(); let testing_keyboard = scene1::TestingScene1::new(); let testing_mouse = scene1::TestingScene1::new(); - + scene_manager.add("testing_scene", Box::new(testing_scene)); input_manager.add_keyboard("testing_scene_keyboard", Box::new(testing_keyboard)); input_manager.add_mouse("testing_scene_mouse", Box::new(testing_mouse)); - + scene_manager.attach_input("testing_scene", "testing_scene_keyboard"); scene_manager.attach_input("testing_scene", "testing_scene_mouse"); scene_manager.switch("testing_scene"); - }).unwrap(); + }) + .unwrap(); } @@ -1,4 +1,14 @@ -use dropbear_engine::{input::{Keyboard, Mouse}, log::{self, debug}, scene::Scene, winit::{event, event_loop::{self, ActiveEventLoop}, keyboard::KeyCode}}; +use dropbear_engine::{ + input::{Keyboard, Mouse}, + log::{self, debug}, + scene::Scene, + winit::{ + event, + event_loop::{self, ActiveEventLoop}, + keyboard::KeyCode, + }, +}; +use dropbear_engine::graphics::Graphics; pub struct TestingScene1; @@ -17,8 +27,8 @@ impl Scene for TestingScene1 { // Scene update logic here } - fn render(&mut self) { - // Scene rendering logic here + fn render(&mut self, graphics: &mut Graphics) { + graphics.clear_colour(); } fn exit(&mut self) { @@ -41,7 +51,6 @@ impl Keyboard for TestingScene1 { } impl Mouse for TestingScene1 { - fn mouse_down(&mut self, button: dropbear_engine::winit::event::MouseButton) { debug!("Mouse button pressed: {:?}", button) } @@ -49,8 +58,8 @@ impl Mouse for TestingScene1 { fn mouse_up(&mut self, button: dropbear_engine::winit::event::MouseButton) { debug!("Mouse button released: {:?}", button); } - + fn mouse_move(&mut self, position: dropbear_engine::winit::dpi::PhysicalPosition<f64>) { debug!("Mouse position: {}, {}", position.x, position.y) } -} +}