aboutsummaryrefslogtreecommitdiff
path: root/map.c
diff options
context:
space:
mode:
authorKirill Petrashin <kirill8201@yandex.ru>2026-04-14 18:25:30 +0300
committerKirill Petrashin <kirill8201@yandex.ru>2026-04-14 18:25:30 +0300
commitf0b6bb6974c823c4b5a7deffce0748f2ff6370de (patch)
tree37ccd97ce0f10959006740ed4949d95b903a2f2f /map.c
parentc8d863b4b37a64f1df3cd4c25e6367949f2e6650 (diff)
downloadastar-f0b6bb6974c823c4b5a7deffce0748f2ff6370de.tar.xz
Change how messages are written, clean up differently
Diffstat (limited to 'map.c')
-rw-r--r--map.c42
1 files changed, 18 insertions, 24 deletions
diff --git a/map.c b/map.c
index ce8f949..035623a 100644
--- a/map.c
+++ b/map.c
@@ -12,6 +12,7 @@
int map_offset_x = 2;
int map_offset_y = 1;
+char message[MESSAGE_MAX_SIZE] = "";
Map empty_map(size_t width, size_t height) {
Map map = malloc(sizeof(MapTile*) * height);
@@ -214,7 +215,8 @@ Map file_plaintext_map(char *filename, size_t *width, size_t *height, Position *
void map_to_file_plaintext(char *filename, Map map, size_t width, size_t height, Position start, Position end) {
FILE *file = fopen(filename, "w");
if (file == NULL) {
- message(height, "Couldn't open %s for writing", filename);
+ set_message("Couldn't open %s for writing", filename);
+ print_message(height);
return;
}
@@ -232,7 +234,8 @@ void map_to_file_plaintext(char *filename, Map map, size_t width, size_t height,
putc('\n', file);
}
- message(height, "Saved the map to %s", filename);
+ set_message("Saved the map to %s", filename);
+ print_message(height);
return;
}
@@ -245,8 +248,7 @@ void draw_map(Map map, size_t width, size_t height, Position start, Position goa
* UPD: it was causing a bug, so I commented it out. I don't know why either */
//wnoutrefresh(stdscr);
- /* Clear the message line */
- if (move(height + map_offset_y + 1, map_offset_x - 2) != ERR) { clrtoeol(); };
+ erase();
/* Rendering boundaries, used to not render stuff that's outside the screen for performance */
size_t top_boundary = 0,
@@ -258,22 +260,6 @@ void draw_map(Map map, size_t width, size_t height, Position start, Position goa
if (top_boundary + LINES < height) bottom_boundary = top_boundary + LINES;
if (left_boundary + COLS/2 < height) right_boundary = left_boundary + COLS/2 + 1;
- /* Clean up the area around the map */
- for (ssize_t i = -1; i <= (ssize_t)(width*2 + 4); i++) { /* Horizontal */
- mvaddch(map_offset_y - 2, i + map_offset_x - 2, ' ');
- mvaddch(height + map_offset_y + 1, i + map_offset_x - 2, ' ');
- mvaddch(height + map_offset_y + 2, i + map_offset_x - 2, ' ');
- mvaddch(height + map_offset_y + 3, i + map_offset_x - 2, ' ');
- }
- for (size_t i = 0; i <= height + 2; i++) { /* Vertical */
- mvaddch(i + map_offset_y - 1, map_offset_x - 4, ' ');
- mvaddch(i + map_offset_y - 1, map_offset_x - 3, ' ');
- mvaddch(i + map_offset_y - 1, width * 2 + 0 + map_offset_x + 2, ' ');
- mvaddch(i + map_offset_y - 1, width * 2 + 1 + map_offset_x + 2, ' ');
- mvaddch(i + map_offset_y - 1, width * 2 + 2 + map_offset_x + 2, ' ');
- mvaddch(i + map_offset_y - 1, width * 2 + 3 + map_offset_x + 2, ' ');
- }
-
/* Draw the borders */
attron(COLOR_PAIR(WALL_COLOR));
for (size_t i = 0; i <= width*2 + 3; i++) { /* Horizontal */
@@ -387,7 +373,7 @@ void draw_map(Map map, size_t width, size_t height, Position start, Position goa
cur = path[cur.y][cur.x].parent;
}
attroff(COLOR_PAIR(PATH_COLOR));
- message(height, "Path cost: %zu", length);
+ /* FIXME: print this as part of bottom wall? set_message("Path cost: %zu", length); */
}
/* Draw the start */
@@ -412,10 +398,16 @@ void draw_map(Map map, size_t width, size_t height, Position start, Position goa
}
attroff(A_BOLD);
+ print_message(height);
+
/* Read the comment at the start of this function */
//doupdate();
}
+void print_message(size_t height) {
+ mvaddnstr(height + map_offset_y + 1, map_offset_x - 2, message, MESSAGE_MAX_SIZE);
+}
+
void map_free(Map map, size_t height) {
if (map == NULL) return;
for (size_t i = 0; i < height; i++) {
@@ -439,7 +431,8 @@ void print_map_out(Map map, size_t width, size_t height) {
void map_editor(Map *map, size_t *width, size_t *height, Position *start, Position *goal) {
clear();
draw_map(*map, *width, *height, *start, *goal, NULL, NULL, NULL, NULL);
- message(*height, "You've entered the map editor. 'q' to quit");
+ set_message("You've entered the map editor. 'q' to quit");
+ print_message(*height);
MEVENT event;
mousemask(ALL_MOUSE_EVENTS | REPORT_MOUSE_POSITION, NULL);
@@ -451,7 +444,7 @@ void map_editor(Map *map, size_t *width, size_t *height, Position *start, Positi
while (1) {
int ch = getch();
- if (ch == 'q') break;
+ if (ch == 'q') {clear_message(); break; }
/* Handle keyboard keys */
switch (ch) {
case 'h': map_offset_x += 2; break;
@@ -485,7 +478,8 @@ void map_editor(Map *map, size_t *width, size_t *height, Position *start, Positi
curs_set(2); /* Show the cursor */
echo(); /* Echo characters */
- message(*height, FILENAME_PROMPT);
+ set_message(FILENAME_PROMPT);
+ print_message(*height);
char filename[FILENAME_BUF_SIZE] = "map";
mvgetnstr(*height + map_offset_y + 1, map_offset_x - 2 + sizeof(FILENAME_PROMPT), filename, FILENAME_BUF_SIZE - 1);