diff options
Diffstat (limited to 'src/gfx2d.c')
| -rw-r--r-- | src/gfx2d.c | 36 |
1 files changed, 24 insertions, 12 deletions
diff --git a/src/gfx2d.c b/src/gfx2d.c index 1c8b06f..eaed2b8 100644 --- a/src/gfx2d.c +++ b/src/gfx2d.c | |||
| @@ -26,6 +26,9 @@ | |||
| 26 | /// Take the minimum of two values. | 26 | /// Take the minimum of two values. |
| 27 | #define min(a, b) ((a) < (b) ? (a) : (b)) | 27 | #define min(a, b) ((a) < (b) ? (a) : (b)) |
| 28 | 28 | ||
| 29 | /// The 0-tile denotes "no tile". The renderer skips drawing 0-tiles. | ||
| 30 | static const Tile NoTile = 0; | ||
| 31 | |||
| 29 | typedef struct ivec2 { | 32 | typedef struct ivec2 { |
| 30 | int x, y; | 33 | int x, y; |
| 31 | } ivec2; | 34 | } ivec2; |
| @@ -606,6 +609,10 @@ static void draw_tile_ortho(Gfx2d* gfx, Tile tile, int x, int y) { | |||
| 606 | assert(x < gfx->map->world_width); | 609 | assert(x < gfx->map->world_width); |
| 607 | assert(y < gfx->map->world_height); | 610 | assert(y < gfx->map->world_height); |
| 608 | 611 | ||
| 612 | if (tile == NoTile) { | ||
| 613 | return; | ||
| 614 | } | ||
| 615 | |||
| 609 | const Ts_Tile* pTile = ts_tileset_get_tile(gfx->tileset, tile); | 616 | const Ts_Tile* pTile = ts_tileset_get_tile(gfx->tileset, tile); |
| 610 | const Pixel* pixels = ts_tileset_get_tile_pixels(gfx->tileset, tile); | 617 | const Pixel* pixels = ts_tileset_get_tile_pixels(gfx->tileset, tile); |
| 611 | 618 | ||
| @@ -626,6 +633,10 @@ static void draw_tile_iso(Gfx2d* gfx, Tile tile, int iso_x, int iso_y) { | |||
| 626 | assert(iso_x < gfx->map->world_width); | 633 | assert(iso_x < gfx->map->world_width); |
| 627 | assert(iso_y < gfx->map->world_height); | 634 | assert(iso_y < gfx->map->world_height); |
| 628 | 635 | ||
| 636 | if (tile == NoTile) { | ||
| 637 | return; | ||
| 638 | } | ||
| 639 | |||
| 629 | const Ts_Tile* pTile = ts_tileset_get_tile(gfx->tileset, tile); | 640 | const Ts_Tile* pTile = ts_tileset_get_tile(gfx->tileset, tile); |
| 630 | const Pixel* pixels = ts_tileset_get_tile_pixels(gfx->tileset, tile); | 641 | const Pixel* pixels = ts_tileset_get_tile_pixels(gfx->tileset, tile); |
| 631 | 642 | ||
| @@ -677,18 +688,19 @@ static void draw_map_iso(Gfx2d* gfx) { | |||
| 677 | assert(gfx); | 688 | assert(gfx); |
| 678 | assert(gfx->map); | 689 | assert(gfx->map); |
| 679 | 690 | ||
| 680 | // TODO: Support for multiple layers. | 691 | for (uint16_t l = 0; l < gfx->map->num_layers; ++l) { |
| 681 | const Tm_Layer* layer = tm_map_get_layer(gfx->map, 0); | 692 | const Tm_Layer* layer = tm_map_get_layer(gfx->map, l); |
| 682 | 693 | ||
| 683 | // TODO: Culling. | 694 | // TODO: Culling. |
| 684 | // Ex: map the screen corners to tile space to cull. | 695 | // Ex: map the screen corners to tile space to cull. |
| 685 | // Ex: walk in screen space and fetch the tile. | 696 | // Ex: walk in screen space and fetch the tile. |
| 686 | // The tile-centric approach might be more cache-friendly since the | 697 | // The tile-centric approach might be more cache-friendly since the |
| 687 | // screen-centric approach would juggle multiple tiles throughout the scan. | 698 | // screen-centric approach would juggle multiple tiles throughout the scan. |
| 688 | for (int wy = 0; wy < gfx->map->world_height; ++wy) { | 699 | for (int wy = 0; wy < gfx->map->world_height; ++wy) { |
| 689 | for (int wx = 0; wx < gfx->map->world_width; ++wx) { | 700 | for (int wx = 0; wx < gfx->map->world_width; ++wx) { |
| 690 | const Tile tile = tm_layer_get_tile(gfx->map, layer, wx, wy); | 701 | const Tile tile = tm_layer_get_tile(gfx->map, layer, wx, wy); |
| 691 | draw_tile_iso(gfx, tile, wx, wy); | 702 | draw_tile_iso(gfx, tile, wx, wy); |
| 703 | } | ||
| 692 | } | 704 | } |
| 693 | } | 705 | } |
| 694 | } | 706 | } |
