From 40d4d279e41c336d5c4e9a1e07c7751bc76ecbfb Mon Sep 17 00:00:00 2001 From: Kirill Petrashin Date: Sun, 29 Mar 2026 15:01:21 +0300 Subject: Add arg to just generate a BMP --- main.c | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/main.c b/main.c index 5684e14..f876697 100644 --- a/main.c +++ b/main.c @@ -61,6 +61,8 @@ int main(int argc, char **argv) { size_t mheight = 10; /* Maze height */ char is_maze = 0; + char bmp_only = 0; + char *bmp_filename = NULL; char anim = 0; int dirs = 8; @@ -71,12 +73,13 @@ int main(int argc, char **argv) { * -a to animate the pathfinding (get input after each step) * -m {width}x{height} to give a maze of given size * -f {filename} to load a map from the filename + * -b {filename} to just generate a bitmap, no interface * -4 for four directions * -8 for eight directions */ /* TODO: Argument to choose the algorithm */ /* TODO: Argument to set seed */ int opt; - while ((opt = getopt(argc, argv, ":am:f:48")) != -1) { + while ((opt = getopt(argc, argv, ":am:f:b:48")) != -1) { switch (opt) { case 'a': anim = 1; break; case 'm': @@ -93,6 +96,10 @@ int main(int argc, char **argv) { case 'f': map = file_plaintext_map(optarg, &width, &height, &start_pos, &end_pos); break; + case 'b': + bmp_only = 1; + bmp_filename = optarg; + break; case '4': dirs = 4; break; case '8': dirs = 8; break; case '?': error("Unknown option: %c\n", optopt); @@ -116,7 +123,9 @@ int main(int argc, char **argv) { signal(SIGINT, sigint_handler); - init_ncurses(); + if (!bmp_only) { + init_ncurses(); + } int offset_x = 0, offset_y = 0; @@ -127,6 +136,12 @@ int main(int argc, char **argv) { Path path = NULL; path = breadth_first_search_path(dirs, map, width, height, start_pos, end_pos, visited, anim); + if (bmp_only) { + map_to_bmp(map, width, height, start_pos, end_pos, path, visited, bmp_filename); + printf("Wrote the bmp to %s\n", bmp_filename); + exit(0); + } + while (1) { draw_map(map, width, height, offset_x, offset_y, start_pos, end_pos, NULL, path, visited, NULL); char c = getch(); -- cgit v1.2.3