refactor(core): remove dashmap
This commit is contained in:
14
Cargo.lock
generated
14
Cargo.lock
generated
@@ -530,19 +530,6 @@ dependencies = [
|
||||
"cfg-if",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "dashmap"
|
||||
version = "5.5.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "978747c1d849a7d2ee5e8adc0159961c48fb7e5db2f06af6723b80123bb53856"
|
||||
dependencies = [
|
||||
"cfg-if",
|
||||
"hashbrown 0.14.0",
|
||||
"lock_api",
|
||||
"once_cell",
|
||||
"parking_lot_core 0.9.8",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "directories"
|
||||
version = "5.0.1"
|
||||
@@ -2086,7 +2073,6 @@ dependencies = [
|
||||
"clap",
|
||||
"color-eyre",
|
||||
"console-subscriber",
|
||||
"dashmap",
|
||||
"directories",
|
||||
"glam 0.23.0",
|
||||
"global_counter",
|
||||
|
||||
@@ -39,7 +39,6 @@ lto = true
|
||||
[dependencies]
|
||||
color-eyre = { version = "0.6.2", default-features = false }
|
||||
clap = { version = "4.2.4", features = ["derive"] }
|
||||
dashmap = "5.4.0"
|
||||
glam = { version = "0.23.0", features = ["mint"] }
|
||||
lazy_static = "1.4.0"
|
||||
mint = "0.5.9"
|
||||
|
||||
@@ -2,6 +2,8 @@ use crate::nodes::Node;
|
||||
use crate::{core::client::Client, nodes::Message};
|
||||
use color_eyre::eyre::Result;
|
||||
use once_cell::sync::OnceCell;
|
||||
use parking_lot::Mutex;
|
||||
use rustc_hash::FxHashMap;
|
||||
use stardust_xr::scenegraph;
|
||||
use stardust_xr::scenegraph::ScenegraphError;
|
||||
use std::os::fd::OwnedFd;
|
||||
@@ -9,14 +11,10 @@ use std::sync::{Arc, Weak};
|
||||
use tokio::sync::oneshot;
|
||||
use tracing::{debug, debug_span, instrument};
|
||||
|
||||
use core::hash::BuildHasherDefault;
|
||||
use dashmap::DashMap;
|
||||
use rustc_hash::FxHasher;
|
||||
|
||||
#[derive(Default)]
|
||||
pub struct Scenegraph {
|
||||
pub(super) client: OnceCell<Weak<Client>>,
|
||||
nodes: DashMap<String, Arc<Node>, BuildHasherDefault<FxHasher>>,
|
||||
nodes: Mutex<FxHashMap<String, Arc<Node>>>,
|
||||
}
|
||||
|
||||
impl Scenegraph {
|
||||
@@ -32,12 +30,12 @@ impl Scenegraph {
|
||||
pub fn add_node_raw(&self, node: Arc<Node>) {
|
||||
debug!(node = ?&*node, "Add node");
|
||||
let path = node.get_path().to_string();
|
||||
self.nodes.insert(path, node);
|
||||
self.nodes.lock().insert(path, node);
|
||||
}
|
||||
|
||||
#[instrument(level = "debug", skip(self))]
|
||||
pub fn get_node(&self, path: &str) -> Option<Arc<Node>> {
|
||||
let mut node = self.nodes.get(path)?.clone();
|
||||
let mut node = self.nodes.lock().get(path)?.clone();
|
||||
while let Some(alias) = node.alias.get() {
|
||||
node = alias.original.upgrade()?;
|
||||
}
|
||||
@@ -46,8 +44,7 @@ impl Scenegraph {
|
||||
|
||||
pub fn remove_node(&self, path: &str) -> Option<Arc<Node>> {
|
||||
debug!(path, "Remove node");
|
||||
let (_, node) = self.nodes.remove(path)?;
|
||||
Some(node)
|
||||
self.nodes.lock().remove(path)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -11,13 +11,11 @@ pub mod spatial;
|
||||
pub mod startup;
|
||||
|
||||
use color_eyre::eyre::{eyre, Result};
|
||||
use core::hash::BuildHasherDefault;
|
||||
use dashmap::DashMap;
|
||||
use nanoid::nanoid;
|
||||
use once_cell::sync::OnceCell;
|
||||
use parking_lot::Mutex;
|
||||
use portable_atomic::{AtomicBool, Ordering};
|
||||
use rustc_hash::FxHasher;
|
||||
use rustc_hash::FxHashMap;
|
||||
use stardust_xr::messenger::MessageSenderHandle;
|
||||
use stardust_xr::scenegraph::ScenegraphError;
|
||||
use stardust_xr::schemas::flex::deserialize;
|
||||
@@ -70,8 +68,8 @@ pub struct Node {
|
||||
client: Weak<Client>,
|
||||
message_sender_handle: Option<MessageSenderHandle>,
|
||||
// trailing_slash_pos: usize,
|
||||
local_signals: DashMap<String, Signal, BuildHasherDefault<FxHasher>>,
|
||||
local_methods: DashMap<String, Method, BuildHasherDefault<FxHasher>>,
|
||||
local_signals: Mutex<FxHashMap<String, Signal>>,
|
||||
local_methods: Mutex<FxHashMap<String, Method>>,
|
||||
destroyable: bool,
|
||||
|
||||
pub alias: OnceCell<Arc<Alias>>,
|
||||
@@ -198,10 +196,10 @@ impl Node {
|
||||
}
|
||||
|
||||
pub fn add_local_signal(&self, name: &str, signal: Signal) {
|
||||
self.local_signals.insert(name.to_string(), signal);
|
||||
self.local_signals.lock().insert(name.to_string(), signal);
|
||||
}
|
||||
pub fn add_local_method(&self, name: &str, method: Method) {
|
||||
self.local_methods.insert(name.to_string(), method);
|
||||
self.local_methods.lock().insert(name.to_string(), method);
|
||||
}
|
||||
|
||||
pub fn get_aspect<F, T>(
|
||||
@@ -236,7 +234,9 @@ impl Node {
|
||||
} else {
|
||||
let signal = self
|
||||
.local_signals
|
||||
.lock()
|
||||
.get(method)
|
||||
.cloned()
|
||||
.ok_or(ScenegraphError::SignalNotFound)?;
|
||||
signal(self, calling_client, message).map_err(|error| ScenegraphError::SignalError {
|
||||
error: error.to_string(),
|
||||
@@ -269,7 +269,7 @@ impl Node {
|
||||
response,
|
||||
)
|
||||
} else {
|
||||
let Some(method) = self.local_methods.get(method) else {
|
||||
let Some(method) = self.local_methods.lock().get(method).cloned() else {
|
||||
response.send(Err(ScenegraphError::MethodNotFound));
|
||||
return;
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user