feat(client): set_base_prefixes

This commit is contained in:
Nova
2022-08-19 12:18:09 -04:00
parent 11299716d9
commit 47cdb408a0
2 changed files with 18 additions and 0 deletions

View File

@@ -11,6 +11,8 @@ use anyhow::Result;
use lazy_static::lazy_static;
use libstardustxr::messenger::Messenger;
use once_cell::sync::OnceCell;
use parking_lot::Mutex;
use std::path::PathBuf;
use std::sync::{Arc, Weak};
use tokio::net::UnixStream;
use tokio::sync::Notify;
@@ -27,6 +29,7 @@ lazy_static! {
messenger: None,
scenegraph: Default::default(),
root: OnceCell::new(),
base_resource_prefixes: Default::default(),
});
}
@@ -39,6 +42,7 @@ pub struct Client {
pub messenger: Option<Messenger>,
pub scenegraph: Scenegraph,
pub root: OnceCell<Arc<Root>>,
pub base_resource_prefixes: Mutex<Vec<PathBuf>>,
}
impl Client {
pub fn from_connection(
@@ -56,6 +60,7 @@ impl Client {
messenger: Some(Messenger::new(connection)),
scenegraph: Default::default(),
root: OnceCell::new(),
base_resource_prefixes: Default::default(),
});
let _ = client.scenegraph.client.set(Arc::downgrade(&client));
let _ = client.root.set(Root::create(&client));

View File

@@ -5,6 +5,7 @@ use crate::core::registry::Registry;
use anyhow::Result;
use glam::Mat4;
use libstardustxr::flex::flexbuffer_from_vector_arguments;
use std::path::PathBuf;
use std::sync::atomic::{AtomicBool, Ordering};
use std::sync::Arc;
@@ -18,6 +19,7 @@ impl Root {
pub fn create(client: &Arc<Client>) -> Arc<Self> {
let node = Node::create(client, "", "", false);
node.add_local_signal("subscribeLogicStep", Root::subscribe_logic_step);
node.add_local_signal("setBasePrefixes", Root::set_base_prefixes);
let node = node.add_to_scenegraph();
let _ = Spatial::add_to(&node, None, Mat4::IDENTITY);
@@ -48,6 +50,17 @@ impl Root {
}
}
}
fn set_base_prefixes(_node: &Node, calling_client: Arc<Client>, data: &[u8]) -> Result<()> {
let flex_vec = flexbuffers::Reader::get_root(data)?.get_vector()?;
*calling_client.base_resource_prefixes.lock() = flex_vec
.iter()
.filter_map(|prefix| prefix.get_str().ok())
.map(|prefix| PathBuf::from(prefix))
.filter(|prefix| prefix.is_absolute())
.collect();
Ok(())
}
}
impl Drop for Root {