X-Git-Url: http://pileus.org/git/?p=aweather;a=blobdiff_plain;f=src%2Fplugins%2Fradar.c;h=94b18c6cbc613e602ba9d0f75af196b67f5f9733;hp=52d94c92d0ed1411c67abb3bafd8a4d255863609;hb=ba4b91f8cb014e34b496070aeb806415c363434f;hpb=8addcb17f030c9d9330f125f6160eedbccddf63d diff --git a/src/plugins/radar.c b/src/plugins/radar.c index 52d94c9..94b18c6 100644 --- a/src/plugins/radar.c +++ b/src/plugins/radar.c @@ -1,5 +1,5 @@ /* - * Copyright (C) 2009-2010 Andy Spencer + * Copyright (C) 2009-2011 Andy Spencer * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -16,12 +16,11 @@ */ #define _XOPEN_SOURCE -#include +#include #include #include #include #include -#include #include #include @@ -41,7 +40,7 @@ static void _gtk_bin_set_child(GtkBin *bin, GtkWidget *new) } static gchar *_find_nearest(time_t time, GList *files, - gsize offset, gchar *format) + gsize offset) { g_debug("RadarSite: find_nearest ..."); time_t nearest_time = 0; @@ -50,7 +49,11 @@ static gchar *_find_nearest(time_t time, GList *files, struct tm tm = {}; for (GList *cur = files; cur; cur = cur->next) { gchar *file = cur->data; - strptime(file+offset, format, &tm); + sscanf(file+offset, "%4d%2d%2d_%2d%2d", + &tm.tm_year, &tm.tm_mon, &tm.tm_mday, + &tm.tm_hour, &tm.tm_min); + tm.tm_year -= 1900; + tm.tm_mon -= 1; if (ABS(time - mktime(&tm)) < ABS(time - nearest_time)) { nearest_file = file; @@ -144,7 +147,7 @@ gpointer _site_update_thread(gpointer _site) "^\\w{4}_\\d{8}_\\d{4}$", site->city->code, "\\d+ (.*)", (offline ? NULL : dir_list)); g_free(dir_list); - gchar *nearest = _find_nearest(site->time, files, 5, "%Y%m%d_%H%M"); + gchar *nearest = _find_nearest(site->time, files, 5); g_list_foreach(files, (GFunc)g_free, NULL); g_list_free(files); if (!nearest) { @@ -179,7 +182,7 @@ gpointer _site_update_thread(gpointer _site) } grits_object_hide(GRITS_OBJECT(site->level2), site->hidden); grits_viewer_add(site->viewer, GRITS_OBJECT(site->level2), - GRITS_LEVEL_WORLD+1, TRUE); + GRITS_LEVEL_WORLD+3, TRUE); out: g_idle_add(_site_update_end, site); @@ -248,6 +251,8 @@ void radar_site_load(RadarSite *site) gtk_notebook_append_page(GTK_NOTEBOOK(site->pconfig), site->config, gtk_label_new(site->city->name)); gtk_widget_show_all(site->config); + if (gtk_notebook_get_current_page(GTK_NOTEBOOK(site->pconfig)) == 0) + gtk_notebook_set_current_page(GTK_NOTEBOOK(site->pconfig), -1); /* Set up radar loading */ site->time_id = g_signal_connect_swapped(site->viewer, "time-changed", @@ -278,12 +283,11 @@ void _site_on_location_changed(GritsViewer *viewer, radar_site_unload(site); } -gboolean _site_add_marker(gpointer _site) +gboolean _site_add_marker(RadarSite *site) { - RadarSite *site = _site; site->marker = grits_marker_new(site->city->name); GRITS_OBJECT(site->marker)->center = site->city->pos; - GRITS_OBJECT(site->marker)->lod = EARTH_R*site->city->lod; + GRITS_OBJECT(site->marker)->lod = EARTH_R*0.75*site->city->lod; grits_viewer_add(site->viewer, GRITS_OBJECT(site->marker), GRITS_LEVEL_OVERLAY, FALSE); return FALSE; @@ -300,6 +304,7 @@ RadarSite *radar_site_new(city_t *city, GtkWidget *pconfig, "level2" G_DIR_SEPARATOR_S); site->city = city; site->pconfig = pconfig; + site->hidden = TRUE; /* Set initial location */ gdouble lat, lon, elev; @@ -307,7 +312,7 @@ RadarSite *radar_site_new(city_t *city, GtkWidget *pconfig, _site_on_location_changed(viewer, lat, lon, elev, site); /* Add marker */ - g_idle_add_full(G_PRIORITY_LOW, _site_add_marker, site, NULL); + _site_add_marker(site); /* Connect signals */ site->location_id = g_signal_connect(viewer, "location-changed", @@ -373,13 +378,14 @@ static void _conus_update_end_copy(GritsTile *tile, guchar *pixels) glGenTextures(1, tile->data); } + gchar *clear = g_malloc0(2048*2048*4); guint *tex = tile->data; glBindTexture(GL_TEXTURE_2D, *tex); glPixelStorei(GL_UNPACK_ALIGNMENT, 1); glPixelStorei(GL_PACK_ALIGNMENT, 1); glTexImage2D(GL_TEXTURE_2D, 0, 4, 2048, 2048, 0, - GL_RGBA, GL_UNSIGNED_BYTE, NULL); + GL_RGBA, GL_UNSIGNED_BYTE, clear); glTexSubImage2D(GL_TEXTURE_2D, 0, 1,1, CONUS_WIDTH/2,CONUS_HEIGHT, GL_RGBA, GL_UNSIGNED_BYTE, pixels); tile->coords.n = 1.0/(CONUS_WIDTH/2); @@ -391,6 +397,7 @@ static void _conus_update_end_copy(GritsTile *tile, guchar *pixels) glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP); glFlush(); + g_free(clear); } /* Split the pixbuf into east and west halves (with 2K sides) @@ -419,7 +426,7 @@ static void _conus_update_end_split(guchar *pixels, guchar *west, guchar *east, dst[0] = src[0]; dst[1] = src[1]; dst[2] = src[2]; - dst[3] = 0xff; + dst[3] = 0xff * 0.75; for (int j = 0; j < G_N_ELEMENTS(alphamap); j++) if (src[0] == alphamap[j][0] && src[1] == alphamap[j][1] && @@ -493,17 +500,18 @@ gpointer _conus_update_thread(gpointer _conus) if (time(NULL) - conus->time < 60*60*5 && !offline) { /* radar.weather.gov is full of lies. * the index pages get cached and out of date */ - struct tm tm; - gmtime_r(&conus->time, &tm); - time_t onthe8 = conus->time - 60*((tm.tm_min+1)%10+1); - gmtime_r(&onthe8, &tm); + /* gmtime is not thread safe, but it's not used very often so + * hopefully it'll be alright for now... :-( */ + struct tm *tm = gmtime(&conus->time); + time_t onthe8 = conus->time - 60*((tm->tm_min+1)%10+1); + tm = gmtime(&onthe8); nearest = g_strdup_printf("Conus_%04d%02d%02d_%02d%02d_N0Ronly.gif", - tm.tm_year+1900, tm.tm_mon+1, tm.tm_mday, - tm.tm_hour, tm.tm_min); + tm->tm_year+1900, tm->tm_mon+1, tm->tm_mday, + tm->tm_hour, tm->tm_min); } else { GList *files = grits_http_available(conus->http, "^Conus_[^\"]*_N0Ronly.gif$", "", NULL, NULL); - nearest = _find_nearest(conus->time, files, 6, "%Y%m%d_%H%M"); + nearest = _find_nearest(conus->time, files, 6); g_list_foreach(files, (GFunc)g_free, NULL); g_list_free(files); if (!nearest) { @@ -563,8 +571,8 @@ RadarConus *radar_conus_new(GtkWidget *pconfig, conus->tile[1] = grits_tile_new(NULL, CONUS_NORTH, south, east, mid); conus->tile[0]->zindex = 2; conus->tile[1]->zindex = 1; - grits_viewer_add(viewer, GRITS_OBJECT(conus->tile[0]), GRITS_LEVEL_WORLD, TRUE); - grits_viewer_add(viewer, GRITS_OBJECT(conus->tile[1]), GRITS_LEVEL_WORLD, TRUE); + grits_viewer_add(viewer, GRITS_OBJECT(conus->tile[0]), GRITS_LEVEL_WORLD+2, FALSE); + grits_viewer_add(viewer, GRITS_OBJECT(conus->tile[1]), GRITS_LEVEL_WORLD+2, FALSE); conus->time_id = g_signal_connect_swapped(viewer, "time-changed", G_CALLBACK(_conus_update), conus); @@ -769,9 +777,13 @@ static void grits_plugin_radar_dispose(GObject *gobject) { g_debug("GritsPluginRadar: dispose"); GritsPluginRadar *self = GRITS_PLUGIN_RADAR(gobject); - g_signal_handler_disconnect(self->config, self->tab_id); - grits_viewer_remove(self->viewer, GRITS_OBJECT(self->hud)); - radar_conus_free(self->conus); + if (self->viewer) { + GritsViewer *viewer = self->viewer; + self->viewer = NULL; + g_signal_handler_disconnect(self->config, self->tab_id); + grits_viewer_remove(viewer, GRITS_OBJECT(self->hud)); + radar_conus_free(self->conus); + } /* Drop references */ G_OBJECT_CLASS(grits_plugin_radar_parent_class)->dispose(gobject); }