fix: clippy

This commit is contained in:
Nova
2022-10-21 06:21:49 -04:00
parent c42a29a034
commit 1550555df1
9 changed files with 79 additions and 43 deletions

View File

@@ -1,7 +1,7 @@
pub mod client;
pub mod destroy_queue;
pub mod eventloop;
pub mod nodelist;
pub mod node_collections;
pub mod registry;
pub mod resource;
pub mod scenegraph;

View File

@@ -0,0 +1,66 @@
use crate::nodes::Node;
use parking_lot::Mutex;
use rustc_hash::FxHashMap;
use std::{
hash::Hash,
sync::{Arc, Weak},
};
#[derive(Default)]
pub struct LifeLinkedNodeList {
nodes: Mutex<Vec<Weak<Node>>>,
}
impl LifeLinkedNodeList {
pub fn add(&self, node: Weak<Node>) {
self.nodes.lock().push(node);
}
pub fn clear(&self) {
self.nodes
.lock()
.iter()
.filter_map(|node| node.upgrade())
.for_each(|node| {
node.destroy();
});
self.nodes.lock().clear();
}
}
impl Drop for LifeLinkedNodeList {
fn drop(&mut self) {
self.clear();
}
}
#[derive(Default)]
pub struct LifeLinkedNodeMap<K: Hash + Eq> {
nodes: Mutex<FxHashMap<K, Weak<Node>>>,
}
#[allow(dead_code)]
impl<K: Hash + Eq> LifeLinkedNodeMap<K> {
pub fn add(&self, key: K, node: &Arc<Node>) {
self.nodes.lock().insert(key, Arc::downgrade(node));
}
pub fn get(&self, key: &K) -> Option<Arc<Node>> {
self.nodes.lock().get(key).and_then(|n| n.upgrade())
}
pub fn remove(&self, key: &K) -> Option<Arc<Node>> {
self.nodes.lock().remove(key).and_then(|n| n.upgrade())
}
pub fn clear(&self) {
let mut nodes = self.nodes.lock();
nodes
.values()
.filter_map(|node| node.upgrade())
.for_each(|node| {
node.destroy();
});
nodes.clear();
}
}
impl<K: Hash + Eq> Drop for LifeLinkedNodeMap<K> {
fn drop(&mut self) {
self.clear();
}
}

View File

@@ -1,29 +0,0 @@
use crate::nodes::Node;
use parking_lot::Mutex;
use std::sync::Weak;
#[derive(Default)]
pub struct LifeLinkedNodeList {
nodes: Mutex<Vec<Weak<Node>>>,
}
impl LifeLinkedNodeList {
pub fn add(&self, node: Weak<Node>) {
self.nodes.lock().push(node);
}
pub fn clear(&self) {
self.nodes
.lock()
.iter()
.filter_map(|node| node.upgrade())
.for_each(|node| {
node.destroy();
});
self.nodes.lock().clear();
}
}
impl Drop for LifeLinkedNodeList {
fn drop(&mut self) {
self.clear();
}
}

View File

@@ -18,7 +18,7 @@ pub struct Alias {
pub info: AliasInfo,
}
impl Alias {
pub fn new(
pub fn create(
client: &Arc<Client>,
parent: &str,
name: &str,

View File

@@ -206,7 +206,7 @@ pub fn ray_march(ray: Ray, field: &Field) -> RayMarchResult {
}
pub fn find_field(client: &Client, path: &str) -> Result<Arc<Field>> {
Ok(client
client
.get_node("Field", path)?
.get_aspect("Field", "info", |n| &n.field)?)
.get_aspect("Field", "info", |n| &n.field)
}

View File

@@ -29,7 +29,7 @@ pub fn frame(sk: &StereoKit) {
}
pub fn make_alias(client: &Arc<Client>) -> Arc<Node> {
Alias::new(
Alias::create(
client,
"",
"hmd",

View File

@@ -5,7 +5,7 @@ use super::fields::Field;
use super::spatial::{find_spatial_parent, parse_transform, Spatial};
use super::{Alias, Node};
use crate::core::client::{Client, INTERNAL_CLIENT};
use crate::core::nodelist::LifeLinkedNodeList;
use crate::core::node_collections::LifeLinkedNodeList;
use crate::core::registry::Registry;
use crate::nodes::alias::AliasInfo;
use crate::nodes::fields::find_field;
@@ -121,7 +121,7 @@ impl Item {
item
}
fn make_alias(&self, client: &Arc<Client>, parent: &str) -> (Arc<Node>, Arc<Alias>) {
let node = Alias::new(
let node = Alias::create(
client,
parent,
&self.uid,
@@ -273,7 +273,7 @@ impl ItemAcceptor {
fn make_aliases(&self, client: &Arc<Client>, parent: &str) -> Vec<Arc<Node>> {
let mut aliases = Vec::new();
let acceptor_node = &self.node.upgrade().unwrap();
let acceptor_alias = Alias::new(
let acceptor_alias = Alias::create(
client,
parent,
acceptor_node.uid.as_str(),
@@ -284,7 +284,7 @@ impl ItemAcceptor {
},
);
if let Some(field) = self.field.lock().upgrade() {
let acceptor_field_alias = Alias::new(
let acceptor_field_alias = Alias::create(
client,
acceptor_alias.get_path(),
"field",

View File

@@ -18,7 +18,7 @@ use std::sync::{Arc, Weak};
static ZONEABLE_REGISTRY: Registry<Spatial> = Registry::new();
pub struct Spatial {
pub(self) uid: String,
uid: String,
pub(super) node: Weak<Node>,
parent: Mutex<Option<Arc<Spatial>>>,
pub(self) old_parent: Mutex<Option<Arc<Spatial>>>,
@@ -296,10 +296,9 @@ pub fn find_spatial(
node_name: &'static str,
node_path: &str,
) -> anyhow::Result<Arc<Spatial>> {
Ok(calling_client
calling_client
.get_node(node_name, node_path)?
.get_aspect(node_name, "spatial", |n| &n.spatial)?
.clone())
.get_aspect(node_name, "spatial", |n| &n.spatial)
}
pub fn find_spatial_parent(
calling_client: &Arc<Client>,

View File

@@ -111,7 +111,7 @@ impl Zone {
self_zone_distance < 0.0 && spatial_zone_distance > self_zone_distance
})
.map(|zoneable| {
let alias = Alias::new(
let alias = Alias::create(
&zone_client,
zone_node.get_path(),
&zoneable.uid,