mirror of
https://github.com/OpenSpace/OpenSpace.git
synced 2026-04-28 14:59:31 -05:00
Decentralize asset synchronization
This commit is contained in:
@@ -44,9 +44,15 @@ class Asset : public std::enable_shared_from_this<Asset> {
|
||||
public:
|
||||
using Optional = std::pair<std::shared_ptr<Asset>, bool>;
|
||||
|
||||
enum class ReadyState : unsigned int {
|
||||
enum class State : unsigned int {
|
||||
Unloaded,
|
||||
LoadingFailed,
|
||||
Loaded,
|
||||
Initialized
|
||||
Synchronizing,
|
||||
SyncResolved,
|
||||
SyncRejected,
|
||||
Initialized,
|
||||
InitializationFailed
|
||||
};
|
||||
|
||||
/**
|
||||
@@ -65,12 +71,18 @@ public:
|
||||
std::string assetDirectory() const;
|
||||
std::string assetName() const;
|
||||
AssetLoader* loader() const;
|
||||
ReadyState readyState() const;
|
||||
State state() const;
|
||||
|
||||
void setState(State state);
|
||||
void addSynchronization(std::shared_ptr<ResourceSynchronization> synchronization);
|
||||
std::vector<std::shared_ptr<ResourceSynchronization>> synchronizations();
|
||||
std::vector<std::shared_ptr<Asset>> allAssets();
|
||||
|
||||
bool startSynchronizations();
|
||||
bool cancelSynchronizations();
|
||||
bool restartSynchronizations();
|
||||
float synchronizationProgress();
|
||||
|
||||
bool isInitReady() const;
|
||||
void initialize();
|
||||
void deinitialize();
|
||||
@@ -86,7 +98,10 @@ public:
|
||||
|
||||
std::string resolveLocalResource(std::string resourceName);
|
||||
private:
|
||||
ReadyState _readyState;
|
||||
void startSync(ResourceSynchronization& rs);
|
||||
void cancelSync(ResourceSynchronization& rs);
|
||||
|
||||
State _state;
|
||||
AssetLoader* _loader;
|
||||
std::vector<std::shared_ptr<ResourceSynchronization>> _synchronizations;
|
||||
|
||||
|
||||
@@ -28,7 +28,6 @@
|
||||
#include <openspace/scene/scenegraphnode.h>
|
||||
|
||||
#include <openspace/scripting/lualibrary.h>
|
||||
#include <openspace/scene/assetsynchronizer.h>
|
||||
#include <openspace/util/resourcesynchronization.h>
|
||||
|
||||
#include <ghoul/misc/dictionary.h>
|
||||
@@ -170,7 +169,6 @@ private:
|
||||
std::map<std::string, std::shared_ptr<Asset>> _importedAssets;
|
||||
std::vector<std::shared_ptr<Asset>> _assetStack;
|
||||
|
||||
AssetSynchronizer* _assetSynchronizer;
|
||||
std::string _assetRootDirectory;
|
||||
ghoul::lua::LuaState* _luaState;
|
||||
|
||||
|
||||
@@ -54,32 +54,20 @@ class Asset;
|
||||
class AssetManager {
|
||||
public:
|
||||
AssetManager(
|
||||
std::unique_ptr<AssetLoader> loader,
|
||||
std::unique_ptr<AssetSynchronizer> synchronizer
|
||||
std::unique_ptr<AssetLoader> loader
|
||||
);
|
||||
|
||||
enum class AssetState : int {
|
||||
Unloaded,
|
||||
Loaded,
|
||||
LoadingFailed,
|
||||
Synchronized,
|
||||
SynchronizationFailed,
|
||||
Initialized,
|
||||
InitializationFailed
|
||||
};
|
||||
|
||||
struct ManagedAsset {
|
||||
std::string path;
|
||||
std::shared_ptr<Asset> asset;
|
||||
AssetState state;
|
||||
};
|
||||
|
||||
bool update();
|
||||
|
||||
void setTargetAssetState(const std::string& path, AssetState targetState);
|
||||
void setTargetAssetState(Asset* asset, AssetState targetState);
|
||||
AssetState currentAssetState(Asset* asset);
|
||||
AssetState currentAssetState(const std::string& path);
|
||||
void setTargetAssetState(const std::string& path, Asset::State targetState);
|
||||
void setTargetAssetState(Asset* asset, Asset::State targetState);
|
||||
Asset::State currentAssetState(Asset* asset);
|
||||
Asset::State currentAssetState(const std::string& path);
|
||||
|
||||
void clearAllTargetAssets();
|
||||
std::vector<std::shared_ptr<Asset>> loadedAssets();
|
||||
@@ -96,7 +84,7 @@ private:
|
||||
std::vector<ManagedAsset> _managedAssets;
|
||||
|
||||
|
||||
std::unordered_map<std::string, AssetState> _pendingStateChangeCommands;
|
||||
std::unordered_map<std::string, Asset::State> _pendingStateChangeCommands;
|
||||
//std::unordered_map<Asset*, AssetState> _stateChangesInProgress;
|
||||
std::unordered_set<Asset*> _pendingInitializations;
|
||||
|
||||
@@ -104,7 +92,6 @@ private:
|
||||
std::unordered_map<Asset*, std::unordered_set<Asset*>> _syncDependencies;
|
||||
|
||||
std::unique_ptr<AssetLoader> _assetLoader;
|
||||
std::unique_ptr<AssetSynchronizer> _assetSynchronizer;
|
||||
};
|
||||
|
||||
} // namespace openspace
|
||||
|
||||
@@ -1,90 +0,0 @@
|
||||
/*****************************************************************************************
|
||||
* *
|
||||
* OpenSpace *
|
||||
* *
|
||||
* Copyright (c) 2014-2017 *
|
||||
* *
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy of this *
|
||||
* software and associated documentation files (the "Software"), to deal in the Software *
|
||||
* without restriction, including without limitation the rights to use, copy, modify, *
|
||||
* merge, publish, distribute, sublicense, and/or sell copies of the Software, and to *
|
||||
* permit persons to whom the Software is furnished to do so, subject to the following *
|
||||
* conditions: *
|
||||
* *
|
||||
* The above copyright notice and this permission notice shall be included in all copies *
|
||||
* or substantial portions of the Software. *
|
||||
* *
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, *
|
||||
* INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A *
|
||||
* PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT *
|
||||
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF *
|
||||
* CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE *
|
||||
* OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. *
|
||||
****************************************************************************************/
|
||||
|
||||
#ifndef __OPENSPACE_CORE___ASSETSYNCHRONIZER___H__
|
||||
#define __OPENSPACE_CORE___ASSETSYNCHRONIZER___H__
|
||||
|
||||
#include <openspace/scene/scenegraphnode.h>
|
||||
#include <openspace/scene/asset.h>
|
||||
|
||||
#include <openspace/scripting/lualibrary.h>
|
||||
|
||||
#include <ghoul/misc/dictionary.h>
|
||||
#include <ghoul/lua/luastate.h>
|
||||
|
||||
#include <ghoul/lua/ghoul_lua.h>
|
||||
#include <ghoul/filesystem/directory.h>
|
||||
|
||||
#include <memory>
|
||||
#include <string>
|
||||
#include <unordered_map>
|
||||
#include <unordered_set>
|
||||
|
||||
namespace openspace {
|
||||
|
||||
class AssetSynchronizer {
|
||||
public:
|
||||
enum class SynchronizationState : int {
|
||||
Unsynced,
|
||||
Synchronizing,
|
||||
Resolved,
|
||||
Rejected
|
||||
};
|
||||
|
||||
struct StateChange {
|
||||
std::shared_ptr<Asset> asset;
|
||||
SynchronizationState state;
|
||||
};
|
||||
|
||||
struct AssetResourceSync {
|
||||
std::shared_ptr<Asset> asset;
|
||||
std::shared_ptr<ResourceSynchronization> sync;
|
||||
};
|
||||
|
||||
AssetSynchronizer();
|
||||
void startSync(std::shared_ptr<Asset> asset);
|
||||
void cancelSync(std::shared_ptr<Asset> asset);
|
||||
void restartSync(std::shared_ptr<Asset> asset);
|
||||
|
||||
SynchronizationState assetState(Asset* asset);
|
||||
float assetProgress(Asset* asset);
|
||||
|
||||
std::vector<StateChange> getStateChanges();
|
||||
|
||||
private:
|
||||
void startAssetResourceSync(std::shared_ptr<Asset> a, std::shared_ptr<ResourceSynchronization> rs);
|
||||
void cancelAssetResourceSync(std::shared_ptr<Asset> a, std::shared_ptr<ResourceSynchronization> rs);
|
||||
|
||||
void handleSyncStateChange(std::shared_ptr<Asset>, std::shared_ptr<ResourceSynchronization>, ResourceSynchronization::State state);
|
||||
|
||||
void setState(std::shared_ptr<Asset> a, SynchronizationState state);
|
||||
|
||||
std::vector<std::shared_ptr<Asset>> _synchronizingAssets;
|
||||
std::unordered_map<Asset*, StateChange> _stateChanges;
|
||||
std::unordered_map<ResourceSynchronization*, std::unordered_set<Asset*>> _resourceToAssetMap;
|
||||
};
|
||||
|
||||
} // namespace openspace
|
||||
|
||||
#endif // __OPENSPACE_CORE___ASSETSYNCHRONIZER___H__
|
||||
Reference in New Issue
Block a user