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