diff --git a/assets/newhorizons.asset b/assets/newhorizons.asset index bb536d3d08..00dfdbc629 100644 --- a/assets/newhorizons.asset +++ b/assets/newhorizons.asset @@ -1,2 +1,3 @@ +asset.import('keybindings') asset.import('solarsystem') asset.import('missions/newhorizons/spice/spice') \ No newline at end of file diff --git a/include/openspace/scene/assetmanager.h b/include/openspace/scene/assetmanager.h index b7802f85bd..1fe3c28518 100644 --- a/include/openspace/scene/assetmanager.h +++ b/include/openspace/scene/assetmanager.h @@ -58,9 +58,12 @@ public: InitializationFailed }; + struct ManagedAsset { + std::shared_ptr asset; + AssetState state; + }; + bool update(); - - std::shared_ptr updateLoadState(std::string path, AssetState targetState); void updateSyncState(Asset* asset, AssetState targetState); void handleSyncStateChange(AssetSynchronizer::StateChange stateChange); @@ -68,18 +71,18 @@ public: void setTargetAssetState(const std::string& path, AssetState targetState); AssetState currentAssetState(Asset* asset); void clearAllTargetAssets(); - std::vector> allAssets(); + std::vector> loadedAssets(); scripting::LuaLibrary luaLibrary(); bool isDone(); private: std::shared_ptr tryLoadAsset(const std::string& path); bool tryInitializeAsset(Asset& asset); - + + std::unordered_map _managedAssets; std::unordered_map _pendingStateChangeCommands; - std::unordered_map, AssetState> _stateChangesInProgress; - std::unordered_map _currentStates; + std::unordered_map _stateChangesInProgress; - std::unordered_map, std::unordered_set>> _syncAncestors; + std::unordered_map> _syncAncestors; std::unique_ptr _assetLoader; std::unique_ptr _assetSynchronizer; }; diff --git a/modules/imgui/CMakeLists.txt b/modules/imgui/CMakeLists.txt index f08034e73d..edd765864a 100644 --- a/modules/imgui/CMakeLists.txt +++ b/modules/imgui/CMakeLists.txt @@ -28,6 +28,7 @@ include(${OPENSPACE_CMAKE_EXT_DIR}/module_definition.cmake) set(HEADER_FILES ${CMAKE_CURRENT_SOURCE_DIR}/include/gui.h + ${CMAKE_CURRENT_SOURCE_DIR}/include/guiassetcomponent.h ${CMAKE_CURRENT_SOURCE_DIR}/include/guicomponent.h ${CMAKE_CURRENT_SOURCE_DIR}/include/guifilepathcomponent.h ${CMAKE_CURRENT_SOURCE_DIR}/include/guiglobebrowsingcomponent.h @@ -45,6 +46,7 @@ source_group("Header Files" FILES ${HEADER_FILES}) set(SOURCE_FILES ${CMAKE_CURRENT_SOURCE_DIR}/src/gui.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/src/guiassetcomponent.cpp ${CMAKE_CURRENT_SOURCE_DIR}/src/guicomponent.cpp ${CMAKE_CURRENT_SOURCE_DIR}/src/guifilepathcomponent.cpp ${CMAKE_CURRENT_SOURCE_DIR}/src/guiglobebrowsingcomponent.cpp diff --git a/modules/imgui/include/gui.h b/modules/imgui/include/gui.h index 4981eda208..d5f9bcbe23 100644 --- a/modules/imgui/include/gui.h +++ b/modules/imgui/include/gui.h @@ -25,6 +25,7 @@ #ifndef __OPENSPACE_MODULE_IMGUI___GUI___H__ #define __OPENSPACE_MODULE_IMGUI___GUI___H__ +#include #include #include #include @@ -67,6 +68,7 @@ public: //protected: GuiHelpComponent _help; GuiFilePathComponent _filePath; + GuiAssetComponent _asset; #ifdef GLOBEBROWSING_USE_GDAL GuiGlobeBrowsingComponent _globeBrowsing; #endif // GLOBEBROWSING_USE_GDAL diff --git a/modules/imgui/src/gui.cpp b/modules/imgui/src/gui.cpp index 6db4244e94..4490f45e84 100644 --- a/modules/imgui/src/gui.cpp +++ b/modules/imgui/src/gui.cpp @@ -280,6 +280,7 @@ GUI::GUI() addPropertySubOwner(_globeBrowsing); #endif // GLOBEBROWSING_USE_GDAL addPropertySubOwner(_filePath); + addPropertySubOwner(_asset); addPropertySubOwner(_spaceTime); addPropertySubOwner(_mission); #ifdef OPENSPACE_MODULE_ISWA_ENABLED @@ -400,6 +401,7 @@ void GUI::initialize() { _featuredProperties.setHasRegularProperties(true); _virtualProperty.initialize(); _filePath.initialize(); + _asset.initialize(); #ifdef GLOBEBROWSING_USE_GDAL _globeBrowsing.initialize(); #endif // GLOBEBROWSING_USE_GDAL @@ -427,6 +429,7 @@ void GUI::deinitialize() { _screenSpaceProperty.deinitialize(); _virtualProperty.deinitialize(); _filePath.deinitialize(); + _asset.deinitialize(); #ifdef GLOBEBROWSING_USE_GDAL _globeBrowsing.deinitialize(); #endif // GLOBEBROWSING_USE_GDAL @@ -510,6 +513,7 @@ void GUI::initializeGL() { _globeBrowsing.initializeGL(); #endif // GLOBEBROWSING_USE_GDAL _filePath.initializeGL(); + _asset.initializeGL(); _parallel.initializeGL(); _mission.initializeGL(); #ifdef OPENSPACE_MODULE_ISWA_ENABLED @@ -546,6 +550,7 @@ void GUI::deinitializeGL() { _globeBrowsing.deinitializeGL(); #endif // GLOBEBROWSING_USE_GDAL _filePath.deinitializeGL(); + _asset.deinitializeGL(); _property.deinitializeGL(); } @@ -604,6 +609,9 @@ void GUI::endFrame() { if (_filePath.isEnabled()) { _filePath.render(); } + if (_asset.isEnabled()) { + _asset.render(); + } #ifdef GLOBEBROWSING_USE_GDAL if (_globeBrowsing.isEnabled()) { @@ -723,6 +731,10 @@ void GUI::render() { ImGui::Checkbox("File Paths", &filePath); _filePath.setEnabled(filePath); + bool asset = _asset.isEnabled(); + ImGui::Checkbox("Assets", &asset); + _asset.setEnabled(asset); + #ifdef GLOBEBROWSING_USE_GDAL bool globeBrowsing = _globeBrowsing.isEnabled(); ImGui::Checkbox("GlobeBrowsing", &globeBrowsing); diff --git a/modules/sync/syncs/torrentsynchronization.cpp b/modules/sync/syncs/torrentsynchronization.cpp index 73a8ca80fc..a11caa6717 100644 --- a/modules/sync/syncs/torrentsynchronization.cpp +++ b/modules/sync/syncs/torrentsynchronization.cpp @@ -149,7 +149,7 @@ bool TorrentSynchronization::nTotalBytesIsKnown() { return false; } -void TorrentSynchronization::updateTorrentProgress(TorrentClient::Progress p) { +void TorrentSynchronization::updateTorrentProgress(TorrentClient::Progress) { // TODO: implement this } diff --git a/modules/sync/torrentclient.cpp b/modules/sync/torrentclient.cpp index e1b20d2f43..9e6101d9b8 100644 --- a/modules/sync/torrentclient.cpp +++ b/modules/sync/torrentclient.cpp @@ -101,7 +101,7 @@ void TorrentClient::pollAlerts() { } } -size_t TorrentClient::addTorrentFile(std::string torrentFile, std::string destination, TorrentProgressCallback cb) { +size_t TorrentClient::addTorrentFile(std::string torrentFile, std::string destination, TorrentProgressCallback) { if (!_session) { LERROR("Torrent session not initialized when adding torrent"); return -1; diff --git a/src/engine/openspaceengine.cpp b/src/engine/openspaceengine.cpp index 123d28fb2b..051bfecf5b 100644 --- a/src/engine/openspaceengine.cpp +++ b/src/engine/openspaceengine.cpp @@ -629,13 +629,14 @@ void OpenSpaceEngine::loadSingleAsset(const std::string& assetPath) { showProgressbar = configurationManager().value(kProgress); } - +/* _loadingScreen = std::make_unique( LoadingScreen::ShowMessage(showMessage), LoadingScreen::ShowNodeNames(showNodeNames), LoadingScreen::ShowProgressbar(showProgressbar) ); - +*/ + _renderEngine->setGlobalBlackOutFactor(0.0); _renderEngine->startFading(1, 3.0); diff --git a/src/scene/assetmanager.cpp b/src/scene/assetmanager.cpp index 07e3a96529..83a8773239 100644 --- a/src/scene/assetmanager.cpp +++ b/src/scene/assetmanager.cpp @@ -60,9 +60,9 @@ bool AssetManager::update() { // Collect all assets for synchronization for (const auto& loadedAsset : loadedAssets) { const std::string& path = loadedAsset.first; + Asset* asset = loadedAsset.second.get(); const AssetState targetState = _pendingStateChangeCommands[path]; - - updateSyncState(path, targetState); + updateSyncState(asset, targetState); } // Collect assets that were resolved and rejected. @@ -87,17 +87,20 @@ std::shared_ptr AssetManager::updateLoadState(std::string path, AssetStat const bool isLoaded = asset != nullptr; if (isLoaded && !shouldBeLoaded) { - _currentStates.erase(asset.get()); + _managedAssets.erase(asset.get()); _assetLoader->unloadAsset(asset.get()); } else if (!isLoaded && shouldBeLoaded) { std::shared_ptr loadedAsset = tryLoadAsset(path); if (loadedAsset) { - _currentStates[loadedAsset.get()] = AssetState::Loaded; + _managedAssets[loadedAsset.get()] = ManagedAsset{ + loadedAsset, + AssetState::Loaded + }; return loadedAsset; } else { - _currentStates[loadedAsset.get()] = AssetState::LoadingFailed; + _managedAssets[loadedAsset.get()].state = AssetState::LoadingFailed; } } return nullptr; @@ -113,31 +116,31 @@ void AssetManager::updateSyncState(Asset* asset, AssetState targetState) { if (shouldSync) { std::vector> importedAssets = - loadedAsset.second->allAssets(); + asset->allAssets(); for (const auto& a : importedAssets) { _assetSynchronizer->startSync(a); - _syncAncestors[a].insert(loadedAsset.second); + _syncAncestors[a.get()].insert(asset); //_syncDependencies[loadedAsset.second].insert(a); } _stateChangesInProgress.emplace( - loadedAsset.second, - _pendingStateChangeCommands[loadedAsset.first] + asset, + _pendingStateChangeCommands[asset->assetFilePath()] ); } else { - _assetSynchronizer->cancelSync(a); + _assetSynchronizer->cancelSync(asset); // Todo: Also cancel syncing of dependendencies } } -void handleSyncStateChange(AssetSynchronizer::StateChange stateChange) { +void AssetManager::handleSyncStateChange(AssetSynchronizer::StateChange stateChange) { // Retrieve ancestors that were waiting for this asset to sync - const auto it = _syncAncestors.find(stateChange.asset); + const auto it = _syncAncestors.find(stateChange.asset.get()); if (it == _syncAncestors.end()) { - continue; // Should not happen. (No ancestor to this synchronization) + return; // Should not happen. (No ancestor to this synchronization) } - std::unordered_set>& ancestors = it->second; + std::unordered_set& ancestors = it->second; if (stateChange.state == AssetSynchronizer::SynchronizationState::Resolved) @@ -152,15 +155,15 @@ void handleSyncStateChange(AssetSynchronizer::StateChange stateChange) { _stateChangesInProgress.erase(ancestor); if (shouldInit) { if (tryInitializeAsset(*ancestor)) { - changedInititializations = true; - _currentStates[ancestor.get()] = AssetState::Initialized; + //changedInititializations = true; + _managedAssets[ancestor].state = AssetState::Initialized; } else { - _currentStates[ancestor.get()] = AssetState::InitializationFailed; + _managedAssets[ancestor].state = AssetState::InitializationFailed; } } else { - _currentStates[ancestor.get()] = AssetState::Synchronized; + _managedAssets[ancestor].state = AssetState::Synchronized; } } } @@ -170,11 +173,11 @@ void handleSyncStateChange(AssetSynchronizer::StateChange stateChange) { AssetSynchronizer::SynchronizationState::Rejected) { for (const auto& ancestor : ancestors) { - _currentStates[ancestor.get()] = AssetState::SynchronizationFailed; + _managedAssets[ancestor].state = AssetState::SynchronizationFailed; } } - _syncAncestors.erase(stateChange.asset); + _syncAncestors.erase(stateChange.asset.get()); } void AssetManager::setTargetAssetState(const std::string& path, AssetState targetState) { @@ -182,11 +185,11 @@ void AssetManager::setTargetAssetState(const std::string& path, AssetState targe } AssetManager::AssetState AssetManager::currentAssetState(Asset* asset) { - const auto it = _currentStates.find(asset); - if (it == _currentStates.end()) { + const auto it = _managedAssets.find(asset); + if (it == _managedAssets.end()) { return AssetManager::AssetState::Unloaded; } - return it->second; + return it->second.state; } void AssetManager::clearAllTargetAssets() { @@ -196,9 +199,14 @@ void AssetManager::clearAllTargetAssets() { } } -std::vector> AssetManager::allAssets() -{ - return std::vector>(); +std::vector> AssetManager::loadedAssets() { + std::vector> assets; + assets.reserve(_managedAssets.size()); + for (auto it : _managedAssets) { + ManagedAsset& ma = it.second; + assets.push_back(ma.asset); + } + return assets; } scripting::LuaLibrary AssetManager::luaLibrary() { diff --git a/src/scene/assetsynchronizer.cpp b/src/scene/assetsynchronizer.cpp index 1f52d48360..575c7397e6 100644 --- a/src/scene/assetsynchronizer.cpp +++ b/src/scene/assetsynchronizer.cpp @@ -79,7 +79,7 @@ void AssetSynchronizer::startSync(std::shared_ptr asset) { } } -void AssetSynchroinier::cancelSync(Asset* asset) { +void AssetSynchronizer::cancelSync(Asset* asset) { // Todo: cancel sync } /* diff --git a/src/util/httprequest.cpp b/src/util/httprequest.cpp index 91432b8678..ab01db2bfb 100644 --- a/src/util/httprequest.cpp +++ b/src/util/httprequest.cpp @@ -168,7 +168,10 @@ SyncHttpDownload::SyncHttpDownload(std::string url) {} void SyncHttpDownload::download(HttpRequest::RequestOptions opt) { - initDownload(); + if (!initDownload()) { + markAsFailed(); + return; + } _httpRequest.onData([this] (HttpRequest::Data d) { return handleData(d); }); @@ -298,6 +301,7 @@ bool HttpFileDownload::initDownload() { LERROR("Cannot open file " << destinationFile); return false; } + return true; } bool HttpFileDownload::deinitDownload() {