Replaced baker in OvenCLI with an std::unique_ptr

This commit is contained in:
seefo 2017-06-08 09:47:01 -07:00
parent 99e9e10882
commit 0c7ffa0ac6
2 changed files with 10 additions and 12 deletions

View file

@ -40,30 +40,25 @@ void BakerCLI::bakeFile(QUrl inputUrl, const QString outputPath) {
} }
// create our appropiate baker // create our appropiate baker
Baker* baker;
if (isFBX) { if (isFBX) {
baker = new FBXBaker(inputUrl, outputPath, []() -> QThread* { _baker = std::unique_ptr<Baker> { new FBXBaker(inputUrl, outputPath, []() -> QThread* { return qApp->getNextWorkerThread(); }) };
return qApp->getNextWorkerThread(); _baker->moveToThread(qApp->getFBXBakerThread());
});
baker->moveToThread(qApp->getFBXBakerThread());
} else if (isSupportedImage) { } else if (isSupportedImage) {
baker = new TextureBaker(inputUrl, image::TextureUsage::CUBE_TEXTURE, outputPath); _baker = std::unique_ptr<Baker> { new TextureBaker(inputUrl, image::TextureUsage::CUBE_TEXTURE, outputPath) };
baker->moveToThread(qApp->getNextWorkerThread()); _baker->moveToThread(qApp->getNextWorkerThread());
} else { } else {
qCDebug(model_baking) << "Failed to determine baker type for file" << inputUrl; qCDebug(model_baking) << "Failed to determine baker type for file" << inputUrl;
return; return;
} }
// invoke the bake method on the baker thread // invoke the bake method on the baker thread
QMetaObject::invokeMethod(baker, "bake"); QMetaObject::invokeMethod(_baker.get(), "bake");
// make sure we hear about the results of this baker when it is done // make sure we hear about the results of this baker when it is done
connect(baker, &Baker::finished, this, &BakerCLI::handleFinishedBaker); connect(_baker.get(), &Baker::finished, this, &BakerCLI::handleFinishedBaker);
} }
void BakerCLI::handleFinishedBaker() { void BakerCLI::handleFinishedBaker() {
qCDebug(model_baking) << "Finished baking file."; qCDebug(model_baking) << "Finished baking file.";
sender()->deleteLater();
QApplication::quit(); QApplication::quit();
} }

View file

@ -14,6 +14,7 @@
#include <QtCore/QObject> #include <QtCore/QObject>
#include "Baker.h"
#include "Oven.h" #include "Oven.h"
class BakerCLI : public QObject { class BakerCLI : public QObject {
@ -24,8 +25,10 @@ public:
void bakeFile(QUrl inputUrl, const QString outputPath); void bakeFile(QUrl inputUrl, const QString outputPath);
private slots: private slots:
void handleFinishedBaker(); void handleFinishedBaker();
private:
std::unique_ptr<Baker> _baker;
}; };
#endif // hifi_BakerCLI_h #endif // hifi_BakerCLI_h