| 78 | } |
| 79 | |
| 80 | float ResourceManager::get_resource_retrieval_progress(const NetworkingObjects::NetObjID& id) { |
| 81 | auto resourceClientID = resourcesBeingRetrieved.find(id); |
| 82 | if(resourceClientID == resourcesBeingRetrieved.end()) |
| 83 | return 0.0f; |
| 84 | if(world.netServer) { |
| 85 | std::weak_ptr<NetServer::ClientData> clientIDToLookFor = resourceClientID->second; |
| 86 | if(clientIDToLookFor.expired()) { |
| 87 | resourcesBeingRetrieved.erase(resourceClientID); |
| 88 | return 0.0f; |
| 89 | } |
| 90 | auto progressBytes = clientIDToLookFor.lock()->get_progress_into_fragmented_message(RESOURCE_COMMAND_CHANNEL); |
| 91 | if(progressBytes.totalBytes == 0) |
| 92 | return 0.0f; |
| 93 | return static_cast<float>(progressBytes.downloadedBytes) / static_cast<float>(progressBytes.totalBytes); |
| 94 | } |
| 95 | else if(world.netClient) { |
| 96 | NetLibrary::DownloadProgress progressBytes = world.netClient->get_progress_into_fragmented_message(RESOURCE_COMMAND_CHANNEL); |
| 97 | if(progressBytes.totalBytes == 0) |
| 98 | return 0.0f; |
| 99 | return static_cast<float>(progressBytes.downloadedBytes) / static_cast<float>(progressBytes.totalBytes); |
| 100 | } |
| 101 | return 0.0f; |
| 102 | } |
| 103 | |
| 104 | void ResourceManager::update() { |
| 105 | for(auto& [k, v] : displays) |