|
|
|
@ -35,7 +35,7 @@ impl EventType
|
|
|
|
|
{
|
|
|
|
|
fn new(rt: u64, rv: u64) -> Self {
|
|
|
|
|
EventType {
|
|
|
|
|
0: (rt as u128).rotate_left(64) + u128::from(rv)
|
|
|
|
|
0: u128::from(rt).rotate_left(64) + u128::from(rv)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
@ -83,6 +83,7 @@ where TEventType: ToEventType<TControllerID>,
|
|
|
|
|
TControllerID: Copy + PartialEq + Serialize,
|
|
|
|
|
TUserAction: Clone + Serialize,
|
|
|
|
|
{
|
|
|
|
|
/// Create a new empty schema
|
|
|
|
|
fn new(name: &str) -> Self {
|
|
|
|
|
Schema {
|
|
|
|
|
name: name.to_string(),
|
|
|
|
@ -93,6 +94,9 @@ where TEventType: ToEventType<TControllerID>,
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// Assign controller to this schema. Future input events will be ignored unless
|
|
|
|
|
/// their controller matches the assigned one. NOTE: many backends don't have controller IDs
|
|
|
|
|
/// for keyboards and mice.
|
|
|
|
|
fn assign_controller(&mut self, event: &TEventType, iaf: InputTypeFlags) -> bool {
|
|
|
|
|
let event_controller_id = event.controller_id();
|
|
|
|
|
|
|
|
|
@ -106,6 +110,7 @@ where TEventType: ToEventType<TControllerID>,
|
|
|
|
|
false
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// Assigns input event -> user action mapping
|
|
|
|
|
fn assign_input(&mut self, event: &TEventType, action: TUserAction, iaf: InputTypeFlags) -> bool {
|
|
|
|
|
if event.filter_for_assignment(iaf) {
|
|
|
|
|
if let Some(event_type) = event.to_raw() {
|
|
|
|
@ -118,6 +123,15 @@ where TEventType: ToEventType<TControllerID>,
|
|
|
|
|
false
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// Removes input event -> user action mappings and assigned controller_id
|
|
|
|
|
/// Player_id stays assigned, if you need to clear that use set_player_id()
|
|
|
|
|
fn clear_assignments(&mut self) {
|
|
|
|
|
self.controller_id = None;
|
|
|
|
|
self.keymap.clear();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// Main processing loop. Takes input event and returns an option with processing result
|
|
|
|
|
/// If the mapping was found result will be set, otherwise None
|
|
|
|
|
fn process_event(&mut self, event: &TEventType) -> Option<ProcessingResult<TUserAction>> {
|
|
|
|
|
if let Some(event_type) = event.to_raw() {
|
|
|
|
|
if let Some(action) = self.keymap.get(&event_type) {
|
|
|
|
@ -136,6 +150,7 @@ where TEventType: ToEventType<TControllerID>,
|
|
|
|
|
None
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// Set player_id as option, use None to clear
|
|
|
|
|
fn set_player_id(&mut self, player_id: Option<usize>) {
|
|
|
|
|
self.player_id = player_id;
|
|
|
|
|
}
|
|
|
|
|