void GMainWindow::OnStartGame() { emu_thread->SetRunning(true); qRegisterMetaType<Core::System::ResultStatus>("Core::System::ResultStatus"); qRegisterMetaType<std::string>("std::string"); connect(emu_thread.get(), SIGNAL(ErrorThrown(Core::System::ResultStatus, std::string)), this, SLOT(OnCoreError(Core::System::ResultStatus, std::string))); ui.action_Start->setEnabled(false); ui.action_Start->setText(tr("Continue")); ui.action_Pause->setEnabled(true); ui.action_Stop->setEnabled(true); }
void EmuThread::run() { render_window->MakeCurrent(); MicroProfileOnThreadCreate("EmuThread"); stop_run = false; // holds whether the cpu was running during the last iteration, // so that the DebugModeLeft signal can be emitted before the // next execution step bool was_active = false; while (!stop_run) { if (running) { if (!was_active) emit DebugModeLeft(); Core::System::ResultStatus result = Core::System::GetInstance().RunLoop(); if (result != Core::System::ResultStatus::Success) { emit ErrorThrown(result, Core::System::GetInstance().GetStatusDetails()); } was_active = running || exec_step; if (!was_active && !stop_run) emit DebugModeEntered(); } else if (exec_step) { if (!was_active) emit DebugModeLeft(); exec_step = false; Core::System::GetInstance().SingleStep(); emit DebugModeEntered(); yieldCurrentThread(); was_active = false; } else { std::unique_lock<std::mutex> lock(running_mutex); running_cv.wait(lock, [this] { return IsRunning() || exec_step || stop_run; }); } } // Shutdown the core emulation Core::System::GetInstance().Shutdown(); #if MICROPROFILE_ENABLED MicroProfileOnThreadExit(); #endif render_window->moveContext(); }