aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--main.c4
-rw-r--r--map.c29
-rw-r--r--map.h4
-rw-r--r--path.c2
4 files changed, 21 insertions, 18 deletions
diff --git a/main.c b/main.c
index 842e2a3..4577fca 100644
--- a/main.c
+++ b/main.c
@@ -134,7 +134,7 @@ int main(int argc, char **argv) {
if (!bmp_only) {
init_ncurses();
- draw_map(map, width, height, start_pos, end_pos, NULL, NULL, NULL, NULL);
+ draw_map(map, NULL, width, height, start_pos, end_pos, NULL, NULL, NULL, NULL);
wrefresh(stdscr);
}
@@ -153,7 +153,7 @@ int main(int argc, char **argv) {
#endif
while (1) {
- draw_map(map, width, height, start_pos, end_pos, NULL, path, visited, NULL);
+ draw_map(map, cell_costs, width, height, start_pos, end_pos, NULL, path, visited, NULL);
int c = getch();
switch (c) {
case 'h': map_offset_x += 2; break;
diff --git a/map.c b/map.c
index 121970c..9917f5f 100644
--- a/map.c
+++ b/map.c
@@ -274,6 +274,8 @@ size_t **file_plaintext_costs(char *filename, size_t width, size_t height) {
fgetc(file); /* the newline */
}
+ set_message("Loaded costs from %s", filename);
+ print_message(height);
return costs;
}
@@ -306,9 +308,8 @@ void map_to_file_plaintext(char *filename, Map map, size_t width, size_t height,
/* TODO: so many fucking arguments lmao. Break it down into several functions? */
/* TODO: draw the start and goal with no background, allowing us to see the frontier/path/whatever's underneath. I think attr_get() will be useful */
-/* TODO: only draw a portion of the map (for bigger ones) */
/* TODO: draw arrow for visited too */
-void draw_map(Map map, size_t width, size_t height, Position start, Position goal, Position *cursor, Path path, char **visited, PositionPQ *frontier) {
+void draw_map(Map map, size_t **cell_costs, size_t width, size_t height, Position start, Position goal, Position *cursor, Path path, char **visited, PositionPQ *frontier) {
/* I think it flickers less when we do that
* UPD: it was causing a bug, so I commented it out. I don't know why either */
//wnoutrefresh(stdscr);
@@ -430,9 +431,11 @@ void draw_map(Map map, size_t width, size_t height, Position start, Position goa
}
if (cur.x - path[cur.y][cur.x].x == 0 || cur.y - path[cur.y][cur.x].y == 0) {
- length += COST_ORTHOGONAL;
+ if (cell_costs != NULL) length += cell_costs[cur.y][cur.x] * COST_ORTHOGONAL;
+ else length += COST_ORTHOGONAL;
} else {
- length += COST_DIAGONAL;
+ if (cell_costs != NULL) length += cell_costs[cur.y][cur.x] * COST_DIAGONAL;
+ else length += COST_DIAGONAL;
}
prev = cur;
cur = path[cur.y][cur.x];
@@ -507,7 +510,7 @@ void map_editor(Map *map, size_t *width, size_t *height, Position *start, Positi
char **visited = NULL;
Path path = NULL;
- draw_map(*map, *width, *height, *start, *goal, NULL, path, visited, NULL);
+ draw_map(*map, NULL, *width, *height, *start, *goal, NULL, path, visited, NULL);
set_message("You've entered the map editor. 'q' to quit");
print_message(*height);
@@ -608,7 +611,7 @@ void map_editor(Map *map, size_t *width, size_t *height, Position *start, Positi
start->x = col;
start->y = row;
if (should_pathfind) path = path_func(dirs, *map, NULL, *width, *height, *start, *goal, visited, 0);
- draw_map(*map, *width, *height, *start, *goal, NULL, path, visited, NULL);
+ draw_map(*map, NULL, *width, *height, *start, *goal, NULL, path, visited, NULL);
}
}
} else if (goal->x == col && goal->y == row) { /* Move the goal */
@@ -619,7 +622,7 @@ void map_editor(Map *map, size_t *width, size_t *height, Position *start, Positi
goal->x = col;
goal->y = row;
if (should_pathfind) path = path_func(dirs, *map, NULL, *width, *height, *start, *goal, visited, 0);
- draw_map(*map, *width, *height, *start, *goal, NULL, path, visited, NULL);
+ draw_map(*map, NULL, *width, *height, *start, *goal, NULL, path, visited, NULL);
}
}
} else if (row == *height) { /* Resize vertically */
@@ -631,7 +634,7 @@ void map_editor(Map *map, size_t *width, size_t *height, Position *start, Positi
/* Wait for BUTTON1_RELEASED */
while ((ch = getch()) == KEY_MOUSE && getmouse(&event) == OK && !(event.bstate & BUTTON1_RELEASED)) {
if (event.y <= map_offset_y) continue;
- draw_map(*map, *width, *height, *start, *goal, NULL, path, visited, NULL);
+ draw_map(*map, NULL, *width, *height, *start, *goal, NULL, path, visited, NULL);
for (size_t i = map_offset_x; i < *width*2 + map_offset_x; i++) {
mvaddch(event.y, i, '=');
}
@@ -664,7 +667,7 @@ void map_editor(Map *map, size_t *width, size_t *height, Position *start, Positi
visited = visited_new(*width, *height);
path = path_func(dirs, *map, NULL, *width, *height, *start, *goal, visited, 0);
}
- draw_map(*map, *width, *height, *start, *goal, NULL, path, visited, NULL);
+ draw_map(*map, NULL, *width, *height, *start, *goal, NULL, path, visited, NULL);
} else if (col == *width) { /* Resize horizontally */
size_t new_width = (event.x - map_offset_x) / 2;
@@ -678,7 +681,7 @@ void map_editor(Map *map, size_t *width, size_t *height, Position *start, Positi
while ((ch = getch()) == KEY_MOUSE && getmouse(&event) == OK && !(event.bstate & BUTTON1_RELEASED)) {
size_t new_width = (event.x - map_offset_x) / 2;
if (event.x <= map_offset_x || new_width == 0) continue;
- draw_map(*map, *width, *height, *start, *goal, NULL, path, visited, NULL);
+ draw_map(*map, NULL, *width, *height, *start, *goal, NULL, path, visited, NULL);
for (size_t i = map_offset_y; i < *height + map_offset_y; i++) {
mvaddch(i, new_width * 2 + map_offset_x, '|');
mvaddch(i, new_width * 2 + map_offset_x + 1, '|');
@@ -711,7 +714,7 @@ void map_editor(Map *map, size_t *width, size_t *height, Position *start, Positi
visited = visited_new(*width, *height);
path = path_func(dirs, *map, NULL, *width, *height, *start, *goal, visited, 0);
}
- draw_map(*map, *width, *height, *start, *goal, NULL, path, visited, NULL);
+ draw_map(*map, NULL, *width, *height, *start, *goal, NULL, path, visited, NULL);
} else { /* Start drawing */
m1down = 1;
if (row < *height && col < *width) {
@@ -734,13 +737,13 @@ void map_editor(Map *map, size_t *width, size_t *height, Position *start, Positi
if (should_pathfind) {
path = path_func(dirs, *map, NULL, *width, *height, *start, *goal, visited, 0);
}
- draw_map(*map, *width, *height, *start, *goal, NULL, path, visited, NULL);
+ draw_map(*map, NULL, *width, *height, *start, *goal, NULL, path, visited, NULL);
}
}
}
} else { /* Only update the map if not a mouse event */
/* FIXME: I don't like in how many places we call draw_map(), maybe there's a better way? */
- draw_map(*map, *width, *height, *start, *goal, NULL, path, visited, NULL);
+ draw_map(*map, NULL, *width, *height, *start, *goal, NULL, path, visited, NULL);
}
}
diff --git a/map.h b/map.h
index 93672b7..7faa597 100644
--- a/map.h
+++ b/map.h
@@ -58,8 +58,8 @@ void map_to_file_plaintext(char *filename, Map map, size_t width, size_t height,
size_t **file_plaintext_costs(char *filename, size_t width, size_t height);
/* Draw the map. Bet you didn't expect that.
- * path could be NULL to draw a map with no path. So can cursor, frontier and visited */
-void draw_map(Map map, size_t width, size_t height, Position start, Position goal, Position *cursor, Path path, char **visited, PositionPQ *frontier);
+ * path could be NULL to draw a map with no path. So can cursor, frontier and visited and cell_costs */
+void draw_map(Map map, size_t **cell_costs, size_t width, size_t height, Position start, Position goal, Position *cursor, Path path, char **visited, PositionPQ *frontier);
void print_message(size_t height);
diff --git a/path.c b/path.c
index 4b791c2..52f7291 100644
--- a/path.c
+++ b/path.c
@@ -20,7 +20,7 @@ char anim_automatic = 0;
/* 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) {
while (1) {
- draw_map(map, width, height, start, end, cur, NULL, visited, frontier);
+ draw_map(map, NULL, width, height, start, end, cur, NULL, visited, frontier);
set_message("cur: %zu %zu", cur->x, cur->y); print_message(height);
if (anim_automatic) { wrefresh(stdscr); usleep(ANIM_DELAY_USEC); return 0; }
switch (getch()) {