diff options
| author | 3gg <3gg@shellblade.net> | 2025-09-06 18:21:43 -0700 |
|---|---|---|
| committer | 3gg <3gg@shellblade.net> | 2025-09-06 18:21:43 -0700 |
| commit | 2c5e621cdaef674fb6c812d8937598575784db63 (patch) | |
| tree | 57977d3e73c4add8f9fb428e112fc1b25ce1abb8 | |
| parent | 41ee3fe4ae76d9bba450f58a09c4edde1493672d (diff) | |
Add preliminary support for multiple layers in ortho maps
| -rw-r--r-- | include/isogfx/asset.h | 8 | ||||
| -rw-r--r-- | src/gfx2d.c | 25 |
2 files changed, 18 insertions, 15 deletions
diff --git a/include/isogfx/asset.h b/include/isogfx/asset.h index cc70ee3..74063a8 100644 --- a/include/isogfx/asset.h +++ b/include/isogfx/asset.h | |||
| @@ -10,6 +10,7 @@ | |||
| 10 | #include <isogfx/types.h> | 10 | #include <isogfx/types.h> |
| 11 | 11 | ||
| 12 | #include <assert.h> | 12 | #include <assert.h> |
| 13 | #include <stddef.h> | ||
| 13 | #include <stdint.h> | 14 | #include <stdint.h> |
| 14 | 15 | ||
| 15 | // Maximum length of path strings in .TS and .TM files. | 16 | // Maximum length of path strings in .TS and .TM files. |
| @@ -177,9 +178,10 @@ static inline const Tm_Layer* tm_map_get_layer( | |||
| 177 | assert(map); | 178 | assert(map); |
| 178 | assert(layer >= 0); | 179 | assert(layer >= 0); |
| 179 | assert(layer < map->num_layers); | 180 | assert(layer < map->num_layers); |
| 180 | return (const Tm_Layer*)((const uint8_t*)map->layers + | 181 | return ( |
| 181 | (layer * map->world_width * map->world_height * | 182 | const Tm_Layer*)((const uint8_t*)map->layers + |
| 182 | sizeof(Tile))); | 183 | ((size_t)(layer * map->world_width * map->world_height) * |
| 184 | sizeof(Tile))); | ||
| 183 | } | 185 | } |
| 184 | 186 | ||
| 185 | /// Return the ith layer in the tile map. | 187 | /// Return the ith layer in the tile map. |
diff --git a/src/gfx2d.c b/src/gfx2d.c index e79dd3e..14e0539 100644 --- a/src/gfx2d.c +++ b/src/gfx2d.c | |||
| @@ -651,18 +651,19 @@ static void draw_map_ortho(Gfx2d* gfx) { | |||
| 651 | assert(gfx); | 651 | assert(gfx); |
| 652 | assert(gfx->map); | 652 | assert(gfx->map); |
| 653 | 653 | ||
| 654 | // TODO: Handle multiple layers. | 654 | for (uint16_t l = 0; l < gfx->map->num_layers; ++l) { |
| 655 | const Tm_Layer* layer = tm_map_get_layer(gfx->map, 0); | 655 | const Tm_Layer* layer = tm_map_get_layer(gfx->map, l); |
| 656 | 656 | ||
| 657 | // TODO: This currently renders with tile granularity. Do so instead in terms | 657 | // TODO: This currently renders with tile granularity. Do so instead in |
| 658 | // of pixels for more accurate camera panning. The camera coordinates are | 658 | // terms of pixels for more accurate camera panning. The camera coordinates |
| 659 | // already given in pixels. | 659 | // are already given in pixels. |
| 660 | for (int wy = gfx->camera.y / gfx->map->base_tile_height; | 660 | for (int wy = gfx->camera.y / gfx->map->base_tile_height; |
| 661 | wy < gfx->map->world_height; ++wy) { | 661 | wy < gfx->map->world_height; ++wy) { |
| 662 | for (int wx = gfx->camera.x / gfx->map->base_tile_width; | 662 | for (int wx = gfx->camera.x / gfx->map->base_tile_width; |
| 663 | wx < gfx->map->world_width; ++wx) { | 663 | wx < gfx->map->world_width; ++wx) { |
| 664 | const Tile tile = tm_layer_get_tile(gfx->map, layer, wx, wy); | 664 | const Tile tile = tm_layer_get_tile(gfx->map, layer, wx, wy); |
| 665 | draw_tile_ortho(gfx, tile, wx, wy); | 665 | draw_tile_ortho(gfx, tile, wx, wy); |
| 666 | } | ||
| 666 | } | 667 | } |
| 667 | } | 668 | } |
| 668 | } | 669 | } |
