editor: improve engine_tick powersave feature

main
Dominik Madarász 2024-02-11 03:17:40 +01:00
parent e4b736e98a
commit 4fd3e9cd67
4 changed files with 25 additions and 19 deletions

View File

@ -382161,16 +382161,18 @@ int engine_send(const char *cmd, const char *optional_value) {
} }
int engine_tick() { int engine_tick() {
enum { engine_hz = 60 }; enum { engine_hz_mid = 30 };
enum { engine_hz_mid = 18 }; enum { engine_hz_low = 10 };
enum { engine_hz_low = 5 }; static double old_hz = 0.0;
if( *engine_geti("powersave") ) { if( *engine_geti("powersave") ) {
// adaptive framerate // adaptive framerate
int app_on_background = !window_has_focus(); int app_on_background = !window_has_focus();
int hz = app_on_background ? engine_hz_low : engine_hz_mid; int hz = app_on_background ? engine_hz_low : engine_hz_mid;
window_fps_lock( hz < 5 ? 5 : hz ); if (!old_hz) old_hz = window_fps_target();
} else { window_fps_lock( hz );
// window_fps_lock( editor_hz ); } else if( old_hz && old_hz != window_fps_target() ) {
window_fps_lock( old_hz );
old_hz = 0.0;
} }
return 0; return 0;

View File

@ -139,16 +139,18 @@ int engine_send(const char *cmd, const char *optional_value) {
} }
int engine_tick() { int engine_tick() {
enum { engine_hz = 60 }; enum { engine_hz_mid = 30 };
enum { engine_hz_mid = 18 }; enum { engine_hz_low = 10 };
enum { engine_hz_low = 5 }; static double old_hz = 0.0;
if( *engine_geti("powersave") ) { if( *engine_geti("powersave") ) {
// adaptive framerate // adaptive framerate
int app_on_background = !window_has_focus(); int app_on_background = !window_has_focus();
int hz = app_on_background ? engine_hz_low : engine_hz_mid; int hz = app_on_background ? engine_hz_low : engine_hz_mid;
window_fps_lock( hz < 5 ? 5 : hz ); if (!old_hz) old_hz = window_fps_target();
} else { window_fps_lock( hz );
// window_fps_lock( editor_hz ); } else if( old_hz && old_hz != window_fps_target() ) {
window_fps_lock( old_hz );
old_hz = 0.0;
} }
return 0; return 0;

View File

@ -29305,16 +29305,18 @@ int engine_send(const char *cmd, const char *optional_value) {
} }
int engine_tick() { int engine_tick() {
enum { engine_hz = 60 }; enum { engine_hz_mid = 30 };
enum { engine_hz_mid = 18 }; enum { engine_hz_low = 10 };
enum { engine_hz_low = 5 }; static double old_hz = 0.0;
if( *engine_geti("powersave") ) { if( *engine_geti("powersave") ) {
// adaptive framerate // adaptive framerate
int app_on_background = !window_has_focus(); int app_on_background = !window_has_focus();
int hz = app_on_background ? engine_hz_low : engine_hz_mid; int hz = app_on_background ? engine_hz_low : engine_hz_mid;
window_fps_lock( hz < 5 ? 5 : hz ); if (!old_hz) old_hz = window_fps_target();
} else { window_fps_lock( hz );
// window_fps_lock( editor_hz ); } else if( old_hz && old_hz != window_fps_target() ) {
window_fps_lock( old_hz );
old_hz = 0.0;
} }
return 0; return 0;