diff options
author | 3gg <3gg@shellblade.net> | 2025-09-06 18:28:17 -0700 |
---|---|---|
committer | 3gg <3gg@shellblade.net> | 2025-09-06 18:28:17 -0700 |
commit | e667ae699b432930932b446834a0c2ead085b996 (patch) | |
tree | 6991447dc1e8578986c82af61ff19204a0092367 /src | |
parent | 2c5e621cdaef674fb6c812d8937598575784db63 (diff) |
Diffstat (limited to 'src')
-rw-r--r-- | src/gfx2d.c | 19 |
1 files changed, 12 insertions, 7 deletions
diff --git a/src/gfx2d.c b/src/gfx2d.c index 14e0539..1c8b06f 100644 --- a/src/gfx2d.c +++ b/src/gfx2d.c | |||
@@ -651,16 +651,21 @@ static void draw_map_ortho(Gfx2d* gfx) { | |||
651 | assert(gfx); | 651 | assert(gfx); |
652 | assert(gfx->map); | 652 | assert(gfx->map); |
653 | 653 | ||
654 | // Render the tiles that the camera view rectangle intersects. | ||
655 | // +1 when computing x1,y1 because the screen dimensions need not be a | ||
656 | // multiple of the base tile dimensions. | ||
657 | const int x_tiles = gfx->screen.width / gfx->map->base_tile_width; | ||
658 | const int y_tiles = gfx->screen.height / gfx->map->base_tile_height; | ||
659 | const int x0 = gfx->camera.x / gfx->map->base_tile_width; | ||
660 | const int y0 = gfx->camera.y / gfx->map->base_tile_height; | ||
661 | const int x1 = min(gfx->map->world_width, x0 + x_tiles + 1); | ||
662 | const int y1 = min(gfx->map->world_height, y0 + y_tiles + 1); | ||
663 | |||
654 | for (uint16_t l = 0; l < gfx->map->num_layers; ++l) { | 664 | for (uint16_t l = 0; l < gfx->map->num_layers; ++l) { |
655 | const Tm_Layer* layer = tm_map_get_layer(gfx->map, l); | 665 | const Tm_Layer* layer = tm_map_get_layer(gfx->map, l); |
656 | 666 | ||
657 | // TODO: This currently renders with tile granularity. Do so instead in | 667 | for (int wy = y0; wy < y1; ++wy) { |
658 | // terms of pixels for more accurate camera panning. The camera coordinates | 668 | for (int wx = x0; wx < x1; ++wx) { |
659 | // are already given in pixels. | ||
660 | for (int wy = gfx->camera.y / gfx->map->base_tile_height; | ||
661 | wy < gfx->map->world_height; ++wy) { | ||
662 | for (int wx = gfx->camera.x / gfx->map->base_tile_width; | ||
663 | wx < gfx->map->world_width; ++wx) { | ||
664 | const Tile tile = tm_layer_get_tile(gfx->map, layer, wx, wy); | 669 | const Tile tile = tm_layer_get_tile(gfx->map, layer, wx, wy); |
665 | draw_tile_ortho(gfx, tile, wx, wy); | 670 | draw_tile_ortho(gfx, tile, wx, wy); |
666 | } | 671 | } |