From 0b176d88d1ee914483b5f77a20549a69be10e8ad Mon Sep 17 00:00:00 2001 From: Kirill Petrashin Date: Mon, 13 Apr 2026 11:47:45 +0300 Subject: Finish draw_map() optimization --- map.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/map.c b/map.c index 70ba953..40c30b5 100644 --- a/map.c +++ b/map.c @@ -253,11 +253,14 @@ void draw_map(Map map, size_t width, size_t height, Position start, Position goa if (map != NULL) { char c = '\0'; /* The char for the current tile */ /* 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; + if (map_offset_y < 0) top_boundary = -map_offset_y; + if (map_offset_x < 0) left_boundary = -(map_offset_x / 2); + if (top_boundary + LINES < height) bottom_boundary = top_boundary + LINES; + if (left_boundary + COLS/2 < height) right_boundary = left_boundary + COLS/2 + 1; 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 */ -- cgit v1.2.3