changed path id

This commit is contained in:
awtterpip
2023-12-27 20:33:25 -06:00
parent e615249ed3
commit 995138ddc9
2 changed files with 38 additions and 19 deletions

View File

@@ -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<Action<Haptic>>;
fn get_haptics(&self, path: ActionPath) -> Result<Action<Haptic>>;
/// Get the pose action at the specified path.
fn get_pose(&self, path: ActionId) -> Result<Action<Pose>>;
fn get_pose(&self, path: ActionPath) -> Result<Action<Pose>>;
/// Get the float action at the specified path.
fn get_float(&self, path: ActionId) -> Result<Action<f32>>;
fn get_float(&self, path: ActionPath) -> Result<Action<f32>>;
/// Get the boolean action at the specified path.
fn get_bool(&self, path: ActionId) -> Result<Action<bool>>;
fn get_bool(&self, path: ActionPath) -> Result<Action<bool>>;
}
// 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<A: ActionType>(&self, path: ActionId) -> Result<Action<A>> {
pub fn get_action<A: ActionType>(&self, path: ActionPath) -> Result<Action<A>> {
A::get(self, path)
}
}
pub trait ActionTrait {
fn id(&self) -> ActionId;
fn id(&self) -> ActionPath;
}
/// Represents input actions, such as bools, floats, and poses

View File

@@ -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<Action<Self>>;
fn get(input: &dyn InputTrait, path: ActionPath) -> Result<Action<Self>>;
}
impl ActionType for Haptic {
type Inner = dyn HapticTrait;
fn get(input: &dyn InputTrait, path: ActionId) -> Result<Action<Self>> {
fn get(input: &dyn InputTrait, path: ActionPath) -> Result<Action<Self>> {
input.get_haptics(path)
}
}
@@ -50,7 +69,7 @@ impl ActionType for Haptic {
impl ActionType for Pose {
type Inner = dyn ActionInputTrait<Pose>;
fn get(input: &dyn InputTrait, path: ActionId) -> Result<Action<Self>> {
fn get(input: &dyn InputTrait, path: ActionPath) -> Result<Action<Self>> {
input.get_pose(path)
}
}
@@ -58,7 +77,7 @@ impl ActionType for Pose {
impl ActionType for f32 {
type Inner = dyn ActionInputTrait<f32>;
fn get(input: &dyn InputTrait, path: ActionId) -> Result<Action<Self>> {
fn get(input: &dyn InputTrait, path: ActionPath) -> Result<Action<Self>> {
input.get_float(path)
}
}
@@ -66,7 +85,7 @@ impl ActionType for f32 {
impl ActionType for bool {
type Inner = dyn ActionInputTrait<bool>;
fn get(input: &dyn InputTrait, path: ActionId) -> Result<Action<Self>> {
fn get(input: &dyn InputTrait, path: ActionPath) -> Result<Action<Self>> {
input.get_bool(path)
}
}