2012-07-14 00:06:04 +00:00
|
|
|
/*
|
2021-12-20 07:45:22 +00:00
|
|
|
graphics.c
|
2012-07-14 00:06:04 +00:00
|
|
|
|
2021-12-20 07:09:45 +00:00
|
|
|
Basic game engine builtins
|
2012-07-14 00:06:04 +00:00
|
|
|
|
2021-12-20 07:09:45 +00:00
|
|
|
Copyright (C) 2012 Bill Currie <bill@taniwha.org>
|
2012-07-14 00:06:04 +00:00
|
|
|
|
2021-12-20 07:09:45 +00:00
|
|
|
Author: Bill Currie <bill@taniwha.org>
|
|
|
|
Date: 2012/7/24
|
2012-07-14 00:06:04 +00:00
|
|
|
|
|
|
|
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"
|
2021-12-20 15:47:13 +00:00
|
|
|
#include "QF/ruamoko.h"
|
2012-07-14 00:06:04 +00:00
|
|
|
#include "QF/screen.h"
|
|
|
|
#include "QF/sound.h"
|
|
|
|
#include "QF/sys.h"
|
|
|
|
#include "QF/vid.h"
|
|
|
|
|
2021-12-22 06:06:17 +00:00
|
|
|
#include "QF/input/event.h"
|
|
|
|
|
2012-07-14 00:06:04 +00:00
|
|
|
#include "QF/plugin/console.h"
|
|
|
|
#include "QF/plugin/vid_render.h"
|
|
|
|
|
2020-06-21 14:15:17 +00:00
|
|
|
#include "ruamoko/qwaq/qwaq.h"
|
2012-07-14 00:06:04 +00:00
|
|
|
|
|
|
|
CLIENT_PLUGIN_PROTOS
|
|
|
|
static plugin_list_t client_plugin_list[] = {
|
|
|
|
CLIENT_PLUGIN_LIST
|
|
|
|
};
|
|
|
|
|
|
|
|
double con_frametime;
|
2016-01-04 11:42:22 +00:00
|
|
|
double con_realtime, basetime;
|
2012-07-14 00:06:04 +00:00
|
|
|
double old_conrealtime;
|
|
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
quit_f (void)
|
|
|
|
{
|
|
|
|
if (!con_module)
|
|
|
|
Sys_Printf ("I hope you wanted to quit\n");
|
|
|
|
Sys_Quit ();
|
|
|
|
}
|
|
|
|
|
|
|
|
static progs_t *bi_rprogs;
|
2022-01-18 06:32:43 +00:00
|
|
|
static pr_func_t qc2d;
|
2021-12-22 06:06:17 +00:00
|
|
|
static int event_handler_id;
|
2012-07-14 00:06:04 +00:00
|
|
|
|
|
|
|
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)
|
|
|
|
{
|
2016-01-04 11:42:22 +00:00
|
|
|
con_realtime = Sys_DoubleTime () - basetime;
|
2012-07-14 00:06:04 +00:00
|
|
|
con_frametime = con_realtime - old_conrealtime;
|
|
|
|
old_conrealtime = con_realtime;
|
|
|
|
bi_rprogs = pr;
|
|
|
|
IN_ProcessEvents ();
|
|
|
|
//GIB_Thread_Execute ();
|
|
|
|
Cbuf_Execute_Stack (qwaq_cbuf);
|
2021-12-02 09:30:57 +00:00
|
|
|
SCR_UpdateScreen (con_realtime, bi_2dfuncs);
|
2012-07-14 00:06:04 +00:00
|
|
|
R_FLOAT (pr) = con_frametime;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
bi_refresh_2d (progs_t *pr)
|
|
|
|
{
|
|
|
|
qc2d = P_FUNCTION (pr, 0);
|
|
|
|
}
|
|
|
|
|
2018-08-19 10:44:45 +00:00
|
|
|
static void
|
2022-01-23 12:54:03 +00:00
|
|
|
bi_shutdown (progs_t *pr)
|
2018-08-19 10:44:45 +00:00
|
|
|
{
|
|
|
|
Sys_Shutdown ();
|
|
|
|
}
|
|
|
|
|
2022-01-23 12:54:03 +00:00
|
|
|
#define bi(x,n,np,params...) {#x, bi_##x, n, np, {params}}
|
|
|
|
#define p(type) PR_PARAM(type)
|
2012-07-14 00:06:04 +00:00
|
|
|
static builtin_t builtins[] = {
|
2022-01-23 12:54:03 +00:00
|
|
|
bi(refresh, -1, 0),
|
|
|
|
bi(refresh_2d, -1, 1, p(func)),
|
|
|
|
bi(shutdown, -1, 0),
|
2012-07-14 00:06:04 +00:00
|
|
|
{0}
|
|
|
|
};
|
|
|
|
|
2021-12-22 06:06:17 +00:00
|
|
|
static int
|
|
|
|
event_handler (const IE_event_t *ie_event, void *_pr)
|
|
|
|
{
|
|
|
|
return IN_Binding_HandleEvent (ie_event);
|
|
|
|
}
|
|
|
|
|
2016-01-03 08:39:03 +00:00
|
|
|
static void
|
2022-01-23 12:54:03 +00:00
|
|
|
BI_shutdown (void *data)
|
2016-01-03 08:39:03 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2012-07-14 00:06:04 +00:00
|
|
|
void
|
2021-12-20 07:45:22 +00:00
|
|
|
BI_Graphics_Init (progs_t *pr)
|
2012-07-14 00:06:04 +00:00
|
|
|
{
|
2021-12-20 11:13:21 +00:00
|
|
|
qwaq_thread_t *thread = PR_Resources_Find (pr, "qwaq_thread");
|
2012-07-14 00:06:04 +00:00
|
|
|
byte *basepal, *colormap;
|
|
|
|
|
2022-01-23 15:20:05 +00:00
|
|
|
PR_RegisterBuiltins (pr, builtins, 0);
|
2012-07-14 00:06:04 +00:00
|
|
|
|
2021-12-20 11:13:21 +00:00
|
|
|
QFS_Init (thread->hunk, "nq");
|
2012-07-14 00:06:04 +00:00
|
|
|
PI_Init ();
|
|
|
|
PI_RegisterPlugins (client_plugin_list);
|
|
|
|
|
2022-01-23 12:54:03 +00:00
|
|
|
Sys_RegisterShutdown (BI_shutdown, pr);
|
2016-01-03 08:39:03 +00:00
|
|
|
|
2012-07-14 00:06:04 +00:00
|
|
|
VID_Init_Cvars ();
|
|
|
|
IN_Init_Cvars ();
|
|
|
|
Mod_Init_Cvars ();
|
|
|
|
S_Init_Cvars ();
|
|
|
|
|
2014-01-23 02:57:57 +00:00
|
|
|
basepal = (byte *) QFS_LoadHunkFile (QFS_FOpenFile ("gfx/palette.lmp"));
|
2012-07-14 00:06:04 +00:00
|
|
|
if (!basepal)
|
|
|
|
Sys_Error ("Couldn't load gfx/palette.lmp");
|
2014-01-23 02:57:57 +00:00
|
|
|
colormap = (byte *) QFS_LoadHunkFile (QFS_FOpenFile ("gfx/colormap.lmp"));
|
2012-07-14 00:06:04 +00:00
|
|
|
if (!colormap)
|
|
|
|
Sys_Error ("Couldn't load gfx/colormap.lmp");
|
|
|
|
|
|
|
|
W_LoadWadFile ("gfx.wad");
|
|
|
|
VID_Init (basepal, colormap);
|
2021-11-18 06:33:49 +00:00
|
|
|
IN_Init ();
|
2012-07-14 00:06:04 +00:00
|
|
|
Mod_Init ();
|
|
|
|
R_Init ();
|
|
|
|
R_Progs_Init (pr);
|
2021-12-20 15:47:13 +00:00
|
|
|
RUA_Game_Init (pr, thread->rua_security);
|
2012-12-17 06:41:56 +00:00
|
|
|
S_Progs_Init (pr);
|
2012-07-14 00:06:04 +00:00
|
|
|
|
2021-12-22 06:06:17 +00:00
|
|
|
event_handler_id = IE_Add_Handler (event_handler, pr);
|
|
|
|
IE_Set_Focus (event_handler_id);
|
|
|
|
|
2012-07-14 00:06:04 +00:00
|
|
|
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;
|
|
|
|
}
|
2021-11-08 02:20:04 +00:00
|
|
|
//Key_SetKeyDest (key_game);
|
2012-07-14 00:06:04 +00:00
|
|
|
|
2012-12-17 06:09:26 +00:00
|
|
|
S_Init (0, &con_frametime);
|
2012-07-14 00:06:04 +00:00
|
|
|
//CDAudio_Init ();
|
|
|
|
Con_NewMap ();
|
2016-01-04 11:42:22 +00:00
|
|
|
basetime = Sys_DoubleTime ();
|
2012-07-14 00:06:04 +00:00
|
|
|
}
|