[qwaq] Add a synchronous printf command

This puts a print command (to Sys_Printf) into the queue making it
easier to check command sequences since regular printf is asynchronous
with the stream.
This commit is contained in:
Bill Currie 2020-03-30 21:58:06 +09:00
parent 5bc57518b7
commit dbbdb31cb1
3 changed files with 45 additions and 5 deletions

View file

@ -55,6 +55,7 @@
#define CMD_SIZE(x) sizeof(x)/sizeof(x[0])
typedef enum qwaq_commands_e {
qwaq_cmd_syncprint,
qwaq_cmd_newwin,
qwaq_cmd_delwin,
qwaq_cmd_getwrect,
@ -89,6 +90,7 @@ typedef enum qwaq_commands_e {
} qwaq_commands;
static const char *qwaq_command_names[]= {
"syncprint",
"newwin",
"delwin",
"getwrect",
@ -118,8 +120,8 @@ static const char *qwaq_command_names[]= {
"mvwblit_line",
"wresize",
"resizeterm",
"mvwhline"
"mvwvline"
"mvwhline",
"mvwvline",
};
static window_t *
@ -280,6 +282,15 @@ qwaq_wait_result (qwaq_resources_t *res, int *result, int cmd, unsigned len)
pthread_mutex_unlock (&res->results_cond.mut);
}
static void
cmd_syncprint (qwaq_resources_t *res)
{
int string_id = RB_PEEK_DATA (res->command_queue, 2);
Sys_Printf ("%s\n", res->strings[string_id].str);
release_string (res, string_id);
}
static void
cmd_newwin (qwaq_resources_t *res)
{
@ -636,10 +647,14 @@ dump_command (qwaq_resources_t *res, int len)
if (0) {
qwaq_commands cmd = RB_PEEK_DATA (res->command_queue, 0);
Sys_Printf ("%s[%d]", qwaq_command_names[cmd], len);
for (int i = 2; i < len; i++) {
Sys_Printf (" %d", RB_PEEK_DATA (res->command_queue, i));
if (cmd == qwaq_cmd_syncprint) {
Sys_Printf (" ");
} else {
for (int i = 2; i < len; i++) {
Sys_Printf (" %d", RB_PEEK_DATA (res->command_queue, i));
}
Sys_Printf ("\n");
}
Sys_Printf ("\n");
}
}
@ -682,6 +697,9 @@ process_commands (qwaq_resources_t *res)
dump_command (res, len);
qwaq_commands cmd = RB_PEEK_DATA (res->command_queue, 0);
switch (cmd) {
case qwaq_cmd_syncprint:
cmd_syncprint (res);
break;
case qwaq_cmd_newwin:
cmd_newwin (res);
break;
@ -829,6 +847,25 @@ bi_shutdown (void *_pr)
}
}
static void
bi_syncprintf (progs_t *pr)
{
qwaq_resources_t *res = PR_Resources_Find (pr, "qwaq");
const char *fmt = P_GSTRING (pr, 0);
int count = pr->pr_argc - 1;
pr_type_t **args = pr->pr_params + 1;
int string_id = acquire_string (res);
dstring_t *print_buffer = res->strings + string_id;
int command[] = { qwaq_cmd_syncprint, 0, string_id };
command[1] = CMD_SIZE(command);
dstring_clearstr (print_buffer);
PR_Sprintf (pr, print_buffer, "mvwaddstr", fmt, count, args);
qwaq_submit_command (res, command);
}
static void
bi_newwin (progs_t *pr)
{
@ -1894,6 +1931,7 @@ bi_qwaq_clear (progs_t *pr, void *data)
static builtin_t builtins[] = {
{"initialize", bi_initialize, -1},
{"syncprintf", bi_syncprintf, -1},
{"create_window", bi_newwin, -1},
{"destroy_window", bi_delwin, -1},
{"getwrect", bi_getwrect, -1},

View file

@ -87,6 +87,7 @@ typedef struct panel_s *panel_t;
extern window_t stdscr;
void initialize (void);
void syncprintf (string fnt, ...);
window_t create_window (int xpos, int ypos, int xlen, int ylen);
void destroy_window (window_t win);
void mvwprintf (window_t win, int x, int y, string fmt, ...);

View file

@ -179,6 +179,7 @@ static TextContext *screen;
window_t stdscr = (window_t) 1;
void initialize (void) = #0;
void syncprintf (string fnt, ...) = #0;
window_t create_window (int xpos, int ypos, int xlen, int ylen) = #0;
void destroy_window (window_t win) = #0;
void mvwprintf (window_t win, int x, int y, string fmt, ...) = #0;