Resource syncing infrastructure

This commit is contained in:
Emil Axelsson
2017-10-31 17:46:48 +01:00
parent fba556b11f
commit 2313a275d3
18 changed files with 334 additions and 140 deletions
+8 -4
View File
@@ -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;
+1 -1
View File
@@ -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;
+22 -5
View File
@@ -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;
};