From 3e694d68a685b6e22d6ab59f34090e4681849ebc Mon Sep 17 00:00:00 2001 From: Daniel Schadt Date: Mon, 13 Mar 2023 22:08:48 +0100 Subject: implement "proper" tile hunter mode Now with fixed zoom level for the hunting. --- src/renderer/mod.rs | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) (limited to 'src/renderer/mod.rs') 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], tick: Sender<()>) -> Result; + fn prepare( + &self, + zoom: u32, + tracks: &[Vec], + tick: Sender<()>, + ) -> Result; /// 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) -> Result<()>; + fn colorize(&self, prepared: Self::Prepared, saver: Sender) -> 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; + fn tile_count(&self, prepared: &Self::Prepared) -> Result; } /// 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 Result<()>>( + renderer: &R, zoom: u32, tracks: &[Vec], mut tick: F, @@ -59,7 +66,7 @@ pub fn prepare 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 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 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)?; -- cgit v1.2.3