diff --git a/src/xr_init.rs b/src/xr_init.rs index 777d777..945fd77 100644 --- a/src/xr_init.rs +++ b/src/xr_init.rs @@ -8,17 +8,14 @@ use bevy::{ prelude::*, render::{ extract_resource::{ExtractResource, ExtractResourcePlugin}, - renderer::{ - self, RenderAdapter, RenderAdapterInfo, RenderDevice, RenderInstance, RenderQueue, - }, + renderer::{self, RenderAdapter, RenderAdapterInfo, RenderDevice, RenderQueue}, settings::WgpuSettings, }, - window::{PrimaryWindow, RawHandleWrapper}, + window::RawHandleWrapper, }; use wgpu::Instance; use crate::{ - graphics, input::XrInput, resources::{ XrEnvironmentBlendMode, XrFormat, XrFrameState, XrFrameWaiter, XrInstance, XrResolution, @@ -107,9 +104,7 @@ impl Plugin for RenderRestartPlugin { .insert_resource(ForceMain) .add_event::() .add_event::() - .add_systems(PreStartup, xr_presetup.run_if(xr_only())) - .add_systems(Startup, xr_setup.run_if(xr_only())) - .add_systems(PostStartup, xr_postsetup.run_if(xr_only())) + .add_systems(PostStartup, setup_xr.run_if(xr_only())) .add_systems( PostUpdate, update_xr_stuff.run_if(on_event::()), @@ -154,17 +149,6 @@ fn add_schedules(app: &mut App) { } } -fn xr_presetup(world: &mut World) { - world.run_schedule(XrPreSetup); -} -fn xr_setup(world: &mut World) { - world.run_schedule(XrSetup); -} -fn xr_postsetup(world: &mut World) { - world.run_schedule(XrPrePostSetup); - world.run_schedule(XrPostSetup); -} - fn setup_xr(world: &mut World) { world.run_schedule(XrPreSetup); world.run_schedule(XrSetup); diff --git a/src/xr_input/actions.rs b/src/xr_input/actions.rs index 827464a..10a0914 100644 --- a/src/xr_input/actions.rs +++ b/src/xr_input/actions.rs @@ -35,40 +35,40 @@ pub fn setup_oxr_actions(world: &mut World) { while let Some((set_name, set)) = a_iter.next() { let mut actions: HashMap<&'static str, TypedAction> = default(); let oxr_action_set = instance - .create_action_set(set_name, set.pretty_name, set.priority) + .create_action_set(set_name, &set.pretty_name, set.priority) .expect("Unable to create action set"); for (action_name, action) in set.actions.into_iter() { let typed_action = match action.action_type { ActionType::F32 => TypedAction::F32(match action.handednes { ActionHandednes::Single => oxr_action_set - .create_action(action_name, action.pretty_name, &[]) + .create_action(action_name, &action.pretty_name, &[]) .expect(&format!("Unable to create action: {}", action_name)), ActionHandednes::Double => oxr_action_set - .create_action(action_name, action.pretty_name, &hands) + .create_action(action_name, &action.pretty_name, &hands) .expect(&format!("Unable to create action: {}", action_name)), }), ActionType::Bool => TypedAction::Bool(match action.handednes { ActionHandednes::Single => oxr_action_set - .create_action(action_name, action.pretty_name, &[]) + .create_action(action_name, &action.pretty_name, &[]) .expect(&format!("Unable to create action: {}", action_name)), ActionHandednes::Double => oxr_action_set - .create_action(action_name, action.pretty_name, &hands) + .create_action(action_name, &action.pretty_name, &hands) .expect(&format!("Unable to create action: {}", action_name)), }), ActionType::PoseF => TypedAction::PoseF(match action.handednes { ActionHandednes::Single => oxr_action_set - .create_action(action_name, action.pretty_name, &[]) + .create_action(action_name, &action.pretty_name, &[]) .expect(&format!("Unable to create action: {}", action_name)), ActionHandednes::Double => oxr_action_set - .create_action(action_name, action.pretty_name, &hands) + .create_action(action_name, &action.pretty_name, &hands) .expect(&format!("Unable to create action: {}", action_name)), }), ActionType::Haptic => TypedAction::Haptic(match action.handednes { ActionHandednes::Single => oxr_action_set - .create_action(action_name, action.pretty_name, &[]) + .create_action(action_name, &action.pretty_name, &[]) .expect(&format!("Unable to create action: {}", action_name)), ActionHandednes::Double => oxr_action_set - .create_action(action_name, action.pretty_name, &hands) + .create_action(action_name, &action.pretty_name, &hands) .expect(&format!("Unable to create action: {}", action_name)), }), }; @@ -149,6 +149,7 @@ pub enum ActionHandednes { Double, } +#[derive(Clone, Copy)] pub enum ActionType { F32, Bool, @@ -164,14 +165,14 @@ pub enum TypedAction { } pub struct SetupAction { - pretty_name: &'static str, + pretty_name: String, action_type: ActionType, handednes: ActionHandednes, bindings: HashMap<&'static str, Vec<&'static str>>, } pub struct SetupActionSet { - pretty_name: &'static str, + pretty_name: String, priority: u32, actions: HashMap<&'static str, SetupAction>, } @@ -180,7 +181,7 @@ impl SetupActionSet { pub fn new_action( &mut self, name: &'static str, - pretty_name: &'static str, + pretty_name: String, action_type: ActionType, handednes: ActionHandednes, ) { @@ -230,7 +231,7 @@ impl SetupActionSets { pub fn add_action_set( &mut self, name: &'static str, - pretty_name: &'static str, + pretty_name: String, priority: u32, ) -> &mut SetupActionSet { self.sets.insert( diff --git a/src/xr_input/hands/emulated.rs b/src/xr_input/hands/emulated.rs index a3423d2..ab1e627 100644 --- a/src/xr_input/hands/emulated.rs +++ b/src/xr_input/hands/emulated.rs @@ -5,8 +5,8 @@ use openxr::{ActionTy, HandJoint}; use super::common::{get_bone_gizmo_style, HandBoneRadius}; use crate::{ - xr_init::{xr_only, XrSetup}, resources::{XrInstance, XrSession}, + xr_init::{xr_only, XrSetup}, xr_input::{ actions::{ ActionHandednes, ActionType, SetupActionSet, SetupActionSets, XrActionSets, XrBinding, @@ -28,10 +28,7 @@ pub struct HandEmulationPlugin; impl Plugin for HandEmulationPlugin { fn build(&self, app: &mut App) { - app.add_systems( - Update, - update_hand_skeleton_from_emulated.run_if(xr_only()), - ); + app.add_systems(Update, update_hand_skeleton_from_emulated.run_if(xr_only())); app.add_systems(XrSetup, setup_hand_emulation_action_set); } } @@ -39,54 +36,55 @@ impl Plugin for HandEmulationPlugin { const HAND_ACTION_SET: &str = "hand_pose_approx"; fn setup_hand_emulation_action_set(mut action_sets: ResMut) { - let mut action_set = action_sets.add_action_set(HAND_ACTION_SET, "Hand Pose Approximaiton", 0); + let action_set = + action_sets.add_action_set(HAND_ACTION_SET, "Hand Pose Approximaiton".into(), 0); action_set.new_action( "thumb_touch", - "Thumb Touched", + "Thumb Touched".into(), ActionType::Bool, ActionHandednes::Double, ); action_set.new_action( "thumb_x", - "Thumb X", + "Thumb X".into(), ActionType::F32, ActionHandednes::Double, ); action_set.new_action( "thumb_y", - "Thumb Y", + "Thumb Y".into(), ActionType::F32, ActionHandednes::Double, ); action_set.new_action( "index_touch", - "Index Finger Touched", + "Index Finger Touched".into(), ActionType::Bool, ActionHandednes::Double, ); action_set.new_action( "index_value", - "Index Finger Pull", + "Index Finger Pull".into(), ActionType::F32, ActionHandednes::Double, ); action_set.new_action( "middle_value", - "Middle Finger Pull", + "Middle Finger Pull".into(), ActionType::F32, ActionHandednes::Double, ); action_set.new_action( "ring_value", - "Ring Finger Pull", + "Ring Finger Pull".into(), ActionType::F32, ActionHandednes::Double, ); action_set.new_action( "little_value", - "Little Finger Pull", + "Little Finger Pull".into(), ActionType::F32, ActionHandednes::Double, ); @@ -126,6 +124,7 @@ fn suggest_oculus_touch_profile(action_set: &mut SetupActionSet) { ); } +#[allow(clippy::type_complexity)] pub(crate) fn update_hand_skeleton_from_emulated( session: Res, instance: Res, @@ -546,5 +545,6 @@ fn get_bone_curl_angle(bone: HandJoint, curl: f32) -> f32 { _ => 1.0, }; let curl_angle = -((mul * curl * 80.0) + 5.0); + #[allow(clippy::needless_return)] return curl_angle; } diff --git a/src/xr_input/oculus_touch.rs b/src/xr_input/oculus_touch.rs index abd501f..6d416bb 100644 --- a/src/xr_input/oculus_touch.rs +++ b/src/xr_input/oculus_touch.rs @@ -305,124 +305,124 @@ pub struct OculusController { impl OculusController { pub fn new(mut action_sets: ResMut) -> anyhow::Result { let action_set = - action_sets.add_action_set("oculus_input", "Oculus Touch Controller Input", 0); + action_sets.add_action_set("oculus_input", "Oculus Touch Controller Input".into(), 0); action_set.new_action( "hand_pose", - "Hand Pose", + "Hand Pose".into(), ActionType::PoseF, ActionHandednes::Double, ); action_set.new_action( "pointer_pose", - "Pointer Pose", + "Pointer Pose".into(), ActionType::PoseF, ActionHandednes::Double, ); action_set.new_action( "squeeze", - "Grip Pull", + "Grip Pull".into(), ActionType::F32, ActionHandednes::Double, ); action_set.new_action( "trigger", - "Trigger Pull", + "Trigger Pull".into(), ActionType::F32, ActionHandednes::Double, ); action_set.new_action( "trigger_touched", - "Trigger Touch", + "Trigger Touch".into(), ActionType::Bool, ActionHandednes::Double, ); action_set.new_action( "haptic_feedback", - "Haptic Feedback", + "Haptic Feedback".into(), ActionType::Haptic, ActionHandednes::Double, ); action_set.new_action( "x_button", - "X Button", + "X Button".into(), ActionType::Bool, ActionHandednes::Single, ); action_set.new_action( "x_button_touch", - "X Button Touch", + "X Button Touch".into(), ActionType::Bool, ActionHandednes::Single, ); action_set.new_action( "y_button", - "Y Button", + "Y Button".into(), ActionType::Bool, ActionHandednes::Single, ); action_set.new_action( "y_button_touch", - "Y Button Touch", + "Y Button Touch".into(), ActionType::Bool, ActionHandednes::Single, ); action_set.new_action( "a_button", - "A Button", + "A Button".into(), ActionType::Bool, ActionHandednes::Single, ); action_set.new_action( "a_button_touch", - "A Button Touch", + "A Button Touch".into(), ActionType::Bool, ActionHandednes::Single, ); action_set.new_action( "b_button", - "B Button", + "B Button".into(), ActionType::Bool, ActionHandednes::Single, ); action_set.new_action( "b_button_touch", - "B Button Touch", + "B Button Touch".into(), ActionType::Bool, ActionHandednes::Single, ); action_set.new_action( "menu_button", - "Menu Button", + "Menu Button".into(), ActionType::Bool, ActionHandednes::Single, ); action_set.new_action( "thumbstick_x", - "Thumbstick X", + "Thumbstick X".into(), ActionType::F32, ActionHandednes::Double, ); action_set.new_action( "thumbstick_y", - "Thumbstick y", + "Thumbstick y".into(), ActionType::F32, ActionHandednes::Double, ); action_set.new_action( "thumbstick_touch", - "Thumbstick Touch", + "Thumbstick Touch".into(), ActionType::Bool, ActionHandednes::Double, ); action_set.new_action( "thumbstick_click", - "Thumbstick Click", + "Thumbstick Click".into(), ActionType::Bool, ActionHandednes::Double, ); action_set.new_action( "thumbrest_touch", - "Thumbrest Touch", + "Thumbrest Touch".into(), ActionType::Bool, ActionHandednes::Double, );