2023-07-26 12:24:18 +02:00
|
|
|
#include "./main_screen.hpp"
|
2024-02-17 19:30:52 +01:00
|
|
|
|
2024-04-14 13:58:31 +02:00
|
|
|
#include <solanaceae/message3/nj/message_components_serializer.hpp>
|
2024-04-14 14:27:25 +02:00
|
|
|
#include <solanaceae/tox_messages/nj/tox_message_components_serializer.hpp>
|
2023-07-26 12:24:18 +02:00
|
|
|
|
2024-02-05 16:05:45 +01:00
|
|
|
#include <solanaceae/contact/components.hpp>
|
|
|
|
|
2023-07-26 12:24:18 +02:00
|
|
|
#include <imgui/imgui.h>
|
|
|
|
|
2023-07-26 20:09:57 +02:00
|
|
|
#include <SDL3/SDL.h>
|
|
|
|
|
2023-07-26 12:24:18 +02:00
|
|
|
#include <memory>
|
2024-02-03 15:00:32 +01:00
|
|
|
#include <cmath>
|
2023-07-26 12:24:18 +02:00
|
|
|
|
2024-04-21 14:17:50 +02:00
|
|
|
MainScreen::MainScreen(SDL_Renderer* renderer_, Theme& theme_, std::string save_path, std::string save_password, std::string new_username, std::vector<std::string> plugins) :
|
2023-07-26 20:09:57 +02:00
|
|
|
renderer(renderer_),
|
|
|
|
rmm(cr),
|
2024-04-14 13:58:31 +02:00
|
|
|
msnj{cr, {}, {}},
|
2023-07-29 20:51:32 +02:00
|
|
|
mts(rmm),
|
2023-08-28 15:33:36 +02:00
|
|
|
tc(save_path, save_password),
|
2023-11-13 15:14:30 +01:00
|
|
|
tpi(tc.getTox()),
|
2023-07-29 20:39:31 +02:00
|
|
|
ad(tc),
|
2023-07-26 20:09:57 +02:00
|
|
|
tcm(cr, tc, tc),
|
|
|
|
tmm(rmm, cr, tcm, tc, tc),
|
|
|
|
ttm(rmm, cr, tcm, tc, tc),
|
2024-02-02 20:26:50 +01:00
|
|
|
tffom(cr, rmm, tcm, tc, tc),
|
2024-04-21 14:17:50 +02:00
|
|
|
theme(theme_),
|
2023-08-02 19:24:51 +02:00
|
|
|
mmil(rmm),
|
2023-10-14 15:59:32 +02:00
|
|
|
tam(rmm, cr, conf),
|
2023-07-28 18:03:45 +02:00
|
|
|
sdlrtu(renderer_),
|
2024-02-05 16:05:45 +01:00
|
|
|
tal(cr),
|
|
|
|
contact_tc(tal, sdlrtu),
|
|
|
|
mil(),
|
|
|
|
msg_tc(mil, sdlrtu),
|
2024-04-21 14:17:50 +02:00
|
|
|
cg(conf, rmm, cr, sdlrtu, contact_tc, msg_tc, theme),
|
2023-10-20 21:40:45 +02:00
|
|
|
sw(conf),
|
2023-11-13 16:23:49 +01:00
|
|
|
tuiu(tc, conf),
|
|
|
|
tdch(tpi)
|
2023-07-26 20:09:57 +02:00
|
|
|
{
|
2023-07-26 12:55:50 +02:00
|
|
|
tel.subscribeAll(tc);
|
2024-04-14 13:58:31 +02:00
|
|
|
|
|
|
|
registerMessageComponents(msnj);
|
2024-04-14 14:27:25 +02:00
|
|
|
registerToxMessageComponents(msnj);
|
2023-07-26 12:55:50 +02:00
|
|
|
|
|
|
|
conf.set("tox", "save_file_path", save_path);
|
|
|
|
|
|
|
|
{ // name stuff
|
2024-04-20 19:53:41 +02:00
|
|
|
// a new profile will not have this set
|
2023-07-26 12:55:50 +02:00
|
|
|
auto name = tc.toxSelfGetName();
|
|
|
|
if (name.empty()) {
|
2024-04-20 19:53:41 +02:00
|
|
|
name = new_username;
|
2023-07-26 12:55:50 +02:00
|
|
|
}
|
|
|
|
conf.set("tox", "name", name);
|
|
|
|
tc.setSelfName(name); // TODO: this is ugly
|
|
|
|
}
|
|
|
|
|
|
|
|
// TODO: remove
|
|
|
|
std::cout << "own address: " << tc.toxSelfGetAddressStr() << "\n";
|
|
|
|
|
|
|
|
{ // setup plugin instances
|
2024-04-11 11:54:00 +02:00
|
|
|
g_provideInstance<ObjectStore2>("ObjectStore2", "host", &os);
|
2024-02-13 12:30:29 +01:00
|
|
|
|
2023-07-26 12:55:50 +02:00
|
|
|
g_provideInstance<ConfigModelI>("ConfigModelI", "host", &conf);
|
2024-01-18 00:32:11 +01:00
|
|
|
g_provideInstance<Contact3Registry>("Contact3Registry", "1", "host", &cr);
|
2023-07-26 12:55:50 +02:00
|
|
|
g_provideInstance<RegistryMessageModel>("RegistryMessageModel", "host", &rmm);
|
2024-04-14 13:58:31 +02:00
|
|
|
g_provideInstance<MessageSerializerNJ>("MessageSerializerNJ", "host", &msnj);
|
2023-07-26 12:55:50 +02:00
|
|
|
|
|
|
|
g_provideInstance<ToxI>("ToxI", "host", &tc);
|
2023-11-13 15:14:30 +01:00
|
|
|
g_provideInstance<ToxPrivateI>("ToxPrivateI", "host", &tpi);
|
2023-07-26 12:55:50 +02:00
|
|
|
g_provideInstance<ToxEventProviderI>("ToxEventProviderI", "host", &tc);
|
2023-08-03 13:05:19 +02:00
|
|
|
g_provideInstance<ToxContactModel2>("ToxContactModel2", "host", &tcm);
|
2023-07-26 12:55:50 +02:00
|
|
|
|
|
|
|
// TODO: pm?
|
|
|
|
|
|
|
|
// graphics
|
2024-01-18 18:36:29 +01:00
|
|
|
g_provideInstance("ImGuiContext", ImGui::GetVersion(), "host", ImGui::GetCurrentContext());
|
2023-07-26 20:09:57 +02:00
|
|
|
g_provideInstance<TextureUploaderI>("TextureUploaderI", "host", &sdlrtu);
|
2023-07-26 12:55:50 +02:00
|
|
|
}
|
|
|
|
|
2023-08-03 13:05:19 +02:00
|
|
|
for (const auto& ppath : plugins) {
|
|
|
|
if (!pm.add(ppath)) {
|
|
|
|
std::cerr << "MS error: loading plugin '" << ppath << "' failed!\n";
|
2024-05-18 14:03:57 +02:00
|
|
|
|
2023-08-03 13:05:19 +02:00
|
|
|
// thow?
|
2024-05-18 14:03:57 +02:00
|
|
|
//assert(false && "failed to load plugin");
|
|
|
|
SDL_MessageBoxData mb;
|
|
|
|
mb.flags = SDL_MESSAGEBOX_ERROR;
|
|
|
|
mb.window = nullptr;
|
|
|
|
mb.title = "Tomato failed to load a plugin!";
|
|
|
|
std::string message {"Failed to load plugin '"};
|
|
|
|
message += ppath;
|
|
|
|
message += "' !";
|
|
|
|
mb.message = message.c_str();
|
|
|
|
|
|
|
|
mb.numbuttons = 2;
|
|
|
|
SDL_MessageBoxButtonData mb_buttons[2] {};
|
|
|
|
mb_buttons[0].buttonID = 1;
|
|
|
|
mb_buttons[0].flags = SDL_MESSAGEBOX_BUTTON_ESCAPEKEY_DEFAULT;
|
|
|
|
mb_buttons[0].text = "Abort";
|
|
|
|
mb_buttons[1].buttonID = 2;
|
|
|
|
mb_buttons[1].flags = SDL_MESSAGEBOX_BUTTON_RETURNKEY_DEFAULT;
|
|
|
|
mb_buttons[1].text = "Continue Anyway";
|
|
|
|
mb.buttons = mb_buttons;
|
|
|
|
|
|
|
|
mb.colorScheme = nullptr;
|
|
|
|
|
|
|
|
int button_id = 0;
|
|
|
|
SDL_ShowMessageBox(&mb, &button_id);
|
|
|
|
if (button_id == 1) {
|
|
|
|
exit(1);
|
|
|
|
}
|
2023-08-03 13:05:19 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-07-26 12:55:50 +02:00
|
|
|
conf.dump();
|
2023-07-26 12:24:18 +02:00
|
|
|
}
|
|
|
|
|
2023-07-26 20:09:57 +02:00
|
|
|
MainScreen::~MainScreen(void) {
|
|
|
|
}
|
|
|
|
|
2023-07-30 15:10:26 +02:00
|
|
|
bool MainScreen::handleEvent(SDL_Event& e) {
|
2023-10-18 14:23:27 +02:00
|
|
|
if (e.type == SDL_EVENT_DROP_FILE) {
|
2024-01-17 22:39:51 +01:00
|
|
|
std::cout << "DROP FILE: " << e.drop.data << "\n";
|
|
|
|
cg.sendFilePath(e.drop.data);
|
2024-01-07 22:20:40 +01:00
|
|
|
_render_interval = 1.f/60.f; // TODO: magic
|
|
|
|
_time_since_event = 0.f;
|
2023-10-18 14:23:27 +02:00
|
|
|
return true; // TODO: forward return succ from sendFilePath()
|
|
|
|
}
|
|
|
|
|
2024-01-06 14:38:21 +01:00
|
|
|
if (
|
|
|
|
e.type == SDL_EVENT_WINDOW_MINIMIZED ||
|
|
|
|
e.type == SDL_EVENT_WINDOW_HIDDEN ||
|
|
|
|
e.type == SDL_EVENT_WINDOW_OCCLUDED // does this trigger on partial occlusion?
|
|
|
|
) {
|
|
|
|
auto* window = SDL_GetWindowFromID(e.window.windowID);
|
|
|
|
auto* event_renderer = SDL_GetRenderer(window);
|
|
|
|
if (event_renderer != nullptr && event_renderer == renderer) {
|
|
|
|
// our window is now obstructed
|
|
|
|
if (_window_hidden_ts < e.window.timestamp) {
|
|
|
|
_window_hidden_ts = e.window.timestamp;
|
|
|
|
_window_hidden = true;
|
|
|
|
//std::cout << "TOMAT: window hidden " << e.window.timestamp << "\n";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return true; // forward?
|
|
|
|
}
|
|
|
|
|
|
|
|
if (
|
|
|
|
e.type == SDL_EVENT_WINDOW_SHOWN ||
|
|
|
|
e.type == SDL_EVENT_WINDOW_RESTORED ||
|
|
|
|
e.type == SDL_EVENT_WINDOW_EXPOSED
|
|
|
|
) {
|
|
|
|
auto* window = SDL_GetWindowFromID(e.window.windowID);
|
|
|
|
auto* event_renderer = SDL_GetRenderer(window);
|
|
|
|
if (event_renderer != nullptr && event_renderer == renderer) {
|
|
|
|
if (_window_hidden_ts <= e.window.timestamp) {
|
|
|
|
_window_hidden_ts = e.window.timestamp;
|
2024-01-06 15:13:45 +01:00
|
|
|
|
|
|
|
if (_window_hidden) {
|
|
|
|
// if window was previously hidden, we shorten the wait for the next frame
|
|
|
|
_render_interval = 1.f/60.f;
|
|
|
|
}
|
|
|
|
|
2024-01-06 14:38:21 +01:00
|
|
|
_window_hidden = false;
|
|
|
|
//std::cout << "TOMAT: window shown " << e.window.timestamp << "\n";
|
|
|
|
}
|
|
|
|
}
|
2024-01-07 22:20:40 +01:00
|
|
|
_render_interval = 1.f/60.f; // TODO: magic
|
|
|
|
_time_since_event = 0.f;
|
2024-01-06 14:38:21 +01:00
|
|
|
return true; // forward?
|
|
|
|
}
|
|
|
|
|
2024-01-06 18:23:06 +01:00
|
|
|
if (
|
|
|
|
_fps_perf_mode <= 1 && (
|
2024-01-07 22:20:40 +01:00
|
|
|
// those are all the events imgui polls
|
2024-01-06 18:23:06 +01:00
|
|
|
e.type == SDL_EVENT_MOUSE_MOTION ||
|
|
|
|
e.type == SDL_EVENT_MOUSE_WHEEL ||
|
|
|
|
e.type == SDL_EVENT_MOUSE_BUTTON_DOWN ||
|
|
|
|
e.type == SDL_EVENT_MOUSE_BUTTON_UP ||
|
|
|
|
e.type == SDL_EVENT_TEXT_INPUT ||
|
|
|
|
e.type == SDL_EVENT_KEY_DOWN ||
|
|
|
|
e.type == SDL_EVENT_KEY_UP ||
|
|
|
|
e.type == SDL_EVENT_WINDOW_MOUSE_ENTER ||
|
|
|
|
e.type == SDL_EVENT_WINDOW_MOUSE_LEAVE ||
|
|
|
|
e.type == SDL_EVENT_WINDOW_FOCUS_GAINED ||
|
|
|
|
e.type == SDL_EVENT_WINDOW_FOCUS_LOST
|
|
|
|
)
|
|
|
|
) {
|
|
|
|
_render_interval = 1.f/60.f; // TODO: magic
|
2024-01-07 22:20:40 +01:00
|
|
|
_time_since_event = 0.f;
|
2024-01-06 18:23:06 +01:00
|
|
|
}
|
|
|
|
|
2023-07-30 15:10:26 +02:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2024-01-07 16:33:08 +01:00
|
|
|
Screen* MainScreen::render(float time_delta, bool&) {
|
2023-10-19 17:21:45 +02:00
|
|
|
// 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.
|
|
|
|
{
|
|
|
|
// TODO: maybe render cg earlier? or move the main window out of cg?
|
|
|
|
constexpr auto bg_window_flags =
|
|
|
|
ImGuiWindowFlags_NoDecoration |
|
|
|
|
ImGuiWindowFlags_NoMove |
|
|
|
|
ImGuiWindowFlags_NoResize |
|
|
|
|
ImGuiWindowFlags_NoSavedSettings |
|
|
|
|
ImGuiWindowFlags_MenuBar |
|
|
|
|
ImGuiWindowFlags_NoBringToFrontOnFocus;
|
|
|
|
|
|
|
|
ImGui::Begin("tomato", nullptr, bg_window_flags);
|
|
|
|
ImGui::End();
|
|
|
|
}
|
|
|
|
|
2024-01-07 16:33:08 +01:00
|
|
|
const float pm_interval = pm.render(time_delta); // render
|
2023-07-29 20:51:32 +02:00
|
|
|
|
2024-02-05 16:05:45 +01:00
|
|
|
// TODO: move this somewhere else!!!
|
|
|
|
// needs both tal and tc <.<
|
|
|
|
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) {
|
|
|
|
to_purge.push_back(c);
|
|
|
|
});
|
|
|
|
cr.remove<Contact::Components::TagAvatarInvalidate>(to_purge.cbegin(), to_purge.cend());
|
|
|
|
contact_tc.invalidate(to_purge);
|
|
|
|
}
|
|
|
|
// ACTUALLY NOT IF RENDERED, MOVED LOGIC TO ABOVE
|
|
|
|
// it might unload textures, so it needs to be done before rendering
|
|
|
|
const float ctc_interval = contact_tc.update();
|
|
|
|
const float msgtc_interval = msg_tc.update();
|
|
|
|
|
2024-02-05 12:50:36 +01:00
|
|
|
const float cg_interval = cg.render(time_delta); // render
|
2024-01-07 16:33:08 +01:00
|
|
|
sw.render(); // render
|
|
|
|
tuiu.render(); // render
|
|
|
|
tdch.render(); // render
|
2023-07-28 18:03:45 +02:00
|
|
|
|
2024-01-06 14:38:21 +01:00
|
|
|
{ // main window menubar injection
|
|
|
|
if (ImGui::Begin("tomato")) {
|
|
|
|
if (ImGui::BeginMenuBar()) {
|
|
|
|
// ImGui::Separator(); // why do we not need this????
|
|
|
|
if (ImGui::BeginMenu("Performance")) {
|
|
|
|
{ // fps
|
2024-01-06 18:23:06 +01:00
|
|
|
const auto targets = "normal\0reduced\0powersave\0";
|
2024-01-06 14:38:21 +01:00
|
|
|
ImGui::SetNextItemWidth(ImGui::GetFontSize()*10);
|
|
|
|
ImGui::Combo("fps mode", &_fps_perf_mode, targets, 4);
|
|
|
|
}
|
|
|
|
|
|
|
|
{ // compute
|
2024-01-13 18:38:12 +01:00
|
|
|
const auto targets = "normal\0powersave\0extreme powersave\0";
|
2024-01-06 14:38:21 +01:00
|
|
|
ImGui::SetNextItemWidth(ImGui::GetFontSize()*10);
|
|
|
|
ImGui::Combo("compute mode", &_compute_perf_mode, targets, 4);
|
2024-01-07 16:33:08 +01:00
|
|
|
ImGui::SetItemTooltip("Limiting compute can slow down things like filetransfers!");
|
2024-01-06 14:38:21 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
ImGui::EndMenu();
|
|
|
|
}
|
2024-01-21 20:20:32 +01:00
|
|
|
if (ImGui::BeginMenu("Settings")) {
|
2024-03-15 13:01:14 +01:00
|
|
|
ImGui::SeparatorText("ImGui");
|
|
|
|
|
|
|
|
if (ImGui::MenuItem("Style Editor")) {
|
2024-01-21 20:20:32 +01:00
|
|
|
_show_tool_style_editor = true;
|
|
|
|
}
|
2024-03-15 13:01:14 +01:00
|
|
|
|
|
|
|
if (ImGui::MenuItem("Metrics")) {
|
|
|
|
_show_tool_metrics = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (ImGui::MenuItem("Debug Log")) {
|
|
|
|
_show_tool_debug_log = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (ImGui::MenuItem("ID Stack Tool")) {
|
|
|
|
_show_tool_id_stack = true;
|
|
|
|
}
|
|
|
|
|
2024-01-21 20:20:32 +01:00
|
|
|
ImGui::EndMenu();
|
|
|
|
}
|
2024-01-06 14:38:21 +01:00
|
|
|
ImGui::EndMenuBar();
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
ImGui::End();
|
|
|
|
}
|
|
|
|
|
2024-01-21 20:20:32 +01:00
|
|
|
if (_show_tool_style_editor) {
|
|
|
|
if (ImGui::Begin("Dear ImGui Style Editor", &_show_tool_style_editor)) {
|
|
|
|
ImGui::ShowStyleEditor();
|
|
|
|
}
|
|
|
|
ImGui::End();
|
|
|
|
}
|
2024-01-06 14:38:21 +01:00
|
|
|
|
2024-03-15 13:01:14 +01:00
|
|
|
if (_show_tool_metrics) {
|
|
|
|
ImGui::ShowMetricsWindow(&_show_tool_metrics);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (_show_tool_debug_log) {
|
|
|
|
ImGui::ShowDebugLogWindow(&_show_tool_debug_log);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (_show_tool_id_stack) {
|
|
|
|
ImGui::ShowIDStackToolWindow(&_show_tool_id_stack);
|
|
|
|
}
|
|
|
|
|
2023-08-28 14:06:27 +02:00
|
|
|
if constexpr (false) {
|
2023-09-29 18:15:18 +02:00
|
|
|
ImGui::ShowDemoWindow();
|
2023-07-26 12:55:50 +02:00
|
|
|
}
|
2023-07-26 12:24:18 +02:00
|
|
|
|
2024-02-05 16:05:45 +01:00
|
|
|
float tc_unfinished_queue_interval;
|
|
|
|
{ // load rendered but not loaded textures
|
|
|
|
bool unfinished_work_queue = contact_tc.workLoadQueue();
|
|
|
|
unfinished_work_queue = unfinished_work_queue || msg_tc.workLoadQueue();
|
2024-02-05 12:50:36 +01:00
|
|
|
|
2024-02-05 16:05:45 +01:00
|
|
|
if (unfinished_work_queue) {
|
|
|
|
tc_unfinished_queue_interval = 0.1f; // so we can get images loaded faster
|
|
|
|
} else {
|
|
|
|
tc_unfinished_queue_interval = 1.f; // TODO: higher min fps?
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// calculate interval for next frame
|
|
|
|
// normal:
|
|
|
|
// - if < 1.5sec since last event
|
|
|
|
// - min all and clamp(1/60, 1/1)
|
|
|
|
// - if < 30sec since last event
|
|
|
|
// - min all (anim + everything else) clamp(1/60, 1/1) (maybe less?)
|
|
|
|
// - else
|
|
|
|
// - min without anim and clamp(1/60, 1/1) (maybe more?)
|
|
|
|
// reduced:
|
|
|
|
// - if < 1sec since last event
|
|
|
|
// - min all and clamp(1/60, 1/1)
|
|
|
|
// - if < 10sec since last event
|
|
|
|
// - min all (anim + everything else) clamp(1/10, 1/1)
|
|
|
|
// - else
|
|
|
|
// - min without anim and max clamp(1/10, 1/1)
|
|
|
|
// powersave:
|
|
|
|
// - if < 0sec since last event
|
|
|
|
// - (ignored)
|
|
|
|
// - if < 1sec since last event
|
|
|
|
// - min all (anim + everything else) clamp(1/8, 1/1)
|
|
|
|
// - else
|
|
|
|
// - min without anim and clamp(1/1, 1/1)
|
|
|
|
struct PerfProfileRender {
|
|
|
|
float low_delay_window {1.5f};
|
|
|
|
float low_delay_min {1.f/60.f};
|
2024-02-05 16:15:10 +01:00
|
|
|
float low_delay_max {1.f/60.f};
|
2024-02-05 16:05:45 +01:00
|
|
|
|
|
|
|
float mid_delay_window {30.f};
|
|
|
|
float mid_delay_min {1.f/60.f};
|
|
|
|
float mid_delay_max {1.f/2.f};
|
|
|
|
|
|
|
|
// also when main window hidden
|
|
|
|
float else_delay_min {1.f/60.f};
|
|
|
|
float else_delay_max {1.f/2.f};
|
|
|
|
};
|
|
|
|
|
|
|
|
const static PerfProfileRender normalPerfProfile{
|
|
|
|
//1.5f, // low_delay_window
|
|
|
|
//1.f/60.f, // low_delay_min
|
2024-02-05 16:15:10 +01:00
|
|
|
//1.f/60.f, // low_delay_max
|
2024-02-05 16:05:45 +01:00
|
|
|
|
|
|
|
//30.f, // mid_delay_window
|
|
|
|
//1.f/60.f, // mid_delay_min
|
|
|
|
//1.f/2.f, // mid_delay_max
|
|
|
|
|
|
|
|
//1.f/60.f, // else_delay_min
|
|
|
|
//1.f/2.f, // else_delay_max
|
|
|
|
};
|
|
|
|
const static PerfProfileRender reducedPerfProfile{
|
|
|
|
1.f, // low_delay_window
|
|
|
|
1.f/60.f, // low_delay_min
|
|
|
|
1.f/30.f, // low_delay_max
|
|
|
|
|
|
|
|
10.f, // mid_delay_window
|
|
|
|
1.f/10.f, // mid_delay_min
|
|
|
|
1.f/4.f, // mid_delay_max
|
|
|
|
|
|
|
|
1.f/10.f, // else_delay_min
|
|
|
|
1.f, // else_delay_max
|
|
|
|
};
|
|
|
|
// TODO: fix powersave by adjusting it in the events handler (make ppr member)
|
|
|
|
const static PerfProfileRender powersavePerfProfile{
|
|
|
|
// no window -> ignore first case
|
|
|
|
0.f, // low_delay_window
|
|
|
|
1.f, // low_delay_min
|
|
|
|
1.f, // low_delay_max
|
|
|
|
|
|
|
|
1.f, // mid_delay_window
|
|
|
|
1.f/8.f, // mid_delay_min
|
|
|
|
1.f/4.f, // mid_delay_max
|
|
|
|
|
|
|
|
1.f, // else_delay_min
|
|
|
|
1.f, // else_delay_max
|
|
|
|
};
|
|
|
|
|
|
|
|
const PerfProfileRender& curr_profile =
|
|
|
|
// TODO: magic
|
|
|
|
_fps_perf_mode > 1
|
|
|
|
? powersavePerfProfile
|
|
|
|
: (
|
|
|
|
_fps_perf_mode == 1
|
|
|
|
? reducedPerfProfile
|
|
|
|
: normalPerfProfile
|
2024-01-07 22:20:40 +01:00
|
|
|
)
|
2024-02-05 16:05:45 +01:00
|
|
|
;
|
|
|
|
|
|
|
|
// min over non animations in all cases
|
|
|
|
_render_interval = std::min<float>(pm_interval, cg_interval);
|
|
|
|
_render_interval = std::min<float>(_render_interval, tc_unfinished_queue_interval);
|
|
|
|
|
|
|
|
// low delay time window
|
|
|
|
if (!_window_hidden && _time_since_event < curr_profile.low_delay_window) {
|
|
|
|
_render_interval = std::min<float>(_render_interval, ctc_interval);
|
|
|
|
_render_interval = std::min<float>(_render_interval, msgtc_interval);
|
|
|
|
|
|
|
|
_render_interval = std::clamp(
|
|
|
|
_render_interval,
|
|
|
|
curr_profile.low_delay_min,
|
|
|
|
curr_profile.low_delay_max
|
|
|
|
);
|
|
|
|
// mid delay time window
|
|
|
|
} else if (!_window_hidden && _time_since_event < curr_profile.mid_delay_window) {
|
|
|
|
_render_interval = std::min<float>(_render_interval, ctc_interval);
|
|
|
|
_render_interval = std::min<float>(_render_interval, msgtc_interval);
|
|
|
|
|
|
|
|
_render_interval = std::clamp(
|
|
|
|
_render_interval,
|
|
|
|
curr_profile.mid_delay_min,
|
|
|
|
curr_profile.mid_delay_max
|
|
|
|
);
|
|
|
|
// timed out or window hidden
|
2024-01-06 14:38:21 +01:00
|
|
|
} else {
|
2024-02-05 16:05:45 +01:00
|
|
|
// no animation timing here
|
|
|
|
_render_interval = std::clamp(
|
|
|
|
_render_interval,
|
|
|
|
curr_profile.else_delay_min,
|
|
|
|
curr_profile.else_delay_max
|
|
|
|
);
|
2024-01-06 14:38:21 +01:00
|
|
|
}
|
|
|
|
|
2024-01-07 22:20:40 +01:00
|
|
|
_time_since_event += time_delta;
|
|
|
|
|
2024-01-05 14:47:08 +01:00
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
Screen* MainScreen::tick(float time_delta, bool& quit) {
|
2024-03-12 12:39:06 +01:00
|
|
|
quit = !tc.iterate(time_delta); // compute
|
2024-01-07 16:33:08 +01:00
|
|
|
|
|
|
|
tcm.iterate(time_delta); // compute
|
|
|
|
|
2024-02-02 20:26:50 +01:00
|
|
|
const float fo_interval = tffom.tick(time_delta);
|
|
|
|
|
2024-01-07 16:33:08 +01:00
|
|
|
tam.iterate(); // compute
|
|
|
|
|
|
|
|
const float pm_interval = pm.tick(time_delta); // compute
|
|
|
|
|
|
|
|
tdch.tick(time_delta); // compute
|
|
|
|
|
2024-02-26 01:22:49 +01:00
|
|
|
mts.iterate(); // compute (after mfs)
|
2024-01-07 16:33:08 +01:00
|
|
|
|
2024-01-13 18:38:12 +01:00
|
|
|
_min_tick_interval = std::min<float>(
|
2024-02-03 15:00:32 +01:00
|
|
|
// HACK: pow by 1.6 to increase 50 -> ~500 (~522)
|
|
|
|
// and it does not change 1
|
|
|
|
std::pow(tc.toxIterationInterval(), 1.6f)/1000.f,
|
2024-01-13 18:38:12 +01:00
|
|
|
pm_interval
|
2024-01-05 14:47:08 +01:00
|
|
|
);
|
2024-02-02 20:26:50 +01:00
|
|
|
_min_tick_interval = std::min<float>(
|
|
|
|
_min_tick_interval,
|
|
|
|
fo_interval
|
|
|
|
);
|
2023-07-26 20:09:57 +02:00
|
|
|
|
2024-02-03 15:00:32 +01:00
|
|
|
//std::cout << "MS: min tick interval: " << _min_tick_interval << "\n";
|
|
|
|
|
2024-01-13 18:38:12 +01:00
|
|
|
switch (_compute_perf_mode) {
|
|
|
|
// normal 1ms lower bound
|
|
|
|
case 0: _min_tick_interval = std::max<float>(_min_tick_interval, 0.001f); break;
|
|
|
|
// in powersave fix the lowerbound to 100ms
|
|
|
|
case 1: _min_tick_interval = std::max<float>(_min_tick_interval, 0.1f); break;
|
|
|
|
// extreme 2s
|
|
|
|
case 2: _min_tick_interval = std::max<float>(_min_tick_interval, 2.f); break;
|
|
|
|
default: std::cerr << "unknown compute perf mode\n"; std::exit(-1);
|
|
|
|
}
|
|
|
|
|
2023-07-26 12:24:18 +02:00
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|