mirror of
https://github.com/OpenSpace/OpenSpace.git
synced 2026-02-13 07:01:11 -06:00
Asset syncing
This commit is contained in:
@@ -70,7 +70,6 @@ public:
|
||||
void addSynchronization(std::shared_ptr<ResourceSynchronization> synchronization);
|
||||
std::vector<std::shared_ptr<ResourceSynchronization>> synchronizations();
|
||||
|
||||
std::vector<std::shared_ptr<Asset>> allActiveAssets();
|
||||
std::vector<std::shared_ptr<Asset>> allAssets();
|
||||
|
||||
bool isInitReady() const;
|
||||
|
||||
@@ -41,6 +41,16 @@ namespace openspace {
|
||||
|
||||
class Asset;
|
||||
|
||||
/**
|
||||
* Interface for managing assets.
|
||||
* The asset manager interface is only concerned with "top level" assets,
|
||||
* i.e. assets that are loaded using setTargetAssetState, and not their dependencies.
|
||||
* However, an asset is not considered synchronized before all its deps are
|
||||
* synchronized.
|
||||
* Also, setting a target state of an asset to Unloaded will only unload an asset
|
||||
* from the system if it is not a dependency of a loaded asset.
|
||||
*/
|
||||
|
||||
class AssetManager {
|
||||
public:
|
||||
AssetManager(
|
||||
@@ -65,12 +75,12 @@ public:
|
||||
};
|
||||
|
||||
bool update();
|
||||
std::shared_ptr<Asset> updateLoadState(std::string path, AssetState targetState);
|
||||
void updateSyncState(Asset* asset, AssetState targetState);
|
||||
void handleSyncStateChange(AssetSynchronizer::StateChange stateChange);
|
||||
|
||||
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 clearAllTargetAssets();
|
||||
std::vector<std::shared_ptr<Asset>> loadedAssets();
|
||||
scripting::LuaLibrary luaLibrary();
|
||||
|
||||
@@ -45,7 +45,7 @@ namespace openspace {
|
||||
class AssetSynchronizer {
|
||||
public:
|
||||
enum class SynchronizationState : int {
|
||||
Unknown,
|
||||
Unsynced,
|
||||
Synchronizing,
|
||||
Resolved,
|
||||
Rejected
|
||||
@@ -56,9 +56,15 @@ public:
|
||||
SynchronizationState state;
|
||||
};
|
||||
|
||||
struct AssetResourceSync {
|
||||
std::shared_ptr<Asset> asset;
|
||||
std::shared_ptr<ResourceSynchronization> sync;
|
||||
};
|
||||
|
||||
AssetSynchronizer();
|
||||
void startSync(std::shared_ptr<Asset> asset);
|
||||
void cancelSync(Asset* asset);
|
||||
void cancelSync(std::shared_ptr<Asset> asset);
|
||||
void restartSync(std::shared_ptr<Asset> asset);
|
||||
|
||||
SynchronizationState assetState(Asset* asset);
|
||||
float assetProgress(Asset* asset);
|
||||
@@ -66,9 +72,13 @@ public:
|
||||
std::vector<StateChange> getStateChanges();
|
||||
|
||||
private:
|
||||
std::unordered_map<Asset*, std::shared_ptr<Asset>> _synchronizingAssets;
|
||||
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 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*, Asset*> _resourceToAssetMap;
|
||||
std::unordered_map<ResourceSynchronization*, std::vector<Asset*>> _resourceToAssetMap;
|
||||
};
|
||||
|
||||
} // namespace openspace
|
||||
|
||||
@@ -34,14 +34,20 @@
|
||||
|
||||
namespace openspace {
|
||||
|
||||
class TorrentClient;
|
||||
|
||||
class ResourceSynchronization;
|
||||
|
||||
class ResourceSynchronization
|
||||
: public std::enable_shared_from_this<ResourceSynchronization>
|
||||
{
|
||||
public:
|
||||
enum class State : int {
|
||||
Unsynced,
|
||||
Syncing,
|
||||
Resolved,
|
||||
Rejected
|
||||
};
|
||||
|
||||
using CallbackHandle = size_t;
|
||||
using StateChangeCallback = std::function<void(State)>;
|
||||
|
||||
static documentation::Documentation Documentation();
|
||||
static std::unique_ptr<ResourceSynchronization> createFromDictionary(
|
||||
const ghoul::Dictionary& dictionary);
|
||||
@@ -60,14 +66,25 @@ public:
|
||||
|
||||
void wait();
|
||||
bool isResolved();
|
||||
bool isRejected();
|
||||
bool isSyncing();
|
||||
CallbackHandle addStateChangeCallback(StateChangeCallback cb);
|
||||
void removeStateChangeCallback(CallbackHandle id);
|
||||
|
||||
protected:
|
||||
void resolve();
|
||||
void reject();
|
||||
void reset();
|
||||
void begin();
|
||||
void updateProgress(float t);
|
||||
|
||||
private:
|
||||
std::atomic<bool> _started;
|
||||
std::atomic<bool> _resolved;
|
||||
std::atomic<bool> _rejected;
|
||||
void setState(State state);
|
||||
|
||||
std::atomic<State> _state = State::Unsynced;
|
||||
std::mutex _callbackMutex;
|
||||
CallbackHandle _nextCallbackId = 0;
|
||||
std::unordered_map<CallbackHandle, StateChangeCallback> _stateChangeCallbacks;
|
||||
};
|
||||
|
||||
} // namespace openspace
|
||||
|
||||
Reference in New Issue
Block a user