From 139db5b03b6b13c53bbff22d3c29260515979cf6 Mon Sep 17 00:00:00 2001 From: Green Sky Date: Mon, 5 Feb 2024 12:50:36 +0100 Subject: [PATCH] faster texture cache loading in low fps modes --- external/solanaceae_contact | 2 +- external/solanaceae_message3 | 2 +- external/solanaceae_util | 2 +- src/chat_gui4.cpp | 12 +++++++++--- src/chat_gui4.hpp | 2 +- src/main_screen.cpp | 8 +++++--- src/texture_cache.hpp | 10 ++++++++-- 7 files changed, 26 insertions(+), 12 deletions(-) diff --git a/external/solanaceae_contact b/external/solanaceae_contact index 2d73c72..9ca6ade 160000 --- a/external/solanaceae_contact +++ b/external/solanaceae_contact @@ -1 +1 @@ -Subproject commit 2d73c7272c3c254086fa067ccfdfb4072c20f7c9 +Subproject commit 9ca6adee4f6f01d83fd1f5ece5c4b84396079ccc diff --git a/external/solanaceae_message3 b/external/solanaceae_message3 index 20af7dd..a1f5add 160000 --- a/external/solanaceae_message3 +++ b/external/solanaceae_message3 @@ -1 +1 @@ -Subproject commit 20af7dd705fe1be68f7678292125620d48aa278b +Subproject commit a1f5add8d347da2eb8acb812cd6dbcb36a46778d diff --git a/external/solanaceae_util b/external/solanaceae_util index 390b123..d304d71 160000 --- a/external/solanaceae_util +++ b/external/solanaceae_util @@ -1 +1 @@ -Subproject commit 390b123fb7380e5da30954d1b0a337208407f40d +Subproject commit d304d719e9b7c3c40d32fc45993f0ccfd34c556e diff --git a/src/chat_gui4.cpp b/src/chat_gui4.cpp index c91783a..7e00d4c 100644 --- a/src/chat_gui4.cpp +++ b/src/chat_gui4.cpp @@ -136,7 +136,7 @@ ChatGui4::~ChatGui4(void) { //} } -void ChatGui4::render(float time_delta) { +float ChatGui4::render(float time_delta) { if (!_cr.storage().empty()) { // handle force-reloads for avatars std::vector to_purge; _cr.view().each([&to_purge](const Contact3 c) { @@ -627,8 +627,14 @@ void ChatGui4::render(float time_delta) { } ImGui::End(); - _contact_tc.workLoadQueue(); - _msg_tc.workLoadQueue(); + bool unfinished_work_queue = _contact_tc.workLoadQueue(); + unfinished_work_queue = unfinished_work_queue || _msg_tc.workLoadQueue(); + + if (unfinished_work_queue) { + return 0.1f; // so we can get images loaded faster + } else { + return 1.f; // TODO: higher min fps? + } } void ChatGui4::sendFilePath(const char* file_path) { diff --git a/src/chat_gui4.hpp b/src/chat_gui4.hpp index 8cb355d..d7410a4 100644 --- a/src/chat_gui4.hpp +++ b/src/chat_gui4.hpp @@ -57,7 +57,7 @@ class ChatGui4 { ~ChatGui4(void); public: - void render(float time_delta); + float render(float time_delta); public: bool any_unread {false}; diff --git a/src/main_screen.cpp b/src/main_screen.cpp index ad1cbff..7821cd8 100644 --- a/src/main_screen.cpp +++ b/src/main_screen.cpp @@ -168,7 +168,7 @@ Screen* MainScreen::render(float time_delta, bool&) { const float pm_interval = pm.render(time_delta); // render - cg.render(time_delta); // render + const float cg_interval = cg.render(time_delta); // render sw.render(); // render tuiu.render(); // render tdch.render(); // render @@ -217,6 +217,8 @@ Screen* MainScreen::render(float time_delta, bool&) { ImGui::ShowDemoWindow(); } + _render_interval = std::min(pm_interval, cg_interval); + if ( _fps_perf_mode > 1 // TODO: magic ) { @@ -228,9 +230,9 @@ Screen* MainScreen::render(float time_delta, bool&) { _window_hidden ) ) { - _render_interval = std::min(1.f/1.f, pm_interval); + _render_interval = std::min(1.f/1.f, _render_interval); } else { - _render_interval = std::min(1.f/60.f, pm_interval); + _render_interval = std::min(1.f/60.f, _render_interval); } _time_since_event += time_delta; diff --git a/src/texture_cache.hpp b/src/texture_cache.hpp index 4120820..0c35f3c 100644 --- a/src/texture_cache.hpp +++ b/src/texture_cache.hpp @@ -162,8 +162,10 @@ struct TextureCache { } } - void workLoadQueue(void) { - for (auto it = _to_load.begin(); it != _to_load.end(); it++) { + // returns true if there is still work queued up + bool workLoadQueue(void) { + auto it = _to_load.begin(); + for (; it != _to_load.end(); it++) { auto new_entry_opt = _l.load(_tu, *it); if (new_entry_opt.has_value()) { _cache.emplace(*it, new_entry_opt.value()); @@ -172,6 +174,10 @@ struct TextureCache { break; // end load from queue/onlyload 1 per update } } + + it++; + + return it != _to_load.end(); } };