Asset baking status first pass

This commit is contained in:
Atlante45 2017-08-09 18:25:58 -07:00
parent cefd16ad95
commit fac6015bb0
4 changed files with 91 additions and 0 deletions

View file

@ -331,6 +331,17 @@ void AssetServer::completeSetup() {
qCCritical(asset_server) << "Asset Server assignment will not continue because mapping file could not be loaded.";
setFinished(true);
}
QRegExp hashFileRegex { "^[a-f0-9]{" + QString::number(SHA256_HASH_HEX_LENGTH) + "}" };
auto files = _filesDirectory.entryInfoList(QDir::Files);
auto mappedHashes = _fileMappings.values();
for (const auto& fileInfo : files) {
AssetHash hash = fileInfo.fileName();
bool isAsset = hashFileRegex.exactMatch(hash);
if (isAsset && _baker.assetNeedsBaking(hash)) {
_baker.addPendingBake(hash);
}
}
}
void AssetServer::cleanupUnmappedFiles() {

View file

@ -19,6 +19,7 @@
#include <ThreadedAssignment.h>
#include "AssetUtils.h"
#include "AutoBaker.h"
#include "ReceivedMessage.h"
class BakeAssetTask : public QObject, public QRunnable {
@ -105,6 +106,8 @@ private:
QHash<QString, std::shared_ptr<BakeAssetTask>> _pendingBakes;
QThreadPool _bakingTaskPool;
AutoBaker _baker;
};
#endif

View file

@ -0,0 +1,38 @@
//
// AutoBaker.cpp
// assignment-client/src/assets
//
// Created by Clement Brisset on 8/9/17
// Copyright 2015 High Fidelity, Inc.
//
// Distributed under the Apache License, Version 2.0.
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
//
#include "AutoBaker.h"
void AutoBaker::addPendingBake(AssetHash hash) {
_pendingBakes.push_back(hash);
}
bool AutoBaker::assetNeedsBaking(AssetHash hash) {
return true;
}
AutoBaker::Status AutoBaker::getAssetStatus(AssetHash hash) {
auto pendingIt = std::find(_pendingBakes.cbegin(), _pendingBakes.cend(), hash);
if (pendingIt != _pendingBakes.cend()) {
return Pending;
}
auto bakingIt = std::find(_currentlyBaking.cbegin(), _currentlyBaking.cend(), hash);
if (bakingIt != _currentlyBaking.cend()) {
return Baking;
}
if (assetNeedsBaking(hash)) {
return NotBaked;
} else {
return Baked;
}
}

View file

@ -0,0 +1,39 @@
//
// AutoBaker.h
// assignment-client/src/assets
//
// Created by Clement Brisset on 8/9/17
// Copyright 2015 High Fidelity, Inc.
//
// Distributed under the Apache License, Version 2.0.
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
//
#ifndef hifi_AutoBaker_h
#define hifi_AutoBaker_h
#include <vector>
#include "AssetUtils.h"
class AutoBaker {
public:
enum Status {
NotBaked,
Pending,
Baking,
Baked
};
void addPendingBake(AssetHash hash);
bool assetNeedsBaking(AssetHash hash);
Status getAssetStatus(AssetHash hash);
private:
std::vector<AssetHash> _pendingBakes;
std::vector<AssetHash> _currentlyBaking;
};
#endif /* hifi_AutoBaker_h */