Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- diff --git a/gui/qt/emuthread.cpp b/gui/qt/emuthread.cpp
- index e72fa51..4741e1c 100644
- --- a/gui/qt/emuthread.cpp
- +++ b/gui/qt/emuthread.cpp
- @@ -20,7 +20,6 @@
- #include <thread>
- #include <QtCore/QEventLoop>
- -#include <QtCore/QTimer>
- #include "mainwindow.h"
- @@ -76,7 +75,8 @@ EmuThread::EmuThread(QObject *p) : QThread(p) {
- assert(emu_thread == nullptr);
- emu_thread = this;
- speed = actualSpeed = 100;
- - last_time = std::chrono::steady_clock::now();
- + timer.start();
- + last_time = timer.elapsed();
- }
- void EmuThread::changeEmuSpeed(int value) {
- @@ -131,7 +131,7 @@ void EmuThread::setDebugStepOutMode() {
- //Called occasionally, only way to do something in the same thread the emulator runs in.
- void EmuThread::doStuff(bool wait_for) {
- - std::chrono::steady_clock::time_point cur_time = std::chrono::steady_clock::now();
- + qint64 cur_time = timer.elapsed();
- (void)wait_for;
- @@ -150,7 +150,7 @@ void EmuThread::doStuff(bool wait_for) {
- openDebugger(DBG_USER, 0);
- }
- - last_time += std::chrono::steady_clock::now() - cur_time;
- + last_time += timer.elapsed() - cur_time;
- }
- void EmuThread::setActualSpeed(int value) {
- @@ -160,18 +160,18 @@ void EmuThread::setActualSpeed(int value) {
- }
- void EmuThread::throttleTimerWait() {
- - std::chrono::duration<int, std::ratio<100, 60>> unit(1);
- - std::chrono::steady_clock::duration interval(std::chrono::duration_cast<std::chrono::steady_clock::duration>
- - (std::chrono::duration<int, std::ratio<1, 60 * 1000000>>(1000000 * 100 / speed)));
- - std::chrono::steady_clock::time_point cur_time = std::chrono::steady_clock::now(), next_time = last_time + interval;
- + qint64 interval = 100000 / (60 * speed);
- + qint64 cur_time = timer.elapsed(), next_time = last_time + interval;
- +
- if (throttle_on && cur_time < next_time) {
- setActualSpeed(speed);
- last_time = next_time;
- - std::this_thread::sleep_until(next_time);
- + QThread::msleep(interval);
- } else {
- - setActualSpeed(unit / (cur_time - last_time));
- + if ((cur_time - last_time) == 0) cur_time++;
- + setActualSpeed(100 * (interval / (cur_time - last_time)));
- last_time = cur_time;
- - std::this_thread::yield();
- + QThread::yieldCurrentThread();
- }
- }
- diff --git a/gui/qt/emuthread.h b/gui/qt/emuthread.h
- index 213881b..6bfbecc 100644
- --- a/gui/qt/emuthread.h
- +++ b/gui/qt/emuthread.h
- @@ -2,6 +2,7 @@
- #define EMUTHREAD_H
- #include <QtCore/QThread>
- +#include <QtCore/QElapsedTimer>
- #include <chrono>
- @@ -55,7 +56,10 @@ private:
- bool enter_receive_state = false;
- bool throttle_on = true;
- int speed, actualSpeed;
- - std::chrono::steady_clock::time_point last_time;
- +
- + QElapsedTimer timer;
- + qint64 last_time;
- +
- };
- // For friends
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement