2001-02-19 21:15:25 +00:00
|
|
|
/*
|
2001-05-24 19:22:35 +00:00
|
|
|
screen.c
|
2001-02-19 21:15:25 +00:00
|
|
|
|
|
|
|
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
|
|
|
|
|
|
|
|
*/
|
2001-09-28 06:26:31 +00:00
|
|
|
static const char rcsid[] =
|
|
|
|
"$Id$";
|
2001-02-19 21:15:25 +00:00
|
|
|
|
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
# include "config.h"
|
|
|
|
#endif
|
|
|
|
#ifdef HAVE_STRING_H
|
|
|
|
# include <string.h>
|
|
|
|
#endif
|
|
|
|
#ifdef HAVE_STRINGS_H
|
|
|
|
# include <strings.h>
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include <time.h>
|
|
|
|
|
2001-03-27 20:33:07 +00:00
|
|
|
#include "QF/console.h"
|
2001-05-31 03:41:35 +00:00
|
|
|
#include "QF/cvar.h"
|
2001-05-09 22:40:51 +00:00
|
|
|
#include "QF/draw.h"
|
2001-05-09 17:57:57 +00:00
|
|
|
#include "QF/pcx.h"
|
2002-08-27 07:16:28 +00:00
|
|
|
#include "QF/quakefs.h"
|
2001-05-24 19:22:35 +00:00
|
|
|
#include "QF/render.h"
|
2001-05-23 06:33:23 +00:00
|
|
|
#include "QF/screen.h"
|
2001-04-15 21:11:41 +00:00
|
|
|
#include "QF/sys.h"
|
2001-05-23 06:33:23 +00:00
|
|
|
#include "QF/texture.h"
|
2001-04-15 21:11:41 +00:00
|
|
|
|
2001-08-16 23:14:46 +00:00
|
|
|
#include "compat.h"
|
2001-05-11 19:21:48 +00:00
|
|
|
#include "r_cvar.h"
|
2001-05-23 06:33:23 +00:00
|
|
|
#include "r_local.h"
|
2002-12-11 17:34:48 +00:00
|
|
|
#include "r_screen.h"
|
2001-02-19 21:15:25 +00:00
|
|
|
#include "sbar.h"
|
|
|
|
#include "view.h"
|
|
|
|
|
|
|
|
/*
|
|
|
|
SCR_CalcRefdef
|
|
|
|
|
|
|
|
Must be called whenever vid changes
|
|
|
|
Internal use only
|
|
|
|
*/
|
|
|
|
static void
|
|
|
|
SCR_CalcRefdef (void)
|
|
|
|
{
|
2001-05-24 19:22:35 +00:00
|
|
|
vrect_t vrect;
|
2001-02-19 21:15:25 +00:00
|
|
|
float size;
|
|
|
|
int h;
|
|
|
|
qboolean full = false;
|
|
|
|
|
|
|
|
scr_fullupdate = 0; // force a background redraw
|
|
|
|
vid.recalc_refdef = 0;
|
|
|
|
|
|
|
|
// force the status bar to redraw
|
|
|
|
Sbar_Changed ();
|
|
|
|
|
|
|
|
// bound viewsize
|
|
|
|
Cvar_SetValue (scr_viewsize, bound (30, scr_viewsize->int_val, 120));
|
|
|
|
|
|
|
|
// bound field of view
|
2002-04-28 08:30:54 +00:00
|
|
|
Cvar_SetValue (scr_fov, bound (1, scr_fov->value, 170));
|
2001-02-19 21:15:25 +00:00
|
|
|
|
|
|
|
if (scr_viewsize->int_val >= 120)
|
|
|
|
sb_lines = 0; // no status bar at all
|
|
|
|
else if (scr_viewsize->int_val >= 110)
|
|
|
|
sb_lines = 24; // no inventory
|
|
|
|
else
|
|
|
|
sb_lines = 24 + 16 + 8;
|
|
|
|
|
|
|
|
if (scr_viewsize->int_val >= 100) {
|
|
|
|
full = true;
|
|
|
|
size = 100.0;
|
|
|
|
} else {
|
|
|
|
size = scr_viewsize->int_val;
|
|
|
|
}
|
|
|
|
// intermission is always full screen
|
2002-12-11 16:45:40 +00:00
|
|
|
if (r_force_fullscreen /* FIXME: better test */) {
|
2001-02-19 21:15:25 +00:00
|
|
|
full = true;
|
|
|
|
size = 100.0;
|
|
|
|
sb_lines = 0;
|
|
|
|
}
|
|
|
|
size /= 100.0;
|
|
|
|
|
2001-05-23 06:33:23 +00:00
|
|
|
h = vid.height - r_lineadj;
|
2001-02-19 21:15:25 +00:00
|
|
|
|
|
|
|
r_refdef.vrect.width = vid.width * size + 0.5;
|
|
|
|
if (r_refdef.vrect.width < 96) {
|
|
|
|
size = 96.0 / r_refdef.vrect.width;
|
|
|
|
r_refdef.vrect.width = 96; // min for icons
|
|
|
|
}
|
|
|
|
|
|
|
|
r_refdef.vrect.height = vid.height * size + 0.5;
|
2001-08-25 02:47:11 +00:00
|
|
|
if (r_refdef.vrect.height > h)
|
|
|
|
r_refdef.vrect.height = h;
|
2001-02-19 21:15:25 +00:00
|
|
|
r_refdef.vrect.x = (vid.width - r_refdef.vrect.width) / 2;
|
|
|
|
if (full)
|
|
|
|
r_refdef.vrect.y = 0;
|
|
|
|
else
|
|
|
|
r_refdef.vrect.y = (h - r_refdef.vrect.height) / 2;
|
|
|
|
|
2002-04-28 08:30:54 +00:00
|
|
|
r_refdef.fov_x = scr_fov->value;
|
2001-02-19 21:15:25 +00:00
|
|
|
r_refdef.fov_y =
|
|
|
|
CalcFov (r_refdef.fov_x, r_refdef.vrect.width, r_refdef.vrect.height);
|
|
|
|
|
|
|
|
scr_vrect = r_refdef.vrect;
|
2001-05-24 19:22:35 +00:00
|
|
|
|
|
|
|
// these calculations mirror those in R_Init() for r_refdef, but take no
|
|
|
|
// account of water warping
|
|
|
|
vrect.x = 0;
|
|
|
|
vrect.y = 0;
|
|
|
|
vrect.width = vid.width;
|
|
|
|
vrect.height = vid.height;
|
|
|
|
|
|
|
|
R_SetVrect (&vrect, &scr_vrect, r_lineadj);
|
|
|
|
|
|
|
|
// guard against going from one mode to another that's less than half the
|
|
|
|
// vertical resolution
|
|
|
|
if (scr_con_current > vid.height)
|
|
|
|
scr_con_current = vid.height;
|
|
|
|
|
|
|
|
// notify the refresh of the change
|
|
|
|
R_ViewChanged (&vrect, r_lineadj, vid.aspect);
|
2001-02-19 21:15:25 +00:00
|
|
|
}
|
|
|
|
|
2001-08-10 00:28:57 +00:00
|
|
|
|
|
|
|
void
|
|
|
|
SCR_ApplyBlend (void) // Used to be V_UpdatePalette
|
|
|
|
{
|
|
|
|
int r, g, b, i;
|
|
|
|
byte *basepal, *newpal;
|
|
|
|
byte pal[768];
|
2002-09-10 06:35:32 +00:00
|
|
|
basepal = vid.basepal;
|
2001-08-10 00:28:57 +00:00
|
|
|
newpal = pal;
|
|
|
|
|
|
|
|
for (i = 0; i < 256; i++) {
|
|
|
|
r = basepal[0];
|
|
|
|
g = basepal[1];
|
|
|
|
b = basepal[2];
|
|
|
|
basepal += 3;
|
|
|
|
|
2001-08-10 03:07:34 +00:00
|
|
|
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));
|
2001-08-10 00:28:57 +00:00
|
|
|
|
|
|
|
newpal[0] = gammatable[r];
|
|
|
|
newpal[1] = gammatable[g];
|
|
|
|
newpal[2] = gammatable[b];
|
|
|
|
newpal += 3;
|
|
|
|
}
|
|
|
|
VID_ShiftPalette (pal);
|
|
|
|
}
|
|
|
|
|
2002-12-11 16:45:40 +00:00
|
|
|
/* SCREEN SHOTS */
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2001-05-23 06:33:23 +00:00
|
|
|
tex_t *
|
|
|
|
SCR_ScreenShot (int width, int height)
|
|
|
|
{
|
|
|
|
unsigned char *src, *dest;
|
2002-12-11 16:45:40 +00:00
|
|
|
float fracw, frach;
|
|
|
|
int count, dex, dey, dx, dy, nx, r, g, b, x, y, w, h;
|
|
|
|
tex_t *tex;
|
2001-05-23 06:33:23 +00:00
|
|
|
|
2001-05-24 19:22:35 +00:00
|
|
|
// enable direct drawing of console to back buffer
|
|
|
|
D_EnableBackBufferAccess ();
|
2001-05-23 06:33:23 +00:00
|
|
|
|
|
|
|
w = (vid.width < width) ? vid.width : width;
|
|
|
|
h = (vid.height < height) ? vid.height : height;
|
|
|
|
|
|
|
|
fracw = (float) vid.width / (float) w;
|
|
|
|
frach = (float) vid.height / (float) h;
|
|
|
|
|
2002-12-10 18:24:38 +00:00
|
|
|
tex = malloc (field_offset (tex_t, data[w * h]));
|
2001-05-24 19:22:35 +00:00
|
|
|
if (!tex)
|
|
|
|
return 0;
|
|
|
|
|
2002-12-09 17:47:12 +00:00
|
|
|
tex->width = w;
|
|
|
|
tex->height = h;
|
|
|
|
tex->palette = vid.palette;
|
|
|
|
|
2001-05-23 06:33:23 +00:00
|
|
|
for (y = 0; y < h; y++) {
|
2002-12-10 18:24:38 +00:00
|
|
|
dest = tex->data + (w * (h - y - 1));
|
2001-05-23 06:33:23 +00:00
|
|
|
|
|
|
|
for (x = 0; x < w; x++) {
|
|
|
|
r = g = b = 0;
|
|
|
|
|
|
|
|
dx = x * fracw;
|
|
|
|
dex = (x + 1) * fracw;
|
|
|
|
if (dex == dx)
|
|
|
|
dex++; // at least one
|
|
|
|
dy = y * frach;
|
|
|
|
dey = (y + 1) * frach;
|
|
|
|
if (dey == dy)
|
|
|
|
dey++; // at least one
|
|
|
|
|
|
|
|
count = 0;
|
2002-12-11 16:45:40 +00:00
|
|
|
for (; dy < dey; dy++) {
|
2001-05-24 19:22:35 +00:00
|
|
|
src = vid.buffer + (vid.rowbytes * dy) + dx;
|
2001-05-23 06:33:23 +00:00
|
|
|
for (nx = dx; nx < dex; nx++) {
|
2002-12-10 18:24:38 +00:00
|
|
|
r += vid.basepal[*src * 3];
|
|
|
|
g += vid.basepal[*src * 3 + 1];
|
|
|
|
b += vid.basepal[*src * 3 + 2];
|
2001-05-24 19:22:35 +00:00
|
|
|
src++;
|
2001-05-23 06:33:23 +00:00
|
|
|
count++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
r /= count;
|
|
|
|
g /= count;
|
|
|
|
b /= count;
|
2001-05-24 19:22:35 +00:00
|
|
|
*dest++ = MipColor (r, g, b);
|
2001-05-23 06:33:23 +00:00
|
|
|
}
|
|
|
|
}
|
2001-05-24 19:22:35 +00:00
|
|
|
// for adapters that can't stay mapped in for linear writes all the time
|
|
|
|
D_DisableBackBufferAccess ();
|
2001-05-23 06:33:23 +00:00
|
|
|
|
|
|
|
return tex;
|
|
|
|
}
|
2001-05-09 17:57:57 +00:00
|
|
|
|
2001-02-19 21:15:25 +00:00
|
|
|
void
|
|
|
|
SCR_ScreenShot_f (void)
|
|
|
|
{
|
|
|
|
char pcxname[MAX_OSPATH];
|
2001-05-24 19:22:35 +00:00
|
|
|
pcx_t *pcx;
|
|
|
|
int pcx_len;
|
2001-02-19 21:15:25 +00:00
|
|
|
|
|
|
|
// find a file name to save it to
|
2001-05-24 19:22:35 +00:00
|
|
|
if (!COM_NextFilename (pcxname, "qf", ".pcx")) {
|
|
|
|
Con_Printf ("SCR_ScreenShot_f: Couldn't create a PCX");
|
2001-02-19 21:15:25 +00:00
|
|
|
return;
|
|
|
|
}
|
2001-05-24 19:22:35 +00:00
|
|
|
|
|
|
|
// enable direct drawing of console to back buffer
|
|
|
|
D_EnableBackBufferAccess ();
|
|
|
|
|
|
|
|
// save the pcx file
|
|
|
|
pcx = EncodePCX (vid.buffer, vid.width, vid.height, vid.rowbytes,
|
2002-09-10 15:13:12 +00:00
|
|
|
vid.basepal, false, &pcx_len);
|
2001-05-24 19:22:35 +00:00
|
|
|
COM_WriteFile (pcxname, pcx, pcx_len);
|
|
|
|
|
|
|
|
|
|
|
|
// for adapters that can't stay mapped in for linear writes all the time
|
|
|
|
D_DisableBackBufferAccess ();
|
|
|
|
|
2001-02-19 21:15:25 +00:00
|
|
|
Con_Printf ("Wrote %s\n", pcxname);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
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-02-19 21:15:25 +00:00
|
|
|
{
|
2002-12-11 16:45:40 +00:00
|
|
|
static int oldviewsize;
|
2001-05-24 19:22:35 +00:00
|
|
|
vrect_t vrect;
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2001-05-24 19:22:35 +00:00
|
|
|
if (scr_skipupdate || block_drawing)
|
2001-02-19 21:15:25 +00:00
|
|
|
return;
|
|
|
|
|
2001-05-24 19:22:35 +00:00
|
|
|
r_realtime = realtime;
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2001-05-24 19:22:35 +00:00
|
|
|
scr_copytop = 0;
|
|
|
|
scr_copyeverything = 0;
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2002-01-16 21:53:42 +00:00
|
|
|
if (!scr_initialized)
|
2001-05-24 19:22:35 +00:00
|
|
|
return; // not initialized yet
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2002-12-11 16:45:40 +00:00
|
|
|
if (oldviewsize != scr_viewsize->int_val) {
|
|
|
|
oldviewsize = scr_viewsize->int_val;
|
|
|
|
vid.recalc_refdef = true;
|
2001-05-24 19:22:35 +00:00
|
|
|
}
|
2001-08-25 02:47:11 +00:00
|
|
|
|
2002-12-11 16:45:40 +00:00
|
|
|
if (oldfov != scr_fov->value) { // determine size of refresh window
|
|
|
|
oldfov = scr_fov->value;
|
2001-05-24 19:22:35 +00:00
|
|
|
vid.recalc_refdef = true;
|
2001-02-19 21:15:25 +00:00
|
|
|
}
|
|
|
|
|
2001-05-24 19:22:35 +00:00
|
|
|
if (oldscreensize != scr_viewsize->int_val) {
|
|
|
|
oldscreensize = scr_viewsize->int_val;
|
2001-02-19 21:15:25 +00:00
|
|
|
vid.recalc_refdef = true;
|
|
|
|
}
|
|
|
|
|
2002-12-11 16:45:40 +00:00
|
|
|
if (vid.recalc_refdef)
|
2001-02-19 21:15:25 +00:00
|
|
|
SCR_CalcRefdef ();
|
2001-08-25 02:47:11 +00:00
|
|
|
|
2001-02-19 21:15:25 +00:00
|
|
|
// do 3D refresh drawing, and then update the screen
|
2001-05-24 19:22:35 +00:00
|
|
|
D_EnableBackBufferAccess (); // of all overlay stuff if drawing
|
2001-08-25 02:47:11 +00:00
|
|
|
// directly
|
2001-05-24 19:22:35 +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;
|
|
|
|
|
2001-02-19 21:15:25 +00:00
|
|
|
SCR_SetUpToDrawConsole ();
|
|
|
|
|
2001-08-25 02:47:11 +00:00
|
|
|
D_DisableBackBufferAccess (); // for adapters that can't stay mapped
|
|
|
|
// in for linear writes all the time
|
2001-05-24 19:22:35 +00:00
|
|
|
VID_LockBuffer ();
|
|
|
|
V_RenderView ();
|
|
|
|
VID_UnlockBuffer ();
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2001-05-24 19:22:35 +00:00
|
|
|
D_EnableBackBufferAccess (); // of all overlay stuff if drawing
|
2001-08-25 02:47:11 +00:00
|
|
|
// directly
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2001-05-24 19:22:35 +00:00
|
|
|
if (r_force_fullscreen /*FIXME*/ == 1 && key_dest == key_game) {
|
2001-02-19 21:15:25 +00:00
|
|
|
Sbar_IntermissionOverlay ();
|
2001-05-24 19:22:35 +00:00
|
|
|
} else if (r_force_fullscreen /*FIXME*/ == 2 && key_dest == key_game) {
|
2001-02-19 21:15:25 +00:00
|
|
|
Sbar_FinaleOverlay ();
|
2001-12-09 14:05:30 +00:00
|
|
|
SCR_CheckDrawCenterString ();
|
2001-02-19 21:15:25 +00:00
|
|
|
} else {
|
2001-05-23 06:33:23 +00:00
|
|
|
while (*scr_funcs) {
|
2001-12-09 14:05:30 +00:00
|
|
|
(*scr_funcs)();
|
2001-05-23 06:33:23 +00:00
|
|
|
scr_funcs++;
|
|
|
|
}
|
2001-02-19 21:15:25 +00:00
|
|
|
}
|
|
|
|
|
2001-08-25 02:47:11 +00:00
|
|
|
D_DisableBackBufferAccess (); // for adapters that can't stay mapped
|
|
|
|
// in for linear writes all the time
|
2001-05-24 19:22:35 +00:00
|
|
|
if (pconupdate) {
|
|
|
|
D_UpdateRects (pconupdate);
|
2001-04-06 02:57:26 +00:00
|
|
|
}
|
|
|
|
|
2001-08-10 00:28:57 +00:00
|
|
|
SCR_ApplyBlend ();
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2001-05-24 19:22:35 +00:00
|
|
|
// 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;
|
|
|
|
vrect.height = vid.height - sb_lines;
|
|
|
|
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;
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2001-05-24 19:22:35 +00:00
|
|
|
VID_Update (&vrect);
|
|
|
|
}
|
2001-02-19 21:15:25 +00:00
|
|
|
}
|