From c5b12d36e0ce47841c283b78103db69ab8f18aa8 Mon Sep 17 00:00:00 2001 From: Nova Date: Tue, 5 Mar 2024 18:59:02 -0500 Subject: [PATCH] feat: update idl --- Cargo.lock | 4 +- codegen/src/lib.rs | 20 +++++-- src/nodes/data.rs | 10 ++-- src/nodes/input/method.rs | 4 +- src/nodes/items/environment.rs | 97 ---------------------------------- src/nodes/items/mod.rs | 9 ---- 6 files changed, 27 insertions(+), 117 deletions(-) delete mode 100644 src/nodes/items/environment.rs diff --git a/Cargo.lock b/Cargo.lock index fbc33c2e..f76db9b7 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2032,7 +2032,7 @@ checksum = "2f2b15926089e5526bb2dd738a2eb0e59034356e06eb71e1cd912358c0e62c4d" [[package]] name = "stardust-xr" version = "0.44.0" -source = "git+https://github.com/StardustXR/core.git#c587446076b92d8a945f4d0e2a872c09f80cc575" +source = "git+https://github.com/StardustXR/core.git#5d54c48d091544f6dc15adf4cef0af59418c5833" dependencies = [ "cluFlock", "color-rs", @@ -2052,7 +2052,7 @@ dependencies = [ [[package]] name = "stardust-xr-schemas" version = "1.5.3" -source = "git+https://github.com/StardustXR/core.git#c587446076b92d8a945f4d0e2a872c09f80cc575" +source = "git+https://github.com/StardustXR/core.git#5d54c48d091544f6dc15adf4cef0af59418c5833" dependencies = [ "flatbuffers", "flexbuffers", diff --git a/codegen/src/lib.rs b/codegen/src/lib.rs index 0e9bf87e..cad0ef0d 100644 --- a/codegen/src/lib.rs +++ b/codegen/src/lib.rs @@ -40,6 +40,10 @@ pub fn codegen_drawable_protocol(_input: proc_macro::TokenStream) -> proc_macro: pub fn codegen_input_protocol(_input: proc_macro::TokenStream) -> proc_macro::TokenStream { codegen_protocol(INPUT_PROTOCOL) } +#[proc_macro] +pub fn codegen_items_protocol(_input: proc_macro::TokenStream) -> proc_macro::TokenStream { + codegen_protocol(ITEM_PROTOCOL) +} fn codegen_protocol(protocol: &'static str) -> proc_macro::TokenStream { let protocol = Protocol::parse(protocol).unwrap(); @@ -462,12 +466,13 @@ fn generate_argument_decl(argument: &Argument, owned_values: bool) -> TokenStrea } fn argument_type_option_name(argument_type: &ArgumentType) -> String { match argument_type { + ArgumentType::Empty => "Empty".to_string(), ArgumentType::Bool => "Bool".to_string(), ArgumentType::Int => "Int".to_string(), ArgumentType::UInt => "UInt".to_string(), ArgumentType::Float => "Float".to_string(), - ArgumentType::Vec2 => "Vec2".to_string(), - ArgumentType::Vec3 => "Vec3".to_string(), + ArgumentType::Vec2(_) => "Vec2".to_string(), + ArgumentType::Vec3(_) => "Vec3".to_string(), ArgumentType::Quat => "Quat".to_string(), ArgumentType::Color => "Color".to_string(), ArgumentType::String => "String".to_string(), @@ -488,12 +493,19 @@ fn generate_argument_type( owned: bool, ) -> TokenStream { let _type = match argument_type { + ArgumentType::Empty => quote!(()), ArgumentType::Bool => quote!(bool), ArgumentType::Int => quote!(i32), ArgumentType::UInt => quote!(u32), ArgumentType::Float => quote!(f32), - ArgumentType::Vec2 => quote!(mint::Vector2), - ArgumentType::Vec3 => quote!(mint::Vector3), + ArgumentType::Vec2(c) => { + let component = generate_argument_type(c, false, true); + quote!(mint::Vector2<#component>) + } + ArgumentType::Vec3(c) => { + let component = generate_argument_type(c, false, true); + quote!(mint::Vector3<#component>) + } ArgumentType::Quat => quote!(mint::Quaternion), ArgumentType::Color => quote!(stardust_xr::values::Color), ArgumentType::Bytes => { diff --git a/src/nodes/data.rs b/src/nodes/data.rs index 7a21e2cc..dbca0edd 100644 --- a/src/nodes/data.rs +++ b/src/nodes/data.rs @@ -117,8 +117,12 @@ impl PulseSender { self.aliases .add(receiver.uid.clone() + "-field", &rx_field_alias); - let _ = - pulse_sender_client::new_receiver(&tx_node, &receiver.uid, &rx_alias, &rx_field_alias); + let _ = pulse_sender_client::create_receiver( + &tx_node, + &receiver.uid, + &rx_alias, + &rx_field_alias, + ); } fn handle_drop_receiver(&self, receiver: &PulseReceiver) { @@ -128,7 +132,7 @@ impl PulseSender { let Some(tx_node) = self.node.upgrade() else { return; }; - let _ = pulse_sender_client::drop_receiver(&tx_node, uid); + let _ = pulse_sender_client::destroy_receiver(&tx_node, uid); } } impl Aspect for PulseSender { diff --git a/src/nodes/input/method.rs b/src/nodes/input/method.rs index 0d716c12..aeff0163 100644 --- a/src/nodes/input/method.rs +++ b/src/nodes/input/method.rs @@ -137,7 +137,7 @@ impl InputMethod { .add(handler.uid.clone() + "-field", &rx_field_alias); } - let _ = input_method_client::new_handler(&method_node, &handler.uid, &handler_node); + let _ = input_method_client::create_handler(&method_node, &handler.uid, &handler_node); } pub(super) fn handle_drop_handler(&self, handler: &InputHandler) { let uid = handler.uid.as_str(); @@ -147,7 +147,7 @@ impl InputMethod { return; }; - let _ = input_method_client::drop_handler(&tx_node, &uid); + let _ = input_method_client::destroy_handler(&tx_node, &uid); } } impl Aspect for InputMethod { diff --git a/src/nodes/items/environment.rs b/src/nodes/items/environment.rs deleted file mode 100644 index 753c1cdb..00000000 --- a/src/nodes/items/environment.rs +++ /dev/null @@ -1,97 +0,0 @@ -use super::{Item, ItemType}; -use crate::{ - core::{ - client::{Client, INTERNAL_CLIENT}, - registry::Registry, - scenegraph::MethodResponseSender, - }, - nodes::{ - items::TypeInfo, - spatial::{parse_transform, Spatial, Transform}, - Message, Node, - }, -}; -use color_eyre::eyre::{eyre, Result}; -use lazy_static::lazy_static; -use nanoid::nanoid; -use serde::Deserialize; -use stardust_xr::schemas::flex::{deserialize, serialize}; -use std::sync::Arc; - -lazy_static! { - pub(super) static ref ITEM_TYPE_INFO_ENVIRONMENT: TypeInfo = TypeInfo { - type_name: "environment", - aliased_local_signals: vec!["apply_sky_tex", "apply_sky_light"], - aliased_local_methods: vec![], - aliased_remote_signals: vec![], - ui: Default::default(), - items: Registry::new(), - acceptors: Registry::new(), - }; -} - -pub struct EnvironmentItem { - path: String, -} -impl EnvironmentItem { - pub fn add_to(node: &Arc, path: String) { - Item::add_to( - node, - nanoid!(), - &ITEM_TYPE_INFO_ENVIRONMENT, - ItemType::Environment(EnvironmentItem { path }), - ); - node.add_local_method("get_path", EnvironmentItem::get_path_flex); - } - - fn get_path_flex( - node: Arc, - _calling_client: Arc, - _message: Message, - response: MethodResponseSender, - ) { - response.wrap_sync(move || { - let ItemType::Environment(environment_item) = - &node.get_aspect::().unwrap().specialization - else { - return Err(eyre!("Wrong item type?")); - }; - Ok(serialize(environment_item.path.as_str())?.into()) - }); - } - - pub fn serialize_start_data(&self, id: &str) -> Result { - Ok(serialize((id, self.path.as_str()))?.into()) - } -} - -pub(super) fn create_environment_item_flex( - _node: Arc, - calling_client: Arc, - message: Message, -) -> Result<()> { - #[derive(Deserialize)] - struct CreateEnvironmentItemInfo<'a> { - name: &'a str, - parent_path: &'a str, - transform: Transform, - item_data: String, - } - let info: CreateEnvironmentItemInfo = deserialize(message.as_ref())?; - let parent_name = format!("/item/{}/item", ITEM_TYPE_INFO_ENVIRONMENT.type_name); - let space = calling_client - .get_node("Spatial parent", info.parent_path)? - .get_aspect::()?; - let transform = parse_transform(info.transform, true, true, false); - - let node = Node::create_parent_name(&INTERNAL_CLIENT, &parent_name, info.name, false) - .add_to_scenegraph()?; - Spatial::add_to(&node, None, transform * space.global_transform(), false); - EnvironmentItem::add_to(&node, info.item_data); - node.get_aspect::().unwrap().make_alias_named( - &calling_client, - &parent_name, - info.name, - )?; - Ok(()) -} diff --git a/src/nodes/items/mod.rs b/src/nodes/items/mod.rs index 22593248..d0d0df25 100644 --- a/src/nodes/items/mod.rs +++ b/src/nodes/items/mod.rs @@ -1,9 +1,7 @@ pub mod camera; -mod environment; pub mod panel; use self::camera::CameraItem; -use self::environment::{EnvironmentItem, ITEM_TYPE_INFO_ENVIRONMENT}; use self::panel::{PanelItemTrait, ITEM_TYPE_INFO_PANEL}; use super::fields::Field; use super::spatial::{parse_transform, Spatial}; @@ -182,14 +180,12 @@ impl Drop for Item { pub enum ItemType { Camera(CameraItem), - Environment(EnvironmentItem), Panel(Arc), } impl ItemType { fn serialize_start_data(&self, id: &str) -> Result { match self { ItemType::Camera(c) => c.serialize_start_data(id), - ItemType::Environment(e) => e.serialize_start_data(id), ItemType::Panel(p) => p.serialize_start_data(id), } } @@ -437,10 +433,6 @@ impl Drop for ItemAcceptor { pub fn create_interface(client: &Arc) -> Result<()> { let node = Node::create_parent_name(client, "", "item", false); node.add_local_signal("create_camera_item", camera::create_camera_item_flex); - node.add_local_signal( - "create_environment_item", - environment::create_environment_item_flex, - ); node.add_local_signal("register_item_ui", register_item_ui_flex); node.add_local_signal("create_item_acceptor", create_item_acceptor_flex); node.add_to_scenegraph().map(|_| ()) @@ -448,7 +440,6 @@ pub fn create_interface(client: &Arc) -> Result<()> { fn type_info(name: &str) -> Result<&'static TypeInfo> { match name { - "environment" => Ok(&ITEM_TYPE_INFO_ENVIRONMENT), #[cfg(feature = "wayland")] "panel" => Ok(&ITEM_TYPE_INFO_PANEL), _ => Err(eyre!("Invalid item type")),