From b77f89156d03d6d4f7cb989ff7328927ed1940f7 Mon Sep 17 00:00:00 2001 From: Kaj-Michael Lang Date: Mon, 17 Mar 2008 16:03:49 +0200 Subject: [PATCH] Some location and map rendering changes: - Make center_ratio a parameter to the macros. - Combine some debug output to make it more clear. - Misc other things. --- src/cb.c | 11 ++++++---- src/map-download.c | 4 +++- src/map.c | 44 ++++++++++++++++++++----------------- src/map.h | 34 ++++++++++++++--------------- src/osm-db.c | 54 ++++++++++++++++++++++++++-------------------- src/osm-db.h | 2 -- 6 files changed, 82 insertions(+), 67 deletions(-) diff --git a/src/cb.c b/src/cb.c index 7e561e4..7a0f8c8 100644 --- a/src/cb.c +++ b/src/cb.c @@ -494,8 +494,8 @@ gboolean menu_cb_settings(GtkAction * action) { settings_dialog(); -MACRO_RECALC_FOCUS_BASE(); -MACRO_RECALC_FOCUS_SIZE(); +MACRO_RECALC_FOCUS_BASE(_center_ratio); +MACRO_RECALC_FOCUS_SIZE(_center_ratio); map_force_redraw(); return TRUE; } @@ -511,9 +511,12 @@ if (settings_dialog_gps(_gps)) { gps_connect_now(_gps); } } -MACRO_RECALC_FOCUS_BASE(); -MACRO_RECALC_FOCUS_SIZE(); +#if 0 +MACRO_RECALC_FOCUS_BASE(_center_ratio); +MACRO_RECALC_FOCUS_SIZE(_center_ratio); map_force_redraw(); +#endif + return TRUE; } diff --git a/src/map-download.c b/src/map-download.c index 3e0ff7a..32cdd1a 100644 --- a/src/map-download.c +++ b/src/map-download.c @@ -399,11 +399,13 @@ map_download_idle_refresh(ProgressUpdateInfo * pui) /* Test if download succeeded (only if retries != 0). */ if (!pui->retries || g_file_test(pui->dest_str, G_FILE_TEST_EXISTS)) { gint zoom_diff = pui->zoom - _zoom; + /* Only refresh at same or "lower" (more detailed) zoom level. */ if (zoom_diff >= 0) { + guint tilex, tiley, tilex_end, tiley_end; + /* If zoom has changed since we first put in the request for * this tile, then we may have to update more than one tile. */ - guint tilex, tiley, tilex_end, tiley_end; for (tilex = pui->tilex << zoom_diff, tilex_end = tilex + (1 << zoom_diff); tilex < tilex_end; tilex++) { for (tiley = pui->tiley << zoom_diff, tiley_end = tiley + (1 << zoom_diff); tiley < tiley_end; tiley++) { g_debug("MDIR: %d %d", tilex, tiley); diff --git a/src/map.c b/src/map.c index a4bfd83..0e58605 100644 --- a/src/map.c +++ b/src/map.c @@ -239,24 +239,18 @@ guint tw, th; tw=TILE_SIZE_PIXELS*((widget->allocation.width/TILE_SIZE_PIXELS)+2); th=TILE_SIZE_PIXELS*((widget->allocation.height/TILE_SIZE_PIXELS)+2); -g_debug("MAP: configure %d %d -> (%d,%d)", widget->allocation.width, widget->allocation.height, tw, th); - if (map_pixmap==NULL) { - g_debug("Initial buffer pixmap"); map_pixmap=gdk_pixmap_new(widget->window, tw, th, -1); } else { if (tw>buf_width_pixels || th>buf_height_pixels) { - g_debug("MC: Large buffer"); g_object_unref(map_pixmap); map_pixmap=gdk_pixmap_new(widget->window, tw, th, -1); - } else if (twwindow, tw, th, -1); - } else { - g_debug("MC: No change ?"); } } +g_assert(map_pixmap); buf_width_pixels=tw; buf_height_pixels=th; @@ -272,8 +266,8 @@ _screen_grids_halfheight = pixel2grid(_screen_height_pixels) / 2; scale_rect.x = (_screen_width_pixels - SCALE_WIDTH) / 2; scale_rect.width = SCALE_WIDTH; -MACRO_RECALC_FOCUS_BASE(); -MACRO_RECALC_FOCUS_SIZE(); +MACRO_RECALC_FOCUS_BASE(_center_ratio); +MACRO_RECALC_FOCUS_SIZE(_center_ratio); _min_center.unitx = pixel2unit(grid2pixel(_screen_grids_halfwidth)); _min_center.unity = pixel2unit(grid2pixel(_screen_grids_halfheight)); @@ -489,8 +483,10 @@ if (map_drag_id>0) if (_home.valid) map_draw_position_icon(&_home); + if(_show_poi) map_render_all_pois(buf_width_pixels, buf_height_pixels); + if(_show_tracks>0) map_render_paths(); } @@ -503,7 +499,7 @@ void map_force_redraw(void) { guint new_x, new_y; -#ifdef DEBUG_MAP_TIME +#ifdef DEBUG gulong tms; g_timer_start(map_timer); @@ -513,10 +509,11 @@ for (new_y = 0; new_y < buf_height_tiles; ++new_y) map_render_tile(_base_tilex + new_x, _base_tiley + new_y, new_x * TILE_SIZE_PIXELS, new_y * TILE_SIZE_PIXELS, FALSE); } -#ifdef DEBUG_MAP_TIME +#ifdef DEBUG g_timer_stop(map_timer); g_debug("Full redraw: %f sec\n", g_timer_elapsed(map_timer, &tms)); #endif + map_render_data(); MACRO_QUEUE_DRAW_AREA(); } @@ -532,15 +529,15 @@ return _zoom; * current zoom level, or if the new zoom is invalid * (not MIN_ZOOM <= new_zoom < MAX_ZOOM), then this method does nothing. */ -void +gboolean map_set_zoom(guint new_zoom) { /* Note that, since new_zoom is a guint and MIN_ZOOM is 0, this if * condition also checks for new_zoom >= MIN_ZOOM. */ if (new_zoom > (MAX_ZOOM - 1)) - return; + return FALSE; if (new_zoom == _zoom) - return; + return FALSE; _zoom = new_zoom / _curr_repo->view_zoom_steps * _curr_repo->view_zoom_steps; _world_size_tiles = unit2tile(WORLD_SIZE_UNITS); @@ -563,11 +560,12 @@ _base_tiley = grid2tile(pixel2grid(unit2pixel(_center.unity)) - _screen_grids_ha /* New zoom level, so we can't reuse the old buffer's pixels. */ /* Update state variables. */ MACRO_RECALC_OFFSET(); -MACRO_RECALC_FOCUS_BASE(); -MACRO_RECALC_FOCUS_SIZE(); +MACRO_RECALC_FOCUS_BASE(_center_ratio); +MACRO_RECALC_FOCUS_SIZE(_center_ratio); map_set_mark(&_gps->data); map_force_redraw(); +return TRUE; } /** @@ -621,6 +619,7 @@ if (new_base_tilex != _base_tilex || new_base_tiley != _base_tiley) { base_old_x = base_new_x + new_base_tilex - _base_tilex; _base_tilex = new_base_tilex; _base_tiley = new_base_tiley; + for (j = 0; j < buf_height_tiles; ++j, new_y += ioy, old_y += ioy) { new_x = base_new_x; old_x = base_old_x; @@ -651,7 +650,7 @@ if (new_base_tilex != _base_tilex || new_base_tiley != _base_tiley) { } MACRO_RECALC_OFFSET(); -MACRO_RECALC_FOCUS_BASE(); +MACRO_RECALC_FOCUS_BASE(_center_ratio); map_set_mark(&_gps->data); MACRO_QUEUE_DRAW_AREA(); @@ -756,6 +755,9 @@ gint x,y; x = unit2bufx(unitx); y = unit2bufy(unity); +if ((x > buf_width_pixels) || (y > buf_height_pixels)) + return; + gdk_draw_pixbuf(map_pixmap, _gc[COLORABLE_POI], p, 0, 0, x - gdk_pixbuf_get_width(p) / 2, @@ -1289,8 +1291,10 @@ gint ilat, ilon; static gboolean inp=FALSE; /* We run the gtk mainloop in progress callback so we can be called again, we don't like that */ -if (inp==TRUE) +if (inp==TRUE) { + g_debug("LOC: Query in progress"); return; +} inp=TRUE; ilat=lat2mp_int(lat); @@ -1299,7 +1303,7 @@ ilon=lon2mp_int(lon); if (_gps->data.fix>1 && !force) osm_set_way_range_from_speed(_gps->data.speed); else - osm_set_way_range(OSM_RANGE_WAY/8); + osm_set_way_range(2800); osm_progress_set_widget(_db, _progress_item); osm_get_location_data(ilat, ilon, _gps->data.heading, &map_loc); diff --git a/src/map.h b/src/map.h index aa0e7ba..9337454 100644 --- a/src/map.h +++ b/src/map.h @@ -83,13 +83,13 @@ }; #define MACRO_RECALC_OFFSET() { \ - _offsetx = grid2pixel(unit2grid(_center.unitx) - _screen_grids_halfwidth - tile2grid(_base_tilex)); \ - _offsety = grid2pixel(unit2grid(_center.unity) - _screen_grids_halfheight - tile2grid(_base_tiley)); \ + _offsetx = grid2pixel(unit2grid(_center.unitx) - _screen_grids_halfwidth - tile2grid(_base_tilex)); \ + _offsety = grid2pixel(unit2grid(_center.unity) - _screen_grids_halfheight - tile2grid(_base_tiley)); \ } -#define MACRO_RECALC_FOCUS_BASE() { \ - _focus.unitx = x2unit(_screen_width_pixels * _center_ratio / 20); \ - _focus.unity = y2unit(_screen_height_pixels * _center_ratio / 20); \ +#define MACRO_RECALC_FOCUS_BASE(sens) { \ + _focus.unitx = x2unit(_screen_width_pixels * sens / 20); \ + _focus.unity = y2unit(_screen_height_pixels * sens / 20); \ } #define MACRO_QUEUE_DRAW_AREA() \ @@ -97,22 +97,22 @@ /* Render all on-map metadata an annotations, including POI and paths. */ #define MACRO_MAP_RENDER_DATA() { \ - if(_show_poi) \ - map_render_poi(); \ - if(_show_tracks > 0) \ - map_render_paths(); \ + if(_show_poi) \ + map_render_poi(); \ + if(_show_tracks > 0) \ + map_render_paths(); \ } -#define MACRO_RECALC_FOCUS_SIZE() { \ - _focus_unitwidth = pixel2unit((10 - _center_ratio) * _screen_width_pixels / 10); \ - _focus_unitheight = pixel2unit((10 - _center_ratio) * _screen_height_pixels / 10); \ +#define MACRO_RECALC_FOCUS_SIZE(sens) { \ + _focus_unitwidth = pixel2unit((10 - sens) * _screen_width_pixels / 10); \ + _focus_unitheight = pixel2unit((10 - sens) * _screen_height_pixels / 10); \ } #define MACRO_RECALC_CENTER_BOUNDS() { \ - _min_center.unitx = pixel2unit(grid2pixel(_screen_grids_halfwidth)); \ - _min_center.unity = pixel2unit(grid2pixel(_screen_grids_halfheight)); \ - _max_center.unitx = WORLD_SIZE_UNITS-grid2unit(_screen_grids_halfwidth) - 1;\ - _max_center.unity = WORLD_SIZE_UNITS-grid2unit(_screen_grids_halfheight)- 1;\ + _min_center.unitx = pixel2unit(grid2pixel(_screen_grids_halfwidth)); \ + _min_center.unity = pixel2unit(grid2pixel(_screen_grids_halfheight)); \ + _max_center.unitx = WORLD_SIZE_UNITS-grid2unit(_screen_grids_halfwidth) - 1;\ + _max_center.unity = WORLD_SIZE_UNITS-grid2unit(_screen_grids_halfheight) - 1;\ } typedef enum { @@ -191,7 +191,7 @@ gboolean map_key_zoom_timeout(); int map_zoom(gint zdir); guint map_get_zoom(void); -void map_set_zoom(guint zoom); +gboolean map_set_zoom(guint zoom); gboolean map_zoom_in(void); gboolean map_zoom_out(void); diff --git a/src/osm-db.c b/src/osm-db.c index c2a5f95..28d218b 100644 --- a/src/osm-db.c +++ b/src/osm-db.c @@ -46,6 +46,9 @@ #define OSM_RANGE_STEP (8192) #define OSM_RANGE_STOP (65535) +/* Way range for searching again */ +#define OSM_RANGE_WAY (20000) + static sqlite3 *osmdb; static gboolean osm_db_ok; @@ -91,15 +94,13 @@ void osm_set_way_range(guint sr) { way_dist_range=sr; +g_debug("way_range set to %d", sr); } void osm_set_way_range_from_speed(gfloat speed) { -if (speed>54.0) - way_dist_range=OSM_RANGE_WAY; -else - way_dist_range=OSM_RANGE_WAY-lrint((speed/4)*1000); +osm_set_way_range(speed>54.0 ? OSM_RANGE_WAY : (OSM_RANGE_WAY-lrint((speed/4)*1000))); } /*****************************************************************************/ @@ -159,7 +160,7 @@ if (dbpw!=NULL && w==NULL) { dbpw=w; if (w!=NULL) { osm_progress_show(db); - sid=g_timeout_add(200, (GSourceFunc)osm_progress_pulse, NULL); + sid=g_timeout_add(330, (GSourceFunc)osm_progress_pulse, NULL); } } @@ -703,15 +704,17 @@ GList *iter; GList *w=NULL; guint range=OSM_RANGE_START; osm_way *cw=NULL; +guint found_ways=0; gdouble pdist=START_DIST, dist_n, dist_p; while ((w=osm_find_nearest_way_nodes(lat, lon, range))==NULL && range<=OSM_RANGE_STOP) { range+=OSM_RANGE_STEP; g_debug("Trying with range: %d", range); } -g_debug("Found %d ways withing range %d", g_list_length(w), range); +found_ways=g_list_length(w); +g_debug("Found %d ways withing range %d", found_ways, range); -if (g_list_length(w)==0) +if (found_ways==0) return NULL; for (iter=w; iter!=NULL; iter=iter->next) { @@ -719,23 +722,24 @@ for (iter=w; iter!=NULL; iter=iter->next) { osm_way_node *wnp; osm_way *way=(osm_way*)iter->data; - g_debug("Way: %d (%d) has %d nodes, nearest is %d,%d", - way->id, way->type, way->nodecnt, way->f, way->t); - way->node_t=NULL; wnn=osm_way_get_next_node(way); if (osm_way_distance(lat, lon, way->node_f, wnn, &dist_n)==FALSE) { osm_way_node_free(wnn); dist_n=START_DIST; - } else if (dist_ndistance=dist_n; way->node_t=wnn; - g_debug("#1 distance: %f (%f)", dist_n, pdist); + } else { + dist_n=START_DIST; } + g_debug("WayN: #%d (T:%d), %d nodes, near [%d-%d], D: %.2f (Valid: %s)", + way->id, way->type, way->nodecnt, way->f, way->t, dist_n, dist_n==START_DIST ? "F" : "T"); + wnp=osm_way_get_prev_node(way); if (osm_way_distance(lat, lon, way->node_f, wnp, &dist_p)==FALSE) { osm_way_node_free(wnp); @@ -748,10 +752,12 @@ for (iter=w; iter!=NULL; iter=iter->next) { osm_way_node_free(wnn); } way->node_t=wnp; - g_debug("#2 distance: %f (%f)", dist_p, pdist); + } else { + dist_p=START_DIST; } - g_debug("Found close way, distance: %f %f (%f)", dist_n, dist_p, pdist); + g_debug("WayP: #%d (T:%d), %d nodes, near [%d-%d], D: %.2f (Valid: %s)", + way->id, way->type, way->nodecnt, way->f, way->t, dist_p, dist_p==START_DIST ? "F" : "T"); if (!cw) { osm_way_free(way); @@ -765,14 +771,13 @@ if (cw==NULL) osm_way_get_name(cw); if (cw->type==WAY_MOTORWAY || cw->type==WAY_TRUNK || - cw->type==WAY_PRIMARY || cw->type==WAY_SECONDARY || - cw->type==WAY_TERTIARY) { + cw->type==WAY_PRIMARY || cw->type==WAY_SECONDARY || cw->type==WAY_TERTIARY) { osm_way_get_ref(cw); } -g_debug("Found way: (ID: %d): [%s]:[%s][%s]", cw->id, cw->name, cw->ref, cw->int_ref); -g_debug("T: %d F: %d N#: %d D: %f", cw->type, cw->flags, cw->nodecnt, cw->dist); -g_debug("\tNF#: %d NT#: %d (D: %f)", cw->f, cw->t, cw->distance); +g_debug("Found: (#%d): [%s]:[%s][%s]", cw->id, cw->name, cw->ref, cw->int_ref); +g_debug("T: %d F: %d N#: %d D: %.2f", cw->type, cw->flags, cw->nodecnt, cw->dist); +g_debug("NF#: %d NT#: %d (DC: %.2f)", cw->f, cw->t, cw->distance); return cw; } @@ -980,7 +985,7 @@ if (map_loc->street && osm_way_distance(lat, lon, map_loc->street->node_f, map_l */ if ( (dist>(gdouble)way_dist_range) || (fabs(heading-map_loc->heading)>10.0)) { /* We have moved a large amount, check way again */ - g_debug("Distance %f > %f range or angle %f > 10.0, checking location", + g_debug("Distance %.2f > %.2f range or angle %f > 10.0, checking location", dist, (gdouble)way_dist_range, fabs(heading-map_loc->heading)); osm_way_free(map_loc->street); map_loc->street=osm_find_nearest_way(lat, lon); @@ -1037,8 +1042,10 @@ if (check_place==TRUE && d>way_dist_range*4) { g_debug("Near city: %s", map_loc->primary->name); else if (osm_find_nearest_place(NODE_PLACE_TOWN, lat, lon, &map_loc->primary)==TRUE) g_debug("Near town: %s", map_loc->primary->name); - else + else { + g_assert(map_loc->primary!=NULL); g_debug("Unknown"); + } } else { g_debug("In: %s", map_loc->primary ? map_loc->primary->name : "?"); } @@ -1053,9 +1060,10 @@ if (check_place==TRUE && d>way_dist_range*4) { g_debug("Near city: %s", map_loc->primary->name); else if (osm_find_nearest_place(NODE_PLACE_TOWN, lat, lon, &map_loc->primary)==TRUE) g_debug("Near town: %s", map_loc->primary->name); - else + else { + g_assert(map_loc->primary!=NULL); g_debug("Unknown"); - + } } } diff --git a/src/osm-db.h b/src/osm-db.h index d7c8369..f443532 100644 --- a/src/osm-db.h +++ b/src/osm-db.h @@ -24,8 +24,6 @@ #include #include "osm.h" -#define OSM_RANGE_WAY (20000) - /** Generic search item list indexes */ typedef enum { ITEM_ID, -- 2.39.5