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,23 +145,19 @@ 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 (fval(rn, RF_MARK))
continue; /* already been there */
if (!allowed(r, rn))
continue; /* can't go there */
if (rn == target) { if (rn == target) {
int i = depth; int i = depth;
path[i + 1] = NULL; path[i + 1] = NULL;
@ -170,7 +166,6 @@ static region **internal_path_find(region * handle_start, const region * target,
path[--i] = n->r; path[--i] = n->r;
n = n->prev; n = n->prev;
} }
found = true;
break; break;
} }
else { else {
@ -179,13 +174,16 @@ static region **internal_path_find(region * handle_start, const region * target,
handle_end = &(*handle_end)->next; 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;
} }