add doc comments

This commit is contained in:
awtterpip
2023-12-27 20:03:41 -06:00
parent 660dd32d84
commit b43f875b3b
4 changed files with 65 additions and 87 deletions

View File

@@ -3,6 +3,9 @@ use std::rc::Rc;
use crate::prelude::*;
/// Entry point to the API
///
/// To see methods available for this struct, refer to [EntryTrait]
#[derive(Clone)]
pub struct Entry(Rc<dyn EntryTrait>);
@@ -16,100 +19,71 @@ impl Entry {
}
}
/// Represents an intent to start a session with requested extensions.
///
/// To see methods available for this struct, refer to [InstanceTrait]
#[derive(Clone)]
pub struct Instance(Rc<dyn InstanceTrait>);
/// Represents a running XR application.
///
/// To see methods available for this struct, refer to [SessionTrait]
#[derive(Clone)]
pub struct Session(Rc<dyn SessionTrait>);
/// A view of one eye. Used to retrieve render data such as texture views and projection matrices.
///
/// To see methods available for this struct, refer to [ViewTrait]
#[derive(Clone)]
pub struct View(Rc<dyn ViewTrait>);
/// Represents all XR input sources.
///
/// To see methods available for this struct, refer to [InputTrait]
#[derive(Clone)]
pub struct Input(Rc<dyn InputTrait>);
/// Represents an XR Action. Can be used to retrieve input values or trigger output devices such as haptics.
///
/// The methods available to this struct are dependent upon the action type. For input values, use `.get()` to retrieve the values.
/// For haptics, please refer to [HapticTrait]
#[derive(Clone)]
pub struct Action<A: ActionType>(A::Inner);
pub struct Action<A: ActionType>(Rc<A::Inner>);
impl Deref for Entry {
type Target = dyn EntryTrait;
macro_rules! impl_api {
($($t:ty, $trait:ident; )*) => {
$(
impl std::ops::Deref for $t {
type Target = dyn $trait;
fn deref(&self) -> &Self::Target {
&*self.0
}
}
impl Deref for Instance {
type Target = dyn InstanceTrait;
fn deref(&self) -> &Self::Target {
&*self.0
}
}
impl Deref for Session {
type Target = dyn SessionTrait;
fn deref(&self) -> &Self::Target {
&*self.0
}
}
impl Deref for View {
type Target = dyn ViewTrait;
fn deref(&self) -> &Self::Target {
&*self.0
}
}
impl Deref for Input {
type Target = dyn InputTrait;
fn deref(&self) -> &Self::Target {
&*self.0
}
}
impl<O, A> Deref for Action<A>
where
A: ActionType,
A::Inner: Deref<Target = O>,
{
type Target = O;
fn deref(&self) -> &Self::Target {
&*self.0
}
}
impl<T: EntryTrait + 'static> From<T> for Entry {
impl<T: $trait + 'static> From<T> for $t {
fn from(value: T) -> Self {
Self(Rc::new(value))
}
}
impl<T: InstanceTrait + 'static> From<T> for Instance {
fn from(value: T) -> Self {
Self(Rc::new(value))
}
)*
};
}
impl<T: SessionTrait + 'static> From<T> for Session {
fn from(value: T) -> Self {
Self(Rc::new(value))
}
impl_api! {
Entry, EntryTrait;
Instance, InstanceTrait;
Session, SessionTrait;
View, ViewTrait;
Input, InputTrait;
}
impl<T: ViewTrait + 'static> From<T> for View {
fn from(value: T) -> Self {
Self(Rc::new(value))
}
}
impl<A: ActionType> Deref for Action<A> {
type Target = A::Inner;
impl<T: InputTrait + 'static> From<T> for Input {
fn from(value: T) -> Self {
Self(Rc::new(value))
fn deref(&self) -> &Self::Target {
&self.0
}
}

View File

@@ -26,8 +26,8 @@ pub trait SessionTrait {
-> Option<(Device, Queue, AdapterInfo, Adapter, wgpu::Instance)>;
/// Request input modules with the specified bindings.
fn create_input(&self, bindings: Bindings) -> Result<Input>;
/// Blocks until a rendering frame is available, then returns the texture views for the left and right eyes.
fn begin_frame(&self) -> Result<(TextureView, TextureView)>;
/// Blocks until a rendering frame is available, then returns the views for the left and right eyes.
fn begin_frame(&self) -> Result<(View, View)>;
/// Submits rendering work for this frame.
fn end_frame(&self) -> Result<()>;
}
@@ -64,8 +64,12 @@ pub trait ActionTrait {
fn id(&self) -> ActionId;
}
pub trait ActionInputTrait<A> {}
/// Represents input actions, such as bools, floats, and poses
pub trait ActionInputTrait<A> {
fn get(&self) -> A;
}
/// Represents haptic actions.
pub trait HapticTrait {}
impl<T: InstanceTrait> EntryTrait for T {

View File

@@ -90,7 +90,7 @@ impl SessionTrait for WebXrSession {
.into())
}
fn begin_frame(&self) -> Result<(wgpu::TextureView, wgpu::TextureView)> {
fn begin_frame(&self) -> Result<(View, View)> {
let mut end_frame_sender = self.end_frame_sender.lock().unwrap();
if end_frame_sender.is_some() {
Err(XrError::Placeholder)?

View File

@@ -33,13 +33,13 @@ pub struct Haptic;
pub struct Pose;
pub trait ActionType: Sized {
type Inner;
type Inner: ?Sized;
fn get(input: &dyn InputTrait, path: ActionId) -> Result<Action<Self>>;
}
impl ActionType for Haptic {
type Inner = Rc<dyn HapticTrait>;
type Inner = dyn HapticTrait;
fn get(input: &dyn InputTrait, path: ActionId) -> Result<Action<Self>> {
input.get_haptics(path)
@@ -47,7 +47,7 @@ impl ActionType for Haptic {
}
impl ActionType for Pose {
type Inner = Rc<dyn ActionInputTrait<Pose>>;
type Inner = dyn ActionInputTrait<Pose>;
fn get(input: &dyn InputTrait, path: ActionId) -> Result<Action<Self>> {
input.get_pose(path)
@@ -55,7 +55,7 @@ impl ActionType for Pose {
}
impl ActionType for f32 {
type Inner = Rc<dyn ActionInputTrait<f32>>;
type Inner = dyn ActionInputTrait<f32>;
fn get(input: &dyn InputTrait, path: ActionId) -> Result<Action<Self>> {
input.get_float(path)
@@ -63,7 +63,7 @@ impl ActionType for f32 {
}
impl ActionType for bool {
type Inner = Rc<dyn ActionInputTrait<bool>>;
type Inner = dyn ActionInputTrait<bool>;
fn get(input: &dyn InputTrait, path: ActionId) -> Result<Action<Self>> {
input.get_bool(path)