[qwaq] Update qwaq-x11's initialization

It now uses the advanced command line parsing used by qwaq-curses and
qwaq-cmd, but currently disables multi-threading (I don't want to deal
with threading in the engine just yet). The int file is -graphics
because qwaq-x11 is really just the X11 target, qwaq-win is built for
windows, but they use the same basic startup (I hope).
This commit is contained in:
Bill Currie 2021-12-20 16:45:22 +09:00
parent 0e7e88815c
commit d3853a2430
5 changed files with 116 additions and 219 deletions

View file

@ -113,10 +113,13 @@ qwaq_x11_libs= \
$(top_builddir)/libs/models/libQFmodels.la \
$(top_builddir)/libs/video/targets/libQFx11.la \
$(qwaq_client_libs)
ruamoko_qwaq_qwaq_x11_SOURCES=ruamoko/qwaq/builtins/qwaq.c ruamoko/qwaq/builtins/qwaq-bi.c
ruamoko_qwaq_qwaq_x11_SOURCES= \
ruamoko/qwaq/builtins/main.c \
ruamoko/qwaq/builtins/qwaq-graphics.c \
ruamoko/qwaq/builtins/graphics.c
ruamoko_qwaq_qwaq_x11_LDADD= $(qwaq_x11_libs) $(QWAQ_LIBS) \
$(VIDMODE_LIBS) $(DGA_LIBS) ${XFIXES_LIBS} $(XI2_LIBS) $(X_LIBS) \
-lX11 $(X_EXTRA_LIBS) $(X_SHM_LIB) $(DL_LIBS)
-lX11 $(X_EXTRA_LIBS) $(X_SHM_LIB) $(PTHREAD_LDFLAGS) $(DL_LIBS)
ruamoko_qwaq_qwaq_x11_LDFLAGS=
ruamoko_qwaq_qwaq_x11_DEPENDENCIES= $(qwaq_x11_libs) $(QWAQ_DEPS)

View file

@ -1,5 +1,5 @@
/*
qwaq-bi.c
graphics.c
Basic game engine builtins
@ -80,21 +80,6 @@ quit_f (void)
Sys_Quit ();
}
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) {
Con_Printf ("%s", dstr->str);
}
dstring_delete (dstr);
}
static progs_t *bi_rprogs;
static func_t qc2d;
@ -138,7 +123,6 @@ bi_shutdown_ (progs_t *pr)
}
static builtin_t builtins[] = {
{"printf", bi_printf, -1},
{"refresh", bi_refresh, -1},
{"refresh_2d", bi_refresh_2d, -1},
{"shutdown", bi_shutdown_, -1},
@ -151,9 +135,11 @@ bi_shutdown (void *data)
}
void
BI_Init (memhunk_t *hunk, progs_t *pr)
BI_Graphics_Init (progs_t *pr)
{
byte *basepal, *colormap;
size_t memsize = 8 * 1024 * 1024;
memhunk_t *hunk = Memory_Init (Sys_Alloc (memsize), memsize);
PR_RegisterBuiltins (pr, builtins);

View file

@ -0,0 +1,106 @@
/*
qwaq-graphics.c
Qwaq graphics initialization
Copyright (C) 2021 Bill Currie
Author: Bill Currie <bill@taniwha.org>
Date: 2021/12/20
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 <string.h>
//#include "QF/cbuf.h"
//#include "QF/cmd.h"
//#include "QF/cvar.h"
//#include "QF/gib.h"
//#include "QF/idparse.h"
#include "QF/input.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"
static progsinit_f main_app[] = {
BI_Graphics_Init,
0
};
#if 0// FIXME no multi-thread support yet
static progsinit_f secondary_app[] = {
0
};
#endif
static FILE *logfile;
static __attribute__((format(PRINTF, 1, 0))) void
qwaq_print (const char *fmt, va_list args)
{
vfprintf (logfile, fmt, args);
fflush (logfile);
}
int
qwaq_init_threads (qwaq_thread_set_t *thread_data)
{
int main_ind = -1;
logfile = fopen ("qwaq-graphics.log", "wt");
Sys_SetStdPrintf (qwaq_print);
IN_Init_Cvars ();
//IN_Init ();
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 = 0;//secondary_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

@ -1,197 +0,0 @@
/*
qwaq.c
Qwaq
Copyright (C) 2001 Bill Currie <bill@taniwha.org>
Author: Bill Currie <bill@taniwha.org>
Date: 2001/6/1
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 "QF/cbuf.h"
#include "QF/cmd.h"
#include "QF/cvar.h"
#include "QF/gib.h"
#include "QF/idparse.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 "ruamoko/qwaq/qwaq.h"
#define MAX_EDICTS 1024
static edict_t *edicts;
static int num_edicts;
static int reserved_edicts;
static progs_t pr;
cbuf_t *qwaq_cbuf;
static QFile *
open_file (const char *path, int *len)
{
QFile *file = Qopen (path, "rbz");
if (!file) {
perror (path);
return 0;
}
*len = Qfilesize (file);
return file;
}
static void *
load_file (progs_t *pr, const char *name, off_t *_size)
{
QFile *file;
int size;
char *sym;
file = open_file (name, &size);
if (!file) {
file = open_file (va (0, "%s.gz", name), &size);
if (!file) {
return 0;
}
}
sym = malloc (size + 1);
sym[size] = 0;
Qread (file, sym, size);
*_size = size;
return sym;
}
static void *
allocate_progs_mem (progs_t *pr, int size)
{
return malloc (size);
}
static void
free_progs_mem (progs_t *pr, void *mem)
{
free (mem);
}
static void
init_qf (void)
{
qwaq_cbuf = Cbuf_New (&id_interp);
Sys_Init ();
GIB_Init (true);
COM_ParseConfig (qwaq_cbuf);
//Cvar_Set (developer, "1");
size_t memsize = 8 * 1024 * 1024;
memhunk_t *hunk = Memory_Init (Sys_Alloc (memsize), memsize);
Cvar_Get ("pr_debug", "2", 0, 0, 0);
Cvar_Get ("pr_boundscheck", "0", 0, 0, 0);
pr.pr_edicts = &edicts;
pr.num_edicts = &num_edicts;
pr.reserved_edicts = &reserved_edicts;
pr.load_file = load_file;
pr.allocate_progs_mem = allocate_progs_mem;
pr.free_progs_mem = free_progs_mem;
pr.no_exec_limit = 1;
PR_Init_Cvars ();
PR_Init (&pr);
RUA_Init (&pr, 0);
PR_Cmds_Init (&pr);
BI_Init (hunk, &pr);
}
static int
load_progs (const char *name)
{
QFile *file;
int size;
file = open_file (name, &size);
if (!file) {
return 0;
}
pr.progs_name = name;
pr.max_edicts = 1;
pr.zone_size = 1024*1024;
PR_LoadProgsFile (&pr, file, size);
Qclose (file);
if (!PR_RunLoadFuncs (&pr) || !PR_RunPostLoadFuncs (&pr))
PR_Error (&pr, "unable to load %s", pr.progs_name);
return 1;
}
int
main (int argc, const char **argv)
{
dfunction_t *dfunc;
func_t main_func = 0;
const char *name = "qwaq.dat";
string_t *pr_argv;
int pr_argc = 1, i;
COM_InitArgv (argc, argv);
init_qf ();
if (argc > 1)
name = argv[1];
if (!load_progs (name))
Sys_Error ("couldn't load %s", name);
PR_PushFrame (&pr);
if (argc > 2)
pr_argc = argc - 1;
pr_argv = PR_Zone_Malloc (&pr, (pr_argc + 1) * 4);
pr_argv[0] = PR_SetTempString (&pr, name);
for (i = 1; i < pr_argc; i++)
pr_argv[i] = PR_SetTempString (&pr, argv[1 + i]);
pr_argv[i] = 0;
if ((dfunc = PR_FindFunction (&pr, ".main"))
|| (dfunc = PR_FindFunction (&pr, "main")))
main_func = dfunc - pr.pr_functions;
else
PR_Undefined (&pr, "function", "main");
PR_RESET_PARAMS (&pr);
P_INT (&pr, 0) = pr_argc;
P_POINTER (&pr, 1) = PR_SetPointer (&pr, pr_argv);
pr.pr_argc = 2;
PR_ExecuteProgram (&pr, main_func);
PR_PopFrame (&pr);
return R_INT (&pr);
}

View file

@ -23,8 +23,7 @@ typedef struct qwaq_thread_s {
typedef struct qwaq_thread_set_s DARRAY_TYPE(qwaq_thread_t *) qwaq_thread_set_t;
struct memhunk_s;
void BI_Init (struct memhunk_s *hunk, progs_t *pr);
void BI_Graphics_Init (progs_t *pr);
void BI_Curses_Init (progs_t *pr);
void BI_TermInput_Init (progs_t *pr);
void QWAQ_EditBuffer_Init (progs_t *pr);