X-Git-Url: https://git.street.me.uk/andy/viking.git/blobdiff_plain/3becfffda014fd9d1e40c457cca6df2377ec0177..ff02058b8be006eb848eacb53a8716e357298552:/src/mapcache.c diff --git a/src/mapcache.c b/src/mapcache.c index 64101ddd..5485f178 100644 --- a/src/mapcache.c +++ b/src/mapcache.c @@ -18,10 +18,16 @@ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * */ +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif #include +#include #include +#include "globals.h" #include "mapcache.h" +#include "preferences.h" #include "config.h" @@ -46,8 +52,21 @@ static GMutex *mc_mutex = NULL; #define HASHKEY_FORMAT_STRING "%d-%d-%d-%d-%d-%d-%.3f-%.3f" #define HASHKEY_FORMAT_STRING_NOSHRINK_NOR_ALPHA "%d-%d-%d-%d-%d-" +static VikLayerParamScale params_scales[] = { + /* min, max, step, digits (decimal places) */ + { 1, 300, 1, 0 }, +}; + +static VikLayerParam prefs[] = { + { VIKING_PREFERENCES_NAMESPACE "mapcache_size", VIK_LAYER_PARAM_UINT, VIK_LAYER_GROUP_NONE, N_("Mapcache memory size (MB):"), VIK_LAYER_WIDGET_HSCALE, params_scales, NULL }, +}; + void a_mapcache_init () { + VikLayerParamData tmp; + tmp.u = VIK_CONFIG_MAPCACHE_SIZE / 1024 / 1024; + a_preferences_register(prefs, tmp, VIKING_PREFERENCES_GROUP_KEY); + mc_mutex = g_mutex_new(); cache = g_hash_table_new_full ( g_str_hash, g_str_equal, g_free, g_object_unref ); } @@ -113,6 +132,9 @@ void a_mapcache_add ( GdkPixbuf *pixbuf, gint x, gint y, gint z, guint8 type, gu g_mutex_lock(mc_mutex); cache_add(key, pixbuf); + // TODO: that should be done on preference change only... + max_queue_size = a_preferences_get(VIKING_PREFERENCES_NAMESPACE "mapcache_size")->u * 1024 * 1024; + if ( queue_size > max_queue_size ) { gchar *oldkey = list_shift_add_entry ( key ); cache_remove(oldkey); @@ -130,7 +152,7 @@ void a_mapcache_add ( GdkPixbuf *pixbuf, gint x, gint y, gint z, guint8 type, gu } g_mutex_unlock(mc_mutex); - if ( (++tmp == 100 )) { g_print("DEBUG: queue count=%d %u\n", queue_count, queue_size ); tmp=0; } + if ( (++tmp == 100 )) { g_print("DEBUG: queue count=%d size=%u\n", queue_count, queue_size ); tmp=0; } } GdkPixbuf *a_mapcache_get ( gint x, gint y, gint z, guint8 type, guint zoom, guint8 alpha, gdouble xshrinkfactor, gdouble yshrinkfactor )