Skip to content

Commit

Permalink
fix: input capturing
Browse files Browse the repository at this point in the history
  • Loading branch information
technobaboo committed Jun 7, 2024
1 parent f770357 commit b590e82
Show file tree
Hide file tree
Showing 16 changed files with 67 additions and 61 deletions.
4 changes: 2 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 14 additions & 1 deletion codegen/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -269,13 +269,26 @@ fn generate_alias_info(aspect: &Aspect) -> TokenStream {
let local_methods = generate_alias_opcodes(aspect, Side::Server, MemberType::Method);
let remote_signals = generate_alias_opcodes(aspect, Side::Client, MemberType::Signal);

let inherits = aspect
.inherits
.iter()
.map(|a| {
Ident::new(
&format!("{}_ASPECT_ALIAS_INFO", a.to_case(Case::ScreamingSnake)),
Span::call_site(),
)
})
.map(|a| quote!(#a.clone()))
.fold(quote!(), |a, b| quote!(#a + #b));

quote! {
lazy_static::lazy_static! {
pub static ref #aspect_alias_info_name: crate::nodes::alias::AliasInfo = crate::nodes::alias::AliasInfo {
server_signals: vec![#local_signals],
server_methods: vec![#local_methods],
client_signals: vec![#remote_signals],
};
}
#inherits;
}
}
}
Expand Down
19 changes: 9 additions & 10 deletions src/nodes/alias.rs
Original file line number Diff line number Diff line change
Expand Up @@ -89,16 +89,15 @@ impl AliasList {
self.0.add_raw(node);
}
pub fn get<A: Aspect>(&self, aspect: &A) -> Option<Arc<Node>> {
self.0
.get_valid_contents()
.into_iter()
.filter_map(|n| get_original(n, false))
.find(|node| {
let Ok(aspect2) = node.get_aspect::<A>() else {
return false;
};
Arc::as_ptr(&aspect2) == (aspect as *const A)
})
self.0.get_valid_contents().into_iter().find(|node| {
let Some(node) = get_original(node.clone(), false) else {
return false;
};
let Ok(aspect2) = node.get_aspect::<A>() else {
return false;
};
Arc::as_ptr(&aspect2) == (aspect as *const A)
})
}
pub fn get_aliases(&self) -> Vec<Arc<Node>> {
self.0.get_valid_contents()
Expand Down
1 change: 1 addition & 0 deletions src/nodes/audio.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ use crate::core::destroy_queue;
use crate::core::registry::Registry;
use crate::core::resource::get_resource_file;
use crate::create_interface;
use crate::nodes::spatial::SPATIAL_ASPECT_ALIAS_INFO;
use crate::nodes::spatial::{Spatial, Transform};
use color_eyre::eyre::{eyre, Result};
use glam::{vec3, Vec4Swizzles};
Expand Down
1 change: 1 addition & 0 deletions src/nodes/data.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ use crate::core::registry::Registry;
use crate::create_interface;
use crate::nodes::fields::FIELD_ALIAS_INFO;
use crate::nodes::spatial::Transform;
use crate::nodes::spatial::SPATIAL_ASPECT_ALIAS_INFO;
use color_eyre::eyre::{bail, ensure, eyre, Result};
use lazy_static::lazy_static;
use parking_lot::Mutex;
Expand Down
1 change: 1 addition & 0 deletions src/nodes/drawable/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ use super::{
spatial::{Spatial, Transform},
Node,
};
use crate::nodes::spatial::SPATIAL_ASPECT_ALIAS_INFO;
use crate::{
core::{client::Client, resource::get_resource_file},
create_interface,
Expand Down
2 changes: 2 additions & 0 deletions src/nodes/fields/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ use super::{Aspect, Node};
use crate::core::client::Client;
use crate::create_interface;
use crate::nodes::spatial::Transform;
use crate::nodes::spatial::SPATIAL_ASPECT_ALIAS_INFO;
use crate::nodes::spatial::SPATIAL_REF_ASPECT_ALIAS_INFO;
use color_eyre::eyre::Result;
use glam::{vec2, vec3a, Mat4, Vec3, Vec3A};
use mint::Vector3;
Expand Down
35 changes: 2 additions & 33 deletions src/nodes/input/handler.rs
Original file line number Diff line number Diff line change
@@ -1,17 +1,7 @@
use super::{
input_handler_client, InputHandlerAspect, InputLink, INPUT_HANDLER_REGISTRY,
INPUT_METHOD_REGISTRY,
};
use crate::nodes::{
alias::AliasList,
fields::Field,
spatial::Spatial,
Aspect, Node,
};
use super::{InputHandlerAspect, INPUT_HANDLER_REGISTRY, INPUT_METHOD_REGISTRY};
use crate::nodes::{alias::AliasList, fields::Field, spatial::Spatial, Aspect, Node};
use color_eyre::eyre::Result;
use stardust_xr::values::Datamap;
use std::sync::Arc;
use tracing::instrument;

pub struct InputHandler {
pub spatial: Arc<Spatial>,
Expand All @@ -32,27 +22,6 @@ impl InputHandler {
node.add_aspect_raw(handler);
Ok(())
}

#[instrument(level = "debug", skip(self, input_link))]
pub(super) fn send_input(
&self,
order: u32,
captured: bool,
input_link: &InputLink,
datamap: Datamap,
) {
let Some(node) = self.spatial.node() else {
return;
};
let Some(method_alias) = self.method_aliases.get(input_link.method.as_ref()) else {
return;
};
let _ = input_handler_client::input(
&node,
&method_alias,
&input_link.serialize(method_alias.id, order, captured, datamap),
);
}
}
impl Aspect for InputHandler {
const NAME: &'static str = "InputHandler";
Expand Down
6 changes: 3 additions & 3 deletions src/nodes/input/method.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use super::{
input_method_client, InputDataTrait, InputDataType, InputHandler, InputMethodAspect,
InputMethodRefAspect, INPUT_HANDLER_REGISTRY, INPUT_METHOD_ASPECT_ALIAS_INFO,
INPUT_METHOD_REF_ASPECT_ALIAS_INFO, INPUT_METHOD_REGISTRY,
InputMethodRefAspect, INPUT_HANDLER_REGISTRY, INPUT_METHOD_REF_ASPECT_ALIAS_INFO,
INPUT_METHOD_REGISTRY,
};
use crate::{
core::{client::Client, registry::Registry},
Expand Down Expand Up @@ -76,7 +76,7 @@ impl InputMethod {
let Ok(method_alias) = Alias::create(
&method_node,
&client,
INPUT_METHOD_ASPECT_ALIAS_INFO.clone(),
INPUT_METHOD_REF_ASPECT_ALIAS_INFO.clone(),
Some(&handler.method_aliases),
) else {
return;
Expand Down
32 changes: 23 additions & 9 deletions src/nodes/input/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,13 @@ mod tip;

pub use handler::*;
pub use method::*;
use rustc_hash::FxHashMap;

use super::fields::Field;
use super::spatial::Spatial;
use crate::create_interface;
use crate::nodes::spatial::SPATIAL_ASPECT_ALIAS_INFO;
use crate::nodes::spatial::SPATIAL_REF_ASPECT_ALIAS_INFO;
use crate::{core::client::Client, nodes::Node};
use crate::{core::registry::Registry, nodes::spatial::Transform};
use color_eyre::eyre::Result;
Expand All @@ -32,9 +35,6 @@ impl InputLink {
InputLink { method, handler }
}

fn send_input(&self, order: u32, captured: bool, datamap: Datamap) {
self.handler.send_input(order, captured, self, datamap);
}
#[instrument(level = "debug", skip(self))]
fn serialize(&self, id: u64, order: u32, captured: bool, datamap: Datamap) -> InputData {
let mut input = self.method.data.lock().clone();
Expand Down Expand Up @@ -136,6 +136,8 @@ pub fn process_input() {
method_alias.set_enabled(false);
}
}
let mut handler_input: FxHashMap<u64, (Arc<Node>, Vec<Arc<Node>>, Vec<InputData>)> =
Default::default();
// const LIMIT: usize = 50;
for method in methods {
debug_span!("Process input method").in_scope(|| {
Expand All @@ -158,20 +160,32 @@ pub fn process_input() {

// Iterate over the distance links and send input to them
for (i, input_link) in input_links.into_iter().enumerate() {
if let Some(method_alias) = input_link
let handler = input_link.handler.spatial.node().unwrap();
if !handler_input.contains_key(&handler.id) {
handler_input.insert(handler.id, (handler.clone(), Vec::new(), Vec::new()));
}
let (_, methods, datas) = handler_input.get_mut(&handler.id).unwrap();

let method_alias = input_link
.handler
.method_aliases
.get(input_link.method.as_ref())
{
method_alias.set_enabled(true);
}
input_link.send_input(
.unwrap();
method_alias.set_enabled(true);
dbg!(&method_alias.local_methods);
datas.push(input_link.serialize(
method_alias.id,
i as u32,
method.captures.contains(&input_link.handler),
method.datamap.lock().clone(),
);
));
methods.push(method_alias);
}
method.capture_requests.clear();
});
}

for (_, (handler, methods, data)) in handler_input {
let _ = input_handler_client::input(&handler, &methods, &data);
}
}
2 changes: 2 additions & 0 deletions src/nodes/items/camera.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
use super::{
create_item_acceptor_flex, register_item_ui_flex, Item, ItemAcceptor, ItemInterface, ItemType,
};
use crate::nodes::items::ITEM_ACCEPTOR_ASPECT_ALIAS_INFO;
use crate::nodes::items::ITEM_ASPECT_ALIAS_INFO;
use crate::{
core::{client::Client, registry::Registry, scenegraph::MethodResponseSender},
create_interface,
Expand Down
2 changes: 1 addition & 1 deletion src/nodes/items/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ use crate::core::client::Client;
use crate::core::registry::Registry;
use crate::nodes::alias::AliasInfo;
use crate::nodes::spatial::Transform;
use crate::nodes::spatial::SPATIAL_ASPECT_ALIAS_INFO;
use color_eyre::eyre::{ensure, Result};
use parking_lot::Mutex;

use std::hash::Hash;
use std::sync::{Arc, Weak};

Expand Down
2 changes: 2 additions & 0 deletions src/nodes/items/panel.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
use crate::nodes::items::ITEM_ACCEPTOR_ASPECT_ALIAS_INFO;
use crate::nodes::items::ITEM_ASPECT_ALIAS_INFO;
use crate::{
core::{
client::{get_env, state, Client, INTERNAL_CLIENT},
Expand Down
4 changes: 2 additions & 2 deletions src/nodes/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ impl Node {
message: Message,
) -> Result<(), ScenegraphError> {
if let Ok(alias) = self.get_aspect::<Alias>() {
if !alias.info.server_signals.iter().any(|e| e == &method) {
if !alias.info.server_signals.iter().any(|e| *e == method) {
return Err(ScenegraphError::SignalNotFound);
}
alias
Expand Down Expand Up @@ -174,7 +174,7 @@ impl Node {
response: MethodResponseSender,
) {
if let Ok(alias) = self.get_aspect::<Alias>() {
if !alias.info.server_methods.iter().any(|e| e == &method) {
if !alias.info.server_methods.iter().any(|e| *e == method) {
response.send(Err(ScenegraphError::MethodNotFound));
return;
}
Expand Down
1 change: 1 addition & 0 deletions src/nodes/root.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ use super::Node;
use crate::core::client::Client;
use crate::core::client_state::ClientStateParsed;
use crate::core::registry::Registry;
use crate::nodes::spatial::SPATIAL_REF_ASPECT_ALIAS_INFO;
#[cfg(feature = "wayland")]
use crate::wayland::WAYLAND_DISPLAY;
#[cfg(feature = "xwayland")]
Expand Down
1 change: 1 addition & 0 deletions src/nodes/spatial/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ use super::{Aspect, Node};
use crate::core::client::Client;
use crate::core::registry::Registry;
use crate::create_interface;
use crate::nodes::OWNED_ASPECT_ALIAS_INFO;
use color_eyre::eyre::{eyre, Result};
use glam::{vec3a, Mat4, Quat, Vec3};
use mint::Vector3;
Expand Down

0 comments on commit b590e82

Please sign in to comment.