feat(registry): const initialization meaning no necessary lazy_static

This commit is contained in:
Nova
2022-08-17 19:28:52 -04:00
parent 85077146d3
commit c272cfaed1
7 changed files with 17 additions and 28 deletions

View File

@@ -74,7 +74,7 @@ impl Node {
destroyable: AtomicBool::from(destroyable),
alias: OnceCell::new(),
aliases: Default::default(),
aliases: Registry::new(),
spatial: OnceCell::new(),
field: OnceCell::new(),

View File

@@ -6,16 +6,13 @@ use crate::core::nodelist::LifeLinkedNodeList;
use crate::core::registry::Registry;
use anyhow::{anyhow, ensure, Result};
use glam::{vec3a, Mat4};
use lazy_static::lazy_static;
use libstardustxr::flex::flexbuffer_from_vector_arguments;
use libstardustxr::{flex_to_quat, flex_to_vec3};
use parking_lot::Mutex;
use std::sync::{Arc, Weak};
lazy_static! {
static ref PULSE_SENDER_REGISTRY: Registry<PulseSender> = Default::default();
static ref PULSE_RECEIVER_REGISTRY: Registry<PulseReceiver> = Default::default();
}
static PULSE_SENDER_REGISTRY: Registry<PulseSender> = Registry::new();
static PULSE_RECEIVER_REGISTRY: Registry<PulseReceiver> = Registry::new();
fn mask_matches(mask_map_lesser: &Mask, mask_map_greater: &Mask) -> bool {
(|| -> Result<_> {

View File

@@ -6,16 +6,13 @@ use crate::core::eventloop::FRAME;
use crate::core::registry::Registry;
use anyhow::{anyhow, ensure, Result};
use glam::Mat4;
use lazy_static::lazy_static;
use libstardustxr::schemas::input::{InputData, InputDataArgs, InputDataRaw};
use std::ops::Deref;
use std::sync::atomic::Ordering;
use std::sync::{Arc, Weak};
lazy_static! {
static ref INPUT_METHOD_REGISTRY: Registry<InputMethod> = Default::default();
static ref INPUT_HANDLER_REGISTRY: Registry<InputHandler> = Default::default();
}
static INPUT_METHOD_REGISTRY: Registry<InputMethod> = Registry::new();
static INPUT_HANDLER_REGISTRY: Registry<InputHandler> = Registry::new();
pub trait InputSpecializationTrait {
fn distance(&self, space: &Arc<Spatial>, field: &Field) -> f32;

View File

@@ -29,8 +29,8 @@ lazy_static! {
aliased_remote_signals: vec![],
aliased_remote_methods: vec![],
ui: Default::default(),
items: Default::default(),
acceptors: Default::default(),
items: Registry::new(),
acceptors: Registry::new(),
};
static ref ITEM_TYPE_INFO_PANEL: TypeInfo = TypeInfo {
type_name: "panel",
@@ -55,8 +55,8 @@ lazy_static! {
aliased_remote_signals: vec![],
aliased_remote_methods: vec![],
ui: Default::default(),
items: Default::default(),
acceptors: Default::default(),
items: Registry::new(),
acceptors: Registry::new(),
};
}
@@ -268,7 +268,7 @@ impl ItemAcceptor {
node: Arc::downgrade(node),
type_info,
field: Mutex::new(field),
accepted: Default::default(),
accepted: Registry::new(),
});
if let Some(ui) = type_info.ui.lock().upgrade() {
ui.handle_create_acceptor(&acceptor);

View File

@@ -18,8 +18,8 @@ use stereokit::lifecycle::DrawContext;
use stereokit::model::Model as SKModel;
use stereokit::StereoKit;
pub static MODEL_REGISTRY: Registry<Model> = Registry::new();
lazy_static! {
pub static ref MODEL_REGISTRY: Registry<Model> = Default::default();
pub static ref MODELS_TO_DROP: Mutex<Vec<SendWrapper<SKModel>>> = Default::default();
}

View File

@@ -4,14 +4,11 @@ use crate::core::client::Client;
use crate::core::registry::Registry;
use anyhow::Result;
use glam::Mat4;
use lazy_static::lazy_static;
use libstardustxr::flex::flexbuffer_from_vector_arguments;
use std::sync::atomic::{AtomicBool, Ordering};
use std::sync::Arc;
lazy_static! {
static ref ROOT_REGISTRY: Registry<Root> = Default::default();
}
static ROOT_REGISTRY: Registry<Root> = Registry::new();
pub struct Root {
node: Arc<Node>,