diff --git a/src/demo/demo.h b/src/demo/demo.h index 0e5becd6f..a05ecc55d 100644 --- a/src/demo/demo.h +++ b/src/demo/demo.h @@ -89,6 +89,7 @@ demo_getc_blocking(struct notcurses* nc, ncinput* ni){ /*-------------------------------time helpers----------------------------*/ #define GIG 1000000000ul +#define MAXSLEEP (GIG / 80) // nanoseconds static inline uint64_t timespec_to_ns(const struct timespec* ts){ diff --git a/src/demo/hud.c b/src/demo/hud.c index 8e3407d88..53d9fc158 100644 --- a/src/demo/hud.c +++ b/src/demo/hud.c @@ -26,6 +26,8 @@ static int plot_grab_y = -1; // position of the plot *when grab started* static int plot_pos_y; +#define FPSHZ 10 + // how many columns for runtime? #define HUD_ROWS (3 + 2) // 2 for borders static const int HUD_COLS = 23 + 2; // 2 for borders @@ -513,7 +515,7 @@ demo_nanosleep_abstime_ns(struct notcurses* nc, uint64_t deadline){ clock_gettime(CLOCK_MONOTONIC, &now); while(deadline > timespec_to_ns(&now)){ fsleep.tv_sec = 0; - fsleep.tv_nsec = GIG / 100; + fsleep.tv_nsec = MAXSLEEP; if(deadline - timespec_to_ns(&now) < GIG / 100){ fsleep.tv_nsec = deadline - timespec_to_ns(&now); } @@ -563,7 +565,7 @@ int demo_render(struct notcurses* nc){ if(!plot_hidden){ ncplane_move_top(ncuplot_plane(plot)); } - uint64_t ns = (timespec_to_ns(&ts) - plottimestart) / (GIG / 10); + uint64_t ns = (timespec_to_ns(&ts) - plottimestart) / (GIG / FPSHZ); ncuplot_add_sample(plot, ns, 1); } if(menu){ diff --git a/src/demo/input.c b/src/demo/input.c index 3cbc8f556..01570754c 100644 --- a/src/demo/input.c +++ b/src/demo/input.c @@ -47,20 +47,22 @@ handle_mouse(const ncinput* ni){ // absolute deadline, so convert it up. char32_t demo_getc(struct notcurses* nc, const struct timespec* ts, ncinput* ni){ struct timespec now; + clock_gettime(CLOCK_REALTIME, &now); uint64_t ns; - struct timespec abstime; // yes, i'd like CLOCK_MONOTONIC too, but pthread_cond_timedwait() is based off // of crappy CLOCK_REALTIME :/ // abstime shouldn't be further out than our maximum sleep time -- this can // lead to 0 frames output during the wait (happening now with zoo FIXME) if(ts){ - clock_gettime(CLOCK_REALTIME, &now); - ns = timespec_to_ns(&now) + timespec_to_ns(ts); - ns_to_timespec(ns, &abstime); + ns = timespec_to_ns(ts); }else{ - abstime.tv_sec = ~0; - abstime.tv_nsec = ~0; + ns = MAXSLEEP; + } + if(ns > MAXSLEEP){ + ns = MAXSLEEP; } + struct timespec abstime; + ns_to_timespec(ns + timespec_to_ns(&now), &abstime); bool handoff = false; // does the input go back to the user? char32_t id; do{