]> git.pond.sub.org Git - empserver/commitdiff
Fix when best_path() prints A* performance statistics
authorMarkus Armbruster <armbru@pond.sub.org>
Sat, 19 Feb 2011 12:50:10 +0000 (13:50 +0100)
committerMarkus Armbruster <armbru@pond.sub.org>
Tue, 12 Apr 2011 19:40:08 +0000 (21:40 +0200)
Print them when A* actually runs, not when best_path() finds a path.
Statistics for unsuccessful runs were lost, and old statistics were
printed for path cache hits.

src/lib/common/path.c

index 965da6e29b81ea838ad47818b855fdd713f09707..9cdf959ec389380e0db58aed13805b0bbaead32b 100644 (file)
@@ -98,6 +98,7 @@ best_path(struct sctstr *from, struct sctstr *to, char *path, int mob_type)
     static struct bestp *mybestpath;
     struct as_data *adp;
     struct as_path *ap;
+    int res;
 
     if (!mybestpath)
        mybestpath = bp_init();
@@ -110,19 +111,19 @@ best_path(struct sctstr *from, struct sctstr *to, char *path, int mob_type)
        adp->to.y = to->sct_y;
        mybestpath->bp_mobtype = mob_type;
 
-       if (as_search(adp) < 0)
+       res = as_search(adp);
+#ifdef AS_STATS
+       as_stats(adp, stderr);
+       fprintf(stderr, "neighbor cache %zu bytes\n",
+               WORLD_SZ() * 6 * sizeof(struct sctstr *));
+#endif
+       if (res < 0)
            return -1;
        ap = adp->path;
     }
 
     if (bp_path(ap, path) < 0)
        return -1;
-
-#ifdef AS_STATS
-    as_stats(adp, stderr);
-    fprintf(stderr, "neighbor cache %zu bytes\n",
-           WORLD_SZ() * 6 * sizeof(struct sctstr *));
-#endif /* AS_STATS */
     return 0;
 }