Merge pull request #28 from OpenArena/sago_particles_anti_crash2

Slightly smaller fix. Now with carrige return
This commit is contained in:
Poul Sander
2016-11-27 11:13:06 +01:00
committed by GitHub

View File

@@ -296,11 +296,12 @@ void R_AddParticleToScene (particle_t *p, vec3_t org, float alpha)
float height;
float time, time2;
float ratio;
int fogNum;
int fogNum = 0;
float invratio;
vec3_t color;
vec4_t color;
time = 0; invratio = 0; // shut up gcc
time = 0;
invratio = 0; // shut up gcc
VectorSet (color, p->cols[0][0], p->cols[1][0], p->cols[2][0]);
THEtime = backEnd.refdef.time;
@@ -330,25 +331,23 @@ void R_AddParticleToScene (particle_t *p, vec3_t org, float alpha)
{// create a front rotating facing polygon
{
// create a front rotating facing polygon
// that can change colors
// and........ something.
vec3_t rr, ru;
vec3_t rotate_ang;
if (p->colortype == P_LFX){ // Ramp
if (p->colortype == P_LFX) {
// Ramp
// hack to prevent that one long particle from going crazy in the world.
if (p->startfade > THEtime){
p->bounce = 0; p->bubbleit = 0; //no cpu expensive checks
return;
}
if (THEtime> p->startfade)
{
if (THEtime > p->startfade) {
float inv1,inv2,inv3,inv4;
invratio = 1 - ( (THEtime- p->startfade) / (p->endtime - p->startfade) );
@@ -361,57 +360,46 @@ void R_AddParticleToScene (particle_t *p, vec3_t org, float alpha)
if (inv2 > 1.0f) inv2 = 1.0f;
if (inv3 > 1.0f) inv3 = 1.0f;
if (inv4 > 1.0f) inv4 = 1.0f;
{
int et;
vec4_t fcol;
for(et=0;et<4;et++)
{
if (invratio < 0.25f)
fcol[et] = (p->cols[et][3] * inv1) + (p->cols[et][4] * (1 - inv1));
else if (invratio < 0.50f)
fcol[et] = (p->cols[et][2] * inv2) + (p->cols[et][3] * (1 - inv2));
else if (invratio < 0.75f)
fcol[et] = (p->cols[et][1] * inv3) + (p->cols[et][2] * (1 - inv3));
else
fcol[et] = (p->cols[et][0] * inv4) + (p->cols[et][1] * (1 - inv4));
}
for(et=0;et<4;et++) {
if (fcol[et]>1)fcol[et]=1.0f;
if (fcol[et]<0)fcol[et]=0.0f;
if (invratio < 0.25f) {
fcol[et] = (p->cols[et][3] * inv1) + (p->cols[et][4] * (1 - inv1));
}
else if (invratio < 0.50f) {
fcol[et] = (p->cols[et][2] * inv2) + (p->cols[et][3] * (1 - inv2));
}
else if (invratio < 0.75f) {
fcol[et] = (p->cols[et][1] * inv3) + (p->cols[et][2] * (1 - inv3));
}
else {
fcol[et] = (p->cols[et][0] * inv4) + (p->cols[et][1] * (1 - inv4));
}
}
for(et=0;et<4;et++){
if (fcol[et]>1) { fcol[et]=1.0f; }
if (fcol[et]<0) { fcol[et]=0.0f; }
}
color[0] = fcol[0];
color[1] = fcol[1];
color[2] = fcol[2];
color[3] = fcol[3];
}
}
if (invratio > 4)
if (invratio > 4) {
invratio = 4;
}
else if (p->colortype = P_INDEXED)
{
}
else if (p->colortype == P_INDEXED) {
VectorSet(color, qpalette[p->qolor][0], qpalette[p->qolor][1], qpalette[p->qolor][2]);
color[3] = 1.0f;
}
else // simple
{
else {
// simple
invratio = 1;
color[0] = p->cols[0][0];
color[1] = p->cols[1][0];
@@ -420,8 +408,8 @@ void R_AddParticleToScene (particle_t *p, vec3_t org, float alpha)
}
if (p->rendertype == LFXSHOCK)
{ // ORIENTED sprite - used for shockwaves, water waves, waves, etc.
if (p->rendertype == LFXSHOCK) {
// ORIENTED sprite - used for shockwaves, water waves, waves, etc.
vec3_t argles;
vec3_t right, up;
int ind=0;
@@ -495,8 +483,8 @@ void R_AddParticleToScene (particle_t *p, vec3_t org, float alpha)
RB_EndSurface();
}
else if (p->rendertype == LFXSPARK)
{ // STRETCHY SPARK sprite - used for sparks etc
else if (p->rendertype == LFXSPARK) {
// STRETCHY SPARK sprite - used for sparks etc
vec3_t argles;
vec3_t right, up, fwd;
vec3_t line;
@@ -597,8 +585,8 @@ void R_AddParticleToScene (particle_t *p, vec3_t org, float alpha)
// center glow of softness? Enable for 2002 particleset?
}
else if (p->rendertype == LFXBURST)
{ // STRETCHY BURST sprite - used for explosions
else if (p->rendertype == LFXBURST) {
// STRETCHY BURST sprite - used for explosions
// like spark but origin doesnt change. it just keeps stretching
// from where it was spawned.
vec3_t argles;
@@ -698,16 +686,13 @@ void R_AddParticleToScene (particle_t *p, vec3_t org, float alpha)
ind+=4;
RB_EndSurface();
}
else if (p->rendertype == LFXTRAIL)
{ // STRETCHY TRAIL sprite - used for..... i dunno
else if (p->rendertype == LFXTRAIL) {
// STRETCHY TRAIL sprite - used for..... i dunno
// like burst but splits into more trails when the certain length is achieved
// TO RETURN
}
else
else {
// VP PARALLEL sprite
{
// trace_t pt1, pt2, pt3, pt4;
// float avgfrac;
int ind=0;
@@ -813,7 +798,7 @@ void R_AddParticleToScene (particle_t *p, vec3_t org, float alpha)
static float roll = 0.0;
#define MINe(p,q) ((p <= q) ? p : q)
int reallyactive;
particle_t* reallyactive;
void R_AddParticles (void)
{
@@ -832,8 +817,6 @@ void R_AddParticles (void)
float f;
int intheworld = 0;
if (!initparticles)
R_ClearParticles ();
@@ -872,21 +855,12 @@ void R_AddParticles (void)
// Intended to keep physics calculations under control, but it doens't work properly. :(
//if ((!backEnd.doneParticles) && !(tr.refdef.rdflags & RDF_NOWORLDMODEL))
for (p=active_particles ; p ; p=next)
{
for (p=active_particles ; p ; p=next) {
next = p->next;
//time = (THEtime- p->time)*0.001;
VectorCopy(p->org, oldorg);
// if we're told to die, it's most likely a quake particle.
if (p->die)
{
if (p->die) {
int scal = 2.6f;
p->endtime = THEtime + (p->die);
p->die = 0;
@@ -915,19 +889,12 @@ void R_AddParticles (void)
p->vel[1] += p->accel[1]*frametime;
p->vel[2] += p->accel[2]*frametime;
}
else
{
else {
p->vel[0] += frametime;
p->vel[1] += frametime;
p->vel[2] += frametime;
int i;
switch (p->type)
{
switch (p->type) {
case pt_static:
break;
case pt_fire:
@@ -982,11 +949,7 @@ void R_AddParticles (void)
break;
}
if (THEtime> p->endtime)
{
if (THEtime> p->endtime) {
p->next = free_particles;
free_particles = p;
p->type = 0;
@@ -1026,22 +989,15 @@ void R_AddParticles (void)
p->active_trail = 0;
continue;
}
}
oldorg[0] = p->org[0];
oldorg[1] = p->org[1];
oldorg[2] = p->org[2];
p->org[0] += p->vel[0]*frametime;
p->org[1] += p->vel[1]*frametime;
p->org[2] += p->vel[2]*frametime;
if (p->rendertype != LFXQUAKE)
{
if (p->rendertype != LFXQUAKE) {
if (alpha > 1.0)
alpha = 1;
if (p->rollfriction){
@@ -1053,12 +1009,7 @@ void R_AddParticles (void)
f = 1.0f - MINe(p->airfriction * frametime, 1);
VectorScale(p->vel, f, p->vel);
}
p->roll += (p->rollvel*frametime);
alpha = p->alpha + time*p->alphavel;
// hack to prevent that one long particle from going crazy in the world.
@@ -1066,8 +1017,8 @@ void R_AddParticles (void)
p->alpha = -1; // kill it
}
if (alpha <= 0)
{ // faded out
if (alpha <= 0) {
// faded out
p->next = free_particles;
free_particles = p;
p->type = 0;
@@ -1079,9 +1030,7 @@ void R_AddParticles (void)
continue;
}
if (THEtime> p->endtime || p->alpha < 0.0f)
{
if (THEtime> p->endtime || p->alpha < 0.0f) {
p->next = free_particles;
free_particles = p;
p->type = 0;
@@ -1121,20 +1070,14 @@ void R_AddParticles (void)
p->active_trail = 0;
continue;
}
}
p->next = NULL;
if (!tail)
if (!tail) {
active = tail = p;
else
{
}
else {
tail->next = p;
tail = p;
}
@@ -1155,8 +1098,7 @@ void R_AddParticles (void)
// leilei - bubble conversion
if(p->bubbleit && p->type != LFXBUBBLE)
{
if (p->bubbleit && p->type != LFXBUBBLE) {
int contents = CM_PointContents( p->org, 0 );
if ( contents & ( CONTENTS_WATER | CONTENTS_SLIME ) ) {
p->type = LFXBUBBLE;
@@ -1173,26 +1115,22 @@ void R_AddParticles (void)
}
}
if(p->type == LFXBUBBLE)
{
if(p->type == LFXBUBBLE) {
int contents = CM_PointContents( p->org, 0 );
if ( contents | ( CONTENTS_WATER | CONTENTS_SLIME ) ) {
p->endtime = THEtime;
}
else
{
else {
p->accel[0] = (crandom() * 4 - 2);
p->accel[1] = (crandom() * 4 - 2);
p->accel[2] = 66;
}
}
// leilei - bounce physics
if(p->bounce > 0)
{
if (p->bounce > 0) {
trace_t trace;
float dist;
@@ -1200,22 +1138,20 @@ void R_AddParticles (void)
P_Trace (&trace, oldorg, NULL, NULL, p->org, -1, CONTENTS_SOLID);
{
if (trace.fraction < 1){
VectorCopy(trace.endpos, p->org); // particle where we've hit from
if (p->bounce < 0)
{
if (p->bounce < 0) {
// bounce -1 means remove on impact
p->endtime = THEtime;
}
// anything else - bounce off solid
dist = DotProduct(p->vel, trace.plane.normal) * -p->bounce;
VectorMA(p->vel, dist, trace.plane.normal, p->vel);
// lets roll
//p->vel[2] = 7;
if(p->bounce < 0.2f)
p->alpha = -5; // kill!
if(p->bounce < 0.2f) {
// kill!
p->alpha = -5;
}
}
}
}
@@ -1236,20 +1172,6 @@ void R_AddParticles (void)
void R_RenderParticles (void)
{
particle_t *p, *next;
float alpha;
float time, time2;
vec3_t oldorg; // leilei
particle_t *active, *tail;
vec3_t rotate_ang;
float frametime;
float time3;
float time1;
float dvel;
float grav;
float f;
if (!initparticles)
return;
@@ -1259,8 +1181,7 @@ void R_RenderParticles (void)
active_particles = reallyactive;
for (p=active_particles ; p ; p=next)
{
for (p=active_particles ; p ; p=next) {
next = p->next;
R_AddParticleToScene (p, p->org, p->alpha);
}
@@ -1943,8 +1864,9 @@ void R_LFX_Generic (int type, vec3_t org, vec3_t dir, float alpha, int spread, i
p = 0; // die warnings
for (i = 0; i < cont; i++) {
if (!free_particles)
if (!free_particles) {
return;
}
p = free_particles;
free_particles = p->next;
p->next = active_particles;
@@ -2015,7 +1937,6 @@ void R_LFX_Generic (int type, vec3_t org, vec3_t dir, float alpha, int spread, i
p->vel[j] = (rand() & (int)spread) - (int)(spread * 0.5f);
p->vel[j] += dir[j];
p->vel[j] += (dir[j] * (rand() & (int)speed));
}
}
}
@@ -2537,10 +2458,7 @@ void LFX_ParticleEffect200X (int effect, vec3_t org, vec3_t dir)
}
// BFG
else if (effect == 9)
{
else if (effect == 9) {
colory[0] = 1.0; colory[1] = 1.0; colory[2] = 1.0; colory[3] = 1.0;
colory2[0] = 0.3; colory2[1] = 1.0; colory2[2] = 0.2; colory2[3] = 0.9;
colory3[0] = 0.0; colory3[1] = 0.3; colory3[2] = 0.1; colory3[3] = 0.7;
@@ -2580,12 +2498,10 @@ void LFX_ParticleEffect200X (int effect, vec3_t org, vec3_t dir)
R_LFX_Burst (sprOrg, sprVel, 175, 15, colory, colory2, colory3, colory4, colory4, 15, 140, 32, 1);
R_LFX_Spark (sprOrg, sprVel, 175, 5, colory, colory2, colory3, colory4, colory4, 15, 1040, 0.8f, 1);
}
// Nail Hit
if (effect == 10)
{
if (effect == 10) {
colory[0] = 0.7; colory[1] = 0.7; colory[2] = 0.7; colory[3] = 0.0;
colory2[0] = 0.7; colory2[1] = 0.7; colory2[2] = 0.7; colory2[3] = 0.5;
colory3[0] = 0.6; colory3[1] = 0.6; colory3[2] = 0.6; colory3[3] = 0.8;
@@ -2610,7 +2526,6 @@ void LFX_ParticleEffect200X (int effect, vec3_t org, vec3_t dir)
R_LFX_Spark (sprOrg, sprVel, 95, 225, colory, colory2, colory3, colory4, colory4, 5, 140, 0.5f, 1);
R_LFX_Spark (sprOrg, sprVel, 95, 185, colory, colory2, colory3, colory4, colory4, 1, 2540, 0.5f, 1);
}
// Blood Sprays for bullets
@@ -2826,8 +2741,7 @@ void LFX_ParticleEffect1998 (int effect, vec3_t org, vec3_t dir)
// Smoke trails on grenades and rockets
// might be a beam.
if (effect == 1)
{
if (effect == 1) {
}
@@ -2837,8 +2751,7 @@ void LFX_ParticleEffect1998 (int effect, vec3_t org, vec3_t dir)
//
if (effect == 2)
{
if (effect == 2) {
// Sparks
colory[0] = 0.6; colory[1] = 0.4; colory[2] = 0.0; colory[3] = 1.0;
colory2[0] = 0.7; colory2[1] = 0.4; colory2[2] = 0.0; colory2[3] = 0.9;
@@ -2850,8 +2763,8 @@ void LFX_ParticleEffect1998 (int effect, vec3_t org, vec3_t dir)
sprVel[2] += 2;
R_LFX_Spark (sprOrg, sprVel, 11, 32, colory, colory2, colory3, colory4, colory4, 4, 440, 0.5f, 1);
sprVel[2] += 64;
R_LFX_Generic
(LFXSMOKE, // Particle Type
R_LFX_Generic (
LFXSMOKE, // Particle Type
sprOrg, // Origin
sprVel, // Velocity
1.0f, // Starting Alpha
@@ -2873,10 +2786,7 @@ void LFX_ParticleEffect1998 (int effect, vec3_t org, vec3_t dir)
alfball // Particle Shader
);
}
else if (effect == 3)
{
else if (effect == 3) {
if (rand() < 0.5f){ // only happens for half the pellets
// Sparks
colory[0] = 0.6; colory[1] = 0.4; colory[2] = 0.0; colory[3] = 1.0;
@@ -2889,8 +2799,8 @@ void LFX_ParticleEffect1998 (int effect, vec3_t org, vec3_t dir)
R_LFX_Spark (sprOrg, sprVel, 95, 32, colory, colory2, colory3, colory4, colory4, 3, 440, 0.5f, 1);
sprVel[2] += 64;
R_LFX_Generic
(LFXSMOKE, // Particle Type
R_LFX_Generic (
LFXSMOKE, // Particle Type
sprOrg, // Origin
sprVel, // Velocity
1.0f, // Starting Alpha
@@ -2917,36 +2827,27 @@ void LFX_ParticleEffect1998 (int effect, vec3_t org, vec3_t dir)
// Plasma Hit
// should become a plain sprite atlas animation.
if (effect == 6)
{
if (effect == 6) {
}
else if (effect == 5 || effect == 4 || effect == 11) {
// Grenade/Rocket/Prox Explosion
// should be an explosion atlas
// plus a smoke atlas that comes in later
// plus a few glquake-ish embers
// plus a couple of sparks that shoots off other sparks
else if (effect == 5 || effect == 4 || effect == 11)
{
}
else if (effect == 9) {
// BFG, could be just a shockwave.
else if (effect == 9)
{
}
// Blood Sprays for bullets
// should be a nondirectional splat of a center atlas gush
// and then several randomly directed blood drops that roll. all is GE128
if (effect == 14 && com_blood->integer)
{
if (effect == 14 && com_blood->integer) {
colory[0] = 1.0; colory[1] = 0.0; colory[2] = 0.0; colory[3] = 1.0;
colory2[0] = 0.8; colory2[1] = 0.0; colory2[2] = 0.0; colory2[3] = 0.5;
colory3[0] = 0.6; colory3[1] = 0.0; colory3[2] = 0.0; colory3[3] = 0.8;
@@ -2954,7 +2855,6 @@ void LFX_ParticleEffect1998 (int effect, vec3_t org, vec3_t dir)
//R_LFX_Smoke2 (sprOrg, sprVel, 2 + (random()*6), 6.54+ (random()*8.7), colory, colory2, colory3, colory4, colory4, 1, 800 + (random()*2000), 2, 8+ (random()*6), 0);
//R_LFX_Smoke2 (sprOrg, sprVel, 2 + (random()*6), 3.54+ (random()*8.7), colory, colory2, colory3, colory4, colory4, 1, 300 + (random()*2000), 2, 8+ (random()*6), 4);
}
}
// 1999 - a certain competing game
@@ -2971,17 +2871,15 @@ void LFX_ParticleEffect1999 (int effect, vec3_t org, vec3_t dir)
// Smoke trails on grenades and rockets
// this should be several smoke atlases along a line.
if (effect == 1)
{
if (effect == 1) {
}
// Bullet Hit
// a smoke puff, a badly looping spark model, and an occasional ball spark (no stretch) of a random amount from 1 to 6 balls.
if (effect == 2)
{
R_LFX_Generic
(777777, // Particle Type
if (effect == 2) {
R_LFX_Generic (
777777, // Particle Type
sprOrg, // Origin
sprVel, // Velocity
1.0f, // Starting Alpha
@@ -3002,17 +2900,15 @@ void LFX_ParticleEffect1999 (int effect, vec3_t org, vec3_t dir)
0.0f, // Particle Rolling Friction
addball // Particle Shader
);
}
// Shotgun Hit
// can be just smoke puffs, preferably atlasy.
if (effect == 3)
{
if (effect == 3) {
VectorMA( origin, 8, dir, sprOrg );
sprVel[2] += 20;
R_LFX_Generic
(LFXSMOKE, // Particle Type
R_LFX_Generic (
LFXSMOKE, // Particle Type
sprOrg, // Origin
sprVel, // Velocity
1.0f, // Starting Alpha
@@ -3037,31 +2933,23 @@ void LFX_ParticleEffect1999 (int effect, vec3_t org, vec3_t dir)
// Plasma Hit
// should become a plain sprite atlas animation.
if (effect == 6)
{
if (effect == 6) {
}
// Lightning Hit
// can become a plain sprite, but we already have that, so.....
if (effect == 8)
{
if (effect == 8) {
}
else if (effect == 5 || effect == 4 || effect == 11) {
// Grenade/Rocket/Prox Explosion
// should be an explosion atlas, but on later versions there's several more delayed explosion atlases to spice up the variety
else if (effect == 5 || effect == 4 || effect == 11)
{
}
else if (effect == 9) {
// BFG, could be an expanding sphere with an explosion atlas
else if (effect == 9)
{
}
@@ -3069,14 +2957,13 @@ void LFX_ParticleEffect1999 (int effect, vec3_t org, vec3_t dir)
// should be an additive smoke puff that doesn't move (but go through an atlas animation)
// as well as a model that has autosprites for ge128 blood sprays, which is kinda cheesy but we can replicate this effect
// withi particles anyhow because we're awesome for having a real particle system ha ha ha ha ha
if (effect == 14 && com_blood->integer)
{
if (effect == 14 && com_blood->integer) {
VectorMA( origin, 8, dir, sprOrg );
sprVel[2] = 0;
sprVel[1] = 0;
sprVel[0] = 0;
R_LFX_Generic
(LFXSMOKE, // Particle Type
R_LFX_Generic (
LFXSMOKE, // Particle Type
sprOrg, // Origin
sprVel, // Velocity
1.0f, // Starting Alpha
@@ -3098,8 +2985,8 @@ void LFX_ParticleEffect1999 (int effect, vec3_t org, vec3_t dir)
addsmoke // Particle Shader
);
R_LFX_Generic
(LFXSMOKE, // Particle Type
R_LFX_Generic (
LFXSMOKE, // Particle Type
sprOrg, // Origin
sprVel, // Velocity
1.0f, // Starting Alpha
@@ -3123,21 +3010,18 @@ void LFX_ParticleEffect1999 (int effect, vec3_t org, vec3_t dir)
}
// "Blood" Sprays for bullets
if (effect == 14 && !com_blood->integer)
{
if (effect == 14 && !com_blood->integer) {
// not yet. this should be an additive green puff
}
// Blood Spray for a gibbing
if (effect == 16 && com_blood->integer)
{
if (effect == 16 && com_blood->integer) {
// not yet.
}
// Water Splash for bullets - there should only be a polygonal white ring. but we don't do model drawing right now
if (effect == 19)
{
if (effect == 19) {
colory[0] = 1.0; colory[1] = 1.0; colory[2] = 1.0; colory[3] = 1.0;
colory2[0] = 0.7; colory2[1] = 0.7; colory2[2] = 0.7; colory2[3] = 0.6;
colory3[0] = 0.4; colory3[1] = 0.4; colory3[2] = 0.4; colory3[3] = 0.3;
@@ -3145,13 +3029,10 @@ void LFX_ParticleEffect1999 (int effect, vec3_t org, vec3_t dir)
VectorScale( dir, 39, sprVel );
R_LFX_Shock (origin, dir, 0, 0, colory, colory2, colory3, colory4, colory4, 1, 800, 80,14);
}
}
void LFX_ParticleEffect (int effect, vec3_t org, vec3_t dir)
{
// choosing particle sets
if (r_particles->value == 1996) // Mimicing the grand old game
@@ -3164,8 +3045,4 @@ void LFX_ParticleEffect (int effect, vec3_t org, vec3_t dir)
LFX_ParticleEffect1999(effect, org, dir);
else
LFX_ParticleEffect200X(effect, org, dir);
}