]> git.pond.sub.org Git - empserver/blobdiff - src/lib/update/finish.c
Merge branch 'pathfind' into pathfind-test
[empserver] / src / lib / update / finish.c
index 6ea7b77029c953735efd347930c08677dd76957f..9da4a8873feb58440b52674717c7bc572982bfb0 100644 (file)
@@ -77,7 +77,19 @@ finish_sects(int etu)
 
     logerror("assembling paths...\n");
     getrusage(RUSAGE_SELF, &rus1);
+
+    /* First, enable the best_path cacheing */
+    bp_enable_cachepath();
+
+    /* Now assemble the paths */
     assemble_dist_paths(import_cost);
+
+    /* Now disable the best_path cacheing */
+    bp_disable_cachepath();
+
+    /* Now, clear the best_path cache that may have been created */
+    bp_clear_cachepath();
+
     getrusage(RUSAGE_SELF, &rus2);
     logerror("done assembling paths %g user %g system",
             rus2.ru_utime.tv_sec + rus2.ru_utime.tv_usec / 1e6
@@ -110,6 +122,7 @@ finish_sects(int etu)
 
 }
 
+#ifdef USE_PATH_FIND
 static int
 distcmp(const void *p, const void *q)
 {
@@ -126,6 +139,7 @@ distcmp(const void *p, const void *q)
        return d;
     return b - a;
 }
+#endif
 
 static void
 assemble_dist_paths(double *import_cost)
@@ -133,6 +147,7 @@ assemble_dist_paths(double *import_cost)
     struct sctstr *sp;
     struct sctstr *dist;
     int n;
+#ifdef USE_PATH_FIND
     static int *job;
     int uid, i;
     coord dx = 1, dy = 0;      /* invalid */
@@ -171,4 +186,26 @@ assemble_dist_paths(double *import_cost)
        import_cost[uid] = path_find_to(sp->sct_x, sp->sct_y);
     }
     path_find_print_stats();
+#else  /* !USE_PATH_FIND */
+    char *path;
+    double d;
+    char buf[512];
+
+    for (n = 0; NULL != (sp = getsectid(n)); n++) {
+       import_cost[n] = -1;
+       if ((sp->sct_dist_x == sp->sct_x) && (sp->sct_dist_y == sp->sct_y))
+           continue;
+       dist = getsectp(sp->sct_dist_x, sp->sct_dist_y);
+       if (CANT_HAPPEN(!dist))
+           continue;
+       if (sp->sct_own != dist->sct_own)
+           continue;
+       /* Now, get the best distribution path over roads */
+       /* Note we go from the dist center to the sector.  This gives
+          us the import path for that sector. */
+       path = BestDistPath(buf, dist, sp, &d);
+       if (path)
+           import_cost[n] = d;
+    }
+#endif /* !USE_PATH_FIND */
 }