Old draw cleanups, frogot I had them around..

Clean up of Dabb's mess, he dies.
This commit is contained in:
Zephaniah E. Hull 2000-08-14 04:53:45 +00:00
parent 9a2ec3c094
commit 23d81824dc
6 changed files with 152 additions and 243 deletions

View file

@ -35,7 +35,6 @@ extern qpic_t *draw_disc; // also used on sbar
void Draw_Init (void);
void Draw_Character8 (int x, int y, int num);
void Draw_DebugChar (char num);
void Draw_SubPic(int x, int y, qpic_t *pic, int srcx, int srcy, int width, int height);
void Draw_Pic (int x, int y, qpic_t *pic);
void Draw_TransPic (int x, int y, qpic_t *pic);

View file

@ -90,11 +90,9 @@ extern int texture_mode;
extern float gldepthmin, gldepthmax;
void GL_Upload32 (unsigned *data, int width, int height, qboolean mipmap, qboolean alpha);
void GL_Upload8 (byte *data, int width, int height, qboolean mipmap, qboolean alpha);
void GL_Upload8_EXT (byte *data, int width, int height, qboolean mipmap, qboolean alpha);
int GL_LoadTexture (char *identifier, int width, int height, byte *data, qboolean mipmap, qboolean alpha, int bytesperpixel);
int GL_FindTexture (char *identifier);
typedef struct
{
@ -291,7 +289,6 @@ void R_DrawSky (void);
//
// gl_draw.c
//
int GL_LoadPicTexture (qpic_t *pic);
void GL_Set2D (void);
//

View file

@ -278,14 +278,22 @@ typedef struct
//=============================================================================
typedef struct
{
netadr_t adr;
double issued;
int floodcount;
int cmdcount;
double firstseen;
netadr_t adr;
double issued;
int floodcount;
int cmdcount;
double firstseen;
} flood_t;
enum {FLOOD_PING, FLOOD_LOG, FLOOD_CONNECT, FLOOD_STATUS, FLOOD_RCON, FLOOD_BAN};
typedef enum
{
FLOOD_PING,
FLOOD_LOG,
FLOOD_CONNECT,
FLOOD_STATUS,
FLOOD_RCON,
FLOOD_BAN
} flood_enum_t;
#define DOSFLOODCMDS 6
#define DOSFLOODIP 64 // remember latest 64 IP's for each cmd.

View file

@ -324,49 +324,6 @@ void Draw_Crosshair(void)
'+');
}
/*
================
Draw_DebugChar
Draws a single character directly to the upper right corner of the screen.
This is for debugging lockups by drawing different chars in different parts
of the code.
================
*/
void Draw_DebugChar (char num)
{
byte *dest;
byte *source;
int drawline;
extern byte *draw_chars;
int row, col;
if (!vid.direct)
return; // don't have direct FB access, so no debugchars...
drawline = 8;
row = num>>4;
col = num&15;
source = draw_chars + (row<<10) + (col<<3);
dest = vid.direct + 312;
while (drawline--)
{
dest[0] = source[0];
dest[1] = source[1];
dest[2] = source[2];
dest[3] = source[3];
dest[4] = source[4];
dest[5] = source[5];
dest[6] = source[6];
dest[7] = source[7];
source += 128;
dest += 320;
}
}
/*
=============
Draw_Pic

View file

@ -56,8 +56,7 @@
#include "console.h"
#include "glquake.h"
// FIXME: Do this right..
void LoadTGA (FILE *fin);
static int GL_LoadPicTexture (qpic_t *pic);
extern byte *host_basepal;
extern unsigned char d_15to8table[65536];
@ -80,12 +79,12 @@ extern byte *draw_chars; // 8*8 graphic characters
qpic_t *draw_disc;
qpic_t *draw_backtile;
int ltexcrctable[256]; // cache mismatch checking --KB
static int ltexcrctable[256]; // cache mismatch checking --KB
int translate_texture;
int char_texture;
int cs_texture; // crosshair texturea
static int translate_texture;
static int char_texture;
static int cs_texture; // crosshair texturea
static byte cs_data[64] = {
0xff, 0xff, 0xff, 0xfe, 0xff, 0xff, 0xff, 0xff,
@ -110,12 +109,10 @@ int gl_lightmap_format = 4;
int gl_solid_format = 3;
int gl_alpha_format = 4;
int gl_filter_min = GL_LINEAR_MIPMAP_NEAREST;
int gl_filter_max = GL_LINEAR;
static int gl_filter_min = GL_LINEAR_MIPMAP_NEAREST;
static int gl_filter_max = GL_LINEAR;
int texels;
typedef struct
{
int texnum;
@ -127,9 +124,8 @@ typedef struct
} gltexture_t;
#define MAX_GLTEXTURES 1024
gltexture_t gltextures[MAX_GLTEXTURES];
int numgltextures;
static gltexture_t gltextures[MAX_GLTEXTURES];
static int numgltextures = 0;
/*
=============================================================================
@ -139,42 +135,45 @@ int numgltextures;
Allocate all the little status bar obejcts into a single texture
to crutch up stupid hardware / drivers
Note, this is a kluge, which may slow down sane cards..
As such its all contained in ifdefs..
=============================================================================
*/
#undef gl_draw_scraps
#ifdef gl_draw_scraps
#define MAX_SCRAPS 1
#define BLOCK_WIDTH 256
#define BLOCK_HEIGHT 256
int scrap_allocated[MAX_SCRAPS][BLOCK_WIDTH];
byte scrap_texels[MAX_SCRAPS][BLOCK_WIDTH*BLOCK_HEIGHT*4];
qboolean scrap_dirty;
int scrap_texnum;
static int scrap_allocated[MAX_SCRAPS][BLOCK_WIDTH];
static byte scrap_texels[MAX_SCRAPS][BLOCK_WIDTH*BLOCK_HEIGHT*4];
static qboolean scrap_dirty;
static int scrap_texnum;
// returns a texture number and the position inside it
int Scrap_AllocBlock (int w, int h, int *x, int *y)
static int Scrap_AllocBlock (int w, int h, int *x, int *y)
{
int i, j;
int best, best2;
int texnum;
for (texnum=0 ; texnum<MAX_SCRAPS ; texnum++)
{
for (texnum=0 ; texnum<MAX_SCRAPS ; texnum++) {
best = BLOCK_HEIGHT;
for (i=0 ; i<BLOCK_WIDTH-w ; i++)
{
for (i=0 ; i<BLOCK_WIDTH-w ; i++) {
best2 = 0;
for (j=0 ; j<w ; j++)
{
for (j=0 ; j<w ; j++) {
if (scrap_allocated[texnum][i+j] >= best)
break;
if (scrap_allocated[texnum][i+j] > best2)
best2 = scrap_allocated[texnum][i+j];
}
if (j == w)
{ // this is a valid spot
if (j == w) { // this is a valid spot
*x = i;
*y = best = best2;
}
@ -186,6 +185,7 @@ int Scrap_AllocBlock (int w, int h, int *x, int *y)
for (i=0 ; i<w ; i++)
scrap_allocated[texnum][*x + i] = best + h;
scrap_dirty = true;
return texnum;
}
@ -193,16 +193,15 @@ int Scrap_AllocBlock (int w, int h, int *x, int *y)
return 0;
}
int scrap_uploads;
void Scrap_Upload (void)
static void Scrap_Upload (void)
{
scrap_uploads++;
glBindTexture (GL_TEXTURE_2D, scrap_texnum);
GL_Upload8 (scrap_texels[0], BLOCK_WIDTH, BLOCK_HEIGHT, false, true);
scrap_dirty = false;
}
#endif
//=============================================================================
/* Support Routines */
@ -215,13 +214,10 @@ typedef struct cachepic_s
} cachepic_t;
#define MAX_CACHED_PICS 128
cachepic_t cachepics[MAX_CACHED_PICS];
int numcachepics;
static cachepic_t cachepics[MAX_CACHED_PICS];
static int numcachepics;
byte menuplyr_pixels[4096];
int pic_texels;
int pic_count;
static byte menuplyr_pixels[4096];
qpic_t *Draw_PicFromWad (char *name)
{
@ -231,15 +227,14 @@ qpic_t *Draw_PicFromWad (char *name)
p = W_GetLumpName (name);
gl = (glpic_t *)p->data;
#ifdef gl_draw_scraps
// load little ones into the scrap
if (p->width < 64 && p->height < 64)
{
if (p->width < 64 && p->height < 64) {
int x, y;
int i, j, k;
int texnum;
texnum = Scrap_AllocBlock (p->width, p->height, &x, &y);
scrap_dirty = true;
k = 0;
for (i=0 ; i<p->height ; i++)
for (j=0 ; j<p->width ; j++, k++)
@ -250,11 +245,9 @@ qpic_t *Draw_PicFromWad (char *name)
gl->sh = (x+p->width-0.01)/(float)BLOCK_WIDTH;
gl->tl = (y+0.01)/(float)BLOCK_WIDTH;
gl->th = (y+p->height-0.01)/(float)BLOCK_WIDTH;
pic_count++;
pic_texels += p->width*p->height;
}
else
#endif
{
gl->texnum = GL_LoadPicTexture (p);
gl->sl = 0;
@ -262,6 +255,7 @@ qpic_t *Draw_PicFromWad (char *name)
gl->tl = 0;
gl->th = 1;
}
return p;
}
@ -287,45 +281,53 @@ qpic_t *Draw_CachePic (char *path)
qpic_t *dat;
glpic_t *gl;
// First, check and see if its cached..
for (pic=cachepics, i=0 ; i<numcachepics ; pic++, i++)
if (!strcmp (path, pic->name))
break;
if ((!strcmp (path, pic->name)) && !pic->dirty)
return &pic->pic;
if (i == numcachepics)
{
if (numcachepics == MAX_CACHED_PICS)
Sys_Error ("menu_numcachepics == MAX_CACHED_PICS");
numcachepics++;
strcpy (pic->name, path);
}
else if (!pic->dirty)
return &pic->pic;
// Its not cached, lets make sure we have space in the cache..
if (numcachepics == MAX_CACHED_PICS)
Sys_Error ("menu_numcachepics == MAX_CACHED_PICS");
//
// load the pic from disk
//
// Load the picture..
dat = (qpic_t *)COM_LoadTempFile (path);
if (!dat)
Sys_Error ("Draw_CachePic: failed to load %s", path);
// Adjust for endian..
SwapPic (dat);
// HACK HACK HACK --- we need to keep the bytes for
// the translatable player picture just for the menu
// configuration dialog
// Ok, the image is here, lets load it up into the cache..
// First the image name..
strncpy (pic->name, path, sizeof(pic->name));
// Now the width and height.
pic->pic.width = dat->width;
pic->pic.height = dat->height;
// Now feed it to the GL stuff and get a texture number..
gl = (glpic_t *)pic->pic.data;
gl->texnum = GL_LoadPicTexture (dat);
// Alignment stuff..
gl->sl = 0; gl->sh = 1; gl->tl = 0; gl->th = 1;
// Now lets mark this cache entry as used..
pic->dirty = false;
numcachepics++;
// FIXME:
// A really ugly kluge, keep a specific image in memory
// for the menu system.
//
// Some days I really dislike legacy support..
if (!strcmp (path, "gfx/menuplyr.lmp"))
memcpy (menuplyr_pixels, dat->data, dat->width*dat->height);
pic->pic.width = dat->width;
pic->pic.height = dat->height;
pic->dirty = false;
gl = (glpic_t *)pic->pic.data;
gl->texnum = GL_LoadPicTexture (dat);
gl->sl = 0;
gl->sh = 1;
gl->tl = 0;
gl->th = 1;
// And now we are done, return what was asked for..
return &pic->pic;
}
@ -336,7 +338,7 @@ typedef struct
int minimize, maximize;
} glmode_t;
glmode_t modes[] = {
static glmode_t modes[] = {
{"GL_NEAREST", GL_NEAREST, GL_NEAREST},
{"GL_LINEAR", GL_LINEAR, GL_LINEAR},
{"GL_NEAREST_MIPMAP_NEAREST", GL_NEAREST_MIPMAP_NEAREST, GL_NEAREST},
@ -350,7 +352,7 @@ glmode_t modes[] = {
Draw_TextureMode_f
===============
*/
void Draw_TextureMode_f (void)
static void Draw_TextureMode_f (void)
{
int i;
gltexture_t *glt;
@ -461,9 +463,11 @@ void Draw_Init (void)
// save a texture slot for translated picture
translate_texture = texture_extension_number++;
#ifdef gl_draw_scraps
// save slots for scraps
scrap_texnum = texture_extension_number;
texture_extension_number += MAX_SCRAPS;
#endif
//
// get the other pics we need
@ -589,20 +593,6 @@ void Draw_Crosshair(void)
scr_vrect.y + scr_vrect.height/2-4 + cl_crossy->value, '+');
}
/*
================
Draw_DebugChar
Draws a single character directly to the upper right corner of the screen.
This is for debugging lockups by drawing different chars in different parts
of the code.
================
*/
void Draw_DebugChar (char num)
{
}
/*
=============
Draw_Pic
@ -612,8 +602,10 @@ void Draw_Pic (int x, int y, qpic_t *pic)
{
glpic_t *gl;
#ifdef gl_draw_scraps
if (scrap_dirty)
Scrap_Upload ();
#endif
gl = (glpic_t *)pic->data;
if (lighthalf)
glColor3f(0.4,0.4,0.4);
@ -632,47 +624,16 @@ void Draw_Pic (int x, int y, qpic_t *pic)
glEnd ();
}
/*
=============
Draw_AlphaPic
=============
*/
void Draw_AlphaPic (int x, int y, qpic_t *pic, float alpha)
{
glpic_t *gl;
if (scrap_dirty)
Scrap_Upload ();
gl = (glpic_t *)pic->data;
if (lighthalf)
glColor4f(0.4,0.4,0.4,alpha);
else
glColor4f(0.8,0.8,0.8,alpha);
glBindTexture (GL_TEXTURE_2D, gl->texnum);
glBegin (GL_QUADS);
glTexCoord2f (gl->sl, gl->tl);
glVertex2f (x, y);
glTexCoord2f (gl->sh, gl->tl);
glVertex2f (x+pic->width, y);
glTexCoord2f (gl->sh, gl->th);
glVertex2f (x+pic->width, y+pic->height);
glTexCoord2f (gl->sl, gl->th);
glVertex2f (x, y+pic->height);
glEnd ();
if (lighthalf)
glColor3f(0.5,0.5,0.5);
else
glColor3f(1,1,1);
}
void Draw_SubPic(int x, int y, qpic_t *pic, int srcx, int srcy, int width, int height)
{
glpic_t *gl;
float newsl, newtl, newsh, newth;
float oldglwidth, oldglheight;
#ifdef gl_draw_scraps
if (scrap_dirty)
Scrap_Upload ();
#endif
gl = (glpic_t *)pic->data;
oldglwidth = gl->sh - gl->sl;
@ -1013,31 +974,12 @@ void GL_Set2D (void)
//====================================================================
/*
================
GL_FindTexture
================
*/
int GL_FindTexture (char *identifier)
{
int i;
gltexture_t *glt;
for (i=0, glt=gltextures ; i<numgltextures ; i++, glt++)
{
if (!strcmp (identifier, glt->identifier))
return gltextures[i].texnum;
}
return -1;
}
/*
================
GL_ResampleTexture
================
*/
void GL_ResampleTexture (unsigned *in, int inwidth, int inheight, unsigned *out, int outwidth, int outheight)
static void GL_ResampleTexture (unsigned *in, int inwidth, int inheight, unsigned *out, int outwidth, int outheight)
{
int i, j;
unsigned *inrow;
@ -1067,7 +1009,7 @@ void GL_ResampleTexture (unsigned *in, int inwidth, int inheight, unsigned *out,
GL_Resample8BitTexture -- JACK
================
*/
void GL_Resample8BitTexture (unsigned char *in, int inwidth, int inheight, unsigned char *out, int outwidth, int outheight)
static void GL_Resample8BitTexture (unsigned char *in, int inwidth, int inheight, unsigned char *out, int outwidth, int outheight)
{
int i, j;
unsigned char *inrow;
@ -1099,7 +1041,7 @@ GL_MipMap
Operates in place, quartering the size of the texture
================
*/
void GL_MipMap (byte *in, int width, int height)
static void GL_MipMap (byte *in, int width, int height)
{
int i, j;
byte *out;
@ -1126,7 +1068,7 @@ GL_MipMap8Bit
Mipping for 8 bit textures
================
*/
void GL_MipMap8Bit (byte *in, int width, int height)
static void GL_MipMap8Bit (byte *in, int width, int height)
{
int i, j;
byte *out;
@ -1156,7 +1098,7 @@ void GL_MipMap8Bit (byte *in, int width, int height)
GL_Upload32
===============
*/
void GL_Upload32 (unsigned *data, int width, int height, qboolean mipmap, qboolean alpha)
static void GL_Upload32 (unsigned *data, int width, int height, qboolean mipmap, qboolean alpha)
{
int samples;
static unsigned scaled[1024*512]; // [512*256];
@ -1190,7 +1132,6 @@ static unsigned scaled[1024*512]; // [512*256];
glTexImage2D (GL_TEXTURE_2D, 0, samples, scaled_width, scaled_height, 0, GL_RGBA, GL_UNSIGNED_BYTE, scaled);
}
#else
texels += scaled_width * scaled_height;
if (scaled_width == width && scaled_height == height)
{
@ -1278,8 +1219,6 @@ void GL_Upload8_EXT (byte *data, int width, int height, qboolean mipmap, qboole
samples = 1; // alpha ? gl_alpha_format : gl_solid_format;
texels += scaled_width * scaled_height;
if (scaled_width == width && scaled_height == height)
{
if (!mipmap)
@ -1384,7 +1323,12 @@ static unsigned trans[640*480]; // FIXME, temporary
}
}
if (VID_Is8bit() && !alpha && (data!=scrap_texels[0])) {
#ifdef gl_draw_scraps
if (VID_Is8bit() && !alpha && (data!=scrap_texels[0]))
#else
if (VID_Is8bit() && !alpha)
#endif
{
GL_Upload8_EXT (data, width, height, mipmap, alpha);
return;
}
@ -1399,10 +1343,8 @@ GL_LoadTexture
*/
int GL_LoadTexture (char *identifier, int width, int height, byte *data, qboolean mipmap, qboolean alpha, int bytesperpixel)
{
int i;
int s;
int lcrc;
gltexture_t *glt;
int i, s, lcrc;
gltexture_t *glt;
// LordHavoc's cache check, not a standard crc but it works --KB
lcrc = 0;
@ -1430,10 +1372,15 @@ int GL_LoadTexture (char *identifier, int width, int height, byte *data, qboolea
}
}
if (numgltextures == MAX_GLTEXTURES)
Sys_Error ("numgltextures == MAX_GLTEXTURES");
glt = &gltextures[numgltextures];
numgltextures++;
strcpy (glt->identifier, identifier);
strncpy (glt->identifier, identifier, sizeof(glt->identifier) - 1);
glt->identifier[sizeof(glt->identifier) - 1] = '\0';
glt->texnum = texture_extension_number;
texture_extension_number++;
@ -1468,7 +1415,7 @@ SetupTexture:
GL_LoadPicTexture
================
*/
int GL_LoadPicTexture (qpic_t *pic)
static int GL_LoadPicTexture (qpic_t *pic)
{
return GL_LoadTexture ("", pic->width, pic->height, pic->data, false, true, 1);
}

View file

@ -392,64 +392,65 @@ Bad sides: affects gamespy and spytools somewhat...
================
*/
int CheckForFlood(char cmdtype)
int CheckForFlood(flood_enum_t cmdtype)
{
static qboolean firsttime=true;
static flood_t floodstatus[DOSFLOODCMDS][DOSFLOODIP];
static qboolean firsttime = true;
static flood_t floodstatus[DOSFLOODCMDS][DOSFLOODIP];
int i;
double currenttime;
double oldestTime;
static double lastmessagetime=0;
int oldest;
int i;
double currenttime;
double oldestTime;
static double lastmessagetime=0;
int oldest;
if (!sv_netdosprotect->value) return 0;
if (!sv_netdosprotect->value)
return 0;
oldestTime=0x7fffffff;
oldest=0;
oldestTime = 0x7fffffff;
oldest = 0;
if (firsttime) {
memset(floodstatus,sizeof(flood_t)*DOSFLOODCMDS*DOSFLOODIP,0);
firsttime=false;
}
memset (floodstatus, sizeof(flood_t) * DOSFLOODCMDS * DOSFLOODIP, 0);
firsttime = false;
}
currenttime=Sys_DoubleTime();
currenttime = Sys_DoubleTime();
for (i = 0 ; i < DOSFLOODIP ; i++)
{
for (i = 0 ; i < DOSFLOODIP ; i++) {
if (NET_CompareBaseAdr (net_from, floodstatus[cmdtype][i].adr))
break;
if (floodstatus[cmdtype][i].issued < oldestTime)
{
if (floodstatus[cmdtype][i].issued < oldestTime) {
oldestTime = floodstatus[cmdtype][i].issued;
oldest = i;
}
}
if (i<DOSFLOODIP && floodstatus[cmdtype][i].issued)
if(floodstatus[cmdtype][i].issued+netdosexpire[cmdtype]>currenttime)
{
floodstatus[cmdtype][i].floodcount+=1;
if (floodstatus[cmdtype][i].floodcount>netdosvalues[cmdtype])
{
if (lastmessagetime+5<currenttime)
Con_Printf("Blocking type %d flood from (or to) %s\n",cmdtype,NET_AdrToString(net_from));
floodstatus[cmdtype][i].floodcount=0;
if (i < DOSFLOODIP && floodstatus[cmdtype][i].issued) {
if ((floodstatus[cmdtype][i].issued + netdosexpire[cmdtype])
> currenttime) {
floodstatus[cmdtype][i].floodcount += 1;
if (floodstatus[cmdtype][i].floodcount > netdosvalues[cmdtype]) {
if ((lastmessagetime + 5) < currenttime)
Con_Printf("Blocking type %d flood from (or to) %s\n",
cmdtype, NET_AdrToString(net_from));
floodstatus[cmdtype][i].floodcount = 0;
floodstatus[cmdtype][i].issued = currenttime;
floodstatus[cmdtype][i].cmdcount+=1;
lastmessagetime=currenttime;
return 1;
}
} else floodstatus[cmdtype][i].floodcount=0;
floodstatus[cmdtype][i].cmdcount += 1;
lastmessagetime = currenttime;
return 1;
}
} else {
floodstatus[cmdtype][i].floodcount = 0;
}
}
if (i == DOSFLOODIP)
{
if (i == DOSFLOODIP) {
i = oldest;
floodstatus[cmdtype][i].adr = net_from;
floodstatus[cmdtype][i].firstseen=currenttime;
floodstatus[cmdtype][i].firstseen = currenttime;
}
floodstatus[cmdtype][i].issued = currenttime;
floodstatus[cmdtype][i].cmdcount+=1;
floodstatus[cmdtype][i].cmdcount += 1;
return 0;
}