]> Pileus Git - grits/blobdiff - src/plugins/sat.c
Fix compiler warnings
[grits] / src / plugins / sat.c
index edbe652834ae855349e3873bf4bcd6cd0cfb3c77..1e61f1de2c630fb6d10e1489be3d82c71929ea39 100644 (file)
 struct _LoadTileData {
        GisPluginSat *sat;
        GisTile      *tile;
-       GdkPixbuf    *pixbuf;
+       gchar        *path;
 };
 static gboolean _load_tile_cb(gpointer _data)
 {
        struct _LoadTileData *data = _data;
-       GisPluginSat *sat    = data->sat;
-       GisTile      *tile   = data->tile;
-       GdkPixbuf    *pixbuf = data->pixbuf;
+       GisPluginSat *sat  = data->sat;
+       GisTile      *tile = data->tile;
+       gchar        *path = data->path;
        g_free(data);
 
-       /* Create Texture */
+       /* Load pixbuf */
        g_debug("GisPluginSat: _load_tile_cb start");
+       GdkPixbuf *pixbuf = gdk_pixbuf_new_from_file(path, NULL);
+       if (!pixbuf) {
+               g_warning("GisPluginSat: _load_tile - Error loading pixbuf %s", path);
+               g_remove(path);
+               g_free(path);
+               return FALSE;
+       }
+       g_free(path);
+
+       /* Create Texture */
        guchar   *pixels = gdk_pixbuf_get_pixels(pixbuf);
        gboolean  alpha  = gdk_pixbuf_get_has_alpha(pixbuf);
        gint      width  = gdk_pixbuf_get_width(pixbuf);
@@ -92,19 +102,11 @@ static void _load_tile(GisTile *tile, gpointer _sat)
 {
        GisPluginSat *sat = _sat;
        g_debug("GisPluginSat: _load_tile start %p", g_thread_self());
-       char *path = gis_wms_fetch(sat->wms, tile, GIS_ONCE, NULL, NULL);
        struct _LoadTileData *data = g_new0(struct _LoadTileData, 1);
-       data->sat   = sat;
-       data->tile   = tile;
-       data->pixbuf = gdk_pixbuf_new_from_file(path, NULL);
-       if (data->pixbuf) {
-               g_idle_add_full(G_PRIORITY_LOW, _load_tile_cb, data, NULL);
-       } else {
-               g_warning("GisPluginSat: _load_tile - Error loading pixbuf %s", path);
-               g_free(data);
-               g_remove(path);
-       }
-       g_free(path);
+       data->sat  = sat;
+       data->tile = tile;
+       data->path = gis_wms_fetch(sat->wms, tile, GIS_ONCE, NULL, NULL);
+       g_idle_add_full(G_PRIORITY_LOW, _load_tile_cb, data, NULL);
        g_debug("GisPluginSat: _load_tile end %p", g_thread_self());
 }
 
@@ -116,21 +118,21 @@ static gboolean _free_tile_cb(gpointer data)
 }
 static void _free_tile(GisTile *tile, gpointer _sat)
 {
-       GisPluginSat *sat = _sat;
-       g_debug("GisPluginSat: _free_tile: %p=%d", tile->data, *(guint*)tile->data);
-       g_idle_add_full(G_PRIORITY_LOW, _free_tile_cb, tile->data, NULL);
+       g_debug("GisPluginSat: _free_tile: %p", tile->data);
+       if (tile->data)
+               g_idle_add_full(G_PRIORITY_LOW, _free_tile_cb, tile->data, NULL);
 }
 
 static gpointer _update_tiles(gpointer _sat)
 {
        g_debug("GisPluginSat: _update_tiles");
        GisPluginSat *sat = _sat;
-       g_mutex_lock(sat->mutex);
-       gdouble lat, lon, elev;
-       gis_viewer_get_location(sat->viewer, &lat, &lon, &elev);
-       gis_tile_update(sat->tiles,
+       if (!g_mutex_trylock(sat->mutex))
+               return NULL;
+       GisPoint eye;
+       gis_viewer_get_location(sat->viewer, &eye.lat, &eye.lon, &eye.elev);
+       gis_tile_update(sat->tiles, &eye,
                        MAX_RESOLUTION, TILE_WIDTH, TILE_WIDTH,
-                       lat, lon, elev,
                        _load_tile, sat);
        gis_tile_gc(sat->tiles, time(NULL)-10,
                        _free_tile, sat);
@@ -147,6 +149,13 @@ static void _on_location_changed(GisViewer *viewer,
        g_thread_create(_update_tiles, sat, FALSE, NULL);
 }
 
+static gpointer _threaded_init(GisPluginSat *sat)
+{
+       _load_tile(sat->tiles, sat);
+       _update_tiles(sat);
+       return NULL;
+}
+
 /***********
  * Methods *
  ***********/
@@ -165,15 +174,14 @@ GisPluginSat *gis_plugin_sat_new(GisViewer *viewer)
        sat->viewer = g_object_ref(viewer);
 
        /* Load initial tiles */
-       _load_tile(sat->tiles, sat);
-       g_thread_create(_update_tiles, sat, FALSE, NULL);
+       g_thread_create((GThreadFunc)_threaded_init, sat, FALSE, NULL);
 
        /* Connect signals */
        sat->sigid = g_signal_connect(sat->viewer, "location-changed",
                        G_CALLBACK(_on_location_changed), sat);
 
        /* Add renderers */
-       gis_viewer_add(viewer, GIS_OBJECT(sat->tiles), GIS_LEVEL_WORLD, 0);
+       gis_viewer_add(viewer, GIS_OBJECT(sat->tiles), GIS_LEVEL_WORLD, FALSE);
 
        return sat;
 }