diff --git a/include/openspace/scene/assetloader.h b/include/openspace/scene/assetloader.h index 6d5a9321ee..54ff73921d 100644 --- a/include/openspace/scene/assetloader.h +++ b/include/openspace/scene/assetloader.h @@ -155,7 +155,8 @@ public: void callOnDependencyDeinitialize(Asset* dependency, Asset* asset); /** - * Generate the absolute path for an asset specified as `path` relative to `baseDirectory` + * Generate the absolute path for an asset specified as `path` + * relative to `baseDirectory` */ std::string generateAssetPath(const std::string& baseDirectory, const std::string& path) const; diff --git a/include/openspace/util/resourcesynchronization.h b/include/openspace/util/resourcesynchronization.h index 623970565c..ec7c04ea55 100644 --- a/include/openspace/util/resourcesynchronization.h +++ b/include/openspace/util/resourcesynchronization.h @@ -61,7 +61,6 @@ public: const ghoul::Dictionary& dictionary); ResourceSynchronization(const ghoul::Dictionary& dictionary); - void configure(std::shared_ptr config); virtual ~ResourceSynchronization(); virtual std::string directory() = 0; virtual void start() = 0; diff --git a/modules/sync/syncs/torrentsynchronization.cpp b/modules/sync/syncs/torrentsynchronization.cpp index e1c7bdc02a..ebc3db3d05 100644 --- a/modules/sync/syncs/torrentsynchronization.cpp +++ b/modules/sync/syncs/torrentsynchronization.cpp @@ -91,7 +91,9 @@ documentation::Documentation TorrentSynchronization::Documentation() { std::string TorrentSynchronization::uniformResourceName() const { size_t begin = _magnetLink.find("=urn") + 1; size_t end = _magnetLink.find('&', begin); - std::string xs = _magnetLink.substr(begin, end == std::string::npos ? end : (end - begin)); + std::string xs = _magnetLink.substr(begin, end == std::string::npos ? + end : (end - begin)); + std::transform(xs.begin(), xs.end(), xs.begin(), [](char x) { if (x == ':') return '.'; return x; @@ -150,8 +152,8 @@ void TorrentSynchronization::cancel() { } void TorrentSynchronization::clear() { - // Todo: remove directory! cancel(); + // TODO: Remove all files from directory. } bool TorrentSynchronization::hasSyncFile() { diff --git a/src/scene/assetloader.cpp b/src/scene/assetloader.cpp index 0800cc46e6..663308a525 100644 --- a/src/scene/assetloader.cpp +++ b/src/scene/assetloader.cpp @@ -57,7 +57,7 @@ namespace { const char* AssetFileSuffix = "asset"; - bool isRelative(std::string path) { + bool isRelative(const std::string& path) { if (path.size() > 2) { if (path[0] == '.' && path[1] == '/') return true; } @@ -108,7 +108,7 @@ void AssetLoader::untrackAsset(Asset* asset) { void AssetLoader::setUpAssetLuaTable(Asset* asset) { /* Set up lua table: - AssetMeta + AssetInfo |- Exports (table) |- Asset | |- localResource @@ -126,21 +126,21 @@ void AssetLoader::setUpAssetLuaTable(Asset* asset) { |- onDeinitialize */ - // Push the global assets table to the lua stack. + // Push the global table of AssetInfos to the lua stack. lua_rawgeti(*_luaState, LUA_REGISTRYINDEX, _assetsTableRef); int globalTableIndex = lua_gettop(*_luaState); - - // Create meta table for the current asset. + // Create a AssetInfo table for the current asset. lua_newtable(*_luaState); - int assetMetaTableIndex = lua_gettop(*_luaState); + int assetInfoTableIndex = lua_gettop(*_luaState); - // Register empty exports table on current asset. + // Register empty Exports table for the current asset. // (string => exported object) lua_newtable(*_luaState); - lua_setfield(*_luaState, assetMetaTableIndex, ExportsTableName); + lua_setfield(*_luaState, assetInfoTableIndex, ExportsTableName); - // Create asset table + // Create Asset table + // (string => lua functions) lua_newtable(*_luaState); int assetTableIndex = lua_gettop(*_luaState); @@ -168,7 +168,6 @@ void AssetLoader::setUpAssetLuaTable(Asset* asset) { lua_pushcclosure(*_luaState, &assetloader::request, 1); lua_setfield(*_luaState, assetTableIndex, RequestFunctionName); - // Register export-dependency function // export(string key, any value) lua_pushlightuserdata(*_luaState, asset); @@ -187,20 +186,21 @@ void AssetLoader::setUpAssetLuaTable(Asset* asset) { lua_pushcclosure(*_luaState, &assetloader::onDeinitialize, 1); lua_setfield(*_luaState, assetTableIndex, OnDeinitializeFunctionName); - // Attach asset table to asset meta table - lua_setfield(*_luaState, assetMetaTableIndex, AssetTableName); + // Attach Asset table to AssetInfo table + lua_setfield(*_luaState, assetInfoTableIndex, AssetTableName); - // Register empty dependant table on asset metatable. + // Register empty dependant table on AssetInfo table. // (importer => dependant object) lua_newtable(*_luaState); - lua_setfield(*_luaState, assetMetaTableIndex, DependantsTableName); + lua_setfield(*_luaState, assetInfoTableIndex, DependantsTableName); - // Extend global asset table (pushed to the lua stack earlier) with this asset meta table + // Extend global asset info table (pushed to the lua stack earlier) + // with this AssetInfo table lua_setfield(*_luaState, globalTableIndex, asset->id().c_str()); } void AssetLoader::tearDownAssetLuaTable(Asset* asset) { - // Push the global assets table to the lua stack. + // Push the global table of AssetInfos to the lua stack. lua_rawgeti(*_luaState, LUA_REGISTRYINDEX, _assetsTableRef); int globalTableIndex = lua_gettop(*_luaState); @@ -288,9 +288,14 @@ std::shared_ptr AssetLoader::getAsset(std::string name) { } } - std::shared_ptr a = std::make_shared(this, _synchronizationWatcher, path); - trackAsset(a); - return a; + std::shared_ptr asset = std::make_shared( + this, + _synchronizationWatcher, + path + ); + + trackAsset(asset); + return asset; } int AssetLoader::onInitializeLua(Asset* asset) { @@ -398,7 +403,8 @@ void AssetLoader::callOnInitialize(Asset* asset) { lua_rawgeti(*_luaState, LUA_REGISTRYINDEX, init); if (lua_pcall(*_luaState, 0, 0, 0) != LUA_OK) { throw ghoul::lua::LuaRuntimeException( - "When initializing " + asset->assetFilePath() + ": " + luaL_checkstring(*_luaState, -1) + "When initializing " + asset->assetFilePath() + ": " + + luaL_checkstring(*_luaState, -1) ); } } @@ -410,7 +416,8 @@ void AssetLoader::callOnDeinitialize(Asset * asset) { lua_rawgeti(*_luaState, LUA_REGISTRYINDEX, *it); if (lua_pcall(*_luaState, 0, 0, 0) != LUA_OK) { throw ghoul::lua::LuaRuntimeException( - "When deinitializing " + asset->assetFilePath() + ": " + luaL_checkstring(*_luaState, -1) + "When deinitializing " + asset->assetFilePath() + ": " + + luaL_checkstring(*_luaState, -1) ); } } @@ -427,7 +434,8 @@ void AssetLoader::callOnDependencyInitialize(Asset* asset, Asset* dependant) { } } // Potential Todo: - // Call dependency->onInitialize with The asset table exported by the child asset as argument + // Call dependency->onInitialize with the asset table + // exported by the child asset as argument } void AssetLoader::callOnDependencyDeinitialize(Asset* asset, Asset* dependant) { @@ -619,17 +627,20 @@ void AssetLoader::assetStateChanged(std::shared_ptr asset, Asset::State s } } -void AssetLoader::assetRequested(std::shared_ptr parent, std::shared_ptr child) { +void AssetLoader::assetRequested(std::shared_ptr parent, + std::shared_ptr child) +{ for (auto& listener : _assetListeners) { listener->assetRequested(parent, child); } } -void AssetLoader::assetUnrequested(std::shared_ptr parent, std::shared_ptr child) { +void AssetLoader::assetUnrequested(std::shared_ptr parent, + std::shared_ptr child) +{ for (auto& listener : _assetListeners) { listener->assetUnrequested(parent, child); } } - }