screen.c cleanup

This commit is contained in:
eukos 2015-08-07 18:17:16 +02:00
parent 0e7169cfc7
commit 1ca123dfd7

View file

@ -23,13 +23,13 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#include "r_local.h"
// only the refresh window will be updated unless these variables are flagged
int scr_copytop;
int scr_copyeverything;
int reflectavailable;
float scr_con_current;
float scr_conlines; // lines of console to display
float oldsbar;
float oldscreensize, oldfov;
int scr_copytop;
int scr_copyeverything;
int reflectavailable;
float scr_con_current;
float scr_conlines; // lines of console to display
float oldsbar;
float oldscreensize, oldfov;
cvar_t *scr_viewsize;
cvar_t *scr_fov; // 10 - 170
cvar_t *scr_fovadapt;// "Hor+" scaling
@ -48,16 +48,17 @@ qboolean scr_initialized; // ready to draw
qpic_t *scr_ram;
qpic_t *scr_net;
qpic_t *scr_turtle;
int sb_what_lines; // leilei - refdef sbar scale hack
int scr_fullupdate;
int sb_what_lines; // leilei - refdef sbar scale hack
int scr_fullupdate;
extern int vidmodetweak; // leilei - 0: normal resolution
// 1: 16:10= 4:3 (320x200, 640x400)
// 2: 2:3 = 4:3 (320x480 Tweaked)
// 3: 8:10 = 4:3 (320x400 Tweaked)
int clearconsole;
int clearnotify;
int retroscalefactor; // leilei
extern int vidmodetweak; // leilei - 0: normal resolution
// 1: 16:10= 4:3 (320x200, 640x400)
// 2: 2:3 = 4:3 (320x480 Tweaked)
// 3: 8:10 = 4:3 (320x400 Tweaked)
//
int clearconsole;
int clearnotify;
int retroscalefactor; // leilei
viddef_t vid; // global video state
vrect_t *pconupdate;
@ -83,9 +84,9 @@ CENTER PRINTING
char scr_centerstring[1024];
float scr_centertime_start; // for slow victory printing
float scr_centertime_off;
int scr_center_lines;
int scr_erase_lines;
int scr_erase_center;
int scr_center_lines;
int scr_erase_lines;
int scr_erase_center;
/*
==============
@ -680,17 +681,16 @@ static void SCR_CalcRefdef (void)
// bound viewsize
if (scr_viewsize->value < 30)
Cvar_Set (scr_viewsize, "30");
if (scr_viewsize->value > 120)
Cvar_Set (scr_viewsize, "120");
else if (scr_viewsize->value > 130)
Cvar_Set (scr_viewsize, "130");
// bound field of view
if (scr_fov->value < 10)
Cvar_Set (scr_fov,"10");
// if (scr_fov->value > 90)
// Cvar_Set (scr_fov,"90"); // cheaters can eat crap
if (scr_fov->value > 199)
Cvar_Set (scr_fov,"199"); // cheaters can eat crap
// leilei - Removed this because it breaks the 'tear gars' in swatteam
Cvar_Set (scr_fov, "10");
else if (scr_fov->value > 110)
Cvar_Set (scr_fov, "110");
vid.recalc_refdef = 0;
// intermission is always full screen
if (cl.intermission)
@ -728,31 +728,25 @@ static void SCR_CalcRefdef (void)
// these calculations mirror those in R_Init() for r_refdef, but take no
// account of water warping
vrect.x = 0;
vrect.y = 0;
vrect.x = vrect.y = 0;
vrect.width = vid.width;
vrect.height = vid.height;
R_SetVrect (&vrect, &scr_vrect, sb_what_lines);
r_refdef.vrect = scr_vrect;
//r_refdef.fov_x = AdaptFovx (scr_fov->value, r_refdef.vrect.width, r_refdef.vrect.height);
//r_refdef.fov_y = CalcFovy (r_refdef.fov_x, r_refdef.vrect.width, r_refdef.vrect.height);
//r_refdef.fov_y = CalcFovy (r_refdef.fov_x, r_refdef.vrect.width, r_refdef.vrect.height);
// quakespasm
if (scr_aspectmode->value == 1){
r_refdef.fov_x = AdaptFovx (scr_fov->value, r_refdef.vrect.width * stretchf, r_refdef.vrect.height);
r_refdef.fov_y = CalcFovy (r_refdef.fov_x, r_refdef.vrect.width * stretchf, r_refdef.vrect.height);
if (scr_aspectmode->value == 1){ // quakespasm
r_refdef.fov_x = AdaptFovx (scr_fov->value, r_refdef.vrect.width * stretchf, r_refdef.vrect.height);
r_refdef.fov_y = CalcFovy (r_refdef.fov_x, r_refdef.vrect.width * stretchf, r_refdef.vrect.height);
}
// mh's "Quakespasm is wrong" post, a bit re-adapted
else if (scr_aspectmode->value == 2){
SCR_SetFOV(scr_fov->value, r_refdef.vrect.width * stretchf, r_refdef.vrect.height);
}
else
// crappy old fov where we lose vert. just like Q3A!
else if (scr_aspectmode->value == 2) // mh's "Quakespasm is wrong" post, a bit re-adapted
{
r_refdef.fov_x = scr_fov->value;
r_refdef.fov_y = CalcFovOld (r_refdef.fov_x, r_refdef.vrect.width * stretchf, r_refdef.vrect.height);
SCR_SetFOV(scr_fov->value, r_refdef.vrect.width * stretchf, r_refdef.vrect.height);
}
else // crappy old fov where we lose vert. just like Q3A!
{
r_refdef.fov_x = scr_fov->value;
r_refdef.fov_y = CalcFovOld (r_refdef.fov_x, r_refdef.vrect.width * stretchf, r_refdef.vrect.height);
}
@ -981,12 +975,12 @@ void SCR_DrawPause (void)
return;
pic = Draw_CachePic ("gfx/pause.lmp");
if (menu_scaled)
Draw_Pic_Scaled ( (vid.vconwidth - pic->width)/2,
(vid.vconheight - 48 - pic->height)/2, pic);
else
Draw_Pic ( (vid.width - pic->width)/2,
(vid.height - 48 - pic->height)/2, pic);
if (menu_scaled)
Draw_Pic_Scaled ( (vid.vconwidth - pic->width)/2,
(vid.vconheight - 48 - pic->height)/2, pic);
else
Draw_Pic ( (vid.width - pic->width)/2,
(vid.height - 48 - pic->height)/2, pic);
}
@ -1031,66 +1025,58 @@ void SCR_SetUpToDrawConsole (void)
if (scr_drawloading)
return; // never a console with loading plaque
// decide on the height of the console
// decide on the height of the console
con_forcedup = !cl.worldmodel || cls.signon != SIGNONS;
if (con_forcedup)
{
scr_conlines = vid.height; // full screen
scr_conlines = vid.height; // full screen
scr_con_current = scr_conlines;
}
else if (key_dest == key_console)
// 2000-01-12 Variable console height by Fett/Maddes start
{
scr_conlines = vid.height/2; // half screen
#ifdef SCALED2D
if (console_scaled)
// scr_conlines = vid.vconheight/2; // half screen
scr_conlines = vid.vconheight*scr_conheight->value; // in-game console
else
else
#endif
scr_conlines = vid.height*scr_conheight->value; // in-game console
if (scr_conlines < (3*8+8+8)) // always leave three lines visible (plus command line and border)
{
if (scr_conlines < (3*8+8+8)) // always leave three lines visible (plus command line and border)
scr_conlines = (3*8+8+8);
}
if (scr_conlines >= vid.height)
{
#ifdef SCALED2D
if (console_scaled)
scr_conlines = vid.vconheight - 1; // maximum is full screen
else
if (console_scaled)
scr_conlines = vid.vconheight - 1; // maximum is full screen
else
#endif
scr_conlines = vid.height - 1; // maximum is full screen
scr_conlines = vid.height - 1; // maximum is full screen
}
}
// 2000-01-12 Variable console height by Fett/Maddes end
else
scr_conlines = 0; // none visible
scr_conlines = 0; // none visible
if (scr_conlines < scr_con_current)
{
// 2001-10-20 TIMESCALE extension by Tomaz/Maddes start
// scr_con_current -= scr_conspeed->value*host_frametime;
if (console_scaled)
scr_con_current -= scr_conspeed->value*host_cpu_frametime * vid.height / vid.vconheight;
scr_con_current -= scr_conspeed->value*host_cpu_frametime * vid.height / vid.vconheight;
else
scr_con_current -= scr_conspeed->value*host_cpu_frametime;
// 2001-10-20 TIMESCALE extension by Tomaz/Maddes end
scr_con_current -= scr_conspeed->value*host_cpu_frametime;
if (scr_conlines > scr_con_current)
scr_con_current = scr_conlines;
}
else if (scr_conlines > scr_con_current)
{
// 2001-10-20 TIMESCALE extension by Tomaz/Maddes start
// scr_con_current += scr_conspeed->value*host_frametime;
if (console_scaled)
scr_con_current += scr_conspeed->value*host_cpu_frametime * vid.height / vid.vconheight;
scr_con_current += scr_conspeed->value*host_cpu_frametime * vid.height / vid.vconheight;
else
scr_con_current += scr_conspeed->value*host_cpu_frametime;
// 2001-10-20 TIMESCALE extension by Tomaz/Maddes end
scr_con_current += scr_conspeed->value*host_cpu_frametime;
if (scr_conlines < scr_con_current)
scr_con_current = scr_conlines;
}
@ -1098,19 +1084,12 @@ if (console_scaled)
if (clearconsole++ < vid.numpages)
{
scr_copytop = 1;
// 2000-08-04 "Transparent" console background for software renderer by Norberto Alfredo Bensa/Maddes start
if (con_alpha->value == 1.0)
{
// 2000-08-04 "Transparent" console background for software renderer by Norberto Alfredo Bensa/Maddes end
Draw_TileClear (0,(int)scr_con_current,vid.width, vid.height - (int)scr_con_current);
// 2000-08-04 "Transparent" console background for software renderer by Norberto Alfredo Bensa/Maddes start
}
Draw_TileClear (0,(int)scr_con_current,vid.width, vid.height - (int)scr_con_current);
else
{
// Draw full valid screen
Draw_TileClear (0, 0, vid.width, vid.height );
}
// 2000-08-04 "Transparent" console background for software renderer by Norberto Alfredo Bensa/Maddes end
Sbar_Changed ();
}
else if (clearnotify++ < vid.numpages)
@ -1154,19 +1133,19 @@ void SCR_DrawConsole (void)
typedef struct
{
char manufacturer;
char version;
char encoding;
char bits_per_pixel;
unsigned short xmin,ymin,xmax,ymax;
unsigned short hres,vres;
unsigned char palette[48];
char reserved;
char color_planes;
unsigned short bytes_per_line;
unsigned short palette_type;
char filler[58];
unsigned char data; // unbounded
char manufacturer;
char version;
char encoding;
char bits_per_pixel;
unsigned short xmin,ymin,xmax,ymax;
unsigned short hres,vres;
unsigned char palette[48];
char reserved;
char color_planes;
unsigned short bytes_per_line;
unsigned short palette_type;
char filler[58];
unsigned char data; // unbounded
} pcx_t;
/*
@ -1174,42 +1153,42 @@ typedef struct
WritePCXfile
==============
*/
void WritePCXfile (char *filename, byte *data, int width, int height,
int rowbytes, byte *palette)
static int WritePCXfile (const char *filename, byte *data, int width, int height, int rowbytes, byte *palette)
{
int i, j, length;
int i, j;
size_t length;
pcx_t *pcx;
byte *pack;
byte *pack;
pcx = Hunk_TempAlloc (width*height*2+1000);
pcx = (pcx_t *) Hunk_TempAlloc (width*height*2+1000);
if (pcx == NULL)
{
Con_Printf("SCR_ScreenShot_f: not enough memory\n");
return;
Con_Printf("WritePCXfile: not enough memory\n");
return -1;
}
pcx->manufacturer = 0x0a; // PCX id
pcx->version = 5; // 256 color
pcx->encoding = 1; // uncompressed
pcx->bits_per_pixel = 8; // 256 color
pcx->version = 5; // 256 color
pcx->encoding = 1; // uncompressed
pcx->bits_per_pixel = 8; // 256 color
pcx->xmin = 0;
pcx->ymin = 0;
pcx->xmax = LittleShort((short)(width-1));
pcx->ymax = LittleShort((short)(height-1));
pcx->hres = LittleShort((short)width);
pcx->vres = LittleShort((short)height);
Q_memset (pcx->palette,0,sizeof(pcx->palette));
memset (pcx->palette, 0, sizeof(pcx->palette));
pcx->color_planes = 1; // chunky image
pcx->bytes_per_line = LittleShort((short)width);
pcx->palette_type = LittleShort(2); // not a grey scale
Q_memset (pcx->filler,0,sizeof(pcx->filler));
pcx->palette_type = LittleShort(2); // not a grey scale
memset (pcx->filler, 0, sizeof(pcx->filler));
// pack the image
pack = &pcx->data;
for (i=0 ; i<height ; i++)
for (i = 0; i < height; i++)
{
for (j=0 ; j<width ; j++)
for (j = 0; j < width; j++)
{
if ( (*data & 0xc0) != 0xc0)
*pack++ = *data++;
@ -1225,13 +1204,14 @@ void WritePCXfile (char *filename, byte *data, int width, int height,
// write the palette
*pack++ = 0x0c; // palette ID byte
for (i=0 ; i<768 ; i++)
for (i = 0; i < 768; i++)
*pack++ = *palette++;
// write output file
// write output file
length = pack - (byte *)pcx;
COM_WriteFile (filename, pcx, length);
COM_WriteFile(filename, pcx, length);
}
#ifdef _WIN32
extern unsigned char vid_curpal[256*3];
#endif
@ -1270,21 +1250,15 @@ void SCR_ScreenShot_f (void)
// save the pcx file
//
D_EnableBackBufferAccess (); // enable direct drawing of console to back
// buffer
printf("Writing PCX - %ix%i named %s\n", vid.width, vid.height, pcxname);
#ifdef _WIN32
WritePCXfile (pcxname, vid.buffer, vid.width, vid.height, vid.rowbytes,
vid_curpal);
WritePCXfile (pcxname, vid.buffer, vid.width, vid.height, vid.rowbytes, vid_curpal);
#else
WritePCXfile (pcxname, vid.buffer, vid.width, vid.height, vid.rowbytes,
host_basepal);
WritePCXfile (pcxname, vid.buffer, vid.width, vid.height, vid.rowbytes, host_basepal);
#endif
D_DisableBackBufferAccess (); // for adapters that can't stay mapped in
// for linear writes all the time
Con_Printf ("Wrote %s\n", pcxname);
}
@ -1506,7 +1480,8 @@ void SCR_ReallyRender (void)
reflectpass = 0;
V_RenderView ();
#endif
};
}
int dontevendraw;
void SCR_UpdateScreen (void)
{
@ -1613,37 +1588,11 @@ void SCR_UpdateScreen (void)
// Draw_FadeScreen ();
VID_LockBuffer ();
// Draw_GetShroomedPT1();
// leilei - water reflections need two passes
// we all start it here!
// TODO- mirror chain
splitpass = 0;
if (!dontevendraw)
SCR_ReallyRender();
if(splitmeup){
client_t oldcle;
client_state_t oldcl;
//*oldcl = cl;
oldcl = cl;
//cl = clsplit;
splitpass = 1;
if (!dontevendraw)
SCR_ReallyRender();
}
VID_UnlockBuffer ();
D_EnableBackBufferAccess (); // of all overlay stuff if drawing directly
// stupid place to put this
//if(oldwateralpha != newwateralpha){
// oldwateralpha = newwateralpha = r_wateralpha->value;
// if(newwateralpha < 1) WaterTableGet();
//}
// leilei - make a new alpha tables.
if (!nolookups){
if(oldwateralpha != r_wateralpha->value || (oldtranquality != (int)r_tranquality->value) || (oldwaterblend != (int)r_waterblend->value)){
@ -1655,37 +1604,22 @@ void SCR_UpdateScreen (void)
}
if(retroscalefactor != scr_retroscale->value){
if(retroscalefactor != scr_retroscale->value)
SCR_CvarCheck();
else if(scalefactor != scr_scale->value && !scr_retroscale->value)
SCR_CvarCheck();
}
else if(scalefactor != scr_scale->value && !scr_retroscale->value){
SCR_CvarCheck();
}
if (dyncolor != r_coloreddyns->value){
if (dyncolor != r_coloreddyns->value)
dyncolor = r_coloreddyns->value;
}
if (shadowhack != r_shadowhack->value){
if (shadowhack != r_shadowhack->value)
shadowhack = r_shadowhack->value;
}
if (r_dynamic->value)
dynlightenabled = 1;
else
dynlightenabled = 0;
// Draw_GetShroomedPT2();
dynlightenabled = r_dynamic->value ? 0 : 1;
if (r_tinge->value == 3)
Draw_DudeScreen ();
Draw_DudeScreen ();
else if (r_tinge->value == 2)
Draw_DudeScreen66 ();
else if (r_tinge->value == 1)
@ -1695,18 +1629,6 @@ void SCR_UpdateScreen (void)
else if (r_tinge->value == -2)
Draw_DudeScreen66A ();
//Draw_Bloom ();
/*if (cl.paused || scr_drawloading || scr_drawdialog){
dontevendraw = 1;
Draw_Something ();
Sbar_Draw ();
}
else
dontevendraw = 0;
*/
if (scr_drawdialog)
{
Sbar_Draw ();
@ -1717,7 +1639,7 @@ void SCR_UpdateScreen (void)
else if (scr_drawloading)
{
//Draw_FadeScreen (); // this WAS cool, but... i'll have to make a whole transition thing first
Draw_FadeScreen ();
SCR_DrawLoading ();
Sbar_Draw ();
}
@ -1740,22 +1662,19 @@ void SCR_UpdateScreen (void)
SCR_DrawRam ();
SCR_DrawNet ();
SCR_DrawTurtle ();
SCR_DrawFPS (); // 2001-11-31 FPS display by QuakeForge/Muff
SCR_DrawFPS ();
SCR_DrawPause ();
SCR_CheckDrawCenterString ();
Sbar_Draw ();
SCR_DrawConsole ();
M_Draw ();
}
D_DisableBackBufferAccess (); // for adapters that can't stay mapped in
// for linear writes all the time
if (pconupdate)
{
D_UpdateRects (pconupdate);
}
if (pconupdate)
D_UpdateRects (pconupdate);
V_UpdatePalette ();
//
@ -1803,7 +1722,6 @@ void SCR_UpdateScreen (void)
}
/*
==================
SCR_UpdateWholeScreen