ref: 2b161b5a8e1292b5bc0dd6b261e5c1ab26d9addf
parent: 32dbd59557b6b1e476d011d207af4d9b0a8e91dc
author: qwx <qwx@sciops.net>
date: Mon Jul 18 21:03:39 EDT 2022
path(1): support benchmarking a∗/octile movement hardcoded
--- a/app/path/client.c
+++ b/app/path/client.c
@@ -56,9 +56,13 @@
{
fmtinstall('P', Pfmt);
fmtinstall('R', Rfmt);
+ fmtinstall('V', Vfmt);
+ fmtinstall('N', Nfmt);
initfs();
if(initmap(scen, v, m, a, d) < 0)
sysfatal("init: %r");
+ if(doprof)
+ return;
initdrw();
if((kc = initkeyboard(nil)) == nil)
sysfatal("initkeyboard: %r");
--- a/app/path/dat.h
+++ b/app/path/dat.h
@@ -9,5 +9,4 @@
Pdijkstra,
Pa∗,
};
-
extern int (*pathfn)(Node*, Node*);
--- a/app/path/fns.h
+++ b/app/path/fns.h
@@ -2,8 +2,11 @@
Node* scrselect(Point);
void updatedrw(void);
void evloop(void);
+void runscens(void);
int readscen(char*, Vertex*, int*, int*, int*);
void initfs(void);
+int Vfmt(Fmt*);
+int Nfmt(Fmt*);
int initmap(char*, Vertex, int, int, int);
void initdrw(void);
void resetdrw(void);
--- a/app/path/fs.c
+++ b/app/path/fs.c
@@ -9,6 +9,7 @@
/* https://bitbucket.org/dharabor/pathfinding/src/gppc/gppc-2014/scenarios/ */
typedef struct Sim Sim;
struct Sim{
+ Prof;
Vertex start;
Vertex goal;
double dist;
@@ -15,6 +16,29 @@
};
static VArray *sims;
+void
+runscens(void)
+{
+ Sim *sp, *se;
+
+ sp = sims->p;
+ se = sp + sims->n;
+ fprint(2, "id\tsteps\ttouched\texpanded\tupdated\topened\n");
+ while(sp < se){
+ start = p2n(sp->start);
+ goal = p2n(sp->goal);
+ if(pathfn(start, goal) < 0)
+ fprint(2, "runscens: findpath from %N to %N: %r\n",
+ start, goal);
+ memcpy(sp, &stats, sizeof stats);
+ fprint(2, "%zd\t%d\t%d\t%d\t%d\t%d\n",
+ sp - (Sim*)sims->p,
+ stats.steps, stats.touched, stats.opened,
+ stats.updated, stats.closed);
+ sp++;
+ }
+}
+
static int
readscenmaphdr(Biobuf *bf, Vertex *v)
{
@@ -65,7 +89,7 @@
for(t=s, u.x=0; (c=*t)!=0; t++, u.x++){
switch(c){
case 'S':
- case 'W':
+ case 'W':
case 'T':
case '@':
case 'O':
--- a/app/path/map.c
+++ b/app/path/map.c
@@ -8,8 +8,6 @@
int movemode;
int (*pathfn)(Node*, Node*);
-static int gotscen;
-
Vertex
n2s(Node *n)
{
@@ -49,7 +47,7 @@
clearmap(void)
{
start = goal = nil;
- if(grid == nil || gotscen)
+ if(grid == nil || doprof)
return;
cleargrid();
}
@@ -70,7 +68,7 @@
}
if(readscen(scen, &v, &m, &a, &d) < 0)
sysfatal("readscen: %r");
- gotscen = 1;
+ doprof = 1;
setparm(m, a, d);
return 0;
}
--- a/app/path/path.c
+++ b/app/path/path.c
@@ -119,6 +119,7 @@
break;
case 'm':
scen = EARGF(usage());
+ doprof = 1;
break;
case 's':
w = strtol(EARGF(usage()), &s, 0);
@@ -144,5 +145,9 @@
keyfn = grkey;
mousefn = grmouse;
init(scen, (Vertex){w,h}, m, a, d);
- evloop();
+ if(doprof)
+ runscens();
+ else
+ evloop();
+ threadexitsall(nil);
}