feat: disabled/enabled
This commit is contained in:
@@ -9,6 +9,7 @@ use color_eyre::eyre::{bail, ensure, Result};
|
|||||||
use glam::Vec3A;
|
use glam::Vec3A;
|
||||||
use mint::Vector3;
|
use mint::Vector3;
|
||||||
use parking_lot::Mutex;
|
use parking_lot::Mutex;
|
||||||
|
use portable_atomic::{AtomicBool, Ordering};
|
||||||
use prisma::{Flatten, Lerp, Rgba};
|
use prisma::{Flatten, Lerp, Rgba};
|
||||||
use serde::Deserialize;
|
use serde::Deserialize;
|
||||||
use stardust_xr::{schemas::flex::deserialize, values::Transform};
|
use stardust_xr::{schemas::flex::deserialize, values::Transform};
|
||||||
@@ -33,6 +34,7 @@ struct LineData {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub struct Lines {
|
pub struct Lines {
|
||||||
|
enabled: Arc<AtomicBool>,
|
||||||
space: Arc<Spatial>,
|
space: Arc<Spatial>,
|
||||||
data: Mutex<LineData>,
|
data: Mutex<LineData>,
|
||||||
}
|
}
|
||||||
@@ -44,6 +46,7 @@ impl Lines {
|
|||||||
);
|
);
|
||||||
|
|
||||||
let lines = LINES_REGISTRY.add(Lines {
|
let lines = LINES_REGISTRY.add(Lines {
|
||||||
|
enabled: node.enabled.clone(),
|
||||||
space: node.get_aspect("Lines", "spatial", |n| &n.spatial)?.clone(),
|
space: node.get_aspect("Lines", "spatial", |n| &n.spatial)?.clone(),
|
||||||
data: Mutex::new(LineData { points, cyclic }),
|
data: Mutex::new(LineData { points, cyclic }),
|
||||||
});
|
});
|
||||||
@@ -112,7 +115,9 @@ impl Drop for Lines {
|
|||||||
|
|
||||||
pub fn draw_all(draw_ctx: &StereoKitDraw) {
|
pub fn draw_all(draw_ctx: &StereoKitDraw) {
|
||||||
for lines in LINES_REGISTRY.get_valid_contents() {
|
for lines in LINES_REGISTRY.get_valid_contents() {
|
||||||
lines.draw(draw_ctx);
|
if lines.enabled.load(Ordering::Relaxed) {
|
||||||
|
lines.draw(draw_ctx);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -9,6 +9,7 @@ use color_eyre::eyre::{bail, ensure, eyre, Result};
|
|||||||
use mint::{ColumnMatrix4, Vector2, Vector3, Vector4};
|
use mint::{ColumnMatrix4, Vector2, Vector3, Vector4};
|
||||||
use once_cell::sync::OnceCell;
|
use once_cell::sync::OnceCell;
|
||||||
use parking_lot::Mutex;
|
use parking_lot::Mutex;
|
||||||
|
use portable_atomic::{AtomicBool, Ordering};
|
||||||
use rustc_hash::FxHashMap;
|
use rustc_hash::FxHashMap;
|
||||||
use send_wrapper::SendWrapper;
|
use send_wrapper::SendWrapper;
|
||||||
use serde::Deserialize;
|
use serde::Deserialize;
|
||||||
@@ -117,6 +118,7 @@ impl MaterialParameter {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub struct Model {
|
pub struct Model {
|
||||||
|
enabled: Arc<AtomicBool>,
|
||||||
space: Arc<Spatial>,
|
space: Arc<Spatial>,
|
||||||
resource_id: ResourceID,
|
resource_id: ResourceID,
|
||||||
pending_model_path: OnceCell<PathBuf>,
|
pending_model_path: OnceCell<PathBuf>,
|
||||||
@@ -136,6 +138,7 @@ impl Model {
|
|||||||
"Internal: Node already has a drawable attached!"
|
"Internal: Node already has a drawable attached!"
|
||||||
);
|
);
|
||||||
let model = Model {
|
let model = Model {
|
||||||
|
enabled: node.enabled.clone(),
|
||||||
space: node.spatial.get().unwrap().clone(),
|
space: node.spatial.get().unwrap().clone(),
|
||||||
resource_id,
|
resource_id,
|
||||||
pending_model_path: OnceCell::new(),
|
pending_model_path: OnceCell::new(),
|
||||||
@@ -244,7 +247,9 @@ impl Drop for Model {
|
|||||||
|
|
||||||
pub fn draw_all(sk: &StereoKitDraw) {
|
pub fn draw_all(sk: &StereoKitDraw) {
|
||||||
for model in MODEL_REGISTRY.get_valid_contents() {
|
for model in MODEL_REGISTRY.get_valid_contents() {
|
||||||
model.draw(sk);
|
if model.enabled.load(Ordering::Relaxed) {
|
||||||
|
model.draw(sk);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -11,6 +11,7 @@ use glam::{vec3, Mat4, Vec2};
|
|||||||
use mint::Vector2;
|
use mint::Vector2;
|
||||||
use once_cell::sync::OnceCell;
|
use once_cell::sync::OnceCell;
|
||||||
use parking_lot::Mutex;
|
use parking_lot::Mutex;
|
||||||
|
use portable_atomic::{AtomicBool, Ordering};
|
||||||
use prisma::{Flatten, Rgba};
|
use prisma::{Flatten, Rgba};
|
||||||
use send_wrapper::SendWrapper;
|
use send_wrapper::SendWrapper;
|
||||||
use serde::Deserialize;
|
use serde::Deserialize;
|
||||||
@@ -37,6 +38,7 @@ struct TextData {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub struct Text {
|
pub struct Text {
|
||||||
|
enabled: Arc<AtomicBool>,
|
||||||
space: Arc<Spatial>,
|
space: Arc<Spatial>,
|
||||||
font_path: Option<PathBuf>,
|
font_path: Option<PathBuf>,
|
||||||
style: OnceCell<SendWrapper<TextStyle>>,
|
style: OnceCell<SendWrapper<TextStyle>>,
|
||||||
@@ -67,6 +69,7 @@ impl Text {
|
|||||||
|
|
||||||
let client = node.get_client().ok_or_else(|| eyre!("Client not found"))?;
|
let client = node.get_client().ok_or_else(|| eyre!("Client not found"))?;
|
||||||
let text = TEXT_REGISTRY.add(Text {
|
let text = TEXT_REGISTRY.add(Text {
|
||||||
|
enabled: node.enabled.clone(),
|
||||||
space: node.spatial.get().unwrap().clone(),
|
space: node.spatial.get().unwrap().clone(),
|
||||||
font_path: font_resource_id.and_then(|res| {
|
font_path: font_resource_id.and_then(|res| {
|
||||||
res.get_file(
|
res.get_file(
|
||||||
@@ -170,7 +173,9 @@ impl Drop for Text {
|
|||||||
|
|
||||||
pub fn draw_all(sk: &StereoKitDraw) {
|
pub fn draw_all(sk: &StereoKitDraw) {
|
||||||
for text in TEXT_REGISTRY.get_valid_contents() {
|
for text in TEXT_REGISTRY.get_valid_contents() {
|
||||||
text.draw(sk);
|
if text.enabled.load(Ordering::Relaxed) {
|
||||||
|
text.draw(sk);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -18,6 +18,7 @@ use color_eyre::eyre::{ensure, Result};
|
|||||||
use glam::Mat4;
|
use glam::Mat4;
|
||||||
use nanoid::nanoid;
|
use nanoid::nanoid;
|
||||||
use parking_lot::Mutex;
|
use parking_lot::Mutex;
|
||||||
|
use portable_atomic::AtomicBool;
|
||||||
use serde::Deserialize;
|
use serde::Deserialize;
|
||||||
use stardust_xr::schemas::flat::{Datamap, InputDataType};
|
use stardust_xr::schemas::flat::{Datamap, InputDataType};
|
||||||
use stardust_xr::schemas::{flat::InputData, flex::deserialize};
|
use stardust_xr::schemas::{flat::InputData, flex::deserialize};
|
||||||
@@ -166,6 +167,7 @@ impl DistanceLink {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub struct InputHandler {
|
pub struct InputHandler {
|
||||||
|
enabled: Arc<AtomicBool>,
|
||||||
node: Weak<Node>,
|
node: Weak<Node>,
|
||||||
spatial: Arc<Spatial>,
|
spatial: Arc<Spatial>,
|
||||||
pub field: Weak<Field>,
|
pub field: Weak<Field>,
|
||||||
@@ -178,6 +180,7 @@ impl InputHandler {
|
|||||||
);
|
);
|
||||||
|
|
||||||
let handler = InputHandler {
|
let handler = InputHandler {
|
||||||
|
enabled: node.enabled.clone(),
|
||||||
node: Arc::downgrade(node),
|
node: Arc::downgrade(node),
|
||||||
spatial: node.spatial.get().unwrap().clone(),
|
spatial: node.spatial.get().unwrap().clone(),
|
||||||
field: Arc::downgrade(field),
|
field: Arc::downgrade(field),
|
||||||
@@ -266,15 +269,18 @@ pub fn process_input() {
|
|||||||
.filter(|method| *method.enabled.lock())
|
.filter(|method| *method.enabled.lock())
|
||||||
.filter(|method| method.datamap.lock().is_some())
|
.filter(|method| method.datamap.lock().is_some())
|
||||||
});
|
});
|
||||||
|
let handlers = INPUT_HANDLER_REGISTRY
|
||||||
|
.get_valid_contents()
|
||||||
|
.into_iter()
|
||||||
|
.filter(|handler| handler.enabled.load(Ordering::Relaxed))
|
||||||
|
.filter(|handler| handler.field.upgrade().is_some());
|
||||||
for method in methods {
|
for method in methods {
|
||||||
debug_span!("Process input method").in_scope(|| {
|
debug_span!("Process input method").in_scope(|| {
|
||||||
// Get all valid input handlers and convert them to DistanceLink objects
|
// Get all valid input handlers and convert them to DistanceLink objects
|
||||||
let mut distance_links: Vec<DistanceLink> = debug_span!("Generate distance links")
|
let mut distance_links: Vec<DistanceLink> = debug_span!("Generate distance links")
|
||||||
.in_scope(|| {
|
.in_scope(|| {
|
||||||
INPUT_HANDLER_REGISTRY
|
handlers
|
||||||
.get_valid_contents()
|
.clone()
|
||||||
.into_iter()
|
|
||||||
.filter(|handler| handler.field.upgrade().is_some())
|
|
||||||
.filter_map(|handler| DistanceLink::from(method.clone(), handler))
|
.filter_map(|handler| DistanceLink::from(method.clone(), handler))
|
||||||
.collect()
|
.collect()
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -15,6 +15,7 @@ use color_eyre::eyre::{ensure, eyre, Result};
|
|||||||
use lazy_static::lazy_static;
|
use lazy_static::lazy_static;
|
||||||
use nanoid::nanoid;
|
use nanoid::nanoid;
|
||||||
use parking_lot::Mutex;
|
use parking_lot::Mutex;
|
||||||
|
use portable_atomic::Ordering;
|
||||||
use serde::Deserialize;
|
use serde::Deserialize;
|
||||||
use stardust_xr::schemas::flex::{deserialize, serialize};
|
use stardust_xr::schemas::flex::{deserialize, serialize};
|
||||||
use stardust_xr::values::Transform;
|
use stardust_xr::values::Transform;
|
||||||
@@ -307,6 +308,10 @@ impl ItemAcceptor {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn capture_flex(node: &Node, calling_client: Arc<Client>, data: &[u8]) -> Result<()> {
|
fn capture_flex(node: &Node, calling_client: Arc<Client>, data: &[u8]) -> Result<()> {
|
||||||
|
if !node.enabled.load(Ordering::Relaxed) {
|
||||||
|
return Ok(());
|
||||||
|
}
|
||||||
|
|
||||||
let acceptor = node.item_acceptor.get().unwrap();
|
let acceptor = node.item_acceptor.get().unwrap();
|
||||||
let item_path: &str = deserialize(data)?;
|
let item_path: &str = deserialize(data)?;
|
||||||
let item_node = calling_client.get_node("Item", item_path)?;
|
let item_node = calling_client.get_node("Item", item_path)?;
|
||||||
|
|||||||
@@ -11,22 +11,22 @@ pub mod spatial;
|
|||||||
pub mod startup;
|
pub mod startup;
|
||||||
|
|
||||||
use color_eyre::eyre::{eyre, Result};
|
use color_eyre::eyre::{eyre, Result};
|
||||||
|
use core::hash::BuildHasherDefault;
|
||||||
|
use dashmap::DashMap;
|
||||||
use nanoid::nanoid;
|
use nanoid::nanoid;
|
||||||
use once_cell::sync::OnceCell;
|
use once_cell::sync::OnceCell;
|
||||||
use parking_lot::Mutex;
|
use parking_lot::Mutex;
|
||||||
|
use portable_atomic::{AtomicBool, Ordering};
|
||||||
|
use rustc_hash::FxHasher;
|
||||||
use stardust_xr::messenger::MessageSenderHandle;
|
use stardust_xr::messenger::MessageSenderHandle;
|
||||||
use stardust_xr::scenegraph::ScenegraphError;
|
use stardust_xr::scenegraph::ScenegraphError;
|
||||||
|
use stardust_xr::schemas::flex::deserialize;
|
||||||
use std::fmt::Debug;
|
use std::fmt::Debug;
|
||||||
use std::future::Future;
|
use std::future::Future;
|
||||||
use std::sync::atomic::{AtomicBool, Ordering};
|
|
||||||
use std::sync::{Arc, Weak};
|
use std::sync::{Arc, Weak};
|
||||||
use std::vec::Vec;
|
use std::vec::Vec;
|
||||||
use tracing::{debug_span, instrument};
|
use tracing::{debug_span, instrument};
|
||||||
|
|
||||||
use core::hash::BuildHasherDefault;
|
|
||||||
use dashmap::DashMap;
|
|
||||||
use rustc_hash::FxHasher;
|
|
||||||
|
|
||||||
use crate::core::client::Client;
|
use crate::core::client::Client;
|
||||||
use crate::core::registry::Registry;
|
use crate::core::registry::Registry;
|
||||||
|
|
||||||
@@ -45,6 +45,7 @@ pub type Signal = fn(&Node, Arc<Client>, &[u8]) -> Result<()>;
|
|||||||
pub type Method = fn(&Node, Arc<Client>, &[u8]) -> Result<Vec<u8>>;
|
pub type Method = fn(&Node, Arc<Client>, &[u8]) -> Result<Vec<u8>>;
|
||||||
|
|
||||||
pub struct Node {
|
pub struct Node {
|
||||||
|
pub enabled: Arc<AtomicBool>,
|
||||||
pub(super) uid: String,
|
pub(super) uid: String,
|
||||||
path: String,
|
path: String,
|
||||||
client: Weak<Client>,
|
client: Weak<Client>,
|
||||||
@@ -52,7 +53,7 @@ pub struct Node {
|
|||||||
// trailing_slash_pos: usize,
|
// trailing_slash_pos: usize,
|
||||||
local_signals: DashMap<String, Signal, BuildHasherDefault<FxHasher>>,
|
local_signals: DashMap<String, Signal, BuildHasherDefault<FxHasher>>,
|
||||||
local_methods: DashMap<String, Method, BuildHasherDefault<FxHasher>>,
|
local_methods: DashMap<String, Method, BuildHasherDefault<FxHasher>>,
|
||||||
destroyable: AtomicBool,
|
destroyable: bool,
|
||||||
|
|
||||||
pub alias: OnceCell<Arc<Alias>>,
|
pub alias: OnceCell<Arc<Alias>>,
|
||||||
aliases: Registry<Alias>,
|
aliases: Registry<Alias>,
|
||||||
@@ -94,15 +95,13 @@ impl Node {
|
|||||||
pub fn get_path(&self) -> &str {
|
pub fn get_path(&self) -> &str {
|
||||||
self.path.as_str()
|
self.path.as_str()
|
||||||
}
|
}
|
||||||
pub fn is_destroyable(&self) -> bool {
|
|
||||||
self.destroyable.load(Ordering::Relaxed)
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn create(client: &Arc<Client>, parent: &str, name: &str, destroyable: bool) -> Self {
|
pub fn create(client: &Arc<Client>, parent: &str, name: &str, destroyable: bool) -> Self {
|
||||||
let mut path = parent.to_string();
|
let mut path = parent.to_string();
|
||||||
path.push('/');
|
path.push('/');
|
||||||
path.push_str(name);
|
path.push_str(name);
|
||||||
let node = Node {
|
let node = Node {
|
||||||
|
enabled: Arc::new(AtomicBool::new(true)),
|
||||||
uid: nanoid!(),
|
uid: nanoid!(),
|
||||||
client: Arc::downgrade(client),
|
client: Arc::downgrade(client),
|
||||||
message_sender_handle: client.message_sender_handle.clone(),
|
message_sender_handle: client.message_sender_handle.clone(),
|
||||||
@@ -110,7 +109,7 @@ impl Node {
|
|||||||
// trailing_slash_pos: parent.len(),
|
// trailing_slash_pos: parent.len(),
|
||||||
local_signals: Default::default(),
|
local_signals: Default::default(),
|
||||||
local_methods: Default::default(),
|
local_methods: Default::default(),
|
||||||
destroyable: AtomicBool::from(destroyable),
|
destroyable,
|
||||||
|
|
||||||
alias: OnceCell::new(),
|
alias: OnceCell::new(),
|
||||||
aliases: Registry::new(),
|
aliases: Registry::new(),
|
||||||
@@ -129,6 +128,7 @@ impl Node {
|
|||||||
sound: OnceCell::new(),
|
sound: OnceCell::new(),
|
||||||
startup_settings: OnceCell::new(),
|
startup_settings: OnceCell::new(),
|
||||||
};
|
};
|
||||||
|
node.add_local_signal("set_enabled", Node::set_enabled_flex);
|
||||||
node.add_local_signal("destroy", Node::destroy_flex);
|
node.add_local_signal("destroy", Node::destroy_flex);
|
||||||
node
|
node
|
||||||
}
|
}
|
||||||
@@ -145,8 +145,12 @@ impl Node {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn set_enabled_flex(node: &Node, _calling_client: Arc<Client>, data: &[u8]) -> Result<()> {
|
||||||
|
node.enabled.store(deserialize(data)?, Ordering::Relaxed);
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
pub fn destroy_flex(node: &Node, _calling_client: Arc<Client>, _data: &[u8]) -> Result<()> {
|
pub fn destroy_flex(node: &Node, _calling_client: Arc<Client>, _data: &[u8]) -> Result<()> {
|
||||||
if node.is_destroyable() {
|
if node.destroyable {
|
||||||
node.destroy();
|
node.destroy();
|
||||||
}
|
}
|
||||||
Ok(())
|
Ok(())
|
||||||
|
|||||||
Reference in New Issue
Block a user