refactor: clean up all warnings by commenting or refactoring

This commit is contained in:
Nova
2022-06-11 00:52:54 -04:00
parent 34a6e86685
commit 26f66fc5a4
3 changed files with 42 additions and 36 deletions

View File

@@ -23,9 +23,9 @@ impl<'a> Client<'a> {
self.messenger.dispatch(&self.scenegraph)
}
pub fn get_messenger(&self) -> &Messenger<'a> {
&self.messenger
}
// pub fn get_messenger(&self) -> &Messenger<'a> {
// &self.messenger
// }
pub fn get_scenegraph(&self) -> &Scenegraph<'a> {
&self.scenegraph
}

View File

@@ -10,7 +10,7 @@ pub type Method = fn(&Node, Rc<Client>, &[u8]) -> Result<Vec<u8>>;
pub struct Node<'a> {
client: Weak<Client<'a>>,
path: String,
trailing_slash_pos: usize,
// trailing_slash_pos: usize,
local_signals: HashMap<String, Signal>,
local_methods: HashMap<String, Method>,
destroyable: bool,
@@ -22,9 +22,9 @@ impl<'a> Node<'a> {
pub fn get_client(&self) -> Option<Rc<Client<'a>>> {
self.client.clone().upgrade()
}
pub fn get_name(&self) -> &str {
&self.path[self.trailing_slash_pos + 1..]
}
// pub fn get_name(&self) -> &str {
// &self.path[self.trailing_slash_pos + 1..]
// }
pub fn get_path(&self) -> &str {
self.path.as_str()
}
@@ -39,7 +39,7 @@ impl<'a> Node<'a> {
let mut node = Node {
client,
path,
trailing_slash_pos: parent.len(),
// trailing_slash_pos: parent.len(),
local_signals: HashMap::new(),
local_methods: HashMap::new(),
destroyable,
@@ -92,23 +92,23 @@ impl<'a> Node<'a> {
.ok_or_else(|| anyhow!("Method {} not found", method))?;
method(self, calling_client, data)
}
pub fn send_remote_signal(&self, method: &str, data: &[u8]) -> Result<()> {
self.get_client()
.ok_or_else(|| anyhow!("Node has no client, can't send remote signal!"))?
.get_messenger()
.send_remote_signal(self.path.as_str(), method, data)
.map_err(|_| anyhow!("Unable to write in messenger"))
}
pub fn execute_remote_method(
&self,
method: &str,
data: &[u8],
callback: Box<dyn Fn(&[u8]) + 'a>,
) -> Result<()> {
self.get_client()
.ok_or_else(|| anyhow!("Node has no client, can't send remote signal!"))?
.get_messenger()
.execute_remote_method(self.path.as_str(), method, data, callback)
.map_err(|_| anyhow!("Unable to write in messenger"))
}
// pub fn send_remote_signal(&self, method: &str, data: &[u8]) -> Result<()> {
// self.get_client()
// .ok_or_else(|| anyhow!("Node has no client, can't send remote signal!"))?
// .get_messenger()
// .send_remote_signal(self.path.as_str(), method, data)
// .map_err(|_| anyhow!("Unable to write in messenger"))
// }
// pub fn execute_remote_method(
// &self,
// method: &str,
// data: &[u8],
// callback: Box<dyn Fn(&[u8]) + 'a>,
// ) -> Result<()> {
// self.get_client()
// .ok_or_else(|| anyhow!("Node has no client, can't send remote signal!"))?
// .get_messenger()
// .execute_remote_method(self.path.as_str(), method, data, callback)
// .map_err(|_| anyhow!("Unable to write in messenger"))
// }
}

View File

@@ -5,12 +5,12 @@ use glam::{Mat4, Quat, Vec3};
use libstardustxr::flex::flexbuffer_from_vector_arguments;
use libstardustxr::push_to_vec;
use libstardustxr::{flex_to_quat, flex_to_vec3};
use rccell::{RcCell, WeakCell};
use rccell::RcCell;
use std::cell::{Cell, RefCell};
use std::rc::Rc;
pub struct Spatial<'a> {
node: WeakCell<Node<'a>>,
// node: WeakCell<Node<'a>>,
parent: RefCell<Option<Rc<Spatial<'a>>>>,
transform: Cell<Mat4>,
}
@@ -25,7 +25,7 @@ impl<'a> Spatial<'a> {
bail!("Node already has a Spatial aspect!");
}
let spatial = Spatial {
node: node.downgrade(),
// node: node.downgrade(),
parent: RefCell::new(parent),
transform: Cell::new(transform),
};
@@ -69,9 +69,15 @@ impl<'a> Spatial<'a> {
let (mut reference_space_scl, mut reference_space_rot, mut reference_space_pos) =
local_transform_in_reference_space.to_scale_rotation_translation();
pos.map(|pos| reference_space_pos = pos);
rot.map(|rot| reference_space_rot = rot);
scl.map(|scl| reference_space_scl = scl);
if let Some(pos) = pos {
reference_space_pos = pos
}
if let Some(rot) = rot {
reference_space_rot = rot
}
if let Some(scl) = scl {
reference_space_scl = scl
}
local_transform_in_reference_space = Mat4::from_scale_rotation_translation(
reference_space_scl,
@@ -122,7 +128,9 @@ impl<'a> Spatial<'a> {
.as_ref()
.ok_or_else(|| anyhow!("Node somehow is not spatial"))?;
let reference_space_path = flex_vec.idx(0).as_str();
let reference_space_transform = if reference_space_path != "" {
let reference_space_transform = if reference_space_path.is_empty() {
None
} else {
Some(
calling_client
.get_scenegraph()
@@ -134,8 +142,6 @@ impl<'a> Spatial<'a> {
.ok_or_else(|| anyhow!("Node is not a Spatial!"))?
.clone(),
)
} else {
None
};
spatial.set_local_transform_components(
reference_space_transform.as_deref(),