From 82c4e6476c96b428a6e093126c9e2c3a0cf7e008 Mon Sep 17 00:00:00 2001 From: Jon Ringle Date: Mon, 18 Mar 2024 22:37:45 -0400 Subject: [PATCH] debug_fps: Add configurable option --- c_src/main.c | 11 ++++++----- c_src/scenic/comms.c | 9 +++++---- c_src/scenic/scenic_types.h | 1 + lib/driver.ex | 9 ++++++++- test/driver_test.exs | 1 + 5 files changed, 21 insertions(+), 10 deletions(-) diff --git a/c_src/main.c b/c_src/main.c index 87fe063..167be27 100644 --- a/c_src/main.c +++ b/c_src/main.c @@ -30,7 +30,7 @@ int main(int argc, char **argv) driver_data_t data = {0}; // super simple arg check - if (argc != 10) { + if (argc != 11) { log_error("Wrong number of parameters"); return -1; } @@ -41,10 +41,11 @@ int main(int argc, char **argv) g_opts.global_opacity = atoi(argv[3]); g_opts.antialias = atoi(argv[4]); g_opts.debug_mode = atoi(argv[5]); - g_opts.width = atoi(argv[6]); - g_opts.height = atoi(argv[7]); - g_opts.resizable = atoi(argv[8]); - g_opts.title = argv[9]; + g_opts.debug_fps = atoi(argv[6]); + g_opts.width = atoi(argv[7]); + g_opts.height = atoi(argv[8]); + g_opts.resizable = atoi(argv[9]); + g_opts.title = argv[10]; // init the hashtables init_scripts(); diff --git a/c_src/scenic/comms.c b/c_src/scenic/comms.c index 5321b83..d08f25f 100644 --- a/c_src/scenic/comms.c +++ b/c_src/scenic/comms.c @@ -28,6 +28,7 @@ The caller will typically be erlang, so use the 2-byte length indicator #define STDIO_TIMEOUT 32 extern device_info_t g_device_info; +extern device_opts_t g_opts; //============================================================================= // raw comms with host app @@ -431,9 +432,9 @@ void render(driver_data_t* p_data) clock_t end_frame = clock(); clock_t delta_ticks = end_frame - begin_frame; - if (delta_ticks > 0) { + if (g_opts.debug_fps && (delta_ticks > 0)) { render_fps = CLOCKS_PER_SEC / delta_ticks; - // log_debug("render_fps (cpu time): %d", render_fps); + log_debug("render_fps (cpu time): %d", render_fps); } frames++; @@ -443,8 +444,8 @@ void render(driver_data_t* p_data) start_real = end_real; time_remaining -= delta_real; - if (time_remaining <= 0) { - log_debug("real_fps: %d", frames); + if (g_opts.debug_fps && (time_remaining <= 0)) { + log_info("real_fps: %d", frames); start_real = monotonic_time(); time_remaining = 1000; frames = 0; diff --git a/c_src/scenic/scenic_types.h b/c_src/scenic/scenic_types.h index 4858a73..fef12c6 100644 --- a/c_src/scenic/scenic_types.h +++ b/c_src/scenic/scenic_types.h @@ -61,6 +61,7 @@ typedef struct { typedef struct { // options from the command line int debug_mode; + int debug_fps; int layer; int global_opacity; int antialias; diff --git a/lib/driver.ex b/lib/driver.ex index b2890e9..5eb83ac 100644 --- a/lib/driver.ex +++ b/lib/driver.ex @@ -26,6 +26,7 @@ defmodule Scenic.Driver.Local do opacity: [type: :integer, default: @default_opacity], debug: [type: :boolean, default: false], debugger: [type: :string, default: ""], + debug_fps: [type: :boolean, default: false], antialias: [type: :boolean, default: true], calibration: [ type: {:custom, __MODULE__, :validate_calibration, []}, @@ -201,6 +202,12 @@ defmodule Scenic.Driver.Local do false -> 0 end + debug_fps = + case opts[:debug_fps] do + true -> 1 + false -> 0 + end + internal_cursor = case opts[:cursor] do true -> 1 @@ -227,7 +234,7 @@ defmodule Scenic.Driver.Local do end args = - " #{internal_cursor} #{layer} #{opacity} #{antialias} #{debug_mode}" <> + " #{internal_cursor} #{layer} #{opacity} #{antialias} #{debug_mode} #{debug_fps}" <> " #{width} #{height} #{resizeable} \"#{title}\"" # open and initialize the window diff --git a/test/driver_test.exs b/test/driver_test.exs index 316f7d1..e7a8b62 100644 --- a/test/driver_test.exs +++ b/test/driver_test.exs @@ -9,6 +9,7 @@ defmodule Scenic.Driver.LocalTest do opacity: 1, debug: false, debugger: "", + debug_fps: false, antialias: true, calibration: [{"calibration_name", {{0, 0, 0}, {0, 0, 0}}}], position: [