2001-08-25 02:47:11 +00:00
|
|
|
/*
|
|
|
|
screen.c
|
|
|
|
|
|
|
|
master for refresh, status bar, console, chat, notify, etc
|
|
|
|
|
|
|
|
Copyright (C) 1996-1997 Id Software, Inc.
|
|
|
|
|
|
|
|
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
|
2003-01-15 15:31:36 +00:00
|
|
|
|
|
|
|
static __attribute__ ((unused)) const char rcsid[] =
|
|
|
|
"$Id$";
|
|
|
|
|
2001-08-25 02:47:11 +00:00
|
|
|
#ifdef HAVE_STRING_H
|
|
|
|
# include <string.h>
|
|
|
|
#endif
|
|
|
|
#ifdef HAVE_STRINGS_H
|
|
|
|
# include <strings.h>
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include <time.h>
|
|
|
|
|
|
|
|
#include "QF/console.h"
|
|
|
|
#include "QF/cvar.h"
|
|
|
|
#include "QF/draw.h"
|
2003-05-23 17:17:01 +00:00
|
|
|
#include "QF/dstring.h"
|
2003-09-04 18:59:39 +00:00
|
|
|
#include "QF/image.h"
|
2001-08-25 02:47:11 +00:00
|
|
|
#include "QF/pcx.h"
|
2002-08-27 07:16:28 +00:00
|
|
|
#include "QF/quakefs.h"
|
2001-08-29 02:16:17 +00:00
|
|
|
#include "QF/render.h"
|
|
|
|
#include "QF/screen.h"
|
2001-08-25 02:47:11 +00:00
|
|
|
#include "QF/sys.h"
|
2003-05-23 17:17:01 +00:00
|
|
|
#include "QF/va.h"
|
2001-08-25 02:47:11 +00:00
|
|
|
|
|
|
|
#include "compat.h"
|
|
|
|
#include "r_cvar.h"
|
2002-12-11 16:45:40 +00:00
|
|
|
#include "r_dynamic.h"
|
2001-08-25 02:47:11 +00:00
|
|
|
#include "r_local.h"
|
2002-12-11 17:34:48 +00:00
|
|
|
#include "r_screen.h"
|
2001-08-25 02:47:11 +00:00
|
|
|
#include "sbar.h"
|
|
|
|
#include "view.h"
|
|
|
|
|
2003-01-06 18:28:13 +00:00
|
|
|
static void
|
2002-12-11 16:45:40 +00:00
|
|
|
SCR_ApplyBlend (void) // Used to be V_UpdatePalette
|
2001-08-25 02:47:11 +00:00
|
|
|
{
|
2002-12-11 16:45:40 +00:00
|
|
|
int r, g, b, i;
|
|
|
|
byte *basepal, *newpal;
|
|
|
|
byte pal[768];
|
2001-08-25 02:47:11 +00:00
|
|
|
|
|
|
|
switch(r_pixbytes) {
|
|
|
|
case 1:
|
|
|
|
{
|
2002-09-10 06:35:32 +00:00
|
|
|
basepal = vid.basepal;
|
2001-08-25 02:47:11 +00:00
|
|
|
newpal = pal;
|
|
|
|
|
|
|
|
for (i = 0; i < 256; i++) {
|
|
|
|
r = basepal[0];
|
|
|
|
g = basepal[1];
|
|
|
|
b = basepal[2];
|
|
|
|
basepal += 3;
|
|
|
|
|
|
|
|
r += (int) (v_blend[3] * (v_blend[0] * 256 - r));
|
|
|
|
g += (int) (v_blend[3] * (v_blend[1] * 256 - g));
|
|
|
|
b += (int) (v_blend[3] * (v_blend[2] * 256 -g));
|
|
|
|
|
|
|
|
newpal[0] = gammatable[r];
|
|
|
|
newpal[1] = gammatable[g];
|
|
|
|
newpal[2] = gammatable[b];
|
|
|
|
newpal += 3;
|
|
|
|
}
|
|
|
|
VID_ShiftPalette (pal);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 2:
|
|
|
|
{
|
2003-04-17 00:01:48 +00:00
|
|
|
unsigned int g1, g2, x, y;
|
2001-08-25 02:47:11 +00:00
|
|
|
unsigned short rramp[32], gramp[64], bramp[32], *temp;
|
|
|
|
for (i = 0; i < 32; i++) {
|
|
|
|
r = i << 3;
|
|
|
|
g1 = i << 3;
|
|
|
|
g2 = g1 + 4;
|
|
|
|
b = i << 3;
|
|
|
|
|
|
|
|
r += (int) (v_blend[3] * (v_blend[0] * 256 - r));
|
|
|
|
g1 += (int) (v_blend[3] * (v_blend[1] - g1));
|
|
|
|
g2 += (int) (v_blend[3] * (v_blend[1] - g2));
|
|
|
|
b += (int) (v_blend[3] * (v_blend[2] - b));
|
|
|
|
|
|
|
|
rramp[i] = (gammatable[r] << 8) & 0xF800;
|
|
|
|
gramp[i*2+0] = (gammatable[g1] << 3) & 0x07E0;
|
|
|
|
gramp[i*2+1] = (gammatable[g2] << 3) & 0x07E0;
|
|
|
|
bramp[i] = (gammatable[b] >> 3) & 0x001F;
|
|
|
|
}
|
|
|
|
temp = vid.buffer;
|
|
|
|
for (y = 0;y < vid.height;y++, temp += (vid.rowbytes >> 1))
|
|
|
|
for (x = 0;x < vid.width;x++)
|
|
|
|
temp[x] = rramp[(temp[x] & 0xF800) >> 11]
|
|
|
|
+ gramp[(temp[x] & 0x07E0) >> 5] + bramp[temp[x] & 0x001F];
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 4:
|
|
|
|
{
|
2003-04-17 00:01:48 +00:00
|
|
|
unsigned int x, y;
|
2001-08-25 02:47:11 +00:00
|
|
|
byte ramp[256][4], *temp;
|
|
|
|
for (i = 0; i < 256; i++) {
|
|
|
|
r = i;
|
|
|
|
g = i;
|
|
|
|
b = i;
|
|
|
|
|
|
|
|
r += (int) (v_blend[3] * (v_blend[0] * 256 - r));
|
|
|
|
g += (int) (v_blend[3] * (v_blend[1] * 256 - g));
|
|
|
|
b += (int) (v_blend[3] * (v_blend[2] * 256 - b));
|
|
|
|
|
|
|
|
ramp[i][0] = gammatable[r];
|
|
|
|
ramp[i][1] = gammatable[g];
|
|
|
|
ramp[i][2] = gammatable[b];
|
|
|
|
ramp[i][3] = 0;
|
|
|
|
}
|
|
|
|
temp = vid.buffer;
|
|
|
|
for (y = 0;y < vid.height;y++, temp += vid.rowbytes)
|
|
|
|
{
|
|
|
|
for (x = 0;x < vid.width;x++)
|
|
|
|
{
|
|
|
|
temp[x*4+0] = ramp[temp[x*4+0]][0];
|
|
|
|
temp[x*4+1] = ramp[temp[x*4+1]][1];
|
|
|
|
temp[x*4+2] = ramp[temp[x*4+2]][2];
|
|
|
|
temp[x*4+3] = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
2002-05-14 06:12:29 +00:00
|
|
|
Sys_Error("V_UpdatePalette: unsupported r_pixbytes %i", r_pixbytes);
|
2001-08-25 02:47:11 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2002-12-11 16:45:40 +00:00
|
|
|
/* SCREEN SHOTS */
|
2001-08-25 02:47:11 +00:00
|
|
|
|
2001-08-25 03:24:44 +00:00
|
|
|
tex_t *
|
|
|
|
SCR_ScreenShot (int width, int height)
|
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2001-08-25 02:47:11 +00:00
|
|
|
void
|
|
|
|
SCR_ScreenShot_f (void)
|
|
|
|
{
|
2003-05-23 17:17:01 +00:00
|
|
|
dstring_t *pcxname = dstring_new ();
|
2003-05-23 17:39:33 +00:00
|
|
|
pcx_t *pcx = 0;
|
2001-08-29 02:16:17 +00:00
|
|
|
int pcx_len;
|
2001-08-25 02:47:11 +00:00
|
|
|
|
|
|
|
// find a file name to save it to
|
2003-05-23 17:17:01 +00:00
|
|
|
if (!QFS_NextFilename (pcxname,
|
|
|
|
va ("%s/qf", qfs_gamedir->dir.def), ".pcx")) {
|
2001-08-25 02:47:11 +00:00
|
|
|
Con_Printf ("SCR_ScreenShot_f: Couldn't create a PCX");
|
2003-05-23 17:17:01 +00:00
|
|
|
} else {
|
|
|
|
// enable direct drawing of console to back buffer
|
|
|
|
D_EnableBackBufferAccess ();
|
|
|
|
|
|
|
|
// save the pcx file
|
|
|
|
switch(r_pixbytes) {
|
|
|
|
case 1:
|
|
|
|
pcx = EncodePCX (vid.buffer, vid.width, vid.height, vid.rowbytes,
|
|
|
|
vid.basepal, false, &pcx_len);
|
|
|
|
break;
|
|
|
|
case 2:
|
|
|
|
Con_Printf("SCR_ScreenShot_f: FIXME - add 16bit support\n");
|
|
|
|
break;
|
|
|
|
case 4:
|
|
|
|
Con_Printf("SCR_ScreenShot_f: FIXME - add 32bit support\n");
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
Sys_Error("SCR_ScreenShot_f: unsupported r_pixbytes %i", r_pixbytes);
|
|
|
|
}
|
2001-08-25 02:47:11 +00:00
|
|
|
|
2003-05-23 17:17:01 +00:00
|
|
|
// for adapters that can't stay mapped in for linear writes all the time
|
|
|
|
D_DisableBackBufferAccess ();
|
2001-08-25 02:47:11 +00:00
|
|
|
|
2003-05-23 17:39:33 +00:00
|
|
|
if (pcx) {
|
|
|
|
QFS_WriteFile (pcxname->str, pcx, pcx_len);
|
|
|
|
Con_Printf ("Wrote %s\n", pcxname->str);
|
|
|
|
}
|
2003-05-23 17:17:01 +00:00
|
|
|
}
|
|
|
|
dstring_delete (pcxname);
|
2001-08-25 02:47:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
SCR_UpdateScreen
|
|
|
|
|
|
|
|
This is called every frame, and can also be called explicitly to flush
|
|
|
|
text to the screen.
|
|
|
|
|
|
|
|
WARNING: be very careful calling this from elsewhere, because the refresh
|
|
|
|
needs almost the entire 256k of stack space!
|
|
|
|
*/
|
|
|
|
void
|
2001-12-09 14:05:30 +00:00
|
|
|
SCR_UpdateScreen (double realtime, SCR_Func *scr_funcs)
|
2001-08-25 02:47:11 +00:00
|
|
|
{
|
2001-08-29 02:16:17 +00:00
|
|
|
vrect_t vrect;
|
2001-08-25 02:47:11 +00:00
|
|
|
|
2004-02-15 03:40:50 +00:00
|
|
|
if (scr_skipupdate)
|
2001-08-25 02:47:11 +00:00
|
|
|
return;
|
|
|
|
|
|
|
|
r_realtime = realtime;
|
|
|
|
|
|
|
|
scr_copytop = 0;
|
|
|
|
scr_copyeverything = 0;
|
|
|
|
|
2002-01-16 21:53:42 +00:00
|
|
|
if (!scr_initialized)
|
2001-08-25 02:47:11 +00:00
|
|
|
return; // not initialized yet
|
|
|
|
|
2002-12-11 16:45:40 +00:00
|
|
|
if (oldfov != scr_fov->value) { // determine size of refresh window
|
|
|
|
oldfov = scr_fov->value;
|
2001-08-25 02:47:11 +00:00
|
|
|
vid.recalc_refdef = true;
|
|
|
|
}
|
|
|
|
|
2002-12-11 16:45:40 +00:00
|
|
|
if (vid.recalc_refdef)
|
2001-08-25 02:47:11 +00:00
|
|
|
SCR_CalcRefdef ();
|
|
|
|
|
|
|
|
// do 3D refresh drawing, and then update the screen
|
|
|
|
D_EnableBackBufferAccess (); // of all overlay stuff if drawing
|
|
|
|
// directly
|
2001-08-29 02:16:17 +00:00
|
|
|
|
2001-08-25 02:47:11 +00:00
|
|
|
if (scr_fullupdate++ < vid.numpages) { // clear the entire screen
|
|
|
|
scr_copyeverything = 1;
|
|
|
|
Draw_TileClear (0, 0, vid.width, vid.height);
|
|
|
|
Sbar_Changed ();
|
|
|
|
}
|
|
|
|
|
|
|
|
pconupdate = NULL;
|
|
|
|
|
|
|
|
SCR_SetUpToDrawConsole ();
|
|
|
|
|
|
|
|
D_DisableBackBufferAccess (); // for adapters that can't stay mapped
|
|
|
|
// in for linear writes all the time
|
|
|
|
VID_LockBuffer ();
|
|
|
|
V_RenderView ();
|
|
|
|
VID_UnlockBuffer ();
|
|
|
|
|
|
|
|
D_EnableBackBufferAccess (); // of all overlay stuff if drawing
|
|
|
|
// directly
|
2001-08-29 02:16:17 +00:00
|
|
|
|
2004-03-01 23:47:39 +00:00
|
|
|
while (*scr_funcs) {
|
|
|
|
(*scr_funcs)();
|
|
|
|
scr_funcs++;
|
2001-08-25 02:47:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
D_DisableBackBufferAccess (); // for adapters that can't stay mapped
|
|
|
|
// in for linear writes all the time
|
|
|
|
if (pconupdate) {
|
|
|
|
D_UpdateRects (pconupdate);
|
|
|
|
}
|
|
|
|
|
|
|
|
SCR_ApplyBlend ();
|
|
|
|
|
|
|
|
// update one of three areas
|
|
|
|
if (scr_copyeverything) {
|
|
|
|
vrect.x = 0;
|
|
|
|
vrect.y = 0;
|
|
|
|
vrect.width = vid.width;
|
|
|
|
vrect.height = vid.height;
|
|
|
|
vrect.pnext = 0;
|
|
|
|
|
|
|
|
VID_Update (&vrect);
|
|
|
|
} else if (scr_copytop) {
|
|
|
|
vrect.x = 0;
|
|
|
|
vrect.y = 0;
|
|
|
|
vrect.width = vid.width;
|
2003-02-11 21:24:27 +00:00
|
|
|
vrect.height = vid.height - r_lineadj;
|
2001-08-25 02:47:11 +00:00
|
|
|
vrect.pnext = 0;
|
|
|
|
|
|
|
|
VID_Update (&vrect);
|
|
|
|
} else {
|
|
|
|
vrect.x = scr_vrect.x;
|
|
|
|
vrect.y = scr_vrect.y;
|
|
|
|
vrect.width = scr_vrect.width;
|
|
|
|
vrect.height = scr_vrect.height;
|
|
|
|
vrect.pnext = 0;
|
|
|
|
|
|
|
|
VID_Update (&vrect);
|
|
|
|
}
|
|
|
|
}
|