AmendHub

Download:

jcs

/

subtext

/

amendments

/

5

console: Add a speed hack to pass in cell hints

Rather than having to scan the entire cell array, just update the
cells in the hints

jcs made amendment 5 over 2 years ago
--- console.c Tue Nov 30 15:07:20 2021 +++ console.c Tue Nov 30 21:55:45 2021 @@ -15,6 +15,7 @@ */ #include <stdio.h> +#include <string.h> #include "subtext.h" #include "console.h" @@ -30,7 +31,7 @@ struct node_funcs console_node_funcs = { console_output, }; -void console_redraw(struct console *console); +void console_redraw(struct console *console, short numhints, short *hints); void console_parse_csi(struct console *console); struct console * @@ -43,6 +44,7 @@ console_init(void) short padding = 20; console = xmalloczero(sizeof(struct console)); + memset(console->chars, ' ', sizeof(console->chars)); bounds.left = (padding / 2); bounds.top = screenBits.bounds.top + (GetMBarHeight() * 2) - 1 + @@ -106,7 +108,7 @@ console_update(struct console *console, EventRecord *e switch (what) { case -1: case updateEvt: - console_redraw(console); + console_redraw(console, -1, NULL); //browser_update_menu(browser); UpdtControl(console->win, console->win->visRgn); @@ -140,6 +142,8 @@ console_output(struct session *session) { struct console *console = (struct console *)session->cookie; short n, len, cursor, iac = 0; + short hints[100]; + short nhints = 0; if (session->obuflen == 0) return 0; @@ -148,6 +152,7 @@ console_output(struct session *session) console->cursor_column; console->attrs[cursor] |= ATTR_DIRTY; console->attrs[cursor] &= ~ATTR_CURSOR; + hints[nhints++] = cursor; for (n = 0; n < session->obuflen; n++) { if (console->cursor_column >= console->ncolumns && @@ -198,6 +203,10 @@ console_output(struct session *session) console->chars[cursor] = session->obuf[n]; console->attrs[cursor] |= ATTR_DIRTY; console->cursor_column++; + if (nhints != -1 && nhints < sizeof(hints) - 1) + hints[nhints++] = cursor; + else + nhints = -1; break; } } @@ -210,7 +219,11 @@ output_done: cursor = (console->cursor_line * console->ncolumns) + console->cursor_column; console->attrs[cursor] |= (ATTR_DIRTY | ATTR_CURSOR); - console_redraw(console); + if (nhints != -1 && nhints < sizeof(hints) - 1) + hints[nhints++] = cursor; + else if (nhints == -1) + nhints = 0; + console_redraw(console, nhints, hints); return len; } @@ -224,20 +237,43 @@ console_input(struct session *session) } void -console_redraw(struct console *console) +console_redraw(struct console *console, short nhints, short hints[]) { Rect cursor; - short n, line = 0, column = 0; + short n, cell, line = 0, column = 0; + short nsize; TextFont(monaco); TextSize(9); - for (n = 0; n < sizeof(console->chars); n++) { - if (!(console->attrs[n] & ATTR_DIRTY)) - continue; + if (nhints > 0) + nsize = nhints; + else { + nsize = sizeof(console->chars); + SetCursor(*(GetCursor(watchCursor))); + } + + for (n = 0; n < nsize; n++) { + if (nhints > 0) { + cell = hints[n]; + } else { + if (nhints == 0 && !(console->attrs[n] & ATTR_DIRTY)) + continue; + + /* + * speed hack: if doing a whole-window update, no need to + * redraw blank space + */ + if (nhints == -1 && console->chars[n] == ' ' && + !(console->attrs[n] & ATTR_CURSOR)) + continue; + + cell = n; + } - line = ((n + 1) / console->ncolumns); - column = n - (line * console->ncolumns); + line = ((cell + 1) / console->ncolumns); + column = cell - (line * console->ncolumns); + cursor.left = FONT_WIDTH + ((console->win->portRect.left + column) * FONT_WIDTH); cursor.top = FONT_WIDTH + ((console->win->portRect.top + line) * @@ -248,12 +284,17 @@ console_redraw(struct console *console) FillRect(&cursor, white); MoveTo(cursor.left, cursor.top + FONT_HEIGHT - 2); - DrawChar(console->chars[n]); + DrawChar(console->chars[cell]); console->attrs[n] &= ~ATTR_DIRTY; - if (console->attrs[n] & ATTR_CURSOR) + if (console->attrs[cell] & ATTR_CURSOR) InvertRect(&cursor); } + + ValidRect(&console->win->portRect); + + if (nhints <= 0) + SetCursor(&arrow); } void --- main.c Tue Nov 30 14:45:17 2021 +++ main.c Tue Nov 30 21:57:29 2021 @@ -70,13 +70,13 @@ main(void) strcpy(config.name, "Kludge BBS"); strcpy(config.hostname, "klud.ge"); - telnet_init(); cur_console = console_init(); + telnet_init(); while (!quitting) { telnet_idle(); uthread_coordinate(); - WaitNextEvent(everyEvent, &event, 1L, 0L); + WaitNextEvent(everyEvent, &event, 1, 0); switch (event.what) { case nullEvent: --- session.c Sun Nov 28 21:25:13 2021 +++ session.c Tue Nov 30 20:15:38 2021 @@ -93,8 +93,10 @@ session_input_char(struct session *session) { char ret; - while (session->ibuflen == 0) + while (session->ibuflen == 0) { session->node_funcs->input(session); + uthread_yield(); + } ret = session->ibuf[0]; if (session->ibuflen == 1)