input: Move from egui to std RwLock (mistake during use choice)
This commit is contained in:
parent
9d3800c718
commit
9d2a4410f0
1 changed files with 15 additions and 9 deletions
|
@ -1,6 +1,8 @@
|
||||||
use std::{collections::HashMap, sync::Arc};
|
use std::{
|
||||||
|
collections::HashMap,
|
||||||
|
sync::{Arc, RwLock},
|
||||||
|
};
|
||||||
|
|
||||||
use egui_winit_vulkano::egui::mutex::RwLock;
|
|
||||||
use winit::{
|
use winit::{
|
||||||
event::{AxisId, ElementState, MouseButton},
|
event::{AxisId, ElementState, MouseButton},
|
||||||
keyboard::PhysicalKey,
|
keyboard::PhysicalKey,
|
||||||
|
@ -29,7 +31,8 @@ impl std::fmt::Debug for VirtualInput {
|
||||||
let mut debug = f.debug_struct("VirtualInput");
|
let mut debug = f.debug_struct("VirtualInput");
|
||||||
|
|
||||||
for (name, state) in &self.states {
|
for (name, state) in &self.states {
|
||||||
debug.field(name, &state.read().value);
|
let value = state.read().expect("Poisoned lock for debug").value;
|
||||||
|
debug.field(name, &value);
|
||||||
}
|
}
|
||||||
|
|
||||||
debug.finish()
|
debug.finish()
|
||||||
|
@ -40,7 +43,7 @@ impl VirtualInput {
|
||||||
pub fn get_state(&self, value_name: &str) -> f32 {
|
pub fn get_state(&self, value_name: &str) -> f32 {
|
||||||
self.states
|
self.states
|
||||||
.get(value_name)
|
.get(value_name)
|
||||||
.map(|state| state.read().value)
|
.map(|state| state.read().expect("Poisoned lock for get state").value)
|
||||||
.unwrap_or(0.0)
|
.unwrap_or(0.0)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -84,6 +87,7 @@ impl VirtualInput {
|
||||||
|
|
||||||
state
|
state
|
||||||
.write()
|
.write()
|
||||||
|
.expect("Poisoned lock for add bindings")
|
||||||
.bindings
|
.bindings
|
||||||
.extend(new_bindings.iter().map(|b| VirtualBindingState {
|
.extend(new_bindings.iter().map(|b| VirtualBindingState {
|
||||||
value: 0.0,
|
value: 0.0,
|
||||||
|
@ -96,7 +100,7 @@ impl VirtualInput {
|
||||||
|
|
||||||
if let Some(states) = states {
|
if let Some(states) = states {
|
||||||
for state in states {
|
for state in states {
|
||||||
let mut state = state.write();
|
let mut state = state.write().expect("Poisoned lock for key update");
|
||||||
state.update_from_key(key, key_state);
|
state.update_from_key(key, key_state);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -104,14 +108,14 @@ impl VirtualInput {
|
||||||
|
|
||||||
pub(super) fn update_mouse_move_binding(&mut self, delta: &glam::Vec2) {
|
pub(super) fn update_mouse_move_binding(&mut self, delta: &glam::Vec2) {
|
||||||
for state in &mut self.mouse_move_states {
|
for state in &mut self.mouse_move_states {
|
||||||
let mut state = state.write();
|
let mut state = state.write().expect("Poisoned lock for mouse move update");
|
||||||
state.update_from_mouse(delta);
|
state.update_from_mouse(delta);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(super) fn update_mouse_wheel_binding(&mut self, delta: &glam::Vec2) {
|
pub(super) fn update_mouse_wheel_binding(&mut self, delta: &glam::Vec2) {
|
||||||
for state in &mut self.mouse_wheel_states {
|
for state in &mut self.mouse_wheel_states {
|
||||||
let mut state = state.write();
|
let mut state = state.write().expect("Poisoned lock for mouse wheel update");
|
||||||
state.update_from_mouse_wheel(delta);
|
state.update_from_mouse_wheel(delta);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -125,7 +129,9 @@ impl VirtualInput {
|
||||||
|
|
||||||
if let Some(states) = states {
|
if let Some(states) = states {
|
||||||
for state in states {
|
for state in states {
|
||||||
let mut state = state.write();
|
let mut state = state
|
||||||
|
.write()
|
||||||
|
.expect("Poisoned lock for mouse button update");
|
||||||
state.update_from_mouse_button(button, button_state);
|
state.update_from_mouse_button(button, button_state);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -136,7 +142,7 @@ impl VirtualInput {
|
||||||
|
|
||||||
if let Some(states) = states {
|
if let Some(states) = states {
|
||||||
for state in states {
|
for state in states {
|
||||||
let mut state = state.write();
|
let mut state = state.write().expect("Poisoned lock for axis update");
|
||||||
state.update_from_axis(axis, axis_state);
|
state.update_from_axis(axis, axis_state);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue