feat: optimization
This commit is contained in:
83
Cargo.lock
generated
83
Cargo.lock
generated
@@ -833,6 +833,19 @@ dependencies = [
|
|||||||
"pin-utils",
|
"pin-utils",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "generator"
|
||||||
|
version = "0.7.5"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "5cc16584ff22b460a382b7feec54b23d2908d858152e5739a120b949293bd74e"
|
||||||
|
dependencies = [
|
||||||
|
"cc",
|
||||||
|
"libc",
|
||||||
|
"log",
|
||||||
|
"rustversion",
|
||||||
|
"windows",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "gethostname"
|
name = "gethostname"
|
||||||
version = "0.3.0"
|
version = "0.3.0"
|
||||||
@@ -1199,6 +1212,19 @@ version = "0.4.20"
|
|||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "b5e6163cb8c49088c2c36f57875e58ccd8c87c7427f7fbd50ea6710b2f3f2e8f"
|
checksum = "b5e6163cb8c49088c2c36f57875e58ccd8c87c7427f7fbd50ea6710b2f3f2e8f"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "loom"
|
||||||
|
version = "0.5.6"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "ff50ecb28bb86013e935fb6683ab1f6d3a20016f123c76fd4c27470076ac30f5"
|
||||||
|
dependencies = [
|
||||||
|
"cfg-if",
|
||||||
|
"generator",
|
||||||
|
"scoped-tls",
|
||||||
|
"tracing",
|
||||||
|
"tracing-subscriber",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "manifest-dir-macros"
|
name = "manifest-dir-macros"
|
||||||
version = "0.1.18"
|
version = "0.1.18"
|
||||||
@@ -2046,7 +2072,7 @@ dependencies = [
|
|||||||
[[package]]
|
[[package]]
|
||||||
name = "stardust-xr"
|
name = "stardust-xr"
|
||||||
version = "0.14.1"
|
version = "0.14.1"
|
||||||
source = "git+https://github.com/StardustXR/core.git#f19187dc1d0015b29e542010ad3e9dbd64d5645e"
|
source = "git+https://github.com/StardustXR/core.git#615d4b098f848b1699ac6763b22d6c8783328f10"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"cluFlock",
|
"cluFlock",
|
||||||
"color-rs",
|
"color-rs",
|
||||||
@@ -2066,7 +2092,7 @@ dependencies = [
|
|||||||
[[package]]
|
[[package]]
|
||||||
name = "stardust-xr-schemas"
|
name = "stardust-xr-schemas"
|
||||||
version = "1.5.3"
|
version = "1.5.3"
|
||||||
source = "git+https://github.com/StardustXR/core.git#f19187dc1d0015b29e542010ad3e9dbd64d5645e"
|
source = "git+https://github.com/StardustXR/core.git#615d4b098f848b1699ac6763b22d6c8783328f10"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"flatbuffers",
|
"flatbuffers",
|
||||||
"flexbuffers",
|
"flexbuffers",
|
||||||
@@ -2110,8 +2136,8 @@ dependencies = [
|
|||||||
"stereokit",
|
"stereokit",
|
||||||
"tokio",
|
"tokio",
|
||||||
"tracing",
|
"tracing",
|
||||||
"tracing-chrome",
|
|
||||||
"tracing-subscriber",
|
"tracing-subscriber",
|
||||||
|
"tracing-tracy",
|
||||||
"xkbcommon",
|
"xkbcommon",
|
||||||
]
|
]
|
||||||
|
|
||||||
@@ -2392,17 +2418,6 @@ dependencies = [
|
|||||||
"syn 2.0.37",
|
"syn 2.0.37",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "tracing-chrome"
|
|
||||||
version = "0.7.1"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "496b3cd5447f7ff527bbbf19b071ad542a000adf297d4127078b4dfdb931f41a"
|
|
||||||
dependencies = [
|
|
||||||
"serde_json",
|
|
||||||
"tracing-core",
|
|
||||||
"tracing-subscriber",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "tracing-core"
|
name = "tracing-core"
|
||||||
version = "0.1.31"
|
version = "0.1.31"
|
||||||
@@ -2442,6 +2457,37 @@ dependencies = [
|
|||||||
"tracing-log",
|
"tracing-log",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "tracing-tracy"
|
||||||
|
version = "0.10.4"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "fc6c7bf057d67aa107e076129a4f331aaac47ec379952d9f0775c6b1d838ee97"
|
||||||
|
dependencies = [
|
||||||
|
"tracing-core",
|
||||||
|
"tracing-subscriber",
|
||||||
|
"tracy-client",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "tracy-client"
|
||||||
|
version = "0.16.3"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "03684af8fb393cc7903210d868e4cb9f5c1e156737be38f52c4217fb21b86bf6"
|
||||||
|
dependencies = [
|
||||||
|
"loom",
|
||||||
|
"once_cell",
|
||||||
|
"tracy-client-sys",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "tracy-client-sys"
|
||||||
|
version = "0.21.2"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "2cb915ea3af048554640d76dd6f1492589a6401a41a30d789b983c1ec280455a"
|
||||||
|
dependencies = [
|
||||||
|
"cc",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "try-lock"
|
name = "try-lock"
|
||||||
version = "0.2.4"
|
version = "0.2.4"
|
||||||
@@ -2618,6 +2664,15 @@ version = "0.4.0"
|
|||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f"
|
checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "windows"
|
||||||
|
version = "0.48.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "e686886bc078bc1b0b600cac0147aadb815089b6e4da64016cbd754b6342700f"
|
||||||
|
dependencies = [
|
||||||
|
"windows-targets",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "windows-sys"
|
name = "windows-sys"
|
||||||
version = "0.48.0"
|
version = "0.48.0"
|
||||||
|
|||||||
@@ -17,7 +17,7 @@ default = ["wayland"]
|
|||||||
wayland = ["dep:smithay", "dep:xkbcommon"]
|
wayland = ["dep:smithay", "dep:xkbcommon"]
|
||||||
xwayland = ["smithay/xwayland"]
|
xwayland = ["smithay/xwayland"]
|
||||||
profile_tokio = ["dep:console-subscriber", "tokio/tracing"]
|
profile_tokio = ["dep:console-subscriber", "tokio/tracing"]
|
||||||
profile_app = ["dep:tracing-chrome"]
|
profile_app = ["dep:tracing-tracy"]
|
||||||
|
|
||||||
[package.metadata.appimage]
|
[package.metadata.appimage]
|
||||||
auto_link = true
|
auto_link = true
|
||||||
@@ -87,8 +87,8 @@ version = "0.16.9"
|
|||||||
version = "0.1.8"
|
version = "0.1.8"
|
||||||
optional = true
|
optional = true
|
||||||
|
|
||||||
[dependencies.tracing-chrome]
|
[dependencies.tracing-tracy]
|
||||||
version = "0.7.1"
|
version = "0.10.4"
|
||||||
optional = true
|
optional = true
|
||||||
|
|
||||||
[dependencies.stardust-xr]
|
[dependencies.stardust-xr]
|
||||||
|
|||||||
@@ -7,33 +7,32 @@ use std::{
|
|||||||
sync::{Arc, Weak},
|
sync::{Arc, Weak},
|
||||||
};
|
};
|
||||||
|
|
||||||
#[derive(Default)]
|
// #[derive(Default)]
|
||||||
pub struct LifeLinkedNodeList {
|
// pub struct LifeLinkedNodeList {
|
||||||
nodes: Mutex<Vec<Weak<Node>>>,
|
// nodes: Mutex<Vec<Weak<Node>>>,
|
||||||
}
|
// }
|
||||||
impl LifeLinkedNodeList {
|
// impl LifeLinkedNodeList {
|
||||||
pub fn add(&self, node: Weak<Node>) {
|
// pub fn add(&self, node: Weak<Node>) {
|
||||||
self.nodes.lock().push(node);
|
// self.nodes.lock().push(node);
|
||||||
}
|
// }
|
||||||
|
// pub fn clear(&self) {
|
||||||
|
// self.nodes
|
||||||
|
// .lock()
|
||||||
|
// .iter()
|
||||||
|
// .filter_map(|node| node.upgrade())
|
||||||
|
// .for_each(|node| {
|
||||||
|
// node.destroy();
|
||||||
|
// });
|
||||||
|
// self.nodes.lock().clear();
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
// impl Drop for LifeLinkedNodeList {
|
||||||
|
// fn drop(&mut self) {
|
||||||
|
// self.clear();
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
|
||||||
pub fn clear(&self) {
|
#[derive(Default, Debug)]
|
||||||
self.nodes
|
|
||||||
.lock()
|
|
||||||
.iter()
|
|
||||||
.filter_map(|node| node.upgrade())
|
|
||||||
.for_each(|node| {
|
|
||||||
node.destroy();
|
|
||||||
});
|
|
||||||
self.nodes.lock().clear();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
impl Drop for LifeLinkedNodeList {
|
|
||||||
fn drop(&mut self) {
|
|
||||||
self.clear();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Default)]
|
|
||||||
pub struct LifeLinkedNodeMap<K: Hash + Eq> {
|
pub struct LifeLinkedNodeMap<K: Hash + Eq> {
|
||||||
nodes: Mutex<FxHashMap<K, Weak<Node>>>,
|
nodes: Mutex<FxHashMap<K, Weak<Node>>>,
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,13 +3,14 @@ use crate::{core::client::Client, nodes::Message};
|
|||||||
use color_eyre::eyre::Result;
|
use color_eyre::eyre::Result;
|
||||||
use once_cell::sync::OnceCell;
|
use once_cell::sync::OnceCell;
|
||||||
use parking_lot::Mutex;
|
use parking_lot::Mutex;
|
||||||
|
use portable_atomic::Ordering;
|
||||||
use rustc_hash::FxHashMap;
|
use rustc_hash::FxHashMap;
|
||||||
use stardust_xr::scenegraph;
|
use stardust_xr::scenegraph;
|
||||||
use stardust_xr::scenegraph::ScenegraphError;
|
use stardust_xr::scenegraph::ScenegraphError;
|
||||||
use std::os::fd::OwnedFd;
|
use std::os::fd::OwnedFd;
|
||||||
use std::sync::{Arc, Weak};
|
use std::sync::{Arc, Weak};
|
||||||
use tokio::sync::oneshot;
|
use tokio::sync::oneshot;
|
||||||
use tracing::{debug, debug_span, instrument};
|
use tracing::{debug, debug_span};
|
||||||
|
|
||||||
#[derive(Default)]
|
#[derive(Default)]
|
||||||
pub struct Scenegraph {
|
pub struct Scenegraph {
|
||||||
@@ -33,11 +34,14 @@ impl Scenegraph {
|
|||||||
self.nodes.lock().insert(path, node);
|
self.nodes.lock().insert(path, node);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[instrument(level = "debug", skip(self))]
|
|
||||||
pub fn get_node(&self, path: &str) -> Option<Arc<Node>> {
|
pub fn get_node(&self, path: &str) -> Option<Arc<Node>> {
|
||||||
let mut node = self.nodes.lock().get(path)?.clone();
|
let mut node = self.nodes.lock().get(path)?.clone();
|
||||||
while let Some(alias) = node.alias.get() {
|
while let Some(alias) = node.alias.get() {
|
||||||
node = alias.original.upgrade()?;
|
if alias.enabled.load(Ordering::Relaxed) {
|
||||||
|
node = alias.original.upgrade()?;
|
||||||
|
} else {
|
||||||
|
return None;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
Some(node)
|
Some(node)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,10 +1,8 @@
|
|||||||
use color_eyre::eyre::Result;
|
use color_eyre::eyre::Result;
|
||||||
use std::future::Future;
|
use std::future::Future;
|
||||||
use tokio::task::JoinHandle;
|
use tokio::task::JoinHandle;
|
||||||
use tracing::instrument;
|
|
||||||
|
|
||||||
#[allow(unused_variables)]
|
#[allow(unused_variables)]
|
||||||
#[instrument(level = "debug", skip_all)]
|
|
||||||
pub fn new<
|
pub fn new<
|
||||||
F: FnOnce() -> S,
|
F: FnOnce() -> S,
|
||||||
S: AsRef<str>,
|
S: AsRef<str>,
|
||||||
|
|||||||
27
src/main.rs
27
src/main.rs
@@ -67,14 +67,18 @@ struct EventLoopInfo {
|
|||||||
socket_path: PathBuf,
|
socket_path: PathBuf,
|
||||||
}
|
}
|
||||||
|
|
||||||
fn setup_tracing() {
|
fn main() {
|
||||||
|
ctrlc::set_handler(|| {
|
||||||
|
if atty::isnt(atty::Stream::Stdout) {
|
||||||
|
STOP_NOTIFIER.notify_waiters()
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.unwrap();
|
||||||
|
|
||||||
let registry = tracing_subscriber::registry();
|
let registry = tracing_subscriber::registry();
|
||||||
|
|
||||||
#[cfg(feature = "profile_app")]
|
#[cfg(feature = "profile_app")]
|
||||||
let (chrome_layer, _guard) = tracing_chrome::ChromeLayerBuilder::new()
|
let registry = registry.with(tracing_tracy::TracyLayer::new().with_filter(LevelFilter::DEBUG));
|
||||||
.include_args(true)
|
|
||||||
.build();
|
|
||||||
#[cfg(feature = "profile_app")]
|
|
||||||
let registry = registry.with(chrome_layer);
|
|
||||||
|
|
||||||
#[cfg(feature = "profile_tokio")]
|
#[cfg(feature = "profile_tokio")]
|
||||||
let (console_layer, _) = console_subscriber::ConsoleLayer::builder().build();
|
let (console_layer, _) = console_subscriber::ConsoleLayer::builder().build();
|
||||||
@@ -87,17 +91,6 @@ fn setup_tracing() {
|
|||||||
.with_line_number(true)
|
.with_line_number(true)
|
||||||
.with_filter(EnvFilter::from_default_env());
|
.with_filter(EnvFilter::from_default_env());
|
||||||
registry.with(log_layer).init();
|
registry.with(log_layer).init();
|
||||||
}
|
|
||||||
|
|
||||||
fn main() {
|
|
||||||
ctrlc::set_handler(|| {
|
|
||||||
if atty::isnt(atty::Stream::Stdout) {
|
|
||||||
STOP_NOTIFIER.notify_waiters()
|
|
||||||
}
|
|
||||||
})
|
|
||||||
.unwrap();
|
|
||||||
|
|
||||||
setup_tracing();
|
|
||||||
|
|
||||||
let project_dirs = ProjectDirs::from("", "", "stardust");
|
let project_dirs = ProjectDirs::from("", "", "stardust");
|
||||||
if project_dirs.is_none() {
|
if project_dirs.is_none() {
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
use super::Node;
|
use super::Node;
|
||||||
use crate::core::client::Client;
|
use crate::core::client::Client;
|
||||||
use color_eyre::eyre::{ensure, Result};
|
use color_eyre::eyre::{ensure, Result};
|
||||||
|
use portable_atomic::AtomicBool;
|
||||||
use std::sync::{Arc, Weak};
|
use std::sync::{Arc, Weak};
|
||||||
|
|
||||||
#[derive(Debug, Default, Clone)]
|
#[derive(Debug, Default, Clone)]
|
||||||
@@ -12,6 +13,7 @@ pub struct AliasInfo {
|
|||||||
|
|
||||||
#[allow(dead_code)]
|
#[allow(dead_code)]
|
||||||
pub struct Alias {
|
pub struct Alias {
|
||||||
|
pub enabled: Arc<AtomicBool>,
|
||||||
pub(super) node: Weak<Node>,
|
pub(super) node: Weak<Node>,
|
||||||
pub original: Weak<Node>,
|
pub original: Weak<Node>,
|
||||||
|
|
||||||
@@ -35,6 +37,7 @@ impl Alias {
|
|||||||
|
|
||||||
let node = Node::create(client, parent, name, true).add_to_scenegraph()?;
|
let node = Node::create(client, parent, name, true).add_to_scenegraph()?;
|
||||||
let alias = Alias {
|
let alias = Alias {
|
||||||
|
enabled: Arc::new(AtomicBool::new(true)),
|
||||||
node: Arc::downgrade(&node),
|
node: Arc::downgrade(&node),
|
||||||
original: Arc::downgrade(original),
|
original: Arc::downgrade(original),
|
||||||
info,
|
info,
|
||||||
|
|||||||
@@ -7,7 +7,6 @@ use color_eyre::eyre::Result;
|
|||||||
use glam::{vec3, Mat4};
|
use glam::{vec3, Mat4};
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
use stereokit::StereoKitMultiThread;
|
use stereokit::StereoKitMultiThread;
|
||||||
use tracing::instrument;
|
|
||||||
|
|
||||||
lazy_static::lazy_static! {
|
lazy_static::lazy_static! {
|
||||||
static ref HMD: Arc<Node> = create();
|
static ref HMD: Arc<Node> = create();
|
||||||
@@ -20,7 +19,6 @@ fn create() -> Arc<Node> {
|
|||||||
node
|
node
|
||||||
}
|
}
|
||||||
|
|
||||||
#[instrument(level = "debug", name = "Update HMD Pose", skip(sk))]
|
|
||||||
pub fn frame(sk: &impl StereoKitMultiThread) {
|
pub fn frame(sk: &impl StereoKitMultiThread) {
|
||||||
let spatial = HMD
|
let spatial = HMD
|
||||||
.spatial
|
.spatial
|
||||||
|
|||||||
@@ -12,8 +12,8 @@ use super::{
|
|||||||
spatial::{find_spatial_parent, parse_transform, Spatial},
|
spatial::{find_spatial_parent, parse_transform, Spatial},
|
||||||
Message, Node,
|
Message, Node,
|
||||||
};
|
};
|
||||||
|
use crate::core::registry::Registry;
|
||||||
use crate::core::{client::Client, node_collections::LifeLinkedNodeMap};
|
use crate::core::{client::Client, node_collections::LifeLinkedNodeMap};
|
||||||
use crate::core::{node_collections::LifeLinkedNodeList, registry::Registry};
|
|
||||||
use color_eyre::eyre::{ensure, Result};
|
use color_eyre::eyre::{ensure, Result};
|
||||||
use glam::Mat4;
|
use glam::Mat4;
|
||||||
use once_cell::sync::OnceCell;
|
use once_cell::sync::OnceCell;
|
||||||
@@ -99,6 +99,7 @@ impl InputMethod {
|
|||||||
};
|
};
|
||||||
for handler in INPUT_HANDLER_REGISTRY.get_valid_contents() {
|
for handler in INPUT_HANDLER_REGISTRY.get_valid_contents() {
|
||||||
method.handle_new_handler(&handler);
|
method.handle_new_handler(&handler);
|
||||||
|
method.make_alias(&handler);
|
||||||
}
|
}
|
||||||
let method = INPUT_METHOD_REGISTRY.add(method);
|
let method = INPUT_METHOD_REGISTRY.add(method);
|
||||||
let _ = node.input_method.set(method.clone());
|
let _ = node.input_method.set(method.clone());
|
||||||
@@ -137,6 +138,26 @@ impl InputMethod {
|
|||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn make_alias(&self, handler: &InputHandler) {
|
||||||
|
let Some(method_node) = self.node.upgrade() else {return};
|
||||||
|
let Some(handler_node) = handler.node.upgrade() else {return};
|
||||||
|
let Some(client) = handler_node.get_client() else {return};
|
||||||
|
let Ok(method_alias) = Alias::create(
|
||||||
|
&client,
|
||||||
|
handler_node.get_path(),
|
||||||
|
&self.uid,
|
||||||
|
&method_node,
|
||||||
|
AliasInfo {
|
||||||
|
server_signals: vec!["capture"],
|
||||||
|
..Default::default()
|
||||||
|
},
|
||||||
|
) else {return};
|
||||||
|
method_alias.enabled.store(false, Ordering::Relaxed);
|
||||||
|
handler
|
||||||
|
.method_aliases
|
||||||
|
.add(self as *const InputMethod as usize, &method_alias);
|
||||||
|
}
|
||||||
|
|
||||||
fn compare_distance(&self, to: &Field) -> f32 {
|
fn compare_distance(&self, to: &Field) -> f32 {
|
||||||
self.specialization
|
self.specialization
|
||||||
.lock()
|
.lock()
|
||||||
@@ -201,25 +222,12 @@ pub struct DistanceLink {
|
|||||||
handler: Arc<InputHandler>,
|
handler: Arc<InputHandler>,
|
||||||
}
|
}
|
||||||
impl DistanceLink {
|
impl DistanceLink {
|
||||||
fn from(method: Arc<InputMethod>, handler: Arc<InputHandler>) -> Option<Self> {
|
fn from(method: Arc<InputMethod>, handler: Arc<InputHandler>) -> Self {
|
||||||
let handler_node = handler.node.upgrade()?;
|
DistanceLink {
|
||||||
let method_alias = Alias::create(
|
|
||||||
&handler_node.get_client()?,
|
|
||||||
handler_node.get_path(),
|
|
||||||
&method.uid,
|
|
||||||
&method.node.upgrade()?,
|
|
||||||
AliasInfo {
|
|
||||||
server_signals: vec!["capture"],
|
|
||||||
..Default::default()
|
|
||||||
},
|
|
||||||
)
|
|
||||||
.ok()?;
|
|
||||||
handler.method_aliases.add(Arc::downgrade(&method_alias));
|
|
||||||
Some(DistanceLink {
|
|
||||||
distance: method.compare_distance(&handler.field),
|
distance: method.compare_distance(&handler.field),
|
||||||
method,
|
method,
|
||||||
handler,
|
handler,
|
||||||
})
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn send_input(&self, order: u32, datamap: Datamap) {
|
fn send_input(&self, order: u32, datamap: Datamap) {
|
||||||
@@ -249,7 +257,7 @@ pub struct InputHandler {
|
|||||||
node: Weak<Node>,
|
node: Weak<Node>,
|
||||||
spatial: Arc<Spatial>,
|
spatial: Arc<Spatial>,
|
||||||
field: Arc<Field>,
|
field: Arc<Field>,
|
||||||
method_aliases: LifeLinkedNodeList,
|
method_aliases: LifeLinkedNodeMap<usize>,
|
||||||
}
|
}
|
||||||
impl InputHandler {
|
impl InputHandler {
|
||||||
pub fn add_to(node: &Arc<Node>, field: &Arc<Field>) -> Result<()> {
|
pub fn add_to(node: &Arc<Node>, field: &Arc<Field>) -> Result<()> {
|
||||||
@@ -264,9 +272,10 @@ impl InputHandler {
|
|||||||
node: Arc::downgrade(node),
|
node: Arc::downgrade(node),
|
||||||
spatial: node.spatial.get().unwrap().clone(),
|
spatial: node.spatial.get().unwrap().clone(),
|
||||||
field: field.clone(),
|
field: field.clone(),
|
||||||
method_aliases: LifeLinkedNodeList::default(),
|
method_aliases: LifeLinkedNodeMap::default(),
|
||||||
};
|
};
|
||||||
for method in INPUT_METHOD_REGISTRY.get_valid_contents() {
|
for method in INPUT_METHOD_REGISTRY.get_valid_contents() {
|
||||||
|
method.make_alias(&handler);
|
||||||
method.handle_new_handler(&handler);
|
method.handle_new_handler(&handler);
|
||||||
}
|
}
|
||||||
let handler = INPUT_HANDLER_REGISTRY.add(handler);
|
let handler = INPUT_HANDLER_REGISTRY.add(handler);
|
||||||
@@ -343,10 +352,12 @@ pub fn process_input() {
|
|||||||
.filter(|method| method.datamap.lock().is_some())
|
.filter(|method| method.datamap.lock().is_some())
|
||||||
});
|
});
|
||||||
let handlers = INPUT_HANDLER_REGISTRY.get_valid_contents();
|
let handlers = INPUT_HANDLER_REGISTRY.get_valid_contents();
|
||||||
for handler in &handlers {
|
const LIMIT: usize = 50;
|
||||||
handler.method_aliases.clear();
|
|
||||||
}
|
|
||||||
for method in methods {
|
for method in methods {
|
||||||
|
for alias in method.node.upgrade().unwrap().aliases.get_valid_contents() {
|
||||||
|
alias.enabled.store(false, Ordering::Relaxed);
|
||||||
|
}
|
||||||
|
|
||||||
debug_span!("Process input method").in_scope(|| {
|
debug_span!("Process input method").in_scope(|| {
|
||||||
// Get all valid input handlers and convert them to DistanceLink objects
|
// Get all valid input handlers and convert them to DistanceLink objects
|
||||||
let distance_links: Vec<DistanceLink> = debug_span!("Generate distance links")
|
let distance_links: Vec<DistanceLink> = debug_span!("Generate distance links")
|
||||||
@@ -357,14 +368,16 @@ pub fn process_input() {
|
|||||||
.iter()
|
.iter()
|
||||||
.filter_map(|h| h.upgrade())
|
.filter_map(|h| h.upgrade())
|
||||||
.filter(|handler| handler.enabled.load(Ordering::Relaxed))
|
.filter(|handler| handler.enabled.load(Ordering::Relaxed))
|
||||||
.filter_map(|handler| DistanceLink::from(method.clone(), handler))
|
.map(|handler| DistanceLink::from(method.clone(), handler))
|
||||||
.collect()
|
.collect()
|
||||||
} else {
|
} else {
|
||||||
let mut distance_links: Vec<_> = handlers
|
let mut distance_links: Vec<_> = handlers
|
||||||
.iter()
|
.iter()
|
||||||
.filter(|handler| handler.enabled.load(Ordering::Relaxed))
|
.filter(|handler| handler.enabled.load(Ordering::Relaxed))
|
||||||
.filter_map(|handler| {
|
.map(|handler| {
|
||||||
DistanceLink::from(method.clone(), handler.clone())
|
debug_span!("Create distance link").in_scope(|| {
|
||||||
|
DistanceLink::from(method.clone(), handler.clone())
|
||||||
|
})
|
||||||
})
|
})
|
||||||
.collect();
|
.collect();
|
||||||
|
|
||||||
@@ -375,6 +388,9 @@ pub fn process_input() {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
distance_links.reverse();
|
||||||
|
distance_links.truncate(LIMIT);
|
||||||
|
distance_links.reverse();
|
||||||
distance_links
|
distance_links
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@@ -382,6 +398,18 @@ pub fn process_input() {
|
|||||||
let captures = method.captures.take_valid_contents();
|
let captures = method.captures.take_valid_contents();
|
||||||
// Iterate over the distance links and send input to them
|
// Iterate over the distance links and send input to them
|
||||||
for (i, distance_link) in distance_links.into_iter().enumerate() {
|
for (i, distance_link) in distance_links.into_iter().enumerate() {
|
||||||
|
if i > LIMIT {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
if let Some(method_alias) = distance_link
|
||||||
|
.handler
|
||||||
|
.method_aliases
|
||||||
|
.get(&(Arc::as_ptr(&distance_link.method) as usize))
|
||||||
|
.and_then(|a| a.alias.get().cloned())
|
||||||
|
{
|
||||||
|
method_alias.enabled.store(true, Ordering::Relaxed);
|
||||||
|
}
|
||||||
distance_link.send_input(i as u32, method.datamap.lock().clone().unwrap());
|
distance_link.send_input(i as u32, method.datamap.lock().clone().unwrap());
|
||||||
|
|
||||||
// If the current distance link is in the list of captured input handlers,
|
// If the current distance link is in the list of captured input handlers,
|
||||||
|
|||||||
@@ -23,7 +23,6 @@ use std::future::Future;
|
|||||||
use std::os::fd::OwnedFd;
|
use std::os::fd::OwnedFd;
|
||||||
use std::sync::{Arc, Weak};
|
use std::sync::{Arc, Weak};
|
||||||
use std::vec::Vec;
|
use std::vec::Vec;
|
||||||
use tracing::instrument;
|
|
||||||
|
|
||||||
use crate::core::client::Client;
|
use crate::core::client::Client;
|
||||||
use crate::core::registry::Registry;
|
use crate::core::registry::Registry;
|
||||||
@@ -272,7 +271,6 @@ impl Node {
|
|||||||
method(self, calling_client, message, response);
|
method(self, calling_client, message, response);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#[instrument(level = "debug", skip_all)]
|
|
||||||
pub fn send_remote_signal(&self, method: &str, message: impl Into<Message>) -> Result<()> {
|
pub fn send_remote_signal(&self, method: &str, message: impl Into<Message>) -> Result<()> {
|
||||||
let message = message.into();
|
let message = message.into();
|
||||||
self.aliases
|
self.aliases
|
||||||
@@ -297,7 +295,6 @@ impl Node {
|
|||||||
}
|
}
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
// #[instrument(level = "debug", skip_all)]
|
|
||||||
pub fn execute_remote_method(
|
pub fn execute_remote_method(
|
||||||
&self,
|
&self,
|
||||||
method: &str,
|
method: &str,
|
||||||
|
|||||||
@@ -17,7 +17,6 @@ use std::fmt::Debug;
|
|||||||
use std::ptr;
|
use std::ptr;
|
||||||
use std::sync::{Arc, OnceLock, Weak};
|
use std::sync::{Arc, OnceLock, Weak};
|
||||||
use stereokit::{bounds_grow_to_fit_box, Bounds};
|
use stereokit::{bounds_grow_to_fit_box, Bounds};
|
||||||
use tracing::instrument;
|
|
||||||
|
|
||||||
static ZONEABLE_REGISTRY: Registry<Spatial> = Registry::new();
|
static ZONEABLE_REGISTRY: Registry<Spatial> = Registry::new();
|
||||||
|
|
||||||
@@ -81,7 +80,6 @@ impl Spatial {
|
|||||||
self.node.upgrade()
|
self.node.upgrade()
|
||||||
}
|
}
|
||||||
|
|
||||||
#[instrument(level = "debug", skip_all)]
|
|
||||||
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());
|
||||||
@@ -89,7 +87,6 @@ impl Spatial {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// the output bounds are probably way bigger than they need to be
|
// the output bounds are probably way bigger than they need to be
|
||||||
#[instrument(level = "debug")]
|
|
||||||
pub fn get_bounding_box(&self) -> Bounds {
|
pub fn get_bounding_box(&self) -> Bounds {
|
||||||
let Some(node) = self.node() else {return Bounds::default()};
|
let Some(node) = self.node() else {return Bounds::default()};
|
||||||
let mut bounds = self
|
let mut bounds = self
|
||||||
@@ -107,7 +104,6 @@ impl Spatial {
|
|||||||
bounds
|
bounds
|
||||||
}
|
}
|
||||||
|
|
||||||
#[instrument(level = "debug", skip_all)]
|
|
||||||
pub fn local_transform(&self) -> Mat4 {
|
pub fn local_transform(&self) -> Mat4 {
|
||||||
*self.transform.lock()
|
*self.transform.lock()
|
||||||
}
|
}
|
||||||
@@ -117,11 +113,9 @@ 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(level = "debug", skip(self, reference_space))]
|
|
||||||
pub fn set_local_transform_components(
|
pub fn set_local_transform_components(
|
||||||
&self,
|
&self,
|
||||||
reference_space: Option<&Spatial>,
|
reference_space: Option<&Spatial>,
|
||||||
@@ -165,7 +159,6 @@ impl Spatial {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[instrument(level = "debug", skip_all)]
|
|
||||||
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 {
|
||||||
@@ -197,7 +190,6 @@ impl Spatial {
|
|||||||
*self.parent.lock() = new_parent;
|
*self.parent.lock() = new_parent;
|
||||||
}
|
}
|
||||||
|
|
||||||
#[instrument(level = "debug", skip_all)]
|
|
||||||
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
|
||||||
.as_ref()
|
.as_ref()
|
||||||
@@ -211,7 +203,6 @@ impl Spatial {
|
|||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
#[instrument(level = "debug", skip_all)]
|
|
||||||
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
|
||||||
.as_ref()
|
.as_ref()
|
||||||
@@ -437,7 +428,6 @@ impl Spatial {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
#[instrument]
|
|
||||||
pub(self) fn zone_distance(&self) -> f32 {
|
pub(self) fn zone_distance(&self) -> f32 {
|
||||||
self.zone
|
self.zone
|
||||||
.lock()
|
.lock()
|
||||||
|
|||||||
@@ -13,7 +13,6 @@ use serde::Serialize;
|
|||||||
use stardust_xr::schemas::{flat::Datamap, flex::flexbuffers};
|
use stardust_xr::schemas::{flat::Datamap, flex::flexbuffers};
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
use stereokit::StereoKitMultiThread;
|
use stereokit::StereoKitMultiThread;
|
||||||
use tracing::instrument;
|
|
||||||
|
|
||||||
#[derive(Debug, Clone, Serialize)]
|
#[derive(Debug, Clone, Serialize)]
|
||||||
pub struct KeyboardEvent {
|
pub struct KeyboardEvent {
|
||||||
@@ -36,7 +35,6 @@ impl EyePointer {
|
|||||||
|
|
||||||
Ok(EyePointer { spatial, pointer })
|
Ok(EyePointer { spatial, pointer })
|
||||||
}
|
}
|
||||||
#[instrument(level = "debug", name = "Update Flatscreen Pointer Ray", skip_all)]
|
|
||||||
pub fn update(&self, sk: &impl StereoKitMultiThread) {
|
pub fn update(&self, sk: &impl StereoKitMultiThread) {
|
||||||
let ray = sk.input_eyes();
|
let ray = sk.input_eyes();
|
||||||
self.spatial
|
self.spatial
|
||||||
|
|||||||
@@ -14,7 +14,6 @@ use nanoid::nanoid;
|
|||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
use std::{convert::TryFrom, sync::Arc};
|
use std::{convert::TryFrom, sync::Arc};
|
||||||
use stereokit::{ray_from_mouse, ButtonState, Key, StereoKitMultiThread};
|
use stereokit::{ray_from_mouse, ButtonState, Key, StereoKitMultiThread};
|
||||||
use tracing::instrument;
|
|
||||||
use xkbcommon::xkb::{Context, Keymap, FORMAT_TEXT_V1};
|
use xkbcommon::xkb::{Context, Keymap, FORMAT_TEXT_V1};
|
||||||
|
|
||||||
#[derive(Default, Deserialize, Serialize)]
|
#[derive(Default, Deserialize, Serialize)]
|
||||||
@@ -77,7 +76,6 @@ impl MousePointer {
|
|||||||
keyboard_sender,
|
keyboard_sender,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
#[instrument(level = "debug", name = "Update Flatscreen Pointer Ray", skip_all)]
|
|
||||||
pub fn update(&mut self, sk: &impl StereoKitMultiThread) {
|
pub fn update(&mut self, sk: &impl StereoKitMultiThread) {
|
||||||
let mouse = sk.input_mouse();
|
let mouse = sk.input_mouse();
|
||||||
|
|
||||||
|
|||||||
@@ -14,7 +14,6 @@ use stereokit::{
|
|||||||
named_colors::WHITE, ButtonState, Handed, Model, RenderLayer, StereoKitDraw,
|
named_colors::WHITE, ButtonState, Handed, Model, RenderLayer, StereoKitDraw,
|
||||||
StereoKitMultiThread,
|
StereoKitMultiThread,
|
||||||
};
|
};
|
||||||
use tracing::instrument;
|
|
||||||
|
|
||||||
#[derive(Default, Deserialize, Serialize)]
|
#[derive(Default, Deserialize, Serialize)]
|
||||||
struct ControllerDatamap {
|
struct ControllerDatamap {
|
||||||
@@ -55,7 +54,6 @@ impl SkController {
|
|||||||
datamap: Default::default(),
|
datamap: Default::default(),
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
#[instrument(level = "debug", name = "Update StereoKit Tip Input Method", skip_all)]
|
|
||||||
pub fn update(&mut self, sk: &impl StereoKitDraw) {
|
pub fn update(&mut self, sk: &impl StereoKitDraw) {
|
||||||
let controller = sk.input_controller(self.handed);
|
let controller = sk.input_controller(self.handed);
|
||||||
*self.input.enabled.lock() = controller.tracked.contains(ButtonState::ACTIVE);
|
*self.input.enabled.lock() = controller.tracked.contains(ButtonState::ACTIVE);
|
||||||
|
|||||||
@@ -13,7 +13,6 @@ use serde::{Deserialize, Serialize};
|
|||||||
use stardust_xr::schemas::flat::{Hand as FlatHand, Joint};
|
use stardust_xr::schemas::flat::{Hand as FlatHand, Joint};
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
use stereokit::{ButtonState, HandJoint, Handed, StereoKitMultiThread};
|
use stereokit::{ButtonState, HandJoint, Handed, StereoKitMultiThread};
|
||||||
use tracing::instrument;
|
|
||||||
|
|
||||||
fn convert_joint(joint: HandJoint) -> Joint {
|
fn convert_joint(joint: HandJoint) -> Joint {
|
||||||
Joint {
|
Joint {
|
||||||
@@ -54,7 +53,6 @@ impl SkHand {
|
|||||||
datamap: Default::default(),
|
datamap: Default::default(),
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
#[instrument(level = "debug", name = "Update Hand Input Method", skip_all)]
|
|
||||||
pub fn update(&mut self, controller_enabled: bool, sk: &impl StereoKitMultiThread) {
|
pub fn update(&mut self, controller_enabled: bool, sk: &impl StereoKitMultiThread) {
|
||||||
let sk_hand = sk.input_hand(self.handed);
|
let sk_hand = sk.input_hand(self.handed);
|
||||||
if let InputType::Hand(hand) = &mut *self.input.specialization.lock() {
|
if let InputType::Hand(hand) = &mut *self.input.specialization.lock() {
|
||||||
|
|||||||
Reference in New Issue
Block a user