diff options
| author | Kirill Petrashin <kirill8201@yandex.ru> | 2026-04-23 14:37:26 +0300 |
|---|---|---|
| committer | Kirill Petrashin <kirill8201@yandex.ru> | 2026-04-23 14:37:26 +0300 |
| commit | 53ed90ab4f3b493f1c3abd4aff4fa45f3f8a0909 (patch) | |
| tree | a7b01bf378aee70847fcda0aa49c8274eebcca67 /path.c | |
| parent | 6834ffa31842ca249514854bac8bae0f0022f104 (diff) | |
| download | astar-53ed90ab4f3b493f1c3abd4aff4fa45f3f8a0909.tar.xz | |
Make path reversable in map_editor()
Diffstat (limited to 'path.c')
| -rw-r--r-- | path.c | 24 |
1 files changed, 13 insertions, 11 deletions
@@ -337,14 +337,19 @@ void path_free(Path path, size_t height) { } void path_reverse(Path *path, size_t width, size_t height, Position *start, Position *end) { - Path new_path = path_new(width, height); - if (new_path == NULL) error("Failed to allocate path\n"); - - Position cur = *end; - while (cur.x != start->x || cur.y != start->y) { - Position parent = (*path)[cur.y][cur.x]; - new_path[parent.y][parent.x] = cur; - cur = parent; + if (*path != NULL) { + Path new_path = path_new(width, height); + if (new_path == NULL) error("Failed to allocate path\n"); + + Position cur = *end; + while (cur.x != start->x || cur.y != start->y) { + Position parent = (*path)[cur.y][cur.x]; + new_path[parent.y][parent.x] = cur; + cur = parent; + } + + path_free(*path, height); + *path = new_path; } /* Switch start and end around */ @@ -356,9 +361,6 @@ void path_reverse(Path *path, size_t width, size_t height, Position *start, Posi end->y ^= start->y; start->y ^= end->y; - path_free(*path, height); - *path = new_path; - return; } |
