1 sec cooldown for reduced fps mode

This commit is contained in:
Green Sky 2024-01-07 22:20:40 +01:00
parent da0f59a3f5
commit be8ceb861c
No known key found for this signature in database
2 changed files with 13 additions and 2 deletions

View File

@ -75,6 +75,8 @@ bool MainScreen::handleEvent(SDL_Event& e) {
if (e.type == SDL_EVENT_DROP_FILE) { if (e.type == SDL_EVENT_DROP_FILE) {
std::cout << "DROP FILE: " << e.drop.file << "\n"; std::cout << "DROP FILE: " << e.drop.file << "\n";
cg.sendFilePath(e.drop.file); cg.sendFilePath(e.drop.file);
_render_interval = 1.f/60.f; // TODO: magic
_time_since_event = 0.f;
return true; // TODO: forward return succ from sendFilePath() return true; // TODO: forward return succ from sendFilePath()
} }
@ -116,11 +118,14 @@ bool MainScreen::handleEvent(SDL_Event& e) {
//std::cout << "TOMAT: window shown " << e.window.timestamp << "\n"; //std::cout << "TOMAT: window shown " << e.window.timestamp << "\n";
} }
} }
_render_interval = 1.f/60.f; // TODO: magic
_time_since_event = 0.f;
return true; // forward? return true; // forward?
} }
if ( if (
_fps_perf_mode <= 1 && ( _fps_perf_mode <= 1 && (
// those are all the events imgui polls
e.type == SDL_EVENT_MOUSE_MOTION || e.type == SDL_EVENT_MOUSE_MOTION ||
e.type == SDL_EVENT_MOUSE_WHEEL || e.type == SDL_EVENT_MOUSE_WHEEL ||
e.type == SDL_EVENT_MOUSE_BUTTON_DOWN || e.type == SDL_EVENT_MOUSE_BUTTON_DOWN ||
@ -135,6 +140,7 @@ bool MainScreen::handleEvent(SDL_Event& e) {
) )
) { ) {
_render_interval = 1.f/60.f; // TODO: magic _render_interval = 1.f/60.f; // TODO: magic
_time_since_event = 0.f;
} }
return false; return false;
@ -203,14 +209,18 @@ Screen* MainScreen::render(float time_delta, bool&) {
// powersave forces 250ms // powersave forces 250ms
_render_interval = 1.f/4.f; _render_interval = 1.f/4.f;
} else if ( } else if (
_fps_perf_mode == 1 || // TODO: magic _time_since_event > 1.f && ( // 1sec cool down
_window_hidden _fps_perf_mode == 1 || // TODO: magic
_window_hidden
)
) { ) {
_render_interval = std::min<float>(1.f/4.f, pm_interval); _render_interval = std::min<float>(1.f/4.f, pm_interval);
} else { } else {
_render_interval = std::min<float>(1.f/60.f, pm_interval); _render_interval = std::min<float>(1.f/60.f, pm_interval);
} }
_time_since_event += time_delta;
return nullptr; return nullptr;
} }

View File

@ -66,6 +66,7 @@ struct MainScreen final : public Screen {
bool _window_hidden {false}; bool _window_hidden {false};
bool _window_hidden_ts {0}; bool _window_hidden_ts {0};
float _time_since_event {0.f};
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);