refactor(input): more compact registry contains
This commit is contained in:
@@ -26,6 +26,11 @@ impl<T: Send + Sync + ?Sized> Registry<T> {
|
||||
.lock()
|
||||
.insert(Arc::as_ptr(t) as *const () as usize, Arc::downgrade(t));
|
||||
}
|
||||
pub fn contains(&self, t: &T) -> bool {
|
||||
self.0
|
||||
.lock()
|
||||
.contains_key(&(ptr::addr_of!(*t) as *const () as usize))
|
||||
}
|
||||
pub fn get_valid_contents(&self) -> Vec<Arc<T>> {
|
||||
self.0
|
||||
.lock()
|
||||
@@ -65,6 +70,11 @@ impl<T: Send + Sync + ?Sized> OwnedRegistry<T> {
|
||||
pub fn get_vec(&self) -> Vec<Arc<T>> {
|
||||
self.0.lock().values().cloned().collect::<Vec<_>>()
|
||||
}
|
||||
pub fn contains(&self, t: &T) -> bool {
|
||||
self.0
|
||||
.lock()
|
||||
.contains_key(&(ptr::addr_of!(*t) as *const () as usize))
|
||||
}
|
||||
pub fn remove(&self, t: &T) {
|
||||
self.0
|
||||
.lock()
|
||||
|
||||
@@ -201,9 +201,9 @@ impl InputHandler {
|
||||
.and_then(|data| data.get_bool())
|
||||
.unwrap_or(false);
|
||||
|
||||
if let Some(method) = method.upgrade() {
|
||||
if let Some(handler) = handler.upgrade() {
|
||||
if capture {
|
||||
if capture {
|
||||
if let Some(method) = method.upgrade() {
|
||||
if let Some(handler) = handler.upgrade() {
|
||||
method.captures.add_raw(&handler);
|
||||
}
|
||||
}
|
||||
@@ -272,19 +272,13 @@ pub fn process_input() {
|
||||
// Get the current frame
|
||||
let frame = FRAME.load(Ordering::Relaxed);
|
||||
|
||||
// Get the list of captured input handlers for this method
|
||||
let captures = method.captures.get_valid_contents();
|
||||
|
||||
// Iterate over the distance links and send input to them
|
||||
for distance_link in distance_links {
|
||||
distance_link.send_input(frame, method.datamap.lock().clone().unwrap());
|
||||
|
||||
// If the current distance link is in the list of captured input handlers,
|
||||
// break out of the loop to avoid sending input to the remaining distance links
|
||||
if captures
|
||||
.iter()
|
||||
.any(|c| Arc::ptr_eq(c, &distance_link.handler))
|
||||
{
|
||||
if method.captures.contains(&distance_link.handler) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user