testing new cg_drawping code

This commit is contained in:
Bryce Hutchings 2002-07-11 04:26:12 +00:00
parent b907328cbc
commit 58788cd1ee

View file

@ -5,6 +5,9 @@
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
// //
// $Log$ // $Log$
// Revision 1.57 2002/07/11 04:26:12 niceass
// testing new cg_drawping code
//
// Revision 1.56 2002/07/09 05:44:08 niceass // Revision 1.56 2002/07/09 05:44:08 niceass
// ctb fixes // ctb fixes
// //
@ -152,6 +155,18 @@ char teamChat2[256];
#define LAG_SAMPLES 128
typedef struct {
int frameSamples[LAG_SAMPLES];
int frameCount;
int snapshotFlags[LAG_SAMPLES];
int snapshotSamples[LAG_SAMPLES];
int snapshotCount;
} lagometer_t;
lagometer_t lagometer;
/* /*
============== ==============
@ -690,15 +705,17 @@ static float CG_DrawFPSandPing(float y)
char *s; char *s;
int w; int w;
static int previousTimes[FPS_FRAMES]; static int previousTimes[FPS_FRAMES];
static int index, index2; static int index;
int i, total; int i, total, l;
int fps; int fps;
static int previous; static int previous;
int t, frameTime, x = 0; int t, frameTime, x = 0;
float Color[4]; float Color[4];
static int Pings[PING_SNAPS]; /*static int Pings[PING_SNAPS];
static int currentSnapshotNum; static int currentSnapshotNum;
static int index2;*/
int avgping = 0;
// don't use serverTime, because that will be drifting to // don't use serverTime, because that will be drifting to
@ -711,11 +728,11 @@ static float CG_DrawFPSandPing(float y)
previousTimes[index % FPS_FRAMES] = frameTime; previousTimes[index % FPS_FRAMES] = frameTime;
if (cg.latestSnapshotNum != currentSnapshotNum && cg.snap) { /*if (cg.latestSnapshotNum != currentSnapshotNum && cg.snap) {
Pings[index2 % PING_SNAPS] = cg.snap->ping; Pings[index2 % PING_SNAPS] = cg.snap->ping;
currentSnapshotNum = cg.latestSnapshotNum; currentSnapshotNum = cg.latestSnapshotNum;
index2++; index2++;
} }*/
index++; index++;
@ -748,29 +765,38 @@ static float CG_DrawFPSandPing(float y)
} }
// Draw ping here: // Draw ping here:
if (index2 > PING_SNAPS) { //if (index2 > PING_SNAPS) {
int avgping = 0, l;
for (l = 0; l < PING_SNAPS; l++) {
avgping += Pings[l];
}
avgping /= PING_SNAPS;
if (cg_drawPing.integer) { if (cg_drawPing.integer) {
for (i = 0; i < (LAG_SAMPLES / 2); i++) {
l = (lagometer.frameCount - 1 - i) & (LAG_SAMPLES - 1);
avgping += lagometer.snapshotSamples[i];
}
avgping /= (LAG_SAMPLES / 2);
s = va("%ims", avgping); s = va("%ims", avgping);
w = CG_DrawStrlen(s) * SMALLCHAR_WIDTH; w = CG_DrawStrlen(s) * SMALLCHAR_WIDTH;
x += w; x += w;
i = (lagometer.frameCount - 1) & (LAG_SAMPLES - 1);
MAKERGBA(Color, 0.0f, 0.0f, 0.0f, 0.4f); MAKERGBA(Color, 0.0f, 0.0f, 0.0f, 0.4f);
CG_FillRect(631 - x - 3, y - 1, w + 6, SMALLCHAR_HEIGHT + 6, Color); CG_FillRect(631 - x - 3, y - 1, w + 6, SMALLCHAR_HEIGHT + 6, Color);
MAKERGBA(Color, 0.0f, 0.0f, 0.0f, 1.0f); MAKERGBA(Color, 0.0f, 1.0f, 0.0f, 1.0f); // Green, All good
if (lagometer.snapshotSamples[i] < 0)
MAKERGBA(Color, 1.0f, 0.0f, 0.0f, 1.0f); // Red. Missed packet
if (lagometer.snapshotFlags[i] & SNAPFLAG_RATE_DELAYED) // Yellow. Delayed packet
MAKERGBA(Color, 1.0f, 1.0f, 0.0f, 1.0f);
CG_DrawCleanRect(631 - x - 3, y - 1, w + 6, SMALLCHAR_HEIGHT + 6, 1, Color); CG_DrawCleanRect(631 - x - 3, y - 1, w + 6, SMALLCHAR_HEIGHT + 6, 1, Color);
CG_DrawSmallString(631 - x, y + 2, s, 1.0F); CG_DrawSmallString(631 - x, y + 2, s, 1.0F);
} }
} //}
if (!cg_drawFPS.integer && !cg_drawPing.integer) if (!cg_drawFPS.integer && !cg_drawPing.integer)
return y; return y;
@ -1353,17 +1379,6 @@ LAGOMETER
=============================================================================== ===============================================================================
*/ */
#define LAG_SAMPLES 128
typedef struct {
int frameSamples[LAG_SAMPLES];
int frameCount;
int snapshotFlags[LAG_SAMPLES];
int snapshotSamples[LAG_SAMPLES];
int snapshotCount;
} lagometer_t;
lagometer_t lagometer;
/* /*
============== ==============