feat(client): set_base_prefixes
This commit is contained in:
@@ -11,6 +11,8 @@ use anyhow::Result;
|
|||||||
use lazy_static::lazy_static;
|
use lazy_static::lazy_static;
|
||||||
use libstardustxr::messenger::Messenger;
|
use libstardustxr::messenger::Messenger;
|
||||||
use once_cell::sync::OnceCell;
|
use once_cell::sync::OnceCell;
|
||||||
|
use parking_lot::Mutex;
|
||||||
|
use std::path::PathBuf;
|
||||||
use std::sync::{Arc, Weak};
|
use std::sync::{Arc, Weak};
|
||||||
use tokio::net::UnixStream;
|
use tokio::net::UnixStream;
|
||||||
use tokio::sync::Notify;
|
use tokio::sync::Notify;
|
||||||
@@ -27,6 +29,7 @@ lazy_static! {
|
|||||||
messenger: None,
|
messenger: None,
|
||||||
scenegraph: Default::default(),
|
scenegraph: Default::default(),
|
||||||
root: OnceCell::new(),
|
root: OnceCell::new(),
|
||||||
|
base_resource_prefixes: Default::default(),
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -39,6 +42,7 @@ pub struct Client {
|
|||||||
pub messenger: Option<Messenger>,
|
pub messenger: Option<Messenger>,
|
||||||
pub scenegraph: Scenegraph,
|
pub scenegraph: Scenegraph,
|
||||||
pub root: OnceCell<Arc<Root>>,
|
pub root: OnceCell<Arc<Root>>,
|
||||||
|
pub base_resource_prefixes: Mutex<Vec<PathBuf>>,
|
||||||
}
|
}
|
||||||
impl Client {
|
impl Client {
|
||||||
pub fn from_connection(
|
pub fn from_connection(
|
||||||
@@ -56,6 +60,7 @@ impl Client {
|
|||||||
messenger: Some(Messenger::new(connection)),
|
messenger: Some(Messenger::new(connection)),
|
||||||
scenegraph: Default::default(),
|
scenegraph: Default::default(),
|
||||||
root: OnceCell::new(),
|
root: OnceCell::new(),
|
||||||
|
base_resource_prefixes: Default::default(),
|
||||||
});
|
});
|
||||||
let _ = client.scenegraph.client.set(Arc::downgrade(&client));
|
let _ = client.scenegraph.client.set(Arc::downgrade(&client));
|
||||||
let _ = client.root.set(Root::create(&client));
|
let _ = client.root.set(Root::create(&client));
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ use crate::core::registry::Registry;
|
|||||||
use anyhow::Result;
|
use anyhow::Result;
|
||||||
use glam::Mat4;
|
use glam::Mat4;
|
||||||
use libstardustxr::flex::flexbuffer_from_vector_arguments;
|
use libstardustxr::flex::flexbuffer_from_vector_arguments;
|
||||||
|
use std::path::PathBuf;
|
||||||
use std::sync::atomic::{AtomicBool, Ordering};
|
use std::sync::atomic::{AtomicBool, Ordering};
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
|
|
||||||
@@ -18,6 +19,7 @@ impl Root {
|
|||||||
pub fn create(client: &Arc<Client>) -> Arc<Self> {
|
pub fn create(client: &Arc<Client>) -> Arc<Self> {
|
||||||
let node = Node::create(client, "", "", false);
|
let node = Node::create(client, "", "", false);
|
||||||
node.add_local_signal("subscribeLogicStep", Root::subscribe_logic_step);
|
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 node = node.add_to_scenegraph();
|
||||||
let _ = Spatial::add_to(&node, None, Mat4::IDENTITY);
|
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 {
|
impl Drop for Root {
|
||||||
|
|||||||
Reference in New Issue
Block a user