mirror of
https://github.com/OpenSpace/OpenSpace.git
synced 2026-05-05 02:20:11 -05:00
Start on asset gui
This commit is contained in:
@@ -1,2 +1,3 @@
|
||||
asset.import('keybindings')
|
||||
asset.import('solarsystem')
|
||||
asset.import('missions/newhorizons/spice/spice')
|
||||
@@ -58,9 +58,12 @@ public:
|
||||
InitializationFailed
|
||||
};
|
||||
|
||||
struct ManagedAsset {
|
||||
std::shared_ptr<Asset> asset;
|
||||
AssetState state;
|
||||
};
|
||||
|
||||
bool update();
|
||||
|
||||
|
||||
std::shared_ptr<Asset> 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<std::shared_ptr<Asset>> allAssets();
|
||||
std::vector<std::shared_ptr<Asset>> loadedAssets();
|
||||
scripting::LuaLibrary luaLibrary();
|
||||
bool isDone();
|
||||
private:
|
||||
std::shared_ptr<Asset> tryLoadAsset(const std::string& path);
|
||||
bool tryInitializeAsset(Asset& asset);
|
||||
|
||||
|
||||
std::unordered_map<Asset*, ManagedAsset> _managedAssets;
|
||||
std::unordered_map<std::string, AssetState> _pendingStateChangeCommands;
|
||||
std::unordered_map<std::shared_ptr<Asset>, AssetState> _stateChangesInProgress;
|
||||
std::unordered_map<Asset*, AssetState> _currentStates;
|
||||
std::unordered_map<Asset*, AssetState> _stateChangesInProgress;
|
||||
|
||||
std::unordered_map<std::shared_ptr<Asset>, std::unordered_set<std::shared_ptr<Asset>>> _syncAncestors;
|
||||
std::unordered_map<Asset*, std::unordered_set<Asset*>> _syncAncestors;
|
||||
std::unique_ptr<AssetLoader> _assetLoader;
|
||||
std::unique_ptr<AssetSynchronizer> _assetSynchronizer;
|
||||
};
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -25,6 +25,7 @@
|
||||
#ifndef __OPENSPACE_MODULE_IMGUI___GUI___H__
|
||||
#define __OPENSPACE_MODULE_IMGUI___GUI___H__
|
||||
|
||||
#include <modules/imgui/include/guiassetcomponent.h>
|
||||
#include <modules/imgui/include/guicomponent.h>
|
||||
#include <modules/imgui/include/guifilepathcomponent.h>
|
||||
#include <modules/imgui/include/guiglobebrowsingcomponent.h>
|
||||
@@ -67,6 +68,7 @@ public:
|
||||
//protected:
|
||||
GuiHelpComponent _help;
|
||||
GuiFilePathComponent _filePath;
|
||||
GuiAssetComponent _asset;
|
||||
#ifdef GLOBEBROWSING_USE_GDAL
|
||||
GuiGlobeBrowsingComponent _globeBrowsing;
|
||||
#endif // GLOBEBROWSING_USE_GDAL
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -149,7 +149,7 @@ bool TorrentSynchronization::nTotalBytesIsKnown() {
|
||||
return false;
|
||||
}
|
||||
|
||||
void TorrentSynchronization::updateTorrentProgress(TorrentClient::Progress p) {
|
||||
void TorrentSynchronization::updateTorrentProgress(TorrentClient::Progress) {
|
||||
// TODO: implement this
|
||||
}
|
||||
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -629,13 +629,14 @@ void OpenSpaceEngine::loadSingleAsset(const std::string& assetPath) {
|
||||
showProgressbar = configurationManager().value<bool>(kProgress);
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
_loadingScreen = std::make_unique<LoadingScreen>(
|
||||
LoadingScreen::ShowMessage(showMessage),
|
||||
LoadingScreen::ShowNodeNames(showNodeNames),
|
||||
LoadingScreen::ShowProgressbar(showProgressbar)
|
||||
);
|
||||
|
||||
*/
|
||||
|
||||
_renderEngine->setGlobalBlackOutFactor(0.0);
|
||||
_renderEngine->startFading(1, 3.0);
|
||||
|
||||
|
||||
+34
-26
@@ -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<Asset> 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<Asset> 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<std::shared_ptr<Asset>> 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<std::shared_ptr<Asset>>& ancestors = it->second;
|
||||
std::unordered_set<Asset*>& 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<std::shared_ptr<Asset>> AssetManager::allAssets()
|
||||
{
|
||||
return std::vector<std::shared_ptr<Asset>>();
|
||||
std::vector<std::shared_ptr<Asset>> AssetManager::loadedAssets() {
|
||||
std::vector<std::shared_ptr<Asset>> assets;
|
||||
assets.reserve(_managedAssets.size());
|
||||
for (auto it : _managedAssets) {
|
||||
ManagedAsset& ma = it.second;
|
||||
assets.push_back(ma.asset);
|
||||
}
|
||||
return assets;
|
||||
}
|
||||
|
||||
scripting::LuaLibrary AssetManager::luaLibrary() {
|
||||
|
||||
@@ -79,7 +79,7 @@ void AssetSynchronizer::startSync(std::shared_ptr<Asset> asset) {
|
||||
}
|
||||
}
|
||||
|
||||
void AssetSynchroinier::cancelSync(Asset* asset) {
|
||||
void AssetSynchronizer::cancelSync(Asset* asset) {
|
||||
// Todo: cancel sync
|
||||
}
|
||||
/*
|
||||
|
||||
@@ -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() {
|
||||
|
||||
Reference in New Issue
Block a user