From a0d84cb7f1adea09974bf9bf44dd489642d3eb9e Mon Sep 17 00:00:00 2001 From: Shane Celis Date: Tue, 23 Apr 2024 05:31:26 -0400 Subject: [PATCH] excise: Remove covec. --- src/cache.rs | 11 ++++++++--- src/covec.rs | 21 --------------------- src/lib.rs | 1 - src/plugin.rs | 43 ++++++------------------------------------- 4 files changed, 14 insertions(+), 62 deletions(-) delete mode 100644 src/covec.rs diff --git a/src/cache.rs b/src/cache.rs index ca92069..a19f6af 100644 --- a/src/cache.rs +++ b/src/cache.rs @@ -1,6 +1,10 @@ //! Cache the trie for reuse. use crate::input_sequence::InputSequence; -use bevy::ecs::system::Resource; +use bevy::{ + ecs::system::Resource, + log::info, + reflect::TypePath, +}; use trie_rs::{ map::{Trie, TrieBuilder}, inc_search::{IncSearch, @@ -17,7 +21,7 @@ pub struct InputSequenceCache { impl InputSequenceCache where - A: Ord + Clone + Send + Sync + 'static, + A: Ord + Clone + Send + Sync + TypePath + 'static, In: Send + Sync + Clone + Eq + Hash + 'static, { /// Retrieve the cached trie without iterating through `sequences`. Or if @@ -32,7 +36,8 @@ where for sequence in sequences { builder.insert(sequence.acts.clone(), sequence.clone()); } - assert!(self.position.len() == 0, "Position should be none when rebuilding trie"); + info!("Building trie for {} input sequences.", A::short_type_path()); + assert!(self.position.is_empty(), "Position should be none when rebuilding trie"); builder.build() }) } diff --git a/src/covec.rs b/src/covec.rs deleted file mode 100644 index abfbd4b..0000000 --- a/src/covec.rs +++ /dev/null @@ -1,21 +0,0 @@ -/// Helps keep two correlated vectors in sync. -pub(crate) struct Covec(pub(crate) Vec, pub(crate) Vec); - -impl Covec { - pub(crate) fn push(&mut self, x: T, y: S) { - self.0.push(x); - self.1.push(y); - } - - pub(crate) fn drain1_sync(&mut self) { - let len0 = self.0.len(); - let len1 = self.1.len(); - let _ = self.1.drain(0..len1.saturating_sub(len0)); - } -} - -impl Default for Covec { - fn default() -> Self { - Self(vec![], vec![]) - } -} diff --git a/src/lib.rs b/src/lib.rs index f4248ca..d6d8e40 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -6,7 +6,6 @@ pub mod action; pub mod cache; mod chord; pub mod cond_system; -mod covec; mod frame_time; pub mod input_sequence; mod plugin; diff --git a/src/plugin.rs b/src/plugin.rs index 2dac96d..bef97d5 100644 --- a/src/plugin.rs +++ b/src/plugin.rs @@ -21,15 +21,11 @@ use std::collections::{VecDeque, HashMap}; use crate::{ cache::InputSequenceCache, chord::is_modifier, - covec::Covec, frame_time::FrameTime, input_sequence::{ButtonSequence, InputSequence, KeySequence}, KeyChord, Modifiers, }; -use trie_rs::{ - map::Trie, - inc_search::{IncSearch, Answer}, -}; +use trie_rs::inc_search::{IncSearch, Answer}; /// ButtonInput sequence plugin. pub struct InputSequencePlugin { @@ -205,14 +201,14 @@ fn button_sequence_matcher( } }; - last_times.push_front(now.clone()); + last_times.push_back(now.clone()); let start = &last_times[0]; let mut search = cache.recall(button.gamepad, sequences.iter().by_ref()); for seq in inc_consume_input(&mut search, std::iter::once(button.button_type)) { if seq .time_limit .as_ref() - .map(|limit| (&now - &start).has_timedout(limit)) + .map(|limit| (&now - start).has_timedout(limit)) .unwrap_or(false) { // Sequence timed out. @@ -230,7 +226,7 @@ fn button_sequence_matcher( #[allow(clippy::too_many_arguments)] fn key_sequence_matcher( - sequences: Query<&InputSequence>, + sequences: Query<&KeySequence>, time: Res