X-Git-Url: https://git.gag.com/?p=fw%2Faltos;a=blobdiff_plain;f=altosuilib%2FAltosUIMapCache.java;h=9cc32e24d4adec1544f1d69c8eba6e915c63932c;hp=3f1512dfdaa2eb10531cfac6bf7b915917fd1d9d;hb=ade2cc9abb8ca403a9ae5d1f9c145ab72ce94919;hpb=97269bb90c1602a1f8c54fc7b6c34383a0370621 diff --git a/altosuilib/AltosUIMapCache.java b/altosuilib/AltosUIMapCache.java index 3f1512df..9cc32e24 100644 --- a/altosuilib/AltosUIMapCache.java +++ b/altosuilib/AltosUIMapCache.java @@ -24,33 +24,36 @@ import java.awt.*; import java.io.*; import java.net.*; -public class AltosUIMapCache { +public class AltosUIMapCache implements AltosUIMapCacheListener { static final int success = 0; static final int loading = 1; static final int failed = 2; static final int bad_request = 3; static final int forbidden = 4; - static final int min_cache_size = 9; - static final int max_cache_size = 24; + int min_cache_size; /* configured minimum cache size */ + int cache_size; /* current cache size */ + int requested_cache_size; /* cache size computed by application */ private Object fetch_lock = new Object(); private Object cache_lock = new Object(); - int cache_size = min_cache_size; - AltosUIMapImage[] images = new AltosUIMapImage[cache_size]; long used; public void set_cache_size(int new_size) { + + requested_cache_size = new_size; + if (new_size < min_cache_size) new_size = min_cache_size; - if (new_size > max_cache_size) - new_size = max_cache_size; + if (new_size == cache_size) return; + System.out.printf("cache size now %d\n", new_size); + synchronized(cache_lock) { AltosUIMapImage[] new_images = new AltosUIMapImage[new_size]; @@ -91,8 +94,12 @@ public class AltosUIMapCache { try { image = new AltosUIMapImage(tile, store); image.used = used++; - if (images[oldest] != null) + if (images[oldest] != null) { + System.out.printf("drop %s\n", images[oldest].store.file.toString()); images[oldest].flush(); + } + + System.out.printf("load %s\n", store.file.toString()); images[oldest] = image; @@ -109,6 +116,28 @@ public class AltosUIMapCache { } } + public void map_cache_changed(int map_cache) { + min_cache_size = map_cache; + + set_cache_size(requested_cache_size); + } + + public void dispose() { + AltosUIPreferences.unregister_map_cache_listener(this); + + for (int i = 0; i < cache_size; i++) { + AltosUIMapImage image = images[i]; + + if (image != null) + image.flush(); + } + } + public AltosUIMapCache() { + min_cache_size = AltosUIPreferences.map_cache(); + + set_cache_size(0); + + AltosUIPreferences.register_map_cache_listener(this); } }