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 7cef107..d589736 100644 --- a/c_src/scenic/comms.c +++ b/c_src/scenic/comms.c @@ -21,21 +21,14 @@ The caller will typically be erlang, so use the 2-byte length indicator #include "script.h" #include "utils.h" -// handy time definitions in microseconds -#define MILLISECONDS_8 8000 -#define MILLISECONDS_16 16000 -#define MILLISECONDS_20 20000 -#define MILLISECONDS_32 32000 -#define MILLISECONDS_64 64000 -#define MILLISECONDS_128 128000 - // Setting the timeout too high means input will be laggy as you // are starving the input polling. Setting it too low means using // energy for no purpose. Probably best if set similar to the // frame rate of the application -#define STDIO_TIMEOUT MILLISECONDS_32 +#define STDIO_TIMEOUT 32 extern device_info_t g_device_info; +extern device_opts_t g_opts; //============================================================================= // raw comms with host app @@ -407,6 +400,14 @@ void receive_crash() //--------------------------------------------------------- void render(driver_data_t* p_data) { + // Setup FPS calc + static int64_t start_real = 0; + static int64_t time_remaining = -1; + static clock_t render_fps = 0; + static uint32_t frames = 0; + + clock_t begin_frame = clock(); + // prep the id to the root scene sid_t id; id.p_data = "_root_"; @@ -428,6 +429,27 @@ void render(driver_data_t* p_data) } device_end_render(p_data); + clock_t end_frame = clock(); + clock_t delta_ticks = end_frame - begin_frame; + + if ((g_opts.debug_fps > 1) && (delta_ticks > 0)) { + render_fps = CLOCKS_PER_SEC / delta_ticks; + log_debug("render_fps (cpu time): %d", render_fps); + } + + frames++; + + int64_t end_real = monotonic_time(); + int64_t delta_real = (end_real - start_real); + start_real = end_real; + time_remaining -= delta_real; + + if ((g_opts.debug_fps > 0) && (time_remaining <= 0)) { + log_info("real_fps: %d", frames); + start_real = monotonic_time(); + time_remaining = 1000; + frames = 0; + } // all done send_ready(); 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..990a44a 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: :integer, default: 0], antialias: [type: :boolean, default: true], calibration: [ type: {:custom, __MODULE__, :validate_calibration, []}, @@ -214,6 +215,7 @@ defmodule Scenic.Driver.Local do end {:ok, debugger} = Keyword.fetch(opts, :debugger) + {:ok, debug_fps} = Keyword.fetch(opts, :debug_fps) {:ok, layer} = Keyword.fetch(opts, :layer) {:ok, opacity} = Keyword.fetch(opts, :opacity) @@ -227,7 +229,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..ad9dc55 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: 0, antialias: true, calibration: [{"calibration_name", {{0, 0, 0}, {0, 0, 0}}}], position: [