Skip to content

Commit

Permalink
Use animated arrows instead of particles to draw pointfiles
Browse files Browse the repository at this point in the history
Also, print "Leak" at the beginning of the pointfile
and add a console warning when a leak is detected.
  • Loading branch information
andrei-drexler committed Nov 27, 2024
1 parent 7238bc0 commit 26902e0
Show file tree
Hide file tree
Showing 5 changed files with 133 additions and 58 deletions.
110 changes: 108 additions & 2 deletions Quake/gl_rmain.c
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ qboolean r_cache_thrash; // compatability

gpuframedata_t r_framedata;

vec3_t *r_pointfile;

int r_visframecount; // bumped when going to a new PVS
int r_framecount; // used for dlight push checking

Expand Down Expand Up @@ -1165,7 +1167,8 @@ void R_DrawViewModel (void)
GL_EndGroup ();
}

typedef struct debugvert_s {
typedef struct debugvert_s
{
vec3_t pos;
uint32_t color;
} debugvert_t;
Expand All @@ -1174,6 +1177,7 @@ static debugvert_t debugverts[4096];
static uint16_t debugidx[8192];
static int numdebugverts = 0;
static int numdebugidx = 0;
static qboolean debugztest = false;

/*
================
Expand All @@ -1186,9 +1190,13 @@ static void R_FlushDebugGeometry (void)
{
GLuint buf;
GLbyte *ofs;
unsigned int state;

GL_UseProgram (glprogs.debug3d);
GL_SetState (GLS_BLEND_ALPHA | GLS_NO_ZTEST | GLS_NO_ZWRITE | GLS_CULL_NONE | GLS_ATTRIBS(2));
state = GLS_BLEND_ALPHA | GLS_NO_ZWRITE | GLS_CULL_NONE | GLS_ATTRIBS(2);
if (!debugztest)
state |= GLS_NO_ZTEST;
GL_SetState (state);

GL_Upload (GL_ARRAY_BUFFER, debugverts, sizeof (debugverts[0]) * numdebugverts, &buf, &ofs);
GL_BindBuffer (GL_ARRAY_BUFFER, buf);
Expand All @@ -1204,6 +1212,19 @@ static void R_FlushDebugGeometry (void)
numdebugidx = 0;
}

/*
================
R_SetDebugGeometryZTest
================
*/
static void R_SetDebugGeometryZTest (qboolean ztest)
{
if (debugztest == ztest)
return;
R_FlushDebugGeometry ();
debugztest = ztest;
}

/*
================
R_AddDebugGeometry
Expand Down Expand Up @@ -1475,6 +1496,8 @@ static void R_ShowBoundingBoxes (void)

GL_BeginGroup ("Show bounding boxes");

R_SetDebugGeometryZTest (false);

oldvm = qcvm;
PR_SwitchQCVM(NULL);
PR_SwitchQCVM(&sv.qcvm);
Expand Down Expand Up @@ -1668,6 +1691,87 @@ static void R_ShowBoundingBoxes (void)
GL_EndGroup ();
}

/*
===============
R_ShowPointFile
===============
*/
static void R_ShowPointFile (void)
{
size_t i;

if (VEC_SIZE (r_pointfile) == 0)
return;

GL_BeginGroup ("Point file");
R_SetDebugGeometryZTest (true);
for (i = 1; i < VEC_SIZE (r_pointfile); i++)
R_EmitArrow (r_pointfile[i - 1], r_pointfile[i], 0xff3f3f7f);
R_FlushDebugGeometry ();
GL_EndGroup ();
}

/*
===============
Collinear
===============
*/
static qboolean Collinear (const vec3_t a, const vec3_t b, const vec3_t c)
{
return Distance (a, b) + Distance (b, c) < Distance (a, c) * 1.00001f;
}

/*
===============
R_ReadPointFile_f
===============
*/
void R_ReadPointFile_f (void)
{
FILE *f;
vec3_t org;
int r, n;
qboolean leakmode;
char name[MAX_QPATH];

VEC_CLEAR (r_pointfile);

if (cls.state != ca_connected)
return; // need an active map.

q_snprintf (name, sizeof(name), "maps/%s.pts", cl.mapname);
leakmode = Cmd_Argc () >= 2 && !strcmp (Cmd_Argv (1), "leak");

COM_FOpenFile (name, &f, NULL);
if (!f)
{
Con_Printf ("couldn't open %s\n", name);
return;
}

if (!leakmode)
Con_Printf ("Reading %s...\n", name);
org[0] = org[1] = org[2] = 0; // silence pesky compiler warnings

for (r = 0; fscanf (f,"%f %f %f\n", &org[0], &org[1], &org[2]) == 3; r++)
{
Vec_Append ((void **) &r_pointfile, sizeof (r_pointfile[0]), &org, 1);
n = (int) VEC_SIZE (r_pointfile);
if (n >= 3 && Collinear (r_pointfile[n-3], r_pointfile[n-2], r_pointfile[n-1]))
{
VectorCopy (r_pointfile[n-1], r_pointfile[n-2]);
VEC_POP (r_pointfile);
}
}

fclose (f);

if (leakmode)
Con_Warning ("map appears to have leaks!\n");
else
Con_Printf ("%i points read (%i significant)\n", r, (int) VEC_SIZE (r_pointfile));
}

/*
================
R_ShowTris -- johnfitz
Expand Down Expand Up @@ -1815,6 +1919,8 @@ void R_RenderScene (void)
R_ShowTris (); //johnfitz

R_ShowBoundingBoxes (); //johnfitz

R_ShowPointFile ();
}

/*
Expand Down
3 changes: 2 additions & 1 deletion Quake/gl_rmisc.c
Original file line number Diff line number Diff line change
Expand Up @@ -514,6 +514,7 @@ void R_NewMap (void)
R_ClearEfrags ();
r_viewleaf = NULL;
R_ClearParticles ();
VEC_CLEAR (r_pointfile);

GL_BuildLightmaps ();
GL_BuildBModelVertexBuffer ();
Expand All @@ -530,7 +531,7 @@ void R_NewMap (void)
// Load pointfile if map has no vis data and either developer mode is on or the game was started from a map editing tool
if (developer.value || map_checks.value)
if (!cl.worldmodel->visdata && COM_FileExists (va ("maps/%s.pts", cl.mapname), NULL))
Cbuf_AddText ("pointfile\n");
Cbuf_AddText ("pointfile leak\n");
}

/*
Expand Down
23 changes: 21 additions & 2 deletions Quake/gl_screen.c
Original file line number Diff line number Diff line change
Expand Up @@ -1353,15 +1353,34 @@ void SCR_DrawEdictInfo (void)
vec3_t crosshair, focus, anchor, proj, bgcolor;
edict_t *ed;

if (VEC_SIZE (bbox_linked) == 0)
if (VEC_SIZE (bbox_linked) == 0 && VEC_SIZE (r_pointfile) == 0)
return;

GL_SetCanvas (CANVAS_BOTTOMRIGHT);
SCR_SetupProjToCanvasMap (&proj2canvas);
VectorMA (r_origin, 8.f, vpn, crosshair);

// If a pointfile was loaded, print "Leak" at the beginning
if (VEC_SIZE (r_pointfile) != 0)
{
VectorCopy (r_pointfile[0], anchor);
SCR_ClipToFrustum (anchor, crosshair);
ProjectVector (anchor, r_matviewproj, proj);
SCR_ProjToCanvas (proj, &proj2canvas, &x, &y);

VEC_CLEAR (scr_edictoverlaystrings);
MultiString_Append (&scr_edictoverlaystrings, "");
COM_TintString ("Leak", tinted, sizeof (tinted));
MultiString_Append (&scr_edictoverlaystrings, tinted);

SCR_DrawKeyValueOverlay (x, y, scr_edictoverlaystrings, rgb_black);
}

if (VEC_SIZE (bbox_linked) == 0)
return;

PR_SwitchQCVM (&sv.qcvm);

VectorMA (r_origin, 8.f, vpn, crosshair);
SCR_GetEntityCenter (bbox_linked[0], focus);
SCR_ClipToFrustum (focus, crosshair);

Expand Down
2 changes: 2 additions & 0 deletions Quake/glquake.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ extern int glx, gly, glwidth, glheight;

#define BACKFACE_EPSILON 0.01

extern vec3_t *r_pointfile;

void R_TimeRefresh_f (void);
void R_ReadPointFile_f (void);
texture_t *R_TextureAnimation (texture_t *base, int frame);
Expand Down
53 changes: 0 additions & 53 deletions Quake/r_part.c
Original file line number Diff line number Diff line change
Expand Up @@ -186,59 +186,6 @@ void R_ClearParticles (void)
r_numactiveparticles = 0;
}

/*
===============
R_ReadPointFile_f
===============
*/
void R_ReadPointFile_f (void)
{
FILE *f;
vec3_t org;
int r;
int c;
particle_t *p;
char name[MAX_QPATH];

if (cls.state != ca_connected)
return; // need an active map.

q_snprintf (name, sizeof(name), "maps/%s.pts", cl.mapname);

COM_FOpenFile (name, &f, NULL);
if (!f)
{
Con_Printf ("couldn't open %s\n", name);
return;
}

Con_Printf ("Reading %s...\n", name);
c = 0;
org[0] = org[1] = org[2] = 0; // silence pesky compiler warnings
for ( ;; )
{
r = fscanf (f,"%f %f %f\n", &org[0], &org[1], &org[2]);
if (r != 3)
break;
c++;

if (!(p = R_AllocParticle ()))
{
Con_Printf ("Not enough free particles\n");
break;
}

p->die = 99999;
p->color = (-c)&15;
p->type = pt_static;
VectorCopy (vec3_origin, p->vel);
VectorCopy (org, p->org);
}

fclose (f);
Con_Printf ("%i points read\n", c);
}

/*
===============
R_ParseParticleEffect
Expand Down

0 comments on commit 26902e0

Please sign in to comment.