Changed to rely only on the promise/future mechanism for return values from MiximageGenerator.

This commit is contained in:
Leon Styhre 2021-06-08 22:25:53 +02:00
parent de36ed1b68
commit 928b0c6575
3 changed files with 9 additions and 13 deletions

View file

@ -4,7 +4,7 @@
// MiximageGenerator.cpp // MiximageGenerator.cpp
// //
// Generates miximages from screenshots, marquees and 3D box/cover images. // Generates miximages from screenshots, marquees and 3D box/cover images.
// Called from GuiScraperSearch. // Called from GuiScraperSearch and GuiOfflineGenerator.
// //
#include "MiximageGenerator.h" #include "MiximageGenerator.h"
@ -17,9 +17,8 @@
#include <chrono> #include <chrono>
MiximageGenerator::MiximageGenerator(FileData* game, bool& result, std::string& resultMessage) MiximageGenerator::MiximageGenerator(FileData* game, std::string& resultMessage)
: mGame(game), : mGame(game),
mResult(result),
mResultMessage(resultMessage), mResultMessage(resultMessage),
mWidth(1280), mWidth(1280),
mHeight(960), mHeight(960),
@ -43,7 +42,6 @@ void MiximageGenerator::startThread(std::promise<bool>* miximagePromise)
if (mGame->getMiximagePath() != "" && !Settings::getInstance()->getBool("MiximageOverwrite")) { if (mGame->getMiximagePath() != "" && !Settings::getInstance()->getBool("MiximageOverwrite")) {
LOG(LogDebug) << "MiximageGenerator::MiximageGenerator(): File already exists and miximage " LOG(LogDebug) << "MiximageGenerator::MiximageGenerator(): File already exists and miximage "
"overwriting has not been enabled, aborting"; "overwriting has not been enabled, aborting";
mResult = true;
mMiximagePromise->set_value(true); mMiximagePromise->set_value(true);
return; return;
} }
@ -52,7 +50,6 @@ void MiximageGenerator::startThread(std::promise<bool>* miximagePromise)
LOG(LogDebug) << "MiximageGenerator::MiximageGenerator(): " LOG(LogDebug) << "MiximageGenerator::MiximageGenerator(): "
"No screenshot image found, aborting"; "No screenshot image found, aborting";
mResultMessage = "No screenshot image found, couldn't generate miximage"; mResultMessage = "No screenshot image found, couldn't generate miximage";
mResult = true;
mMiximagePromise->set_value(true); mMiximagePromise->set_value(true);
return; return;
} }
@ -89,7 +86,9 @@ void MiximageGenerator::startThread(std::promise<bool>* miximagePromise)
if (generateImage()) { if (generateImage()) {
LOG(LogError) << "Failed to generate miximage"; LOG(LogError) << "Failed to generate miximage";
mResult = true; mMiximagePromise->set_value(true);
mResultMessage = mMessage;
return;
} }
else { else {
const auto endTime = std::chrono::system_clock::now(); const auto endTime = std::chrono::system_clock::now();
@ -99,7 +98,6 @@ void MiximageGenerator::startThread(std::promise<bool>* miximagePromise)
(endTime - startTime).count() << " ms"; (endTime - startTime).count() << " ms";
} }
mResult = false;
mResultMessage = mMessage; mResultMessage = mMessage;
mMiximagePromise->set_value(false); mMiximagePromise->set_value(false);
} }

View file

@ -4,7 +4,7 @@
// MiximageGenerator.h // MiximageGenerator.h
// //
// Generates miximages from screenshots, marquees and 3D box/cover images. // Generates miximages from screenshots, marquees and 3D box/cover images.
// Called from GuiScraperSearch. // Called from GuiScraperSearch and GuiOfflineGenerator.
// //
#ifndef ES_APP_SCRAPERS_MIXIMAGE_GENERATOR_H #ifndef ES_APP_SCRAPERS_MIXIMAGE_GENERATOR_H
@ -25,7 +25,7 @@ using namespace cimg_library;
class MiximageGenerator class MiximageGenerator
{ {
public: public:
MiximageGenerator(FileData* game, bool& result, std::string& resultMessage); MiximageGenerator(FileData* game, std::string& resultMessage);
~MiximageGenerator(); ~MiximageGenerator();
void startThread(std::promise<bool>* miximagePromise); void startThread(std::promise<bool>* miximagePromise);
@ -44,10 +44,8 @@ private:
std::string getSavePath(); std::string getSavePath();
FileData* mGame; FileData* mGame;
bool& mResult;
std::string& mResultMessage; std::string& mResultMessage;
std::string mMessage; std::string mMessage;
std::promise<bool>* mMiximagePromise; std::promise<bool>* mMiximagePromise;
std::string mScreenshotPath; std::string mScreenshotPath;

View file

@ -667,7 +667,7 @@ void GuiScraperSearch::update(int deltaTime)
mMDResolveHandle.reset(); mMDResolveHandle.reset();
// We always let the miximage generator thread complete. // We always let the miximage generator thread complete.
mMiximageGeneratorThread.join(); mMiximageGeneratorThread.join();
if (!mMiximageResult) if (!mGeneratorFuture.get())
mScrapeResult.savedNewMedia = true; mScrapeResult.savedNewMedia = true;
returnResult(mScrapeResult); returnResult(mScrapeResult);
mMiximageGenerator.reset(); mMiximageGenerator.reset();
@ -687,7 +687,7 @@ void GuiScraperSearch::update(int deltaTime)
Settings::getInstance()->getBool("MiximageOverwrite"))) { Settings::getInstance()->getBool("MiximageOverwrite"))) {
mMiximageGenerator = std::make_unique<MiximageGenerator>(mLastSearch.game, mMiximageGenerator = std::make_unique<MiximageGenerator>(mLastSearch.game,
mMiximageResult, mResultMessage); mResultMessage);
// The promise/future mechanism is used as signaling for the thread to // The promise/future mechanism is used as signaling for the thread to
// indicate that processing has been completed. The reason to run a separate // indicate that processing has been completed. The reason to run a separate