diff options
Diffstat (limited to 'engine/src')
| -rw-r--r-- | engine/src/util.rs | 9 | ||||
| -rw-r--r-- | engine/src/windowing.rs | 4 | ||||
| -rw-r--r-- | engine/src/windowing/keyboard.rs | 3 |
3 files changed, 10 insertions, 6 deletions
diff --git a/engine/src/util.rs b/engine/src/util.rs index f820b64..9d1c887 100644 --- a/engine/src/util.rs +++ b/engine/src/util.rs @@ -234,11 +234,13 @@ impl<const SIZE: usize, const BITS_PER_ITEM: usize> BitArray<SIZE, BITS_PER_ITEM (self.inner[byte_index] >> (bit_index_in_byte)) & Self::ITEM_MASK } - #[tracing::instrument(skip_all)] - pub fn set(&mut self, item_index: usize, item_bits: u8) + #[tracing::instrument(skip(self))] + pub fn clear_and_set(&mut self, item_index: usize, item_bits: u8, clear_mask: u8) { let item_bits = item_bits & Self::ITEM_MASK; + let clear_mask = clear_mask & Self::ITEM_MASK; + let bit_index = item_index * BITS_PER_ITEM; let byte_index = bit_index / 8; @@ -246,14 +248,13 @@ impl<const SIZE: usize, const BITS_PER_ITEM: usize> BitArray<SIZE, BITS_PER_ITEM let bit_index_in_byte = bit_index - (byte_index * 8); tracing::trace!( - item_bits, bit_index, byte_index, bit_index_in_byte, "Setting item bits" ); - self.inner[byte_index] &= !(Self::ITEM_MASK << bit_index_in_byte); + self.inner[byte_index] &= !(clear_mask << bit_index_in_byte); self.inner[byte_index] |= item_bits << bit_index_in_byte; } diff --git a/engine/src/windowing.rs b/engine/src/windowing.rs index 805004a..4279148 100644 --- a/engine/src/windowing.rs +++ b/engine/src/windowing.rs @@ -1005,7 +1005,9 @@ impl ApplicationHandler for App KeyState::Released => KEY_RELEASED_BITS, }; - input.keys.set(key as usize, key_state_bits); + input + .keys + .clear_and_set(key as usize, key_state_bits, u8::MAX); } WindowEvent::CursorMoved { device_id: _, position } => { { diff --git a/engine/src/windowing/keyboard.rs b/engine/src/windowing/keyboard.rs index 8e0cfbe..dffa95e 100644 --- a/engine/src/windowing/keyboard.rs +++ b/engine/src/windowing/keyboard.rs @@ -96,12 +96,13 @@ impl Keyboard pub fn set_key_state(&mut self, key: Key, key_state: KeyState) { - self.keys.set( + self.keys.clear_and_set( key as usize, match key_state { KeyState::Pressed => KEY_CURR_PRESSED_BITS, KeyState::Released => 0, }, + KEY_CURR_PRESSED_BITS, ); } |
