diff --git a/Source/Core/Common/WorkQueueThread.h b/Source/Core/Common/WorkQueueThread.h index 8947b099cb..426d8b493d 100644 --- a/Source/Core/Common/WorkQueueThread.h +++ b/Source/Core/Common/WorkQueueThread.h @@ -35,7 +35,7 @@ public: { { std::unique_lock lg(m_lock); - m_items.emplace(std::move(args)...); + m_items.emplace(std::forward(args)...); } m_wakeup.Set(); } diff --git a/Source/Core/DolphinQt2/GameList/GameTracker.cpp b/Source/Core/DolphinQt2/GameList/GameTracker.cpp index 6050feaa8d..f1558f153d 100644 --- a/Source/Core/DolphinQt2/GameList/GameTracker.cpp +++ b/Source/Core/DolphinQt2/GameList/GameTracker.cpp @@ -17,23 +17,11 @@ static const QStringList game_filters{ GameTracker::GameTracker(QObject* parent) : QFileSystemWatcher(parent) { - m_loader = new GameLoader; - m_loader->moveToThread(&m_loader_thread); - qRegisterMetaType>(); - connect(&m_loader_thread, &QThread::finished, m_loader, &QObject::deleteLater); connect(this, &QFileSystemWatcher::directoryChanged, this, &GameTracker::UpdateDirectory); connect(this, &QFileSystemWatcher::fileChanged, this, &GameTracker::UpdateFile); - connect(this, &GameTracker::PathChanged, m_loader, &GameLoader::LoadGame); - connect(m_loader, &GameLoader::GameLoaded, this, &GameTracker::GameLoaded); - m_loader_thread.start(); -} - -GameTracker::~GameTracker() -{ - m_loader_thread.quit(); - m_loader_thread.wait(); + m_load_thread.Reset([this](const QString& path) { LoadGame(path); }); } void GameTracker::AddDirectory(const QString& dir) @@ -81,7 +69,7 @@ void GameTracker::UpdateDirectory(const QString& dir) { addPath(path); m_tracked_files[path] = QSet{dir}; - emit PathChanged(path); + m_load_thread.EmplaceItem(path); } } @@ -127,7 +115,7 @@ void GameTracker::UpdateFile(const QString& file) GameRemoved(file); addPath(file); - emit PathChanged(file); + m_load_thread.EmplaceItem(file); } else if (removePath(file)) { @@ -136,7 +124,7 @@ void GameTracker::UpdateFile(const QString& file) } } -void GameLoader::LoadGame(const QString& path) +void GameTracker::LoadGame(const QString& path) { if (!DiscIO::ShouldHideFromGameList(path.toStdString())) { diff --git a/Source/Core/DolphinQt2/GameList/GameTracker.h b/Source/Core/DolphinQt2/GameList/GameTracker.h index 926e2a9ae2..550a6548ee 100644 --- a/Source/Core/DolphinQt2/GameList/GameTracker.h +++ b/Source/Core/DolphinQt2/GameList/GameTracker.h @@ -9,25 +9,19 @@ #include #include #include -#include -#include +#include "Common/WorkQueueThread.h" #include "DolphinQt2/GameList/GameFile.h" -class GameLoader; - // Watches directories and loads GameFiles in a separate thread. // To use this, just add directories using AddDirectory, and listen for the -// GameLoaded and GameRemoved signals. Ignore the PathChanged signal, it's -// only there because the Qt people made fileChanged and directoryChanged -// private. +// GameLoaded and GameRemoved signals. class GameTracker final : public QFileSystemWatcher { Q_OBJECT public: explicit GameTracker(QObject* parent = nullptr); - ~GameTracker(); void AddDirectory(const QString& dir); void RemoveDirectory(const QString& dir); @@ -36,28 +30,15 @@ signals: void GameLoaded(QSharedPointer game); void GameRemoved(const QString& path); - void PathChanged(const QString& path); - private: + void LoadGame(const QString& path); void UpdateDirectory(const QString& dir); void UpdateFile(const QString& path); QSet FindMissingFiles(const QString& dir); // game path -> directories that track it QMap> m_tracked_files; - QThread m_loader_thread; - GameLoader* m_loader; -}; - -class GameLoader final : public QObject -{ - Q_OBJECT - -public: - void LoadGame(const QString& path); - -signals: - void GameLoaded(QSharedPointer game); + Common::WorkQueueThread m_load_thread; }; Q_DECLARE_METATYPE(QSharedPointer)