From 8ec5be627d3408303407238dc98760c351654699 Mon Sep 17 00:00:00 2001 From: Kaj-Michael Lang Date: Thu, 10 Jan 2008 14:20:16 +0200 Subject: [PATCH] Misc. Renames and code moving. --- src/gps-nmea-parse.c | 4 +-- src/gps.c | 6 ++--- src/gps.h | 3 +-- src/gpx.c | 1 + src/latlon.h | 17 ++++++------- src/map-download.c | 27 +++++++++++++++++++++ src/map-download.h | 2 ++ src/map-repo.c | 22 ++++++----------- src/map.c | 2 +- src/map.h | 56 ++++++++++++++++++++++++++++++++++++++++++ src/mapper-types.h | 1 + src/utils.c | 26 -------------------- src/utils.h | 58 -------------------------------------------- 13 files changed, 110 insertions(+), 115 deletions(-) diff --git a/src/gps-nmea-parse.c b/src/gps-nmea-parse.c index 012226a..ec2faa2 100644 --- a/src/gps-nmea-parse.c +++ b/src/gps-nmea-parse.c @@ -188,7 +188,7 @@ channel_parse_rmc(gchar * sentence) if ((_conn_state == RCVR_FIXED) && (_track_store==TRUE)) { if ((_gps_filter==TRUE) && (track_drop_cnt<_filter_maxdrop)) { - integerize_data(&_gps, &_pos); + gps_integerize_data(&_gps, &_pos); if ( (_gps.hdop<_filter_hdop || _filter_hdop==0.0) && (_gps.vdop<_filter_vdop || _filter_vdop==0.0) && (fabs(_gps.heading-_gps.lheading)>_filter_angle || _filter_angle==0.0 ) && @@ -208,7 +208,7 @@ channel_parse_rmc(gchar * sentence) map_refresh_mark(); } else { track_drop_cnt=0; - integerize_data(&_gps, &_pos); + gps_integerize_data(&_gps, &_pos); track_add(_pos.time, newly_fixed); _gps.lheading=_gps.heading; map_refresh_mark(); diff --git a/src/gps.c b/src/gps.c index 8aa897b..fc3c940 100644 --- a/src/gps.c +++ b/src/gps.c @@ -25,6 +25,7 @@ #include "gps.h" #include "latlon.h" +#include "map.h" void gps_init(void) @@ -40,19 +41,18 @@ _gps.speed = 0.f; _pos.unitx = 0; _pos.unity = 0; -integerize_data(&_gps, &_pos); +gps_integerize_data(&_gps, &_pos); } /** * Convert the float lat/lon/speed/heading data into integer units. */ void -integerize_data(GpsData *gps, Point *pos) +gps_integerize_data(GpsData *gps, Point *pos) { gdouble tmp; latlon2unit(gps->lat, gps->lon, pos->unitx, pos->unity); - tmp=(gps->heading*(1.f/180.f))*G_PI; gps->vel_offsetx=(gint)(floorf(gps->speed*sinf(tmp)+0.5f)); gps->vel_offsety=-(gint)(floorf(gps->speed*cosf(tmp)+0.5f)); diff --git a/src/gps.h b/src/gps.h index 7f79ff3..78693ac 100644 --- a/src/gps.h +++ b/src/gps.h @@ -55,10 +55,9 @@ GpsSatelliteData _gps_sat[12]; Point _pos; void gps_init(void); +void gps_integerize_data(GpsData *gps, Point *pos); gboolean channel_cb_error(GIOChannel * src, GIOCondition condition, gpointer data); gboolean channel_cb_input(GIOChannel * src, GIOCondition condition, gpointer data); -void integerize_data(GpsData *gps, Point *pos); - #endif diff --git a/src/gpx.c b/src/gpx.c index da58f14..bafb012 100644 --- a/src/gpx.c +++ b/src/gpx.c @@ -54,6 +54,7 @@ #include "gps.h" #include "mapper-types.h" #include "latlon.h" +#include "map.h" #include "gpx.h" #define XML_DATE_FORMAT "%FT%T" diff --git a/src/latlon.h b/src/latlon.h index 9f0de8a..47dfe05 100644 --- a/src/latlon.h +++ b/src/latlon.h @@ -13,18 +13,17 @@ #define MERCATOR_TOP (3.14159188886811f) #define latlon2unit(lat, lon, unitx, unity) { \ - gdouble tmp; \ - unitx = (lon + 180.f) * (WORLD_SIZE_UNITS / 360.f) + 0.5f; \ - tmp = sinf(lat * (PI / 180.f)); \ - unity = 0.5f + (WORLD_SIZE_UNITS / MERCATOR_SPAN) \ - * (logf((1.f + tmp) / (1.f - tmp)) * 0.5f - MERCATOR_TOP); \ + gdouble tmp; \ + unitx = (lon + 180.f) * (WORLD_SIZE_UNITS / 360.f) + 0.5f; \ + tmp = sinf(lat * (PI / 180.f)); \ + unity = 0.5f + (WORLD_SIZE_UNITS / MERCATOR_SPAN) \ + * (logf((1.f + tmp) / (1.f - tmp)) * 0.5f - MERCATOR_TOP); \ } #define unit2latlon(unitx, unity, lat, lon) { \ - (lon) = ((unitx) * (360.f / WORLD_SIZE_UNITS)) - 180.f; \ - (lat) = (360.f * (atanf(expf(((unity) \ - * (MERCATOR_SPAN / WORLD_SIZE_UNITS)) \ - + MERCATOR_TOP)))) * (1.f / PI) - 90.f; \ + (lon) = ((unitx) * (360.f / WORLD_SIZE_UNITS)) - 180.f; \ + (lat) = (360.f * (atanf(expf(((unity) * (MERCATOR_SPAN / WORLD_SIZE_UNITS)) \ + + MERCATOR_TOP)))) * (1.f / PI) - 90.f; \ } typedef enum { diff --git a/src/map-download.c b/src/map-download.c index 017ba59..d1860a5 100644 --- a/src/map-download.c +++ b/src/map-download.c @@ -73,6 +73,33 @@ get_next_pui(gpointer key, gpointer value, ProgressUpdateInfo ** data) return TRUE; } +static gint +download_comparefunc(const ProgressUpdateInfo * a, const ProgressUpdateInfo * b, gpointer user_data) +{ +gint diff = (a->priority - b->priority); +if (diff) + return diff; +diff = (a->tilex - b->tilex); +if (diff) + return diff; +diff = (a->tiley - b->tiley); +if (diff) + return diff; +diff = (a->zoom - b->zoom); +if (diff) + return diff; +diff = (a->repo - b->repo); +if (diff) + return diff; +/* Otherwise, deletes are "greatest" (least priority). */ +if (!a->retries) + return (b->retries ? -1 : 0); +else if (!b->retries) + return (a->retries ? 1 : 0); +/* Do updates after non-updates (because they'll both be done anyway). */ +return (a->retries - b->retries); +} + /** * Free a ProgressUpdateInfo data structure that was allocated during the * auto-map-download process. diff --git a/src/map-download.h b/src/map-download.h index 28b5ed2..ab58330 100644 --- a/src/map-download.h +++ b/src/map-download.h @@ -7,6 +7,8 @@ #include #include "mapper-types.h" +#define INITIAL_DOWNLOAD_RETRIES (3) + CURLM *_curl_multi; GQueue *_curl_easy_queue; GTree *_pui_tree; diff --git a/src/map-repo.c b/src/map-repo.c index 8a55cee..8339a11 100644 --- a/src/map-repo.c +++ b/src/map-repo.c @@ -49,6 +49,7 @@ #include "route.h" #include "settings.h" #include "mapper-types.h" +#include "map-download.h" #include "ui-common.h" #include "help.h" @@ -649,13 +650,11 @@ repoman_dialog() /* Populate combo box and pages in notebook. */ for (i = 0, curr = _repo_list; curr; curr = curr->next, i++) { RepoData *rd = (RepoData *) curr->data; - RepoEditInfo *rei = - repoman_dialog_add_repo(&rmi, g_strdup(rd->name)); + RepoEditInfo *rei = repoman_dialog_add_repo(&rmi, g_strdup(rd->name)); /* Initialize fields with data from the RepoData object. */ gtk_entry_set_text(GTK_ENTRY(rei->txt_url), rd->url); - gtk_entry_set_text(GTK_ENTRY(rei->txt_cache_dir), - rd->cache_dir); + gtk_entry_set_text(GTK_ENTRY(rei->txt_cache_dir), rd->cache_dir); hildon_controlbar_set_value(HILDON_CONTROLBAR (rei->num_dl_zoom_steps), rd->dl_zoom_steps); @@ -672,17 +671,12 @@ repoman_dialog() } /* Connect signals. */ - g_signal_connect(G_OBJECT(btn_rename), "clicked", - G_CALLBACK(repoman_dialog_rename), &rmi); - g_signal_connect(G_OBJECT(btn_delete), "clicked", - G_CALLBACK(repoman_dialog_delete), &rmi); - g_signal_connect(G_OBJECT(btn_new), "clicked", - G_CALLBACK(repoman_dialog_new), &rmi); - g_signal_connect(G_OBJECT(rmi.cmb_repos), "changed", - G_CALLBACK(repoman_dialog_select), &rmi); + g_signal_connect(G_OBJECT(btn_rename), "clicked", G_CALLBACK(repoman_dialog_rename), &rmi); + g_signal_connect(G_OBJECT(btn_delete), "clicked", G_CALLBACK(repoman_dialog_delete), &rmi); + g_signal_connect(G_OBJECT(btn_new), "clicked", G_CALLBACK(repoman_dialog_new), &rmi); + g_signal_connect(G_OBJECT(rmi.cmb_repos), "changed", G_CALLBACK(repoman_dialog_select), &rmi); gtk_combo_box_set_active(GTK_COMBO_BOX(rmi.cmb_repos), curr_repo_index); - gtk_notebook_set_current_page(GTK_NOTEBOOK(rmi.notebook), - curr_repo_index); + gtk_notebook_set_current_page(GTK_NOTEBOOK(rmi.notebook), curr_repo_index); gtk_widget_show_all(rmi.dialog); diff --git a/src/map.c b/src/map.c index c02a421..e1a779c 100644 --- a/src/map.c +++ b/src/map.c @@ -1095,7 +1095,7 @@ _pos.unitx = x2unit((gint) (x + 0.5)); _pos.unity = y2unit((gint) (y + 0.5)); unit2latlon(_pos.unitx, _pos.unity, _gps.lat, _gps.lon); _gps.speed = 20.f; -integerize_data(&_gps, &_pos); +gps_integerize_data(&_gps, &_pos); track_add(time(NULL), FALSE); map_refresh_mark(); } diff --git a/src/map.h b/src/map.h index 03cc8a4..6c6b597 100644 --- a/src/map.h +++ b/src/map.h @@ -21,6 +21,62 @@ #include "utils.h" #include "mapper-types.h" +/** MAX_ZOOM defines the largest map zoom level we will download. + * (MAX_ZOOM - 1) is the largest map zoom level that the user can zoom to. + */ +#define MAX_ZOOM 16 + +#define TILE_SIZE_PIXELS (256) +#define TILE_SIZE_P2 (8) + +#ifdef WITH_DEVICE_770 +#define BUF_WIDTH_TILES (4) +#define BUF_HEIGHT_TILES (3) +#define BUF_WIDTH_PIXELS (1024) +#define BUF_HEIGHT_PIXELS (768) +#else +#define BUF_WIDTH_TILES (8) +#define BUF_HEIGHT_TILES (8) +#define BUF_WIDTH_PIXELS (2048) +#define BUF_HEIGHT_PIXELS (2048) +#endif + +#define WORLD_SIZE_UNITS (2 << (MAX_ZOOM + TILE_SIZE_P2)) + +#define tile2grid(tile) ((tile) << 3) +#define grid2tile(grid) ((grid) >> 3) +#define tile2pixel(tile) ((tile) << 8) +#define pixel2tile(pixel) ((pixel) >> 8) +#define tile2unit(tile) ((tile) << (8 + _zoom)) +#define unit2tile(unit) ((unit) >> (8 + _zoom)) +#define tile2zunit(tile, zoom) ((tile) << (8 + zoom)) +#define unit2ztile(unit, zoom) ((unit) >> (8 + zoom)) + +#define grid2pixel(grid) ((grid) << 5) +#define pixel2grid(pixel) ((pixel) >> 5) +#define grid2unit(grid) ((grid) << (5 + _zoom)) +#define unit2grid(unit) ((unit) >> (5 + _zoom)) + +#define pixel2unit(pixel) ((pixel) << _zoom) +#define unit2pixel(pixel) ((pixel) >> _zoom) +#define pixel2zunit(pixel, zoom) ((pixel) << (zoom)) + +#define unit2bufx(unit) (unit2pixel(unit) - tile2pixel(_base_tilex)) +#define bufx2unit(x) (pixel2unit(x) + tile2unit(_base_tilex)) +#define unit2bufy(unit) (unit2pixel(unit) - tile2pixel(_base_tiley)) +#define bufy2unit(y) (pixel2unit(y) + tile2unit(_base_tiley)) + +#define unit2x(unit) (unit2pixel(unit) - tile2pixel(_base_tilex) - _offsetx) +#define x2unit(x) (pixel2unit(x + _offsetx) + tile2unit(_base_tilex)) +#define unit2y(unit) (unit2pixel(unit) - tile2pixel(_base_tiley) - _offsety) +#define y2unit(y) (pixel2unit(y + _offsety) + tile2unit(_base_tiley)) + +#define leadx2unit() (_pos.unitx + (_lead_ratio) * pixel2unit(_gps.vel_offsetx)) +#define leady2unit() (_pos.unity + (0.6f*_lead_ratio)*pixel2unit(_gps.vel_offsety)) + +/* Pans are done two "grids" at a time, or 64 pixels. */ +#define PAN_UNITS (grid2unit(2)) + #define MACRO_RECALC_CENTER(center_unitx, center_unity) { \ switch(_center_mode) \ { \ diff --git a/src/mapper-types.h b/src/mapper-types.h index 6792b4b..e4fdec0 100644 --- a/src/mapper-types.h +++ b/src/mapper-types.h @@ -60,6 +60,7 @@ typedef enum { CAT_LABEL, CAT_DESC, CAT_POI_CNT, + CAT_ICON, CAT_NUM_COLUMNS } CategoryList; diff --git a/src/utils.c b/src/utils.c index 4b00d8e..0a690ea 100644 --- a/src/utils.c +++ b/src/utils.c @@ -24,29 +24,3 @@ gdk_beep(); #endif } -gint -download_comparefunc(const ProgressUpdateInfo * a, const ProgressUpdateInfo * b, gpointer user_data) -{ -gint diff = (a->priority - b->priority); -if (diff) - return diff; -diff = (a->tilex - b->tilex); -if (diff) - return diff; -diff = (a->tiley - b->tiley); -if (diff) - return diff; -diff = (a->zoom - b->zoom); -if (diff) - return diff; -diff = (a->repo - b->repo); -if (diff) - return diff; -/* Otherwise, deletes are "greatest" (least priority). */ -if (!a->retries) - return (b->retries ? -1 : 0); -else if (!b->retries) - return (a->retries ? 1 : 0); -/* Do updates after non-updates (because they'll both be done anyway). */ -return (a->retries - b->retries); -} diff --git a/src/utils.h b/src/utils.h index 970ff48..a0ae697 100644 --- a/src/utils.h +++ b/src/utils.h @@ -69,65 +69,8 @@ #define SQR(s) ((s)*(s)) -/** MAX_ZOOM defines the largest map zoom level we will download. - * (MAX_ZOOM - 1) is the largest map zoom level that the user can zoom to. - */ -#define MAX_ZOOM 16 - -#define TILE_SIZE_PIXELS (256) -#define TILE_SIZE_P2 (8) - -#ifdef WITH_DEVICE_770 -#define BUF_WIDTH_TILES (4) -#define BUF_HEIGHT_TILES (3) -#define BUF_WIDTH_PIXELS (1024) -#define BUF_HEIGHT_PIXELS (768) -#else -#define BUF_WIDTH_TILES (8) -#define BUF_HEIGHT_TILES (8) -#define BUF_WIDTH_PIXELS (2048) -#define BUF_HEIGHT_PIXELS (2048) -#endif - #define ARRAY_CHUNK_SIZE (1024) #define BUFFER_SIZE (2048) -#define WORLD_SIZE_UNITS (2 << (MAX_ZOOM + TILE_SIZE_P2)) - -#define tile2grid(tile) ((tile) << 3) -#define grid2tile(grid) ((grid) >> 3) -#define tile2pixel(tile) ((tile) << 8) -#define pixel2tile(pixel) ((pixel) >> 8) -#define tile2unit(tile) ((tile) << (8 + _zoom)) -#define unit2tile(unit) ((unit) >> (8 + _zoom)) -#define tile2zunit(tile, zoom) ((tile) << (8 + zoom)) -#define unit2ztile(unit, zoom) ((unit) >> (8 + zoom)) - -#define grid2pixel(grid) ((grid) << 5) -#define pixel2grid(pixel) ((pixel) >> 5) -#define grid2unit(grid) ((grid) << (5 + _zoom)) -#define unit2grid(unit) ((unit) >> (5 + _zoom)) - -#define pixel2unit(pixel) ((pixel) << _zoom) -#define unit2pixel(pixel) ((pixel) >> _zoom) -#define pixel2zunit(pixel, zoom) ((pixel) << (zoom)) - -#define unit2bufx(unit) (unit2pixel(unit) - tile2pixel(_base_tilex)) -#define bufx2unit(x) (pixel2unit(x) + tile2unit(_base_tilex)) -#define unit2bufy(unit) (unit2pixel(unit) - tile2pixel(_base_tiley)) -#define bufy2unit(y) (pixel2unit(y) + tile2unit(_base_tiley)) - -#define unit2x(unit) (unit2pixel(unit) - tile2pixel(_base_tilex) - _offsetx) -#define x2unit(x) (pixel2unit(x + _offsetx) + tile2unit(_base_tilex)) -#define unit2y(unit) (unit2pixel(unit) - tile2pixel(_base_tiley) - _offsety) -#define y2unit(y) (pixel2unit(y + _offsety) + tile2unit(_base_tiley)) - -#define leadx2unit() (_pos.unitx + (_lead_ratio) * pixel2unit(_gps.vel_offsetx)) -#define leady2unit() (_pos.unity + (0.6f*_lead_ratio)*pixel2unit(_gps.vel_offsety)) - -/* Pans are done two "grids" at a time, or 64 pixels. */ -#define PAN_UNITS (grid2unit(2)) - -#define INITIAL_DOWNLOAD_RETRIES (3) #define MACRO_PARSE_INT(tofill, str) { \ gchar *error_check; \ @@ -206,6 +149,5 @@ if (_http_proxy_host) { \ #endif void sound_noise(void); -gint download_comparefunc(const ProgressUpdateInfo * a, const ProgressUpdateInfo * b, gpointer user_data); #endif -- 2.39.5