we prefer get_neighbours over rconnect

This commit is contained in:
Enno Rehling 2019-08-26 22:46:59 +02:00
parent 331546eec4
commit a5e59a6464

View file

@ -145,47 +145,45 @@ static region **internal_path_find(region * handle_start, const region * target,
node *root = new_node(handle_start, 0, NULL); node *root = new_node(handle_start, 0, NULL);
node **handle_end = &root->next; node **handle_end = &root->next;
node *n = root; node *n = root;
bool found = false;
assert(maxlen <= MAXDEPTH); assert(maxlen <= MAXDEPTH);
fset(handle_start, RF_MARK); fset(handle_start, RF_MARK);
while (n != NULL) { while (n != NULL) {
region *adj[MAXDIRECTIONS];
region *r = n->r; region *r = n->r;
int depth = n->distance + 1; int depth = n->distance + 1;
if (n->distance >= maxlen) if (n->distance >= maxlen)
break; break;
get_neighbours(r, adj);
for (d = 0; d != MAXDIRECTIONS; ++d) { for (d = 0; d != MAXDIRECTIONS; ++d) {
region *rn = rconnect(r, d); region *rn = adj[d];
if (rn == NULL) if (rn && !fval(rn, RF_MARK) && allowed(r, rn)) {
continue; if (rn == target) {
if (fval(rn, RF_MARK)) int i = depth;
continue; /* already been there */ path[i + 1] = NULL;
if (!allowed(r, rn)) path[i] = rn;
continue; /* can't go there */ while (n) {
if (rn == target) { path[--i] = n->r;
int i = depth; n = n->prev;
path[i + 1] = NULL; }
path[i] = rn; break;
while (n) { }
path[--i] = n->r; else {
n = n->prev; fset(rn, RF_MARK);
*handle_end = new_node(rn, depth, n);
handle_end = &(*handle_end)->next;
} }
found = true;
break;
}
else {
fset(rn, RF_MARK);
*handle_end = new_node(rn, depth, n);
handle_end = &(*handle_end)->next;
} }
} }
if (found) if (d != MAXDIRECTIONS) {
break; break;
}
n = n->next; n = n->next;
} }
free_nodes(root); free_nodes(root);
if (found) if (n) {
return path; return path;
}
return NULL; return NULL;
} }