refactor(scenegraph): use parking_lot
This commit is contained in:
@@ -3,11 +3,11 @@ use crate::nodes::core::Node;
|
|||||||
use anyhow::Result;
|
use anyhow::Result;
|
||||||
use libstardustxr::scenegraph;
|
use libstardustxr::scenegraph;
|
||||||
use libstardustxr::scenegraph::ScenegraphError;
|
use libstardustxr::scenegraph::ScenegraphError;
|
||||||
|
use parking_lot::RwLock;
|
||||||
use rccell::RcCell;
|
use rccell::RcCell;
|
||||||
use std::cell::RefCell;
|
use std::cell::RefCell;
|
||||||
use std::collections::HashMap;
|
use std::collections::HashMap;
|
||||||
use std::rc::{Rc, Weak};
|
use std::rc::{Rc, Weak};
|
||||||
use std::sync::RwLock;
|
|
||||||
|
|
||||||
#[derive(Default)]
|
#[derive(Default)]
|
||||||
pub struct Scenegraph<'a> {
|
pub struct Scenegraph<'a> {
|
||||||
@@ -27,16 +27,16 @@ impl<'a> Scenegraph<'a> {
|
|||||||
pub fn add_node(&self, node: Node<'a>) -> RcCell<Node<'a>> {
|
pub fn add_node(&self, node: Node<'a>) -> RcCell<Node<'a>> {
|
||||||
let path = node.get_path().to_string();
|
let path = node.get_path().to_string();
|
||||||
let node_rc = RcCell::new(node);
|
let node_rc = RcCell::new(node);
|
||||||
self.nodes.write().unwrap().insert(path, node_rc.clone());
|
self.nodes.write().insert(path, node_rc.clone());
|
||||||
node_rc
|
node_rc
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn get_node(&self, path: &str) -> Option<RcCell<Node<'a>>> {
|
pub fn get_node(&self, path: &str) -> Option<RcCell<Node<'a>>> {
|
||||||
Some(self.nodes.read().ok()?.get(path)?.clone())
|
Some(self.nodes.read().get(path)?.clone())
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn remove_node(&self, path: &str) -> Option<RcCell<Node<'a>>> {
|
pub fn remove_node(&self, path: &str) -> Option<RcCell<Node<'a>>> {
|
||||||
self.nodes.write().unwrap().remove(path)
|
self.nodes.write().remove(path)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user