Cleanup AssetManager class

This commit is contained in:
Alexander Bock
2020-05-06 21:40:23 +02:00
parent 01f0a864dc
commit 340444ce0d
10 changed files with 60 additions and 61 deletions

View File

@@ -55,9 +55,9 @@ int exportAsset(lua_State* state);
} // namespace assetloader
class Asset;
class AssetListener;
class ResourceSynchronization;
class SynchronizationWatcher;
class AssetListener;
class AssetLoader {
public:
@@ -92,10 +92,11 @@ public:
*/
std::shared_ptr<Asset> has(const std::string& identifier) const;
/**
* Return the root asset
*/
std::shared_ptr<Asset> rootAsset() const;
/// Return the root asset
const Asset& rootAsset() const;
/// Return the root asset
Asset& rootAsset();
/**
* Return the asset root directory
@@ -190,7 +191,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);

View File

@@ -27,9 +27,12 @@
#include <openspace/scene/assetlistener.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 {
@@ -46,11 +49,9 @@ class SynchronizationWatcher;
* 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;
@@ -59,11 +60,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(Asset* asset, Asset::State state);
void assetRequested(Asset* parent, std::shared_ptr<Asset> child);
void assetUnrequested(Asset* parent, std::shared_ptr<Asset> child);
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();
scripting::LuaLibrary luaLibrary();
@@ -73,8 +75,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