2000-05-10 20:33:16 +00:00
|
|
|
/*
|
2000-05-11 16:03:29 +00:00
|
|
|
gl_ngraph.c
|
2000-05-10 20:33:16 +00:00
|
|
|
|
2000-05-11 16:03:29 +00:00
|
|
|
(description)
|
2000-05-10 20:33:16 +00:00
|
|
|
|
2000-05-11 16:03:29 +00:00
|
|
|
Copyright (C) 1996-1997 Id Software, Inc.
|
2000-05-10 20:33:16 +00:00
|
|
|
|
2000-05-11 16:03:29 +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.
|
2000-05-10 20:33:16 +00:00
|
|
|
|
2000-05-11 16:03:29 +00:00
|
|
|
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.
|
2000-05-10 20:33:16 +00:00
|
|
|
|
2000-05-11 16:03:29 +00:00
|
|
|
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
|
|
|
|
|
|
|
|
$Id$
|
2000-05-10 20:33:16 +00:00
|
|
|
*/
|
2000-05-22 06:58:14 +00:00
|
|
|
|
2000-05-17 10:03:19 +00:00
|
|
|
#ifdef HAVE_CONFIG_H
|
2000-05-23 17:05:34 +00:00
|
|
|
# include "config.h"
|
2000-05-17 10:03:19 +00:00
|
|
|
#endif
|
2000-12-30 02:16:36 +00:00
|
|
|
|
|
|
|
#ifdef HAVE_STRING_H
|
2000-05-12 19:17:02 +00:00
|
|
|
#include <string.h>
|
2000-12-30 02:16:36 +00:00
|
|
|
#endif
|
|
|
|
#ifdef HAVE_STRINGS_H
|
|
|
|
#include <strings.h>
|
|
|
|
#endif
|
2000-05-12 19:17:02 +00:00
|
|
|
#include <stdio.h>
|
|
|
|
|
2000-12-30 02:16:36 +00:00
|
|
|
#include "cl_parse.h"
|
2000-05-12 19:17:02 +00:00
|
|
|
#include "cvar.h"
|
2000-12-30 02:16:36 +00:00
|
|
|
#include "draw.h"
|
2000-05-12 19:17:02 +00:00
|
|
|
#include "glquake.h"
|
2000-12-30 02:16:36 +00:00
|
|
|
#include "sbar.h"
|
2000-05-10 11:29:38 +00:00
|
|
|
|
2000-12-12 02:46:46 +00:00
|
|
|
extern byte *draw_chars; // 8*8 graphic characters
|
2000-07-02 05:16:10 +00:00
|
|
|
extern qboolean lighthalf;
|
2000-05-10 11:29:38 +00:00
|
|
|
|
2000-12-12 02:46:46 +00:00
|
|
|
extern cvar_t *r_netgraph;
|
|
|
|
extern cvar_t *r_netgraph_alpha;
|
|
|
|
extern cvar_t *r_netgraph_box;
|
|
|
|
|
|
|
|
int netgraphtexture; // netgraph texture
|
2000-05-10 11:29:38 +00:00
|
|
|
|
|
|
|
#define NET_GRAPHHEIGHT 32
|
|
|
|
|
2000-12-08 06:51:37 +00:00
|
|
|
static byte ngraph_texels[NET_GRAPHHEIGHT][NET_TIMINGS];
|
2000-05-10 11:29:38 +00:00
|
|
|
|
2000-12-08 06:51:37 +00:00
|
|
|
static void
|
|
|
|
R_LineGraph (int x, int h)
|
2000-05-10 11:29:38 +00:00
|
|
|
{
|
2000-12-08 06:51:37 +00:00
|
|
|
int i;
|
|
|
|
int s;
|
|
|
|
int color;
|
2000-05-10 11:29:38 +00:00
|
|
|
|
|
|
|
s = NET_GRAPHHEIGHT;
|
|
|
|
|
|
|
|
if (h == 10000)
|
2000-12-08 06:51:37 +00:00
|
|
|
color = 0x6f; // yellow
|
2000-05-10 11:29:38 +00:00
|
|
|
else if (h == 9999)
|
2000-12-08 06:51:37 +00:00
|
|
|
color = 0x4f; // red
|
2000-05-10 11:29:38 +00:00
|
|
|
else if (h == 9998)
|
2000-12-08 06:51:37 +00:00
|
|
|
color = 0xd0; // blue
|
2000-05-10 11:29:38 +00:00
|
|
|
else
|
2000-12-08 06:51:37 +00:00
|
|
|
color = 0xfe; // white
|
2000-05-10 11:29:38 +00:00
|
|
|
|
2000-12-08 06:51:37 +00:00
|
|
|
if (h > s)
|
2000-05-10 11:29:38 +00:00
|
|
|
h = s;
|
2000-12-08 06:51:37 +00:00
|
|
|
|
|
|
|
for (i = 0; i < h; i++)
|
2000-05-10 11:29:38 +00:00
|
|
|
if (i & 1)
|
|
|
|
ngraph_texels[NET_GRAPHHEIGHT - i - 1][x] = 0xff;
|
|
|
|
else
|
2000-12-08 06:51:37 +00:00
|
|
|
ngraph_texels[NET_GRAPHHEIGHT - i - 1][x] = (byte) color;
|
2000-05-10 11:29:38 +00:00
|
|
|
|
2000-12-08 06:51:37 +00:00
|
|
|
for (; i < s; i++)
|
|
|
|
ngraph_texels[NET_GRAPHHEIGHT - i - 1][x] = (byte) 0xff;
|
2000-05-10 11:29:38 +00:00
|
|
|
}
|
|
|
|
|
2000-12-08 06:51:37 +00:00
|
|
|
void
|
|
|
|
Draw_CharToNetGraph (int x, int y, int num)
|
2000-05-10 11:29:38 +00:00
|
|
|
{
|
2000-12-08 06:51:37 +00:00
|
|
|
int row, col;
|
|
|
|
byte *source;
|
|
|
|
int drawline;
|
|
|
|
int nx;
|
|
|
|
|
|
|
|
row = num >> 4;
|
|
|
|
col = num & 15;
|
|
|
|
source = draw_chars + (row << 10) + (col << 3);
|
|
|
|
|
|
|
|
for (drawline = 8; drawline; drawline--, y++) {
|
|
|
|
for (nx = 0; nx < 8; nx++)
|
2000-05-10 11:29:38 +00:00
|
|
|
if (source[nx] != 255)
|
2000-12-08 06:51:37 +00:00
|
|
|
ngraph_texels[y][nx + x] = 0x60 + source[nx];
|
2000-05-10 11:29:38 +00:00
|
|
|
source += 128;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
==============
|
|
|
|
R_NetGraph
|
|
|
|
==============
|
|
|
|
*/
|
2000-12-08 06:51:37 +00:00
|
|
|
void
|
|
|
|
R_NetGraph (void)
|
2000-05-10 11:29:38 +00:00
|
|
|
{
|
2000-12-08 06:51:37 +00:00
|
|
|
int a, x, i, y;
|
|
|
|
int lost;
|
|
|
|
char st[80];
|
|
|
|
unsigned int ngraph_pixels[NET_GRAPHHEIGHT][NET_TIMINGS];
|
2000-05-10 11:29:38 +00:00
|
|
|
|
|
|
|
x = 0;
|
2000-12-08 06:51:37 +00:00
|
|
|
lost = CL_CalcNet ();
|
|
|
|
for (a = 0; a < NET_TIMINGS; a++) {
|
|
|
|
i = (cls.netchan.outgoing_sequence - a) & NET_TIMINGSMASK;
|
|
|
|
R_LineGraph (NET_TIMINGS - 1 - a, packet_latency[i]);
|
2000-05-10 11:29:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// now load the netgraph texture into gl and draw it
|
|
|
|
for (y = 0; y < NET_GRAPHHEIGHT; y++)
|
|
|
|
for (x = 0; x < NET_TIMINGS; x++)
|
|
|
|
ngraph_pixels[y][x] = d_8to24table[ngraph_texels[y][x]];
|
|
|
|
|
2000-12-12 02:46:46 +00:00
|
|
|
x = cl_hudswap->int_val ? vid.width - (NET_TIMINGS + 16): 0 ;
|
2000-05-10 11:29:38 +00:00
|
|
|
y = vid.height - sb_lines - 24 - NET_GRAPHHEIGHT - 1;
|
|
|
|
|
2000-12-12 02:46:46 +00:00
|
|
|
if (r_netgraph_alpha->value < 0.995) // roundoff
|
|
|
|
glColor4f (1, 1, 1, r_netgraph_alpha->value);
|
|
|
|
|
|
|
|
if (r_netgraph_box->int_val)
|
|
|
|
Draw_TextBox (x, y, NET_TIMINGS / 8, NET_GRAPHHEIGHT / 8 + 1);
|
|
|
|
|
2000-05-10 11:29:38 +00:00
|
|
|
y += 8;
|
|
|
|
|
2000-12-08 06:51:37 +00:00
|
|
|
snprintf (st, sizeof (st), "%3i%% packet loss", lost);
|
2000-12-12 02:46:46 +00:00
|
|
|
if (cl_hudswap->int_val) {
|
|
|
|
Draw_String8 (vid.width - ((strlen (st) * 8) + 8), y, st);
|
|
|
|
} else {
|
|
|
|
Draw_String8 (8, y, st);
|
|
|
|
}
|
|
|
|
|
|
|
|
x = cl_hudswap->int_val ? vid.width - (NET_TIMINGS + 8) : 8;
|
|
|
|
|
2000-05-10 11:29:38 +00:00
|
|
|
y += 8;
|
|
|
|
|
2000-12-08 06:51:37 +00:00
|
|
|
glBindTexture (GL_TEXTURE_2D, netgraphtexture);
|
2000-05-10 11:29:38 +00:00
|
|
|
|
2000-12-08 06:51:37 +00:00
|
|
|
glTexImage2D (GL_TEXTURE_2D, 0, gl_alpha_format,
|
|
|
|
NET_TIMINGS, NET_GRAPHHEIGHT, 0, GL_RGBA,
|
|
|
|
GL_UNSIGNED_BYTE, ngraph_pixels);
|
|
|
|
|
|
|
|
glTexParameterf (GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
|
|
|
|
glTexParameterf (GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
|
2000-05-10 11:29:38 +00:00
|
|
|
|
|
|
|
glBegin (GL_QUADS);
|
|
|
|
glTexCoord2f (0, 0);
|
|
|
|
glVertex2f (x, y);
|
|
|
|
glTexCoord2f (1, 0);
|
2000-12-08 06:51:37 +00:00
|
|
|
glVertex2f (x + NET_TIMINGS, y);
|
2000-05-10 11:29:38 +00:00
|
|
|
glTexCoord2f (1, 1);
|
2000-12-08 06:51:37 +00:00
|
|
|
glVertex2f (x + NET_TIMINGS, y + NET_GRAPHHEIGHT);
|
2000-05-10 11:29:38 +00:00
|
|
|
glTexCoord2f (0, 1);
|
2000-12-08 06:51:37 +00:00
|
|
|
glVertex2f (x, y + NET_GRAPHHEIGHT);
|
2000-05-10 11:29:38 +00:00
|
|
|
glEnd ();
|
2000-12-12 02:46:46 +00:00
|
|
|
|
|
|
|
glColor3ubv (lighthalf_v);
|
2000-05-10 11:29:38 +00:00
|
|
|
}
|