summaryrefslogtreecommitdiff
path: root/engine/src/util.rs
diff options
context:
space:
mode:
authorHampusM <hampus@hampusmat.com>2026-08-15 19:11:14 +0200
committerHampusM <hampus@hampusmat.com>2026-08-15 19:11:14 +0200
commit068dadbbb0eccd9bbb8963e975ba22dd0738d859 (patch)
tree2c399dd841a1fe533754a951cd2af6535d060c1b /engine/src/util.rs
parent1ac2ff603b1c843541234648ab801e83b2947444 (diff)
fix(engine): stop overwriting previous keyboard key states
Diffstat (limited to 'engine/src/util.rs')
-rw-r--r--engine/src/util.rs9
1 files changed, 5 insertions, 4 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;
}