mirror of
https://github.com/OpenSpace/OpenSpace.git
synced 2026-04-24 13:08:49 -05:00
Resource syncing infrastructure
This commit is contained in:
@@ -49,10 +49,13 @@ public:
|
||||
);
|
||||
|
||||
enum class AssetState : int {
|
||||
Unloaded = 0,
|
||||
Loaded = 1,
|
||||
Synchronized = 2,
|
||||
Initialized = 3
|
||||
Unloaded,
|
||||
Loaded,
|
||||
LoadingFailed,
|
||||
Synchronized,
|
||||
SynchronizatoinFailed,
|
||||
Initialized,
|
||||
InitializationFailed
|
||||
};
|
||||
|
||||
bool update();
|
||||
@@ -63,6 +66,7 @@ public:
|
||||
scripting::LuaLibrary luaLibrary();
|
||||
|
||||
private:
|
||||
std::shared_ptr<Asset> tryLoadAsset(const std::string& path);
|
||||
bool tryInitializeAsset(Asset& asset);
|
||||
|
||||
std::unordered_map<std::string, AssetState> _pendingStateChangeCommands;
|
||||
|
||||
@@ -70,7 +70,7 @@ private:
|
||||
|
||||
std::unordered_map<Asset*, AssetSynchronization> _managedAssets;
|
||||
std::unordered_map<ResourceSynchronization*, Asset*> _resourceToAssetMap;
|
||||
std::vector<Asset*> _finishedSynchronizations;
|
||||
std::vector<Asset*> _trivialSynchronizations;
|
||||
};
|
||||
|
||||
|
||||
|
||||
@@ -30,38 +30,44 @@
|
||||
#include <ghoul/filesystem/directory.h>
|
||||
#include <ghoul/misc/dictionary.h>
|
||||
|
||||
#include <openspace/documentation/documentation.h>
|
||||
|
||||
namespace openspace {
|
||||
|
||||
class ResourceSynchronization;
|
||||
|
||||
struct SynchronizationProduct {
|
||||
std::shared_ptr<ResourceSynchronization> synchronization;
|
||||
ResourceSynchronization* synchronization;
|
||||
};
|
||||
|
||||
class SynchronizationJob : public Job<SynchronizationProduct> {
|
||||
public:
|
||||
SynchronizationJob(std::shared_ptr<ResourceSynchronization> synchronization);
|
||||
void execute() = 0;
|
||||
protected:
|
||||
void resolve();
|
||||
void updateProgress(float t);
|
||||
SynchronizationJob(ResourceSynchronization* synchronization);
|
||||
void execute() override;
|
||||
std::shared_ptr<SynchronizationProduct> product() override;
|
||||
private:
|
||||
std::shared_ptr<ResourceSynchronization> _synchronization;
|
||||
ResourceSynchronization* _synchronization;
|
||||
};
|
||||
|
||||
class ResourceSynchronization {
|
||||
class ResourceSynchronization
|
||||
: protected std::enable_shared_from_this<ResourceSynchronization>
|
||||
{
|
||||
public:
|
||||
ResourceSynchronization();
|
||||
static documentation::Documentation Documentation();
|
||||
static std::unique_ptr<ResourceSynchronization> createFromDictionary(
|
||||
const ghoul::Dictionary& dictionary);
|
||||
|
||||
virtual std::shared_ptr<SynchronizationJob> job();
|
||||
ResourceSynchronization();
|
||||
virtual void synchronize() = 0;
|
||||
|
||||
void wait();
|
||||
bool isResolved();
|
||||
void resolve();
|
||||
float progress();
|
||||
void updateProgress(float t);
|
||||
std::shared_ptr<SynchronizationJob> job();
|
||||
private:
|
||||
std::shared_ptr<SynchronizationJob> _job;
|
||||
std::atomic<bool> _started;
|
||||
std::atomic<bool> _resolved;
|
||||
std::atomic<float> _progress;
|
||||
|
||||
@@ -34,12 +34,29 @@ class ResourceSyncClient {};
|
||||
|
||||
class ResourceSynchronizer {
|
||||
public:
|
||||
void enqueueSynchronization(std::shared_ptr<ResourceSynchronization> sync, ResourceSyncClient* client);
|
||||
void cancelSynchronization(ResourceSynchronization* sync, ResourceSyncClient* client);
|
||||
std::vector<std::shared_ptr<SynchronizationProduct>> finishedSynchronizations(ResourceSyncClient* client);
|
||||
ResourceSynchronizer();
|
||||
|
||||
void enqueueSynchronization(
|
||||
std::shared_ptr<ResourceSynchronization> sync,
|
||||
ResourceSyncClient* client);
|
||||
|
||||
void cancelSynchronization(
|
||||
ResourceSynchronization* sync,
|
||||
ResourceSyncClient* client);
|
||||
|
||||
std::vector<std::shared_ptr<ResourceSynchronization>>
|
||||
finishedSynchronizations(ResourceSyncClient* client);
|
||||
|
||||
private:
|
||||
std::map<std::shared_ptr<ResourceSynchronization>,
|
||||
std::shared_ptr<ResourceSyncClient>> _origin;
|
||||
std::unordered_map<ResourceSynchronization*, ResourceSyncClient*> _clientMap;
|
||||
|
||||
std::unordered_map<ResourceSynchronization*, std::shared_ptr<ResourceSynchronization>>
|
||||
_managedSynchronizations;
|
||||
|
||||
std::unordered_map<ResourceSyncClient*, std::vector<ResourceSynchronization*>>
|
||||
_finishedSynchronizations;
|
||||
|
||||
ConcurrentJobManager<SynchronizationProduct> _jobManager;
|
||||
};
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user