Clients can now see download progress of large resources
This commit is contained in:
parent
2a213028c0
commit
3b12f630f8
11 changed files with 87 additions and 30 deletions
|
|
@ -93,6 +93,13 @@ void NetClient::parse_received_messages() {
|
|||
}
|
||||
}
|
||||
|
||||
std::pair<uint64_t, uint64_t> NetClient::get_progress_into_fragmented_message(const std::string& channel) {
|
||||
auto& m = pfm[channel];
|
||||
if(m.partialFragmentMessage.empty())
|
||||
return {0, 0};
|
||||
return {m.partialFragmentMessageLoc, m.partialFragmentMessage.size()};
|
||||
}
|
||||
|
||||
void NetClient::send_queued_messages() {
|
||||
for(auto& [channelName, messageQueue] : messageQueues) {
|
||||
bool addMessageOrder = NetLibrary::is_ordered_channel(channelName);
|
||||
|
|
|
|||
|
|
@ -37,6 +37,7 @@ class NetClient : public std::enable_shared_from_this<NetClient> {
|
|||
void update();
|
||||
void add_recv_callback(MessageCommandType commandID, const NetClientRecvCallback& callback);
|
||||
bool is_disconnected();
|
||||
std::pair<uint64_t, uint64_t> get_progress_into_fragmented_message(const std::string& channel);
|
||||
|
||||
private:
|
||||
std::string localID;
|
||||
|
|
|
|||
|
|
@ -1,4 +1,5 @@
|
|||
#include "ConnectionManager.hpp"
|
||||
#include "Helpers/Networking/NetLibrary.hpp"
|
||||
#include "Server/CommandList.hpp"
|
||||
#include <chrono>
|
||||
|
||||
|
|
@ -38,3 +39,10 @@ bool ConnectionManager::is_client_disconnected() {
|
|||
bool ConnectionManager::is_host_disconnected() {
|
||||
return localServer && localServer->netServer->is_disconnected();
|
||||
}
|
||||
|
||||
std::pair<uint64_t, uint64_t> ConnectionManager::client_get_resource_retrieval_progress() {
|
||||
if(client)
|
||||
return client->get_progress_into_fragmented_message(RESOURCE_COMMAND_CHANNEL);
|
||||
else
|
||||
return {0, 0};
|
||||
}
|
||||
|
|
|
|||
|
|
@ -14,6 +14,7 @@ class ConnectionManager {
|
|||
}
|
||||
bool is_client_disconnected();
|
||||
bool is_host_disconnected();
|
||||
std::pair<uint64_t, uint64_t> client_get_resource_retrieval_progress();
|
||||
private:
|
||||
std::shared_ptr<NetClient> client;
|
||||
std::unique_ptr<MainServer> localServer;
|
||||
|
|
|
|||
|
|
@ -5,6 +5,8 @@
|
|||
#include "../SharedTypes.hpp"
|
||||
#include "../World.hpp"
|
||||
|
||||
#include "../MainProgram.hpp"
|
||||
|
||||
#ifndef IS_SERVER
|
||||
#include <include/core/SkSamplingOptions.h>
|
||||
#include "../DrawCollision.hpp"
|
||||
|
|
@ -54,6 +56,23 @@ void DrawImage::update_from_delayed_ptr(const std::shared_ptr<DrawComponent>& de
|
|||
d = newPtr->d;
|
||||
}
|
||||
|
||||
void DrawImage::draw_download_progress_bar(SkCanvas* canvas, const DrawData& drawData, float progress) {
|
||||
if(progress == 0.0f)
|
||||
return;
|
||||
canvas->save();
|
||||
canvas_do_calculated_transform(canvas);
|
||||
SkPaint p;
|
||||
p.setStroke(true);
|
||||
p.setStrokeWidth(10.0f);
|
||||
p.setStrokeCap(SkPaint::kRound_Cap);
|
||||
p.setColor4f(drawData.main->toolbar.io->theme->fillColor5);
|
||||
Vector2f center = (d.p1 + d.p2) * 0.5f;
|
||||
|
||||
const float DOWNLOAD_ARC_RADIUS = 50.0f;
|
||||
canvas->drawArc(SkRect::MakeLTRB(center.x() - DOWNLOAD_ARC_RADIUS, center.y() - DOWNLOAD_ARC_RADIUS, center.x() + DOWNLOAD_ARC_RADIUS, center.y() + DOWNLOAD_ARC_RADIUS), 0.0f, progress * 360.0f, false, p);
|
||||
canvas->restore();
|
||||
}
|
||||
|
||||
void DrawImage::draw(SkCanvas* canvas, const DrawData& drawData) {
|
||||
if(drawSetupData.shouldDraw) {
|
||||
canvas->save();
|
||||
|
|
|
|||
|
|
@ -15,6 +15,8 @@ class DrawImage : public DrawComponent {
|
|||
virtual void get_used_resources(std::unordered_set<ServerClientID>& v) const override;
|
||||
virtual void remap_resource_ids(std::unordered_map<ServerClientID, ServerClientID>& newIDs) override;
|
||||
|
||||
void draw_download_progress_bar(SkCanvas* canvas, const DrawData& drawData, float progress);
|
||||
|
||||
// User input data
|
||||
struct Data {
|
||||
Vector2f p1;
|
||||
|
|
|
|||
|
|
@ -707,26 +707,6 @@ void DrawingProgram::draw(SkCanvas* canvas, const DrawData& drawData) {
|
|||
}
|
||||
}
|
||||
else {
|
||||
if(!drawData.main->takingScreenshot) {
|
||||
for(auto& droppedDownFile : droppedDownloadingFiles) {
|
||||
if(droppedDownFile.comp->obj->collabListInfo.lock()) {
|
||||
canvas->save();
|
||||
auto img = std::static_pointer_cast<DrawImage>(droppedDownFile.comp->obj);
|
||||
img->canvas_do_calculated_transform(canvas);
|
||||
SkPaint p;
|
||||
p.setStroke(true);
|
||||
p.setStrokeWidth(10.0f);
|
||||
p.setStrokeCap(SkPaint::kRound_Cap);
|
||||
p.setColor4f(drawData.main->toolbar.io->theme->fillColor5);
|
||||
Vector2f center = (img->d.p1 + img->d.p2) * 0.5f;
|
||||
|
||||
const float DOWNLOAD_ARC_RADIUS = 50.0f;
|
||||
canvas->drawArc(SkRect::MakeLTRB(center.x() - DOWNLOAD_ARC_RADIUS, center.y() - DOWNLOAD_ARC_RADIUS, center.x() + DOWNLOAD_ARC_RADIUS, center.y() + DOWNLOAD_ARC_RADIUS), 0.0f, droppedDownFile.downData->progress * 360.0f, false, p);
|
||||
canvas->restore();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
canvas->saveLayer(nullptr, nullptr);
|
||||
canvas->clear(SkColor4f{0.0f, 0.0f, 0.0f, 0.0f});
|
||||
compCache.refresh_all_draw_cache(drawData);
|
||||
|
|
@ -735,6 +715,22 @@ void DrawingProgram::draw(SkCanvas* canvas, const DrawData& drawData) {
|
|||
selection.draw_components(canvas, drawData);
|
||||
canvas->restore();
|
||||
canvas->restore();
|
||||
|
||||
if(!drawData.main->takingScreenshot) {
|
||||
for(auto& droppedDownFile : droppedDownloadingFiles) {
|
||||
if(droppedDownFile.comp->obj->collabListInfo.lock())
|
||||
std::static_pointer_cast<DrawImage>(droppedDownFile.comp->obj)->draw_download_progress_bar(canvas, drawData, droppedDownFile.downData->progress);
|
||||
}
|
||||
|
||||
for(auto& c : updateableComponents) {
|
||||
if(c->get_type() == DRAWCOMPONENT_IMAGE) {
|
||||
auto img = std::static_pointer_cast<DrawImage>(c);
|
||||
if(img->d.imageID == drawData.main->world->rMan.get_resource_being_retrieved() && img->d.imageID != ServerClientID{0, 0})
|
||||
img->draw_download_progress_bar(canvas, drawData, drawData.main->world->rMan.get_resource_retrieval_progress());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
selection.draw_gui(canvas, drawData);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -18,12 +18,26 @@ ResourceManager::ResourceManager(World& initWorld):
|
|||
{}
|
||||
|
||||
void ResourceManager::init_client_callbacks() {
|
||||
world.con.client_add_recv_callback(CLIENT_NEW_RESOURCE, [&](cereal::PortableBinaryInputArchive& message) {
|
||||
ServerClientID resourceID;
|
||||
message(resourceID);
|
||||
message(resources[resourceID]);
|
||||
std::cout << "Received new resource: " << resourceID.first << " " << resourceID.second << " " << resources[resourceID].data->size() << std::endl;
|
||||
world.con.client_add_recv_callback(CLIENT_NEW_RESOURCE_ID, [&](cereal::PortableBinaryInputArchive& message) {
|
||||
message(resourceBeingRetrieved);
|
||||
});
|
||||
world.con.client_add_recv_callback(CLIENT_NEW_RESOURCE_DATA, [&](cereal::PortableBinaryInputArchive& message) {
|
||||
message(resources[resourceBeingRetrieved]);
|
||||
Logger::get().log("INFO", "Received new resource with id: " + std::to_string(resourceBeingRetrieved.first) + " " + std::to_string(resourceBeingRetrieved.second) + " of size " + std::to_string(resources[resourceBeingRetrieved].data->size()));
|
||||
resourceBeingRetrieved = {0, 0};
|
||||
});
|
||||
}
|
||||
|
||||
ServerClientID ResourceManager::get_resource_being_retrieved() {
|
||||
return resourceBeingRetrieved;
|
||||
}
|
||||
|
||||
float ResourceManager::get_resource_retrieval_progress() {
|
||||
std::pair<uint64_t, uint64_t> progressBytes = world.con.client_get_resource_retrieval_progress();
|
||||
if(progressBytes.second == 0)
|
||||
return 0.0f;
|
||||
else
|
||||
return static_cast<float>(progressBytes.first) / static_cast<float>(progressBytes.second);
|
||||
}
|
||||
|
||||
void ResourceManager::update() {
|
||||
|
|
|
|||
|
|
@ -44,9 +44,13 @@ class ResourceManager {
|
|||
std::optional<ResourceData> get_resource(const ServerClientID& id) const;
|
||||
ClientPortionID get_max_id(ServerPortionID serverID) const;
|
||||
const std::unordered_map<ServerClientID, ResourceData>& resource_list();
|
||||
ServerClientID get_resource_being_retrieved();
|
||||
float get_resource_retrieval_progress();
|
||||
|
||||
World& world;
|
||||
private:
|
||||
ServerClientID resourceBeingRetrieved = {0, 0};
|
||||
|
||||
std::unordered_map<ServerClientID, ResourceData> resources;
|
||||
std::unordered_map<ServerClientID, std::shared_ptr<ResourceDisplay>> displays;
|
||||
|
||||
|
|
|
|||
|
|
@ -37,7 +37,8 @@ enum ClientCommands : MessageCommandType {
|
|||
CLIENT_ERASE_MANY_COMPONENTS,
|
||||
CLIENT_UPDATE_COMPONENT,
|
||||
CLIENT_MOVE_MOUSE,
|
||||
CLIENT_NEW_RESOURCE,
|
||||
CLIENT_NEW_RESOURCE_ID,
|
||||
CLIENT_NEW_RESOURCE_DATA,
|
||||
CLIENT_CHAT_MESSAGE,
|
||||
CLIENT_NEW_BOOKMARK,
|
||||
CLIENT_REMOVE_BOOKMARK,
|
||||
|
|
|
|||
|
|
@ -63,8 +63,10 @@ MainServer::MainServer(World& initWorld, const std::string& serverLocalID):
|
|||
netServer->send_items_to_client(client, RELIABLE_COMMAND_CHANNEL, CLIENT_INITIAL_DATA, isDirectConnect, newClient.serverID, newClient.cursorColor);
|
||||
else {
|
||||
netServer->send_items_to_client(client, RELIABLE_COMMAND_CHANNEL, CLIENT_INITIAL_DATA, isDirectConnect, newClient.serverID, newClient.cursorColor, newClient.displayName, fileDisplayName, clients, data);
|
||||
for(auto& [id, rData] : data.resources)
|
||||
netServer->send_items_to_client(client, RESOURCE_COMMAND_CHANNEL, CLIENT_NEW_RESOURCE, id, rData);
|
||||
for(auto& [id, rData] : data.resources) {
|
||||
netServer->send_items_to_client(client, RESOURCE_COMMAND_CHANNEL, CLIENT_NEW_RESOURCE_ID, id);
|
||||
netServer->send_items_to_client(client, RESOURCE_COMMAND_CHANNEL, CLIENT_NEW_RESOURCE_DATA, rData);
|
||||
}
|
||||
}
|
||||
clients.emplace(newClient.serverID, newClient);
|
||||
});
|
||||
|
|
@ -190,7 +192,8 @@ MainServer::MainServer(World& initWorld, const std::string& serverLocalID):
|
|||
if(c.pendingResourceData.empty())
|
||||
c.pendingResourceID.emplace(newID);
|
||||
else {
|
||||
netServer->send_items_to_all_clients_except(client, RESOURCE_COMMAND_CHANNEL, CLIENT_NEW_RESOURCE, newID, c.pendingResourceData.front());
|
||||
netServer->send_items_to_all_clients_except(client, RESOURCE_COMMAND_CHANNEL, CLIENT_NEW_RESOURCE_ID, newID);
|
||||
netServer->send_items_to_all_clients_except(client, RESOURCE_COMMAND_CHANNEL, CLIENT_NEW_RESOURCE_DATA, c.pendingResourceData.front());
|
||||
data.resources.emplace(newID, c.pendingResourceData.front());
|
||||
c.pendingResourceData.pop();
|
||||
}
|
||||
|
|
@ -204,7 +207,8 @@ MainServer::MainServer(World& initWorld, const std::string& serverLocalID):
|
|||
c.pendingResourceData.back() = std::move(resourceData);
|
||||
}
|
||||
else {
|
||||
netServer->send_items_to_all_clients_except(client, RESOURCE_COMMAND_CHANNEL, CLIENT_NEW_RESOURCE, c.pendingResourceID.front(), resourceData);
|
||||
netServer->send_items_to_all_clients_except(client, RESOURCE_COMMAND_CHANNEL, CLIENT_NEW_RESOURCE_ID, c.pendingResourceID.front());
|
||||
netServer->send_items_to_all_clients_except(client, RESOURCE_COMMAND_CHANNEL, CLIENT_NEW_RESOURCE_DATA, resourceData);
|
||||
data.resources.emplace(c.pendingResourceID.front(), resourceData);
|
||||
c.pendingResourceID.pop();
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue