From 001dea3a620f6f76882c5e6bacaae7b86ba39306 Mon Sep 17 00:00:00 2001 From: Emil Axelsson Date: Thu, 11 Jan 2018 09:39:51 +0100 Subject: [PATCH] Add resource synchronization percentage to loading screen --- include/openspace/rendering/loadingscreen.h | 3 ++- modules/sync/torrentclient.cpp | 4 +--- src/engine/openspaceengine.cpp | 13 ++++++++++--- src/rendering/loadingscreen.cpp | 18 +++++++++++++++--- src/scene/sceneinitializer.cpp | 11 +++++++---- 5 files changed, 35 insertions(+), 14 deletions(-) diff --git a/include/openspace/rendering/loadingscreen.h b/include/openspace/rendering/loadingscreen.h index 7b4ba69b2b..e156ec6f69 100644 --- a/include/openspace/rendering/loadingscreen.h +++ b/include/openspace/rendering/loadingscreen.h @@ -84,7 +84,7 @@ public: Failed }; - void updateItem(const std::string& itemName, ItemStatus newStatus); + void updateItem(const std::string& itemName, ItemStatus newStatus, float progress); private: bool _showMessage; @@ -124,6 +124,7 @@ private: struct Item { std::string name; ItemStatus status; + float progress; bool hasLocation; glm::vec2 ll; diff --git a/modules/sync/torrentclient.cpp b/modules/sync/torrentclient.cpp index 8764bd58e5..f81260c4b7 100644 --- a/modules/sync/torrentclient.cpp +++ b/modules/sync/torrentclient.cpp @@ -207,9 +207,7 @@ void TorrentClient::notify(TorrentId id) { TorrentProgress progress; - progress.finished = status.state == libtorrent::torrent_status::state_t::finished || - status.state == libtorrent::torrent_status::state_t::seeding; - + progress.finished = status.is_finished; progress.nTotalBytesKnown = status.total_wanted > 0; progress.nTotalBytes = status.total_wanted; progress.nDownloadedBytes = status.total_wanted_done; diff --git a/src/engine/openspaceengine.cpp b/src/engine/openspaceengine.cpp index ecb973aec3..eed8aab633 100644 --- a/src/engine/openspaceengine.cpp +++ b/src/engine/openspaceengine.cpp @@ -705,7 +705,8 @@ void OpenSpaceEngine::loadSingleAsset(const std::string& assetPath) { resourceSyncs.insert(s); _loadingScreen->updateItem( s->name(), - LoadingScreen::ItemStatus::Started + LoadingScreen::ItemStatus::Started, + s->progress() ); } } @@ -721,13 +722,19 @@ void OpenSpaceEngine::loadSingleAsset(const std::string& assetPath) { auto it = resourceSyncs.begin(); while (it != resourceSyncs.end()) { if ((*it)->state() == ResourceSynchronization::State::Syncing) { - ++it; loading = true; + _loadingScreen->updateItem( + (*it)->name(), + LoadingScreen::ItemStatus::Started, + (*it)->progress() + ); + ++it; } else { _loadingScreen->tickItem(); _loadingScreen->updateItem( (*it)->name(), - LoadingScreen::ItemStatus::Finished + LoadingScreen::ItemStatus::Finished, + 1.0f ); it = resourceSyncs.erase(it); } diff --git a/src/rendering/loadingscreen.cpp b/src/rendering/loadingscreen.cpp index e710be8bd9..7eb4b43065 100644 --- a/src/rendering/loadingscreen.cpp +++ b/src/rendering/loadingscreen.cpp @@ -480,7 +480,7 @@ void LoadingScreen::render() { FR::BoundingBoxInformation b = renderer.boundingBox( *_itemFont, "%s", - item.name.c_str() + (item.name + " 100%").c_str() ); // The maximum count is in here since we can't control the amount of @@ -593,12 +593,19 @@ void LoadingScreen::render() { } #endif // LOADINGSCREEN_DEBUGGING + std::string text = item.name; + if (item.status == ItemStatus::Started && item.progress > 0) { + text += " " + + std::to_string(static_cast(std::round(item.progress * 100))) + + "%"; + } + renderer.render( *_itemFont, item.ll, color, "%s", - item.name.c_str() + text.c_str() ); } @@ -669,7 +676,10 @@ void LoadingScreen::setPhase(Phase phase) { _iProgress = 0; } -void LoadingScreen::updateItem(const std::string& itemName, ItemStatus newStatus) { +void LoadingScreen::updateItem(const std::string& itemName, + ItemStatus newStatus, + float newProgress) +{ if (!_showNodeNames) { // If we don't want to show the node names, we can disable the updating which // also would create any of the text information @@ -686,6 +696,7 @@ void LoadingScreen::updateItem(const std::string& itemName, ItemStatus newStatus ); if (it != _items.end()) { it->status = newStatus; + it->progress = newProgress; if (newStatus == ItemStatus::Finished) { it->finishedTime = std::chrono::system_clock::now(); } @@ -700,6 +711,7 @@ void LoadingScreen::updateItem(const std::string& itemName, ItemStatus newStatus _items.push_back({ itemName, ItemStatus::Started, + newProgress, false, #ifdef LOADINGSCREEN_DEBUGGING false, diff --git a/src/scene/sceneinitializer.cpp b/src/scene/sceneinitializer.cpp index 20eaee8ea2..15be7e731a 100644 --- a/src/scene/sceneinitializer.cpp +++ b/src/scene/sceneinitializer.cpp @@ -55,7 +55,8 @@ void MultiThreadedSceneInitializer::initializeNode(SceneGraphNode* node) { loadingScreen.updateItem( node->name(), - LoadingScreen::ItemStatus::Initializing + LoadingScreen::ItemStatus::Initializing, + 1.f ); node->initialize(); @@ -65,15 +66,17 @@ void MultiThreadedSceneInitializer::initializeNode(SceneGraphNode* node) { loadingScreen.updateItem( node->name(), - LoadingScreen::ItemStatus::Finished + LoadingScreen::ItemStatus::Finished, + 1.f ); }; LoadingScreen& loadingScreen = OsEng.loadingScreen(); loadingScreen.setItemNumber(loadingScreen.itemNumber() + 1); loadingScreen.updateItem( - node->name(), - LoadingScreen::ItemStatus::Started + node->name(), + LoadingScreen::ItemStatus::Started, + 0.0f ); std::lock_guard g(_mutex);