diff options
author | Malfurious <m@lfurio.us> | 2024-05-07 04:42:24 -0400 |
---|---|---|
committer | Malfurious <m@lfurio.us> | 2024-05-08 05:57:59 -0400 |
commit | 27bb9ccc06b715ea8f76c269e8bc2fab03110155 (patch) | |
tree | cc159f7474a1043ec733088326dcdeaec2623b9e | |
parent | 635cfa9d02cff374b1e8cff1493aef178f73cfab (diff) | |
download | misplays-27bb9ccc06b715ea8f76c269e8bc2fab03110155.tar.gz misplays-27bb9ccc06b715ea8f76c269e8bc2fab03110155.zip |
Previously, the test UI logic would constantly regenerate and print the
screen's contents every iteration of the main processing loop to naively
ensure that changes to the underlying system were reflected immediately.
Sometimes, this would result in a screen flicker due to the rapid
clearing and printing.
This makes the UI a bit smarter about when refreshes occur, by
monitoring activity results from the debugger and console modules in
addition to user input. This should improve the screen flicker
performance.
This also addresses an issue selecting text on the screen, which was
previously not possible due to the rapid refreshing as well.
Signed-off-by: Malfurious <m@lfurio.us>
-rw-r--r-- | console.c | 9 | ||||
-rw-r--r-- | console.h | 2 | ||||
-rw-r--r-- | debugger.c | 4 | ||||
-rw-r--r-- | debugger.h | 2 | ||||
-rw-r--r-- | misplays.c | 29 |
5 files changed, 32 insertions, 14 deletions
@@ -55,11 +55,12 @@ void console_leave(struct console *cons, PANEL *pan) { cbreak(); } -void console_update(struct console *cons, PANEL *pan) { - ssize_t nb; +int console_update(struct console *cons, PANEL *pan) { char c; + int did_read = 0; - while ((nb = read(cons->master, &c, 1)) > 0) { + while (read(cons->master, &c, 1) > 0) { + did_read = 1; if (!cons->isesc) { if (c == 0x1b) { cons->isesc = 1; @@ -72,6 +73,8 @@ void console_update(struct console *cons, PANEL *pan) { } } } + + return did_read; } void console_input(struct console *cons, int ch) { @@ -11,7 +11,7 @@ extern int console_init(struct console *cons); extern int console_deinit(struct console *cons); extern void console_enter(struct console *cons, PANEL *pan); extern void console_leave(struct console *cons, PANEL *pan); -extern void console_update(struct console *cons, PANEL *pan); +extern int console_update(struct console *cons, PANEL *pan); extern void console_input(struct console *cons, int ch); extern int console_configslave(struct console *cons); @@ -546,7 +546,7 @@ int dbg_free(struct thread *th) { return -1; } -void dbg_sync(struct process *proc) { +int dbg_sync(struct process *proc) { struct thread *acted = NULL; struct list *threads = &proc->threads; @@ -566,6 +566,8 @@ void dbg_sync(struct process *proc) { capture_state(proc); resume_threads(proc); } + + return acted != NULL; } int dbg_intr(struct thread *th) { @@ -67,7 +67,7 @@ extern struct process *dbg_attach(pid_t pid, int child); extern void dbg_detach(struct process *proc); extern int dbg_free(struct thread *th); -extern void dbg_sync(struct process *proc); +extern int dbg_sync(struct process *proc); extern int dbg_intr(struct thread *th); extern int dbg_cont(struct thread *th); @@ -193,10 +193,12 @@ static void info_update(struct thread *th, PANEL *pan) { disasm(th, pan); } -static void wait_all_threads(struct list *processes) { +static int wait_all_threads(struct list *processes) { + int action = 0; for (struct process *proc = processes->head; proc != processes->end; proc = proc->next) { - dbg_sync(proc); + action |= dbg_sync(proc); } + return action; } static void layout(struct list *processes, struct thread *th) { @@ -286,14 +288,11 @@ int main(int argc, char **argv) { int quit = 0; int mode = 0; + int dirty = 1; + int pressed = 0; while (!quit) { - wait_all_threads(&processes); - layout(&processes, th); - console_update(&cons, right); - info_update(th, left); - cursupdate(); - int ch = getch(); + pressed = 1; if (mode == 0) { switch (ch) { @@ -406,6 +405,9 @@ int main(int argc, char **argv) { b->enabled = en; b->tid = tid; break; + case ERR: + pressed = 0; + break; } } else { switch (ch) { @@ -417,12 +419,23 @@ int main(int argc, char **argv) { console_leave(&cons, right); break; case ERR: + pressed = 0; break; default: console_input(&cons, ch); break; } } + + dirty |= wait_all_threads(&processes); + dirty |= console_update(&cons, right); + + if (dirty || pressed) { + layout(&processes, th); + info_update(th, left); + cursupdate(); + dirty = 0; + } } for (struct process *p = processes.head; p != processes.end; p = p->next) { |