diff options
author | Daniel Schadt <kingdread@gmx.de> | 2023-03-13 22:08:48 +0100 |
---|---|---|
committer | Daniel Schadt <kingdread@gmx.de> | 2023-03-13 22:08:48 +0100 |
commit | 3e694d68a685b6e22d6ab59f34090e4681849ebc (patch) | |
tree | 0e9d817d38d8d3524b459c5e8ebe4c55876e322b /src/renderer/mod.rs | |
parent | 3bec9ff1bcb7fb8b93693c0c93b8d42797f95e1c (diff) | |
download | hittekaart-3e694d68a685b6e22d6ab59f34090e4681849ebc.tar.gz hittekaart-3e694d68a685b6e22d6ab59f34090e4681849ebc.tar.bz2 hittekaart-3e694d68a685b6e22d6ab59f34090e4681849ebc.zip |
implement "proper" tile hunter mode
Now with fixed zoom level for the hunting.
Diffstat (limited to 'src/renderer/mod.rs')
-rw-r--r-- | src/renderer/mod.rs | 20 |
1 files changed, 14 insertions, 6 deletions
diff --git a/src/renderer/mod.rs b/src/renderer/mod.rs index f109872..73c2e87 100644 --- a/src/renderer/mod.rs +++ b/src/renderer/mod.rs @@ -7,6 +7,7 @@ use crossbeam_channel::Sender; use super::gpx::Coordinates; pub mod heatmap; +pub mod marktile; pub mod tilehunt; const CHANNEL_SIZE: usize = 30; @@ -26,25 +27,30 @@ pub struct RenderedTile { /// /// This is done in two steps, preparation and actual rendering. This allows different feedback for /// the user. -pub trait Renderer { +pub trait Renderer: Send + Sync { type Prepared: Send; /// Prepare the rendered data. /// /// The `tick` channel is used to provide user-feedback, for every finished track a tick should /// be sent. - fn prepare(zoom: u32, tracks: &[Vec<Coordinates>], tick: Sender<()>) -> Result<Self::Prepared>; + fn prepare( + &self, + zoom: u32, + tracks: &[Vec<Coordinates>], + tick: Sender<()>, + ) -> Result<Self::Prepared>; /// Actually produce the colored tiles, using the previously prepared data. /// /// The `saver` channel is used to send the finished tiles to a thread that is responsible for /// saving them. - fn colorize(prepared: Self::Prepared, saver: Sender<RenderedTile>) -> Result<()>; + fn colorize(&self, prepared: Self::Prepared, saver: Sender<RenderedTile>) -> Result<()>; /// Returns the tile count of the prepared data. /// /// This is used for the user interface, to scale progress bars appropriately. - fn tile_count(prepared: &Self::Prepared) -> Result<u64>; + fn tile_count(&self, prepared: &Self::Prepared) -> Result<u64>; } /// A convenience wrapper to call [`Renderer::prepare`]. @@ -52,6 +58,7 @@ pub trait Renderer { /// This function takes the same arguments, but provides the ability to use a callback closure /// instead of having to set up a channel. The callback is always called on the same thread. pub fn prepare<R: Renderer, F: FnMut() -> Result<()>>( + renderer: &R, zoom: u32, tracks: &[Vec<Coordinates>], mut tick: F, @@ -59,7 +66,7 @@ pub fn prepare<R: Renderer, F: FnMut() -> Result<()>>( thread::scope(|s| { let (sender, receiver) = crossbeam_channel::bounded(CHANNEL_SIZE); - let preparer = s.spawn(|| R::prepare(zoom, tracks, sender)); + let preparer = s.spawn(|| renderer.prepare(zoom, tracks, sender)); for _ in receiver { tick()?; @@ -74,13 +81,14 @@ pub fn prepare<R: Renderer, F: FnMut() -> Result<()>>( /// This function takes the same arguments, but provides the ability to use a callback closure /// instead of having to set up a channel. The callback is always called on the same thread. pub fn colorize<R: Renderer, F: FnMut(RenderedTile) -> Result<()>>( + renderer: &R, prepared: R::Prepared, mut saver: F, ) -> Result<()> { thread::scope(|s| { let (sender, receiver) = crossbeam_channel::bounded(CHANNEL_SIZE); - let colorizer = s.spawn(|| R::colorize(prepared, sender)); + let colorizer = s.spawn(|| renderer.colorize(prepared, sender)); for tile in receiver { saver(tile)?; |