diff options
| author | Kirill Petrashin <kirill8201@yandex.ru> | 2026-03-26 14:02:39 +0300 |
|---|---|---|
| committer | Kirill Petrashin <kirill8201@yandex.ru> | 2026-03-26 14:02:39 +0300 |
| commit | 86f00ecf96149e0dd489979bd39e076131a16cf5 (patch) | |
| tree | f5666d92b5264e753be39b7b4f58505218b93cd1 | |
| parent | 56099c2b9e185c21376b3f2f98f72f300b4bea70 (diff) | |
| download | astar-86f00ecf96149e0dd489979bd39e076131a16cf5.tar.xz | |
Clean up draw_map() a bit
| -rw-r--r-- | map.c | 63 |
1 files changed, 35 insertions, 28 deletions
@@ -200,12 +200,8 @@ Map file_plaintext_map(char *filename, size_t *width, size_t *height, Position * return map; } -/* FIXME: I don't think we need DRAW_MAP_OFFSET_{X,Y} anymore - * Although, at the same time, it does make less magic values, so I guess it's fine */ -/* TODO: Maybe add an option to render with ▄? that doubles the resolution, but requires us to use ncursesw, probably. */ /* TODO: so many fucking arguments lmao. Break it down into several functions? */ void draw_map(Map map, size_t width, size_t height, int offset_x, int offset_y, Position start, Position goal, Position *cursor, Path path, char visited[height][width], PositionPQ *frontier) { - (void)path; /* I think it flickers less when we do that */ wnoutrefresh(stdscr); @@ -221,7 +217,7 @@ void draw_map(Map map, size_t width, size_t height, int offset_x, int offset_y, mvaddch(i + offset_y, DRAW_MAP_OFFSET_X + width * 2 + 1 + offset_x + 2, ' '); } - /* Draw the borders*/ + /* Draw the borders */ attron(COLOR_PAIR(WALL_COLOR)); for (size_t i = 0; i <= width*2 + 3; i++) { /* Horizontal */ mvaddch(DRAW_MAP_OFFSET_Y - 1 + offset_y, i + offset_x, WALL_CHAR); @@ -236,30 +232,41 @@ void draw_map(Map map, size_t width, size_t height, int offset_x, int offset_y, attroff(COLOR_PAIR(WALL_COLOR)); /* Draw field */ - char c; /* The char for the current tile */ - for (size_t i = 0; i < height; i++) { - for (size_t j = 0; j < width; j++) { - int color_pair = 0; /* The color pair of the current char */ - switch (map[i][j]) { - case EMPTY: - if (visited != NULL && visited[i][j]) - color_pair = COLOR_PAIR(VISITED_COLOR); - else - color_pair = COLOR_PAIR(EMPTY_COLOR); - c = EMPTY_CHAR; - break; - case WALL: - color_pair = COLOR_PAIR(WALL_COLOR); - c = WALL_CHAR; - break; - + if (map != NULL) { + char c; /* The char for the current tile */ + for (size_t i = 0; i < height; i++) { + for (size_t j = 0; j < width; j++) { + int color_pair = 0; /* The color pair of the current char */ + switch (map[i][j]) { + case EMPTY: + if (visited != NULL && visited[i][j]) + color_pair = COLOR_PAIR(VISITED_COLOR); + else + color_pair = COLOR_PAIR(EMPTY_COLOR); + c = EMPTY_CHAR; + break; + case WALL: + color_pair = COLOR_PAIR(WALL_COLOR); + c = WALL_CHAR; + break; + + } + attron(color_pair); + /* We draw two characters because they roughly make a square together. + * It looks WAY better if we do this. */ + mvaddch(i + DRAW_MAP_OFFSET_Y + offset_y, j*2 + DRAW_MAP_OFFSET_X + offset_x, c); + mvaddch(i + DRAW_MAP_OFFSET_Y + offset_y, j*2 + DRAW_MAP_OFFSET_X + 1 + offset_x, c); + attroff(color_pair); + } + } + } else { + for (size_t i = 0; i < height; i++) { + for (size_t j = 0; j < width; j++) { + if (visited != NULL && visited[i][j]) attron(COLOR_PAIR(VISITED_COLOR)); + mvaddch(i + DRAW_MAP_OFFSET_Y + offset_y, j*2 + DRAW_MAP_OFFSET_X + offset_x, ' '); + mvaddch(i + DRAW_MAP_OFFSET_Y + offset_y, j*2 + DRAW_MAP_OFFSET_X + 1 + offset_x, ' '); + if (visited != NULL && visited[i][j]) attroff(COLOR_PAIR(VISITED_COLOR)); } - attron(color_pair); - /* We draw two characters because they roughly make a square together. - * It looks WAY better if we do this. */ - mvaddch(i + DRAW_MAP_OFFSET_Y + offset_y, j*2 + DRAW_MAP_OFFSET_X + offset_x, c); - mvaddch(i + DRAW_MAP_OFFSET_Y + offset_y, j*2 + DRAW_MAP_OFFSET_X + 1 + offset_x, c); - attroff(color_pair); } } |
