Yet more cleanup of Asset-related files

This commit is contained in:
Alexander Bock
2020-05-06 20:33:27 +02:00
parent fa56e9ecf4
commit 01f0a864dc
7 changed files with 33 additions and 37 deletions
+1 -2
View File
@@ -81,8 +81,7 @@ public:
void addSynchronization(std::shared_ptr<ResourceSynchronization> synchronization);
void clearSynchronizations();
const std::vector<std::shared_ptr<ResourceSynchronization>>&
ownSynchronizations() const;
std::vector<ResourceSynchronization*> ownSynchronizations() const;
void syncStateChanged(ResourceSynchronization* sync,
ResourceSynchronization::State state);
@@ -68,9 +68,9 @@ public:
State state() const;
const std::string& name() const;
bool isResolved();
bool isRejected();
bool isSyncing();
bool isResolved() const;
bool isRejected() const;
bool isSyncing() const;
CallbackHandle addStateChangeCallback(StateChangeCallback cb);
void removeStateChangeCallback(CallbackHandle id);
@@ -53,12 +53,6 @@ public:
ResourceSynchronization::StateChangeCallback callback;
};
/*using SyncStateChangeCallback =
std::function<void(
std::shared_ptr<ResourceSynchronization>,
ResourceSynchronization::State
)>;*/
WatchHandle watchSynchronization(
std::shared_ptr<ResourceSynchronization> synchronization,
ResourceSynchronization::StateChangeCallback callback
+2 -2
View File
@@ -107,7 +107,7 @@ void GuiAssetComponent::renderTree(const Asset& asset, const std::string& relati
const std::vector<std::shared_ptr<Asset>>& requested = asset.requestedAssets();
const std::vector<std::shared_ptr<Asset>>& required = asset.requiredAssets();
const std::vector<std::shared_ptr<ResourceSynchronization>>& resourceSyncs =
const std::vector<ResourceSynchronization*>& resourceSyncs =
asset.ownSynchronizations();
if (requested.empty() && required.empty() && resourceSyncs.empty()) {
@@ -126,7 +126,7 @@ void GuiAssetComponent::renderTree(const Asset& asset, const std::string& relati
}
if (!resourceSyncs.empty() && ImGui::TreeNode("Resource Synchronizations")) {
for (const std::shared_ptr<ResourceSynchronization>& sync : resourceSyncs) {
for (ResourceSynchronization* sync : resourceSyncs) {
std::string resourceText = sync->directory() +
" " + syncStateToString(sync->state());
if (sync->state() == ResourceSynchronization::State::Syncing) {
+3 -4
View File
@@ -762,12 +762,11 @@ void OpenSpaceEngine::loadSingleAsset(const std::string& assetPath) {
std::vector<std::shared_ptr<const Asset>> allAssets =
_assetManager->rootAsset()->subTreeAssets();
std::unordered_set<std::shared_ptr<ResourceSynchronization>> resourceSyncs;
std::unordered_set<ResourceSynchronization*> resourceSyncs;
for (const std::shared_ptr<const Asset>& a : allAssets) {
std::vector<std::shared_ptr<ResourceSynchronization>> syncs =
a->ownSynchronizations();
std::vector<ResourceSynchronization*> syncs = a->ownSynchronizations();
for (const std::shared_ptr<ResourceSynchronization>& s : syncs) {
for (ResourceSynchronization* s : syncs) {
ZoneScopedN("Update resource synchronization")
if (s->state() == ResourceSynchronization::State::Syncing) {
+21 -17
View File
@@ -33,19 +33,19 @@
#include <algorithm>
#include <unordered_set>
namespace openspace {
namespace {
constexpr const char* _loggerCat = "Asset";
float syncProgress(const std::vector<std::shared_ptr<const openspace::Asset>>& assets)
{
float syncProgress(const std::vector<std::shared_ptr<const Asset>>& assets) {
size_t nTotalBytes = 0;
size_t nSyncedBytes = 0;
for (const std::shared_ptr<const openspace::Asset>& a : assets) {
const std::vector<std::shared_ptr<openspace::ResourceSynchronization>>& s =
a->ownSynchronizations();
for (const std::shared_ptr<const Asset>& a : assets) {
const std::vector<ResourceSynchronization*>& s = a->ownSynchronizations();
for (const std::shared_ptr<openspace::ResourceSynchronization>& sync : s) {
for (ResourceSynchronization* sync : s) {
if (sync->nTotalBytesIsKnown()) {
nTotalBytes += sync->nTotalBytes();
nSyncedBytes += sync->nSynchronizedBytes();
@@ -64,7 +64,6 @@ namespace {
}
} // namespace
namespace openspace {
Asset::Asset(AssetLoader* loader, SynchronizationWatcher* watcher)
: _state(State::SyncResolved)
@@ -221,23 +220,28 @@ bool Asset::isSyncResolveReady() {
return false;
}
const std::vector<std::shared_ptr<ResourceSynchronization>>& syncs =
ownSynchronizations();
const std::vector<ResourceSynchronization*>& syncs = ownSynchronizations();
auto unresolvedOwnSynchronization = std::find_if(
syncs.cbegin(),
syncs.cend(),
[](const std::shared_ptr<ResourceSynchronization>& s) { return !s->isResolved(); }
[](ResourceSynchronization* s) { return !s->isResolved(); }
);
// To be considered resolved, all own synchronizations need to be resolved
return unresolvedOwnSynchronization == syncs.cend();
}
const std::vector<std::shared_ptr<ResourceSynchronization>>&
Asset::ownSynchronizations() const
{
return _synchronizations;
std::vector<ResourceSynchronization*> Asset::ownSynchronizations() const {
std::vector<ResourceSynchronization*> res;
res.reserve(_synchronizations.size());
std::transform(
_synchronizations.begin(), _synchronizations.end(),
std::back_inserter(res),
std::mem_fn(&std::shared_ptr<ResourceSynchronization>::get)
);
return res;
}
std::vector<std::shared_ptr<const Asset>> Asset::subTreeAssets() const {
@@ -389,7 +393,7 @@ bool Asset::startSynchronizations() {
}
// Now synchronize its own synchronizations
for (const std::shared_ptr<ResourceSynchronization>& s : ownSynchronizations()) {
for (ResourceSynchronization* s : ownSynchronizations()) {
if (!s->isResolved()) {
s->start();
}
@@ -411,7 +415,7 @@ bool Asset::cancelAllSynchronizations() {
}
);
for (const std::shared_ptr<ResourceSynchronization>& s : ownSynchronizations()) {
for (ResourceSynchronization* s : ownSynchronizations()) {
if (s->isSyncing()) {
cancelledAnySync = true;
s->cancel();
@@ -438,7 +442,7 @@ bool Asset::cancelUnwantedSynchronizations() {
}
);
for (const std::shared_ptr<ResourceSynchronization>& s : ownSynchronizations()) {
for (ResourceSynchronization* s : ownSynchronizations()) {
if (s->isSyncing()) {
cancelledAnySync = true;
s->cancel();
+3 -3
View File
@@ -95,15 +95,15 @@ ResourceSynchronization::State ResourceSynchronization::state() const {
return _state;
}
bool ResourceSynchronization::isResolved() {
bool ResourceSynchronization::isResolved() const {
return _state == State::Resolved;
}
bool ResourceSynchronization::isRejected() {
bool ResourceSynchronization::isRejected() const {
return _state == State::Rejected;
}
bool ResourceSynchronization::isSyncing() {
bool ResourceSynchronization::isSyncing() const {
return _state == State::Syncing;
}