Explorar el Código

Add --sync option

Johannes Hofmann hace 7 años
padre
commit
5d67d3bef5
Se han modificado 4 ficheros con 29 adiciones y 7 borrados
  1. 9
    3
      src/main.rs
  2. 8
    2
      src/map_view_gl.rs
  3. 8
    2
      src/tile_atlas.rs
  4. 4
    0
      src/tile_loader.rs

+ 9
- 3
src/main.rs Ver fichero

@@ -221,11 +221,16 @@ fn main() {
221 221
                     .map_err(|e| e.description().to_string())
222 222
             })
223 223
             .help("Set target frames per second (default is 60). \
224
-                  This should equal the refresh rate of the display.")
224
+                This should equal the refresh rate of the display.")
225 225
             .takes_value(true))
226 226
         .arg(Arg::with_name("offline")
227 227
             .long("offline")
228
-            .help("Do not use the network"))
228
+            .help("Do not use the network. \
229
+                Try to load tiles from the offline file system cache."))
230
+        .arg(Arg::with_name("sync")
231
+            .long("sync")
232
+            .help("Load tiles in a synchronous fashion. \
233
+                Interaction is not possible while tiles are loading."))
229 234
         .get_matches();
230 235
 
231 236
     let config = if let Some(config_path) = matches.value_of_os("config") {
@@ -253,7 +258,8 @@ fn main() {
253 258
             &cx,
254 259
             window.get_inner_size_pixels().unwrap(),
255 260
             move || { proxy.wakeup_event_loop(); },
256
-            !matches.is_present("offline")
261
+            !matches.is_present("offline"),
262
+            !matches.is_present("sync"),
257 263
         )
258 264
     };
259 265
 

+ 8
- 2
src/map_view_gl.rs Ver fichero

@@ -23,7 +23,13 @@ pub struct MapViewGl<'a> {
23 23
 }
24 24
 
25 25
 impl<'a> MapViewGl<'a> {
26
-    pub fn new<F>(cx: &Context, initial_size: (u32, u32), update_func: F, use_network: bool) -> MapViewGl
26
+    pub fn new<F>(
27
+        cx: &Context,
28
+        initial_size: (u32, u32),
29
+        update_func: F,
30
+        use_network: bool,
31
+        use_async: bool,
32
+        ) -> MapViewGl
27 33
         where F: Fn() + Sync + Send + 'static,
28 34
     {
29 35
         unsafe {
@@ -81,7 +87,7 @@ impl<'a> MapViewGl<'a> {
81 87
                 viewport_size: initial_size,
82 88
                 map_view: map_view,
83 89
                 tile_cache: TileCache::new(move |_tile| update_func(), use_network),
84
-                tile_atlas: TileAtlas::new(tex, 256),
90
+                tile_atlas: TileAtlas::new(tex, 256, use_async),
85 91
             }
86 92
         }
87 93
     }

+ 8
- 2
src/tile_atlas.rs Ver fichero

@@ -22,6 +22,7 @@ pub struct TileAtlas<'a> {
22 22
     tile_size: u32,
23 23
     slots_lru: LinkedHashMap<CacheSlot, Option<Tile>>, // LRU cache of slots
24 24
     tile_to_slot: HashMap<Tile, CacheSlot>,
25
+    use_async: bool,
25 26
 }
26 27
 
27 28
 impl<'a> TileAtlas<'a> {
@@ -50,12 +51,13 @@ impl<'a> TileAtlas<'a> {
50 51
         self.tile_to_slot.reserve(num_slots);
51 52
     }
52 53
 
53
-    pub fn new(tex: Texture<'a>, tile_size: u32) -> Self {
54
+    pub fn new(tex: Texture<'a>, tile_size: u32, use_async: bool) -> Self {
54 55
         let mut atlas = TileAtlas {
55 56
             texture: tex,
56 57
             tile_size: tile_size,
57 58
             slots_lru: LinkedHashMap::new(),
58 59
             tile_to_slot: HashMap::new(),
60
+            use_async: use_async,
59 61
         };
60 62
 
61 63
         atlas.init();
@@ -93,7 +95,11 @@ impl<'a> TileAtlas<'a> {
93 95
         let slot = match self.tile_to_slot.entry(tile) {
94 96
             Entry::Vacant(entry) => {
95 97
                 let img_option = if load {
96
-                    cache.get_async(tile_coord, source, true)
98
+                    if self.use_async {
99
+                        cache.get_async(tile_coord, source, true)
100
+                    } else {
101
+                        cache.get_sync(tile_coord, source, true)
102
+                    }
97 103
                 } else {
98 104
                     cache.lookup(tile)
99 105
                 };

+ 4
- 0
src/tile_loader.rs Ver fichero

@@ -264,6 +264,7 @@ impl TileLoader {
264 264
 
265 265
         match image::open(source.local_tile_path(tile)) {
266 266
             Ok(img) => {
267
+                debug!("sync ok from path {:?}", tile);
267 268
                 Some(img)
268 269
             },
269 270
             Err(_) => {
@@ -284,13 +285,16 @@ impl TileLoader {
284 285
                                             warn!("could not write file {}, {}", &path.display(), e.description());
285 286
                                         }
286 287
                                     }
288
+                                    debug!("sync ok from network {:?}", tile);
287 289
                                     return Some(img);
288 290
                                 }
289 291
                             }
290 292
                         }
291 293
                     }
294
+                    debug!("sync fail from network {:?}", tile);
292 295
                     None
293 296
                 } else {
297
+                    debug!("sync fail from path {:?}", tile);
294 298
                     None
295 299
                 }
296 300
             },