Browse Source

Change main event loop to use label/goto

Save a level of nesting and mental bookkeeping. The control flow was
already jumping within and outside of the loop, so we aren't making this
any more complicated than it already was -- in fact, it's more simple,
because now we also don't have to remember that we're in a 'for' loop.
master
cancel 5 years ago
parent
commit
8362d2862d
  1. 22
      tui_main.c

22
tui_main.c

@ -3469,9 +3469,8 @@ int main(int argc, char **argv) {
tui_restart_osc_udp_if_enabled(&t);
WINDOW *cont_window = NULL;
int key = KEY_RESIZE;
WINDOW *cont_window = NULL; // No window yet, wait for resize
int key = KEY_RESIZE; // Make first event a resize
wtimeout(stdscr, 0);
int cur_timeout = 0;
Usz bracketed_paste_starting_x = 0, bracketed_paste_y = 0,
@ -3482,7 +3481,8 @@ int main(int argc, char **argv) {
// Send initial BPM
send_num_message(t.ged.oosc_dev, "/orca/bpm", (I32)t.ged.bpm);
for (;;) {
// Main loop. Process events as they arrive.
event_loop:
switch (key) {
case ERR: {
ged_do_stuff(&t.ged);
@ -3632,8 +3632,7 @@ int main(int argc, char **argv) {
delwin(cont_window);
}
wclear(stdscr);
cont_window =
derwin(stdscr, content_h, content_w, content_y, content_x);
cont_window = derwin(stdscr, content_h, content_w, content_y, content_x);
t.ged.is_draw_dirty = true;
}
// We might do this once soon after startup if the user specified neither
@ -3646,8 +3645,7 @@ int main(int argc, char **argv) {
Usz new_field_h, new_field_w;
if (tui_suggest_nice_grid_size(&t, content_h, content_w, &new_field_h,
&new_field_w)) {
field_init_fill(&t.ged.field, (Usz)new_field_h, (Usz)new_field_w,
'.');
field_init_fill(&t.ged.field, (Usz)new_field_h, (Usz)new_field_w, '.');
mbuf_reusable_ensure_size(&t.ged.mbuf_r, new_field_h, new_field_w);
ged_make_cursor_visible(&t.ged);
} else {
@ -3734,8 +3732,8 @@ int main(int argc, char **argv) {
if (bracketed_paste_y < t.ged.field.height &&
bracketed_paste_x < t.ged.field.width) {
gbuffer_poke(t.ged.field.buffer, t.ged.field.height,
t.ged.field.width, bracketed_paste_y,
bracketed_paste_x, cleaned);
t.ged.field.width, bracketed_paste_y, bracketed_paste_x,
cleaned);
// Could move this out one level if we wanted the final selection
// size to reflect even the pasted area which didn't fit on the
// grid.
@ -4004,13 +4002,13 @@ int main(int argc, char **argv) {
#endif
break;
}
next_getch:
next_getch:
key = wgetch(stdscr);
if (cur_timeout != 0) {
wtimeout(stdscr, 0);
cur_timeout = 0;
}
}
goto event_loop;
quit:
ged_stop_all_sustained_notes(&t.ged);
qnav_deinit();

Loading…
Cancel
Save