Fix example

This commit is contained in:
hodasemi 2025-03-03 17:51:24 +01:00
parent b0462d7377
commit 06a64c81b7
6 changed files with 54 additions and 29 deletions

View file

@ -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<Item = &Controller> {
self.presentation.event_system().controllers()
}
pub fn joysticks(&self) -> impl Iterator<Item = &Joystick> {
self.presentation.event_system().joysticks()
}
}
impl std::fmt::Debug for Context {

View file

@ -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::<GuiHandlerRenderer>(10_000_000);
// context.render_core_mut().add_render_routine::<Scene>(100);
context.render_core_mut().add_render_routine::<Scene>(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::<T>);

View file

@ -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<T: EventConsumer>(
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(())

View file

@ -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,
[

View file

@ -362,6 +362,10 @@ impl EventSystem {
pub fn controllers(&self) -> impl Iterator<Item = &Controller> {
self.connected_controllers.values()
}
pub fn joysticks(&self) -> impl Iterator<Item = &Joystick> {
self.connected_joysticks.values()
}
}
unsafe impl Send for EventSystem {}

View file

@ -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