From be4ec97c08fdad86f8bc5995a4082e6ba733a4e3 Mon Sep 17 00:00:00 2001 From: Shute052 Date: Wed, 31 Jan 2024 04:38:31 +0800 Subject: [PATCH 1/6] Fix accumulation issue in `which_pressed()` for `ActionData::axis_pair` --- src/input_map.rs | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/src/input_map.rs b/src/input_map.rs index 4ee004f5..508f4e6e 100644 --- a/src/input_map.rs +++ b/src/input_map.rs @@ -323,23 +323,19 @@ impl InputMap { // Generate the raw action presses for (action, input_vec) in self.iter() { - let mut pressed = false; let mut action_datum = ActionData::default(); for input in input_vec { - action_datum.axis_pair = input_streams.input_axis_pair(input); + action_datum.axis_pair = input_streams.input_axis_pair(input).map(|new_data| { + new_data.merged_with(action_datum.axis_pair.unwrap_or_default()) + }); if input_streams.input_pressed(input) { - pressed = true; - + action_datum.state = ButtonState::JustPressed; action_datum.value += input_streams.input_value(input, true); } } - if pressed { - action_datum.state = ButtonState::JustPressed; - } - action_data.insert(action.clone(), action_datum); } From 34ccc19bce606a9bebd89043bed0e18f1a7eb5ac Mon Sep 17 00:00:00 2001 From: Shute052 Date: Wed, 31 Jan 2024 05:16:08 +0800 Subject: [PATCH 2/6] Fix get `None` --- src/input_map.rs | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/input_map.rs b/src/input_map.rs index 508f4e6e..4d8dd4e7 100644 --- a/src/input_map.rs +++ b/src/input_map.rs @@ -326,9 +326,10 @@ impl InputMap { let mut action_datum = ActionData::default(); for input in input_vec { - action_datum.axis_pair = input_streams.input_axis_pair(input).map(|new_data| { - new_data.merged_with(action_datum.axis_pair.unwrap_or_default()) - }); + if let Some(new_data) = input_streams.input_axis_pair(input) { + let current_data = action_datum.axis_pair.unwrap_or_default(); + action_datum.axis_pair = Some(new_data.merged_with(current_data)); + } if input_streams.input_pressed(input) { action_datum.state = ButtonState::JustPressed; From 732baa3e7befd75cfd3df7c6e842c782c7389d95 Mon Sep 17 00:00:00 2001 From: Shute052 Date: Wed, 31 Jan 2024 05:18:35 +0800 Subject: [PATCH 3/6] Rename the variable --- src/input_map.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/input_map.rs b/src/input_map.rs index 4d8dd4e7..da1a645d 100644 --- a/src/input_map.rs +++ b/src/input_map.rs @@ -326,9 +326,9 @@ impl InputMap { let mut action_datum = ActionData::default(); for input in input_vec { - if let Some(new_data) = input_streams.input_axis_pair(input) { - let current_data = action_datum.axis_pair.unwrap_or_default(); - action_datum.axis_pair = Some(new_data.merged_with(current_data)); + if let Some(new_axis_pair) = input_streams.input_axis_pair(input) { + let current_axis_pair = action_datum.axis_pair.unwrap_or_default(); + action_datum.axis_pair = Some(new_axis_pair.merged_with(current_axis_pair)); } if input_streams.input_pressed(input) { From d6c5b990b4f88d541dabaf9ab750418e1d6553aa Mon Sep 17 00:00:00 2001 From: Shute052 Date: Wed, 31 Jan 2024 05:21:02 +0800 Subject: [PATCH 4/6] Change order --- src/input_map.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/input_map.rs b/src/input_map.rs index da1a645d..f6ae389a 100644 --- a/src/input_map.rs +++ b/src/input_map.rs @@ -328,7 +328,7 @@ impl InputMap { for input in input_vec { if let Some(new_axis_pair) = input_streams.input_axis_pair(input) { let current_axis_pair = action_datum.axis_pair.unwrap_or_default(); - action_datum.axis_pair = Some(new_axis_pair.merged_with(current_axis_pair)); + action_datum.axis_pair = Some(current_axis_pair.merged_with(new_axis_pair)); } if input_streams.input_pressed(input) { From f2c59edc79221e368e4dcfb78a66a0be2f7cf37d Mon Sep 17 00:00:00 2001 From: Shute052 Date: Thu, 1 Feb 2024 14:35:50 +0800 Subject: [PATCH 5/6] Minor refactor --- src/input_map.rs | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/input_map.rs b/src/input_map.rs index f6ae389a..fe3bff4f 100644 --- a/src/input_map.rs +++ b/src/input_map.rs @@ -326,9 +326,13 @@ impl InputMap { let mut action_datum = ActionData::default(); for input in input_vec { - if let Some(new_axis_pair) = input_streams.input_axis_pair(input) { - let current_axis_pair = action_datum.axis_pair.unwrap_or_default(); - action_datum.axis_pair = Some(current_axis_pair.merged_with(new_axis_pair)); + // Merge axis pair into action datum + if let Some(axis_pair) = input_streams.input_axis_pair(input) { + action_datum.axis_pair = action_datum + .axis_pair + .map_or(Some(axis_pair), |current_axis_pair| { + Some(current_axis_pair.merged_with(axis_pair)) + }) } if input_streams.input_pressed(input) { From 97d7cdc63955cd58251c247d33b1de229e23928a Mon Sep 17 00:00:00 2001 From: Shute052 Date: Thu, 1 Feb 2024 14:43:35 +0800 Subject: [PATCH 6/6] Add semicolon --- src/input_map.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/input_map.rs b/src/input_map.rs index fe3bff4f..afcef5fe 100644 --- a/src/input_map.rs +++ b/src/input_map.rs @@ -332,7 +332,7 @@ impl InputMap { .axis_pair .map_or(Some(axis_pair), |current_axis_pair| { Some(current_axis_pair.merged_with(axis_pair)) - }) + }); } if input_streams.input_pressed(input) {