path changes
This commit is contained in:
@@ -3,7 +3,7 @@ use wgpu::{Adapter, AdapterInfo, Device, Queue, TextureView};
|
|||||||
|
|
||||||
use crate::prelude::*;
|
use crate::prelude::*;
|
||||||
|
|
||||||
use self::path::{InputComponent, UntypedActionPath};
|
use crate::path::{InputComponent, UntypedActionPath};
|
||||||
|
|
||||||
pub trait EntryTrait {
|
pub trait EntryTrait {
|
||||||
/// Return currently available extensions
|
/// Return currently available extensions
|
||||||
@@ -54,15 +54,15 @@ pub trait ViewTrait {
|
|||||||
|
|
||||||
pub trait InputTrait {
|
pub trait InputTrait {
|
||||||
/// Get the haptic action at the specified path.
|
/// Get the haptic action at the specified path.
|
||||||
fn create_action_haptics(&self, name: &str, path: UntypedActionPath) -> Result<Action<Haptic>>;
|
fn create_action_haptics(&self, path: UntypedActionPath) -> Result<Action<Haptic>>;
|
||||||
/// Get the pose action at the specified path.
|
/// Get the pose action at the specified path.
|
||||||
fn create_action_pose(&self, name: &str, path: UntypedActionPath) -> Result<Action<Pose>>;
|
fn create_action_pose(&self, path: UntypedActionPath) -> Result<Action<Pose>>;
|
||||||
/// Get the float action at the specified path.
|
/// Get the float action at the specified path.
|
||||||
fn create_action_float(&self, name: &str, path: UntypedActionPath) -> Result<Action<f32>>;
|
fn create_action_float(&self, path: UntypedActionPath) -> Result<Action<f32>>;
|
||||||
/// Get the boolean action at the specified path.
|
/// Get the boolean action at the specified path.
|
||||||
fn create_action_bool(&self, name: &str, path: UntypedActionPath) -> Result<Action<bool>>;
|
fn create_action_bool(&self, path: UntypedActionPath) -> Result<Action<bool>>;
|
||||||
/// Get the Vec2 action at the specified path.
|
/// Get the Vec2 action at the specified path.
|
||||||
fn create_action_vec2(&self, name: &str, path: UntypedActionPath) -> Result<Action<Vec2>>;
|
fn create_action_vec2(&self, path: UntypedActionPath) -> Result<Action<Vec2>>;
|
||||||
}
|
}
|
||||||
|
|
||||||
// This impl is moved outside of the trait to ensure that InputTrait stays object safe.
|
// This impl is moved outside of the trait to ensure that InputTrait stays object safe.
|
||||||
@@ -70,10 +70,9 @@ impl dyn InputTrait {
|
|||||||
/// Get the action at the specified path.
|
/// Get the action at the specified path.
|
||||||
pub fn create_action<P: InputComponent>(
|
pub fn create_action<P: InputComponent>(
|
||||||
&self,
|
&self,
|
||||||
name: &str,
|
|
||||||
path: ActionPath<P>,
|
path: ActionPath<P>,
|
||||||
) -> Result<Action<P::PathType>> {
|
) -> Result<Action<P::PathType>> {
|
||||||
P::PathType::get(self, name, path.untyped())
|
P::PathType::get(self, path.untyped())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -8,7 +8,7 @@ use hashbrown::{hash_map, HashMap};
|
|||||||
use openxr::{EnvironmentBlendMode, Vector2f};
|
use openxr::{EnvironmentBlendMode, Vector2f};
|
||||||
use tracing::{info, info_span, warn};
|
use tracing::{info, info_span, warn};
|
||||||
|
|
||||||
use crate::{backend::oxr::graphics::VIEW_TYPE, prelude::*};
|
use crate::{backend::oxr::graphics::VIEW_TYPE, path, prelude::*};
|
||||||
|
|
||||||
pub struct OXrEntry(openxr::Entry);
|
pub struct OXrEntry(openxr::Entry);
|
||||||
|
|
||||||
@@ -155,10 +155,49 @@ impl SessionTrait for OXrSession {
|
|||||||
{
|
{
|
||||||
let mut bindings = self.bindings.lock().unwrap();
|
let mut bindings = self.bindings.lock().unwrap();
|
||||||
if !bindings.sessions_attached {
|
if !bindings.sessions_attached {
|
||||||
|
if let Some(interaction_profile) = bindings.bindings {
|
||||||
let _span = info_span!("xr_attach_actions");
|
let _span = info_span!("xr_attach_actions");
|
||||||
|
let controller_bindings: Vec<openxr::Binding> = bindings
|
||||||
|
.map
|
||||||
|
.iter()
|
||||||
|
.filter_map(|(path, action)| {
|
||||||
|
let path = match self.inner_instance.string_to_path(path) {
|
||||||
|
Ok(path) => path,
|
||||||
|
Err(e) => {
|
||||||
|
warn!("{e}");
|
||||||
|
return None;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
Some(match action {
|
||||||
|
UntypedOXrAction::Haptics(action) => {
|
||||||
|
openxr::Binding::new(action, path)
|
||||||
|
}
|
||||||
|
UntypedOXrAction::Pose(action) => {
|
||||||
|
openxr::Binding::new(action, path)
|
||||||
|
}
|
||||||
|
UntypedOXrAction::Float(action) => {
|
||||||
|
openxr::Binding::new(action, path)
|
||||||
|
}
|
||||||
|
UntypedOXrAction::Bool(action) => {
|
||||||
|
openxr::Binding::new(action, path)
|
||||||
|
}
|
||||||
|
UntypedOXrAction::Vec2(action) => {
|
||||||
|
openxr::Binding::new(action, path)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
})
|
||||||
|
.collect();
|
||||||
|
self.inner_instance.suggest_interaction_profile_bindings(
|
||||||
|
self.inner_instance
|
||||||
|
.string_to_path(interaction_profile.get_interaction_profile())?,
|
||||||
|
&controller_bindings,
|
||||||
|
)?;
|
||||||
|
|
||||||
let action_sets = self.action_sets.lock().unwrap();
|
let action_sets = self.action_sets.lock().unwrap();
|
||||||
self.session
|
self.session
|
||||||
.attach_action_sets(&action_sets.iter().collect::<Vec<_>>())?;
|
.attach_action_sets(&action_sets.iter().collect::<Vec<_>>())?;
|
||||||
|
}
|
||||||
|
|
||||||
bindings.sessions_attached = true;
|
bindings.sessions_attached = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -219,6 +258,11 @@ impl SessionTrait for OXrSession {
|
|||||||
let _span = info_span!("xr_wait_image").entered();
|
let _span = info_span!("xr_wait_image").entered();
|
||||||
self.swapchain.wait_image().unwrap();
|
self.swapchain.wait_image().unwrap();
|
||||||
}
|
}
|
||||||
|
{
|
||||||
|
let action_sets = self.action_sets.lock().unwrap();
|
||||||
|
self.session
|
||||||
|
.sync_actions(&action_sets.iter().map(Into::into).collect::<Vec<_>>())?;
|
||||||
|
}
|
||||||
let views = {
|
let views = {
|
||||||
let _span = info_span!("xr_locate_views").entered();
|
let _span = info_span!("xr_locate_views").entered();
|
||||||
self.session
|
self.session
|
||||||
@@ -293,11 +337,7 @@ pub struct OXrInput {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl InputTrait for OXrInput {
|
impl InputTrait for OXrInput {
|
||||||
fn create_action_haptics(
|
fn create_action_haptics(&self, path: path::UntypedActionPath) -> Result<Action<Haptic>> {
|
||||||
&self,
|
|
||||||
name: &str,
|
|
||||||
path: path::UntypedActionPath,
|
|
||||||
) -> Result<Action<Haptic>> {
|
|
||||||
let mut bindings = self.bindings.lock().unwrap();
|
let mut bindings = self.bindings.lock().unwrap();
|
||||||
let action = match bindings.map.entry(path.into_xr_path()) {
|
let action = match bindings.map.entry(path.into_xr_path()) {
|
||||||
hash_map::Entry::Occupied(entry) => match entry.get() {
|
hash_map::Entry::Occupied(entry) => match entry.get() {
|
||||||
@@ -305,6 +345,7 @@ impl InputTrait for OXrInput {
|
|||||||
_ => Err(XrError::Placeholder)?,
|
_ => Err(XrError::Placeholder)?,
|
||||||
},
|
},
|
||||||
hash_map::Entry::Vacant(entry) => {
|
hash_map::Entry::Vacant(entry) => {
|
||||||
|
let name = &path.into_name();
|
||||||
let action = self
|
let action = self
|
||||||
.action_set
|
.action_set
|
||||||
.create_action::<openxr::Haptic>(name, name, &[])?;
|
.create_action::<openxr::Haptic>(name, name, &[])?;
|
||||||
@@ -315,11 +356,7 @@ impl InputTrait for OXrInput {
|
|||||||
Ok(OXrHaptics(action, self.inner_session.clone()).into())
|
Ok(OXrHaptics(action, self.inner_session.clone()).into())
|
||||||
}
|
}
|
||||||
|
|
||||||
fn create_action_pose(
|
fn create_action_pose(&self, path: path::UntypedActionPath) -> Result<Action<Pose>> {
|
||||||
&self,
|
|
||||||
name: &str,
|
|
||||||
path: path::UntypedActionPath,
|
|
||||||
) -> Result<Action<Pose>> {
|
|
||||||
let mut bindings = self.bindings.lock().unwrap();
|
let mut bindings = self.bindings.lock().unwrap();
|
||||||
let action = match bindings.map.entry(path.into_xr_path()) {
|
let action = match bindings.map.entry(path.into_xr_path()) {
|
||||||
hash_map::Entry::Occupied(entry) => match entry.get() {
|
hash_map::Entry::Occupied(entry) => match entry.get() {
|
||||||
@@ -327,6 +364,7 @@ impl InputTrait for OXrInput {
|
|||||||
_ => Err(XrError::Placeholder)?,
|
_ => Err(XrError::Placeholder)?,
|
||||||
},
|
},
|
||||||
hash_map::Entry::Vacant(entry) => {
|
hash_map::Entry::Vacant(entry) => {
|
||||||
|
let name = &path.into_name();
|
||||||
let action = self
|
let action = self
|
||||||
.action_set
|
.action_set
|
||||||
.create_action::<openxr::Posef>(name, name, &[])?;
|
.create_action::<openxr::Posef>(name, name, &[])?;
|
||||||
@@ -346,11 +384,7 @@ impl InputTrait for OXrInput {
|
|||||||
.into())
|
.into())
|
||||||
}
|
}
|
||||||
|
|
||||||
fn create_action_float(
|
fn create_action_float(&self, path: path::UntypedActionPath) -> Result<Action<f32>> {
|
||||||
&self,
|
|
||||||
name: &str,
|
|
||||||
path: path::UntypedActionPath,
|
|
||||||
) -> Result<Action<f32>> {
|
|
||||||
let mut bindings = self.bindings.lock().unwrap();
|
let mut bindings = self.bindings.lock().unwrap();
|
||||||
let action = match bindings.map.entry(path.into_xr_path()) {
|
let action = match bindings.map.entry(path.into_xr_path()) {
|
||||||
hash_map::Entry::Occupied(entry) => match entry.get() {
|
hash_map::Entry::Occupied(entry) => match entry.get() {
|
||||||
@@ -358,6 +392,7 @@ impl InputTrait for OXrInput {
|
|||||||
_ => Err(XrError::Placeholder)?,
|
_ => Err(XrError::Placeholder)?,
|
||||||
},
|
},
|
||||||
hash_map::Entry::Vacant(entry) => {
|
hash_map::Entry::Vacant(entry) => {
|
||||||
|
let name = &path.into_name();
|
||||||
let action = self.action_set.create_action::<f32>(name, name, &[])?;
|
let action = self.action_set.create_action::<f32>(name, name, &[])?;
|
||||||
entry.insert(UntypedOXrAction::Float(action.clone()));
|
entry.insert(UntypedOXrAction::Float(action.clone()));
|
||||||
action
|
action
|
||||||
@@ -366,11 +401,7 @@ impl InputTrait for OXrInput {
|
|||||||
Ok(OXrAction(action, self.inner_session.clone(), PhantomData).into())
|
Ok(OXrAction(action, self.inner_session.clone(), PhantomData).into())
|
||||||
}
|
}
|
||||||
|
|
||||||
fn create_action_bool(
|
fn create_action_bool(&self, path: path::UntypedActionPath) -> Result<Action<bool>> {
|
||||||
&self,
|
|
||||||
name: &str,
|
|
||||||
path: path::UntypedActionPath,
|
|
||||||
) -> Result<Action<bool>> {
|
|
||||||
let mut bindings = self.bindings.lock().unwrap();
|
let mut bindings = self.bindings.lock().unwrap();
|
||||||
let action = match bindings.map.entry(path.into_xr_path()) {
|
let action = match bindings.map.entry(path.into_xr_path()) {
|
||||||
hash_map::Entry::Occupied(entry) => match entry.get() {
|
hash_map::Entry::Occupied(entry) => match entry.get() {
|
||||||
@@ -378,6 +409,7 @@ impl InputTrait for OXrInput {
|
|||||||
_ => Err(XrError::Placeholder)?,
|
_ => Err(XrError::Placeholder)?,
|
||||||
},
|
},
|
||||||
hash_map::Entry::Vacant(entry) => {
|
hash_map::Entry::Vacant(entry) => {
|
||||||
|
let name = &path.into_name();
|
||||||
let action = self.action_set.create_action::<bool>(name, name, &[])?;
|
let action = self.action_set.create_action::<bool>(name, name, &[])?;
|
||||||
entry.insert(UntypedOXrAction::Bool(action.clone()));
|
entry.insert(UntypedOXrAction::Bool(action.clone()));
|
||||||
action
|
action
|
||||||
@@ -386,11 +418,7 @@ impl InputTrait for OXrInput {
|
|||||||
Ok(OXrAction(action, self.inner_session.clone(), PhantomData).into())
|
Ok(OXrAction(action, self.inner_session.clone(), PhantomData).into())
|
||||||
}
|
}
|
||||||
|
|
||||||
fn create_action_vec2(
|
fn create_action_vec2(&self, path: path::UntypedActionPath) -> Result<Action<Vec2>> {
|
||||||
&self,
|
|
||||||
name: &str,
|
|
||||||
path: path::UntypedActionPath,
|
|
||||||
) -> Result<Action<Vec2>> {
|
|
||||||
let mut bindings = self.bindings.lock().unwrap();
|
let mut bindings = self.bindings.lock().unwrap();
|
||||||
let action = match bindings.map.entry(path.into_xr_path()) {
|
let action = match bindings.map.entry(path.into_xr_path()) {
|
||||||
hash_map::Entry::Occupied(entry) => match entry.get() {
|
hash_map::Entry::Occupied(entry) => match entry.get() {
|
||||||
@@ -398,6 +426,7 @@ impl InputTrait for OXrInput {
|
|||||||
_ => Err(XrError::Placeholder)?,
|
_ => Err(XrError::Placeholder)?,
|
||||||
},
|
},
|
||||||
hash_map::Entry::Vacant(entry) => {
|
hash_map::Entry::Vacant(entry) => {
|
||||||
|
let name = &path.into_name();
|
||||||
let action = self.action_set.create_action::<Vector2f>(name, name, &[])?;
|
let action = self.action_set.create_action::<Vector2f>(name, name, &[])?;
|
||||||
entry.insert(UntypedOXrAction::Vec2(action.clone()));
|
entry.insert(UntypedOXrAction::Vec2(action.clone()));
|
||||||
action
|
action
|
||||||
|
|||||||
@@ -7,6 +7,8 @@ use crate::{
|
|||||||
prelude::Pose,
|
prelude::Pose,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
use super::Bindings;
|
||||||
|
|
||||||
impl From<openxr::sys::Result> for XrError {
|
impl From<openxr::sys::Result> for XrError {
|
||||||
fn from(_: openxr::sys::Result) -> Self {
|
fn from(_: openxr::sys::Result) -> Self {
|
||||||
XrError::Placeholder
|
XrError::Placeholder
|
||||||
@@ -87,4 +89,57 @@ impl UntypedActionPath {
|
|||||||
path.push_str(comp_path);
|
path.push_str(comp_path);
|
||||||
path
|
path
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub(crate) fn into_name(&self) -> String {
|
||||||
|
let comp_path = match self.comp {
|
||||||
|
PathComponent::Click => "_click",
|
||||||
|
PathComponent::Touch => "_touch",
|
||||||
|
PathComponent::Value => "_value",
|
||||||
|
PathComponent::X => "_x",
|
||||||
|
PathComponent::Y => "_y",
|
||||||
|
PathComponent::Pose => "_pose",
|
||||||
|
PathComponent::Haptic => "",
|
||||||
|
};
|
||||||
|
let dev_path = match self.input {
|
||||||
|
InputId::Left(hand) => match hand {
|
||||||
|
Handed::PrimaryButton => "left_primary_button",
|
||||||
|
Handed::SecondaryButton => "left_secondary_button",
|
||||||
|
Handed::Select => "left_select",
|
||||||
|
Handed::Menu => "left_menu",
|
||||||
|
Handed::Thumbstick => "left_thumbstick",
|
||||||
|
Handed::Trigger => "left_trigger",
|
||||||
|
Handed::Grip => "left_grip",
|
||||||
|
Handed::Output => "left_output",
|
||||||
|
},
|
||||||
|
InputId::Right(hand) => match hand {
|
||||||
|
Handed::PrimaryButton => "right_primary_button",
|
||||||
|
Handed::SecondaryButton => "right_secondary_button",
|
||||||
|
Handed::Select => "right_select",
|
||||||
|
Handed::Menu => "right_menu",
|
||||||
|
Handed::Thumbstick => "right_thumbstick",
|
||||||
|
Handed::Trigger => "right_trigger",
|
||||||
|
Handed::Grip => "right_grip",
|
||||||
|
Handed::Output => "right_output",
|
||||||
|
},
|
||||||
|
InputId::Head(head) => {
|
||||||
|
use input::head::Head;
|
||||||
|
match head {
|
||||||
|
Head::VolumeUp => "volume_up",
|
||||||
|
Head::VolumeDown => "volume_down",
|
||||||
|
Head::MuteMic => "mute_mic",
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
let mut path = dev_path.to_string();
|
||||||
|
path.push_str(comp_path);
|
||||||
|
path
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Bindings {
|
||||||
|
pub(crate) fn get_interaction_profile(&self) -> &'static str {
|
||||||
|
match self {
|
||||||
|
Bindings::OculusTouch => "/interaction_profiles/oculus/touch_controller",
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -16,7 +16,7 @@ pub mod prelude {
|
|||||||
pub use super::api::*;
|
pub use super::api::*;
|
||||||
pub use super::api_traits::*;
|
pub use super::api_traits::*;
|
||||||
pub use super::error::*;
|
pub use super::error::*;
|
||||||
pub use super::path::{self, ActionPath};
|
pub use super::path::{input, ActionPath};
|
||||||
pub use super::types::*;
|
pub use super::types::*;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -15,6 +15,7 @@ pub struct SessionCreateInfo {
|
|||||||
pub texture_format: wgpu::TextureFormat,
|
pub texture_format: wgpu::TextureFormat,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Clone, Copy, Debug, PartialEq, Eq, PartialOrd, Ord)]
|
||||||
pub enum Bindings {
|
pub enum Bindings {
|
||||||
OculusTouch,
|
OculusTouch,
|
||||||
}
|
}
|
||||||
@@ -29,45 +30,45 @@ pub struct Pose {
|
|||||||
pub trait ActionType: Sized {
|
pub trait ActionType: Sized {
|
||||||
type Inner: ?Sized;
|
type Inner: ?Sized;
|
||||||
|
|
||||||
fn get(input: &dyn InputTrait, name: &str, path: UntypedActionPath) -> Result<Action<Self>>;
|
fn get(input: &dyn InputTrait, path: UntypedActionPath) -> Result<Action<Self>>;
|
||||||
}
|
}
|
||||||
|
|
||||||
impl ActionType for Haptic {
|
impl ActionType for Haptic {
|
||||||
type Inner = dyn HapticTrait;
|
type Inner = dyn HapticTrait;
|
||||||
|
|
||||||
fn get(input: &dyn InputTrait, name: &str, path: UntypedActionPath) -> Result<Action<Self>> {
|
fn get(input: &dyn InputTrait, path: UntypedActionPath) -> Result<Action<Self>> {
|
||||||
input.create_action_haptics(name, path)
|
input.create_action_haptics(path)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl ActionType for Pose {
|
impl ActionType for Pose {
|
||||||
type Inner = dyn ActionInputTrait<Pose>;
|
type Inner = dyn ActionInputTrait<Pose>;
|
||||||
|
|
||||||
fn get(input: &dyn InputTrait, name: &str, path: UntypedActionPath) -> Result<Action<Self>> {
|
fn get(input: &dyn InputTrait, path: UntypedActionPath) -> Result<Action<Self>> {
|
||||||
input.create_action_pose(name, path)
|
input.create_action_pose(path)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl ActionType for f32 {
|
impl ActionType for f32 {
|
||||||
type Inner = dyn ActionInputTrait<f32>;
|
type Inner = dyn ActionInputTrait<f32>;
|
||||||
|
|
||||||
fn get(input: &dyn InputTrait, name: &str, path: UntypedActionPath) -> Result<Action<Self>> {
|
fn get(input: &dyn InputTrait, path: UntypedActionPath) -> Result<Action<Self>> {
|
||||||
input.create_action_float(name, path)
|
input.create_action_float(path)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl ActionType for bool {
|
impl ActionType for bool {
|
||||||
type Inner = dyn ActionInputTrait<bool>;
|
type Inner = dyn ActionInputTrait<bool>;
|
||||||
|
|
||||||
fn get(input: &dyn InputTrait, name: &str, path: UntypedActionPath) -> Result<Action<Self>> {
|
fn get(input: &dyn InputTrait, path: UntypedActionPath) -> Result<Action<Self>> {
|
||||||
input.create_action_bool(name, path)
|
input.create_action_bool(path)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl ActionType for Vec2 {
|
impl ActionType for Vec2 {
|
||||||
type Inner = dyn ActionInputTrait<Vec2>;
|
type Inner = dyn ActionInputTrait<Vec2>;
|
||||||
|
|
||||||
fn get(input: &dyn InputTrait, name: &str, path: UntypedActionPath) -> Result<Action<Self>> {
|
fn get(input: &dyn InputTrait, path: UntypedActionPath) -> Result<Action<Self>> {
|
||||||
input.create_action_vec2(name, path)
|
input.create_action_vec2(path)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user