properly seperate tick and render

This commit is contained in:
Green Sky 2024-01-07 16:33:08 +01:00
parent a0ba0b39d8
commit e8234f2a4a
No known key found for this signature in database
6 changed files with 36 additions and 27 deletions

@ -1 +1 @@
Subproject commit 96bab0200f5b13671756abe7e3132ed78aaa2a40
Subproject commit 75e7c5e3c77ecd5e03ad0a1429e3a5fc6d067408

View File

@ -51,7 +51,7 @@ ChatGui4::ChatGui4(
) : _conf(conf), _rmm(rmm), _cr(cr), _tal(_cr), _contact_tc(_tal, tu), _msg_tc(_mil, tu), _sip(tu) {
}
void ChatGui4::render(void) {
void ChatGui4::render(float time_delta) {
if (!_cr.storage<Contact::Components::TagAvatarInvalidate>().empty()) { // handle force-reloads for avatars
std::vector<Contact3> to_purge;
_cr.view<Contact::Components::TagAvatarInvalidate>().each([&to_purge](const Contact3 c) {
@ -66,7 +66,7 @@ void ChatGui4::render(void) {
_msg_tc.update();
_fss.render();
_sip.render();
_sip.render(time_delta);
const ImGuiViewport* viewport = ImGui::GetMainViewport();
ImGui::SetNextWindowPos(viewport->WorkPos);

View File

@ -46,7 +46,7 @@ class ChatGui4 {
);
public:
void render(void);
void render(float time_delta);
public:
bool any_unread {false};

View File

@ -140,13 +140,7 @@ bool MainScreen::handleEvent(SDL_Event& e) {
return false;
}
Screen* MainScreen::render(float time_delta, bool& quit) {
quit = !tc.iterate();
tcm.iterate(time_delta);
tam.iterate();
Screen* MainScreen::render(float time_delta, bool&) {
// HACK: render the tomato main window first, with proper flags set.
// flags need to be set the first time begin() is called.
// and plugins are run before the main cg is run.
@ -164,15 +158,12 @@ Screen* MainScreen::render(float time_delta, bool& quit) {
ImGui::End();
}
pm.tick(time_delta);
tdch.tick(time_delta);
const float pm_interval = pm.render(time_delta); // render
mts.iterate();
cg.render();
sw.render();
tuiu.render();
tdch.render();
cg.render(time_delta); // render
sw.render(); // render
tuiu.render(); // render
tdch.render(); // render
{ // main window menubar injection
if (ImGui::Begin("tomato")) {
@ -189,7 +180,7 @@ Screen* MainScreen::render(float time_delta, bool& quit) {
const auto targets = "normal\0powersave\0";
ImGui::SetNextItemWidth(ImGui::GetFontSize()*10);
ImGui::Combo("compute mode", &_compute_perf_mode, targets, 4);
ImGui::SetItemTooltip("Limiting compute can slow down things filetransfers.");
ImGui::SetItemTooltip("Limiting compute can slow down things like filetransfers!");
}
ImGui::EndMenu();
@ -207,22 +198,40 @@ Screen* MainScreen::render(float time_delta, bool& quit) {
}
if (
_fps_perf_mode >= 1 || // TODO: magic
_fps_perf_mode > 1 // TODO: magic
) {
// powersave forces 250ms
_render_interval = 1.f/4.f;
} else if (
_fps_perf_mode == 1 || // TODO: magic
_window_hidden
) {
_render_interval = 1.f/4.f;
_render_interval = std::min<float>(1.f/4.f, pm_interval);
} else {
_render_interval = 1.f/60.f;
_render_interval = std::min<float>(1.f/60.f, pm_interval);
}
return nullptr;
}
Screen* MainScreen::tick(float time_delta, bool& quit) {
quit = !tc.iterate(); // compute
tcm.iterate(time_delta); // compute
tam.iterate(); // compute
const float pm_interval = pm.tick(time_delta); // compute
tdch.tick(time_delta); // compute
mts.iterate(); // compute
_min_tick_interval = std::max<float>(
std::min<float>(
tc.toxIterationInterval()/1000.f,
0.03f // HACK: 30ms upper bound, should be the same as tox but will change
pm_interval
//0.03f // HACK: 30ms upper bound, should be the same as tox but will change
),
(_compute_perf_mode == 0 ? 0.001f : 0.1f) // in powersave fix the lowerbound to 100ms
);

View File

@ -158,7 +158,7 @@ void SendImagePopup::sendMemory(
}
void SendImagePopup::render(void) {
void SendImagePopup::render(float time_delta) {
if (_open_popup) {
_open_popup = false;
ImGui::OpenPopup("send image##SendImagePopup");
@ -171,7 +171,7 @@ void SendImagePopup::render(void) {
preview_image.doAnimation(getNowMS());
time += 1.f/60.f; // TODO: actual delay
time += time_delta;
time = fmod(time, 1.f); // fract()
//ImGui::Text("send file....\n......");

View File

@ -71,6 +71,6 @@ struct SendImagePopup {
// from file_path
// call this each frame
void render(void);
void render(float time_delta);
};