feat: spatial tracing
This commit is contained in:
@@ -55,6 +55,7 @@ optional = true
|
|||||||
[dependencies.tracing-chrome]
|
[dependencies.tracing-chrome]
|
||||||
version = "0.7.0"
|
version = "0.7.0"
|
||||||
optional = true
|
optional = true
|
||||||
|
|
||||||
[features]
|
[features]
|
||||||
default = ["wayland"]
|
default = ["wayland"]
|
||||||
wayland = ["dep:smithay", "dep:xkbcommon"]
|
wayland = ["dep:smithay", "dep:xkbcommon"]
|
||||||
|
|||||||
@@ -19,6 +19,7 @@ use std::future::Future;
|
|||||||
use std::sync::atomic::{AtomicBool, Ordering};
|
use std::sync::atomic::{AtomicBool, Ordering};
|
||||||
use std::sync::{Arc, Weak};
|
use std::sync::{Arc, Weak};
|
||||||
use std::vec::Vec;
|
use std::vec::Vec;
|
||||||
|
use tracing::debug_span;
|
||||||
|
|
||||||
use core::hash::BuildHasherDefault;
|
use core::hash::BuildHasherDefault;
|
||||||
use dashmap::DashMap;
|
use dashmap::DashMap;
|
||||||
@@ -188,8 +189,10 @@ impl Node {
|
|||||||
.local_signals
|
.local_signals
|
||||||
.get(method)
|
.get(method)
|
||||||
.ok_or(ScenegraphError::SignalNotFound)?;
|
.ok_or(ScenegraphError::SignalNotFound)?;
|
||||||
signal(self, calling_client, data).map_err(|error| ScenegraphError::SignalError {
|
debug_span!("Handle signal").in_scope(|| {
|
||||||
error: error.to_string(),
|
signal(self, calling_client, data).map_err(|error| ScenegraphError::SignalError {
|
||||||
|
error: error.to_string(),
|
||||||
|
})
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -213,8 +216,11 @@ impl Node {
|
|||||||
.local_methods
|
.local_methods
|
||||||
.get(method)
|
.get(method)
|
||||||
.ok_or(ScenegraphError::MethodNotFound)?;
|
.ok_or(ScenegraphError::MethodNotFound)?;
|
||||||
method(self, calling_client, data).map_err(|error| ScenegraphError::MethodError {
|
|
||||||
error: error.to_string(),
|
debug_span!("Handle method").in_scope(|| {
|
||||||
|
method(self, calling_client, data).map_err(|error| ScenegraphError::MethodError {
|
||||||
|
error: error.to_string(),
|
||||||
|
})
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -12,8 +12,10 @@ use parking_lot::Mutex;
|
|||||||
use serde::Deserialize;
|
use serde::Deserialize;
|
||||||
use stardust_xr::schemas::flex::{deserialize, serialize};
|
use stardust_xr::schemas::flex::{deserialize, serialize};
|
||||||
use stardust_xr::values::Transform;
|
use stardust_xr::values::Transform;
|
||||||
|
use std::fmt::Debug;
|
||||||
use std::ptr;
|
use std::ptr;
|
||||||
use std::sync::{Arc, Weak};
|
use std::sync::{Arc, Weak};
|
||||||
|
use tracing::instrument;
|
||||||
|
|
||||||
static ZONEABLE_REGISTRY: Registry<Spatial> = Registry::new();
|
static ZONEABLE_REGISTRY: Registry<Spatial> = Registry::new();
|
||||||
|
|
||||||
@@ -71,12 +73,14 @@ impl Spatial {
|
|||||||
Ok(spatial_arc)
|
Ok(spatial_arc)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[instrument]
|
||||||
pub fn space_to_space_matrix(from: Option<&Spatial>, to: Option<&Spatial>) -> Mat4 {
|
pub fn space_to_space_matrix(from: Option<&Spatial>, to: Option<&Spatial>) -> Mat4 {
|
||||||
let space_to_world_matrix = from.map_or(Mat4::IDENTITY, |from| from.global_transform());
|
let space_to_world_matrix = from.map_or(Mat4::IDENTITY, |from| from.global_transform());
|
||||||
let world_to_space_matrix = to.map_or(Mat4::IDENTITY, |to| to.global_transform().inverse());
|
let world_to_space_matrix = to.map_or(Mat4::IDENTITY, |to| to.global_transform().inverse());
|
||||||
world_to_space_matrix * space_to_world_matrix
|
world_to_space_matrix * space_to_world_matrix
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[instrument]
|
||||||
pub fn local_transform(&self) -> Mat4 {
|
pub fn local_transform(&self) -> Mat4 {
|
||||||
*self.transform.lock()
|
*self.transform.lock()
|
||||||
}
|
}
|
||||||
@@ -86,9 +90,11 @@ impl Spatial {
|
|||||||
None => *self.transform.lock(),
|
None => *self.transform.lock(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
#[instrument]
|
||||||
pub fn set_local_transform(&self, transform: Mat4) {
|
pub fn set_local_transform(&self, transform: Mat4) {
|
||||||
*self.transform.lock() = transform;
|
*self.transform.lock() = transform;
|
||||||
}
|
}
|
||||||
|
#[instrument]
|
||||||
pub fn set_local_transform_components(
|
pub fn set_local_transform_components(
|
||||||
&self,
|
&self,
|
||||||
reference_space: Option<&Spatial>,
|
reference_space: Option<&Spatial>,
|
||||||
@@ -126,6 +132,7 @@ impl Spatial {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[instrument]
|
||||||
pub fn is_ancestor_of(&self, spatial: Arc<Spatial>) -> bool {
|
pub fn is_ancestor_of(&self, spatial: Arc<Spatial>) -> bool {
|
||||||
let mut current_ancestor = spatial;
|
let mut current_ancestor = spatial;
|
||||||
loop {
|
loop {
|
||||||
@@ -142,6 +149,7 @@ impl Spatial {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[instrument]
|
||||||
pub fn set_spatial_parent(&self, parent: Option<&Arc<Spatial>>) -> Result<()> {
|
pub fn set_spatial_parent(&self, parent: Option<&Arc<Spatial>>) -> Result<()> {
|
||||||
let is_ancestor = parent
|
let is_ancestor = parent
|
||||||
.map(|parent| self.is_ancestor_of(parent.clone()))
|
.map(|parent| self.is_ancestor_of(parent.clone()))
|
||||||
@@ -155,6 +163,7 @@ impl Spatial {
|
|||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[instrument]
|
||||||
pub fn set_spatial_parent_in_place(&self, parent: Option<&Arc<Spatial>>) -> Result<()> {
|
pub fn set_spatial_parent_in_place(&self, parent: Option<&Arc<Spatial>>) -> Result<()> {
|
||||||
let is_ancestor = parent
|
let is_ancestor = parent
|
||||||
.map(|parent| self.is_ancestor_of(parent.clone()))
|
.map(|parent| self.is_ancestor_of(parent.clone()))
|
||||||
@@ -249,6 +258,7 @@ impl Spatial {
|
|||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[instrument]
|
||||||
pub(self) fn zone_distance(&self) -> f32 {
|
pub(self) fn zone_distance(&self) -> f32 {
|
||||||
self.zone
|
self.zone
|
||||||
.lock()
|
.lock()
|
||||||
@@ -258,6 +268,16 @@ impl Spatial {
|
|||||||
.unwrap_or(f32::MAX)
|
.unwrap_or(f32::MAX)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
impl Debug for Spatial {
|
||||||
|
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||||
|
f.debug_struct("Spatial")
|
||||||
|
.field("uid", &self.uid)
|
||||||
|
.field("parent", &self.parent)
|
||||||
|
.field("old_parent", &self.old_parent)
|
||||||
|
.field("transform", &self.transform)
|
||||||
|
.finish()
|
||||||
|
}
|
||||||
|
}
|
||||||
impl Drop for Spatial {
|
impl Drop for Spatial {
|
||||||
fn drop(&mut self) {
|
fn drop(&mut self) {
|
||||||
ZONEABLE_REGISTRY.remove(self);
|
ZONEABLE_REGISTRY.remove(self);
|
||||||
|
|||||||
Reference in New Issue
Block a user