From c680d55078aeec96bb70218767c44bcf26bea726 Mon Sep 17 00:00:00 2001 From: Kirill Petrashin Date: Sun, 12 Apr 2026 19:25:17 +0300 Subject: Outline an optimization in draw_map() --- map.c | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/map.c b/map.c index 57f1c65..70ba953 100644 --- a/map.c +++ b/map.c @@ -215,8 +215,6 @@ Map file_plaintext_map(char *filename, size_t *width, size_t *height, Position * /* 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 */ -/* FIXME: clean up better maybe idk. There's a bug where parts of path may not be rendered if goal slightly above start in an empty area */ -/* FIXME: yeah there are plenty of bugs. the path just doesn't get rendered correctrly at times, even if it's calculated just fine. AND IT's SPECIFICALLY AFTER map_editor() WHAT IN THE ACTUAL FUCK AAAAAAAAAAAAAAAAAAAAAAAAAAAAA*/ void draw_map(Map map, 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 */ @@ -254,12 +252,18 @@ void draw_map(Map map, size_t width, size_t height, Position start, Position goa /* Draw field */ if (map != NULL) { char c = '\0'; /* The char for the current tile */ - for (size_t i = 0; i < height; i++) { - for (size_t j = 0; j < width; j++) { + /* Rendering boundaries, used to not render stuff that's outside the screen for performance */ + /* TODO: finish this, calculate the appropriate boundaries */ + size_t top_boundary = 0, + bottom_boundary = height, + left_boundary = 0, + right_boundary = width; + for (size_t row = top_boundary; row < bottom_boundary; row++) { + for (size_t col = left_boundary; col < right_boundary; col++) { int color_pair = 0; /* The color pair of the current char */ - switch (map[i][j]) { + switch (map[row][col]) { case EMPTY: - if (visited != NULL && visited[i][j]) + if (visited != NULL && visited[row][col]) color_pair = COLOR_PAIR(VISITED_COLOR); else color_pair = COLOR_PAIR(EMPTY_COLOR); @@ -274,8 +278,8 @@ void draw_map(Map map, size_t width, size_t height, Position start, Position goa attron(color_pair); /* We draw two characters because they roughly make a square together. * It looks WAY better if we do this. */ - mvaddch(i + map_offset_y, j*2 + map_offset_x, c); - mvaddch(i + map_offset_y, j*2 + 1 + map_offset_x, c); + mvaddch(row + map_offset_y, col*2 + map_offset_x, c); + mvaddch(row + map_offset_y, col*2 + 1 + map_offset_x, c); attroff(color_pair); } } -- cgit v1.2.3