mirror of
https://git.code.sf.net/p/quake/quakeforge
synced 2025-02-17 09:22:43 +00:00
[qwaq] Convert remaining functions to command queue
Now that the initial prototype seems to be working well, it's time to implement more commands. I might have to do some wrappers for actual command writing (and result reading) as it looks like there will be a lot of nearly identical code.
This commit is contained in:
parent
513c808875
commit
0119660b01
2 changed files with 80 additions and 23 deletions
|
@ -32,5 +32,7 @@ int main (int argc, string *argv)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} while (ch != 'q' && ch != 'Q');
|
} while (ch != 'q' && ch != 'Q');
|
||||||
|
destroy_window (win);
|
||||||
|
get_event (&event);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
|
@ -265,7 +265,6 @@ create_window (qwaq_resources_t *res)
|
||||||
keypad (window->win, TRUE);
|
keypad (window->win, TRUE);
|
||||||
|
|
||||||
int window_id = window_index (res, window);
|
int window_id = window_index (res, window);
|
||||||
|
|
||||||
int cmd_result[] = { qwaq_cmd_create_window, window_id };
|
int cmd_result[] = { qwaq_cmd_create_window, window_id };
|
||||||
|
|
||||||
// loop
|
// loop
|
||||||
|
@ -274,6 +273,44 @@ create_window (qwaq_resources_t *res)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
destroy_window (qwaq_resources_t *res)
|
||||||
|
{
|
||||||
|
int window_id = RB_PEEK_DATA (res->command_queue, 2);
|
||||||
|
|
||||||
|
window_t *window = get_window (res, __FUNCTION__, window_id);
|
||||||
|
delwin (window->win);
|
||||||
|
window_free (res, window);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
create_panel (qwaq_resources_t *res)
|
||||||
|
{
|
||||||
|
int window_id = RB_PEEK_DATA (res->command_queue, 2);
|
||||||
|
|
||||||
|
window_t *window = get_window (res, __FUNCTION__, window_id);
|
||||||
|
panel_t *panel = panel_new (res);
|
||||||
|
panel->panel = new_panel (window->win);
|
||||||
|
|
||||||
|
int panel_id = panel_index (res, panel);
|
||||||
|
int cmd_result[] = { qwaq_cmd_create_panel, panel_id };
|
||||||
|
|
||||||
|
// loop
|
||||||
|
if (RB_SPACE_AVAILABLE (res->results) >= CMD_SIZE (cmd_result)) {
|
||||||
|
RB_WRITE_DATA (res->results, cmd_result, CMD_SIZE (cmd_result));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
destroy_panel (qwaq_resources_t *res)
|
||||||
|
{
|
||||||
|
int panel_id = RB_PEEK_DATA (res->command_queue, 2);
|
||||||
|
|
||||||
|
panel_t *panel = get_panel (res, __FUNCTION__, panel_id);
|
||||||
|
del_panel (panel->panel);
|
||||||
|
panel_free (res, panel);
|
||||||
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
move_print (qwaq_resources_t *res)
|
move_print (qwaq_resources_t *res)
|
||||||
{
|
{
|
||||||
|
@ -297,10 +334,13 @@ process_commands (qwaq_resources_t *res)
|
||||||
create_window (res);
|
create_window (res);
|
||||||
break;
|
break;
|
||||||
case qwaq_cmd_destroy_window:
|
case qwaq_cmd_destroy_window:
|
||||||
|
destroy_window (res);
|
||||||
break;
|
break;
|
||||||
case qwaq_cmd_create_panel:
|
case qwaq_cmd_create_panel:
|
||||||
|
create_panel (res);
|
||||||
break;
|
break;
|
||||||
case qwaq_cmd_destroy_panel:
|
case qwaq_cmd_destroy_panel:
|
||||||
|
destroy_panel (res);
|
||||||
break;
|
break;
|
||||||
case qwaq_cmd_mvwprint:
|
case qwaq_cmd_mvwprint:
|
||||||
move_print (res);
|
move_print (res);
|
||||||
|
@ -411,31 +451,56 @@ static void
|
||||||
bi_destroy_window (progs_t *pr)
|
bi_destroy_window (progs_t *pr)
|
||||||
{
|
{
|
||||||
qwaq_resources_t *res = PR_Resources_Find (pr, "qwaq");
|
qwaq_resources_t *res = PR_Resources_Find (pr, "qwaq");
|
||||||
window_t *window = get_window (res, __FUNCTION__, P_INT (pr, 0));
|
int window_id = P_INT (pr, 0);
|
||||||
delwin (window->win);
|
int command[] = { qwaq_cmd_destroy_window, 0, window_id, };
|
||||||
window->win = 0;
|
|
||||||
window_free (res, window);
|
if (get_window (res, __FUNCTION__, window_id)) {
|
||||||
|
command[1] = CMD_SIZE(command);
|
||||||
|
|
||||||
|
if (RB_SPACE_AVAILABLE (res->command_queue) >= CMD_SIZE(command)) {
|
||||||
|
RB_WRITE_DATA (res->command_queue, command, CMD_SIZE(command));
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
bi_create_panel (progs_t *pr)
|
bi_create_panel (progs_t *pr)
|
||||||
{
|
{
|
||||||
qwaq_resources_t *res = PR_Resources_Find (pr, "qwaq");
|
qwaq_resources_t *res = PR_Resources_Find (pr, "qwaq");
|
||||||
window_t *window = get_window (res, __FUNCTION__, P_INT (pr, 0));
|
int window_id = P_INT (pr, 0);
|
||||||
|
int command[] = { qwaq_cmd_create_panel, 0, window_id, };
|
||||||
|
|
||||||
panel_t *panel = panel_new (res);
|
if (get_window (res, __FUNCTION__, window_id)) {
|
||||||
panel->panel = new_panel (window->win);
|
command[1] = CMD_SIZE(command);
|
||||||
R_INT (pr) = panel_index (res, panel);
|
|
||||||
|
if (RB_SPACE_AVAILABLE (res->command_queue) >= CMD_SIZE(command)) {
|
||||||
|
RB_WRITE_DATA (res->command_queue, command, CMD_SIZE(command));
|
||||||
|
}
|
||||||
|
|
||||||
|
// locking and loop until id is correct
|
||||||
|
if (RB_DATA_AVAILABLE (res->results)
|
||||||
|
&& RB_PEEK_DATA (res->results, 0) == qwaq_cmd_create_panel) {
|
||||||
|
int cmd_result[2]; // should results have a size?
|
||||||
|
RB_READ_DATA (res->results, cmd_result, CMD_SIZE (cmd_result));
|
||||||
|
R_INT (pr) = cmd_result[1];
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
bi_destroy_panel (progs_t *pr)
|
bi_destroy_panel (progs_t *pr)
|
||||||
{
|
{
|
||||||
qwaq_resources_t *res = PR_Resources_Find (pr, "qwaq");
|
qwaq_resources_t *res = PR_Resources_Find (pr, "qwaq");
|
||||||
panel_t *panel = get_panel (res, __FUNCTION__, P_INT (pr, 0));
|
int panel_id = P_INT (pr, 0);
|
||||||
del_panel (panel->panel);
|
int command[] = { qwaq_cmd_destroy_panel, 0, panel_id, };
|
||||||
panel->panel = 0;
|
|
||||||
panel_free (res, panel);
|
if (get_panel (res, __FUNCTION__, panel_id)) {
|
||||||
|
command[1] = CMD_SIZE(command);
|
||||||
|
|
||||||
|
if (RB_SPACE_AVAILABLE (res->command_queue) >= CMD_SIZE(command)) {
|
||||||
|
RB_WRITE_DATA (res->command_queue, command, CMD_SIZE(command));
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
|
@ -467,15 +532,6 @@ bi_mvwprintf (progs_t *pr)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
|
||||||
bi_wgetch (progs_t *pr)
|
|
||||||
{
|
|
||||||
qwaq_resources_t *res = PR_Resources_Find (pr, "qwaq");
|
|
||||||
window_t *window = get_window (res, __FUNCTION__, P_INT (pr, 0));
|
|
||||||
|
|
||||||
R_INT (pr) = wgetch (window->win);
|
|
||||||
}
|
|
||||||
|
|
||||||
static void
|
static void
|
||||||
bi_get_event (progs_t *pr)
|
bi_get_event (progs_t *pr)
|
||||||
{
|
{
|
||||||
|
@ -525,7 +581,6 @@ static builtin_t builtins[] = {
|
||||||
{"create_panel", bi_create_panel, -1},
|
{"create_panel", bi_create_panel, -1},
|
||||||
{"destroy_panel", bi_destroy_panel, -1},
|
{"destroy_panel", bi_destroy_panel, -1},
|
||||||
{"mvwprintf", bi_mvwprintf, -1},
|
{"mvwprintf", bi_mvwprintf, -1},
|
||||||
{"wgetch", bi_wgetch, -1},
|
|
||||||
{"get_event", bi_get_event, -1},
|
{"get_event", bi_get_event, -1},
|
||||||
{0}
|
{0}
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in a new issue