feat(spatial): basic interface
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
use super::scenegraph::Scenegraph;
|
||||
use crate::nodes::spatial;
|
||||
use libstardustxr::messenger::Messenger;
|
||||
use mio::net::UnixStream;
|
||||
use rccell::{RcCell, WeakCell};
|
||||
@@ -6,7 +7,7 @@ use rccell::{RcCell, WeakCell};
|
||||
pub struct Client<'a> {
|
||||
weak_ref: WeakCell<Client<'a>>,
|
||||
messenger: Messenger<'a>,
|
||||
scenegraph: Option<Scenegraph<'a>>,
|
||||
scenegraph: Scenegraph<'a>,
|
||||
}
|
||||
|
||||
impl<'a> Client<'a> {
|
||||
@@ -16,20 +17,22 @@ impl<'a> Client<'a> {
|
||||
scenegraph: Default::default(),
|
||||
messenger: Messenger::new(connection),
|
||||
});
|
||||
client.borrow_mut().scenegraph.set_client(client.clone());
|
||||
client.borrow_mut().weak_ref = client.downgrade();
|
||||
spatial::create_interface(client.clone());
|
||||
client
|
||||
}
|
||||
pub fn dispatch(&self) -> Result<(), std::io::Error> {
|
||||
self.messenger.dispatch(self.scenegraph.as_ref().unwrap())
|
||||
self.messenger.dispatch(&self.scenegraph)
|
||||
}
|
||||
|
||||
pub fn get_messenger(&self) -> &Messenger<'a> {
|
||||
&self.messenger
|
||||
}
|
||||
pub fn get_scenegraph(&self) -> &Scenegraph<'a> {
|
||||
self.scenegraph.as_ref().unwrap()
|
||||
&self.scenegraph
|
||||
}
|
||||
pub fn get_scenegraph_mut(&mut self) -> &mut Scenegraph<'a> {
|
||||
self.scenegraph.as_mut().unwrap()
|
||||
&mut self.scenegraph
|
||||
}
|
||||
}
|
||||
|
||||
@@ -11,6 +11,19 @@ pub struct Scenegraph<'a> {
|
||||
pub nodes: HashMap<String, RcCell<Node<'a>>>,
|
||||
}
|
||||
|
||||
impl<'a> Scenegraph<'a> {
|
||||
pub fn set_client(&mut self, client: RcCell<Client<'a>>) {
|
||||
self.client = client.downgrade();
|
||||
}
|
||||
|
||||
pub fn add_node(&mut self, node: Node<'a>) -> RcCell<Node<'a>> {
|
||||
let path = node.get_path().to_string();
|
||||
let node_rc = RcCell::new(node);
|
||||
self.nodes.insert(path, node_rc.clone());
|
||||
node_rc
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a> Default for Scenegraph<'a> {
|
||||
fn default() -> Self {
|
||||
Scenegraph {
|
||||
|
||||
Reference in New Issue
Block a user