[qwaq] Create a commandline-only version of qwaq

qwaq-curses has its place, but its use for running vkgen was really a
placeholder because I didn't feel like sorting out the different
initialization requirements at the time. qwaq-cmd has the (currently
unnecessary) threading power of qwaq-curses, but doesn't include any UI
stuff and thus doesn't need curses. The work also paves the way for
qwaq-x11 to become a proper engine (though sorting out its init will be
taken care of later).

Fixes #15.
This commit is contained in:
Bill Currie 2021-07-06 11:55:29 +09:00
parent 490cf966f9
commit ae58a8ba5d
10 changed files with 270 additions and 95 deletions

View file

@ -69,7 +69,7 @@ XMMS_LIBS= @XMMS_LIBS@
PAK=$(top_builddir)/pak$(EXEEXT) PAK=$(top_builddir)/pak$(EXEEXT)
QFCC_DEP=qfcc$(EXEEXT) QFCC_DEP=qfcc$(EXEEXT)
QFCC=$(top_builddir)/$(QFCC_DEP) QFCC=$(top_builddir)/$(QFCC_DEP)
QWAQ_CURSES=$(top_builddir)/ruamoko/qwaq/qwaq-curses$(EXEEXT) QWAQ=$(top_builddir)/ruamoko/qwaq/qwaq-cmd$(EXEEXT)
GZ=@progs_gz@ GZ=@progs_gz@

View file

@ -276,8 +276,13 @@ if test "x$ENABLE_tools_qfvis" = xyes; then
QF_NEED(libs,[util]) QF_NEED(libs,[util])
fi fi
if test "x$ENABLE_tools_qwaq" = xyes; then if test "x$ENABLE_tools_qwaq" = xyes; then
if test "x$HAVE_PANEL" = xyes -a "x$HAVE_PTHREAD" = xyes; then if test "x$HAVE_NCURSES" == "xyes" -a "x$HAVE_PANEL" = xyes -a "x$HAVE_PTHREAD" = xyes; then
QWAQ_TARGETS="$QWAQ_TARGETS ruamoko/qwaq/qwaq-curses\$(EXEEXT)" QWAQ_TARGETS="$QWAQ_TARGETS ruamoko/qwaq/qwaq-curses\$(EXEEXT)"
dnl FIXME move key code (maybe to ui?)
QF_NEED(vid, [common])
fi
if test "x$HAVE_PTHREAD" = xyes; then
QWAQ_TARGETS="$QWAQ_TARGETS ruamoko/qwaq/qwaq-cmd\$(EXEEXT)"
fi fi
QF_NEED(tools,[qfcc]) QF_NEED(tools,[qfcc])
QF_NEED(ruamoko,[qwaq]) QF_NEED(ruamoko,[qwaq])

View file

@ -85,10 +85,10 @@ static QFile *log_file;
static cvar_t *sv_logfile; static cvar_t *sv_logfile;
static cvar_t *sv_conmode; static cvar_t *sv_conmode;
static void C_KeyEvent (knum_t key, short unicode, qboolean down);
#ifdef HAVE_NCURSES #ifdef HAVE_NCURSES
static void key_event (knum_t key, short unicode, qboolean down);
enum { enum {
sv_resize_x = 1, sv_resize_x = 1,
sv_resize_y = 2, sv_resize_y = 2,
@ -465,7 +465,7 @@ process_input (void)
if (ch < 0 || ch >= 256) if (ch < 0 || ch >= 256)
ch = 0; ch = 0;
} }
C_KeyEvent (ch, 0, 1); key_event (ch, 0, 1);
} }
} }
@ -757,14 +757,6 @@ C_ProcessInput (void)
} }
} }
static void
C_KeyEvent (knum_t key, short unicode, qboolean down)
{
#ifdef HAVE_NCURSES
key_event (key, unicode, down);
#endif
}
static void static void
C_DrawConsole (void) C_DrawConsole (void)
{ {

View file

@ -284,7 +284,7 @@ libs/video/renderer/vulkan/shader.lo: libs/video/renderer/vulkan/shader.c $(vksh
libs/video/renderer/vulkan/vulkan_vid_common.lo: libs/video/renderer/vulkan/vulkan_vid_common.c $(vkparse_src) $(pipeline_gen) ${renderpass_gen} libs/video/renderer/vulkan/vulkan_vid_common.lo: libs/video/renderer/vulkan/vulkan_vid_common.c $(vkparse_src) $(pipeline_gen) ${renderpass_gen}
qwaq_curses = $(top_builddir)/ruamoko/qwaq/qwaq-curses$(EXEEXT) qwaq_cmd = $(top_builddir)/ruamoko/qwaq/qwaq-cmd$(EXEEXT)
vkparse_cinc = $(top_builddir)/libs/video/renderer/vulkan/vkparse.cinc vkparse_cinc = $(top_builddir)/libs/video/renderer/vulkan/vkparse.cinc
vkparse_hinc = $(top_builddir)/libs/video/renderer/vulkan/vkparse.hinc vkparse_hinc = $(top_builddir)/libs/video/renderer/vulkan/vkparse.hinc
vkparse_src = \ vkparse_src = \
@ -409,8 +409,8 @@ V_VKGEN_ = $(V_VKGEN_@AM_DEFAULT_V@)
V_VKGEN_0 = @echo " VKGEN " $@; V_VKGEN_0 = @echo " VKGEN " $@;
V_VKGEN_1 = V_VKGEN_1 =
$(vkparse_cinc): $(vkgen) $(qwaq_curses) $(vkparse_plist) $(vkparse_cinc): $(vkgen) $(qwaq_cmd) $(vkparse_plist)
$(V_VKGEN)$(QWAQ_CURSES) $(vkgen) -- $(vkparse_plist) $(vkparse_cinc).t $(vkparse_hinc).t &&\ $(V_VKGEN)$(QWAQ) $(vkgen) -- $(vkparse_plist) $(vkparse_cinc).t $(vkparse_hinc).t &&\
$(am__mv) $(vkparse_cinc).t $(vkparse_cinc) &&\ $(am__mv) $(vkparse_cinc).t $(vkparse_cinc) &&\
$(am__mv) $(vkparse_hinc).t $(vkparse_hinc) $(am__mv) $(vkparse_hinc).t $(vkparse_hinc)
@ -418,7 +418,6 @@ $(vkparse_hinc): $(vkparse_cinc)
# do nothing: hinc generated at the same time as cinc # do nothing: hinc generated at the same time as cinc
CLEANFILES += \ CLEANFILES += \
$(top_builddir)/qwaq-curses.log \
libs/video/renderer/glsl/*.vc \ libs/video/renderer/glsl/*.vc \
libs/video/renderer/glsl/*.fc \ libs/video/renderer/glsl/*.fc \
libs/video/renderer/glsl/*.slc \ libs/video/renderer/glsl/*.slc \

View file

@ -768,6 +768,7 @@ create_view (VkImage image, int baseLayer, int data, int id, vulkan_ctx_t *ctx)
QFV_duSetObjectName (device, VK_OBJECT_TYPE_IMAGE_VIEW, view, QFV_duSetObjectName (device, VK_OBJECT_TYPE_IMAGE_VIEW, view,
va (ctx->va_ctx, "iview:shadowmap:%s:%d", va (ctx->va_ctx, "iview:shadowmap:%s:%d",
viewtype, id)); viewtype, id));
(void) viewtype;//silence unused warning when vulkan debug disabled
return view; return view;
} }

View file

@ -51,13 +51,25 @@ ruamoko_qwaq_qwaq_curses_SOURCES= \
ruamoko/qwaq/builtins/curses.c \ ruamoko/qwaq/builtins/curses.c \
ruamoko/qwaq/builtins/debug.c \ ruamoko/qwaq/builtins/debug.c \
ruamoko/qwaq/builtins/editbuffer.c \ ruamoko/qwaq/builtins/editbuffer.c \
ruamoko/qwaq/builtins/input.c ruamoko/qwaq/builtins/input.c \
ruamoko/qwaq/builtins/qwaq-curses.c
ruamoko_qwaq_qwaq_curses_LDADD= $(qwaq_curses_libs) $(QWAQ_LIBS) \ ruamoko_qwaq_qwaq_curses_LDADD= $(qwaq_curses_libs) $(QWAQ_LIBS) \
$(PANEL_LIBS) $(NCURSES_LIBS) $(PTHREAD_LDFLAGS) $(DL_LIBS) $(PANEL_LIBS) $(NCURSES_LIBS) $(PTHREAD_LDFLAGS) $(DL_LIBS)
ruamoko_qwaq_qwaq_curses_LDFLAGS= ruamoko_qwaq_qwaq_curses_LDFLAGS=
ruamoko_qwaq_qwaq_curses_DEPENDENCIES= $(qwaq_curses_libs) $(QWAQ_DEPS) ruamoko_qwaq_qwaq_curses_DEPENDENCIES= $(qwaq_curses_libs) $(QWAQ_DEPS)
qwaq_cmd_libs=
ruamoko_qwaq_qwaq_cmd_SOURCES= \
ruamoko/qwaq/builtins/main.c \
ruamoko/qwaq/builtins/qwaq-cmd.c
ruamoko_qwaq_qwaq_cmd_LDADD= $(qwaq_cmd_libs) $(QWAQ_LIBS) \
$(PTHREAD_LDFLAGS) $(DL_LIBS)
ruamoko_qwaq_qwaq_cmd_LDFLAGS=
ruamoko_qwaq_qwaq_cmd_DEPENDENCIES= $(qwaq_cmd_libs) $(QWAQ_DEPS)
qwaq_cl_plugin_libs= \ qwaq_cl_plugin_libs= \
@client_static_plugin_libs@ @client_static_plugin_libs@
@ -109,7 +121,11 @@ ruamoko/qwaq/z-transform.dat$(EXEEXT): $(ruamoko_qwaq_z_transform_obj) $(QFCC_DE
include $(ruamoko_qwaq_z_transform_dep) # am--include-marker include $(ruamoko_qwaq_z_transform_dep) # am--include-marker
r_depfiles_remade += $(ruamoko_qwaq_z_transform_dep) r_depfiles_remade += $(ruamoko_qwaq_z_transform_dep)
EXTRA_PROGRAMS += ruamoko/qwaq/qwaq-curses ruamoko/qwaq/qwaq-x11 EXTRA_PROGRAMS += \
ruamoko/qwaq/qwaq-cmd \
ruamoko/qwaq/qwaq-curses \
ruamoko/qwaq/qwaq-x11
EXTRA_DIST += \ EXTRA_DIST += \
$(qwaq_dat_src) \ $(qwaq_dat_src) \
ruamoko/qwaq/debugger/debug.h \ ruamoko/qwaq/debugger/debug.h \

View file

@ -77,7 +77,7 @@ static const char *short_options =
"-" // magic option parsing mode doohicky (must come first) "-" // magic option parsing mode doohicky (must come first)
; ;
struct DARRAY_TYPE(qwaq_thread_t *) thread_data; qwaq_thread_set_t thread_data;
static QFile * static QFile *
open_file (const char *path, int *len) open_file (const char *path, int *len)
@ -148,6 +148,47 @@ init_qf (void)
PR_Opcode_Init (); PR_Opcode_Init ();
} }
static void
bi_printf (progs_t *pr)
{
const char *fmt = P_GSTRING (pr, 0);
int count = pr->pr_argc - 1;
pr_type_t **args = pr->pr_params + 1;
dstring_t *dstr = dstring_new ();
PR_Sprintf (pr, dstr, "bi_printf", fmt, count, args);
if (dstr->str) {
Sys_Printf ("%s", dstr->str);
}
dstring_delete (dstr);
}
static void
bi_traceon (progs_t *pr)
{
pr->pr_trace = true;
pr->pr_trace_depth = pr->pr_depth;
}
static void
bi_traceoff (progs_t *pr)
{
pr->pr_trace = false;
}
static builtin_t common_builtins[] = {
{"printf", bi_printf, -1},
{"traceon", bi_traceon, -1},
{"traceoff", bi_traceoff, -1},
{},
};
static void
common_builtins_init (progs_t *pr)
{
PR_RegisterBuiltins (pr, common_builtins);
}
static progs_t * static progs_t *
create_progs (qwaq_thread_t *thread) create_progs (qwaq_thread_t *thread)
{ {
@ -163,6 +204,7 @@ create_progs (qwaq_thread_t *thread)
PR_Init_Cvars (); PR_Init_Cvars ();
PR_Init (pr); PR_Init (pr);
RUA_Init (pr, 0); RUA_Init (pr, 0);
common_builtins_init (pr);
while (*funcs) { while (*funcs) {
(*funcs++) (pr); (*funcs++) (pr);
} }
@ -344,60 +386,6 @@ done:
return qargs_ind; return qargs_ind;
} }
static void
bi_printf (progs_t *pr)
{
const char *fmt = P_GSTRING (pr, 0);
int count = pr->pr_argc - 1;
pr_type_t **args = pr->pr_params + 1;
dstring_t *dstr = dstring_new ();
PR_Sprintf (pr, dstr, "bi_printf", fmt, count, args);
if (dstr->str) {
Sys_Printf ("%s", dstr->str);
}
dstring_delete (dstr);
}
static void
bi_traceon (progs_t *pr)
{
pr->pr_trace = true;
pr->pr_trace_depth = pr->pr_depth;
}
static void
bi_traceoff (progs_t *pr)
{
pr->pr_trace = false;
}
static builtin_t common_builtins[] = {
{"printf", bi_printf, -1},
{"traceon", bi_traceon, -1},
{"traceoff", bi_traceoff, -1},
{},
};
static void
common_builtins_init (progs_t *pr)
{
PR_RegisterBuiltins (pr, common_builtins);
}
static progsinit_f main_app[] = {
BI_Init,
common_builtins_init,
QWAQ_EditBuffer_Init,
QWAQ_Debug_Init,
0
};
static progsinit_f target_app[] = {
common_builtins_init,
QWAQ_DebugTarget_Init,
0
};
int int
main (int argc, char **argv) main (int argc, char **argv)
@ -454,27 +442,7 @@ main (int argc, char **argv)
DARRAY_APPEND (&thread_data, thread); DARRAY_APPEND (&thread_data, thread);
} }
for (size_t i = 1, thread_ind = 0; i < thread_data.size; i++) { main_ind = qwaq_init_threads (&thread_data);
qwaq_thread_t *thread = thread_data.a[i];
progsinit_f *app_funcs = target_app;
if (thread->args.size && thread->args.a[0]
&& strcmp (thread->args.a[0], "--qargs")) {
// skip the args set that's passed to qargs
continue;
}
if (thread_ind < thread_data.a[0]->args.size) {
thread->args.a[0] = thread_data.a[0]->args.a[thread_ind++];
} else {
printf ("ignoring extra arg sets\n");
break;
}
if (main_ind < 0) {
main_ind = i;
app_funcs = main_app;
}
thread->progsinit = app_funcs;
}
if (main_ind >= 0) { if (main_ind >= 0) {
// threads might start new threads before the end is reached // threads might start new threads before the end is reached
size_t count = thread_data.size; size_t count = thread_data.size;

View file

@ -0,0 +1,91 @@
/*
#FILENAME#
Qwaq
Copyright (C) 2001 Bill Currie
Author: Bill Currie <bill@taniwha.org>
Date: 2001/06/01
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to:
Free Software Foundation, Inc.
59 Temple Place - Suite 330
Boston, MA 02111-1307, USA
*/
#ifdef HAVE_CONFIG_H
# include "config.h"
#endif
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <pthread.h>
#include <errno.h>
#include <getopt.h>
#include "QF/cbuf.h"
#include "QF/cmd.h"
#include "QF/cvar.h"
#include "QF/gib.h"
#include "QF/idparse.h"
#include "QF/keys.h"
#include "QF/progs.h"
#include "QF/qargs.h"
#include "QF/quakefs.h"
#include "QF/ruamoko.h"
#include "QF/sys.h"
#include "QF/va.h"
#include "QF/zone.h"
#include "compat.h"
#include "ruamoko/qwaq/qwaq.h"
#include "ruamoko/qwaq/debugger/debug.h"
static progsinit_f main_app[] = {
0
};
int
qwaq_init_threads (qwaq_thread_set_t *thread_data)
{
int main_ind = -1;
for (size_t i = 1, thread_ind = 0; i < thread_data->size; i++) {
qwaq_thread_t *thread = thread_data->a[i];
progsinit_f *app_funcs = main_app;
if (thread->args.size && thread->args.a[0]
&& strcmp (thread->args.a[0], "--qargs")) {
// skip the args set that's passed to qargs
continue;
}
if (thread_ind < thread_data->a[0]->args.size) {
thread->args.a[0] = thread_data->a[0]->args.a[thread_ind++];
} else {
printf ("ignoring extra arg sets\n");
break;
}
if (main_ind < 0) {
main_ind = i;
app_funcs = main_app;
}
thread->progsinit = app_funcs;
}
return main_ind;
}

View file

@ -0,0 +1,99 @@
/*
#FILENAME#
Qwaq
Copyright (C) 2001 Bill Currie
Author: Bill Currie <bill@taniwha.org>
Date: 2001/06/01
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to:
Free Software Foundation, Inc.
59 Temple Place - Suite 330
Boston, MA 02111-1307, USA
*/
#ifdef HAVE_CONFIG_H
# include "config.h"
#endif
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <pthread.h>
#include <errno.h>
#include <getopt.h>
#include "QF/cbuf.h"
#include "QF/cmd.h"
#include "QF/cvar.h"
#include "QF/gib.h"
#include "QF/idparse.h"
#include "QF/keys.h"
#include "QF/progs.h"
#include "QF/qargs.h"
#include "QF/quakefs.h"
#include "QF/ruamoko.h"
#include "QF/sys.h"
#include "QF/va.h"
#include "QF/zone.h"
#include "compat.h"
#include "ruamoko/qwaq/qwaq.h"
#include "ruamoko/qwaq/debugger/debug.h"
static progsinit_f main_app[] = {
BI_Init,
QWAQ_EditBuffer_Init,
QWAQ_Debug_Init,
0
};
static progsinit_f target_app[] = {
QWAQ_DebugTarget_Init,
0
};
int
qwaq_init_threads (qwaq_thread_set_t *thread_data)
{
int main_ind = -1;
for (size_t i = 1, thread_ind = 0; i < thread_data->size; i++) {
qwaq_thread_t *thread = thread_data->a[i];
progsinit_f *app_funcs = target_app;
if (thread->args.size && thread->args.a[0]
&& strcmp (thread->args.a[0], "--qargs")) {
// skip the args set that's passed to qargs
continue;
}
if (thread_ind < thread_data->a[0]->args.size) {
thread->args.a[0] = thread_data->a[0]->args.a[thread_ind++];
} else {
printf ("ignoring extra arg sets\n");
break;
}
if (main_ind < 0) {
main_ind = i;
app_funcs = main_app;
}
thread->progsinit = app_funcs;
}
return main_ind;
}

View file

@ -21,9 +21,13 @@ typedef struct qwaq_thread_s {
void *data; void *data;
} qwaq_thread_t; } qwaq_thread_t;
typedef struct qwaq_thread_set_s DARRAY_TYPE(qwaq_thread_t *) qwaq_thread_set_t;
void BI_Init (progs_t *pr); void BI_Init (progs_t *pr);
void QWAQ_EditBuffer_Init (progs_t *pr); void QWAQ_EditBuffer_Init (progs_t *pr);
extern struct cbuf_s *qwaq_cbuf; extern struct cbuf_s *qwaq_cbuf;
qwaq_thread_t *create_thread (void *(*thread_func) (qwaq_thread_t *), void *); qwaq_thread_t *create_thread (void *(*thread_func) (qwaq_thread_t *), void *);
int qwaq_init_threads (qwaq_thread_set_t *thread_data);
#endif//__qwaq_h #endif//__qwaq_h