2 Copyright (C) 1996-1997 Id Software, Inc.
4 This program is free software; you can redistribute it and/or
5 modify it under the terms of the GNU General Public License
6 as published by the Free Software Foundation; either version 2
7 of the License, or (at your option) any later version.
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
13 See the GNU General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the Free Software
17 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
23 #define MAX_PARTICLES 32768 // default max # of particles at one
25 #define ABSOLUTE_MIN_PARTICLES 512 // no fewer than this no matter what's
26 // on the command line
28 int ramp1[8] = {0x6f, 0x6d, 0x6b, 0x69, 0x67, 0x65, 0x63, 0x61};
29 int ramp2[8] = {0x6f, 0x6e, 0x6d, 0x6c, 0x6b, 0x6a, 0x68, 0x66};
30 int ramp3[8] = {0x6d, 0x6b, 6, 5, 4, 3};
33 int smokeparticletexture[8];
34 int flareparticletexture;
35 int rainparticletexture;
36 int bloodcloudparticletexture;
37 int bubbleparticletexture;
39 particle_t *active_particles, *free_particles;
41 particle_t *particles;
44 vec3_t r_pright, r_pup, r_ppn;
46 // LordHavoc: reduced duplicate code, and allow particle allocation system independence
47 #define ALLOCPARTICLE \
51 free_particles = p->next;\
52 p->next = active_particles;\
55 cvar_t r_particles = {"r_particles", "1"};
56 cvar_t r_dynamicparticles = {"r_dynamicparticles", "0", TRUE};
58 void fractalnoise(char *noise, int size);
59 void fractalnoise_zeroedge(char *noise, int size);
61 void R_InitParticleTexture (void)
64 float dx, dy, dz, f, dot;
65 byte data[32][32][4], noise1[32][32], noise2[32][32];
68 particletexture = texture_extension_number++;
69 glBindTexture(GL_TEXTURE_2D, particletexture);
71 for (x=0 ; x<32 ; x++)
73 for (y=0 ; y<32 ; y++)
75 data[y][x][0] = data[y][x][1] = data[y][x][2] = 255;
78 d = (255 - (dx*dx+dy*dy));
80 data[y][x][3] = (byte) d;
83 glTexImage2D (GL_TEXTURE_2D, 0, 4, 32, 32, 0, GL_RGBA, GL_UNSIGNED_BYTE, data);
85 glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
87 glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
88 glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
93 fractalnoise(&noise1[0][0], 32);
94 fractalnoise(&noise2[0][0], 32);
95 for (y = 0;y < 32;y++)
96 for (x = 0;x < 32;x++)
98 data[y][x][0] = data[y][x][1] = data[y][x][2] = (noise1[y][x] >> 1) + 128;
101 d = noise2[y][x] * 4 - 512;
106 d = (d * (255 - (int) (dx*dx+dy*dy))) >> 8;
108 if (d > 255) d = 255;
109 data[y][x][3] = (byte) d;
116 for (x=0 ; x<34 ; x+=2)
117 for (y=0 ; y<34 ; y+=2)
118 data[y][x][0] = data[y][x][1] = data[y][x][2] = (rand()%32)+192;
119 for (x=0 ; x<32 ; x+=2)
120 for (y=0 ; y<32 ; y+=2)
122 data[y ][x+1][0] = data[y ][x+1][1] = data[y ][x+1][2] = (int) (data[y ][x ][0] + data[y ][x+2][0]) >> 1;
123 data[y+1][x ][0] = data[y+1][x ][1] = data[y+1][x ][2] = (int) (data[y ][x ][0] + data[y+2][x ][0]) >> 1;
124 data[y+1][x+1][0] = data[y+1][x+1][1] = data[y+1][x+1][2] = (int) (data[y ][x ][0] + data[y ][x+2][0] + data[y+2][x ][0] + data[y+2][x+2][0]) >> 2;
126 for (x=0 ; x<32 ; x++)
128 for (y=0 ; y<32 ; y++)
130 //data[y][x][0] = data[y][x][1] = data[y][x][2] = (rand()%192)+32;
133 d = (255 - (dx*dx+dy*dy));
135 data[y][x][3] = (byte) d;
139 smokeparticletexture[i] = texture_extension_number++;
140 glBindTexture(GL_TEXTURE_2D, smokeparticletexture[i]);
141 glTexImage2D (GL_TEXTURE_2D, 0, 4, 32, 32, 0, GL_RGBA, GL_UNSIGNED_BYTE, data);
142 glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
143 glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
144 glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
147 fractalnoise(&noise1[0][0], 32);
148 fractalnoise(&noise2[0][0], 32);
149 for (y = 0;y < 32;y++)
150 for (x = 0;x < 32;x++)
152 data[y][x][0] = data[y][x][1] = data[y][x][2] = (noise1[y][x] >> 1) + 128;
155 d = (noise2[y][x] * (255 - (dx*dx+dy*dy))) * (1.0f / 255.0f);
157 if (d > 255) d = 255;
158 data[y][x][3] = (byte) d;
161 bloodcloudparticletexture = texture_extension_number++;
162 glBindTexture(GL_TEXTURE_2D, bloodcloudparticletexture);
163 glTexImage2D (GL_TEXTURE_2D, 0, 4, 32, 32, 0, GL_RGBA, GL_UNSIGNED_BYTE, data);
164 glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
165 glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
166 glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
168 flareparticletexture = texture_extension_number++;
169 glBindTexture(GL_TEXTURE_2D, flareparticletexture);
171 for (x=0 ; x<32 ; x++)
173 for (y=0 ; y<32 ; y++)
175 data[y][x][0] = data[y][x][1] = data[y][x][2] = 255;
178 d = 2048 / (dx*dx+dy*dy+1) - 32;
179 d = bound(0, d, 255);
180 data[y][x][3] = (byte) d;
183 glTexImage2D (GL_TEXTURE_2D, 0, 4, 32, 32, 0, GL_RGBA, GL_UNSIGNED_BYTE, data);
185 glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
187 glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
188 glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
190 rainparticletexture = texture_extension_number++;
191 glBindTexture(GL_TEXTURE_2D, rainparticletexture);
193 for (x=0 ; x<32 ; x++)
195 for (y=0 ; y<32 ; y++)
197 data[y][x][0] = data[y][x][1] = data[y][x][2] = 255;
198 if (y < 24) // stretch the upper half to make a raindrop
202 d = (255 - (dx*dx+dy*dy))/2;
208 d = (255 - (dx*dx+dy*dy))/2;
211 data[y][x][3] = (byte) d;
214 glTexImage2D (GL_TEXTURE_2D, 0, 4, 32, 32, 0, GL_RGBA, GL_UNSIGNED_BYTE, data);
216 glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
218 glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
219 glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
221 bubbleparticletexture = texture_extension_number++;
222 glBindTexture(GL_TEXTURE_2D, bubbleparticletexture);
224 light[0] = 1;light[1] = 1;light[2] = 1;
225 VectorNormalize(light);
226 for (x=0 ; x<32 ; x++)
228 for (y=0 ; y<32 ; y++)
230 data[y][x][0] = data[y][x][1] = data[y][x][2] = 255;
231 dx = x * (1.0 / 16.0) - 1.0;
232 dy = y * (1.0 / 16.0) - 1.0;
233 if (dx*dx+dy*dy < 1) // it does hit the sphere
235 dz = 1 - (dx*dx+dy*dy);
238 normal[0] = dx;normal[1] = dy;normal[2] = dz;
239 VectorNormalize(normal);
240 dot = DotProduct(normal, light);
241 if (dot > 0.5) // interior reflection
242 f += ((dot * 2) - 1);
243 else if (dot < -0.5) // exterior reflection
244 f += ((dot * -2) - 1);
246 normal[0] = dx;normal[1] = dy;normal[2] = -dz;
247 VectorNormalize(normal);
248 dot = DotProduct(normal, light);
249 if (dot > 0.5) // interior reflection
250 f += ((dot * 2) - 1);
251 else if (dot < -0.5) // exterior reflection
252 f += ((dot * -2) - 1);
254 f = bound(0, f, 255);
255 data[y][x][3] = (byte) f;
261 glTexImage2D (GL_TEXTURE_2D, 0, 4, 32, 32, 0, GL_RGBA, GL_UNSIGNED_BYTE, data);
263 glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
265 glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
266 glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
274 void R_InitParticles (void)
278 i = COM_CheckParm ("-particles");
282 r_numparticles = (int)(atoi(com_argv[i+1]));
283 if (r_numparticles < ABSOLUTE_MIN_PARTICLES)
284 r_numparticles = ABSOLUTE_MIN_PARTICLES;
288 r_numparticles = MAX_PARTICLES;
291 particles = (particle_t *) Hunk_AllocName (r_numparticles * sizeof(particle_t), "particles");
293 Cvar_RegisterVariable (&r_particles);
294 Cvar_RegisterVariable (&r_dynamicparticles);
295 R_InitParticleTexture ();
304 #define NUMVERTEXNORMALS 162
305 extern float r_avertexnormals[NUMVERTEXNORMALS][3];
306 vec3_t avelocities[NUMVERTEXNORMALS];
307 float beamlength = 16;
308 vec3_t avelocity = {23, 7, 3};
309 float partstep = 0.01;
310 float timescale = 0.01;
312 void R_EntityParticles (entity_t *ent)
318 float sr, sp, sy, cr, cp, cy;
321 if (!r_particles.value) return; // LordHavoc: particles are optional
326 if (!avelocities[0][0])
328 for (i=0 ; i<NUMVERTEXNORMALS*3 ; i++)
329 avelocities[0][i] = (rand()&255) * 0.01;
333 for (i=0 ; i<NUMVERTEXNORMALS ; i++)
335 angle = cl.time * avelocities[i][0];
338 angle = cl.time * avelocities[i][1];
341 angle = cl.time * avelocities[i][2];
351 // p->pushvel[0] = p->pushvel[1] = p->pushvel[2] = p->vel[0] = p->vel[1] = p->vel[2] = 0;
352 p->texnum = flareparticletexture;
357 p->type = pt_explode;
359 p->org[0] = ent->origin[0] + r_avertexnormals[i][0]*dist + forward[0]*beamlength;
360 p->org[1] = ent->origin[1] + r_avertexnormals[i][1]*dist + forward[1]*beamlength;
361 p->org[2] = ent->origin[2] + r_avertexnormals[i][2]*dist + forward[2]*beamlength;
371 void R_ClearParticles (void)
375 free_particles = &particles[0];
376 active_particles = NULL;
378 for (i=0 ;i<r_numparticles ; i++)
379 particles[i].next = &particles[i+1];
380 particles[r_numparticles-1].next = NULL;
384 void R_ReadPointFile_f (void)
391 char name[MAX_OSPATH];
393 sprintf (name,"maps/%s.pts", sv.name);
395 COM_FOpenFile (name, &f, false);
398 Con_Printf ("couldn't open %s\n", name);
402 Con_Printf ("Reading %s...\n", name);
406 r = fscanf (f,"%f %f %f\n", &org[0], &org[1], &org[2]);
413 Con_Printf ("Not enough free particles\n");
418 p->texnum = particletexture;
424 // p->pushvel[0] = p->pushvel[1] = p->pushvel[2] = p->vel[0] = p->vel[1] = p->vel[2] = 0;
425 VectorCopy (org, p->org);
429 Con_Printf ("%i points read\n", c);
436 LordHavoc: blasts away particles in the area, used for explosions to disturb the smoke trail and such
440 void R_BlastParticles(vec3_t org, vec_t radius, vec_t power)
444 vec_t radius2 = radius * radius, speed, dist, scale = 2.5 * power / radius;
445 p = active_particles;
450 VectorSubtract(p->org, org, v);
451 dist = DotProduct(v,v);
454 speed = (radius - sqrt(dist)) * scale;
456 VectorMA(p->pushvel, speed, v, p->pushvel);
465 R_ParseParticleEffect
467 Parse an effect out of the server message
470 void R_ParseParticleEffect (void)
473 int i, count, msgcount, color;
475 for (i=0 ; i<3 ; i++)
476 org[i] = MSG_ReadCoord ();
477 for (i=0 ; i<3 ; i++)
478 dir[i] = MSG_ReadChar () * (1.0/16);
479 msgcount = MSG_ReadByte ();
480 color = MSG_ReadByte ();
487 R_RunParticleEffect (org, dir, color, count);
496 void R_ParticleExplosion (vec3_t org, int smoke)
500 if (!r_particles.value) return; // LordHavoc: particles are optional
503 for (i=0 ; i<1024 ; i++)
507 // p->pushvel[0] = p->pushvel[1] = p->pushvel[2] = 0;
508 p->texnum = particletexture;
509 p->scale = lhrandom(1,3);
510 p->alpha = rand()&255;
511 p->die = cl.time + 5;
513 p->ramp = lhrandom(0, 4);
515 // p->type = pt_explode;
517 // p->type = pt_explode2;
518 p->color = ramp1[rand()&7];
519 p->type = pt_fallfadespark;
520 for (j=0 ; j<3 ; j++)
522 p->org[j] = org[j] + lhrandom(-8,8);
523 p->vel[j] = lhrandom(-192, 192);
529 i = Mod_PointInLeaf(org, cl.worldmodel)->contents;
530 if (i == CONTENTS_SLIME || i == CONTENTS_WATER)
532 for (i=0 ; i<32 ; i++)
536 // p->pushvel[0] = p->pushvel[1] = p->pushvel[2] = 0;
537 p->texnum = bubbleparticletexture;
538 p->scale = lhrandom(1,2);
540 p->color = (rand()&3)+12;
542 p->die = cl.time + 2;
543 for (j=0 ; j<3 ; j++)
545 p->org[j] = org[j] + lhrandom(-16,16);
546 p->vel[j] = lhrandom(-16,16);
552 // for (i=0 ; i<32 ; i++)
556 // p->pushvel[0] = p->pushvel[1] = p->pushvel[2] = 0;
557 p->texnum = smokeparticletexture[rand()&7];
561 p->die = cl.time + 2;
562 p->type = pt_smokecloud;
563 p->color = (rand()&7) + 8;
564 for (j=0 ; j<3 ; j++)
566 // p->org[j] = org[j] + ((rand()%96)-48);
567 // p->vel[j] = (rand()&63)-32;
581 void R_ParticleExplosion2 (vec3_t org, int colorStart, int colorLength)
586 if (!r_particles.value) return; // LordHavoc: particles are optional
588 for (i=0; i<512; i++)
592 // p->pushvel[0] = p->pushvel[1] = p->pushvel[2] = 0;
593 p->texnum = particletexture;
596 p->die = cl.time + 0.3;
597 p->color = colorStart + (colorMod % colorLength);
601 for (j=0 ; j<3 ; j++)
603 p->org[j] = org[j] + ((rand()&15)-8);
604 p->vel[j] = lhrandom(-192, 192);
615 void R_BlobExplosion (vec3_t org)
619 if (!r_particles.value) return; // LordHavoc: particles are optional
621 for (i=0 ; i<1024 ; i++)
625 // p->pushvel[0] = p->pushvel[1] = p->pushvel[2] = 0;
626 p->texnum = particletexture;
629 p->die = cl.time + 1 + (rand()&8)*0.05;
634 p->color = 66 + rand()%6;
635 for (j=0 ; j<3 ; j++)
637 p->org[j] = org[j] + ((rand()%32)-16);
638 p->vel[j] = lhrandom(-128, 128);
644 p->color = 150 + rand()%6;
645 for (j=0 ; j<3 ; j++)
647 p->org[j] = org[j] + ((rand()%32)-16);
648 p->vel[j] = lhrandom(-128, 128);
662 void R_RunParticleEffect (vec3_t org, vec3_t dir, int color, int count)
666 if (!r_particles.value) return; // LordHavoc: particles are optional
670 R_ParticleExplosion(org, false);
678 p->alpha = (count & 7) * 16 + (rand()&15);
687 // p->pushvel[0] = p->pushvel[1] = p->pushvel[2] = 0;
688 p->texnum = particletexture;
690 p->die = cl.time + 1; //lhrandom(0.1, 0.5);
691 p->color = (color&~7) + (rand()&7);
692 p->type = pt_fade; //static; //slowgrav;
693 for (j=0 ; j<3 ; j++)
695 p->org[j] = org[j] + ((rand()&15)-8);
696 p->vel[j] = dir[j]*15;// + (rand()%300)-150;
701 // LordHavoc: added this for spawning sparks/dust (which have strong gravity)
708 void R_SparkShower (vec3_t org, vec3_t dir, int count, int type)
712 if (!r_particles.value) return; // LordHavoc: particles are optional
715 // p->pushvel[0] = p->pushvel[1] = p->pushvel[2] = 0;
716 if (type == 0) // sparks
718 p->texnum = smokeparticletexture[rand()&7];
721 p->color = (rand()&3)+12;
722 p->type = pt_bulletpuff;
723 p->die = cl.time + 1;
724 VectorCopy(org, p->org);
725 p->vel[0] = p->vel[1] = p->vel[2] = 0;
729 p->texnum = smokeparticletexture[rand()&7];
732 p->color = (rand()&3)+68;
733 p->type = pt_bloodcloud;
734 p->die = cl.time + 0.5;
735 VectorCopy(org, p->org);
736 p->vel[0] = p->vel[1] = p->vel[2] = 0;
739 for (i=0 ; i<count ; i++)
743 // p->pushvel[0] = p->pushvel[1] = p->pushvel[2] = 0;
744 p->texnum = flareparticletexture;
747 p->die = cl.time + 0.0625 * (rand()&15);
749 if (type == 0) // sparks
753 p->ramp = (rand()&3);
754 p->color = ramp1[(int)p->ramp];
755 for (j=0 ; j<3 ; j++)
757 p->org[j] = org[j] + ((rand()&7)-4);
758 p->vel[j] = dir[j] + (rand()%192)-96;
764 p->type = pt_fadespark2;
765 p->color = 67 + (rand()&3);
766 for (j=0 ; j<3 ; j++)
768 p->org[j] = org[j] + (rand()&7)-4;
769 p->vel[j] = dir[j] + (rand()&63)-32;
776 void R_BloodShower (vec3_t mins, vec3_t maxs, float velspeed, int count)
783 if (!r_particles.value) return; // LordHavoc: particles are optional
785 VectorSubtract(maxs, mins, diff);
786 center[0] = (mins[0] + maxs[0]) * 0.5;
787 center[1] = (mins[1] + maxs[1]) * 0.5;
788 center[2] = (mins[2] + maxs[2]) * 0.5;
789 velscale[0] = velspeed * 2.0 / diff[0];
790 velscale[1] = velspeed * 2.0 / diff[1];
791 velscale[2] = velspeed * 2.0 / diff[2];
793 for (i=0 ; i<count ; i++)
797 // p->pushvel[0] = p->pushvel[1] = p->pushvel[2] = 0;
798 p->texnum = bloodcloudparticletexture;
800 p->alpha = 96 + (rand()&63);
801 p->die = cl.time + 2; //0.015625 * (rand()%128);
802 p->type = pt_fadespark;
803 p->color = (rand()&3)+68;
804 // p->color = 67 + (rand()&3);
805 for (j=0 ; j<3 ; j++)
807 p->org[j] = diff[j] * (float) (rand()%1024) * (1.0 / 1024.0) + mins[j];
808 p->vel[j] = (p->org[j] - center[j]) * velscale[j];
813 void R_ParticleCube (vec3_t mins, vec3_t maxs, vec3_t dir, int count, int colorbase, int gravity, int randomvel)
819 if (!r_particles.value) return; // LordHavoc: particles are optional
820 if (maxs[0] <= mins[0]) {t = mins[0];mins[0] = maxs[0];maxs[0] = t;}
821 if (maxs[1] <= mins[1]) {t = mins[1];mins[1] = maxs[1];maxs[1] = t;}
822 if (maxs[2] <= mins[2]) {t = mins[2];mins[2] = maxs[2];maxs[2] = t;}
824 VectorSubtract(maxs, mins, diff);
826 for (i=0 ; i<count ; i++)
830 // p->pushvel[0] = p->pushvel[1] = p->pushvel[2] = 0;
831 p->texnum = flareparticletexture;
834 p->die = cl.time + 1 + (rand()&15)*0.0625;
839 p->color = colorbase + (rand()&3);
840 for (j=0 ; j<3 ; j++)
842 p->org[j] = diff[j] * (float) (rand()&1023) * (1.0 / 1024.0) + mins[j];
844 p->vel[j] = dir[j] + (rand()%randomvel)-(randomvel*0.5);
851 void R_ParticleRain (vec3_t mins, vec3_t maxs, vec3_t dir, int count, int colorbase, int type)
859 if (!r_particles.value) return; // LordHavoc: particles are optional
860 if (maxs[0] <= mins[0]) {t = mins[0];mins[0] = maxs[0];maxs[0] = t;}
861 if (maxs[1] <= mins[1]) {t = mins[1];mins[1] = maxs[1];maxs[1] = t;}
862 if (maxs[2] <= mins[2]) {t = mins[2];mins[2] = maxs[2];maxs[2] = t;}
863 if (dir[2] < 0) // falling
865 t = (maxs[2] - mins[2]) / -dir[2];
870 t = (maxs[2] - mins[2]) / dir[2];
873 if (t < 0 || t > 2) // sanity check
877 VectorSubtract(maxs, mins, diff);
879 for (i=0 ; i<count ; i++)
883 vel[0] = dir[0] + (rand()&31) - 16;
884 vel[1] = dir[1] + (rand()&31) - 16;
885 vel[2] = dir[2] + (rand()&63) - 32;
886 org[0] = diff[0] * (float) (rand()&1023) * (1.0 / 1024.0) + mins[0];
887 org[1] = diff[1] * (float) (rand()&1023) * (1.0 / 1024.0) + mins[1];
890 // p->pushvel[0] = p->pushvel[1] = p->pushvel[2] = 0;
896 p->texnum = particletexture;
901 p->texnum = rainparticletexture;
904 p->color = colorbase + (rand()&3);
905 VectorCopy(org, p->org);
906 VectorCopy(vel, p->vel);
907 VectorCopy(vel, p->vel2);
918 void R_LavaSplash (vec3_t org)
924 if (!r_particles.value) return; // LordHavoc: particles are optional
926 for (i=-16 ; i<16 ; i+=2)
927 for (j=-16 ; j<16 ; j+=2)
928 for (k=0 ; k<1 ; k++)
932 // p->pushvel[0] = p->pushvel[1] = p->pushvel[2] = 0;
933 p->texnum = flareparticletexture;
936 p->die = cl.time + 2 + (rand()&31) * 0.02;
937 p->color = 224 + (rand()&7);
938 p->type = pt_slowgrav;
940 dir[0] = j*8 + (rand()&7);
941 dir[1] = i*8 + (rand()&7);
944 p->org[0] = org[0] + dir[0];
945 p->org[1] = org[1] + dir[1];
946 p->org[2] = org[2] + (rand()&63);
948 VectorNormalize (dir);
949 vel = 50 + (rand()&63);
950 VectorScale (dir, vel, p->vel);
960 void R_TeleportSplash (vec3_t org)
965 if (!r_particles.value) return; // LordHavoc: particles are optional
968 for (i=-16 ; i<16 ; i+=4)
969 for (j=-16 ; j<16 ; j+=4)
970 for (k=-24 ; k<32 ; k+=4)
974 // p->pushvel[0] = p->pushvel[1] = p->pushvel[2] = 0;
976 p->texnum = particletexture;
979 p->die = cl.time + 0.2 + (rand()&7) * 0.02;
980 p->color = 7 + (rand()&7);
981 p->type = pt_slowgrav;
987 p->org[0] = org[0] + i + (rand()&3);
988 p->org[1] = org[1] + j + (rand()&3);
989 p->org[2] = org[2] + k + (rand()&3);
991 VectorNormalize (dir);
992 vel = 50 + (rand()&63);
993 VectorScale (dir, vel, p->vel);
997 for (i=-24 ; i<24 ; i+=8)
998 for (j=-24 ; j<24 ; j+=8)
999 for (k=-24 ; k<32 ; k+=8)
1003 // p->pushvel[0] = p->pushvel[1] = p->pushvel[2] = 0;
1004 p->texnum = flareparticletexture;
1006 p->alpha = lhrandom(32,256);
1007 p->die = cl.time + 5;
1008 p->color = 254; //8 + (rand()&7);
1009 p->type = pt_fadespark;
1011 p->org[0] = org[0] + i + (rand()&7);
1012 p->org[1] = org[1] + j + (rand()&7);
1013 p->org[2] = org[2] + k + (rand()&7);
1015 p->vel[0] = i*2 + (rand()%25) - 12;
1016 p->vel[1] = j*2 + (rand()%25) - 12;
1017 p->vel[2] = k*2 + (rand()%25) - 12 + 40;
1021 void R_RocketTrail (vec3_t start, vec3_t end, int type, entity_t *ent)
1024 float len, dec = 0, t, nt, speed;
1025 int j, contents, bubbles;
1027 static int tracercount;
1028 if (!r_particles.value) return; // LordHavoc: particles are optional
1032 if (ent->trail_leftover < 0)
1033 ent->trail_leftover = 0;
1034 t += ent->trail_leftover;
1035 ent->trail_leftover -= (cl.time - cl.oldtime);
1039 contents = Mod_PointInLeaf(start, cl.worldmodel)->contents;
1040 if (contents == CONTENTS_SKY || contents == CONTENTS_LAVA)
1043 VectorSubtract (end, start, vec);
1044 len = VectorNormalizeLength (vec);
1047 speed = len / (nt - t);
1049 bubbles = (contents == CONTENTS_WATER || contents == CONTENTS_SLIME);
1055 // p->pushvel[0] = p->pushvel[1] = p->pushvel[2] = 0;
1056 p->vel[0] = p->vel[1] = p->vel[2] = 0;
1057 p->die = cl.time + 2;
1061 case 0: // rocket trail
1062 case 1: // grenade trail
1066 p->texnum = bubbleparticletexture;
1067 p->scale = lhrandom(1,2);
1069 p->color = (rand()&3)+12;
1070 p->type = pt_bubble;
1071 p->die = cl.time + 2;
1072 for (j=0 ; j<3 ; j++)
1074 p->vel[j] = (rand()&31)-16;
1075 p->org[j] = start[j] + ((rand()&3)-2);
1081 p->texnum = smokeparticletexture[rand()&7];
1082 p->scale = lhrandom(8, 12);
1083 p->alpha = 64 + (rand()&31);
1084 p->color = (rand()&3)+12;
1086 p->die = cl.time + 10000;
1087 VectorCopy(start, p->org);
1092 case 1: // smoke smoke
1094 p->texnum = smokeparticletexture;
1095 p->scale = lhrandom(6,9);
1097 if (r_smokecolor.value)
1098 p->color = r_smokecolor.value;
1100 p->color = (rand()&3)+12;
1102 p->die = cl.time + 1;
1103 VectorCopy(start, p->org);
1109 p->texnum = smokeparticletexture[rand()&7];
1110 p->scale = lhrandom(6, 8);
1112 p->color = (rand()&3)+68;
1113 p->type = pt_bloodcloud;
1114 p->die = cl.time + 9999;
1115 for (j=0 ; j<3 ; j++)
1117 p->vel[j] = (rand()&15)-8;
1118 p->org[j] = start[j] + ((rand()&3)-2);
1125 p->texnum = flareparticletexture;
1128 p->die = cl.time + 0.2; //5;
1129 p->type = pt_static;
1131 p->color = 52 + ((tracercount&4)<<1);
1133 p->color = 230 + ((tracercount&4)<<1);
1137 VectorCopy (start, p->org);
1138 if (tracercount & 1)
1140 p->vel[0] = 30*vec[1];
1141 p->vel[1] = 30*-vec[0];
1145 p->vel[0] = 30*-vec[1];
1146 p->vel[1] = 30*vec[0];
1150 case 4: // slight blood
1151 dec = 0.025f; // sparse trail
1152 p->texnum = smokeparticletexture[rand()&7];
1153 p->scale = lhrandom(6, 8);
1155 p->color = (rand()&3)+68;
1156 p->type = pt_fadespark2;
1157 p->die = cl.time + 9999;
1158 for (j=0 ; j<3 ; j++)
1160 p->vel[j] = (rand()&15)-8;
1161 p->org[j] = start[j] + ((rand()&3)-2);
1165 case 6: // voor trail
1166 dec = 0.05f; // sparse trail
1167 p->texnum = smokeparticletexture[rand()&7];
1168 p->scale = lhrandom(3, 5);
1170 p->color = 9*16 + 8 + (rand()&3);
1171 p->type = pt_fadespark2;
1172 p->die = cl.time + 2;
1173 for (j=0 ; j<3 ; j++)
1175 p->vel[j] = (rand()&15)-8;
1176 p->org[j] = start[j] + ((rand()&3)-2);
1180 case 7: // Nehahra smoke tracer
1182 p->texnum = smokeparticletexture[rand()&7];
1183 p->scale = lhrandom(8, 12);
1185 p->color = (rand()&3)+12;
1187 p->die = cl.time + 10000;
1188 for (j=0 ; j<3 ; j++)
1189 p->org[j] = start[j] + ((rand()&3)-2);
1195 VectorMA (start, dec, vec, start);
1197 ent->trail_leftover = t - cl.time;
1200 void R_RocketTrail2 (vec3_t start, vec3_t end, int color, entity_t *ent)
1205 if (!r_particles.value) return; // LordHavoc: particles are optional
1207 VectorSubtract (end, start, vec);
1208 len = VectorNormalizeLength (vec);
1215 // p->pushvel[0] = p->pushvel[1] = p->pushvel[2] = 0;
1216 p->vel[0] = p->vel[1] = p->vel[2] = 0;
1218 p->texnum = flareparticletexture;
1223 p->die = cl.time + 1;
1224 VectorCopy(start, p->org);
1225 // for (j=0 ; j<3 ; j++)
1226 // p->org[j] = start[j] + ((rand()&15)-8);
1228 VectorAdd (start, vec, start);
1233 extern qboolean lighthalf;
1240 extern cvar_t sv_gravity;
1241 void R_CompleteLightPoint (vec3_t color, vec3_t p);
1243 void R_DrawParticles (void)
1245 particle_t *p, *kill;
1247 float grav, grav1, time1, time2, time3, dvel, frametime, scale, scale2/*, f1, f2*/, minparticledist;
1249 vec3_t up, right, uprightangles, forward2, up2, right2, tempcolor;
1251 // LordHavoc: early out condition
1252 if (!active_particles)
1255 VectorScale (vup, 1.5, up);
1256 VectorScale (vright, 1.5, right);
1258 uprightangles[0] = 0;
1259 uprightangles[1] = r_refdef.viewangles[1];
1260 uprightangles[2] = 0;
1261 AngleVectors (uprightangles, forward2, right2, up2);
1263 frametime = cl.time - cl.oldtime;
1264 time3 = frametime * 15;
1265 time2 = frametime * 10; // 15;
1266 time1 = frametime * 5;
1267 grav = (grav1 = frametime * sv_gravity.value) * 0.05;
1268 dvel = 1+4*frametime;
1270 minparticledist = DotProduct(r_refdef.vieworg, vpn) + 16.0f;
1272 // remove dead particles at beginning of list
1275 kill = active_particles;
1276 if (kill && kill->die < cl.time)
1278 active_particles = kill->next;
1279 kill->next = free_particles;
1280 free_particles = kill;
1286 for (p=active_particles ; p ; p=p->next)
1288 // remove dead particles following this one
1292 if (kill && kill->die < cl.time)
1294 p->next = kill->next;
1295 kill->next = free_particles;
1296 free_particles = kill;
1302 // LordHavoc: only render if not too close
1303 if (DotProduct(p->org, vpn) >= minparticledist)
1305 color24 = (byte *) &d_8to24table[(int)p->color];
1316 if (r_dynamicparticles.value)
1318 R_CompleteLightPoint(tempcolor, p->org);
1319 r = (r * (int) tempcolor[0]) >> 7;
1320 g = (g * (int) tempcolor[1]) >> 7;
1321 b = (b * (int) tempcolor[2]) >> 7;
1323 transpolybegin(p->texnum, 0, p->texnum, TPOLYTYPE_ALPHA);
1324 scale = p->scale * -0.5;scale2 = p->scale * 0.5;
1325 if (p->texnum == rainparticletexture) // rain streak
1327 transpolyvert(p->org[0] + up2[0]*scale + right2[0]*scale , p->org[1] + up2[1]*scale + right2[1]*scale , p->org[2] + up2[2]*scale + right2[2]*scale , 0,1,r,g,b,a);
1328 transpolyvert(p->org[0] + up2[0]*scale2 + right2[0]*scale , p->org[1] + up2[1]*scale2 + right2[1]*scale , p->org[2] + up2[2]*scale2 + right2[2]*scale , 0,0,r,g,b,a);
1329 transpolyvert(p->org[0] + up2[0]*scale2 + right2[0]*scale2, p->org[1] + up2[1]*scale2 + right2[1]*scale2, p->org[2] + up2[2]*scale2 + right2[2]*scale2, 1,0,r,g,b,a);
1330 transpolyvert(p->org[0] + up2[0]*scale + right2[0]*scale2, p->org[1] + up2[1]*scale + right2[1]*scale2, p->org[2] + up2[2]*scale + right2[2]*scale2, 1,1,r,g,b,a);
1334 transpolyvert(p->org[0] + up[0]*scale + right[0]*scale , p->org[1] + up[1]*scale + right[1]*scale , p->org[2] + up[2]*scale + right[2]*scale , 0,1,r,g,b,a);
1335 transpolyvert(p->org[0] + up[0]*scale2 + right[0]*scale , p->org[1] + up[1]*scale2 + right[1]*scale , p->org[2] + up[2]*scale2 + right[2]*scale , 0,0,r,g,b,a);
1336 transpolyvert(p->org[0] + up[0]*scale2 + right[0]*scale2, p->org[1] + up[1]*scale2 + right[1]*scale2, p->org[2] + up[2]*scale2 + right[2]*scale2, 1,0,r,g,b,a);
1337 transpolyvert(p->org[0] + up[0]*scale + right[0]*scale2, p->org[1] + up[1]*scale + right[1]*scale2, p->org[2] + up[2]*scale + right[2]*scale2, 1,1,r,g,b,a);
1343 if (p->pushvel[0] || p->pushvel[1] || p->pushvel[2])
1345 p->org[0] += (p->vel[0]+p->pushvel[0])*frametime;
1346 p->org[1] += (p->vel[1]+p->pushvel[1])*frametime;
1347 p->org[2] += (p->vel[2]+p->pushvel[2])*frametime;
1348 f1 = sqrt(DotProduct(p->pushvel,p->pushvel));
1349 f2 = f1 - frametime * 32;
1351 p->pushvel[0] = p->pushvel[1] = p->pushvel[2] = 0;
1355 p->pushvel[0] *= f2;
1356 p->pushvel[1] *= f2;
1357 p->pushvel[2] *= f2;
1362 if (p->type != pt_smokecloud)
1365 p->org[0] += p->vel[0]*frametime;
1366 p->org[1] += p->vel[1]*frametime;
1367 p->org[2] += p->vel[2]*frametime;
1382 p->color = ramp3[(int)p->ramp];
1391 p->color = ramp1[(int)p->ramp];
1392 // p->vel[2] -= grav1; // LordHavoc: apply full gravity to explosion sparks
1393 for (i=0 ; i<3 ; i++)
1395 // p->vel[2] -= grav;
1403 p->color = ramp2[(int)p->ramp];
1404 // p->vel[2] -= grav1; // LordHavoc: apply full gravity to explosion sparks
1405 for (i=0 ; i<3 ; i++)
1406 // p->vel[i] -= p->vel[i]*frametime;
1408 //// p->vel[2] -= grav;
1412 for (i=0 ; i<3 ; i++)
1413 p->vel[i] += p->vel[i]*dvel;
1418 for (i=0 ; i<2 ; i++)
1419 p->vel[i] -= p->vel[i]*dvel;
1429 // LordHavoc: gunshot spark showers
1432 p->scale -= frametime * 4;
1433 p->alpha -= frametime * 48;
1434 if (p->ramp >= 8 || p->scale < 1 || p->alpha < 1)
1437 p->color = ramp3[(int)p->ramp];
1440 // LordHavoc: for smoke trails
1442 p->scale += frametime * 6;
1443 p->alpha -= frametime * 128;
1444 // p->vel[2] += grav;
1449 if (cl.time > p->time2)
1451 p->time2 = cl.time + (rand() & 3) * 0.1;
1452 p->vel[0] = (rand()&63)-32 + p->vel2[0];
1453 p->vel[1] = (rand()&63)-32 + p->vel2[1];
1454 p->vel[2] = (rand()&63)-32 + p->vel2[2];
1458 p->scale -= frametime * 64;
1459 p->alpha -= frametime * 1024;
1461 if (p->alpha < 1 || p->scale < 1)
1465 if (Mod_PointInLeaf(p->org, cl.worldmodel)->contents != CONTENTS_EMPTY)
1470 p->scale += frametime * 4;
1471 p->alpha -= frametime * 64;
1473 if (p->alpha < 1 || p->scale < 1)
1477 p->alpha -= frametime * 256;
1483 p->alpha -= frametime * 512;
1488 case pt_fallfadespark:
1489 p->alpha -= frametime * 256;
1494 case pt_fallfadespark2:
1495 p->alpha -= frametime * 512;
1501 p->alpha -= frametime * 512;
1506 if (Mod_PointInLeaf(p->org, cl.worldmodel)->contents == CONTENTS_EMPTY)
1508 p->vel[2] += grav1 * 2;
1509 if (p->vel[2] >= 200)
1510 p->vel[2] = lhrandom(130, 200);
1511 if (cl.time > p->time2)
1513 p->time2 = cl.time + lhrandom(0, 0.5);
1514 p->vel[0] = lhrandom(-32,32);
1515 p->vel[1] = lhrandom(-32,32);
1517 p->alpha -= frametime * 64;
1522 p->scale += frametime * 60;
1523 p->alpha -= frametime * 96;