From 995138ddc916fe5b044591271c237923bb37ee10 Mon Sep 17 00:00:00 2001 From: awtterpip Date: Wed, 27 Dec 2023 20:33:25 -0600 Subject: [PATCH] changed path id --- xr_api/src/api_traits.rs | 12 +++++------ xr_api/src/types.rs | 45 ++++++++++++++++++++++++++++------------ 2 files changed, 38 insertions(+), 19 deletions(-) diff --git a/xr_api/src/api_traits.rs b/xr_api/src/api_traits.rs index 95ac71b..63ef9e8 100644 --- a/xr_api/src/api_traits.rs +++ b/xr_api/src/api_traits.rs @@ -43,25 +43,25 @@ pub trait ViewTrait { pub trait InputTrait { /// Get the haptic action at the specified path. - fn get_haptics(&self, path: ActionId) -> Result>; + fn get_haptics(&self, path: ActionPath) -> Result>; /// Get the pose action at the specified path. - fn get_pose(&self, path: ActionId) -> Result>; + fn get_pose(&self, path: ActionPath) -> Result>; /// Get the float action at the specified path. - fn get_float(&self, path: ActionId) -> Result>; + fn get_float(&self, path: ActionPath) -> Result>; /// Get the boolean action at the specified path. - fn get_bool(&self, path: ActionId) -> Result>; + fn get_bool(&self, path: ActionPath) -> Result>; } // This impl is moved outside of the trait to ensure that InputTrait stays object safe. impl dyn InputTrait { /// Get the action at the specified path. - pub fn get_action(&self, path: ActionId) -> Result> { + pub fn get_action(&self, path: ActionPath) -> Result> { A::get(self, path) } } pub trait ActionTrait { - fn id(&self) -> ActionId; + fn id(&self) -> ActionPath; } /// Represents input actions, such as bools, floats, and poses diff --git a/xr_api/src/types.rs b/xr_api/src/types.rs index 6fdac87..219d651 100644 --- a/xr_api/src/types.rs +++ b/xr_api/src/types.rs @@ -13,9 +13,33 @@ pub struct Bindings {} /// THIS IS NOT COMPLETE, im not sure how i am going to index actions currently. #[derive(Clone, Copy, PartialEq)] -pub struct ActionId { - pub handedness: Handedness, - pub device: XrDevice, +pub struct ActionPath { + pub device: DevicePath, + pub subpath: SubPath, +} + +#[derive(Clone, Copy, PartialEq)] +pub enum DevicePath { + LeftHand, + RightHand, + Head, + Gamepad, + Treadmill, +} + +#[derive(Clone, Copy, PartialEq)] +pub enum SubPath { + A, + B, + X, + Y, + Start, + Home, + End, + Select, + Joystick, + Trigger, + Squeeze, } #[derive(Clone, Copy, PartialEq)] @@ -25,24 +49,19 @@ pub enum Handedness { None, } -#[derive(Clone, Copy, PartialEq)] -pub enum XrDevice { - Controller, -} - pub struct Haptic; pub struct Pose; pub trait ActionType: Sized { type Inner: ?Sized; - fn get(input: &dyn InputTrait, path: ActionId) -> Result>; + fn get(input: &dyn InputTrait, path: ActionPath) -> Result>; } impl ActionType for Haptic { type Inner = dyn HapticTrait; - fn get(input: &dyn InputTrait, path: ActionId) -> Result> { + fn get(input: &dyn InputTrait, path: ActionPath) -> Result> { input.get_haptics(path) } } @@ -50,7 +69,7 @@ impl ActionType for Haptic { impl ActionType for Pose { type Inner = dyn ActionInputTrait; - fn get(input: &dyn InputTrait, path: ActionId) -> Result> { + fn get(input: &dyn InputTrait, path: ActionPath) -> Result> { input.get_pose(path) } } @@ -58,7 +77,7 @@ impl ActionType for Pose { impl ActionType for f32 { type Inner = dyn ActionInputTrait; - fn get(input: &dyn InputTrait, path: ActionId) -> Result> { + fn get(input: &dyn InputTrait, path: ActionPath) -> Result> { input.get_float(path) } } @@ -66,7 +85,7 @@ impl ActionType for f32 { impl ActionType for bool { type Inner = dyn ActionInputTrait; - fn get(input: &dyn InputTrait, path: ActionId) -> Result> { + fn get(input: &dyn InputTrait, path: ActionPath) -> Result> { input.get_bool(path) } }