refactor: Improve Rendering Logic and Debugging in Dungeon Components

- Updated DungeonCanvasViewer to disable room layout drawing to reduce visual clutter, enhancing clarity during object placement.
- Enhanced BackgroundBuffer to skip empty and floor tiles, preventing overwriting of drawn elements and improving rendering efficiency.
- Refined Bitmap palette application to ensure correct transparency handling and marked bitmaps as modified for texture updates.
- Streamlined ObjectDrawer by removing unnecessary debug logs and simplifying object drawing logic, improving performance and readability.
- Adjusted Room rendering methods to utilize palette indirection for accurate color application, ensuring consistent visual output across rooms.
This commit is contained in:
scawful
2025-10-10 02:20:22 -04:00
parent 6f3c9ba81b
commit 0bcad79d06
6 changed files with 72 additions and 95 deletions

View File

@@ -106,22 +106,29 @@ void BackgroundBuffer::DrawBackground(std::span<uint8_t> gfx16_data) {
// For each tile on the tile buffer
int drawn_count = 0;
int skipped_count = 0;
int non_floor_count = 0;
for (int yy = 0; yy < tiles_h; yy++) {
for (int xx = 0; xx < tiles_w; xx++) {
uint16_t word = buffer_[xx + yy * tiles_w];
// Prevent draw if tile == 0xFFFF since it's 0 indexed
// Skip empty tiles (0xFFFF) - these show the floor
if (word == 0xFFFF) {
skipped_count++;
continue;
}
// Skip zero tiles - also show the floor
if (word == 0) {
skipped_count++;
continue;
}
auto tile = gfx::WordToTileInfo(word);
// Count floor tiles vs non-floor
if (tile.id_ >= 0xEE && tile.id_ <= 0xFF) {
// This looks like a floor tile (based on DrawFloor's 14EE pattern)
} else if (word != 0) {
non_floor_count++;
// Skip floor tiles (0xEC-0xFD) - don't overwrite DrawFloor's work
// These are the animated floor tiles, already drawn by DrawFloor
if (tile.id_ >= 0xEC && tile.id_ <= 0xFD) {
skipped_count++;
continue;
}
// Calculate pixel offset for tile position (xx, yy) in the 512x512 bitmap
@@ -176,6 +183,9 @@ void BackgroundBuffer::DrawFloor(const std::vector<uint8_t>& rom_data,
rom_data[tile_address_floor + f + 5]);
gfx::TileInfo floorTile8(rom_data[tile_address_floor + f + 6],
rom_data[tile_address_floor + f + 7]);
// Floor tiles specify which 8-color sub-palette from the 90-color dungeon palette
// e.g., palette 6 = colors 48-55 (6 * 8 = 48)
// Draw the floor tiles in a pattern
// Convert TileInfo to 16-bit words with palette information

View File

@@ -269,13 +269,23 @@ void Bitmap::ApplyStoredPalette() {
}
SDL_UnlockSurface(surface_);
// Apply all palette colors from the SnesPalette
for (size_t i = 0; i < palette_.size() && i < 256; ++i) {
const auto& pal_color = palette_[i];
sdl_palette->colors[i].r = pal_color.rgb().x;
sdl_palette->colors[i].g = pal_color.rgb().y;
sdl_palette->colors[i].b = pal_color.rgb().z;
sdl_palette->colors[i].a = pal_color.rgb().w;
// NOTE: rgb() stores 0-255 values directly in ImVec4 (unconventional but intentional)
sdl_palette->colors[i].r = static_cast<Uint8>(pal_color.rgb().x);
sdl_palette->colors[i].g = static_cast<Uint8>(pal_color.rgb().y);
sdl_palette->colors[i].b = static_cast<Uint8>(pal_color.rgb().z);
// CRITICAL: Transparency for color 0 of each sub-palette
if (pal_color.is_transparent()) {
sdl_palette->colors[i].a = 0; // Fully transparent
} else {
sdl_palette->colors[i].a = 255; // Fully opaque
}
}
SDL_LockSurface(surface_);
}
@@ -285,6 +295,9 @@ void Bitmap::SetPalette(const SnesPalette &palette) {
// Apply it immediately if surface is ready
ApplyStoredPalette();
// Mark as modified to trigger texture update
modified_ = true;
}
void Bitmap::SetPaletteWithTransparent(const SnesPalette &palette, size_t index,