Particle code cleanup and optimizations..

Also fix a bug theoddone interduced by not cleaning up old particles
if they were turned off (would crash when it ran out of free particles)
This commit is contained in:
Zephaniah E. Hull 2000-04-11 11:14:48 +00:00
parent b7f3d61625
commit b7df9b7d1f

View file

@ -61,98 +61,91 @@ void R_DrawParticles (void)
float scale; float scale;
qboolean alphaTestEnabled; qboolean alphaTestEnabled;
if (gl_particles->value) // Do we actually want to render particles in the first place?
{ if (!gl_particles->value) {
GL_Bind(particletexture); // We still need to prune the particles...
alphaTestEnabled = glIsEnabled(GL_ALPHA_TEST); for (p=active_particles ; p ;)
if (alphaTestEnabled)
glDisable(GL_ALPHA_TEST);
glEnable (GL_BLEND);
glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
glBegin (GL_TRIANGLES);
VectorScale (vup, 1.5, up);
VectorScale (vright, 1.5, right);
#ifdef UQUAKE
frametime = cl.time - cl.oldtime;
#else
frametime = host_frametime;
#endif
time3 = frametime * 15;
time2 = frametime * 10; // 15;
time1 = frametime * 5;
#ifdef UQUAKE
grav = frametime * sv_gravity->value * 0.05;
#else
grav = frametime * 800 * 0.05;
#endif
dvel = 4*frametime;
for ( ;; )
{ {
kill = active_particles; // Is it dead?
if (kill && kill->die < cl.time) if (p->next && (p->next->die < cl.time)) {
{ // First save our place..
active_particles = kill->next; kill = p->next;
p->next = p->next->next;
// Remove from list and continue.
kill->next = free_particles; kill->next = free_particles;
free_particles = kill; free_particles = kill;
continue;
} }
break; p = p->next;
} }
for (p=active_particles ; p ; p=p->next) return;
{ }
for ( ;; )
{ GL_Bind(particletexture);
kill = p->next; alphaTestEnabled = glIsEnabled(GL_ALPHA_TEST);
if (kill && kill->die < cl.time)
{ if (alphaTestEnabled)
p->next = kill->next; glDisable(GL_ALPHA_TEST);
kill->next = free_particles; glEnable (GL_BLEND);
free_particles = kill; glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
continue; glBegin (GL_TRIANGLES);
}
break; VectorScale (vup, 1.5, up);
} VectorScale (vright, 1.5, right);
#ifdef UQUAKE
// hack a scale up to keep particles from disapearing frametime = cl.time - cl.oldtime;
scale = (p->org[0] - r_origin[0])*vpn[0]
+ (p->org[1] - r_origin[1])*vpn[1]
+ (p->org[2] - r_origin[2])*vpn[2];
if (scale < 20)
scale = gl_particles->value;
else
scale = gl_particles->value + scale * 0.004;
#if 0 // was in uquake, but give it a go
glColor3ubv ((byte *)&d_8to24table[(int)p->color]);
#else #else
at = (byte *)&d_8to24table[(int)p->color]; frametime = host_frametime;
if (p->type==pt_fire)
theAlpha = 255*(6-p->ramp)/6;
// theAlpha = 192;
// else if (p->type==pt_explode || p->type==pt_explode2)
// theAlpha = 255*(8-p->ramp)/8;
else
theAlpha = 255;
glColor4ub (*at, *(at+1), *(at+2), theAlpha);
// glColor3ubv (at);
// glColor3ubv ((byte *)&d_8to24table[(int)p->color]);
#endif #endif
glTexCoord2f (0,0); time3 = frametime * 15;
glVertex3fv (p->org); time2 = frametime * 10; // 15;
glTexCoord2f (1,0); time1 = frametime * 5;
glVertex3f (p->org[0] + up[0]*scale, p->org[1] + up[1]*scale, p->org[2] + up[2]*scale); #ifdef UQUAKE
glTexCoord2f (0,1); grav = frametime * sv_gravity->value * 0.05;
glVertex3f (p->org[0] + right[0]*scale, p->org[1] + right[1]*scale, p->org[2] + right[2]*scale); #else
grav = frametime * 800 * 0.05;
#endif
dvel = 4*frametime;
p->org[0] += p->vel[0]*frametime; for (p=active_particles ; p ;)
p->org[1] += p->vel[1]*frametime; {
p->org[2] += p->vel[2]*frametime; // Is it dead?
if (p->next && (p->next->die < cl.time)) {
// First save our place..
kill = p->next;
p->next = p->next->next;
// Remove from list and continue.
kill->next = free_particles;
free_particles = kill;
}
switch (p->type) // hack a scale up to keep particles from disapearing
{ scale = (p->org[0] - r_origin[0])*vpn[0]
+ (p->org[1] - r_origin[1])*vpn[1]
+ (p->org[2] - r_origin[2])*vpn[2];
if (scale < 20)
scale = gl_particles->value;
else
scale = gl_particles->value + scale * 0.004;
at = (byte *)&d_8to24table[(int)p->color];
if (p->type==pt_fire)
theAlpha = 255*(6-p->ramp)/6;
else
theAlpha = 255;
glColor4ub (*at, *(at+1), *(at+2), theAlpha);
glTexCoord2f (0,0);
glVertex3fv (p->org);
glTexCoord2f (1,0);
glVertex3f (p->org[0] + up[0]*scale, p->org[1] + up[1]*scale, p->org[2] + up[2]*scale);
glTexCoord2f (0,1);
glVertex3f (p->org[0] + right[0]*scale, p->org[1] + right[1]*scale, p->org[2] + right[2]*scale);
p->org[0] += p->vel[0]*frametime;
p->org[1] += p->vel[1]*frametime;
p->org[2] += p->vel[2]*frametime;
switch (p->type)
{
case pt_static: case pt_static:
break; break;
case pt_fire: case pt_fire:
@ -163,7 +156,7 @@ void R_DrawParticles (void)
p->color = ramp3[(int)p->ramp]; p->color = ramp3[(int)p->ramp];
p->vel[2] += grav; p->vel[2] += grav;
break; break;
case pt_explode: case pt_explode:
p->ramp += time2; p->ramp += time2;
if (p->ramp >=8) if (p->ramp >=8)
@ -174,7 +167,7 @@ void R_DrawParticles (void)
p->vel[i] += p->vel[i]*dvel; p->vel[i] += p->vel[i]*dvel;
p->vel[2] -= grav; p->vel[2] -= grav;
break; break;
case pt_explode2: case pt_explode2:
p->ramp += time3; p->ramp += time3;
if (p->ramp >=8) if (p->ramp >=8)
@ -185,13 +178,13 @@ void R_DrawParticles (void)
p->vel[i] -= p->vel[i]*frametime; p->vel[i] -= p->vel[i]*frametime;
p->vel[2] -= grav; p->vel[2] -= grav;
break; break;
case pt_blob: case pt_blob:
for (i=0 ; i<3 ; i++) for (i=0 ; i<3 ; i++)
p->vel[i] += p->vel[i]*dvel; p->vel[i] += p->vel[i]*dvel;
p->vel[2] -= grav; p->vel[2] -= grav;
break; break;
case pt_blob2: case pt_blob2:
for (i=0 ; i<2 ; i++) for (i=0 ; i<2 ; i++)
p->vel[i] -= p->vel[i]*dvel; p->vel[i] -= p->vel[i]*dvel;
@ -203,19 +196,20 @@ void R_DrawParticles (void)
// so for now it's being fixed. // so for now it's being fixed.
// We can implement it as a feature, but it's // We can implement it as a feature, but it's
// not all that cool. // not all that cool.
// p->vel[2] -= grav * 20; // p->vel[2] -= grav * 20;
// break; // break;
case pt_slowgrav: case pt_slowgrav:
p->vel[2] -= grav; p->vel[2] -= grav;
break; break;
}
} }
p = p->next;
}
glEnd (); glEnd ();
glDisable (GL_BLEND); glDisable (GL_BLEND);
if (alphaTestEnabled) if (alphaTestEnabled)
glEnable(GL_ALPHA_TEST); glEnable(GL_ALPHA_TEST);
glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE); glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);
} // if (gl_particles->value)
} }