Skip to content

Commit

Permalink
fix updating causing the ui to lag out like hell
Browse files Browse the repository at this point in the history
  • Loading branch information
HJfod committed Nov 16, 2024
1 parent b9fb2f6 commit c94a533
Showing 1 changed file with 17 additions and 2 deletions.
19 changes: 17 additions & 2 deletions loader/src/server/DownloadManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ class ModDownload::Impl final {
DownloadStatus m_status;
EventListener<ServerRequest<ServerModVersion>> m_infoListener;
EventListener<web::WebTask> m_downloadListener;
unsigned int m_scheduledEventForFrame = 0;

Impl(
std::string const& id,
Expand Down Expand Up @@ -83,7 +84,14 @@ class ModDownload::Impl final {
}

if (!ModDownloadManager::get()->checkAutoConfirm()) {
ModDownloadEvent(m_id).post();
// Throttle events to only once per frame to not cause a
// billion UI updates at once
if (m_scheduledEventForFrame != CCDirector::get()->getTotalFrames()) {
m_scheduledEventForFrame = CCDirector::get()->getTotalFrames();
Loader::get()->queueInMainThread([id = m_id]() {
ModDownloadEvent(id).post();
});
}
}
});
auto fetchVersion = version.has_value() ? ModVersion(*version) : ModVersion(ModVersionLatest());
Expand Down Expand Up @@ -157,7 +165,14 @@ class ModDownload::Impl final {
else if (event->isCancelled()) {
m_status = DownloadStatusCancelled();
}
ModDownloadEvent(m_id).post();
// Throttle events to only once per frame to not cause a
// billion UI updates at once
if (m_scheduledEventForFrame != CCDirector::get()->getTotalFrames()) {
m_scheduledEventForFrame = CCDirector::get()->getTotalFrames();
Loader::get()->queueInMainThread([id = m_id]() {
ModDownloadEvent(id).post();
});
}
});

auto req = web::WebRequest();
Expand Down

0 comments on commit c94a533

Please sign in to comment.