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 4096 // 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 cvar_t r_particles = {"r_particles", "1"};
47 cvar_t r_dynamicparticles = {"r_dynamicparticles", "1"};
49 void fractalnoise(char *noise, int size);
50 void fractalnoise_zeroedge(char *noise, int size);
52 void R_InitParticleTexture (void)
55 float dx, dy, dz, f, dot;
56 byte data[32][32][4], noise1[32][32], noise2[32][32];
59 particletexture = texture_extension_number++;
60 glBindTexture(GL_TEXTURE_2D, particletexture);
62 for (x=0 ; x<32 ; x++)
64 for (y=0 ; y<32 ; y++)
66 data[y][x][0] = data[y][x][1] = data[y][x][2] = 255;
69 d = (255 - (dx*dx+dy*dy));
71 data[y][x][3] = (byte) d;
74 glTexImage2D (GL_TEXTURE_2D, 0, 4, 32, 32, 0, GL_RGBA, GL_UNSIGNED_BYTE, data);
76 glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
78 glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
79 glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
84 fractalnoise(&noise1[0][0], 32);
85 fractalnoise(&noise2[0][0], 32);
86 for (y = 0;y < 32;y++)
87 for (x = 0;x < 32;x++)
89 data[y][x][0] = data[y][x][1] = data[y][x][2] = (noise1[y][x] >> 1) + 128;
92 d = noise2[y][x] * 4 - 512;
97 d = (d * (255 - (int) (dx*dx+dy*dy))) >> 8;
100 data[y][x][3] = (byte) d;
107 for (x=0 ; x<34 ; x+=2)
108 for (y=0 ; y<34 ; y+=2)
109 data[y][x][0] = data[y][x][1] = data[y][x][2] = (rand()%32)+192;
110 for (x=0 ; x<32 ; x+=2)
111 for (y=0 ; y<32 ; y+=2)
113 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;
114 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;
115 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;
117 for (x=0 ; x<32 ; x++)
119 for (y=0 ; y<32 ; y++)
121 //data[y][x][0] = data[y][x][1] = data[y][x][2] = (rand()%192)+32;
124 d = (255 - (dx*dx+dy*dy));
126 data[y][x][3] = (byte) d;
130 smokeparticletexture[i] = texture_extension_number++;
131 glBindTexture(GL_TEXTURE_2D, smokeparticletexture[i]);
132 glTexImage2D (GL_TEXTURE_2D, 0, 4, 32, 32, 0, GL_RGBA, GL_UNSIGNED_BYTE, data);
133 glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
134 glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
135 glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
138 fractalnoise(&noise1[0][0], 32);
139 fractalnoise(&noise2[0][0], 32);
140 for (y = 0;y < 32;y++)
141 for (x = 0;x < 32;x++)
143 data[y][x][0] = data[y][x][1] = data[y][x][2] = (noise1[y][x] >> 1) + 128;
146 d = (noise2[y][x] * (255 - (dx*dx+dy*dy))) * (1.0f / 255.0f);
148 if (d > 255) d = 255;
149 data[y][x][3] = (byte) d;
152 bloodcloudparticletexture = texture_extension_number++;
153 glBindTexture(GL_TEXTURE_2D, bloodcloudparticletexture);
154 glTexImage2D (GL_TEXTURE_2D, 0, 4, 32, 32, 0, GL_RGBA, GL_UNSIGNED_BYTE, data);
155 glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
156 glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
157 glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
159 flareparticletexture = texture_extension_number++;
160 glBindTexture(GL_TEXTURE_2D, flareparticletexture);
162 for (x=0 ; x<32 ; x++)
164 for (y=0 ; y<32 ; y++)
166 data[y][x][0] = data[y][x][1] = data[y][x][2] = 255;
169 d = 2048 / (dx*dx+dy*dy+1) - 32;
170 d = bound(0, d, 255);
171 data[y][x][3] = (byte) d;
174 glTexImage2D (GL_TEXTURE_2D, 0, 4, 32, 32, 0, GL_RGBA, GL_UNSIGNED_BYTE, data);
176 glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
178 glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
179 glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
181 rainparticletexture = texture_extension_number++;
182 glBindTexture(GL_TEXTURE_2D, rainparticletexture);
184 for (x=0 ; x<32 ; x++)
186 for (y=0 ; y<32 ; y++)
188 data[y][x][0] = data[y][x][1] = data[y][x][2] = 255;
189 if (y < 24) // stretch the upper half to make a raindrop
193 d = (255 - (dx*dx+dy*dy))/2;
199 d = (255 - (dx*dx+dy*dy))/2;
202 data[y][x][3] = (byte) d;
205 glTexImage2D (GL_TEXTURE_2D, 0, 4, 32, 32, 0, GL_RGBA, GL_UNSIGNED_BYTE, data);
207 glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
209 glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
210 glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
212 bubbleparticletexture = texture_extension_number++;
213 glBindTexture(GL_TEXTURE_2D, bubbleparticletexture);
215 light[0] = 1;light[1] = 1;light[2] = 1;
216 VectorNormalize(light);
217 for (x=0 ; x<32 ; x++)
219 for (y=0 ; y<32 ; y++)
221 data[y][x][0] = data[y][x][1] = data[y][x][2] = 255;
222 dx = x * (1.0 / 16.0) - 1.0;
223 dy = y * (1.0 / 16.0) - 1.0;
224 if (dx*dx+dy*dy < 1) // it does hit the sphere
226 dz = 1 - (dx*dx+dy*dy);
229 normal[0] = dx;normal[1] = dy;normal[2] = dz;
230 VectorNormalize(normal);
231 dot = DotProduct(normal, light);
232 if (dot > 0.5) // interior reflection
233 f += ((dot * 2) - 1);
234 else if (dot < -0.5) // exterior reflection
235 f += ((dot * -2) - 1);
237 normal[0] = dx;normal[1] = dy;normal[2] = -dz;
238 VectorNormalize(normal);
239 dot = DotProduct(normal, light);
240 if (dot > 0.5) // interior reflection
241 f += ((dot * 2) - 1);
242 else if (dot < -0.5) // exterior reflection
243 f += ((dot * -2) - 1);
245 f = bound(0, f, 255);
246 data[y][x][3] = (byte) f;
252 glTexImage2D (GL_TEXTURE_2D, 0, 4, 32, 32, 0, GL_RGBA, GL_UNSIGNED_BYTE, data);
254 glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
256 glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
257 glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
265 void R_InitParticles (void)
269 i = COM_CheckParm ("-particles");
273 r_numparticles = (int)(atoi(com_argv[i+1]));
274 if (r_numparticles < ABSOLUTE_MIN_PARTICLES)
275 r_numparticles = ABSOLUTE_MIN_PARTICLES;
279 r_numparticles = MAX_PARTICLES;
282 particles = (particle_t *) Hunk_AllocName (r_numparticles * sizeof(particle_t), "particles");
284 Cvar_RegisterVariable (&r_particles);
285 Cvar_RegisterVariable (&r_dynamicparticles);
286 R_InitParticleTexture ();
295 #define NUMVERTEXNORMALS 162
296 extern float r_avertexnormals[NUMVERTEXNORMALS][3];
297 vec3_t avelocities[NUMVERTEXNORMALS];
298 float beamlength = 16;
299 vec3_t avelocity = {23, 7, 3};
300 float partstep = 0.01;
301 float timescale = 0.01;
303 void R_EntityParticles (entity_t *ent)
309 float sr, sp, sy, cr, cp, cy;
312 if (!r_particles.value) return; // LordHavoc: particles are optional
317 if (!avelocities[0][0])
319 for (i=0 ; i<NUMVERTEXNORMALS*3 ; i++)
320 avelocities[0][i] = (rand()&255) * 0.01;
324 for (i=0 ; i<NUMVERTEXNORMALS ; i++)
326 angle = cl.time * avelocities[i][0];
329 angle = cl.time * avelocities[i][1];
332 angle = cl.time * avelocities[i][2];
343 free_particles = p->next;
344 p->next = active_particles;
345 active_particles = p;
347 p->texnum = flareparticletexture;
350 p->die = cl.time + 0.01;
352 p->type = pt_explode;
354 p->org[0] = ent->origin[0] + r_avertexnormals[i][0]*dist + forward[0]*beamlength;
355 p->org[1] = ent->origin[1] + r_avertexnormals[i][1]*dist + forward[1]*beamlength;
356 p->org[2] = ent->origin[2] + r_avertexnormals[i][2]*dist + forward[2]*beamlength;
366 void R_ClearParticles (void)
370 free_particles = &particles[0];
371 active_particles = NULL;
373 for (i=0 ;i<r_numparticles ; i++)
374 particles[i].next = &particles[i+1];
375 particles[r_numparticles-1].next = NULL;
379 void R_ReadPointFile_f (void)
386 char name[MAX_OSPATH];
388 sprintf (name,"maps/%s.pts", sv.name);
390 COM_FOpenFile (name, &f, false);
393 Con_Printf ("couldn't open %s\n", name);
397 Con_Printf ("Reading %s...\n", name);
401 r = fscanf (f,"%f %f %f\n", &org[0], &org[1], &org[2]);
408 Con_Printf ("Not enough free particles\n");
412 free_particles = p->next;
413 p->next = active_particles;
414 active_particles = p;
416 p->texnum = particletexture;
422 VectorCopy (vec3_origin, p->vel);
423 VectorCopy (org, p->org);
427 Con_Printf ("%i points read\n", c);
432 R_ParseParticleEffect
434 Parse an effect out of the server message
437 void R_ParseParticleEffect (void)
440 int i, count, msgcount, color;
442 for (i=0 ; i<3 ; i++)
443 org[i] = MSG_ReadCoord ();
444 for (i=0 ; i<3 ; i++)
445 dir[i] = MSG_ReadChar () * (1.0/16);
446 msgcount = MSG_ReadByte ();
447 color = MSG_ReadByte ();
454 R_RunParticleEffect (org, dir, color, count);
463 void R_ParticleExplosion (vec3_t org, int smoke)
467 if (!r_particles.value) return; // LordHavoc: particles are optional
469 for (i=0 ; i<1024 ; i++)
474 free_particles = p->next;
475 p->next = active_particles;
476 active_particles = p;
478 p->texnum = particletexture;
479 p->scale = lhrandom(1,3);
480 p->alpha = rand()&255;
481 p->die = cl.time + 5;
483 p->ramp = lhrandom(0, 4);
485 // p->type = pt_explode;
487 // p->type = pt_explode2;
488 p->color = ramp1[rand()&7];
489 p->type = pt_fallfadespark;
490 for (j=0 ; j<3 ; j++)
492 p->org[j] = org[j] + ((rand()&15)-8);
493 p->vel[j] = lhrandom(-192, 192);
500 for (i=0 ; i<32 ; i++)
505 free_particles = p->next;
506 p->next = active_particles;
507 active_particles = p;
509 p->texnum = smokeparticletexture[rand()&7];
512 p->die = cl.time + 2;
514 p->color = (rand()&7) + 8;
515 for (j=0 ; j<3 ; j++)
517 p->org[j] = org[j] + ((rand()%96)-48);
518 p->vel[j] = (rand()&63)-32;
530 void R_ParticleExplosion2 (vec3_t org, int colorStart, int colorLength)
535 if (!r_particles.value) return; // LordHavoc: particles are optional
537 for (i=0; i<512; i++)
542 free_particles = p->next;
543 p->next = active_particles;
544 active_particles = p;
546 p->texnum = smokeparticletexture[rand()&7];
549 p->die = cl.time + 0.3;
550 p->color = colorStart + (colorMod % colorLength);
554 for (j=0 ; j<3 ; j++)
556 p->org[j] = org[j] + ((rand()&15)-8);
557 p->vel[j] = lhrandom(-192, 192);
568 void R_BlobExplosion (vec3_t org)
572 if (!r_particles.value) return; // LordHavoc: particles are optional
574 for (i=0 ; i<1024 ; i++)
579 free_particles = p->next;
580 p->next = active_particles;
581 active_particles = p;
583 p->texnum = smokeparticletexture[rand()&7];
586 p->die = cl.time + 1 + (rand()&8)*0.05;
591 p->color = 66 + rand()%6;
592 for (j=0 ; j<3 ; j++)
594 p->org[j] = org[j] + ((rand()%32)-16);
595 p->vel[j] = lhrandom(-128, 128);
601 p->color = 150 + rand()%6;
602 for (j=0 ; j<3 ; j++)
604 p->org[j] = org[j] + ((rand()%32)-16);
605 p->vel[j] = lhrandom(-128, 128);
619 void R_RunParticleEffect (vec3_t org, vec3_t dir, int color, int count)
623 if (!r_particles.value) return; // LordHavoc: particles are optional
627 R_ParticleExplosion(org, false);
635 free_particles = p->next;
636 p->next = active_particles;
637 active_particles = p;
640 p->alpha = (count & 7) * 16 + (rand()&15);
649 p->texnum = particletexture;
651 p->die = cl.time + 1; //lhrandom(0.1, 0.5);
652 p->color = (color&~7) + (rand()&7);
653 p->type = pt_fade; //static; //slowgrav;
654 for (j=0 ; j<3 ; j++)
656 p->org[j] = org[j] + ((rand()&15)-8);
657 p->vel[j] = dir[j]*15;// + (rand()%300)-150;
662 // LordHavoc: added this for spawning sparks/dust (which have strong gravity)
669 void R_SparkShower (vec3_t org, vec3_t dir, int count, int type)
673 if (!r_particles.value) return; // LordHavoc: particles are optional
678 free_particles = p->next;
679 p->next = active_particles;
680 active_particles = p;
681 if (type == 0) // sparks
683 p->texnum = smokeparticletexture[rand()&7];
686 p->color = (rand()&3)+12;
687 p->type = pt_bulletpuff;
688 p->die = cl.time + 1;
689 VectorCopy(org, p->org);
690 p->vel[0] = p->vel[1] = p->vel[2] = 0;
694 p->texnum = smokeparticletexture[rand()&7];
697 p->color = (rand()&3)+68;
698 p->type = pt_bloodcloud;
699 p->die = cl.time + 0.5;
700 VectorCopy(org, p->org);
701 p->vel[0] = p->vel[1] = p->vel[2] = 0;
704 for (i=0 ; i<count ; i++)
709 free_particles = p->next;
710 p->next = active_particles;
711 active_particles = p;
713 p->texnum = flareparticletexture;
716 p->die = cl.time + 0.0625 * (rand()&15);
718 if (type == 0) // sparks
722 p->ramp = (rand()&3);
723 p->color = ramp1[(int)p->ramp];
724 for (j=0 ; j<3 ; j++)
726 p->org[j] = org[j] + ((rand()&7)-4);
727 p->vel[j] = dir[j] + (rand()%192)-96;
733 p->type = pt_fadespark2;
734 p->color = 67 + (rand()&3);
735 for (j=0 ; j<3 ; j++)
737 p->org[j] = org[j] + (rand()&7)-4;
738 p->vel[j] = dir[j] + (rand()&63)-32;
745 void R_BloodShower (vec3_t mins, vec3_t maxs, float velspeed, int count)
752 if (!r_particles.value) return; // LordHavoc: particles are optional
754 VectorSubtract(maxs, mins, diff);
755 center[0] = (mins[0] + maxs[0]) * 0.5;
756 center[1] = (mins[1] + maxs[1]) * 0.5;
757 center[2] = (mins[2] + maxs[2]) * 0.5;
758 velscale[0] = velspeed * 2.0 / diff[0];
759 velscale[1] = velspeed * 2.0 / diff[1];
760 velscale[2] = velspeed * 2.0 / diff[2];
762 for (i=0 ; i<count ; i++)
767 free_particles = p->next;
768 p->next = active_particles;
769 active_particles = p;
771 p->texnum = bloodcloudparticletexture;
773 p->alpha = 96 + (rand()&63);
774 p->die = cl.time + 2; //0.015625 * (rand()%128);
775 p->type = pt_fadespark;
776 p->color = (rand()&3)+68;
777 // p->color = 67 + (rand()&3);
778 for (j=0 ; j<3 ; j++)
780 p->org[j] = diff[j] * (float) (rand()%1024) * (1.0 / 1024.0) + mins[j];
781 p->vel[j] = (p->org[j] - center[j]) * velscale[j];
786 void R_ParticleCube (vec3_t mins, vec3_t maxs, vec3_t dir, int count, int colorbase, int gravity, int randomvel)
792 if (!r_particles.value) return; // LordHavoc: particles are optional
793 if (maxs[0] <= mins[0]) {t = mins[0];mins[0] = maxs[0];maxs[0] = t;}
794 if (maxs[1] <= mins[1]) {t = mins[1];mins[1] = maxs[1];maxs[1] = t;}
795 if (maxs[2] <= mins[2]) {t = mins[2];mins[2] = maxs[2];maxs[2] = t;}
797 VectorSubtract(maxs, mins, diff);
799 for (i=0 ; i<count ; i++)
804 free_particles = p->next;
805 p->next = active_particles;
806 active_particles = p;
808 p->texnum = flareparticletexture;
811 p->die = cl.time + 1 + (rand()&15)*0.0625;
816 p->color = colorbase + (rand()&3);
817 for (j=0 ; j<3 ; j++)
819 p->org[j] = diff[j] * (float) (rand()&1023) * (1.0 / 1024.0) + mins[j];
821 p->vel[j] = dir[j] + (rand()%randomvel)-(randomvel*0.5);
828 void R_ParticleRain (vec3_t mins, vec3_t maxs, vec3_t dir, int count, int colorbase, int type)
836 if (!r_particles.value) return; // LordHavoc: particles are optional
837 if (maxs[0] <= mins[0]) {t = mins[0];mins[0] = maxs[0];maxs[0] = t;}
838 if (maxs[1] <= mins[1]) {t = mins[1];mins[1] = maxs[1];maxs[1] = t;}
839 if (maxs[2] <= mins[2]) {t = mins[2];mins[2] = maxs[2];maxs[2] = t;}
840 if (dir[2] < 0) // falling
842 t = (maxs[2] - mins[2]) / -dir[2];
847 t = (maxs[2] - mins[2]) / dir[2];
850 if (t < 0 || t > 2) // sanity check
854 VectorSubtract(maxs, mins, diff);
856 for (i=0 ; i<count ; i++)
861 free_particles = p->next;
862 p->next = active_particles;
863 active_particles = p;
865 vel[0] = dir[0] + (rand()&31) - 16;
866 vel[1] = dir[1] + (rand()&31) - 16;
867 vel[2] = dir[2] + (rand()&63) - 32;
868 org[0] = diff[0] * (float) (rand()&1023) * (1.0 / 1024.0) + mins[0];
869 org[1] = diff[1] * (float) (rand()&1023) * (1.0 / 1024.0) + mins[1];
877 p->texnum = particletexture;
882 p->texnum = rainparticletexture;
885 p->color = colorbase + (rand()&3);
886 VectorCopy(org, p->org);
887 VectorCopy(vel, p->vel);
888 VectorCopy(vel, p->vel2);
899 void R_LavaSplash (vec3_t org)
905 if (!r_particles.value) return; // LordHavoc: particles are optional
907 for (i=-16 ; i<16 ; i+=2)
908 for (j=-16 ; j<16 ; j+=2)
909 for (k=0 ; k<1 ; k++)
914 free_particles = p->next;
915 p->next = active_particles;
916 active_particles = p;
918 p->texnum = flareparticletexture;
921 p->die = cl.time + 2 + (rand()&31) * 0.02;
922 p->color = 224 + (rand()&7);
923 p->type = pt_slowgrav;
925 dir[0] = j*8 + (rand()&7);
926 dir[1] = i*8 + (rand()&7);
929 p->org[0] = org[0] + dir[0];
930 p->org[1] = org[1] + dir[1];
931 p->org[2] = org[2] + (rand()&63);
933 VectorNormalize (dir);
934 vel = 50 + (rand()&63);
935 VectorScale (dir, vel, p->vel);
945 void R_TeleportSplash (vec3_t org)
950 if (!r_particles.value) return; // LordHavoc: particles are optional
953 for (i=-16 ; i<16 ; i+=4)
954 for (j=-16 ; j<16 ; j+=4)
955 for (k=-24 ; k<32 ; k+=4)
960 free_particles = p->next;
961 p->next = active_particles;
962 active_particles = p;
965 p->texnum = particletexture;
968 p->die = cl.time + 0.2 + (rand()&7) * 0.02;
969 p->color = 7 + (rand()&7);
970 p->type = pt_slowgrav;
976 p->org[0] = org[0] + i + (rand()&3);
977 p->org[1] = org[1] + j + (rand()&3);
978 p->org[2] = org[2] + k + (rand()&3);
980 VectorNormalize (dir);
981 vel = 50 + (rand()&63);
982 VectorScale (dir, vel, p->vel);
986 for (i=-24 ; i<24 ; i+=8)
987 for (j=-24 ; j<24 ; j+=8)
988 for (k=-24 ; k<32 ; k+=8)
993 free_particles = p->next;
994 p->next = active_particles;
995 active_particles = p;
997 p->texnum = flareparticletexture;
999 p->alpha = lhrandom(32,256);
1000 p->die = cl.time + 5;
1001 p->color = 254; //8 + (rand()&7);
1002 p->type = pt_fadespark;
1004 p->org[0] = org[0] + i + (rand()&7);
1005 p->org[1] = org[1] + j + (rand()&7);
1006 p->org[2] = org[2] + k + (rand()&7);
1008 p->vel[0] = i*2 + (rand()%25) - 12;
1009 p->vel[1] = j*2 + (rand()%25) - 12;
1010 p->vel[2] = k*2 + (rand()%25) - 12 + 40;
1014 void R_RocketTrail (vec3_t start, vec3_t end, int type, entity_t *ent)
1017 float len, dec = 0, t, nt, speed;
1018 int j, contents, bubbles;
1020 static int tracercount;
1021 if (!r_particles.value) return; // LordHavoc: particles are optional
1025 if (ent->trail_leftover < 0)
1026 ent->trail_leftover = 0;
1027 t += ent->trail_leftover;
1028 ent->trail_leftover -= (cl.time - cl.oldtime);
1032 contents = Mod_PointInLeaf(start, cl.worldmodel)->contents;
1033 if (contents == CONTENTS_SKY || contents == CONTENTS_LAVA)
1036 VectorSubtract (end, start, vec);
1037 len = VectorNormalizeLength (vec);
1040 speed = len / (nt - t);
1042 bubbles = (contents == CONTENTS_WATER || contents == CONTENTS_SLIME);
1046 if (!free_particles)
1049 free_particles = p->next;
1050 p->next = active_particles;
1051 active_particles = p;
1053 p->vel[0] = p->vel[1] = p->vel[2] = 0;
1054 p->die = cl.time + 2;
1058 case 0: // rocket trail
1059 case 1: // grenade trail
1063 p->texnum = bubbleparticletexture;
1064 p->scale = lhrandom(1,2);
1066 p->color = (rand()&3)+12;
1067 p->type = pt_bubble;
1068 p->die = cl.time + 2;
1069 for (j=0 ; j<3 ; j++)
1071 p->vel[j] = (rand()&31)-16;
1072 p->org[j] = start[j] + ((rand()&3)-2);
1078 p->texnum = smokeparticletexture[rand()&7];
1079 p->scale = lhrandom(6, 10);
1080 p->alpha = 64 + (rand()&31);
1081 p->color = (rand()&3)+12;
1083 p->die = cl.time + 10000;
1084 VectorCopy(start, p->org);
1089 case 1: // smoke smoke
1091 p->texnum = smokeparticletexture;
1092 p->scale = lhrandom(6,9);
1094 if (r_smokecolor.value)
1095 p->color = r_smokecolor.value;
1097 p->color = (rand()&3)+12;
1099 p->die = cl.time + 1;
1100 VectorCopy(start, p->org);
1106 p->texnum = smokeparticletexture[rand()&7];
1107 p->scale = lhrandom(6, 8);
1109 p->color = (rand()&3)+68;
1110 p->type = pt_bloodcloud;
1111 p->die = cl.time + 2;
1112 for (j=0 ; j<3 ; j++)
1114 p->vel[j] = (rand()&15)-8;
1115 p->org[j] = start[j] + ((rand()&3)-2);
1122 p->texnum = flareparticletexture;
1125 p->die = cl.time + 0.2; //5;
1126 p->type = pt_static;
1128 p->color = 52 + ((tracercount&4)<<1);
1130 p->color = 230 + ((tracercount&4)<<1);
1134 VectorCopy (start, p->org);
1135 if (tracercount & 1)
1137 p->vel[0] = 30*vec[1];
1138 p->vel[1] = 30*-vec[0];
1142 p->vel[0] = 30*-vec[1];
1143 p->vel[1] = 30*vec[0];
1147 case 4: // slight blood
1148 dec = 0.025f; // sparse trail
1149 p->texnum = smokeparticletexture[rand()&7];
1150 p->scale = lhrandom(6, 8);
1152 p->color = (rand()&3)+68;
1153 p->type = pt_fadespark2;
1154 p->die = cl.time + 2;
1155 for (j=0 ; j<3 ; j++)
1157 p->vel[j] = (rand()&15)-8;
1158 p->org[j] = start[j] + ((rand()&3)-2);
1162 case 6: // voor trail
1163 dec = 0.05f; // sparse trail
1164 p->texnum = smokeparticletexture[rand()&7];
1165 p->scale = lhrandom(3, 5);
1167 p->color = 9*16 + 8 + (rand()&3);
1168 p->type = pt_fadespark2;
1169 p->die = cl.time + 2;
1170 for (j=0 ; j<3 ; j++)
1172 p->vel[j] = (rand()&15)-8;
1173 p->org[j] = start[j] + ((rand()&3)-2);
1177 case 7: // Nehahra smoke tracer
1179 p->texnum = smokeparticletexture[rand()&7];
1180 p->scale = lhrandom(8, 12);
1182 p->color = (rand()&3)+12;
1184 p->die = cl.time + 10000;
1185 for (j=0 ; j<3 ; j++)
1186 p->org[j] = start[j] + ((rand()&3)-2);
1192 VectorMA (start, dec, vec, start);
1194 ent->trail_leftover = t - cl.time;
1197 void R_RocketTrail2 (vec3_t start, vec3_t end, int color, entity_t *ent)
1202 if (!r_particles.value) return; // LordHavoc: particles are optional
1204 VectorSubtract (end, start, vec);
1205 len = VectorNormalizeLength (vec);
1210 if (!free_particles)
1213 free_particles = p->next;
1214 p->next = active_particles;
1215 active_particles = p;
1217 VectorCopy (vec3_origin, p->vel);
1219 p->texnum = flareparticletexture;
1224 p->die = cl.time + 1;
1225 VectorCopy(start, p->org);
1226 // for (j=0 ; j<3 ; j++)
1227 // p->org[j] = start[j] + ((rand()&15)-8);
1229 VectorAdd (start, vec, start);
1234 extern qboolean lighthalf;
1241 extern cvar_t sv_gravity;
1242 void R_CompleteLightPoint (vec3_t color, vec3_t p);
1244 void R_DrawParticles (void)
1246 particle_t *p, *kill;
1248 float grav, grav1, time1, time2, time3, dvel, frametime, scale, scale2;
1250 vec3_t up, right, uprightangles, forward2, up2, right2, v, tempcolor;
1252 // LordHavoc: early out condition
1253 if (!active_particles)
1256 VectorScale (vup, 1.5, up);
1257 VectorScale (vright, 1.5, right);
1259 uprightangles[0] = 0;
1260 uprightangles[1] = r_refdef.viewangles[1];
1261 uprightangles[2] = 0;
1262 AngleVectors (uprightangles, forward2, right2, up2);
1264 frametime = cl.time - cl.oldtime;
1265 time3 = frametime * 15;
1266 time2 = frametime * 10; // 15;
1267 time1 = frametime * 5;
1268 grav = (grav1 = frametime * sv_gravity.value) * 0.05;
1269 dvel = 1+4*frametime;
1273 kill = active_particles;
1274 if (kill && kill->die < cl.time)
1276 active_particles = kill->next;
1277 kill->next = free_particles;
1278 free_particles = kill;
1284 for (p=active_particles ; p ; p=p->next)
1289 if (kill && kill->die < cl.time)
1291 p->next = kill->next;
1292 kill->next = free_particles;
1293 free_particles = kill;
1298 // LordHavoc: 'removed last in list' condition
1302 VectorSubtract(p->org, r_refdef.vieworg, v);
1303 if (DotProduct(v, v) >= 256.0f)
1305 scale = p->scale * -0.5;scale2 = p->scale * 0.5;
1306 color24 = (byte *) &d_8to24table[(int)p->color];
1317 if (r_dynamicparticles.value)
1319 R_CompleteLightPoint(tempcolor, p->org);
1320 r = (r * (int) tempcolor[0]) >> 7;
1321 g = (g * (int) tempcolor[1]) >> 7;
1322 b = (b * (int) tempcolor[2]) >> 7;
1324 transpolybegin(p->texnum, 0, p->texnum, TPOLYTYPE_ALPHA);
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);
1342 p->org[0] += p->vel[0]*frametime;
1343 p->org[1] += p->vel[1]*frametime;
1344 p->org[2] += p->vel[2]*frametime;
1355 p->color = ramp3[(int)p->ramp];
1364 p->color = ramp1[(int)p->ramp];
1365 // p->vel[2] -= grav1; // LordHavoc: apply full gravity to explosion sparks
1366 for (i=0 ; i<3 ; i++)
1368 // p->vel[2] -= grav;
1376 p->color = ramp2[(int)p->ramp];
1377 // p->vel[2] -= grav1; // LordHavoc: apply full gravity to explosion sparks
1378 for (i=0 ; i<3 ; i++)
1379 // p->vel[i] -= p->vel[i]*frametime;
1381 //// p->vel[2] -= grav;
1385 for (i=0 ; i<3 ; i++)
1386 p->vel[i] += p->vel[i]*dvel;
1391 for (i=0 ; i<2 ; i++)
1392 p->vel[i] -= p->vel[i]*dvel;
1402 // LordHavoc: gunshot spark showers
1405 p->scale -= frametime * 4;
1406 if (p->ramp >= 8 || p->scale <= 0)
1409 p->color = ramp3[(int)p->ramp];
1412 // LordHavoc: for smoke trails
1414 p->scale += frametime * 4;
1415 p->alpha -= frametime * 48;
1416 // p->vel[2] += grav;
1421 if (cl.time > p->time2)
1423 p->time2 = cl.time + (rand() & 3) * 0.1;
1424 p->vel[0] = (rand()&63)-32 + p->vel2[0];
1425 p->vel[1] = (rand()&63)-32 + p->vel2[1];
1426 p->vel[2] = (rand()&63)-32 + p->vel2[2];
1430 p->scale -= frametime * 64;
1431 p->alpha -= frametime * 1024;
1433 if (p->alpha < 1 || p->scale < 1)
1437 p->scale += frametime * 4;
1438 p->alpha -= frametime * 64;
1440 if (p->alpha < 1 || p->scale < 1)
1444 p->alpha -= frametime * 256;
1450 p->alpha -= frametime * 512;
1455 case pt_fallfadespark:
1456 p->alpha -= frametime * 256;
1461 case pt_fallfadespark2:
1462 p->alpha -= frametime * 512;
1468 p->alpha -= frametime * 512;
1473 if (Mod_PointInLeaf(p->org, cl.worldmodel)->contents == CONTENTS_EMPTY)
1475 p->vel[2] += grav1 * 2;
1476 if (p->vel[2] >= 200)
1477 p->vel[2] = lhrandom(130, 200);
1478 if (cl.time > p->time2)
1480 p->time2 = cl.time + lhrandom(0, 0.5);
1481 p->vel[0] = lhrandom(-32,32);
1482 p->vel[1] = lhrandom(-32,32);
1484 p->alpha -= frametime * 64;