diff --git a/context/src/core/context.rs b/context/src/core/context.rs index 5481b59..fae29df 100644 --- a/context/src/core/context.rs +++ b/context/src/core/context.rs @@ -72,6 +72,7 @@ impl Context { ) { Ok(res) => { if !res { + self.device().wait_idle()?; return Ok(false); } } @@ -119,6 +120,10 @@ impl Context { pub fn controllers(&self) -> impl Iterator { self.presentation.event_system().controllers() } + + pub fn joysticks(&self) -> impl Iterator { + self.presentation.event_system().joysticks() + } } impl std::fmt::Debug for Context { diff --git a/engine/src/engine/engine.rs b/engine/src/engine/engine.rs index f54aff1..6ad4a52 100644 --- a/engine/src/engine/engine.rs +++ b/engine/src/engine/engine.rs @@ -175,18 +175,14 @@ impl Engine { let asset_manager = AssetManager::new(&engine_settings)?; let gui_handler = GuiHandler::new(create_info.gui_info, &context)?; - let engine = Engine { - resource_base_path: create_info.resource_base_path, - }; - context .render_core_mut() .add_render_routine::(10_000_000); - // context.render_core_mut().add_render_routine::(100); + context.render_core_mut().add_render_routine::(100); world.resources.insert(context); - let scene = Scene::new( + Scene::new( create_info.rasterizer_info, create_info.raytracing_info, create_info.graphics_info, @@ -204,9 +200,10 @@ impl Engine { world.resources.insert(GuiHandlerRenderer); world.resources.insert(InputMap { direction_mapping }); world.resources.insert(asset_manager); - world.resources.insert(engine); + world.resources.insert(Engine { + resource_base_path: create_info.resource_base_path, + }); world.resources.insert(engine_settings); - world.resources.insert(scene); world.add_system(Self::main_system::); diff --git a/engine/src/engine/engine_event_handling.rs b/engine/src/engine/engine_event_handling.rs index 52607df..a0b79fb 100644 --- a/engine/src/engine/engine_event_handling.rs +++ b/engine/src/engine/engine_event_handling.rs @@ -12,13 +12,18 @@ pub enum EngineEvent<'a> { KeyDown(Keycode), KeyUp(Keycode), - ButtonDown(ControllerButton), - ButtonUp(ControllerButton), - ControllerAxis(ControllerAxis), - + ControllerButtonDown(&'a Controller, ControllerButton), + ControllerButtonUp(&'a Controller, ControllerButton), + ControllerAxis(&'a Controller, ControllerAxis), ControllerAdded(&'a Controller), ControllerRemoved(&'a Controller), + JoystickButtonDown(&'a Joystick), + JoystickButtonUp(&'a Joystick), + JoystickAxis(&'a Joystick), + JoystickAdded(&'a Joystick), + JoystickRemoved(&'a Joystick), + FileDrop(String), } @@ -66,11 +71,11 @@ impl Engine { Event::TextInput(text) => { Self::text_input(gui_handler, text)?; } - Event::ControllerButtonDown(_controller, button) => { - Self::button_down_event(world, gui_handler, consumer, button)?; + Event::ControllerButtonDown(controller, button) => { + Self::button_down_event(world, gui_handler, consumer, controller, button)?; } - Event::ControllerButtonUp(_controller, button) => { - Self::button_up_event(world, consumer, button)?; + Event::ControllerButtonUp(controller, button) => { + Self::button_up_event(world, consumer, controller, button)?; } Event::ControllerAxis(controller) => { if !gui_handler.check_navigatable()? { @@ -86,11 +91,21 @@ impl Engine { Self::controller_removed(world, consumer, controller)? } - Event::JoystickAxis(_joystick) => todo!(), - Event::JoystickButtonDown(_joystick) => todo!(), - Event::JoystickButtonUp(_joystick) => todo!(), - Event::JoystickAdded(_joystick) => todo!(), - Event::JoystickRemoved(_joystick) => todo!(), + Event::JoystickAxis(joystick) => { + consumer.event(world, EngineEvent::JoystickAxis(joystick))? + } + Event::JoystickButtonDown(joystick) => { + consumer.event(world, EngineEvent::JoystickButtonDown(joystick))? + } + Event::JoystickButtonUp(joystick) => { + consumer.event(world, EngineEvent::JoystickButtonUp(joystick))? + } + Event::JoystickAdded(joystick) => { + consumer.event(world, EngineEvent::JoystickAdded(joystick))? + } + Event::JoystickRemoved(joystick) => { + consumer.event(world, EngineEvent::JoystickRemoved(joystick))? + } Event::FileDrop(filename) => consumer.event(world, EngineEvent::FileDrop(filename))?, } @@ -192,9 +207,10 @@ impl Engine { fn button_up_event( world: &mut World, consumer: &mut T, + controller: &Controller, button: ControllerButton, ) -> Result<()> { - consumer.event(world, EngineEvent::ButtonUp(button))?; + consumer.event(world, EngineEvent::ControllerButtonUp(controller, button))?; Ok(()) } @@ -204,12 +220,13 @@ impl Engine { world: &mut World, gui_handler: &GuiHandler, consumer: &mut T, + controller: &Controller, button: ControllerButton, ) -> Result<()> { if gui_handler.check_navigatable()? { - Self::check_button_down(world, gui_handler, consumer, button)?; + Self::check_button_down(world, gui_handler, consumer, controller, button)?; } else { - consumer.event(world, EngineEvent::ButtonDown(button))?; + consumer.event(world, EngineEvent::ControllerButtonDown(controller, button))?; } Ok(()) @@ -223,7 +240,7 @@ impl Engine { ) -> Result<()> { consumer.event( world, - EngineEvent::ControllerAxis(controller.controller_axis()), + EngineEvent::ControllerAxis(controller, controller.controller_axis()), )?; Ok(()) @@ -234,6 +251,7 @@ impl Engine { world: &mut World, gui_handler: &GuiHandler, consumer: &mut T, + controller: &Controller, button: ControllerButton, ) -> Result<()> { match button { @@ -313,7 +331,7 @@ impl Engine { } if !gui_handler.accept_custom_selection(button)? { - consumer.event(world, EngineEvent::ButtonDown(button))?; + consumer.event(world, EngineEvent::ControllerButtonDown(controller, button))?; } Ok(()) diff --git a/examples/simple_window/src/main.rs b/examples/simple_window/src/main.rs index 5e949b8..911ed58 100644 --- a/examples/simple_window/src/main.rs +++ b/examples/simple_window/src/main.rs @@ -14,8 +14,8 @@ fn main() -> Result<()> { world_builder.add_system(GameState::update); world_builder.resources.insert(GameState::Startup); - let dir = Path::new("C:/Users/M.Huebner/Downloads/Space Skybox Generator/Export"); - // let dir = Path::new("/home/michaelh/Sync/skybox"); + // let dir = Path::new("C:/Users/M.Huebner/Downloads/Space Skybox Generator/Export"); + let dir = Path::new("/home/michaelh/Sync/skybox"); SkyBox::new( &mut world_builder, [ diff --git a/presentation/src/input/eventsystem.rs b/presentation/src/input/eventsystem.rs index f00f1c4..9ab2187 100644 --- a/presentation/src/input/eventsystem.rs +++ b/presentation/src/input/eventsystem.rs @@ -362,6 +362,10 @@ impl EventSystem { pub fn controllers(&self) -> impl Iterator { self.connected_controllers.values() } + + pub fn joysticks(&self) -> impl Iterator { + self.connected_joysticks.values() + } } unsafe impl Send for EventSystem {} diff --git a/presentation/src/prelude.rs b/presentation/src/prelude.rs index 5374ff4..4291c32 100644 --- a/presentation/src/prelude.rs +++ b/presentation/src/prelude.rs @@ -1,6 +1,6 @@ pub use crate::traits::*; -pub use crate::{create_render_core, RenderCoreCreateInfo}; +pub use crate::{RenderCoreCreateInfo, create_render_core}; pub use crate::presentationcore::{ApplicationInfo, PresentationBackend, PresentationCore, VRMode}; @@ -10,6 +10,7 @@ pub use crate::renderbackend::{Eye, VRTransformations}; pub use crate::input::{ controller::{Controller, ControllerDeadzones}, controlleraxis::ControllerAxis, + joystick::Joystick, }; // wsi