/* * Rosalie's Mupen GUI - https://github.com/Rosalie241/RMG * Copyright (C) 2020 Rosalie Wanders * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License version 3. * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ #include "HotkeysThread.hpp" #include using namespace Thread; HotkeysThread::HotkeysThread(std::function checkHotkeysFunc, QObject *parent) : QThread(parent) { this->checkHotkeysFunc = checkHotkeysFunc; } HotkeysThread::~HotkeysThread() { if (this->isRunning()) { this->StopLoop(); } } void HotkeysThread::SetState(HotkeysThreadState state) { this->state = state; } void HotkeysThread::StopLoop(void) { this->keepLoopRunning = false; while (this->isRunning()) { // wait until we're not running anymore } } void HotkeysThread::run(void) { while (this->keepLoopRunning) { // sleep for 300ms when no ROM is opened if (this->state == HotkeysThreadState::RomClosed) { QThread::msleep(300); continue; } if (CoreIsEmulationPaused()) { for (int i = 0; i < 4; i++) { this->checkHotkeysFunc(i); } } // sleep for 100ms QThread::msleep(100); } }