aboutsummaryrefslogtreecommitdiff
path: root/path.c
diff options
context:
space:
mode:
authorKirill Petrashin <kirill8201@yandex.ru>2026-04-14 18:50:25 +0300
committerKirill Petrashin <kirill8201@yandex.ru>2026-04-14 18:50:25 +0300
commitfe2e095a4a331bc284e857d8fcc6babc84ab09f3 (patch)
treef505af602ef34f540e339007543e28c9b1df07a3 /path.c
parent7f45a02a1383da0f0a0e72d61388e1e07974a6e3 (diff)
downloadastar-fe2e095a4a331bc284e857d8fcc6babc84ab09f3.tar.xz
Some anim() shit
Diffstat (limited to 'path.c')
-rw-r--r--path.c15
1 files changed, 11 insertions, 4 deletions
diff --git a/path.c b/path.c
index a8410fc..442ca14 100644
--- a/path.c
+++ b/path.c
@@ -12,14 +12,15 @@
#include "error.h"
#include "config.h"
+char anim_automatic = 0;
+
/* TODO: make it move the map maybe to show the path */
/* TODO: figure out input when automatic = 1. timeout() seems useful */
int anim(Map map, size_t width, size_t height, Position start, Position end, Position *cur, char **visited, PositionPQ *frontier) {
- static char automatic = 0;
while (1) {
draw_map(map, width, height, start, end, cur, NULL, visited, frontier);
set_message("cur: %zu %zu", cur->x, cur->y); print_message(height);
- if (automatic) { wrefresh(stdscr); usleep(ANIM_DELAY_USEC); return 0; }
+ if (anim_automatic) { wrefresh(stdscr); usleep(ANIM_DELAY_USEC); return 0; }
switch (getch()) {
case 'h': map_offset_x += 2; break;
case 'l': map_offset_x -= 2; break;
@@ -51,7 +52,7 @@ int anim(Map map, size_t width, size_t height, Position start, Position end, Pos
/* TODO: Add a binding to do a bmp */
- case 'a': automatic = 1; break;
+ case 'a': anim_automatic = 1; break;
case 'q': clear_message(); return -1;
default: return 0;
}
@@ -60,6 +61,8 @@ int anim(Map map, size_t width, size_t height, Position start, Position end, Pos
}
/* BLOODY FUCK IT WORKS */
Path breadth_first_search_path(int dirs, Map map, size_t width, size_t height, Position start, Position end, char **visited, char should_anim) {
+ anim_automatic = 0;
+
/* The function to use to find neighbours */
unsigned int (*neighbours)(Position[], size_t[], Position, size_t, size_t, char**) = NULL;
switch (dirs) {
@@ -123,6 +126,8 @@ Path breadth_first_search_path(int dirs, Map map, size_t width, size_t height, P
}
Path dijkstra_path(int dirs, Map map, size_t width, size_t height, Position start, Position end, char **visited, char should_anim) {
+ anim_automatic = 0;
+
/* The function to use to find neighbours */
unsigned int (*neighbours)(Position[], size_t[], Position, size_t, size_t, char**) = NULL;
@@ -191,6 +196,8 @@ Path dijkstra_path(int dirs, Map map, size_t width, size_t height, Position star
}
Path astar_path(int dirs, Map map, size_t width, size_t height, Position start, Position end, char **visited, char should_anim) {
+ anim_automatic = 0;
+
/* The function to use to find neighbours */
unsigned int (*neighbours)(Position[], size_t[], Position, size_t, size_t, char**) = NULL;
/* The heuristic function */
@@ -200,7 +207,7 @@ Path astar_path(int dirs, Map map, size_t width, size_t height, Position start,
switch (dirs) {
case 4: neighbours = &neighbours_4dir; heuristic = &manhattan_distance; break;
case 8: neighbours = &neighbours_8dir; heuristic = &diagonal_distance; break;
- default: error("Tried to call dijkstra_path with wrong direction amount\n");
+ default: error("Tried to call astar_path with wrong direction amount\n");
}
Path path = malloc(sizeof(PathNode)*height);