Refactor graphics loading and decompression for consistency
- Updated various graphics loading functions to ensure consistent use of semicolons in ASSIGN_OR_RETURN statements. - Changed set_filename method in Rom class to accept std::string_view for improved efficiency. - Enhanced code readability and maintainability across multiple files by standardizing syntax.
This commit is contained in:
@@ -80,7 +80,7 @@ absl::Status DungeonEditor::Load() {
|
|||||||
// Load the palette group and palette for the dungeon
|
// Load the palette group and palette for the dungeon
|
||||||
full_palette_ = dungeon_man_pal_group[current_palette_group_id_];
|
full_palette_ = dungeon_man_pal_group[current_palette_group_id_];
|
||||||
ASSIGN_OR_RETURN(current_palette_group_,
|
ASSIGN_OR_RETURN(current_palette_group_,
|
||||||
gfx::CreatePaletteGroupFromLargePalette(full_palette_))
|
gfx::CreatePaletteGroupFromLargePalette(full_palette_));
|
||||||
|
|
||||||
CalculateUsageStats();
|
CalculateUsageStats();
|
||||||
is_loaded_ = true;
|
is_loaded_ = true;
|
||||||
|
|||||||
@@ -756,7 +756,7 @@ absl::Status GraphicsEditor::DrawMemoryEditor() {
|
|||||||
|
|
||||||
absl::Status GraphicsEditor::DecompressImportData(int size) {
|
absl::Status GraphicsEditor::DecompressImportData(int size) {
|
||||||
ASSIGN_OR_RETURN(import_data_, gfx::lc_lz2::DecompressV2(
|
ASSIGN_OR_RETURN(import_data_, gfx::lc_lz2::DecompressV2(
|
||||||
temp_rom_.data(), current_offset_, size))
|
temp_rom_.data(), current_offset_, size));
|
||||||
|
|
||||||
auto converted_sheet = gfx::SnesTo8bppSheet(import_data_, 3);
|
auto converted_sheet = gfx::SnesTo8bppSheet(import_data_, 3);
|
||||||
bin_bitmap_.Create(gfx::kTilesheetWidth, 0x2000, gfx::kTilesheetDepth,
|
bin_bitmap_.Create(gfx::kTilesheetWidth, 0x2000, gfx::kTilesheetDepth,
|
||||||
@@ -785,7 +785,7 @@ absl::Status GraphicsEditor::DecompressSuperDonkey() {
|
|||||||
std::stoi(offset, nullptr, 16); // convert hex string to int
|
std::stoi(offset, nullptr, 16); // convert hex string to int
|
||||||
ASSIGN_OR_RETURN(
|
ASSIGN_OR_RETURN(
|
||||||
auto decompressed_data,
|
auto decompressed_data,
|
||||||
gfx::lc_lz2::DecompressV2(temp_rom_.data(), offset_value, 0x1000))
|
gfx::lc_lz2::DecompressV2(temp_rom_.data(), offset_value, 0x1000));
|
||||||
auto converted_sheet = gfx::SnesTo8bppSheet(decompressed_data, 3);
|
auto converted_sheet = gfx::SnesTo8bppSheet(decompressed_data, 3);
|
||||||
gfx_sheets_[i] = gfx::Bitmap(gfx::kTilesheetWidth, gfx::kTilesheetHeight,
|
gfx_sheets_[i] = gfx::Bitmap(gfx::kTilesheetWidth, gfx::kTilesheetHeight,
|
||||||
gfx::kTilesheetDepth, converted_sheet);
|
gfx::kTilesheetDepth, converted_sheet);
|
||||||
@@ -810,7 +810,7 @@ absl::Status GraphicsEditor::DecompressSuperDonkey() {
|
|||||||
std::stoi(offset, nullptr, 16); // convert hex string to int
|
std::stoi(offset, nullptr, 16); // convert hex string to int
|
||||||
ASSIGN_OR_RETURN(
|
ASSIGN_OR_RETURN(
|
||||||
auto decompressed_data,
|
auto decompressed_data,
|
||||||
gfx::lc_lz2::DecompressV2(temp_rom_.data(), offset_value, 0x1000))
|
gfx::lc_lz2::DecompressV2(temp_rom_.data(), offset_value, 0x1000));
|
||||||
auto converted_sheet = gfx::SnesTo8bppSheet(decompressed_data, 3);
|
auto converted_sheet = gfx::SnesTo8bppSheet(decompressed_data, 3);
|
||||||
gfx_sheets_[i] = gfx::Bitmap(gfx::kTilesheetWidth, gfx::kTilesheetHeight,
|
gfx_sheets_[i] = gfx::Bitmap(gfx::kTilesheetWidth, gfx::kTilesheetHeight,
|
||||||
gfx::kTilesheetDepth, converted_sheet);
|
gfx::kTilesheetDepth, converted_sheet);
|
||||||
|
|||||||
@@ -760,7 +760,7 @@ absl::Status ValidateCompressionResult(CompressionPiecePointer& chain_head,
|
|||||||
RETURN_IF_ERROR(
|
RETURN_IF_ERROR(
|
||||||
temp_rom.LoadFromData(CreateCompressionString(chain_head->next, mode)))
|
temp_rom.LoadFromData(CreateCompressionString(chain_head->next, mode)))
|
||||||
ASSIGN_OR_RETURN(auto decomp_data,
|
ASSIGN_OR_RETURN(auto decomp_data,
|
||||||
DecompressV2(temp_rom.data(), 0, temp_rom.size()))
|
DecompressV2(temp_rom.data(), 0, temp_rom.size()));
|
||||||
if (!std::equal(decomp_data.begin() + start, decomp_data.end(),
|
if (!std::equal(decomp_data.begin() + start, decomp_data.end(),
|
||||||
temp_rom.begin())) {
|
temp_rom.begin())) {
|
||||||
return absl::InternalError(absl::StrFormat(
|
return absl::InternalError(absl::StrFormat(
|
||||||
@@ -1180,7 +1180,7 @@ absl::Status ValidateCompressionResultV3(const CompressionContext& context) {
|
|||||||
Rom temp_rom;
|
Rom temp_rom;
|
||||||
RETURN_IF_ERROR(temp_rom.LoadFromData(context.compressed_data));
|
RETURN_IF_ERROR(temp_rom.LoadFromData(context.compressed_data));
|
||||||
ASSIGN_OR_RETURN(auto decomp_data,
|
ASSIGN_OR_RETURN(auto decomp_data,
|
||||||
DecompressV2(temp_rom.data(), 0, temp_rom.size()))
|
DecompressV2(temp_rom.data(), 0, temp_rom.size()));
|
||||||
|
|
||||||
if (!std::equal(decomp_data.begin() + context.start, decomp_data.end(),
|
if (!std::equal(decomp_data.begin() + context.start, decomp_data.end(),
|
||||||
temp_rom.begin())) {
|
temp_rom.begin())) {
|
||||||
|
|||||||
@@ -46,7 +46,7 @@ absl::StatusOr<std::vector<uint8_t>> Load2BppGraphics(const Rom &rom) {
|
|||||||
rom.version_constants().kOverworldGfxPtr2,
|
rom.version_constants().kOverworldGfxPtr2,
|
||||||
rom.version_constants().kOverworldGfxPtr3);
|
rom.version_constants().kOverworldGfxPtr3);
|
||||||
ASSIGN_OR_RETURN(auto decomp_sheet,
|
ASSIGN_OR_RETURN(auto decomp_sheet,
|
||||||
gfx::lc_lz2::DecompressV2(rom.data(), offset))
|
gfx::lc_lz2::DecompressV2(rom.data(), offset));
|
||||||
auto converted_sheet = gfx::SnesTo8bppSheet(decomp_sheet, 2);
|
auto converted_sheet = gfx::SnesTo8bppSheet(decomp_sheet, 2);
|
||||||
for (const auto &each_pixel : converted_sheet) {
|
for (const auto &each_pixel : converted_sheet) {
|
||||||
sheet.push_back(each_pixel);
|
sheet.push_back(each_pixel);
|
||||||
@@ -64,7 +64,7 @@ absl::StatusOr<std::array<gfx::Bitmap, kNumLinkSheets>> LoadLinkGraphics(
|
|||||||
ASSIGN_OR_RETURN(
|
ASSIGN_OR_RETURN(
|
||||||
auto link_sheet_data,
|
auto link_sheet_data,
|
||||||
rom.ReadByteVector(/*offset=*/kLinkGfxOffset + (i * kLinkGfxLength),
|
rom.ReadByteVector(/*offset=*/kLinkGfxOffset + (i * kLinkGfxLength),
|
||||||
/*length=*/kLinkGfxLength))
|
/*length=*/kLinkGfxLength));
|
||||||
auto link_sheet_8bpp = gfx::SnesTo8bppSheet(link_sheet_data, /*bpp=*/4);
|
auto link_sheet_8bpp = gfx::SnesTo8bppSheet(link_sheet_data, /*bpp=*/4);
|
||||||
link_graphics[i].Create(gfx::kTilesheetWidth, gfx::kTilesheetHeight,
|
link_graphics[i].Create(gfx::kTilesheetWidth, gfx::kTilesheetHeight,
|
||||||
gfx::kTilesheetDepth, link_sheet_8bpp);
|
gfx::kTilesheetDepth, link_sheet_8bpp);
|
||||||
@@ -155,7 +155,7 @@ absl::StatusOr<std::array<gfx::Bitmap, kNumGfxSheets>> LoadAllGraphicsData(
|
|||||||
rom.data(), i, rom.version_constants().kOverworldGfxPtr1,
|
rom.data(), i, rom.version_constants().kOverworldGfxPtr1,
|
||||||
rom.version_constants().kOverworldGfxPtr2,
|
rom.version_constants().kOverworldGfxPtr2,
|
||||||
rom.version_constants().kOverworldGfxPtr3);
|
rom.version_constants().kOverworldGfxPtr3);
|
||||||
ASSIGN_OR_RETURN(sheet, gfx::lc_lz2::DecompressV2(rom.data(), offset))
|
ASSIGN_OR_RETURN(sheet, gfx::lc_lz2::DecompressV2(rom.data(), offset));
|
||||||
bpp3 = true;
|
bpp3 = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -222,6 +222,7 @@ absl::Status SaveAllGraphicsData(
|
|||||||
rom.version_constants().kOverworldGfxPtr2,
|
rom.version_constants().kOverworldGfxPtr2,
|
||||||
rom.version_constants().kOverworldGfxPtr3);
|
rom.version_constants().kOverworldGfxPtr3);
|
||||||
std::copy(final_data.begin(), final_data.end(), rom.begin() + offset);
|
std::copy(final_data.begin(), final_data.end(), rom.begin() + offset);
|
||||||
|
std::ranges::copy(final_data, rom.begin() + offset);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return absl::OkStatus();
|
return absl::OkStatus();
|
||||||
@@ -551,16 +552,16 @@ absl::StatusOr<gfx::Tile16> Rom::ReadTile16(uint32_t tile16_id) {
|
|||||||
// Skip 8 bytes per tile.
|
// Skip 8 bytes per tile.
|
||||||
auto tpos = kTile16Ptr + (tile16_id * 0x08);
|
auto tpos = kTile16Ptr + (tile16_id * 0x08);
|
||||||
gfx::Tile16 tile16 = {};
|
gfx::Tile16 tile16 = {};
|
||||||
ASSIGN_OR_RETURN(auto new_tile0, ReadWord(tpos))
|
ASSIGN_OR_RETURN(auto new_tile0, ReadWord(tpos));
|
||||||
tile16.tile0_ = gfx::WordToTileInfo(new_tile0);
|
tile16.tile0_ = gfx::WordToTileInfo(new_tile0);
|
||||||
tpos += 2;
|
tpos += 2;
|
||||||
ASSIGN_OR_RETURN(auto new_tile1, ReadWord(tpos))
|
ASSIGN_OR_RETURN(auto new_tile1, ReadWord(tpos));
|
||||||
tile16.tile1_ = gfx::WordToTileInfo(new_tile1);
|
tile16.tile1_ = gfx::WordToTileInfo(new_tile1);
|
||||||
tpos += 2;
|
tpos += 2;
|
||||||
ASSIGN_OR_RETURN(auto new_tile2, ReadWord(tpos))
|
ASSIGN_OR_RETURN(auto new_tile2, ReadWord(tpos));
|
||||||
tile16.tile2_ = gfx::WordToTileInfo(new_tile2);
|
tile16.tile2_ = gfx::WordToTileInfo(new_tile2);
|
||||||
tpos += 2;
|
tpos += 2;
|
||||||
ASSIGN_OR_RETURN(auto new_tile3, ReadWord(tpos))
|
ASSIGN_OR_RETURN(auto new_tile3, ReadWord(tpos));
|
||||||
tile16.tile3_ = gfx::WordToTileInfo(new_tile3);
|
tile16.tile3_ = gfx::WordToTileInfo(new_tile3);
|
||||||
return tile16;
|
return tile16;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -180,7 +180,7 @@ class Rom {
|
|||||||
auto end() { return rom_data_.end(); }
|
auto end() { return rom_data_.end(); }
|
||||||
auto vector() const { return rom_data_; }
|
auto vector() const { return rom_data_; }
|
||||||
auto filename() const { return filename_; }
|
auto filename() const { return filename_; }
|
||||||
auto set_filename(std::string name) { filename_ = name; }
|
auto set_filename(std::string_view name) { filename_ = name; }
|
||||||
auto short_name() const { return short_name_; }
|
auto short_name() const { return short_name_; }
|
||||||
auto graphics_buffer() const { return graphics_buffer_; }
|
auto graphics_buffer() const { return graphics_buffer_; }
|
||||||
auto mutable_graphics_buffer() { return &graphics_buffer_; }
|
auto mutable_graphics_buffer() { return &graphics_buffer_; }
|
||||||
|
|||||||
@@ -76,7 +76,7 @@ absl::Status Inventory::Create() {
|
|||||||
absl::Status Inventory::BuildTileset() {
|
absl::Status Inventory::BuildTileset() {
|
||||||
tilesheets_.reserve(6 * 0x2000);
|
tilesheets_.reserve(6 * 0x2000);
|
||||||
for (int i = 0; i < 6 * 0x2000; i++) tilesheets_.push_back(0xFF);
|
for (int i = 0; i < 6 * 0x2000; i++) tilesheets_.push_back(0xFF);
|
||||||
ASSIGN_OR_RETURN(tilesheets_, Load2BppGraphics(*rom()))
|
ASSIGN_OR_RETURN(tilesheets_, Load2BppGraphics(*rom()));
|
||||||
std::vector<uint8_t> test;
|
std::vector<uint8_t> test;
|
||||||
for (int i = 0; i < 0x4000; i++) {
|
for (int i = 0; i < 0x4000; i++) {
|
||||||
test_.push_back(tilesheets_[i]);
|
test_.push_back(tilesheets_[i]);
|
||||||
|
|||||||
@@ -65,7 +65,7 @@
|
|||||||
if (!error_or_value.ok()) { \
|
if (!error_or_value.ok()) { \
|
||||||
return error_or_value.status(); \
|
return error_or_value.status(); \
|
||||||
} \
|
} \
|
||||||
type_variable_name = std::move(*error_or_value);
|
type_variable_name = std::move(*error_or_value)
|
||||||
|
|
||||||
#define ASSIGN_OR_LOG_ERROR(type_variable_name, expression) \
|
#define ASSIGN_OR_LOG_ERROR(type_variable_name, expression) \
|
||||||
ASSIGN_OR_LOG_ERROR_IMPL(APPEND_NUMBER(error_or_value, __LINE__), \
|
ASSIGN_OR_LOG_ERROR_IMPL(APPEND_NUMBER(error_or_value, __LINE__), \
|
||||||
|
|||||||
Reference in New Issue
Block a user