mirror of
https://github.com/hrydgard/ppsspp.git
synced 2026-11-13 09:39:33 +01:00
Store: Show a rough speed indicator.
Some of the homebrew are a bit larger, it's nice to see a speed and not just the progress bar.
This commit is contained in:
1 parent
3379f33882
commit
2f08fb6583
7 files changed
+39
-7
No files matched your search
@@ -423,11 +423,11 @@ int Client::ReadResponseEntity(net::Buffer *readbuf, const std::vector<std::stri
|
||||
|
||||
if (!contentLength) {
|
||||
// No way to know how far along we are. Let's just not update the progress counter.
|
||||
if (!readbuf->ReadAllWithProgress(sock(), contentLength, nullptr, progress->cancelled))
|
||||
if (!readbuf->ReadAllWithProgress(sock(), contentLength, nullptr, &progress->kBps, progress->cancelled))
|
||||
return -1;
|
||||
} else {
|
||||
// Let's read in chunks, updating progress between each.
|
||||
if (!readbuf->ReadAllWithProgress(sock(), contentLength, &progress->progress, progress->cancelled))
|
||||
if (!readbuf->ReadAllWithProgress(sock(), contentLength, &progress->progress, &progress->kBps, progress->cancelled))
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
||||
@@ -48,6 +48,7 @@ struct RequestProgress {
|
||||
explicit RequestProgress(bool *c) : cancelled(c) {}
|
||||
|
||||
float progress = 0.0f;
|
||||
float kBps = 0.0f;
|
||||
bool *cancelled = nullptr;
|
||||
};
|
||||
|
||||
@@ -98,6 +99,7 @@ public:
|
||||
|
||||
// Returns 1.0 when done. That one value can be compared exactly - or just use Done().
|
||||
float Progress() const { return progress_.progress; }
|
||||
float SpeedKBps() const { return progress_.kBps; }
|
||||
|
||||
bool Done() const { return completed_; }
|
||||
bool Failed() const { return failed_; }
|
||||
|
||||
@@ -47,7 +47,7 @@ bool Buffer::FlushSocket(uintptr_t sock, double timeout, bool *cancelled) {
|
||||
return true;
|
||||
}
|
||||
|
||||
bool Buffer::ReadAllWithProgress(int fd, int knownSize, float *progress, bool *cancelled) {
|
||||
bool Buffer::ReadAllWithProgress(int fd, int knownSize, float *progress, float *kBps, bool *cancelled) {
|
||||
static constexpr float CANCEL_INTERVAL = 0.25f;
|
||||
std::vector<char> buf;
|
||||
// We're non-blocking and reading from an OS buffer, so try to read as much as we can at a time.
|
||||
@@ -59,6 +59,7 @@ bool Buffer::ReadAllWithProgress(int fd, int knownSize, float *progress, bool *c
|
||||
buf.resize(1024);
|
||||
}
|
||||
|
||||
double st = time_now_d();
|
||||
int total = 0;
|
||||
while (true) {
|
||||
bool ready = false;
|
||||
@@ -84,6 +85,8 @@ bool Buffer::ReadAllWithProgress(int fd, int knownSize, float *progress, bool *c
|
||||
total += retval;
|
||||
if (progress)
|
||||
*progress = (float)total / (float)knownSize;
|
||||
if (kBps)
|
||||
*kBps = (float)(total / (time_now_d() - st)) / 1024.0f;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -8,7 +8,7 @@ class Buffer : public ::Buffer {
|
||||
public:
|
||||
bool FlushSocket(uintptr_t sock, double timeout, bool *cancelled = nullptr);
|
||||
|
||||
bool ReadAllWithProgress(int fd, int knownSize, float *progress, bool *cancelled);
|
||||
bool ReadAllWithProgress(int fd, int knownSize, float *progress, float *kBps, bool *cancelled);
|
||||
|
||||
// < 0: error
|
||||
// >= 0: number of bytes read
|
||||
|
||||
Reference in new issue
Block a user