Initial checkin of the qwaq mini-engine.

This commit is contained in:
Bill Currie 2012-07-14 09:06:04 +09:00
parent f9c6eacb84
commit 97c87cf996
5 changed files with 418 additions and 1 deletions

View file

@ -23,6 +23,7 @@ HW_TARGETS=""
QTV_TARGETS="" QTV_TARGETS=""
QW_TARGETS="" QW_TARGETS=""
NQ_TARGETS="" NQ_TARGETS=""
QWAQ_TARGETS=""
QW_DESKTOP_DATA="" QW_DESKTOP_DATA=""
NQ_DESKTOP_DATA="" NQ_DESKTOP_DATA=""
@ -64,6 +65,7 @@ if test "x$HAVE_X" = xyes; then
if test "x$ENABLE_clients_x11" = xyes; then if test "x$ENABLE_clients_x11" = xyes; then
QW_TARGETS="$QW_TARGETS qw-client-x11\$(EXEEXT)" QW_TARGETS="$QW_TARGETS qw-client-x11\$(EXEEXT)"
NQ_TARGETS="$NQ_TARGETS nq-x11\$(EXEEXT)" NQ_TARGETS="$NQ_TARGETS nq-x11\$(EXEEXT)"
QWAQ_TARGETS="$QWAQ_TARGETS qwaq-x11\$(EXEEXT)"
QW_DESKTOP_DATA="$QW_DESKTOP_DATA quakeforge-qw-x11.desktop" QW_DESKTOP_DATA="$QW_DESKTOP_DATA quakeforge-qw-x11.desktop"
NQ_DESKTOP_DATA="$NQ_DESKTOP_DATA quakeforge-nq-x11.desktop" NQ_DESKTOP_DATA="$NQ_DESKTOP_DATA quakeforge-nq-x11.desktop"
CL_TARGETS="$CL_TARGETS X11" CL_TARGETS="$CL_TARGETS X11"
@ -312,6 +314,7 @@ QF_SUBST(HW_TARGETS)
QF_SUBST(NQ_TARGETS) QF_SUBST(NQ_TARGETS)
QF_SUBST(NQ_DESKTOP_DATA) QF_SUBST(NQ_DESKTOP_DATA)
QF_SUBST(QTV_TARGETS) QF_SUBST(QTV_TARGETS)
QF_SUBST(QWAQ_TARGETS)
QF_SUBST(QW_TARGETS) QF_SUBST(QW_TARGETS)
QF_SUBST(QW_DESKTOP_DATA) QF_SUBST(QW_DESKTOP_DATA)
QF_SUBST(CD_TARGETS) QF_SUBST(CD_TARGETS)

View file

@ -8,7 +8,7 @@ QFCC_DEP=$(top_builddir)/tools/qfcc/source/qfcc$(EXEEXT)
QFCC=$(top_builddir)/tools/qfcc/source/qfcc QFCC=$(top_builddir)/tools/qfcc/source/qfcc
QCFLAGS=-qq -g -Werror --advanced --no-default-paths QCFLAGS=-qq -g -Werror --advanced --no-default-paths
noinst_PROGRAMS=qwaq noinst_PROGRAMS=qwaq @QWAQ_TARGETS@
noinst_DATA=qwaq.dat noinst_DATA=qwaq.dat
qwaq_dat_src= \ qwaq_dat_src= \
@ -18,8 +18,33 @@ qwaq_SOURCES= main.c builtins.c
qwaq_LDADD= $(QWAQ_LIBS) qwaq_LDADD= $(QWAQ_LIBS)
qwaq_DEPENDENCIES= $(QWAQ_DEPS) qwaq_DEPENDENCIES= $(QWAQ_DEPS)
cl_plugin_libs= \
@client_static_plugin_libs@
client_libs= \
$(top_builddir)/libs/console/libQFconsole.la \
$(top_builddir)/libs/video/targets/libQFjs.la \
$(top_builddir)/libs/audio/libQFcd.la \
$(top_builddir)/libs/audio/libQFsound.la \
$(top_builddir)/libs/image/libQFimage.la
qwaq_x11_libs= \
$(cl_plugin_libs) \
$(top_builddir)/libs/video/renderer/libQFrenderer.la \
$(top_builddir)/libs/models/libQFmodels.la \
$(top_builddir)/libs/video/targets/libQFx11.la \
$(client_libs) \
$(top_builddir)/libs/gib/libQFgib.la
qwaq_x11_SOURCES=qwaq.c qwaq-bi.c
qwaq_x11_LDADD= $(qwaq_x11_libs) $(QWAQ_LIBS) \
$(VIDMODE_LIBS) $(DGA_LIBS) $(X_LIBS) -lX11 \
$(X_EXTRA_LIBS) $(X_SHM_LIB)
qwaq_x11_LDFLAGS=
qwaq_x11_DEPENDENCIES= $(qwaq_x11_libs) $(QWAQ_DEPS)
qwaq.dat: progs.src $(qwaq_dat_src) $(QFCC_DEP) $(top_srcdir)/ruamoko/lib/Object.r qwaq.dat: progs.src $(qwaq_dat_src) $(QFCC_DEP) $(top_srcdir)/ruamoko/lib/Object.r
$(QFCC) $(QCFLAGS) -I$(top_srcdir)/ruamoko/include $(QFCC) $(QCFLAGS) -I$(top_srcdir)/ruamoko/include
EXTRA_PROGRAMS=qwaq-x11
EXTRA_DIST=$(qwaq_dat_src) qwaq.h EXTRA_DIST=$(qwaq_dat_src) qwaq.h
CLEANFILES= *.dat *.sym CLEANFILES= *.dat *.sym

196
tools/qwaq/qwaq-bi.c Normal file
View file

@ -0,0 +1,196 @@
/*
#FILENAME#
#DESCRIPTION#
Copyright (C) 2001 #AUTHOR#
Author: #AUTHOR#
Date: #DATE#
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
static __attribute__ ((used)) const char rcsid[] = "$Id$";
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <unistd.h>
#include <errno.h>
#include <string.h>
#include "QF/cbuf.h"
#include "QF/cdaudio.h"
#include "QF/console.h"
#include "QF/draw.h"
#include "QF/dstring.h"
#include "QF/input.h"
#include "QF/model.h"
#include "QF/plugin.h"
#include "QF/progs.h"
#include "QF/quakefs.h"
#include "QF/render.h"
#include "QF/screen.h"
#include "QF/sound.h"
#include "QF/sys.h"
#include "QF/vid.h"
#include "QF/zone.h"
#include "QF/plugin/console.h"
#include "QF/plugin/vid_render.h"
#include "qwaq.h"
CLIENT_PLUGIN_PROTOS
static plugin_list_t client_plugin_list[] = {
CLIENT_PLUGIN_LIST
};
double con_frametime;
double con_realtime;
double old_conrealtime;
static void
quit_f (void)
{
if (!con_module)
Sys_Printf ("I hope you wanted to quit\n");
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 (dstr->str, stdout);
dstring_delete (dstr);
}
static progs_t *bi_rprogs;
static func_t qc3d, qc2d;
static void
bi_3d (void)
{
if (qc3d)
PR_ExecuteProgram (bi_rprogs, qc3d);
}
static void
bi_2d (void)
{
if (qc2d)
PR_ExecuteProgram (bi_rprogs, qc2d);
}
static SCR_Func bi_2dfuncs[] = {
bi_2d,
Con_DrawConsole,
0,
};
static void
bi_refresh (progs_t *pr)
{
con_realtime = Sys_DoubleTime ();
con_frametime = con_realtime - old_conrealtime;
old_conrealtime = con_realtime;
bi_rprogs = pr;
IN_ProcessEvents ();
//GIB_Thread_Execute ();
Cbuf_Execute_Stack (qwaq_cbuf);
r_funcs->SCR_UpdateScreen (con_realtime, bi_3d, bi_2dfuncs);
R_FLOAT (pr) = con_frametime;
}
static void
bi_refresh_2d (progs_t *pr)
{
qc2d = P_FUNCTION (pr, 0);
}
static void
bi_refresh_3d (progs_t *pr)
{
qc3d = P_FUNCTION (pr, 0);
}
static builtin_t builtins[] = {
{"printf", bi_printf, -1},
{"refresh", bi_refresh, -1},
{"refresh_2d", bi_refresh_2d, -1},
{"refresh_3d", bi_refresh_3d, -1},
{0}
};
void
BI_Init (progs_t *pr)
{
byte *basepal, *colormap;
PR_RegisterBuiltins (pr, builtins);
QFS_Init ("nq");
PI_Init ();
PI_RegisterPlugins (client_plugin_list);
VID_Init_Cvars ();
IN_Init_Cvars ();
Mod_Init_Cvars ();
S_Init_Cvars ();
basepal = (byte *) QFS_LoadHunkFile ("gfx/palette.lmp");
if (!basepal)
Sys_Error ("Couldn't load gfx/palette.lmp");
colormap = (byte *) QFS_LoadHunkFile ("gfx/colormap.lmp");
if (!colormap)
Sys_Error ("Couldn't load gfx/colormap.lmp");
W_LoadWadFile ("gfx.wad");
VID_Init (basepal, colormap);
IN_Init (qwaq_cbuf);
Mod_Init ();
R_Init ();
R_Progs_Init (pr);
Con_Init ("client");
if (con_module) {
con_module->data->console->realtime = &con_realtime;
con_module->data->console->frametime = &con_frametime;
con_module->data->console->quit = quit_f;
con_module->data->console->cbuf = qwaq_cbuf;
}
Key_SetKeyDest (key_game);
//S_Init (&cl.worldmodel, &viewentity, &host_frametime);
//CDAudio_Init ();
Con_NewMap ();
}

192
tools/qwaq/qwaq.c Normal file
View file

@ -0,0 +1,192 @@
/*
#FILENAME#
#DESCRIPTION#
Copyright (C) 2001 #AUTHOR#
Author: #AUTHOR#
Date: #DATE#
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 "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)
{
QFile *file;
int size;
char *sym;
file = open_file (name, &size);
if (!file) {
file = open_file (va ("%s.gz", name), &size);
if (!file) {
return 0;
}
}
sym = malloc (size + 1);
sym[size] = 0;
Qread (file, sym, 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 ();
//Cvar_Get ("developer", "128", 0, 0, 0);
Memory_Init (malloc (1024 * 1024), 1024 * 1024);
Cvar_Get ("pr_debug", "2", 0, 0, 0);
Cvar_Get ("pr_boundscheck", "0", 0, 0, 0);
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 ();
RUA_Init (&pr, 0);
PR_Cmds_Init (&pr);
BI_Init (&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_LoadProgsFile (&pr, file, size, 1, 1024 * 1024);
Qclose (file);
if (!PR_RunLoadFuncs (&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", "qwaq.dat");
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_ExecuteProgram (&pr, main_func);
PR_PopFrame (&pr);
return R_INT (&pr);
}

View file

@ -1 +1,2 @@
void BI_Init (progs_t *pr); void BI_Init (progs_t *pr);
extern struct cbuf_s *qwaq_cbuf;