From fac6015bb0e391850d3d68b28d40b2daf3e6921d Mon Sep 17 00:00:00 2001 From: Atlante45 Date: Wed, 9 Aug 2017 18:25:58 -0700 Subject: [PATCH] Asset baking status first pass --- assignment-client/src/assets/AssetServer.cpp | 11 ++++++ assignment-client/src/assets/AssetServer.h | 3 ++ assignment-client/src/assets/AutoBaker.cpp | 38 +++++++++++++++++++ assignment-client/src/assets/AutoBaker.h | 39 ++++++++++++++++++++ 4 files changed, 91 insertions(+) create mode 100644 assignment-client/src/assets/AutoBaker.cpp create mode 100644 assignment-client/src/assets/AutoBaker.h diff --git a/assignment-client/src/assets/AssetServer.cpp b/assignment-client/src/assets/AssetServer.cpp index e28ad9ead8..1f74a401e3 100644 --- a/assignment-client/src/assets/AssetServer.cpp +++ b/assignment-client/src/assets/AssetServer.cpp @@ -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() { diff --git a/assignment-client/src/assets/AssetServer.h b/assignment-client/src/assets/AssetServer.h index 2dfc5f6c35..2ce223760f 100644 --- a/assignment-client/src/assets/AssetServer.h +++ b/assignment-client/src/assets/AssetServer.h @@ -19,6 +19,7 @@ #include #include "AssetUtils.h" +#include "AutoBaker.h" #include "ReceivedMessage.h" class BakeAssetTask : public QObject, public QRunnable { @@ -105,6 +106,8 @@ private: QHash> _pendingBakes; QThreadPool _bakingTaskPool; + + AutoBaker _baker; }; #endif diff --git a/assignment-client/src/assets/AutoBaker.cpp b/assignment-client/src/assets/AutoBaker.cpp new file mode 100644 index 0000000000..c56e00d025 --- /dev/null +++ b/assignment-client/src/assets/AutoBaker.cpp @@ -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; + } +} diff --git a/assignment-client/src/assets/AutoBaker.h b/assignment-client/src/assets/AutoBaker.h new file mode 100644 index 0000000000..7b92118aee --- /dev/null +++ b/assignment-client/src/assets/AutoBaker.h @@ -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 + +#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 _pendingBakes; + std::vector _currentlyBaking; +}; + +#endif /* hifi_AutoBaker_h */