Merge branch 'master' into feature/profiles

# Conflicts:
#	include/openspace/scene/assetloader.h
#	src/scene/assetloader.cpp
This commit is contained in:
Alexander Bock
2020-06-14 17:54:25 +02:00
117 changed files with 3952 additions and 2105 deletions

View File

@@ -28,6 +28,7 @@
#include <openspace/util/resourcesynchronization.h>
#include <openspace/util/synchronizationwatcher.h>
#include <memory>
#include <optional>
#include <string>
#include <vector>
@@ -37,7 +38,7 @@ class AssetLoader;
class Asset : public std::enable_shared_from_this<Asset> {
public:
enum class State : unsigned int {
enum class State {
Unloaded,
LoadingFailed,
Loaded,
@@ -48,8 +49,14 @@ public:
InitializationFailed
};
using StateChangeCallback = std::function<void(State)>;
using CallbackHandle = size_t;
struct MetaInformation {
std::string name;
std::string version;
std::string description;
std::string author;
std::string url;
std::string license;
};
/**
* Root asset constructor
@@ -69,10 +76,9 @@ public:
AssetLoader* loader() const;
State state() const;
void addSynchronization(std::shared_ptr<ResourceSynchronization> synchronization);
void addSynchronization(std::unique_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);
@@ -92,12 +98,6 @@ public:
* its own synchronizations and required assets' synchronizations could start.
*/
bool startSynchronizations();
bool hasSyncingOrResolvedParent() const;
bool isSynchronized() const;
bool isSyncingOrResolved() const;
bool cancelAllSynchronizations();
bool cancelUnwantedSynchronizations();
bool restartAllSynchronizations();
float requiredSynchronizationProgress() const;
float requestedSynchronizationProgress();
@@ -120,21 +120,16 @@ public:
void request(std::shared_ptr<Asset> child);
void unrequest(Asset* child);
const std::vector<std::shared_ptr<Asset>>& requestedAssets() const;
std::vector<std::shared_ptr<Asset>> requestingAssets() const;
const std::vector<std::shared_ptr<Asset>>& requiredAssets() const;
std::vector<std::shared_ptr<Asset>> requiringAssets() const;
std::vector<Asset*> requestedAssets() const;
std::vector<Asset*> requestingAssets() const;
std::vector<Asset*> requiredAssets() const;
std::vector<Asset*> requiringAssets() const;
std::vector<std::shared_ptr<const Asset>> requiredSubTreeAssets() const;
std::vector<std::shared_ptr<const Asset>> subTreeAssets() const;
std::vector<std::shared_ptr<Asset>> childAssets() const;
std::vector<std::shared_ptr<Asset>> parentAssets() const;
std::vector<const Asset*> subTreeAssets() const;
std::vector<Asset*> childAssets() const;
bool isRequired() const;
bool isRequested() const;
bool shouldBeInitialized() const;
std::string resolveLocalResource(std::string resourceName);
void setMetaInformation(MetaInformation metaInformation);
std::optional<MetaInformation> metaInformation() const;
private:
void setState(State state);
@@ -142,7 +137,14 @@ private:
void requiredAssetChangedState(Asset::State childState);
void requestedAssetChangedState(Asset* child, Asset::State childState);
bool isSynchronized() const;
bool isSyncingOrResolved() const;
bool isSyncResolveReady();
bool hasSyncingOrResolvedParent() const;
bool cancelAllSynchronizations();
bool cancelUnwantedSynchronizations();
std::vector<const Asset*> requiredSubTreeAssets() const;
std::atomic<State> _state;
AssetLoader* _loader;
@@ -157,6 +159,8 @@ private:
// Absolute path to asset file
std::string _assetPath;
std::optional<MetaInformation> _metaInformation;
// Required assets
std::vector<std::shared_ptr<Asset>> _requiredAssets;

View File

@@ -32,12 +32,9 @@ namespace openspace {
class AssetListener {
public:
virtual ~AssetListener() = default;
virtual void assetStateChanged(std::shared_ptr<Asset> asset, Asset::State state) = 0;
virtual void assetRequested(std::shared_ptr<Asset> parent,
std::shared_ptr<Asset> child) = 0;
virtual void assetUnrequested(std::shared_ptr<Asset> parent,
std::shared_ptr<Asset> child) = 0;
virtual void assetStateChanged(Asset* asset, Asset::State state) = 0;
virtual void assetRequested(Asset* parent, std::shared_ptr<Asset> child) = 0;
virtual void assetUnrequested(Asset* parent, std::shared_ptr<Asset> child) = 0;
};
} // namespace openspace

View File

@@ -50,15 +50,13 @@ int request(lua_State* state);
int exists(lua_State* state);
int localResource(lua_State* state);
int syncedResource(lua_State* state);
int noOperation(lua_State* state);
int exportAsset(lua_State* state);
} // namespace assetloader
class Asset;
class AssetListener;
class ResourceSynchronization;
class SynchronizationWatcher;
class AssetListener;
class AssetLoader {
public:
@@ -88,30 +86,26 @@ public:
void untrackAsset(Asset* asset);
/**
* Return the asset identified by the identifier,
* if the asset is tracked. Otherwise return nullptr.
*/
* Return the asset identified by the identifier,
* if the asset is tracked. Otherwise return nullptr.
*/
std::shared_ptr<Asset> has(const std::string& identifier) const;
/**
* Return the lua state
*/
ghoul::lua::LuaState* luaState();
/// Return the root asset
const Asset& rootAsset() const;
/// Return the root asset
Asset& rootAsset();
/**
* Return the root asset
* Return the asset root directory
*/
std::shared_ptr<Asset> rootAsset() const;
/**
* Return the asset root directory
*/
const std::string& assetRootDirectory() const;
/**
* Load an asset
*/
bool loadAsset(std::shared_ptr<Asset> asset);
bool loadAsset(Asset* asset);
/**
* Unload an asset
@@ -158,17 +152,17 @@ public:
/**
* Notify listeners about asset state change
*/
void assetStateChanged(std::shared_ptr<Asset> asset, Asset::State state);
void assetStateChanged(Asset* asset, Asset::State state);
/**
* Notify listeners about new requests
*/
void assetRequested(std::shared_ptr<Asset> parent, std::shared_ptr<Asset> child);
void assetRequested(Asset* parent, std::shared_ptr<Asset> child);
/**
* Notify listeners about removed requests
*/
void assetUnrequested(std::shared_ptr<Asset> parent, std::shared_ptr<Asset> child);
void assetUnrequested(Asset* parent, std::shared_ptr<Asset> child);
/**
* Retrieve a reference to vector list of all assets events, including require,
@@ -182,7 +176,6 @@ public:
void resetAssetEvents();
private:
std::shared_ptr<Asset> require(const std::string& identifier);
std::shared_ptr<Asset> request(const std::string& identifier);
void unrequest(const std::string& identifier);
void addToProfileTracking(std::string asset, Profile::AssetEventType type);
@@ -190,10 +183,10 @@ private:
void setUpAssetLuaTable(Asset* asset);
void tearDownAssetLuaTable(Asset* asset);
std::shared_ptr<Asset> getAsset(std::string name);
std::shared_ptr<Asset> getAsset(const std::string& name);
ghoul::filesystem::Directory currentDirectory() const;
void setCurrentAsset(std::shared_ptr<Asset> asset);
void setCurrentAsset(Asset* asset);
void addLuaDependencyTable(Asset* dependant, Asset* dependency);
// Lua functions
@@ -208,7 +201,7 @@ private:
int syncedResourceLua(Asset* asset);
int exportAssetLua(Asset* asset);
// Friend c closures (callable from lua, and maps to lua functions above)
// Friend C closures (callable from Lua, and maps to Lua functions above)
friend int assetloader::onInitialize(lua_State* state);
friend int assetloader::onDeinitialize(lua_State* state);
friend int assetloader::onInitializeDependency(lua_State* state);
@@ -222,7 +215,7 @@ private:
// Member variables
std::shared_ptr<Asset> _rootAsset;
std::shared_ptr<Asset> _currentAsset;
Asset* _currentAsset = nullptr;
std::unordered_map<std::string, std::weak_ptr<Asset>> _trackedAssets;
SynchronizationWatcher* _synchronizationWatcher;
std::string _assetRootDirectory;
@@ -231,14 +224,15 @@ private:
// State change listeners
std::vector<AssetListener*> _assetListeners;
// References to lua values
// References to Lua values
std::unordered_map<Asset*, std::vector<int>> _onInitializationFunctionRefs;
std::unordered_map<Asset*, std::vector<int>> _onDeinitializationFunctionRefs;
std::unordered_map<Asset*, std::map<Asset*, std::vector<int>>>
_onDependencyInitializationFunctionRefs;
std::unordered_map<Asset*, std::map<Asset*, std::vector<int>>>
_onDependencyDeinitializationFunctionRefs;
int _assetsTableRef;
int _assetsTableRef = 0;
std::vector<Profile::AssetEvent> _profileAssets;
};

View File

@@ -28,9 +28,12 @@
#include <openspace/scene/assetlistener.h>
#include <openspace/scene/profile.h>
#include <openspace/scene/assetloader.h>
#include <ghoul/lua/ghoul_lua.h>
#include <ghoul/lua/luastate.h>
#include <memory>
#include <vector>
#include <unordered_map>
#include <vector>
namespace openspace {
@@ -42,18 +45,14 @@ class SynchronizationWatcher;
/**
* 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.
* The asset manager interface is only concerned with "top level" assets, 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 : AssetListener {
public:
AssetManager(std::unique_ptr<AssetLoader> loader,
std::unique_ptr<SynchronizationWatcher> syncWatcher);
AssetManager(ghoul::lua::LuaState* state, std::string assetRootDirectory);
virtual ~AssetManager() = default;
@@ -62,13 +61,12 @@ public:
void add(const std::string& path);
void remove(const std::string& path);
void removeAll();
std::shared_ptr<Asset> rootAsset();
const Asset& rootAsset() const;
Asset& rootAsset();
void assetStateChanged(std::shared_ptr<Asset> asset, Asset::State state) override;
void assetRequested(std::shared_ptr<Asset> parent,
std::shared_ptr<Asset> child) override;
void assetUnrequested(std::shared_ptr<Asset> parent,
std::shared_ptr<Asset> child) override;
void assetStateChanged(Asset* asset, Asset::State state) override;
void assetRequested(Asset* parent, std::shared_ptr<Asset> child) override;
void assetUnrequested(Asset* parent, std::shared_ptr<Asset> child) override;
bool update();
const std::vector<Profile::AssetEvent>& assetEvents() const;
@@ -80,8 +78,8 @@ private:
std::mutex _pendingInitializationsMutex;
std::vector<std::shared_ptr<Asset>> _pendingInitializations;
std::unique_ptr<SynchronizationWatcher> _synchronizationWatcher;
std::unique_ptr<AssetLoader> _assetLoader;
SynchronizationWatcher _synchronizationWatcher;
AssetLoader _assetLoader;
};
} // namespace openspace

View File

@@ -28,7 +28,6 @@
#include <openspace/interaction/navigationhandler.h>
#include <openspace/scene/profilefile.h>
#include <openspace/scene/scenegraphnode.h>
#include <openspace/scene/scenelicense.h>
#include <ghoul/misc/easing.h>
#include <ghoul/misc/exception.h>
#include <mutex>

View File

@@ -28,7 +28,6 @@
#include <openspace/properties/propertyowner.h>
#include <openspace/scene/scenegraphnode.h>
#include <openspace/scene/scenelicense.h>
#include <ghoul/misc/easing.h>
#include <ghoul/misc/exception.h>
#include <mutex>
@@ -134,8 +133,6 @@ public:
*/
void unregisterNode(SceneGraphNode* node);
void addSceneLicense(SceneLicense license);
/**
* Mark the node registry as dirty
*/
@@ -146,14 +143,6 @@ public:
*/
const std::vector<SceneGraphNode*>& allSceneGraphNodes() const;
/**
* Generate JSON about the license information for the scenegraph nodes that are
* contained in this scene
* \param path The file path that will contain the documentation about the licenses
* used in this scene
*/
std::string generateSceneLicenseDocumentationJson();
/**
* Returns a map from identifier to scene graph node.
*/
@@ -261,8 +250,6 @@ private:
std::vector<InterestingTime> _interestingTimes;
std::vector<SceneLicense> _licenses;
std::mutex _programUpdateLock;
std::set<ghoul::opengl::ProgramObject*> _programsToUpdate;
std::vector<std::unique_ptr<ghoul::opengl::ProgramObject>> _programs;

View File

@@ -1,56 +0,0 @@
/*****************************************************************************************
* *
* OpenSpace *
* *
* Copyright (c) 2014-2020 *
* *
* 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___SCENELICENSE___H__
#define __OPENSPACE_CORE___SCENELICENSE___H__
#include <string>
#include <vector>
namespace ghoul { class Dictionary; }
namespace openspace {
namespace documentation { struct Documentation; }
struct SceneLicense {
// module must not be empty
SceneLicense(const ghoul::Dictionary& dictionary, std::string m);
std::string module;
std::string name;
std::string attribution;
std::string url;
std::string licenseText;
static documentation::Documentation Documentation();
};
void writeSceneLicenseDocumentation(const std::vector<SceneLicense>& licenses,
const std::string& file, const std::string& type);
} // namespace openspace
#endif // __OPENSPACE_CORE___SCENELICENSE___H__

View File

@@ -31,15 +31,10 @@
namespace openspace {
struct SceneLicense;
class SceneLicenseWriter : public DocumentationGenerator {
public:
SceneLicenseWriter(std::vector<SceneLicense> licenses);
SceneLicenseWriter();
std::string generateJson() const override;
private:
const std::vector<SceneLicense>& _licenses;
};
} // namespace openspace

View File

@@ -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);

View File

@@ -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
@@ -69,7 +63,6 @@ public:
void notify();
private:
WatchHandle generateWatchHandle();
std::mutex _mutex;
std::unordered_map<WatchHandle, WatchData> _watchedSyncs;
std::vector<NotificationData> _pendingNotifications;