Skip to content

Commit

Permalink
debug_fps: Add configurable option
Browse files Browse the repository at this point in the history
  • Loading branch information
ringlej committed Mar 19, 2024
1 parent 4a2073b commit 9ae099b
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 10 deletions.
11 changes: 6 additions & 5 deletions c_src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand All @@ -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();
Expand Down
9 changes: 5 additions & 4 deletions c_src/scenic/comms.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 > 1) && (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++;
Expand All @@ -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 > 0) && (time_remaining <= 0)) {
log_info("real_fps: %d", frames);
start_real = monotonic_time();
time_remaining = 1000;
frames = 0;
Expand Down
1 change: 1 addition & 0 deletions c_src/scenic/scenic_types.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
4 changes: 3 additions & 1 deletion lib/driver.ex
Original file line number Diff line number Diff line change
Expand Up @@ -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, []},
Expand Down Expand Up @@ -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)

Expand All @@ -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
Expand Down
1 change: 1 addition & 0 deletions test/driver_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -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: [
Expand Down

0 comments on commit 9ae099b

Please sign in to comment.