feat: Enhance Emulator and Rendering Performance with New Features
- Implemented a Cleanup method in the Emulator class to manage resources effectively during shutdown. - Added auto-pause functionality to the emulator when the window loses focus, optimizing CPU and battery usage. - Updated the DoRender method in the Controller class to include frame timing management and a gentle frame rate cap. - Enhanced texture processing in the Arena class to batch process up to 8 texture commands per frame, improving rendering efficiency.
This commit is contained in:
@@ -49,6 +49,24 @@ using ImGui::Separator;
|
||||
using ImGui::TableNextColumn;
|
||||
using ImGui::Text;
|
||||
|
||||
Emulator::~Emulator() {
|
||||
Cleanup();
|
||||
}
|
||||
|
||||
void Emulator::Cleanup() {
|
||||
// Stop emulation
|
||||
running_ = false;
|
||||
|
||||
// Don't try to destroy PPU texture during shutdown
|
||||
// The renderer is destroyed before the emulator, so attempting to
|
||||
// call renderer_->DestroyTexture() will crash
|
||||
// The texture will be cleaned up automatically when SDL quits
|
||||
ppu_texture_ = nullptr;
|
||||
|
||||
// Reset state
|
||||
snes_initialized_ = false;
|
||||
}
|
||||
|
||||
void Emulator::Initialize(gfx::IRenderer* renderer, const std::vector<uint8_t>& rom_data) {
|
||||
// This method is now optional - emulator can be initialized lazily in Run()
|
||||
renderer_ = renderer;
|
||||
@@ -105,6 +123,18 @@ void Emulator::Run(Rom* rom) {
|
||||
|
||||
RenderNavBar();
|
||||
|
||||
// Auto-pause emulator when window loses focus to save CPU/battery
|
||||
static bool was_running_before_focus_loss = false;
|
||||
bool window_has_focus = ImGui::IsWindowFocused(ImGuiFocusedFlags_RootWindow);
|
||||
|
||||
if (!window_has_focus && running_) {
|
||||
was_running_before_focus_loss = true;
|
||||
running_ = false;
|
||||
} else if (window_has_focus && !running_ && was_running_before_focus_loss) {
|
||||
// Don't auto-resume - let user manually resume
|
||||
was_running_before_focus_loss = false;
|
||||
}
|
||||
|
||||
if (running_) {
|
||||
HandleEvents();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user