|
15 | 15 | #include <QMetaObject> |
16 | 16 |
|
17 | 17 | Controller::Controller() { |
18 | | - threadA.reset(new QThread()); |
19 | | - threadB.reset(new QThread()); |
20 | | - workerA.reset(new QObject()); |
21 | | - workerB.reset(new QObject()); |
22 | | - |
23 | | - workerA->moveToThread(threadA.data()); |
24 | | - workerB->moveToThread(threadB.data()); |
25 | | - |
26 | | - threadA->start(); |
27 | | - threadB->start(); |
| 18 | + threadDatabase.reset(new QThread()); |
| 19 | + threadFile.reset(new QThread()); |
| 20 | + threadScrape.reset(new QThread()); |
| 21 | + threadRun.reset(new QThread()); |
| 22 | + |
| 23 | + workerDatabase.reset(new QObject()); |
| 24 | + workerFile.reset(new QObject()); |
| 25 | + workerScrape.reset(new QObject()); |
| 26 | + workerRun.reset(new QObject()); |
| 27 | + |
| 28 | + workerDatabase->moveToThread(threadDatabase.data()); |
| 29 | + workerFile->moveToThread(threadFile.data()); |
| 30 | + workerScrape->moveToThread(threadScrape.data()); |
| 31 | + workerRun->moveToThread(threadRun.data()); |
| 32 | + |
| 33 | + threadDatabase->start(); |
| 34 | + threadFile->start(); |
| 35 | + threadScrape->start(); |
| 36 | + threadRun->start(); |
28 | 37 |
|
29 | 38 | connect(&model, &Model::modelTickSignal, |
30 | 39 | this, &Controller::controllerTickSignal, |
@@ -53,48 +62,71 @@ Controller::Controller() { |
53 | 62 | connect(&model, &Model::modelLoadingDoneSignal, |
54 | 63 | this, &Controller::controllerLoadingDone, |
55 | 64 | Qt::QueuedConnection); |
| 65 | + |
| 66 | + connect(&model, &Model::modelRunningDoneSignal, |
| 67 | + this, &Controller::controllerRunningDone, |
| 68 | + Qt::QueuedConnection); |
56 | 69 | } |
57 | 70 |
|
58 | 71 | Controller::~Controller() { |
59 | | - threadA->quit(); |
60 | | - threadB->quit(); |
61 | | - threadA->wait(); |
62 | | - threadB->wait(); |
| 72 | + threadDatabase->quit(); |
| 73 | + threadFile->quit(); |
| 74 | + threadScrape->quit(); |
| 75 | + threadRun->quit(); |
| 76 | + |
| 77 | + threadDatabase->wait(); |
| 78 | + threadFile->wait(); |
| 79 | + threadScrape->wait(); |
| 80 | + threadRun->wait(); |
63 | 81 | } |
64 | 82 |
|
65 | | -void Controller::runOnThreadA(std::function<void()> func) { |
66 | | - QMetaObject::invokeMethod( |
67 | | - workerA.data(), [func]() { func(); }, Qt::QueuedConnection); |
| 83 | +void Controller::runOnThreadDatabase(std::function<void()> func) { |
| 84 | + QMetaObject::invokeMethod(workerDatabase.data(), |
| 85 | + [func]() { func(); }, Qt::QueuedConnection); |
68 | 86 | } |
69 | 87 |
|
70 | | -void Controller::runOnThreadB(std::function<void()> func) { |
71 | | - QMetaObject::invokeMethod( |
72 | | - workerB.data(), [func]() { func(); }, Qt::QueuedConnection); |
| 88 | +void Controller::runOnThreadFile(std::function<void()> func) { |
| 89 | + QMetaObject::invokeMethod(workerFile.data(), |
| 90 | + [func]() { func(); }, Qt::QueuedConnection); |
| 91 | +} |
| 92 | + |
| 93 | +void Controller::runOnThreadScrape(std::function<void()> func) { |
| 94 | + QMetaObject::invokeMethod(workerScrape.data(), |
| 95 | + [func]() { func(); }, Qt::QueuedConnection); |
| 96 | +} |
| 97 | + |
| 98 | +void Controller::runOnThreadRun(std::function<void()> func) { |
| 99 | + QMetaObject::invokeMethod(workerRun.data(), |
| 100 | + [func]() { func(); }, Qt::QueuedConnection); |
73 | 101 | } |
74 | 102 |
|
75 | 103 | // Threaded work |
76 | 104 | void Controller::setup() { |
77 | | - runOnThreadA([=]() { model.setup(); }); |
| 105 | + runOnThreadFile([=]() { model.setup(); }); |
78 | 106 | } |
79 | 107 |
|
80 | 108 | void Controller::setupGame(int id) { |
81 | | - runOnThreadA([=]() { model.setupGame(id); }); |
| 109 | + runOnThreadFile([=]() { model.setupGame(id); }); |
82 | 110 | } |
83 | 111 |
|
84 | 112 | void Controller::setupLevel(int id) { |
85 | | - runOnThreadA([=]() { model.getLevel(id); }); |
| 113 | + runOnThreadFile([=]() { model.getLevel(id); }); |
86 | 114 | } |
87 | 115 |
|
88 | 116 | void Controller::updateLevel(int id) { |
89 | | - runOnThreadA([=]() { model.updateLevel(id); }); |
| 117 | + runOnThreadScrape([=]() { model.updateLevel(id); }); |
90 | 118 | } |
91 | 119 |
|
92 | 120 | void Controller::syncLevels() { |
93 | | - runOnThreadA([=]() { model.syncLevels(); }); |
| 121 | + runOnThreadScrape([=]() { model.syncLevels(); }); |
94 | 122 | } |
95 | 123 |
|
96 | 124 | void Controller::getCoverList(QVector<QSharedPointer<ListItemData>> items) { |
97 | | - runOnThreadB([=]() { model.getCoverList(items); }); |
| 125 | + runOnThreadDatabase([=]() { model.getCoverList(items); }); |
| 126 | +} |
| 127 | + |
| 128 | +void Controller::run(RunnerOptions opptions) { |
| 129 | + runOnThreadRun([=]() { model.run(opptions); }); |
98 | 130 | } |
99 | 131 |
|
100 | 132 | // UI/main thread work |
|
0 commit comments