Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve `sendMap()` performance #392

Merged
Merged
Changes from 1 commit
Commits
File filter...
Filter file types
Jump to…
Jump to file or symbol
Failed to load files and symbols.

Always

Just for now

Prev

Minor improvements to NETgetDownloadProgress()

  • Loading branch information...
past-due committed Jun 17, 2019
commit 166a5178627624e03a9fc2d9112ef1ee4588a6ca
@@ -2047,18 +2047,18 @@ int NETrecvFile(NETQUEUE queue)
return 100; // file is nullbyte, so we are done.
}

int NETgetDownloadProgress(unsigned player)
unsigned NETgetDownloadProgress(unsigned player)
{
std::vector<WZFile> const &files = player == selectedPlayer ?
NetPlay.wzFiles : // Check our own download progress.
NetPlay.players[player].wzFiles; // Check their download progress (currently only works if we are the host).

int progress = 100;
uint32_t progress = 100;
for (WZFile const &file : files)
{
progress = std::min<unsigned>(progress, file.pos * 100 / std::max<unsigned>(file.size, 1));
progress = std::min<uint32_t>(progress, (uint32_t)((uint64_t)file.pos * 100 / (uint64_t)std::max<uint32_t>(file.size, 1)));
}
return progress;
return static_cast<unsigned>(progress);
}

static ssize_t readLobbyResponse(Socket *sock, unsigned int timeout)
@@ -281,7 +281,7 @@ void NETflush(); //

int NETsendFile(WZFile &file, unsigned player); ///< Send file chunk. Returns 100 when done.
int NETrecvFile(NETQUEUE queue); ///< Receive file chunk. Returns 100 when done.
int NETgetDownloadProgress(unsigned player); ///< Returns 100 when done.
unsigned NETgetDownloadProgress(unsigned player); ///< Returns 100 when done.

int NETclose(); // close current game
int NETshutdown(); // leave the game in play.
@@ -4356,13 +4356,13 @@ void displayPlayer(WIDGET *psWidget, UDWORD xOffset, UDWORD yOffset)

const int nameX = 32;

int downloadProgress = NETgetDownloadProgress(j);
unsigned downloadProgress = NETgetDownloadProgress(j);

drawBlueBox(x, y, psWidget->width(), psWidget->height());
if (downloadProgress != 100)
{
char progressString[MAX_STR_LENGTH];
ssprintf(progressString, j != selectedPlayer ? _("Sending Map: %d%% ") : _("Map: %d%% downloaded"), downloadProgress);
ssprintf(progressString, j != selectedPlayer ? _("Sending Map: %u%% ") : _("Map: %u%% downloaded"), downloadProgress);
cache.wzMainText.setText(progressString, font_regular);
cache.wzMainText.render(x + 5, y + 22, WZCOL_FORM_TEXT);
return;
ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.