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