]> err.no Git - mapper/commitdiff
Remove usage of global route waypoint variables
authorKaj-Michael Lang <milang@tal.org>
Mon, 21 Apr 2008 08:15:26 +0000 (11:15 +0300)
committerKaj-Michael Lang <milang@tal.org>
Mon, 21 Apr 2008 08:15:26 +0000 (11:15 +0300)
src/cb.c
src/map.c
src/path.c
src/route.c
src/route.h
src/ui-common.c

index 82a5674364232e9b6fadbabb90cf9d664ca52b09..0df1230bf882f5501f98f936659f20d38bd3d3c0 100644 (file)
--- a/src/cb.c
+++ b/src/cb.c
@@ -349,11 +349,13 @@ return TRUE;
 gboolean 
 menu_cb_goto_nextway(GtkAction * action)
 {
-if (_next_way && _next_way->point->unity) {
+g_return_val_if_fail(_route, TRUE);
+
+if (_route->next_way && _route->next_way->point->unity) {
        if (_center_mode > 0)
                set_action_activate("autocenter_none", TRUE);
 
-       map_center_unit(_next_way->point->unitx, _next_way->point->unity);
+       map_center_unit(_route->next_way->point->unitx, _route->next_way->point->unity);
 } else {
        MACRO_BANNER_SHOW_INFO(_window, _("There is no next waypoint."));
 }
index 48f41f02160d2ac6896cc2637a2f4e3027b88d98..f05c18871c1d258c8fb426b8106551e44297ca0e 100644 (file)
--- a/src/map.c
+++ b/src/map.c
@@ -912,11 +912,15 @@ gdk_draw_arc(map_pixmap, gc, FALSE, x1 - _draw_width, y1 - _draw_width, 2 * _dra
  * redrawn.
  */
 void 
-map_render_path(Path * path, GdkGC ** gc)
+map_render_path(Path *path, GdkGC **gc)
 {
 Point *curr;
 WayPoint *wcurr;
 
+g_return_if_fail(path);
+if (path->head==path->tail)
+       return;
+
 /* gc is a pointer to the first GC to use (for plain points).  (gc + 1)
  * is a pointer to the GC to use for waypoints, and (gc + 2) is a pointer
  * to the GC to use for breaks. */
@@ -937,24 +941,36 @@ for (curr = path->head, wcurr = path->whead; curr++ != path->tail;) {
 }
 }
 
+void
+map_render_next_waypoint(Path *path)
+{
+guint x1, y1;
+
+g_return_if_fail(path);
+if (!path->next_way)
+       return;
+
+g_return_if_fail(path->next_way->point);
+
+x1=unit2bufx(path->next_way->point->unitx);
+y1=unit2bufy(path->next_way->point->unity);
+
+if ((x1 < buf_width_pixels) && (y1 < buf_height_pixels)) {
+       /* Draw the next waypoint as a break. */
+       gdk_draw_arc(map_pixmap, _gc[COLORABLE_ROUTE_BREAK], FALSE,
+               x1 - _draw_width, y1 - _draw_width, 
+               4 * _draw_width, 4 * _draw_width, 0, 360 * 64);
+}
+}
+
 void 
 map_render_paths(void)
 {
-if ((_show_tracks & ROUTES_MASK) && _route->head != _route->tail) {
+if (_show_tracks & ROUTES_MASK) {
        map_render_path(_route, _gc + COLORABLE_ROUTE);
 
        /* Now, draw the next waypoint on top of all other waypoints. */
-       if (_next_way) {
-               guint x1 = unit2bufx(_next_way->point->unitx);
-               guint y1 = unit2bufy(_next_way->point->unity);
-
-               if ((x1 < buf_width_pixels) && (y1 < buf_height_pixels)) {
-                       /* Draw the next waypoint as a break. */
-                       gdk_draw_arc(map_pixmap, _gc[COLORABLE_ROUTE_BREAK], FALSE,     /* FALSE: not filled. */
-                            x1 - _draw_width, y1 - _draw_width, 4 * _draw_width, 4 * _draw_width, 0,   /* start at 0 degrees. */
-                            360 * 64);
-               }
-       }
+       map_render_next_waypoint(_route);
 }
 if (_show_tracks & TRACKS_MASK)
        map_render_path(_track, _gc + COLORABLE_TRACK);
@@ -1321,11 +1337,11 @@ if (_dest.valid) {
 gtk_compass_set_dest_heading(_gps_compass, _dest.valid, (gfloat)dh);
 gtk_compass_set_dest_heading(_tab_compass, _dest.valid, (gfloat)dh);
 
-if (_next_way && _next_way->point) {
+if (_route->next_way && _route->next_way->point) {
        gdouble wp_lat, wp_lon;
        gfloat wc;
 
-       unit2latlon(_next_way->point->unitx,_next_way->point->unity, wp_lat, wp_lon);
+       unit2latlon(_route->next_way->point->unitx, _route->next_way->point->unity, wp_lat, wp_lon);
        wc=calculate_course(lat, lon, wp_lat, wp_lon);
        gtk_compass_set_way_heading(_gps_compass, TRUE, wc);
        gtk_compass_set_way_heading(_tab_compass, TRUE, wc);
index a1c8c4807c9e84b3d17896cbf728ec155b5f2b53..7e20514bac5bd57aa69656e893c8842d3430c543 100644 (file)
@@ -23,7 +23,6 @@ struct sql_select_stmt {
 };
 static struct sql_select_stmt sql;
 
-
 /* Path point add sensitivity */
 static gint sensitivity=3;
 
index 67966d87ed4abf7c0466c7640c165b4eb8b685a3..e972975c40609255f19a7055dc9fd07545a373ca 100644 (file)
@@ -84,14 +84,14 @@ if (!gps)
 if (!_announce_waypoints)
        return;
 
-if (!_next_way)
+if (!route->next_way)
        return;
 
 announce_thres_unsquared=(20+(guint)gps->speed)*_announce_notice_ratio*3;
 
-if (_next_way_dist_squared<(announce_thres_unsquared * announce_thres_unsquared) && _next_way!=announced_waypoint) {
-       announce_waypoint(_next_way->desc);
-       announced_waypoint=_next_way;
+if (route->next_way_dist_squared<(announce_thres_unsquared * announce_thres_unsquared) && route->next_way!=announced_waypoint) {
+       announce_waypoint(route->next_way->desc);
+       announced_waypoint=route->next_way;
 }
 
 }
@@ -102,7 +102,7 @@ if (_next_way_dist_squared<(announce_thres_unsquared * announce_thres_unsquared)
 void
 route_autoroute_check(Path *route)
 {
-if (_autoroute_data.enabled && !_autoroute_data.in_progress && _near_point_dist_squared > 400) {
+if (_autoroute_data.enabled && !_autoroute_data.in_progress && route->near_point_dist_squared > 400) {
        MACRO_BANNER_SHOW_INFO(_window, _("Recalculating directions..."));
        _autoroute_data.in_progress = TRUE;
        show_directions = FALSE;
@@ -515,9 +515,9 @@ return NULL;
 }
 
 /**
- * Updates _near_point, _next_way, and _next_wpt.  If quick is FALSE (as
+ * Updates near_point, next_way, and next_wpt.  If quick is FALSE (as
  * it is when this function is called from route_find_nearest_point), then
- * the entire list (starting from _near_point) is searched.  Otherwise, we
+ * the entire list (starting from near_point) is searched.  Otherwise, we
  * stop searching when we find a point that is farther away.
  */
 gboolean 
@@ -532,16 +532,16 @@ guint64 near_dist_squared;
  * waypoint", which is defined as the waypoint after the nearest point,
  * UNLESS we've passed that waypoint, in which case the waypoint after
  * that waypoint becomes the "next" waypoint. */
-if (_next_way) {
+if (route->next_way) {
        /* First, set near_dist_squared with the new distance from
-        * _near_point. */
-       near = _near_point;
+        * near_point. */
+       near = route->near_point;
        near_dist_squared = DISTANCE_SQUARED(_gps->data, *near);
 
        /* Now, search route for a closer point.  If quick is TRUE, then we'll
         * only search forward, only as long as we keep finding closer points.
         */
-       for (curr = _near_point; curr++ != route->tail;) {
+       for (curr = route->near_point; curr++ != route->tail;) {
                if (curr->unity) {
                        guint dist_squared = DISTANCE_SQUARED(_gps->data, *curr);
                        if (dist_squared <= near_dist_squared) {
@@ -553,13 +553,13 @@ if (_next_way) {
        }
 
        /* Update _near_point. */
-       _near_point = near;
-       _near_point_dist_squared = near_dist_squared;
+       route->near_point = near;
+       route->near_point_dist_squared = near_dist_squared;
 
-       for (wnext = wcurr = _next_way; wcurr != route->wtail; wcurr++) {
+       for (wnext = wcurr = route->next_way; wcurr != route->wtail; wcurr++) {
                if (wcurr->point < near || (wcurr->point == near && quick 
-                               && (_next_wpt && (DISTANCE_SQUARED(_gps->data, *near) > _next_way_dist_squared
-                               && DISTANCE_SQUARED(_gps->data, *_next_wpt) < _next_wpt_dist_squared))))
+                               && (route->next_wpt && (DISTANCE_SQUARED(_gps->data, *near) > route->next_way_dist_squared
+                               && DISTANCE_SQUARED(_gps->data, *route->next_wpt) < route->next_wpt_dist_squared))))
                    /* Okay, this else if expression warrants explanation.  If the
                     * nearest track point happens to be a waypoint, then we want to
                     * check if we have "passed" that waypoint.  To check this, we
@@ -574,65 +574,65 @@ if (_next_way) {
        }
 
        if (wnext == route->wtail && (wnext->point < near || (wnext->point == near && quick
-                                         && (_next_wpt && (DISTANCE_SQUARED (_gps->data, *near) > _next_way_dist_squared
-                                              && DISTANCE_SQUARED(_gps->data, *_next_wpt) < _next_wpt_dist_squared)))))
+                                         && (route->next_wpt && (DISTANCE_SQUARED (_gps->data, *near) > route->next_way_dist_squared
+                                              && DISTANCE_SQUARED(_gps->data, *route->next_wpt) < route->next_wpt_dist_squared)))))
        {
-               _next_way = NULL;
-               _next_wpt = NULL;
-               _next_way_dist_squared = -1;
-               _next_wpt_dist_squared = -1;
+               route->next_way = NULL;
+               route->next_wpt = NULL;
+               route->next_way_dist_squared = -1;
+               route->next_wpt_dist_squared = -1;
                ret = TRUE;
        }
-       /* Only update _next_way (and consequently _next_wpt) if _next_way is
+       /* Only update next_way (and consequently _next_wpt) if _next_way is
         * different, and record that fact for return. */
        else {
-               if (!quick || _next_way != wnext) {
-                       _next_way = wnext;
-                       _next_wpt = wnext->point;
-                       if (_next_wpt == route->tail)
-                               _next_wpt = NULL;
+               if (!quick || route->next_way != wnext) {
+                       route->next_way = wnext;
+                       route->next_wpt = wnext->point;
+                       if (route->next_wpt == route->tail)
+                               route->next_wpt = NULL;
                        else {
-                               while (!(++_next_wpt)->unity) {
-                                       if (_next_wpt == route->tail) {
-                                               _next_wpt = NULL;
+                               while (!(++route->next_wpt)->unity) {
+                                       if (route->next_wpt == route->tail) {
+                                               route->next_wpt = NULL;
                                                break;
                                        }
                                }
                        }
                        ret = TRUE;
                }
-               _next_way_dist_squared = DISTANCE_SQUARED(_gps->data, *wnext->point);
-               if (_next_wpt)
-                       _next_wpt_dist_squared = DISTANCE_SQUARED(_gps->data, *_next_wpt);
+               route->next_way_dist_squared = DISTANCE_SQUARED(_gps->data, *wnext->point);
+               if (route->next_wpt)
+                       route->next_wpt_dist_squared = DISTANCE_SQUARED(_gps->data, *route->next_wpt);
        }
 }
 return ret;
 }
 
 /**
- * Reset the _near_point data by searching the entire route for the nearest
+ * Reset the near_point data by searching the entire route for the nearest
  * route point and waypoint.
  */
 void 
 route_find_nearest_point(Path *route)
 {
-/* Initialize _near_point to first non-zero point. */
-_near_point = route->head;
-while (!_near_point->unity && _near_point != route->tail)
-       _near_point++;
+/* Initialize near_point to first non-zero point. */
+route->near_point = route->head;
+while (!route->near_point->unity && route->near_point != route->tail)
+       route->near_point++;
 
-/* Initialize _next_way. */
+/* Initialize next_way. */
 if (route->wtail == route->whead - 1 || (_autoroute_data.enabled && route->wtail == route->whead))
-       _next_way = NULL;
+       route->next_way = NULL;
 else
        /* We have at least one waypoint. */
-       _next_way = (_autoroute_data.enabled ? route->whead + 1 : route->whead);
+       route->next_way = (_autoroute_data.enabled ? route->whead + 1 : route->whead);
 
-_next_way_dist_squared = -1;
+route->next_way_dist_squared = -1;
 
 /* Initialize _next_wpt. */
-_next_wpt = NULL;
-_next_wpt_dist_squared = -1;
+route->next_wpt = NULL;
+route->next_wpt_dist_squared = -1;
 
 route_update_nears(route, FALSE);
 }
index f1200ffe84d48308254e3c9b5089d8c5b96fcfd5..39450c6c02115d281ee557e11a4b0637c6ba1b27 100644 (file)
 /** The current route. */
 Path *_route;
 
-/** Data for tracking waypoints for the purpose of announcement. */
-
-/* _near_point is the route point to which we are closest. */
-Point *_near_point;
-guint64 _near_point_dist_squared;
-
-/* _next_way is what we currently interpret to be the next waypoint. */
-WayPoint *_next_way;
-guint64 _next_way_dist_squared;
-gchar *_last_spoken_phrase;
-
-/* _next_wpt is the route point immediately following _next_way. */
-Point *_next_wpt;
-guint64 _next_wpt_dist_squared;
-
 /** The singleton auto-route-download data. */
 AutoRouteDownloadData _autoroute_data;
 
index 5a5fc61a0dd53e4c11a28e63619a0d8793e17424..be7964c6fba6ce92c69a28fcf65bfcbcd233f3a7 100644 (file)
@@ -754,7 +754,6 @@ ui_notebook.audio=gtk_notebook_append_page(notebook, an_ui->vbox, label);
 menu_maps_add_repos();
 menu_init_cmenu();
 
-_last_spoken_phrase = g_strdup("");
 memset(&_autoroute_data, 0, sizeof(_autoroute_data));
 
 g_signal_connect(G_OBJECT(_window), "delete_event", G_CALLBACK(mapper_cb_quit), NULL);