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/draw.h"
|
2022-05-08 14:41:12 +00:00
|
|
|
#include "QF/image.h"
|
2012-07-14 00:06:04 +00:00
|
|
|
#include "QF/input.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"
|
|
|
|
|
2021-12-22 06:06:17 +00:00
|
|
|
#include "QF/input/event.h"
|
2022-05-08 14:41:12 +00:00
|
|
|
#include "QF/math/bitop.h"
|
2021-12-22 06:06:17 +00:00
|
|
|
|
2012-07-14 00:06:04 +00:00
|
|
|
#include "QF/plugin/console.h"
|
2022-05-05 12:30:14 +00:00
|
|
|
|
|
|
|
#include "rua_internal.h"
|
2012-07-14 00:06:04 +00:00
|
|
|
|
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,
|
|
|
|
};
|
|
|
|
|
2022-05-05 12:30:14 +00:00
|
|
|
static void
|
|
|
|
bi_newscene (progs_t *pr, void *_res)
|
|
|
|
{
|
|
|
|
pr_ulong_t scene_id = P_ULONG (pr, 0);
|
|
|
|
SCR_NewScene (Scene_GetScene (pr, scene_id));
|
|
|
|
}
|
|
|
|
|
2012-07-14 00:06:04 +00:00
|
|
|
static void
|
2022-02-14 03:28:38 +00:00
|
|
|
bi_refresh (progs_t *pr, void *_res)
|
2012-07-14 00:06:04 +00:00
|
|
|
{
|
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);
|
2022-02-28 07:59:38 +00:00
|
|
|
SCR_UpdateScreen (0, con_realtime, bi_2dfuncs);
|
2012-07-14 00:06:04 +00:00
|
|
|
R_FLOAT (pr) = con_frametime;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2022-02-14 03:28:38 +00:00
|
|
|
bi_refresh_2d (progs_t *pr, void *_res)
|
2012-07-14 00:06:04 +00:00
|
|
|
{
|
|
|
|
qc2d = P_FUNCTION (pr, 0);
|
|
|
|
}
|
|
|
|
|
2018-08-19 10:44:45 +00:00
|
|
|
static void
|
2022-02-14 03:28:38 +00:00
|
|
|
bi_shutdown (progs_t *pr, void *_res)
|
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-05-05 12:30:14 +00:00
|
|
|
bi(newscene, -1, 1, p(long)),
|
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
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2022-05-08 14:41:12 +00:00
|
|
|
static byte default_palette[256][3];
|
|
|
|
|
|
|
|
static byte *
|
|
|
|
write_raw_rgb (byte *dst, byte r, byte g, byte b)
|
|
|
|
{
|
|
|
|
*dst++ = r;
|
|
|
|
*dst++ = g;
|
|
|
|
*dst++ = b;
|
|
|
|
return dst;
|
|
|
|
}
|
|
|
|
|
|
|
|
static byte *
|
|
|
|
write_rgb (byte *dst, byte r, byte g, byte b)
|
|
|
|
{
|
|
|
|
#define shift(x) (((x) << 2) | (((x) & 0x3f) >> 4))
|
|
|
|
*dst++ = shift(r);
|
|
|
|
*dst++ = shift(g);
|
|
|
|
*dst++ = shift(b);
|
|
|
|
return dst;
|
|
|
|
#undef shift
|
|
|
|
}
|
|
|
|
|
|
|
|
static byte *
|
|
|
|
write_grey (byte *dst, byte grey)
|
|
|
|
{
|
|
|
|
return write_rgb (dst, grey, grey, grey);
|
|
|
|
}
|
|
|
|
|
|
|
|
static byte *
|
|
|
|
genererate_irgb (byte *dst, byte lo, byte melo, byte mehi, byte hi)
|
|
|
|
{
|
|
|
|
for (int i = 0; i < 16; i++) {
|
|
|
|
byte l = i & 8 ? melo : lo;
|
|
|
|
byte h = i & 8 ? hi : mehi;
|
|
|
|
byte r = i & 4 ? h : l;
|
|
|
|
byte g = i & 2 ? h : l;
|
|
|
|
byte b = i & 1 ? h : l;
|
|
|
|
if (i == 6) { // make dim yellow brown
|
|
|
|
g = melo;
|
|
|
|
}
|
|
|
|
dst = write_rgb (dst, r, g, b);
|
|
|
|
}
|
|
|
|
return dst;
|
|
|
|
}
|
|
|
|
|
|
|
|
static byte *
|
|
|
|
write_run (byte *dst, byte *hue, byte ch, const byte *levels)
|
|
|
|
{
|
|
|
|
byte rgb[3] = {
|
|
|
|
*hue & 4 ? levels[4] : levels[0],
|
|
|
|
*hue & 2 ? levels[4] : levels[0],
|
|
|
|
*hue & 1 ? levels[4] : levels[0],
|
|
|
|
};
|
|
|
|
byte chan = 2 - BITOP_LOG2 (ch);
|
|
|
|
int ind = *hue & ch ? 4 : 0;
|
|
|
|
int dir = *hue & ch ? -1 : 1;
|
|
|
|
|
|
|
|
for (int i = 0; i < 4; i++, ind += dir) {
|
|
|
|
rgb[chan] = levels[ind];
|
|
|
|
dst = write_rgb (dst, rgb[0], rgb[1], rgb[2]);
|
|
|
|
}
|
|
|
|
|
|
|
|
*hue ^= ch;
|
|
|
|
return dst;
|
|
|
|
}
|
|
|
|
|
|
|
|
static byte *
|
|
|
|
write_cycle (byte *dst, byte lo, byte melo, byte me, byte mehi, byte hi)
|
|
|
|
{
|
|
|
|
const byte levels[] = { lo, melo, me, mehi, hi };
|
|
|
|
byte hue = 1;
|
|
|
|
dst = write_run (dst, &hue, 4, levels);
|
|
|
|
dst = write_run (dst, &hue, 1, levels);
|
|
|
|
dst = write_run (dst, &hue, 2, levels);
|
|
|
|
|
|
|
|
dst = write_run (dst, &hue, 4, levels);
|
|
|
|
dst = write_run (dst, &hue, 1, levels);
|
|
|
|
dst = write_run (dst, &hue, 2, levels);
|
|
|
|
return dst;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
generate_palette (void)
|
|
|
|
{
|
|
|
|
const byte grey[] = {
|
|
|
|
0, 5, 8, 11, 14, 17, 20, 24,
|
|
|
|
28, 32, 36, 40, 45, 50, 56, 63,
|
|
|
|
};
|
|
|
|
byte *dst = default_palette[0];
|
|
|
|
|
|
|
|
dst = genererate_irgb (dst, 0, 21, 42, 63);
|
|
|
|
|
|
|
|
for (int i = 0; i < 16; i++) {
|
|
|
|
dst = write_grey (dst, grey[i]);
|
|
|
|
}
|
|
|
|
|
|
|
|
dst = write_cycle (dst, 11, 12, 13, 15, 16);
|
|
|
|
dst = write_cycle (dst, 8, 10, 12, 14, 16);
|
|
|
|
dst = write_cycle (dst, 0, 4, 8, 12, 16);
|
|
|
|
|
|
|
|
dst = write_cycle (dst, 20, 22, 24, 26, 28);
|
|
|
|
dst = write_cycle (dst, 14, 17, 21, 24, 28);
|
|
|
|
dst = write_cycle (dst, 0, 7, 14, 21, 28);
|
|
|
|
|
|
|
|
dst = write_cycle (dst, 45, 49, 54, 58, 63);
|
|
|
|
dst = write_cycle (dst, 31, 39, 47, 55, 63);
|
|
|
|
dst = write_cycle (dst, 0, 16, 31, 47, 63);
|
|
|
|
|
|
|
|
// std is black, but want vis trans and some phosphors
|
|
|
|
dst = write_raw_rgb (dst, 40, 40, 40);
|
|
|
|
dst = write_raw_rgb (dst, 40, 127, 40);
|
|
|
|
dst = write_raw_rgb (dst, 51, 255, 51);
|
|
|
|
dst = write_raw_rgb (dst, 102, 255, 102);
|
|
|
|
dst = write_raw_rgb (dst, 127, 102, 0);
|
|
|
|
dst = write_raw_rgb (dst, 255, 176, 0);
|
|
|
|
dst = write_raw_rgb (dst, 255, 204, 0);
|
|
|
|
|
|
|
|
dst = write_raw_rgb (dst, 176, 160, 176);
|
|
|
|
}
|
|
|
|
|
|
|
|
static byte default_colormap[64 * 256 + 1] = { [64 * 256] = 32 };
|
|
|
|
|
|
|
|
static void
|
|
|
|
generate_colormap (void)
|
|
|
|
{
|
|
|
|
byte colors[64][256][3];
|
|
|
|
tex_t tex = {
|
|
|
|
.width = 256,
|
|
|
|
.height = 64,
|
|
|
|
.format = tex_rgb,
|
|
|
|
.data = colors[0][0],
|
|
|
|
};
|
|
|
|
|
|
|
|
// baseline colors
|
|
|
|
for (int i = 0; i < 256; i++) {
|
|
|
|
VectorCopy (default_palette[i], colors[31][i]);
|
|
|
|
VectorCopy (default_palette[i], colors[32][i]);
|
|
|
|
}
|
|
|
|
for (int i = 0; i < 64; i++) {
|
|
|
|
// main colors
|
|
|
|
if (i < 31 || i > 32) {
|
|
|
|
float scale = i < 32 ? 2 - i / 31.0 : 1 - (i - 32) / 31.0;
|
|
|
|
for (int j = 0; j < 224; j++) {
|
|
|
|
for (int k = 0; k < 3; k++) {
|
|
|
|
colors[i][j][k] = bound (0, scale * colors[31][j][k], 255);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// fullbrights
|
|
|
|
memcpy (colors[i][224], colors[31][224], 32 * 3);
|
|
|
|
}
|
|
|
|
tex_t *cmap = ConvertImage (&tex, default_palette[0]);
|
|
|
|
memcpy (default_colormap, cmap->data, sizeof (default_colormap));
|
|
|
|
free (cmap);
|
|
|
|
}
|
|
|
|
|
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
|
|
|
|
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 ();
|
|
|
|
|
2022-05-08 14:41:12 +00:00
|
|
|
generate_palette ();
|
|
|
|
generate_colormap ();
|
2012-07-14 00:06:04 +00:00
|
|
|
|
2022-05-08 14:41:12 +00:00
|
|
|
VID_Init (default_palette[0], default_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
|
|
|
}
|