From 03da9d4eaa09fb60b660913de0b2a3dc1f466f95 Mon Sep 17 00:00:00 2001 From: scawful Date: Sun, 10 Nov 2024 11:28:51 -0500 Subject: [PATCH] Add sheet_offset parameter to ComposeTile16 and update sheet ID validation --- src/app/gfx/tilesheet.cc | 9 +++++---- src/app/gfx/tilesheet.h | 11 ++++++++++- 2 files changed, 15 insertions(+), 5 deletions(-) diff --git a/src/app/gfx/tilesheet.cc b/src/app/gfx/tilesheet.cc index c5991c11..0f0470f0 100644 --- a/src/app/gfx/tilesheet.cc +++ b/src/app/gfx/tilesheet.cc @@ -63,7 +63,8 @@ void Tilesheet::ComposeTile16(const std::vector& graphics_buffer, const TileInfo& top_left, const TileInfo& top_right, const TileInfo& bottom_left, - const TileInfo& bottom_right) { + const TileInfo& bottom_right, int sheet_offset) { + sheet_offset_ = sheet_offset; // Calculate the base position for this Tile16 in the full-size bitmap int tiles_per_row = bitmap_->width() / tile_width_; int tile16_row = num_tiles_ / tiles_per_row; @@ -123,13 +124,13 @@ std::vector Tilesheet::FetchTileDataFromGraphicsBuffer( // Calculate the position in the graphics_buffer_ based on tile_id std::vector tile_data(0x40, 0x00); - int sheet = (tile_id / tiles_per_sheet) % 4 + 212; + int sheet = (tile_id / tiles_per_sheet) % 4 + sheet_offset_; int position_in_sheet = tile_id % tiles_per_sheet; int row_in_sheet = position_in_sheet / tiles_per_row; int column_in_sheet = position_in_sheet % tiles_per_row; - // Ensure that the sheet ID is between 212 and 215 - assert(sheet >= 212 && sheet <= 215); + // Ensure that the sheet ID is between 212 and 215 if using full gfx buffer + assert(sheet >= sheet_offset_ && sheet <= sheet_offset_ + 3); // Copy the tile data from the graphics_buffer_ to tile_data for (int y = 0; y < 8; ++y) { diff --git a/src/app/gfx/tilesheet.h b/src/app/gfx/tilesheet.h index abcb9273..94fec6dc 100644 --- a/src/app/gfx/tilesheet.h +++ b/src/app/gfx/tilesheet.h @@ -37,7 +37,8 @@ class Tilesheet { void ComposeTile16(const std::vector& graphics_buffer, const TileInfo& top_left, const TileInfo& top_right, - const TileInfo& bottom_left, const TileInfo& bottom_right); + const TileInfo& bottom_left, const TileInfo& bottom_right, + int sheet_offset = 0); void ComposeAndPlaceTilePart(const std::vector& graphics_buffer, const TileInfo& tile_info, int baseX, int baseY); @@ -84,6 +85,13 @@ class Tilesheet { auto tile_type() const { return tile_type_; } auto tile_info() const { return tile_info_; } auto mutable_tile_info() { return tile_info_; } + void clear() { + palette_.clear(); + internal_data_.clear(); + tile_info_.clear(); + bitmap_.reset(); + num_tiles_ = 0; + } private: int CalculateTileIndex(int x, int y) { @@ -115,6 +123,7 @@ class Tilesheet { int num_tiles_ = 0; int tile_width_ = 0; int tile_height_ = 0; + int sheet_offset_ = 0; TileType tile_type_; };