Fix example
This commit is contained in:
parent
b0462d7377
commit
06a64c81b7
6 changed files with 54 additions and 29 deletions
|
@ -72,6 +72,7 @@ impl Context {
|
||||||
) {
|
) {
|
||||||
Ok(res) => {
|
Ok(res) => {
|
||||||
if !res {
|
if !res {
|
||||||
|
self.device().wait_idle()?;
|
||||||
return Ok(false);
|
return Ok(false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -119,6 +120,10 @@ impl Context {
|
||||||
pub fn controllers(&self) -> impl Iterator<Item = &Controller> {
|
pub fn controllers(&self) -> impl Iterator<Item = &Controller> {
|
||||||
self.presentation.event_system().controllers()
|
self.presentation.event_system().controllers()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn joysticks(&self) -> impl Iterator<Item = &Joystick> {
|
||||||
|
self.presentation.event_system().joysticks()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl std::fmt::Debug for Context {
|
impl std::fmt::Debug for Context {
|
||||||
|
|
|
@ -175,18 +175,14 @@ impl Engine {
|
||||||
let asset_manager = AssetManager::new(&engine_settings)?;
|
let asset_manager = AssetManager::new(&engine_settings)?;
|
||||||
let gui_handler = GuiHandler::new(create_info.gui_info, &context)?;
|
let gui_handler = GuiHandler::new(create_info.gui_info, &context)?;
|
||||||
|
|
||||||
let engine = Engine {
|
|
||||||
resource_base_path: create_info.resource_base_path,
|
|
||||||
};
|
|
||||||
|
|
||||||
context
|
context
|
||||||
.render_core_mut()
|
.render_core_mut()
|
||||||
.add_render_routine::<GuiHandlerRenderer>(10_000_000);
|
.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);
|
world.resources.insert(context);
|
||||||
|
|
||||||
let scene = Scene::new(
|
Scene::new(
|
||||||
create_info.rasterizer_info,
|
create_info.rasterizer_info,
|
||||||
create_info.raytracing_info,
|
create_info.raytracing_info,
|
||||||
create_info.graphics_info,
|
create_info.graphics_info,
|
||||||
|
@ -204,9 +200,10 @@ impl Engine {
|
||||||
world.resources.insert(GuiHandlerRenderer);
|
world.resources.insert(GuiHandlerRenderer);
|
||||||
world.resources.insert(InputMap { direction_mapping });
|
world.resources.insert(InputMap { direction_mapping });
|
||||||
world.resources.insert(asset_manager);
|
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(engine_settings);
|
||||||
world.resources.insert(scene);
|
|
||||||
|
|
||||||
world.add_system(Self::main_system::<T>);
|
world.add_system(Self::main_system::<T>);
|
||||||
|
|
||||||
|
|
|
@ -12,13 +12,18 @@ pub enum EngineEvent<'a> {
|
||||||
KeyDown(Keycode),
|
KeyDown(Keycode),
|
||||||
KeyUp(Keycode),
|
KeyUp(Keycode),
|
||||||
|
|
||||||
ButtonDown(ControllerButton),
|
ControllerButtonDown(&'a Controller, ControllerButton),
|
||||||
ButtonUp(ControllerButton),
|
ControllerButtonUp(&'a Controller, ControllerButton),
|
||||||
ControllerAxis(ControllerAxis),
|
ControllerAxis(&'a Controller, ControllerAxis),
|
||||||
|
|
||||||
ControllerAdded(&'a Controller),
|
ControllerAdded(&'a Controller),
|
||||||
ControllerRemoved(&'a Controller),
|
ControllerRemoved(&'a Controller),
|
||||||
|
|
||||||
|
JoystickButtonDown(&'a Joystick),
|
||||||
|
JoystickButtonUp(&'a Joystick),
|
||||||
|
JoystickAxis(&'a Joystick),
|
||||||
|
JoystickAdded(&'a Joystick),
|
||||||
|
JoystickRemoved(&'a Joystick),
|
||||||
|
|
||||||
FileDrop(String),
|
FileDrop(String),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -66,11 +71,11 @@ impl Engine {
|
||||||
Event::TextInput(text) => {
|
Event::TextInput(text) => {
|
||||||
Self::text_input(gui_handler, text)?;
|
Self::text_input(gui_handler, text)?;
|
||||||
}
|
}
|
||||||
Event::ControllerButtonDown(_controller, button) => {
|
Event::ControllerButtonDown(controller, button) => {
|
||||||
Self::button_down_event(world, gui_handler, consumer, button)?;
|
Self::button_down_event(world, gui_handler, consumer, controller, button)?;
|
||||||
}
|
}
|
||||||
Event::ControllerButtonUp(_controller, button) => {
|
Event::ControllerButtonUp(controller, button) => {
|
||||||
Self::button_up_event(world, consumer, button)?;
|
Self::button_up_event(world, consumer, controller, button)?;
|
||||||
}
|
}
|
||||||
Event::ControllerAxis(controller) => {
|
Event::ControllerAxis(controller) => {
|
||||||
if !gui_handler.check_navigatable()? {
|
if !gui_handler.check_navigatable()? {
|
||||||
|
@ -86,11 +91,21 @@ impl Engine {
|
||||||
Self::controller_removed(world, consumer, controller)?
|
Self::controller_removed(world, consumer, controller)?
|
||||||
}
|
}
|
||||||
|
|
||||||
Event::JoystickAxis(_joystick) => todo!(),
|
Event::JoystickAxis(joystick) => {
|
||||||
Event::JoystickButtonDown(_joystick) => todo!(),
|
consumer.event(world, EngineEvent::JoystickAxis(joystick))?
|
||||||
Event::JoystickButtonUp(_joystick) => todo!(),
|
}
|
||||||
Event::JoystickAdded(_joystick) => todo!(),
|
Event::JoystickButtonDown(joystick) => {
|
||||||
Event::JoystickRemoved(_joystick) => todo!(),
|
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))?,
|
Event::FileDrop(filename) => consumer.event(world, EngineEvent::FileDrop(filename))?,
|
||||||
}
|
}
|
||||||
|
@ -192,9 +207,10 @@ impl Engine {
|
||||||
fn button_up_event<T: EventConsumer>(
|
fn button_up_event<T: EventConsumer>(
|
||||||
world: &mut World,
|
world: &mut World,
|
||||||
consumer: &mut T,
|
consumer: &mut T,
|
||||||
|
controller: &Controller,
|
||||||
button: ControllerButton,
|
button: ControllerButton,
|
||||||
) -> Result<()> {
|
) -> Result<()> {
|
||||||
consumer.event(world, EngineEvent::ButtonUp(button))?;
|
consumer.event(world, EngineEvent::ControllerButtonUp(controller, button))?;
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
@ -204,12 +220,13 @@ impl Engine {
|
||||||
world: &mut World,
|
world: &mut World,
|
||||||
gui_handler: &GuiHandler,
|
gui_handler: &GuiHandler,
|
||||||
consumer: &mut T,
|
consumer: &mut T,
|
||||||
|
controller: &Controller,
|
||||||
button: ControllerButton,
|
button: ControllerButton,
|
||||||
) -> Result<()> {
|
) -> Result<()> {
|
||||||
if gui_handler.check_navigatable()? {
|
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 {
|
} else {
|
||||||
consumer.event(world, EngineEvent::ButtonDown(button))?;
|
consumer.event(world, EngineEvent::ControllerButtonDown(controller, button))?;
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
|
@ -223,7 +240,7 @@ impl Engine {
|
||||||
) -> Result<()> {
|
) -> Result<()> {
|
||||||
consumer.event(
|
consumer.event(
|
||||||
world,
|
world,
|
||||||
EngineEvent::ControllerAxis(controller.controller_axis()),
|
EngineEvent::ControllerAxis(controller, controller.controller_axis()),
|
||||||
)?;
|
)?;
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
|
@ -234,6 +251,7 @@ impl Engine {
|
||||||
world: &mut World,
|
world: &mut World,
|
||||||
gui_handler: &GuiHandler,
|
gui_handler: &GuiHandler,
|
||||||
consumer: &mut T,
|
consumer: &mut T,
|
||||||
|
controller: &Controller,
|
||||||
button: ControllerButton,
|
button: ControllerButton,
|
||||||
) -> Result<()> {
|
) -> Result<()> {
|
||||||
match button {
|
match button {
|
||||||
|
@ -313,7 +331,7 @@ impl Engine {
|
||||||
}
|
}
|
||||||
|
|
||||||
if !gui_handler.accept_custom_selection(button)? {
|
if !gui_handler.accept_custom_selection(button)? {
|
||||||
consumer.event(world, EngineEvent::ButtonDown(button))?;
|
consumer.event(world, EngineEvent::ControllerButtonDown(controller, button))?;
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
|
|
|
@ -14,8 +14,8 @@ fn main() -> Result<()> {
|
||||||
world_builder.add_system(GameState::update);
|
world_builder.add_system(GameState::update);
|
||||||
world_builder.resources.insert(GameState::Startup);
|
world_builder.resources.insert(GameState::Startup);
|
||||||
|
|
||||||
let dir = Path::new("C:/Users/M.Huebner/Downloads/Space Skybox Generator/Export");
|
// 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("/home/michaelh/Sync/skybox");
|
||||||
SkyBox::new(
|
SkyBox::new(
|
||||||
&mut world_builder,
|
&mut world_builder,
|
||||||
[
|
[
|
||||||
|
|
|
@ -362,6 +362,10 @@ impl EventSystem {
|
||||||
pub fn controllers(&self) -> impl Iterator<Item = &Controller> {
|
pub fn controllers(&self) -> impl Iterator<Item = &Controller> {
|
||||||
self.connected_controllers.values()
|
self.connected_controllers.values()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn joysticks(&self) -> impl Iterator<Item = &Joystick> {
|
||||||
|
self.connected_joysticks.values()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
unsafe impl Send for EventSystem {}
|
unsafe impl Send for EventSystem {}
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
pub use crate::traits::*;
|
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};
|
pub use crate::presentationcore::{ApplicationInfo, PresentationBackend, PresentationCore, VRMode};
|
||||||
|
|
||||||
|
@ -10,6 +10,7 @@ pub use crate::renderbackend::{Eye, VRTransformations};
|
||||||
pub use crate::input::{
|
pub use crate::input::{
|
||||||
controller::{Controller, ControllerDeadzones},
|
controller::{Controller, ControllerDeadzones},
|
||||||
controlleraxis::ControllerAxis,
|
controlleraxis::ControllerAxis,
|
||||||
|
joystick::Joystick,
|
||||||
};
|
};
|
||||||
|
|
||||||
// wsi
|
// wsi
|
||||||
|
|
Loading…
Reference in a new issue