summaryrefslogtreecommitdiff
path: root/src/citra_qt/bootmanager.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/citra_qt/bootmanager.cpp')
-rw-r--r--src/citra_qt/bootmanager.cpp48
1 files changed, 34 insertions, 14 deletions
diff --git a/src/citra_qt/bootmanager.cpp b/src/citra_qt/bootmanager.cpp
index b0aa1e561..573060d30 100644
--- a/src/citra_qt/bootmanager.cpp
+++ b/src/citra_qt/bootmanager.cpp
@@ -1,5 +1,6 @@
1#include <QHBoxLayout> 1#include <QHBoxLayout>
2#include <QKeyEvent> 2#include <QKeyEvent>
3#include <QApplication>
3 4
4#include "common/common.h" 5#include "common/common.h"
5#include "bootmanager.hxx" 6#include "bootmanager.hxx"
@@ -19,7 +20,8 @@
19 20
20EmuThread::EmuThread(GRenderWindow* render_window) : 21EmuThread::EmuThread(GRenderWindow* render_window) :
21 exec_cpu_step(false), cpu_running(false), 22 exec_cpu_step(false), cpu_running(false),
22 render_window(render_window), filename("") 23 render_window(render_window), filename(""),
24 stop_run(false)
23{ 25{
24} 26}
25 27
@@ -30,7 +32,8 @@ void EmuThread::SetFilename(std::string filename)
30 32
31void EmuThread::run() 33void EmuThread::run()
32{ 34{
33 while (true) 35 stop_run = false;
36 while (!stop_run)
34 { 37 {
35 for (int tight_loop = 0; tight_loop < 10000; ++tight_loop) 38 for (int tight_loop = 0; tight_loop < 10000; ++tight_loop)
36 { 39 {
@@ -40,11 +43,14 @@ void EmuThread::run()
40 exec_cpu_step = false; 43 exec_cpu_step = false;
41 44
42 Core::SingleStep(); 45 Core::SingleStep();
43 if (!cpu_running) 46 if (!cpu_running) {
44 emit CPUStepped(); 47 emit CPUStepped();
48 yieldCurrentThread();
49 }
45 } 50 }
46 } 51 }
47 } 52 }
53 render_window->moveContext();
48 54
49 Core::Stop(); 55 Core::Stop();
50} 56}
@@ -56,17 +62,21 @@ void EmuThread::Stop()
56 INFO_LOG(MASTER_LOG, "EmuThread::Stop called while emu thread wasn't running, returning..."); 62 INFO_LOG(MASTER_LOG, "EmuThread::Stop called while emu thread wasn't running, returning...");
57 return; 63 return;
58 } 64 }
65 stop_run = true;
59 66
60 //core::g_state = core::SYS_DIE; 67 //core::g_state = core::SYS_DIE;
61 68
62 wait(1000); 69 wait(500);
63 if (isRunning()) 70 if (isRunning())
64 { 71 {
65 WARN_LOG(MASTER_LOG, "EmuThread still running, terminating..."); 72 WARN_LOG(MASTER_LOG, "EmuThread still running, terminating...");
66 terminate(); 73 quit();
67 wait(1000); 74 wait(1000);
68 if (isRunning()) 75 if (isRunning())
76 {
69 WARN_LOG(MASTER_LOG, "EmuThread STILL running, something is wrong here..."); 77 WARN_LOG(MASTER_LOG, "EmuThread STILL running, something is wrong here...");
78 terminate();
79 }
70 } 80 }
71 INFO_LOG(MASTER_LOG, "EmuThread stopped"); 81 INFO_LOG(MASTER_LOG, "EmuThread stopped");
72} 82}
@@ -77,17 +87,13 @@ void EmuThread::Stop()
77class GGLWidgetInternal : public QGLWidget 87class GGLWidgetInternal : public QGLWidget
78{ 88{
79public: 89public:
80 GGLWidgetInternal(QGLFormat fmt, GRenderWindow* parent) : QGLWidget(parent) 90 GGLWidgetInternal(QGLFormat fmt, GRenderWindow* parent) : QGLWidget(fmt, parent)
81 { 91 {
82 doneCurrent();
83 parent_ = parent; 92 parent_ = parent;
84 } 93 }
85 94
86 void paintEvent(QPaintEvent* ev) 95 void paintEvent(QPaintEvent* ev)
87 { 96 {
88 // Apparently, Windows doesn't display anything if we don't call this here.
89 // TODO: Breaks linux though because we aren't calling doneCurrent() ... -.-
90// makeCurrent();
91 } 97 }
92 void resizeEvent(QResizeEvent* ev) { 98 void resizeEvent(QResizeEvent* ev) {
93 parent_->SetClientAreaWidth(size().width()); 99 parent_->SetClientAreaWidth(size().width());
@@ -118,24 +124,37 @@ GRenderWindow::GRenderWindow(QWidget* parent) : QWidget(parent), emu_thread(this
118 layout->addWidget(child); 124 layout->addWidget(child);
119 layout->setMargin(0); 125 layout->setMargin(0);
120 setLayout(layout); 126 setLayout(layout);
127 QObject::connect(&emu_thread, SIGNAL(started()), this, SLOT(moveContext()));
121 128
122 BackupGeometry(); 129 BackupGeometry();
123} 130}
124 131
132void GRenderWindow::moveContext()
133{
134 DoneCurrent();
135 // We need to move GL context to the swapping thread in Qt5
136#if QT_VERSION > QT_VERSION_CHECK(5, 0, 0)
137 // If the thread started running, move the GL Context to the new thread. Otherwise, move it back.
138 child->context()->moveToThread((QThread::currentThread() == qApp->thread()) ? &emu_thread : qApp->thread());
139#endif
140}
141
125GRenderWindow::~GRenderWindow() 142GRenderWindow::~GRenderWindow()
126{ 143{
127 emu_thread.Stop(); 144 if (emu_thread.isRunning())
145 emu_thread.Stop();
128} 146}
129 147
130void GRenderWindow::SwapBuffers() 148void GRenderWindow::SwapBuffers()
131{ 149{
132 child->makeCurrent(); // TODO: Not necessary? 150 // MakeCurrent is already called in renderer_opengl
133 child->swapBuffers(); 151 child->swapBuffers();
134} 152}
135 153
136void GRenderWindow::closeEvent(QCloseEvent* event) 154void GRenderWindow::closeEvent(QCloseEvent* event)
137{ 155{
138 emu_thread.Stop(); 156 if (emu_thread.isRunning())
157 emu_thread.Stop();
139 QWidget::closeEvent(event); 158 QWidget::closeEvent(event);
140} 159}
141 160
@@ -212,4 +231,5 @@ void GRenderWindow::keyReleaseEvent(QKeyEvent* event)
212 if (!key_processed) 231 if (!key_processed)
213 QWidget::keyPressEvent(event); 232 QWidget::keyPressEvent(event);
214 */ 233 */
215} \ No newline at end of file 234}
235