Add --print-fps option to output FPS to stdout

Works both for the editor and games.

Projects can still use "debug/settings/stdout/print_fps" to enable it
permanently. The --print-fps option takes precedence (so works even if
the project setting is disabled). That setting is also no longer redefined
on the fly based on the verbose flag, that was a mess.
This commit is contained in:
Rémi Verschelde 2018-03-21 08:46:05 +01:00
parent b49ca9486c
commit 10fa69285c
2 changed files with 15 additions and 4 deletions

View File

@ -127,6 +127,7 @@ static bool disable_render_loop = false;
static int fixed_fps = -1; static int fixed_fps = -1;
static bool auto_build_solutions = false; static bool auto_build_solutions = false;
static bool auto_quit = false; static bool auto_quit = false;
static bool print_fps = false;
static OS::ProcessID allow_focus_steal_pid = 0; static OS::ProcessID allow_focus_steal_pid = 0;
@ -255,6 +256,7 @@ void Main::print_help(const char *p_binary) {
OS::get_singleton()->print(" --disable-render-loop Disable render loop so rendering only occurs when called explicitly from script.\n"); OS::get_singleton()->print(" --disable-render-loop Disable render loop so rendering only occurs when called explicitly from script.\n");
OS::get_singleton()->print(" --disable-crash-handler Disable crash handler when supported by the platform code.\n"); OS::get_singleton()->print(" --disable-crash-handler Disable crash handler when supported by the platform code.\n");
OS::get_singleton()->print(" --fixed-fps <fps> Force a fixed number of frames per second. This setting disables real-time synchronization.\n"); OS::get_singleton()->print(" --fixed-fps <fps> Force a fixed number of frames per second. This setting disables real-time synchronization.\n");
OS::get_singleton()->print(" --print-fps Print the frames per second to the stdout.\n");
OS::get_singleton()->print("\n"); OS::get_singleton()->print("\n");
OS::get_singleton()->print("Standalone tools:\n"); OS::get_singleton()->print("Standalone tools:\n");
@ -665,6 +667,8 @@ Error Main::setup(const char *execpath, int argc, char *argv[], bool p_second_ph
OS::get_singleton()->print("Missing fixed-fps argument, aborting.\n"); OS::get_singleton()->print("Missing fixed-fps argument, aborting.\n");
goto error; goto error;
} }
} else if (I->get() == "--print-fps") {
print_fps = true;
} else if (I->get() == "--disable-crash-handler") { } else if (I->get() == "--disable-crash-handler") {
OS::get_singleton()->disable_crash_handler(); OS::get_singleton()->disable_crash_handler();
} else { } else {
@ -953,7 +957,7 @@ Error Main::setup(const char *execpath, int argc, char *argv[], bool p_second_ph
Engine::get_singleton()->set_iterations_per_second(GLOBAL_DEF("physics/common/physics_fps", 60)); Engine::get_singleton()->set_iterations_per_second(GLOBAL_DEF("physics/common/physics_fps", 60));
Engine::get_singleton()->set_target_fps(GLOBAL_DEF("debug/settings/fps/force_fps", 0)); Engine::get_singleton()->set_target_fps(GLOBAL_DEF("debug/settings/fps/force_fps", 0));
GLOBAL_DEF("debug/settings/stdout/print_fps", OS::get_singleton()->is_stdout_verbose()); GLOBAL_DEF("debug/settings/stdout/print_fps", false);
if (!OS::get_singleton()->_verbose_stdout) //overridden if (!OS::get_singleton()->_verbose_stdout) //overridden
OS::get_singleton()->_verbose_stdout = GLOBAL_DEF("debug/settings/stdout/verbose_stdout", false); OS::get_singleton()->_verbose_stdout = GLOBAL_DEF("debug/settings/stdout/verbose_stdout", false);
@ -1826,9 +1830,13 @@ bool Main::iteration() {
if (frame > 1000000) { if (frame > 1000000) {
if (GLOBAL_DEF("debug/settings/stdout/print_fps", OS::get_singleton()->is_stdout_verbose()) && !editor) { if (editor || project_manager) {
print_line("FPS: " + itos(frames)); if (print_fps) {
}; print_line("Editor FPS: " + itos(frames));
}
} else if (GLOBAL_GET("debug/settings/stdout/print_fps") || print_fps) {
print_line("Game FPS: " + itos(frames));
}
Engine::get_singleton()->_fps = frames; Engine::get_singleton()->_fps = frames;
performance->set_process_time(USEC_TO_SEC(idle_process_max)); performance->set_process_time(USEC_TO_SEC(idle_process_max));

View File

@ -119,6 +119,9 @@ Disable crash handler when supported by the platform code.
.TP .TP
\fB\-\-fixed\-fps\fR <fps> \fB\-\-fixed\-fps\fR <fps>
Force a fixed number of frames per second. This setting disables real\-time synchronization. Force a fixed number of frames per second. This setting disables real\-time synchronization.
.TP
\fB\-\-print\-fps\fR
Print the frames per second to the stdout.
.SS "Standalone tools:" .SS "Standalone tools:"
.TP .TP
\fB\-s\fR, \fB\-\-script\fR <script> \fB\-s\fR, \fB\-\-script\fR <script>