mirror of
https://github.com/OpenSpace/OpenSpace.git
synced 2026-02-27 07:18:57 -06:00
Add resource synchronization percentage to loading screen
This commit is contained in:
@@ -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;
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
@@ -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<int>(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,
|
||||
|
||||
@@ -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<std::mutex> g(_mutex);
|
||||
|
||||
Reference in New Issue
Block a user