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

View file

@ -4,7 +4,7 @@
// MiximageGenerator.h
//
// 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
@ -25,7 +25,7 @@ using namespace cimg_library;
class MiximageGenerator
{
public:
MiximageGenerator(FileData* game, bool& result, std::string& resultMessage);
MiximageGenerator(FileData* game, std::string& resultMessage);
~MiximageGenerator();
void startThread(std::promise<bool>* miximagePromise);
@ -44,10 +44,8 @@ private:
std::string getSavePath();
FileData* mGame;
bool& mResult;
std::string& mResultMessage;
std::string mMessage;
std::promise<bool>* mMiximagePromise;
std::string mScreenshotPath;

View file

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