forked from Green-Sky/tomato
wip low fps mode for hidden states and powersave modes.
dont use yet, as all compute is still done in the render method
This commit is contained in:
parent
14fcaf1d7e
commit
5a0651eaf0
@ -78,6 +78,41 @@ bool MainScreen::handleEvent(SDL_Event& e) {
|
|||||||
return true; // TODO: forward return succ from sendFilePath()
|
return true; // TODO: forward return succ from sendFilePath()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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;
|
||||||
|
_window_hidden = false;
|
||||||
|
//std::cout << "TOMAT: window shown " << e.window.timestamp << "\n";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return true; // forward?
|
||||||
|
}
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -115,17 +150,57 @@ Screen* MainScreen::render(float time_delta, bool& quit) {
|
|||||||
tuiu.render();
|
tuiu.render();
|
||||||
tdch.render();
|
tdch.render();
|
||||||
|
|
||||||
|
{ // main window menubar injection
|
||||||
|
if (ImGui::Begin("tomato")) {
|
||||||
|
if (ImGui::BeginMenuBar()) {
|
||||||
|
// ImGui::Separator(); // why do we not need this????
|
||||||
|
if (ImGui::BeginMenu("Performance")) {
|
||||||
|
{ // fps
|
||||||
|
const auto targets = "normal\0power save\0";
|
||||||
|
ImGui::SetNextItemWidth(ImGui::GetFontSize()*10);
|
||||||
|
ImGui::Combo("fps mode", &_fps_perf_mode, targets, 4);
|
||||||
|
}
|
||||||
|
|
||||||
|
{ // compute
|
||||||
|
const auto targets = "normal\0power save\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::EndMenu();
|
||||||
|
}
|
||||||
|
ImGui::EndMenuBar();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
ImGui::End();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
if constexpr (false) {
|
if constexpr (false) {
|
||||||
ImGui::ShowDemoWindow();
|
ImGui::ShowDemoWindow();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (
|
||||||
|
_fps_perf_mode == 1 || // TODO: magic
|
||||||
|
_window_hidden
|
||||||
|
) {
|
||||||
|
_render_interval = 1.f/4.f;
|
||||||
|
} else {
|
||||||
|
_render_interval = 1.f/60.f;
|
||||||
|
}
|
||||||
|
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
Screen* MainScreen::tick(float time_delta, bool& quit) {
|
Screen* MainScreen::tick(float time_delta, bool& quit) {
|
||||||
_min_tick_interval = std::min<float>(
|
_min_tick_interval = std::max<float>(
|
||||||
|
std::min<float>(
|
||||||
tc.toxIterationInterval()/1000.f,
|
tc.toxIterationInterval()/1000.f,
|
||||||
0.03f // HACK: 30ms upper bound, should be the same as tox but will change
|
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
|
||||||
);
|
);
|
||||||
|
|
||||||
return nullptr;
|
return nullptr;
|
||||||
|
@ -38,8 +38,6 @@ extern "C" {
|
|||||||
struct MainScreen final : public Screen {
|
struct MainScreen final : public Screen {
|
||||||
SDL_Renderer* renderer;
|
SDL_Renderer* renderer;
|
||||||
|
|
||||||
std::chrono::high_resolution_clock::time_point last_time = std::chrono::high_resolution_clock::now();
|
|
||||||
|
|
||||||
SimpleConfigModel conf;
|
SimpleConfigModel conf;
|
||||||
Contact3Registry cr;
|
Contact3Registry cr;
|
||||||
RegistryMessageModel rmm;
|
RegistryMessageModel rmm;
|
||||||
@ -66,6 +64,9 @@ struct MainScreen final : public Screen {
|
|||||||
ToxUIUtils tuiu;
|
ToxUIUtils tuiu;
|
||||||
ToxDHTCapHisto tdch;
|
ToxDHTCapHisto tdch;
|
||||||
|
|
||||||
|
bool _window_hidden {false};
|
||||||
|
bool _window_hidden_ts {0};
|
||||||
|
|
||||||
MainScreen(SDL_Renderer* renderer_, std::string save_path, std::string save_password, std::vector<std::string> plugins);
|
MainScreen(SDL_Renderer* renderer_, std::string save_path, std::string save_password, std::vector<std::string> plugins);
|
||||||
~MainScreen(void);
|
~MainScreen(void);
|
||||||
|
|
||||||
@ -76,6 +77,11 @@ struct MainScreen final : public Screen {
|
|||||||
Screen* render(float time_delta, bool&) override;
|
Screen* render(float time_delta, bool&) override;
|
||||||
Screen* tick(float time_delta, bool&) override;
|
Screen* tick(float time_delta, bool&) override;
|
||||||
|
|
||||||
|
// 0 - normal
|
||||||
|
// 1 - power save
|
||||||
|
int _fps_perf_mode {0};
|
||||||
|
int _compute_perf_mode {0};
|
||||||
|
|
||||||
float _render_interval {1.f/60.f};
|
float _render_interval {1.f/60.f};
|
||||||
float _min_tick_interval {0.f};
|
float _min_tick_interval {0.f};
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user