Refactor bitmap palette management across various components to streamline palette setting and improve error handling; remove unnecessary status checks and enhance consistency in palette application methods.

This commit is contained in:
scawful
2025-04-17 21:49:47 -04:00
parent eeab477e72
commit 44e13cf4bb
17 changed files with 253 additions and 316 deletions

View File

@@ -142,17 +142,14 @@ void DungeonObjectRenderer::UpdateObjectBitmap() {
bitmap_.Create(256, 256, 8, tilemap_);
}
absl::Status DungeonObjectRenderer::SetPalette(const gfx::SnesPalette& palette,
size_t transparent_index) {
void DungeonObjectRenderer::SetPalette(const gfx::SnesPalette& palette,
size_t transparent_index) {
// Apply the palette to the bitmap
RETURN_IF_ERROR(
bitmap_.SetPaletteWithTransparent(palette, transparent_index));
bitmap_.SetPaletteWithTransparent(palette, transparent_index);
// Store the palette in the VRAM structure for future reference
vram_.palettes.clear();
vram_.palettes.push_back(palette);
return absl::OkStatus();
}
} // namespace zelda3

View File

@@ -65,9 +65,8 @@ class DungeonObjectRenderer : public SharedRom {
*
* @param palette The palette to use for the object
* @param transparent_index Index of the transparent color (default: 0)
* @return absl::Status Success or error status
*/
absl::Status SetPalette(const gfx::SnesPalette& palette, size_t transparent_index = 0);
void SetPalette(const gfx::SnesPalette& palette, size_t transparent_index = 0);
/**
* @brief Gets the rendered bitmap

View File

@@ -618,8 +618,8 @@ absl::Status SetColorsPalette(Rom &rom, int index, gfx::SnesPalette &current,
}
}
current.Create(new_palette);
for (int i = 0; i < 256; i++) {
current[i] = new_palette[i];
current[(i / 16) * 16].set_transparent(true);
}
@@ -661,7 +661,7 @@ absl::Status OverworldMap::LoadPalette() {
(sprite_palette_[game_state_] * 2) + 1];
auto grass_pal_group = rom_->palette_group().grass;
ASSIGN_OR_RETURN(gfx::SnesColor bgr, grass_pal_group[0].GetColor(0));
auto bgr = grass_pal_group[0][0];
auto ow_aux_pal_group = rom_->palette_group().overworld_aux;
ASSIGN_OR_RETURN(gfx::SnesPalette aux1,
@@ -677,14 +677,14 @@ absl::Status OverworldMap::LoadPalette() {
if (parent_ < kDarkWorldMapIdStart) {
pal0 = parent_ == 0x03 || parent_ == 0x05 || parent_ == 0x07 ? 2 : 0;
ASSIGN_OR_RETURN(bgr, grass_pal_group[0].GetColor(0));
bgr = grass_pal_group[0][0];
} else if (parent_ >= kDarkWorldMapIdStart &&
parent_ < kSpecialWorldMapIdStart) {
pal0 = parent_ == 0x43 || parent_ == 0x45 || parent_ == 0x47 ? 3 : 1;
ASSIGN_OR_RETURN(bgr, grass_pal_group[0].GetColor(1));
bgr = grass_pal_group[0][1];
} else if (parent_ >= 128 && parent_ < kNumOverworldMaps) {
pal0 = 0;
ASSIGN_OR_RETURN(bgr, grass_pal_group[0].GetColor(2));
bgr = grass_pal_group[0][2];
}
if (parent_ == 0x88) {

View File

@@ -68,7 +68,7 @@ absl::Status Inventory::Create() {
}
bitmap_.Create(256, 256, 8, data_);
RETURN_IF_ERROR(bitmap_.SetPalette(palette_));
bitmap_.SetPalette(palette_);
Renderer::GetInstance().RenderBitmap(&bitmap_);
return absl::OkStatus();
}
@@ -87,7 +87,7 @@ absl::Status Inventory::BuildTileset() {
tilesheets_bmp_.Create(128, 0x130, 64, test_);
auto hud_pal_group = rom()->palette_group().hud;
palette_ = hud_pal_group[0];
RETURN_IF_ERROR(tilesheets_bmp_.SetPalette(palette_))
tilesheets_bmp_.SetPalette(palette_);
Renderer::GetInstance().RenderBitmap(&tilesheets_bmp_);
return absl::OkStatus();
}