Browse Source

Remove source text redundancy for deadline timer comparisons

Makes it easier to read, I think.
master
cancel 5 years ago
parent
commit
735491fe02
  1. 77
      tui_main.c

77
tui_main.c

@ -3553,6 +3553,8 @@ event_loop:;
if (drew_any) if (drew_any)
doupdate(); doupdate();
double secs_to_d = ged_secs_to_deadline(&t.ged); double secs_to_d = ged_secs_to_deadline(&t.ged);
#define DEADTIME(_millisecs, _new_timeout) \
else if (secs_to_d < ms_to_sec(_millisecs)) new_timeout = _new_timeout;
int new_timeout; int new_timeout;
// These values are tuned to work OK with the normal scheduling behavior // These values are tuned to work OK with the normal scheduling behavior
// on Linux, Mac, and Windows. All of the usual caveats of trying to // on Linux, Mac, and Windows. All of the usual caveats of trying to
@ -3563,55 +3565,34 @@ event_loop:;
// here are bad, or it's some OS that behaves differently than expected, // here are bad, or it's some OS that behaves differently than expected,
// this won't be very good. But there's not really much we can do about // this won't be very good. But there's not really much we can do about
// it, and it's better than doing nothing and burning up the CPU! // it, and it's better than doing nothing and burning up the CPU!
if (t.strict_timing) { if (t.strict_timing) { // clang-format off
if (secs_to_d < ms_to_sec(0.5)) { if (false) {}
new_timeout = 0; // "If there's less than 1.5 milliseconds to the deadline, use a curses
} else if (secs_to_d < ms_to_sec(1.5)) { // timeout value of 0."
new_timeout = 0; DEADTIME( 1.5, 0)
} else if (secs_to_d < ms_to_sec(3.0)) { DEADTIME( 3.0, 1)
new_timeout = 1; DEADTIME( 5.0, 2)
} else if (secs_to_d < ms_to_sec(5.0)) { DEADTIME( 7.0, 3)
new_timeout = 2; DEADTIME( 9.0, 4)
} else if (secs_to_d < ms_to_sec(7.0)) { DEADTIME( 11.0, 5)
new_timeout = 3; DEADTIME( 13.0, 6)
} else if (secs_to_d < ms_to_sec(9.0)) { DEADTIME( 15.0, 7)
new_timeout = 4; DEADTIME( 25.0, 12)
} else if (secs_to_d < ms_to_sec(11.0)) { DEADTIME( 50.0, 20)
new_timeout = 5; DEADTIME(100.0, 40)
} else if (secs_to_d < ms_to_sec(13.0)) { else new_timeout = 50;
new_timeout = 6;
} else if (secs_to_d < ms_to_sec(15.0)) {
new_timeout = 7;
} else if (secs_to_d < ms_to_sec(25.0)) {
new_timeout = 12;
} else if (secs_to_d < ms_to_sec(50.0)) {
new_timeout = 20;
} else if (secs_to_d < ms_to_sec(100.0)) {
new_timeout = 40;
} else {
new_timeout = 50;
}
} else { } else {
if (secs_to_d < ms_to_sec(0.5)) { if (false) {}
new_timeout = 0; DEADTIME( 1.0, 0)
} else if (secs_to_d < ms_to_sec(1.0)) { DEADTIME( 2.0, 1)
new_timeout = 0; DEADTIME( 7.0, 2)
} else if (secs_to_d < ms_to_sec(2.0)) { DEADTIME( 15.0, 5)
new_timeout = 1; DEADTIME( 25.0, 10)
} else if (secs_to_d < ms_to_sec(7.0)) { DEADTIME( 50.0, 20)
new_timeout = 2; DEADTIME(100.0, 40)
} else if (secs_to_d < ms_to_sec(15.0)) { else new_timeout = 50;
new_timeout = 5; } // clang-format on
} else if (secs_to_d < ms_to_sec(25.0)) { #undef DEADTIME
new_timeout = 10;
} else if (secs_to_d < ms_to_sec(50.0)) {
new_timeout = 20;
} else if (secs_to_d < ms_to_sec(100.0)) {
new_timeout = 40;
} else {
new_timeout = 50;
}
}
if (new_timeout != cur_timeout) { if (new_timeout != cur_timeout) {
wtimeout(stdscr, new_timeout); wtimeout(stdscr, new_timeout);
cur_timeout = new_timeout; cur_timeout = new_timeout;

Loading…
Cancel
Save