Advertisement
alberthrocks

CEmu diff

Jan 16th, 2016
140
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Diff 2.91 KB | None | 0 0
  1. diff --git a/gui/qt/emuthread.cpp b/gui/qt/emuthread.cpp
  2. index e72fa51..4741e1c 100644
  3. --- a/gui/qt/emuthread.cpp
  4. +++ b/gui/qt/emuthread.cpp
  5. @@ -20,7 +20,6 @@
  6.  #include <thread>
  7.  
  8.  #include <QtCore/QEventLoop>
  9. -#include <QtCore/QTimer>
  10.  
  11.  #include "mainwindow.h"
  12.  
  13. @@ -76,7 +75,8 @@ EmuThread::EmuThread(QObject *p) : QThread(p) {
  14.      assert(emu_thread == nullptr);
  15.      emu_thread = this;
  16.      speed = actualSpeed = 100;
  17. -    last_time = std::chrono::steady_clock::now();
  18. +    timer.start();
  19. +    last_time = timer.elapsed();
  20.  }
  21.  
  22.  void EmuThread::changeEmuSpeed(int value) {
  23. @@ -131,7 +131,7 @@ void EmuThread::setDebugStepOutMode() {
  24.  
  25.  //Called occasionally, only way to do something in the same thread the emulator runs in.
  26.  void EmuThread::doStuff(bool wait_for) {
  27. -    std::chrono::steady_clock::time_point cur_time = std::chrono::steady_clock::now();
  28. +    qint64 cur_time = timer.elapsed();
  29.  
  30.      (void)wait_for;
  31.  
  32. @@ -150,7 +150,7 @@ void EmuThread::doStuff(bool wait_for) {
  33.          openDebugger(DBG_USER, 0);
  34.      }
  35.  
  36. -    last_time += std::chrono::steady_clock::now() - cur_time;
  37. +    last_time += timer.elapsed() - cur_time;
  38.  }
  39.  
  40.  void EmuThread::setActualSpeed(int value) {
  41. @@ -160,18 +160,18 @@ void EmuThread::setActualSpeed(int value) {
  42.  }
  43.  
  44.  void EmuThread::throttleTimerWait() {
  45. -    std::chrono::duration<int, std::ratio<100, 60>> unit(1);
  46. -    std::chrono::steady_clock::duration interval(std::chrono::duration_cast<std::chrono::steady_clock::duration>
  47. -                                                 (std::chrono::duration<int, std::ratio<1, 60 * 1000000>>(1000000 * 100 / speed)));
  48. -    std::chrono::steady_clock::time_point cur_time = std::chrono::steady_clock::now(), next_time = last_time + interval;
  49. +    qint64 interval = 100000 / (60 * speed);
  50. +    qint64 cur_time = timer.elapsed(), next_time = last_time + interval;
  51. +    
  52.      if (throttle_on && cur_time < next_time) {
  53.          setActualSpeed(speed);
  54.          last_time = next_time;
  55. -        std::this_thread::sleep_until(next_time);
  56. +        QThread::msleep(interval);
  57.      } else {
  58. -        setActualSpeed(unit / (cur_time - last_time));
  59. +        if ((cur_time - last_time) == 0) cur_time++;
  60. +        setActualSpeed(100 * (interval / (cur_time - last_time)));
  61.          last_time = cur_time;
  62. -        std::this_thread::yield();
  63. +        QThread::yieldCurrentThread();
  64.      }
  65.  }
  66.  
  67. diff --git a/gui/qt/emuthread.h b/gui/qt/emuthread.h
  68. index 213881b..6bfbecc 100644
  69. --- a/gui/qt/emuthread.h
  70. +++ b/gui/qt/emuthread.h
  71. @@ -2,6 +2,7 @@
  72.  #define EMUTHREAD_H
  73.  
  74.  #include <QtCore/QThread>
  75. +#include <QtCore/QElapsedTimer>
  76.  
  77.  #include <chrono>
  78.  
  79. @@ -55,7 +56,10 @@ private:
  80.      bool enter_receive_state = false;
  81.      bool throttle_on = true;
  82.      int speed, actualSpeed;
  83. -    std::chrono::steady_clock::time_point last_time;
  84. +    
  85. +    QElapsedTimer timer;
  86. +    qint64 last_time;
  87. +    
  88.  };
  89.  
  90.  // For friends
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement