diff --git a/Cargo.toml b/Cargo.toml index 19dd744..2b790e3 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -5,7 +5,7 @@ edition = "2021" [features] default = ["drivers", "scheduler"] -drivers = ["micromap", "compact_str"] +drivers = ["compact_str"] scheduler = ["spin_sleep"] named_colors = [] @@ -18,7 +18,6 @@ palette = { version = "0.7.3", default-features = false, features = [ ] } toml = "0.8.0" smallvec = "1.11.2" -micromap = { version = "0.0.15", optional = true } compact_str = { version = "0.7", optional = true } spin_sleep = { version = "1.1.1", optional = true } diff --git a/examples/calibration.rs b/examples/calibration.rs index c2a9852..59ac73e 100644 --- a/examples/calibration.rs +++ b/examples/calibration.rs @@ -1,5 +1,4 @@ mod resources; -use std::mem::size_of; use resources::tui::SledTerminalDisplay; @@ -7,7 +6,6 @@ use glam::Vec2; use sled::{color::Rgb, Sled, SledError}; fn main() -> Result<(), SledError> { - print!("{}", size_of::()); let mut sled = Sled::new("./examples/resources/config.toml")?; let mut display = SledTerminalDisplay::start("Calibration", sled.domain()); @@ -22,4 +20,3 @@ fn main() -> Result<(), SledError> { display.refresh().unwrap(); Ok(()) } - diff --git a/examples/quirky_trail.rs b/examples/quirky_trail.rs index 9ce6afa..7db3391 100644 --- a/examples/quirky_trail.rs +++ b/examples/quirky_trail.rs @@ -2,21 +2,21 @@ mod drivers; use drivers::quirky_trail; mod resources; -use resources::tui::SledTerminalDisplay; +// use resources::tui::SledTerminalDisplay; use sled::{scheduler::Scheduler, Sled}; fn main() { let sled = Sled::new("./examples/resources/config.toml").unwrap(); - let mut display = SledTerminalDisplay::start("Quirky Trail", sled.domain()); + // let mut display = SledTerminalDisplay::start("Quirky Trail", sled.domain()); let mut driver = quirky_trail::build_driver(); driver.mount(sled); let mut scheduler = Scheduler::fixed_hz(500.0); scheduler.loop_until_err(|| { driver.step(); - display.leds = driver.read_colors_and_positions(); - display.refresh()?; + // display.leds = driver.read_colors_and_positions(); + // display.refresh()?; Ok(()) }); } diff --git a/src/driver/buffers.rs b/src/driver/buffers.rs index 7c0896a..5c1273b 100644 --- a/src/driver/buffers.rs +++ b/src/driver/buffers.rs @@ -2,81 +2,72 @@ use std::any::type_name; use compact_str::{CompactString, ToCompactString}; use glam::Vec2; -use micromap::Map; use palette::rgb::Rgb; -use smallvec::SmallVec; - -const MAX_BUFFERS: usize = 4; -const DEFAULT_BUFFER_SIZE: usize = 12; - -pub trait BufferDataStructure {} -impl BufferDataStructure for SmallVec {} - -pub type Buffer = SmallVec<[T; N]>; +use std::collections::HashMap; pub struct BufferContainer { - f32s: Map, MAX_BUFFERS>, - rgbs: Map, MAX_BUFFERS>, - bools: Map, MAX_BUFFERS>, - vec2s: Map, MAX_BUFFERS>, - usizes: Map, MAX_BUFFERS>, + f32s: HashMap>, + rgbs: HashMap>, + bools: HashMap>, + vec2s: HashMap>, + usizes: HashMap>, } mod internal_traits { - use super::{Buffer, BufferContainer}; - use super::{CompactString, Map, MAX_BUFFERS}; + use super::BufferContainer; + use super::{CompactString, HashMap}; use super::{Rgb, Vec2}; pub trait MapForType { - fn map_for_type_mut(&mut self) -> &mut Map, MAX_BUFFERS>; - fn map_for_type(&self) -> &Map, MAX_BUFFERS>; + fn map_for_type_mut(&mut self) -> &mut HashMap>; + fn map_for_type(&self) -> &HashMap>; } impl MapForType for BufferContainer { - fn map_for_type(&self) -> &Map, MAX_BUFFERS> { + fn map_for_type(&self) -> &HashMap> { &self.usizes } - fn map_for_type_mut(&mut self) -> &mut Map, MAX_BUFFERS> { + fn map_for_type_mut(&mut self) -> &mut HashMap> { &mut self.usizes } } impl MapForType for BufferContainer { - fn map_for_type_mut(&mut self) -> &mut Map, MAX_BUFFERS> { + fn map_for_type_mut(&mut self) -> &mut HashMap> { &mut self.bools } - fn map_for_type(&self) -> &Map, MAX_BUFFERS> { + fn map_for_type(&self) -> &HashMap> { &self.bools } } impl MapForType for BufferContainer { - fn map_for_type_mut(&mut self) -> &mut Map, MAX_BUFFERS> { + fn map_for_type_mut(&mut self) -> &mut HashMap> { &mut self.f32s } - fn map_for_type(&self) -> &Map, MAX_BUFFERS> { + fn map_for_type(&self) -> &HashMap> { &self.f32s } } impl MapForType for BufferContainer { - fn map_for_type_mut(&mut self) -> &mut Map, MAX_BUFFERS> { + fn map_for_type_mut(&mut self) -> &mut HashMap> { &mut self.rgbs } - fn map_for_type(&self) -> &Map, MAX_BUFFERS> { + fn map_for_type(&self) -> &HashMap> { &self.rgbs } } impl MapForType for BufferContainer { - fn map_for_type_mut(&mut self) -> &mut Map, MAX_BUFFERS> { + fn map_for_type_mut(&mut self) -> &mut HashMap> { &mut self.vec2s } - fn map_for_type(&self) -> &Map, MAX_BUFFERS> { + fn map_for_type(&self) -> &HashMap> { &self.vec2s } } @@ -86,28 +77,27 @@ use crate::SledError; pub use self::internal_traits::MapForType; -#[allow(dead_code)] impl BufferContainer { pub fn new() -> Self { BufferContainer { - f32s: Map::new(), - rgbs: Map::new(), - bools: Map::new(), - vec2s: Map::new(), - usizes: Map::new(), + f32s: HashMap::new(), + rgbs: HashMap::new(), + bools: HashMap::new(), + vec2s: HashMap::new(), + usizes: HashMap::new(), } } - pub fn create(&mut self, buffer_name: &str) -> &mut Buffer + pub fn create(&mut self, buffer_name: &str) -> &mut Vec where BufferContainer: MapForType, { let map = self.map_for_type_mut(); - map.insert(buffer_name.to_compact_string(), Buffer::new()); - &mut map[buffer_name] + map.insert(buffer_name.to_compact_string(), Vec::new()); + map.get_mut(buffer_name).unwrap() } - pub fn get_buffer(&self, buffer_name: &str) -> Option<&Buffer> + pub fn get_buffer(&self, buffer_name: &str) -> Option<&Vec> where BufferContainer: MapForType, { @@ -115,7 +105,7 @@ impl BufferContainer { map.get(buffer_name) } - pub fn get_buffer_mut(&mut self, buffer_name: &str) -> Option<&mut Buffer> + pub fn get_buffer_mut(&mut self, buffer_name: &str) -> Option<&mut Vec> where BufferContainer: MapForType, { @@ -138,7 +128,7 @@ impl BufferContainer { { let buffer = self.get_buffer_mut(buffer_name).ok_or_else(|| { SledError::new(format!( - "There is no Buffer<{}> with the name `{}`.", + "There is no Vec<{}> with the name `{}`.", type_name::(), buffer_name )) @@ -154,7 +144,7 @@ impl BufferContainer { { let buffer = self.get_buffer_mut(buffer_name).ok_or_else(|| { SledError::new(format!( - "There is no Buffer<{}> with the name `{}`.", + "There is no Vec<{}> with the name `{}`.", type_name::(), buffer_name )) @@ -172,10 +162,8 @@ fn deref_option(option: Option<&T>) -> Option { } } -trait TypedIndex {} - impl std::ops::Index<&str> for BufferContainer { - type Output = Buffer; + type Output = Vec; fn index(&self, index: &str) -> &Self::Output { &self.f32s[index] diff --git a/src/driver/filters.rs b/src/driver/filters.rs index a7f0a28..bd38e10 100644 --- a/src/driver/filters.rs +++ b/src/driver/filters.rs @@ -1,10 +1,9 @@ -use compact_str::{CompactString, ToCompactString}; -use micromap::Map; - use crate::Filter; +use compact_str::{CompactString, ToCompactString}; +use std::collections::HashMap; pub struct Filters { - map: Map, + map: HashMap, } impl Default for Filters { @@ -15,7 +14,9 @@ impl Default for Filters { impl Filters { pub fn new() -> Self { - Filters { map: Map::new() } + Filters { + map: HashMap::new(), + } } pub fn set(&mut self, key: &str, value: Filter) { diff --git a/src/driver/mod.rs b/src/driver/mod.rs index 59d7557..237d69e 100644 --- a/src/driver/mod.rs +++ b/src/driver/mod.rs @@ -4,7 +4,7 @@ use std::time::{Duration, Instant}; mod filters; // mod sliders; mod buffers; -pub use buffers::{Buffer, BufferContainer}; +pub use buffers::BufferContainer; pub use filters::Filters; pub enum RefreshTiming { @@ -23,7 +23,6 @@ type ComputeCommands = Box SledResult>; type DrawCommands = Box SledResult>; pub struct Driver { - _timing_strategy: RefreshTiming, sled: Option, startup_commands: StartupCommands, compute_commands: ComputeCommands, @@ -43,7 +42,6 @@ impl Default for Driver { impl Driver { pub fn new() -> Self { Driver { - _timing_strategy: RefreshTiming::None, sled: None, startup_commands: Box::new(|_, _, _| Ok(())), compute_commands: Box::new(|_, _, _, _| Ok(())),