mirror of
https://github.com/bevyengine/bevy
synced 2024-11-26 14:40:19 +00:00
Only insert or remove input if needed (#4273)
# Objective We are currently inserting an `input` into `pressed` even if it is already pressed. This also applies to releasing an input. This is not a big deal, but since we are already checking if the `input` is pressed or not we might as well remove the cost of the value update caused by the `pressed.insert` method. Related to #4209 ## Solution Only insert or remove input if needed.
This commit is contained in:
parent
551d9f6cd7
commit
f5e53ba6f5
1 changed files with 4 additions and 6 deletions
|
@ -51,11 +51,10 @@ where
|
|||
{
|
||||
/// Register a press for input `input`.
|
||||
pub fn press(&mut self, input: T) {
|
||||
if !self.pressed(input) {
|
||||
// Returns `true` if the `input` wasn't pressed.
|
||||
if self.pressed.insert(input) {
|
||||
self.just_pressed.insert(input);
|
||||
}
|
||||
|
||||
self.pressed.insert(input);
|
||||
}
|
||||
|
||||
/// Check if `input` has been pressed.
|
||||
|
@ -70,11 +69,10 @@ where
|
|||
|
||||
/// Register a release for input `input`.
|
||||
pub fn release(&mut self, input: T) {
|
||||
if self.pressed(input) {
|
||||
// Returns `true` if the `input` was pressed.
|
||||
if self.pressed.remove(&input) {
|
||||
self.just_released.insert(input);
|
||||
}
|
||||
|
||||
self.pressed.remove(&input);
|
||||
}
|
||||
|
||||
/// Check if `input` has been just pressed.
|
||||
|
|
Loading…
Reference in a new issue