refactor(model): move into drawable

This commit is contained in:
Nova
2022-09-25 03:41:36 -04:00
parent 0e09aae9f8
commit 69f7a432d5
7 changed files with 77 additions and 55 deletions

View File

@@ -1,7 +1,7 @@
use super::{eventloop::EventLoop, scenegraph::Scenegraph};
use crate::{
core::registry::Registry,
nodes::{data, fields, hmd, input, items, model, root::Root, spatial, startup},
nodes::{data, drawable, fields, hmd, input, items, root::Root, spatial, startup},
};
use anyhow::Result;
use lazy_static::lazy_static;
@@ -67,7 +67,7 @@ impl Client {
hmd::make_alias(&client);
spatial::create_interface(&client);
fields::create_interface(&client);
model::create_interface(&client);
drawable::create_interface(&client);
data::create_interface(&client);
items::create_interface(&client);
input::create_interface(&client);

View File

@@ -7,13 +7,16 @@ use once_cell::sync::Lazy;
use parking_lot::Mutex;
use rustc_hash::FxHashMap;
pub struct Registry<T>(Lazy<Mutex<FxHashMap<usize, Weak<T>>>>);
pub struct Registry<T: Send + Sync + ?Sized>(Lazy<Mutex<FxHashMap<usize, Weak<T>>>>);
impl<T: Send + Sync> Registry<T> {
impl<T: Send + Sync + ?Sized> Registry<T> {
pub const fn new() -> Self {
Registry(Lazy::new(|| Mutex::new(FxHashMap::default())))
}
pub fn add(&self, t: T) -> Arc<T> {
pub fn add(&self, t: T) -> Arc<T>
where
T: Sized,
{
let t_arc = Arc::new(t);
self.add_raw(&t_arc);
t_arc
@@ -21,7 +24,7 @@ impl<T: Send + Sync> Registry<T> {
pub fn add_raw(&self, t: &Arc<T>) {
self.0
.lock()
.insert(Arc::as_ptr(t) as usize, Arc::downgrade(t));
.insert(Arc::as_ptr(t) as *const () as usize, Arc::downgrade(t));
}
pub fn get_valid_contents(&self) -> Vec<Arc<T>> {
self.0
@@ -31,7 +34,9 @@ impl<T: Send + Sync> Registry<T> {
.collect()
}
pub fn remove(&self, t: &T) {
self.0.lock().remove(&(ptr::addr_of!(*t) as usize));
self.0
.lock()
.remove(&(ptr::addr_of!(*t) as *const () as usize));
}
pub fn clear(&self) {
self.0.lock().clear();