Kill r_particles->int_val testing in gl particle engine. Also merge a bit down to r_part.c/r_cvar.c. Properly declare cl_max_particles (how the heck was it working when only ever declared as exter cvar_t *cl_max_particles?).

Should be a minor speedup for gl, definitely a code cleanup.
This commit is contained in:
Ragnvald Maartmann-Moe IV 2001-09-22 02:37:45 +00:00
parent 0425afb190
commit bb6796247c
5 changed files with 81 additions and 165 deletions

View file

@ -54,16 +54,11 @@
#include "r_shared.h" #include "r_shared.h"
#include "varrays.h" #include "varrays.h"
static particle_t *particles, **freeparticles;
static short r_maxparticles, numparticles;
int ramp[8] = { 0x6f, 0x6d, 0x6b, 0x69, 0x67, 0x65, 0x63, 0x61 }; int ramp[8] = { 0x6f, 0x6d, 0x6b, 0x69, 0x67, 0x65, 0x63, 0x61 };
extern int part_tex_dot; extern int part_tex_dot, part_tex_spark, part_tex_smoke[8];
extern int part_tex_spark; extern short r_maxparticles, numparticles;
extern int part_tex_smoke[8]; extern particle_t *particles, **freeparticles;
extern cvar_t *cl_max_particles;
inline particle_t * inline particle_t *
@ -110,51 +105,9 @@ particle_new_random (ptype_t type, int texnum, vec3_t org, int org_fuzz,
return particle_new (type, texnum, porg, scale, pvel, die, color, alpha); return particle_new (type, texnum, porg, scale, pvel, die, color, alpha);
} }
/*
R_MaxParticlesCheck
Misty-chan: Dynamically change the maximum amount of particles on the fly.
Thanks to a LOT of help from Taniwha, Deek, Mercury, Lordhavoc, and lots of
others.
*/
void
R_MaxParticlesCheck (cvar_t *var)
{
/*
Catchall. If the user changed the setting to a number less than zero *or*
if we had a wacky cfg get past the init code check, this will make sure we
don't have problems. Also note that grabbing the var->int_val is IMPORTANT:
Prevents a segfault since if we grabbed the int_val of cl_max_particles
we'd sig11 right here at startup.
*/
r_maxparticles = max(var->int_val, 0);
/*
Be very careful the next time we do something like this. calloc/free are
IMPORTANT and the compiler doesn't know when we do bad things with them.
*/
free (particles);
free (freeparticles);
particles = (particle_t *) calloc (r_maxparticles, sizeof (particle_t));
freeparticles = (particle_t **)
calloc (r_maxparticles, sizeof (particle_t *));
R_ClearParticles();
}
void void
R_Particles_Init_Cvars (void) R_Particles_Init_Cvars (void)
{ {
/*
Misty-chan: This is a cvar that does callbacks. Whenever it
changes, it calls the function R_MaxParticlesCheck and therefore
is very nifty.
*/
Cvar_Get ("cl_max_particles", "2048", CVAR_ARCHIVE, R_MaxParticlesCheck,
"Maximum amount of particles to display. No maximum, minimum "
"is 0, although it's best to use r_particles 0 instead.");
} }
inline void inline void
@ -216,9 +169,6 @@ R_ParticleExplosion (vec3_t org)
// int i; // int i;
// int j = 1024; // int j = 1024;
if (!r_particles->int_val)
return;
if (numparticles >= r_maxparticles) if (numparticles >= r_maxparticles)
return; return;
// else if (numparticles + j >= r_maxparticles) // else if (numparticles + j >= r_maxparticles)
@ -242,9 +192,6 @@ R_ParticleExplosion2 (vec3_t org, int colorStart, int colorLength)
int i; int i;
int colorMod = 0, j = 512; int colorMod = 0, j = 512;
if (!r_particles->int_val)
return;
if (numparticles >= r_maxparticles) if (numparticles >= r_maxparticles)
return; return;
else if (numparticles + j >= r_maxparticles) else if (numparticles + j >= r_maxparticles)
@ -264,9 +211,6 @@ R_BlobExplosion (vec3_t org)
int i; int i;
int j = 1024; int j = 1024;
if (!r_particles->int_val)
return;
if (numparticles >= r_maxparticles) if (numparticles >= r_maxparticles)
return; return;
else if (numparticles + j >= r_maxparticles) else if (numparticles + j >= r_maxparticles)
@ -317,7 +261,8 @@ R_BloodPuff (vec3_t org, int count)
void void
R_RunPuffEffect (vec3_t org, particle_effect_t type, byte count) R_RunPuffEffect (vec3_t org, particle_effect_t type, byte count)
{ {
if (!r_particles->int_val) // FIXME: Is this test worthwhile?
if (numparticles >= r_maxparticles)
return; return;
switch (type) { switch (type) {
@ -362,9 +307,6 @@ R_RunParticleEffect (vec3_t org, int color, int count)
int k = count; int k = count;
vec3_t porg; vec3_t porg;
if (!r_particles->int_val)
return;
if (numparticles >= r_maxparticles) if (numparticles >= r_maxparticles)
return; return;
@ -392,9 +334,6 @@ R_RunParticleEffect (vec3_t org, int color, int count)
void void
R_RunSpikeEffect (vec3_t org, particle_effect_t type) R_RunSpikeEffect (vec3_t org, particle_effect_t type)
{ {
if (!r_particles->int_val)
return;
switch (type) { switch (type) {
case PE_SPIKE: case PE_SPIKE:
R_RunSparkEffect (org, 5, 8); R_RunSparkEffect (org, 5, 8);
@ -421,9 +360,6 @@ R_LavaSplash (vec3_t org)
int k = 256; int k = 256;
vec3_t dir, porg, pvel; vec3_t dir, porg, pvel;
if (!r_particles->int_val)
return;
if (numparticles + k >= r_maxparticles) { if (numparticles + k >= r_maxparticles) {
return; return;
} // else if (numparticles + k >= r_maxparticles) { } // else if (numparticles + k >= r_maxparticles) {
@ -458,9 +394,6 @@ R_TeleportSplash (vec3_t org)
int l = 896; int l = 896;
vec3_t dir, porg, pvel; vec3_t dir, porg, pvel;
if (!r_particles->int_val)
return;
if (numparticles + l >= r_maxparticles) { if (numparticles + l >= r_maxparticles) {
return; return;
} // else if (numparticles + l >= r_maxparticles) { } // else if (numparticles + l >= r_maxparticles) {
@ -493,7 +426,7 @@ R_RocketTrail (entity_t *ent)
float dist, len, pscale, pscalenext; float dist, len, pscale, pscalenext;
vec3_t subtract, vec; vec3_t subtract, vec;
if (!r_particles->int_val) if (numparticles >= r_maxparticles)
return; return;
R_AddFire (ent->old_origin, ent->origin, ent); R_AddFire (ent->old_origin, ent->origin, ent);
@ -527,7 +460,7 @@ R_GrenadeTrail (entity_t *ent)
float dist, len, pscale, pscalenext; float dist, len, pscale, pscalenext;
vec3_t subtract, vec; vec3_t subtract, vec;
if (!r_particles->int_val) if (numparticles >= r_maxparticles)
return; return;
VectorSubtract (ent->origin, ent->old_origin, vec); VectorSubtract (ent->origin, ent->old_origin, vec);
@ -560,7 +493,7 @@ R_BloodTrail (entity_t *ent)
int j; int j;
vec3_t subtract, vec, porg, pvel; vec3_t subtract, vec, porg, pvel;
if (!r_particles->int_val) if (numparticles >= r_maxparticles)
return; return;
VectorSubtract (ent->origin, ent->old_origin, vec); VectorSubtract (ent->origin, ent->old_origin, vec);
@ -599,7 +532,7 @@ R_SlightBloodTrail (entity_t *ent)
int j; int j;
vec3_t subtract, vec, porg, pvel; vec3_t subtract, vec, porg, pvel;
if (!r_particles->int_val) if (numparticles >= r_maxparticles)
return; return;
VectorSubtract (ent->origin, ent->old_origin, vec); VectorSubtract (ent->origin, ent->old_origin, vec);
@ -638,7 +571,7 @@ R_GreenTrail (entity_t *ent)
static int tracercount; static int tracercount;
vec3_t subtract, vec, pvel; vec3_t subtract, vec, pvel;
if (!r_particles->int_val) if (numparticles >= r_maxparticles)
return; return;
VectorSubtract (ent->origin, ent->old_origin, vec); VectorSubtract (ent->origin, ent->old_origin, vec);
@ -676,7 +609,7 @@ R_FlameTrail (entity_t *ent)
static int tracercount; static int tracercount;
vec3_t subtract, vec, pvel; vec3_t subtract, vec, pvel;
if (!r_particles->int_val) if (numparticles >= r_maxparticles)
return; return;
VectorSubtract (ent->origin, ent->old_origin, vec); VectorSubtract (ent->origin, ent->old_origin, vec);
@ -713,7 +646,7 @@ R_VoorTrail (entity_t *ent)
int j; int j;
vec3_t subtract, vec, porg; vec3_t subtract, vec, porg;
if (!r_particles->int_val) if (numparticles >= r_maxparticles)
return; return;
VectorSubtract (ent->origin, ent->old_origin, vec); VectorSubtract (ent->origin, ent->old_origin, vec);

View file

@ -39,11 +39,11 @@
#include "r_dynamic.h" #include "r_dynamic.h"
extern cvar_t *gl_sky_divide; // FIXME
cvar_t *cl_crossx; cvar_t *cl_crossx;
cvar_t *cl_crossy; cvar_t *cl_crossy;
cvar_t *cl_max_particles;
cvar_t *cl_verstring; cvar_t *cl_verstring;
cvar_t *crosshair; cvar_t *crosshair;
cvar_t *crosshaircolor; cvar_t *crosshaircolor;
@ -125,11 +125,19 @@ cvar_t *scr_showram;
cvar_t *scr_showturtle; cvar_t *scr_showturtle;
cvar_t *scr_viewsize; cvar_t *scr_viewsize;
extern short r_maxparticles;
extern cvar_t *gl_sky_divide; // FIXME
extern void R_MaxParticlesCheck (cvar_t *var);
static void static void
r_particles_f (cvar_t *var) r_particles_f (cvar_t *var)
{ {
if (!var->int_val) if (!var->int_val)
R_ClearParticles (); R_ClearParticles ();
if (cl_max_particles)
r_maxparticles = var->int_val * cl_max_particles->int_val;
} }
void void
@ -139,6 +147,10 @@ R_Init_Cvars (void)
"Sets the position of the crosshair on the X-axis."); "Sets the position of the crosshair on the X-axis.");
cl_crossy = Cvar_Get ("cl_crossy", "0", CVAR_ARCHIVE, NULL, cl_crossy = Cvar_Get ("cl_crossy", "0", CVAR_ARCHIVE, NULL,
"Sets the position of the crosshair on the Y-axis."); "Sets the position of the crosshair on the Y-axis.");
cl_max_particles = Cvar_Get ("cl_max_particles", "2048", CVAR_ARCHIVE,
R_MaxParticlesCheck, "Maximum amount of "
"particles to display. No maximum, minimum "
"is 0.");
cl_verstring = Cvar_Get ("cl_verstring", PROGRAM " " VERSION, CVAR_NONE, cl_verstring = Cvar_Get ("cl_verstring", PROGRAM " " VERSION, CVAR_NONE,
NULL, "Client version string"); NULL, "Client version string");
crosshair = Cvar_Get ("crosshair", "0", CVAR_ARCHIVE, NULL, "Crosshair " crosshair = Cvar_Get ("crosshair", "0", CVAR_ARCHIVE, NULL, "Crosshair "

View file

@ -32,16 +32,56 @@
#endif #endif
#include "QF/console.h" #include "QF/console.h"
#include "QF/cvar.h"
#include "QF/qargs.h" #include "QF/qargs.h"
#include "QF/render.h" #include "QF/render.h"
#include "compat.h" #include "compat.h"
#include "r_local.h" #include "r_local.h"
particle_t *active_particles, *free_particles, *particles; short r_maxparticles, numparticles;
vec3_t r_pright, r_pup, r_ppn; particle_t *active_particles, *free_particles, *particles, **freeparticles;
int r_maxparticles; vec3_t r_pright, r_pup, r_ppn;
extern cvar_t *cl_max_particles;
extern cvar_t *r_particles;
/*
R_MaxParticlesCheck
Misty-chan: Dynamically change the maximum amount of particles on the fly.
Thanks to a LOT of help from Taniwha, Deek, Mercury, Lordhavoc, and lots of
others.
*/
void
R_MaxParticlesCheck (cvar_t *var)
{
/*
Catchall. If the user changed the setting to a number less than zero *or*
if we had a wacky cfg get past the init code check, this will make sure we
don't have problems. Also note that grabbing the var->int_val is IMPORTANT:
Prevents a segfault since if we grabbed the int_val of cl_max_particles
we'd sig11 right here at startup.
*/
if (r_particles)
r_maxparticles = max(var->int_val * r_particles->int_val, 0);
else
r_maxparticles = max(var->int_val, 0);
/*
Be very careful the next time we do something like this. calloc/free are
IMPORTANT and the compiler doesn't know when we do bad things with them.
*/
free (particles);
free (freeparticles);
particles = (particle_t *) calloc (r_maxparticles, sizeof (particle_t));
freeparticles = (particle_t **) calloc (r_maxparticles,
sizeof (particle_t *));
R_ClearParticles();
}
void void
R_DarkFieldParticles (entity_t *ent) R_DarkFieldParticles (entity_t *ent)

View file

@ -43,48 +43,19 @@
#include "r_dynamic.h" #include "r_dynamic.h"
#include "r_local.h" #include "r_local.h"
int ramp1[8] = { 0x6f, 0x6d, 0x6b, 0x69, 0x67, 0x65, 0x63, 0x61 }; int ramp1[8] = { 0x6f, 0x6d, 0x6b, 0x69, 0x67, 0x65, 0x63, 0x61 };
int ramp2[8] = { 0x6f, 0x6e, 0x6d, 0x6c, 0x6b, 0x6a, 0x68, 0x66 }; int ramp2[8] = { 0x6f, 0x6e, 0x6d, 0x6c, 0x6b, 0x6a, 0x68, 0x66 };
int ramp3[8] = { 0x6d, 0x6b, 6, 5, 4, 3 }; int ramp3[8] = { 0x6d, 0x6b, 6, 5, 4, 3 };
int r_maxparticles; vec3_t r_pright, r_pup, r_ppn;
particle_t *active_particles, *free_particles, *particles;
vec3_t r_pright, r_pup, r_ppn;
extern short r_maxparticles;
extern particle_t *active_particles, *free_particles, *particles;
/*
R_MaxParticlesCheck
Misty-chan: EXTREME heavy lifting and bugfixing thanks goes out to taniwha
- I built this, and he got it working :)
*/
void
R_MaxParticlesCheck (cvar_t *var)
{
// Do not use 0 in this! sw doesn't grok 0 and it'll segfault if we do!
r_maxparticles = max(var->int_val, 1);
/*
Debugging code. will print what the above was set to, and is also useful
for checking if this is accidentally being run all the time.
Con_Printf ("%d", r_maxparticles);
*/
if (particles)
free (particles);
particles = (particle_t *) calloc (r_maxparticles, sizeof (particle_t));
R_ClearParticles ();
}
void void
R_Particles_Init_Cvars (void) R_Particles_Init_Cvars (void)
{ {
// Does a callback to R_MaxParticleCheck when the cvar changes. Neat trick.
Cvar_Get ("cl_max_particles", "2048", CVAR_ARCHIVE, R_MaxParticlesCheck,
"Maximum amount of particles to display. No maximum, minimum "
"is 1.");
} }
void void

View file

@ -43,53 +43,21 @@
#include "r_dynamic.h" #include "r_dynamic.h"
#include "r_local.h" #include "r_local.h"
int ramp1[8] = { 0x6f, 0x6d, 0x6b, 0x69, 0x67, 0x65, 0x63, 0x61 }; int ramp1[8] = { 0x6f, 0x6d, 0x6b, 0x69, 0x67, 0x65, 0x63, 0x61 };
int ramp2[8] = { 0x6f, 0x6e, 0x6d, 0x6c, 0x6b, 0x6a, 0x68, 0x66 }; int ramp2[8] = { 0x6f, 0x6e, 0x6d, 0x6c, 0x6b, 0x6a, 0x68, 0x66 };
int ramp3[8] = { 0x6d, 0x6b, 6, 5, 4, 3 }; int ramp3[8] = { 0x6d, 0x6b, 6, 5, 4, 3 };
particle_t *active_particles, *free_particles;
particle_t *particles;
int r_maxparticles;
vec3_t r_pright, r_pup, r_ppn; vec3_t r_pright, r_pup, r_ppn;
/* extern short r_maxparticles;
R_MaxParticlesCheck extern particle_t *active_particles, *free_particles, *particles;
Misty-chan: EXTREME heavy lifting and bugfixing thanks goes out to taniwha
- I built this, and he got it working :)
*/
void
R_MaxParticlesCheck (cvar_t *var)
{
// Do not use 0 in this! sw doesn't grok 0 and it'll segfault if we do!
r_maxparticles = max(var->int_val, 1);
/*
Debugging code. will print what the above was set to, and is also useful
for checking if this is accidentally being run all the time.
Con_Printf ("%d", r_maxparticles);
*/
if (particles)
free (particles);
particles = (particle_t *) calloc (r_maxparticles, sizeof (particle_t));
R_ClearParticles ();
}
void void
R_Particles_Init_Cvars (void) R_Particles_Init_Cvars (void)
{ {
// Does a callback to R_MaxParticleCheck when the cvar changes. Neat trick.
Cvar_Get ("cl_max_particles", "2048", CVAR_ARCHIVE, R_MaxParticlesCheck,
"Maximum amount of particles to display. No maximum, minimum is 1.");
} }
void void
R_ClearParticles (void) R_ClearParticles (void)
{ {
@ -103,7 +71,6 @@ R_ClearParticles (void)
particles[r_maxparticles - 1].next = NULL; particles[r_maxparticles - 1].next = NULL;
} }
void void
R_ReadPointFile_f (void) R_ReadPointFile_f (void)
{ {
@ -153,7 +120,6 @@ R_ReadPointFile_f (void)
Con_Printf ("%i points read\n", c); Con_Printf ("%i points read\n", c);
} }
void void
R_RunSpikeEffect (vec3_t pos, particle_effect_t type) R_RunSpikeEffect (vec3_t pos, particle_effect_t type)
{ {
@ -175,7 +141,6 @@ R_RunSpikeEffect (vec3_t pos, particle_effect_t type)
} }
} }
void void
R_RunPuffEffect (vec3_t pos, particle_effect_t type, byte cnt) R_RunPuffEffect (vec3_t pos, particle_effect_t type, byte cnt)
{ {
@ -197,7 +162,6 @@ R_RunPuffEffect (vec3_t pos, particle_effect_t type, byte cnt)
} }
} }
void void
R_ParticleExplosion (vec3_t org) R_ParticleExplosion (vec3_t org)
{ {
@ -234,7 +198,6 @@ R_ParticleExplosion (vec3_t org)
} }
} }
void void
R_ParticleExplosion2 (vec3_t org, int colorStart, int colorLength) R_ParticleExplosion2 (vec3_t org, int colorStart, int colorLength)
{ {
@ -264,7 +227,6 @@ R_ParticleExplosion2 (vec3_t org, int colorStart, int colorLength)
} }
} }
void void
R_BlobExplosion (vec3_t org) R_BlobExplosion (vec3_t org)
{ {
@ -302,7 +264,6 @@ R_BlobExplosion (vec3_t org)
} }
} }
void void
R_RunParticleEffect (vec3_t org, int color, int count) R_RunParticleEffect (vec3_t org, int color, int count)
{ {
@ -338,7 +299,6 @@ R_RunParticleEffect (vec3_t org, int color, int count)
} }
} }
void void
R_LavaSplash (vec3_t org) R_LavaSplash (vec3_t org)
{ {