feat: Enhance emulator UI and performance features

- Added new UI components for the emulator, including dedicated panels for CPU and APU debugging, improving user interaction and debugging capabilities.
- Implemented a caching mechanism for rendered objects in the DungeonCanvasViewer to optimize performance and reduce rendering time.
- Updated the CMake configuration to include new UI source files, ensuring proper organization and build management.
- Enhanced the theme manager with improved color definitions for better visibility and consistency across the UI.
- Refactored the emulator interface to delegate rendering tasks to the UI layer, streamlining the codebase and improving maintainability.
This commit is contained in:
scawful
2025-10-08 23:38:20 -04:00
parent d2dab43358
commit b5ec0cb637
10 changed files with 1025 additions and 900 deletions

View File

@@ -179,6 +179,23 @@ void DungeonCanvasViewer::RenderObjectInCanvas(const zelda3::RoomObject &object,
return; // Skip objects outside visible area
}
// Calculate palette hash for caching
uint64_t palette_hash = 0;
for (size_t i = 0; i < palette.size() && i < 16; ++i) {
palette_hash ^= std::hash<uint16_t>{}(palette[i].snes()) + 0x9e3779b9 +
(palette_hash << 6) + (palette_hash >> 2);
}
// Check cache first
for (auto& cached : object_render_cache_) {
if (cached.object_id == object.id_ && cached.object_x == object.x_ &&
cached.object_y == object.y_ && cached.object_size == object.size_ &&
cached.palette_hash == palette_hash && cached.is_valid) {
canvas_.DrawBitmap(cached.rendered_bitmap, canvas_x, canvas_y, 1.0f, 255);
return;
}
}
// Create a mutable copy of the object to ensure tiles are loaded
auto mutable_object = object;
mutable_object.set_rom(rom_);
@@ -192,10 +209,27 @@ void DungeonCanvasViewer::RenderObjectInCanvas(const zelda3::RoomObject &object,
// Ensure the bitmap is valid and has content
if (object_bitmap.width() > 0 && object_bitmap.height() > 0) {
object_bitmap.SetPalette(palette);
// Queue texture creation for the object bitmap via Arena's deferred system
// Add to cache
ObjectRenderCache cache_entry;
cache_entry.object_id = object.id_;
cache_entry.object_x = object.x_;
cache_entry.object_y = object.y_;
cache_entry.object_size = object.size_;
cache_entry.palette_hash = palette_hash;
cache_entry.rendered_bitmap = std::move(object_bitmap); // Move bitmap into cache
cache_entry.is_valid = true;
if (object_render_cache_.size() >= 200) { // Limit cache size
object_render_cache_.erase(object_render_cache_.begin());
}
object_render_cache_.push_back(std::move(cache_entry));
// Get pointer to cached bitmap and queue texture creation
gfx::Bitmap* cached_bitmap = &object_render_cache_.back().rendered_bitmap;
gfx::Arena::Get().QueueTextureCommand(
gfx::Arena::TextureCommandType::CREATE, &object_bitmap);
canvas_.DrawBitmap(object_bitmap, canvas_x, canvas_y, 1.0f, 255);
gfx::Arena::TextureCommandType::CREATE, cached_bitmap);
canvas_.DrawBitmap(*cached_bitmap, canvas_x, canvas_y, 1.0f, 255);
return;
}
}

View File

@@ -336,7 +336,7 @@ void MessageEditor::DrawMessagePreview() {
} else {
// Create bitmap and queue texture creation
current_font_gfx16_bitmap_.Create(kCurrentMessageWidth, kCurrentMessageHeight,
172, message_preview_.current_preview_data_);
64, message_preview_.current_preview_data_);
current_font_gfx16_bitmap_.SetPalette(font_preview_colors_);
gfx::Arena::Get().QueueTextureCommand(
gfx::Arena::TextureCommandType::CREATE, &current_font_gfx16_bitmap_);