add domain bake progress to results table

This commit is contained in:
Stephen Birarda 2017-04-17 09:33:52 -07:00
parent 49e7ae6dbc
commit 446cbf59b3
4 changed files with 34 additions and 0 deletions

View file

@ -212,10 +212,14 @@ void DomainBaker::enumerateEntities() {
// add this QJsonValueRef to our multi hash so that we can easily re-write
// the model URL to the baked version once the baker is complete
_entitiesNeedingRewrite.insert(modelURL, *it);
++_totalNumberOfEntities;
}
}
}
}
// emit progress now to say we're just starting
emit bakeProgress(0, _totalNumberOfEntities);
}
void DomainBaker::handleFinishedBaker() {
@ -260,6 +264,9 @@ void DomainBaker::handleFinishedBaker() {
// drop our shared pointer to this baker so that it gets cleaned up
_bakers.remove(baker->getFBXUrl());
// emit progress to tell listeners how many models we have baked
emit bakeProgress(_totalNumberOfEntities - _entitiesNeedingRewrite.keys().size(), _totalNumberOfEntities);
if (_entitiesNeedingRewrite.isEmpty()) {
emit allModelsFinished();
}

View file

@ -31,6 +31,7 @@ public:
signals:
void allModelsFinished();
void bakeProgress(int modelsBaked, int modelsTotal);
private slots:
void handleFinishedBaker();
@ -54,6 +55,8 @@ private:
std::unique_ptr<QThread> _fbxBakerThread;
QHash<QUrl, QSharedPointer<FBXBaker>> _bakers;
QMultiHash<QUrl, QJsonValueRef> _entitiesNeedingRewrite;
int _totalNumberOfEntities;
};
#endif // hifi_DomainBaker_h

View file

@ -213,6 +213,9 @@ void DomainBakeWidget::bakeButtonClicked() {
// make sure we hear from the baker when it is done
connect(domainBaker.get(), &DomainBaker::finished, this, &DomainBakeWidget::handleFinishedBaker);
// watch the baker's progress so that we can put its progress in the results table
connect(domainBaker.get(), &DomainBaker::bakeProgress, this, &DomainBakeWidget::handleBakerProgress);
// run the baker in our thread pool
QtConcurrent::run(domainBaker.get(), &DomainBaker::bake);
@ -226,6 +229,26 @@ void DomainBakeWidget::bakeButtonClicked() {
}
}
void DomainBakeWidget::handleBakerProgress(int modelsBaked, int modelsTotal) {
if (auto baker = qobject_cast<DomainBaker*>(sender())) {
// add the results of this bake to the results window
auto it = std::remove_if(_bakers.begin(), _bakers.end(), [baker](const BakerRowPair& value) {
return value.first.get() == baker;
});
if (it != _bakers.end()) {
auto resultRow = it->second;
auto resultsWindow = qApp->getMainWindow()->showResultsWindow();
int percentage = roundf(float(modelsBaked) / float(modelsTotal) * 100.0f);
qDebug() << percentage;
auto statusString = QString("Baking - %1 of %2 models baked - %3%").arg(modelsBaked).arg(modelsTotal).arg(percentage);
resultsWindow->changeStatusForRow(resultRow, statusString);
}
}
}
void DomainBakeWidget::handleFinishedBaker() {
if (auto baker = qobject_cast<DomainBaker*>(sender())) {
// add the results of this bake to the results window

View file

@ -34,6 +34,7 @@ private slots:
void outputDirectoryChanged(const QString& newDirectory);
void handleBakerProgress(int modelsBaked, int modelsTotal);
void handleFinishedBaker();
private: