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;
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", true};
48 void fractalnoise(char *noise, int size);
49 void fractalnoise_zeroedge(char *noise, int size);
51 void R_InitParticleTexture (void)
54 float dx, dy, dz, f, dot;
55 byte data[32][32][4], noise1[32][32], noise2[32][32];
58 particletexture = texture_extension_number++;
59 glBindTexture(GL_TEXTURE_2D, particletexture);
61 for (x=0 ; x<32 ; x++)
63 for (y=0 ; y<32 ; y++)
65 data[y][x][0] = data[y][x][1] = data[y][x][2] = 255;
68 d = (255 - (dx*dx+dy*dy));
70 data[y][x][3] = (byte) d;
73 glTexImage2D (GL_TEXTURE_2D, 0, 4, 32, 32, 0, GL_RGBA, GL_UNSIGNED_BYTE, data);
75 glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
77 glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
78 glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
81 fractalnoise(&noise1[0][0], 32);
82 fractalnoise(&noise2[0][0], 32);
83 for (y = 0;y < 32;y++)
84 for (x = 0;x < 32;x++)
86 data[y][x][0] = data[y][x][1] = data[y][x][2] = (noise1[y][x] >> 1) + 128;
89 d = (noise2[y][x] * (255 - (dx*dx+dy*dy))) * (1.0f / 255.0f);
92 data[y][x][3] = (byte) d;
96 for (x=0 ; x<34 ; x+=2)
97 for (y=0 ; y<34 ; y+=2)
98 data[y][x][0] = data[y][x][1] = data[y][x][2] = (rand()%32)+192;
99 for (x=0 ; x<32 ; x+=2)
100 for (y=0 ; y<32 ; y+=2)
102 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;
103 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;
104 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;
106 for (x=0 ; x<32 ; x++)
108 for (y=0 ; y<32 ; y++)
110 //data[y][x][0] = data[y][x][1] = data[y][x][2] = (rand()%192)+32;
113 d = (255 - (dx*dx+dy*dy));
115 data[y][x][3] = (byte) d;
119 smokeparticletexture = texture_extension_number++;
120 glBindTexture(GL_TEXTURE_2D, smokeparticletexture);
121 glTexImage2D (GL_TEXTURE_2D, 0, 4, 32, 32, 0, GL_RGBA, GL_UNSIGNED_BYTE, data);
122 glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
123 glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
124 glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
126 fractalnoise(&noise1[0][0], 32);
127 fractalnoise(&noise2[0][0], 32);
128 for (y = 0;y < 32;y++)
129 for (x = 0;x < 32;x++)
131 data[y][x][0] = data[y][x][1] = data[y][x][2] = (noise1[y][x] >> 1) + 128;
134 d = (noise2[y][x] * (255 - (dx*dx+dy*dy))) * (1.0f / 255.0f);
136 if (d > 255) d = 255;
137 data[y][x][3] = (byte) d;
140 bloodcloudparticletexture = texture_extension_number++;
141 glBindTexture(GL_TEXTURE_2D, bloodcloudparticletexture);
142 glTexImage2D (GL_TEXTURE_2D, 0, 4, 32, 32, 0, GL_RGBA, GL_UNSIGNED_BYTE, data);
143 glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
144 glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
145 glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
147 flareparticletexture = texture_extension_number++;
148 glBindTexture(GL_TEXTURE_2D, flareparticletexture);
150 for (x=0 ; x<32 ; x++)
152 for (y=0 ; y<32 ; y++)
154 data[y][x][0] = data[y][x][1] = data[y][x][2] = 255;
157 d = 2048 / (dx*dx+dy*dy+1) - 32;
158 d = bound(0, d, 255);
159 data[y][x][3] = (byte) d;
162 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);
166 glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
167 glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
169 rainparticletexture = texture_extension_number++;
170 glBindTexture(GL_TEXTURE_2D, rainparticletexture);
172 for (x=0 ; x<32 ; x++)
174 for (y=0 ; y<32 ; y++)
176 data[y][x][0] = data[y][x][1] = data[y][x][2] = 255;
177 if (y < 24) // stretch the upper half to make a raindrop
181 d = (255 - (dx*dx+dy*dy))/2;
187 d = (255 - (dx*dx+dy*dy))/2;
190 data[y][x][3] = (byte) d;
193 glTexImage2D (GL_TEXTURE_2D, 0, 4, 32, 32, 0, GL_RGBA, GL_UNSIGNED_BYTE, data);
195 glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
197 glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
198 glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
200 bubbleparticletexture = texture_extension_number++;
201 glBindTexture(GL_TEXTURE_2D, bubbleparticletexture);
203 light[0] = 1;light[1] = 1;light[2] = 1;
204 VectorNormalize(light);
205 for (x=0 ; x<32 ; x++)
207 for (y=0 ; y<32 ; y++)
209 data[y][x][0] = data[y][x][1] = data[y][x][2] = 255;
210 dx = x * (1.0 / 16.0) - 1.0;
211 dy = y * (1.0 / 16.0) - 1.0;
212 if (dx*dx+dy*dy < 1) // it does hit the sphere
214 dz = 1 - (dx*dx+dy*dy);
217 normal[0] = dx;normal[1] = dy;normal[2] = dz;
218 VectorNormalize(normal);
219 dot = DotProduct(normal, light);
220 if (dot > 0.5) // interior reflection
221 f += ((dot * 2) - 1);
222 else if (dot < -0.5) // exterior reflection
223 f += ((dot * -2) - 1);
225 normal[0] = dx;normal[1] = dy;normal[2] = -dz;
226 VectorNormalize(normal);
227 dot = DotProduct(normal, light);
228 if (dot > 0.5) // interior reflection
229 f += ((dot * 2) - 1);
230 else if (dot < -0.5) // exterior reflection
231 f += ((dot * -2) - 1);
233 f = bound(0, f, 255);
234 data[y][x][3] = (byte) f;
240 glTexImage2D (GL_TEXTURE_2D, 0, 4, 32, 32, 0, GL_RGBA, GL_UNSIGNED_BYTE, data);
242 glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
244 glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
245 glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
253 void R_InitParticles (void)
257 i = COM_CheckParm ("-particles");
261 r_numparticles = (int)(atoi(com_argv[i+1]));
262 if (r_numparticles < ABSOLUTE_MIN_PARTICLES)
263 r_numparticles = ABSOLUTE_MIN_PARTICLES;
267 r_numparticles = MAX_PARTICLES;
270 particles = (particle_t *) Hunk_AllocName (r_numparticles * sizeof(particle_t), "particles");
272 Cvar_RegisterVariable (&r_particles);
273 R_InitParticleTexture ();
282 #define NUMVERTEXNORMALS 162
283 extern float r_avertexnormals[NUMVERTEXNORMALS][3];
284 vec3_t avelocities[NUMVERTEXNORMALS];
285 float beamlength = 16;
286 vec3_t avelocity = {23, 7, 3};
287 float partstep = 0.01;
288 float timescale = 0.01;
290 void R_EntityParticles (entity_t *ent)
296 float sr, sp, sy, cr, cp, cy;
299 if (!r_particles.value) return; // LordHavoc: particles are optional
304 if (!avelocities[0][0])
306 for (i=0 ; i<NUMVERTEXNORMALS*3 ; i++)
307 avelocities[0][i] = (rand()&255) * 0.01;
311 for (i=0 ; i<NUMVERTEXNORMALS ; i++)
313 angle = cl.time * avelocities[i][0];
316 angle = cl.time * avelocities[i][1];
319 angle = cl.time * avelocities[i][2];
330 free_particles = p->next;
331 p->next = active_particles;
332 active_particles = p;
334 p->texnum = flareparticletexture;
337 p->die = cl.time + 0.01;
339 p->type = pt_explode;
341 p->org[0] = ent->origin[0] + r_avertexnormals[i][0]*dist + forward[0]*beamlength;
342 p->org[1] = ent->origin[1] + r_avertexnormals[i][1]*dist + forward[1]*beamlength;
343 p->org[2] = ent->origin[2] + r_avertexnormals[i][2]*dist + forward[2]*beamlength;
353 void R_ClearParticles (void)
357 free_particles = &particles[0];
358 active_particles = NULL;
360 for (i=0 ;i<r_numparticles ; i++)
361 particles[i].next = &particles[i+1];
362 particles[r_numparticles-1].next = NULL;
366 void R_ReadPointFile_f (void)
373 char name[MAX_OSPATH];
375 sprintf (name,"maps/%s.pts", sv.name);
377 COM_FOpenFile (name, &f, false);
380 Con_Printf ("couldn't open %s\n", name);
384 Con_Printf ("Reading %s...\n", name);
388 r = fscanf (f,"%f %f %f\n", &org[0], &org[1], &org[2]);
395 Con_Printf ("Not enough free particles\n");
399 free_particles = p->next;
400 p->next = active_particles;
401 active_particles = p;
403 p->texnum = particletexture;
409 VectorCopy (vec3_origin, p->vel);
410 VectorCopy (org, p->org);
414 Con_Printf ("%i points read\n", c);
419 R_ParseParticleEffect
421 Parse an effect out of the server message
424 void R_ParseParticleEffect (void)
427 int i, count, msgcount, color;
429 for (i=0 ; i<3 ; i++)
430 org[i] = MSG_ReadCoord ();
431 for (i=0 ; i<3 ; i++)
432 dir[i] = MSG_ReadChar () * (1.0/16);
433 msgcount = MSG_ReadByte ();
434 color = MSG_ReadByte ();
441 R_RunParticleEffect (org, dir, color, count);
450 void R_ParticleExplosion (vec3_t org, int smoke)
454 if (!r_particles.value) return; // LordHavoc: particles are optional
456 for (i=0 ; i<1024 ; i++)
461 free_particles = p->next;
462 p->next = active_particles;
463 active_particles = p;
465 p->texnum = flareparticletexture;
466 p->scale = lhrandom(2,5);
467 p->alpha = rand()&255;
468 p->die = cl.time + 5;
473 p->type = pt_explode;
475 p->type = pt_explode2;
477 p->color = ramp1[rand()&7];
478 p->type = pt_fallfadespark;
479 for (j=0 ; j<3 ; j++)
481 p->org[j] = org[j] + ((rand()&63)-32);
482 p->vel[j] = (rand()&511)-256;
489 for (i=0 ; i<32 ; i++)
494 free_particles = p->next;
495 p->next = active_particles;
496 active_particles = p;
498 p->texnum = smokeparticletexture;
501 p->die = cl.time + 2;
503 p->color = (rand()&7) + 8;
504 for (j=0 ; j<3 ; j++)
506 p->org[j] = org[j] + ((rand()%96)-48);
507 p->vel[j] = (rand()&63)-32;
519 void R_ParticleExplosion2 (vec3_t org, int colorStart, int colorLength)
524 if (!r_particles.value) return; // LordHavoc: particles are optional
526 for (i=0; i<512; i++)
531 free_particles = p->next;
532 p->next = active_particles;
533 active_particles = p;
535 p->texnum = flareparticletexture;
538 p->die = cl.time + 0.3;
539 p->color = colorStart + (colorMod % colorLength);
543 for (j=0 ; j<3 ; j++)
545 p->org[j] = org[j] + ((rand()%32)-16);
546 p->vel[j] = (rand()%512)-256;
557 void R_BlobExplosion (vec3_t org)
561 if (!r_particles.value) return; // LordHavoc: particles are optional
563 for (i=0 ; i<1024 ; i++)
568 free_particles = p->next;
569 p->next = active_particles;
570 active_particles = p;
572 p->texnum = flareparticletexture;
575 p->die = cl.time + 1 + (rand()&8)*0.05;
580 p->color = 66 + rand()%6;
581 for (j=0 ; j<3 ; j++)
583 p->org[j] = org[j] + ((rand()%32)-16);
584 p->vel[j] = (rand()%512)-256;
590 p->color = 150 + rand()%6;
591 for (j=0 ; j<3 ; j++)
593 p->org[j] = org[j] + ((rand()%32)-16);
594 p->vel[j] = (rand()%512)-256;
606 void R_RunParticleEffect (vec3_t org, vec3_t dir, int color, int count)
610 if (!r_particles.value) return; // LordHavoc: particles are optional
612 for (i=0 ; i<count ; i++)
617 free_particles = p->next;
618 p->next = active_particles;
619 active_particles = p;
622 { // rocket explosion
623 p->texnum = flareparticletexture;
626 p->die = cl.time + 5;
631 p->type = pt_explode;
632 for (j=0 ; j<3 ; j++)
634 p->org[j] = org[j] + ((rand()%32)-16);
635 p->vel[j] = (rand()%512)-256;
640 p->type = pt_explode2;
641 for (j=0 ; j<3 ; j++)
643 p->org[j] = org[j] + ((rand()%32)-16);
644 p->vel[j] = (rand()%512)-256;
650 p->texnum = flareparticletexture;
653 p->die = cl.time + 0.1*(rand()%5);
654 p->color = (color&~7) + (rand()&7);
655 p->type = pt_static; //slowgrav;
656 for (j=0 ; j<3 ; j++)
658 p->org[j] = org[j] + ((rand()&15)-8);
659 p->vel[j] = dir[j]*15;// + (rand()%300)-150;
665 // LordHavoc: added this for spawning sparks/dust (which have strong gravity)
672 void R_SparkShower (vec3_t org, vec3_t dir, int count, int type)
676 if (!r_particles.value) return; // LordHavoc: particles are optional
681 free_particles = p->next;
682 p->next = active_particles;
683 active_particles = p;
684 if (type == 0) // sparks
686 p->texnum = smokeparticletexture;
689 p->color = (rand()&3)+12;
690 p->type = pt_bulletpuff;
691 p->die = cl.time + 1;
692 VectorCopy(org, p->org);
693 p->vel[0] = p->vel[1] = p->vel[2] = 0;
697 p->texnum = bloodcloudparticletexture;
700 p->color = (rand()&3)+68;
701 p->type = pt_bloodcloud;
702 p->die = cl.time + 0.5;
703 VectorCopy(org, p->org);
704 p->vel[0] = p->vel[1] = p->vel[2] = 0;
707 for (i=0 ; i<count ; i++)
712 free_particles = p->next;
713 p->next = active_particles;
714 active_particles = p;
716 p->texnum = flareparticletexture;
719 p->die = cl.time + 0.0625 * (rand()&15);
721 if (type == 0) // sparks
725 p->ramp = (rand()&3);
726 p->color = ramp1[(int)p->ramp];
727 for (j=0 ; j<3 ; j++)
729 p->org[j] = org[j] + ((rand()&7)-4);
730 p->vel[j] = dir[j] + (rand()%192)-96;
736 p->type = pt_fadespark2;
737 p->color = 67 + (rand()&3);
738 for (j=0 ; j<3 ; j++)
740 p->org[j] = org[j] + (rand()&7)-4;
741 p->vel[j] = dir[j] + (rand()&63)-32;
748 void R_BloodShower (vec3_t mins, vec3_t maxs, float velspeed, int count)
755 if (!r_particles.value) return; // LordHavoc: particles are optional
757 VectorSubtract(maxs, mins, diff);
758 center[0] = (mins[0] + maxs[0]) * 0.5;
759 center[1] = (mins[1] + maxs[1]) * 0.5;
760 center[2] = (mins[2] + maxs[2]) * 0.5;
761 velscale[0] = velspeed * 2.0 / diff[0];
762 velscale[1] = velspeed * 2.0 / diff[1];
763 velscale[2] = velspeed * 2.0 / diff[2];
765 for (i=0 ; i<count ; i++)
770 free_particles = p->next;
771 p->next = active_particles;
772 active_particles = p;
774 p->texnum = bloodcloudparticletexture;
776 p->alpha = 96 + (rand()&63);
777 p->die = cl.time + 2; //0.015625 * (rand()%128);
778 p->type = pt_fadespark;
779 p->color = (rand()&3)+68;
780 // p->color = 67 + (rand()&3);
781 for (j=0 ; j<3 ; j++)
783 p->org[j] = diff[j] * (float) (rand()%1024) * (1.0 / 1024.0) + mins[j];
784 p->vel[j] = (p->org[j] - center[j]) * velscale[j];
789 void R_ParticleCube (vec3_t mins, vec3_t maxs, vec3_t dir, int count, int colorbase, int gravity, int randomvel)
795 if (!r_particles.value) return; // LordHavoc: particles are optional
796 if (maxs[0] <= mins[0]) {t = mins[0];mins[0] = maxs[0];maxs[0] = t;}
797 if (maxs[1] <= mins[1]) {t = mins[1];mins[1] = maxs[1];maxs[1] = t;}
798 if (maxs[2] <= mins[2]) {t = mins[2];mins[2] = maxs[2];maxs[2] = t;}
800 VectorSubtract(maxs, mins, diff);
802 for (i=0 ; i<count ; i++)
807 free_particles = p->next;
808 p->next = active_particles;
809 active_particles = p;
811 p->texnum = flareparticletexture;
814 p->die = cl.time + 1 + (rand()&15)*0.0625;
819 p->color = colorbase + (rand()&3);
820 for (j=0 ; j<3 ; j++)
822 p->org[j] = diff[j] * (float) (rand()&1023) * (1.0 / 1024.0) + mins[j];
824 p->vel[j] = dir[j] + (rand()%randomvel)-(randomvel*0.5);
831 void R_ParticleRain (vec3_t mins, vec3_t maxs, vec3_t dir, int count, int colorbase, int type)
839 if (!r_particles.value) return; // LordHavoc: particles are optional
840 if (maxs[0] <= mins[0]) {t = mins[0];mins[0] = maxs[0];maxs[0] = t;}
841 if (maxs[1] <= mins[1]) {t = mins[1];mins[1] = maxs[1];maxs[1] = t;}
842 if (maxs[2] <= mins[2]) {t = mins[2];mins[2] = maxs[2];maxs[2] = t;}
843 if (dir[2] < 0) // falling
845 t = (maxs[2] - mins[2]) / -dir[2];
850 t = (maxs[2] - mins[2]) / dir[2];
853 if (t < 0 || t > 2) // sanity check
857 VectorSubtract(maxs, mins, diff);
859 for (i=0 ; i<count ; i++)
864 free_particles = p->next;
865 p->next = active_particles;
866 active_particles = p;
868 vel[0] = dir[0] + (rand()&31) - 16;
869 vel[1] = dir[1] + (rand()&31) - 16;
870 vel[2] = dir[2] + (rand()&63) - 32;
871 org[0] = diff[0] * (float) (rand()&1023) * (1.0 / 1024.0) + mins[0];
872 org[1] = diff[1] * (float) (rand()&1023) * (1.0 / 1024.0) + mins[1];
880 p->texnum = particletexture;
885 p->texnum = rainparticletexture;
888 p->color = colorbase + (rand()&3);
889 VectorCopy(org, p->org);
890 VectorCopy(vel, p->vel);
891 VectorCopy(vel, p->vel2);
902 void R_LavaSplash (vec3_t org)
908 if (!r_particles.value) return; // LordHavoc: particles are optional
910 for (i=-16 ; i<16 ; i+=2)
911 for (j=-16 ; j<16 ; j+=2)
912 for (k=0 ; k<1 ; k++)
917 free_particles = p->next;
918 p->next = active_particles;
919 active_particles = p;
921 p->texnum = flareparticletexture;
924 p->die = cl.time + 2 + (rand()&31) * 0.02;
925 p->color = 224 + (rand()&7);
926 p->type = pt_slowgrav;
928 dir[0] = j*8 + (rand()&7);
929 dir[1] = i*8 + (rand()&7);
932 p->org[0] = org[0] + dir[0];
933 p->org[1] = org[1] + dir[1];
934 p->org[2] = org[2] + (rand()&63);
936 VectorNormalize (dir);
937 vel = 50 + (rand()&63);
938 VectorScale (dir, vel, p->vel);
948 void R_TeleportSplash (vec3_t org)
953 if (!r_particles.value) return; // LordHavoc: particles are optional
956 for (i=-16 ; i<16 ; i+=4)
957 for (j=-16 ; j<16 ; j+=4)
958 for (k=-24 ; k<32 ; k+=4)
963 free_particles = p->next;
964 p->next = active_particles;
965 active_particles = p;
967 p->texnum = particletexture;
970 p->die = cl.time + 0.2 + (rand()&7) * 0.02;
971 p->color = 7 + (rand()&7);
972 p->type = pt_slowgrav;
978 p->org[0] = org[0] + i + (rand()&3);
979 p->org[1] = org[1] + j + (rand()&3);
980 p->org[2] = org[2] + k + (rand()&3);
982 VectorNormalize (dir);
983 vel = 50 + (rand()&63);
984 VectorScale (dir, vel, p->vel);
988 for (i=-24 ; i<24 ; i+=8)
989 for (j=-24 ; j<24 ; j+=8)
990 for (k=-24 ; k<32 ; k+=8)
995 free_particles = p->next;
996 p->next = active_particles;
997 active_particles = p;
999 p->texnum = flareparticletexture;
1001 p->alpha = (1 + rand()&7) * 32;
1002 p->die = cl.time + 5;
1003 p->color = 254; //8 + (rand()&7);
1004 p->type = pt_fadespark;
1006 p->org[0] = org[0] + i + (rand()&7);
1007 p->org[1] = org[1] + j + (rand()&7);
1008 p->org[2] = org[2] + k + (rand()&7);
1010 p->vel[0] = i*2 + (rand()%25) - 12;
1011 p->vel[1] = j*2 + (rand()%25) - 12;
1012 p->vel[2] = k*2 + (rand()%25) - 12 + 40;
1016 void R_RocketTrail (vec3_t start, vec3_t end, int type, entity_t *ent)
1019 float len, dec, t, nt, speed;
1020 int j, contents, bubbles;
1022 static int tracercount;
1023 if (!r_particles.value) return; // LordHavoc: particles are optional
1027 if (ent->trail_leftover < 0)
1028 ent->trail_leftover = 0;
1029 t += ent->trail_leftover;
1030 ent->trail_leftover -= (cl.time - cl.oldtime);
1034 contents = Mod_PointInLeaf(start, cl.worldmodel)->contents;
1035 if (contents == CONTENTS_SKY || contents == CONTENTS_LAVA)
1038 VectorSubtract (end, start, vec);
1039 len = VectorNormalizeLength (vec);
1042 speed = len / (nt - t);
1044 bubbles = (contents == CONTENTS_WATER || contents == CONTENTS_SLIME);
1048 if (!free_particles)
1051 free_particles = p->next;
1052 p->next = active_particles;
1053 active_particles = p;
1055 p->vel[0] = p->vel[1] = p->vel[2] = 0;
1056 p->die = cl.time + 2;
1060 case 0: // rocket trail
1061 case 1: // grenade trail
1065 p->texnum = bubbleparticletexture;
1066 p->scale = lhrandom(1,2);
1068 p->color = (rand()&3)+12;
1069 p->type = pt_bubble;
1070 p->die = cl.time + 2;
1071 for (j=0 ; j<3 ; j++)
1073 p->vel[j] = (rand()&31)-16;
1074 p->org[j] = start[j] + ((rand()&3)-2);
1080 p->texnum = smokeparticletexture;
1081 p->scale = lhrandom(4, 7);
1082 p->alpha = 64 + (rand()&31);
1083 p->color = (rand()&3)+12;
1085 p->die = cl.time + 10000;
1086 VectorCopy(start, p->org);
1091 case 1: // smoke smoke
1093 p->texnum = smokeparticletexture;
1094 p->scale = lhrandom(6,9);
1096 if (r_smokecolor.value)
1097 p->color = r_smokecolor.value;
1099 p->color = (rand()&3)+12;
1101 p->die = cl.time + 1;
1102 VectorCopy(start, p->org);
1108 p->texnum = bloodcloudparticletexture;
1109 p->scale = lhrandom(8, 12);
1111 p->color = (rand()&3)+68;
1112 p->type = pt_bloodcloud;
1113 p->die = cl.time + 2;
1114 for (j=0 ; j<3 ; j++)
1116 p->vel[j] = (rand()&15)-8;
1117 p->org[j] = start[j] + ((rand()&3)-2);
1124 p->texnum = flareparticletexture;
1127 p->die = cl.time + 0.2; //5;
1128 p->type = pt_static;
1130 p->color = 52 + ((tracercount&4)<<1);
1132 p->color = 230 + ((tracercount&4)<<1);
1136 VectorCopy (start, p->org);
1137 if (tracercount & 1)
1139 p->vel[0] = 30*vec[1];
1140 p->vel[1] = 30*-vec[0];
1144 p->vel[0] = 30*-vec[1];
1145 p->vel[1] = 30*vec[0];
1149 case 4: // slight blood
1150 dec = 0.03f; // sparse trail
1151 p->texnum = bloodcloudparticletexture;
1152 p->scale = lhrandom(8,12);
1154 p->color = (rand()&3)+68;
1155 p->type = pt_fadespark2;
1156 p->die = cl.time + 2;
1157 for (j=0 ; j<3 ; j++)
1159 p->vel[j] = (rand()&15)-8;
1160 p->org[j] = start[j] + ((rand()&3)-2);
1164 case 6: // voor trail
1165 dec = 0.05f; // sparse trail
1166 p->texnum = flareparticletexture;
1167 p->scale = lhrandom(4, 8);
1169 p->color = 9*16 + 8 + (rand()&3);
1170 p->type = pt_fadespark2;
1171 p->die = cl.time + 2;
1172 for (j=0 ; j<3 ; j++)
1174 p->vel[j] = (rand()&15)-8;
1175 p->org[j] = start[j] + ((rand()&3)-2);
1179 case 7: // Nehahra smoke tracer
1181 p->texnum = smokeparticletexture;
1182 p->scale = lhrandom(6, 10);
1184 p->color = (rand()&3)+12;
1186 p->die = cl.time + 10000;
1187 for (j=0 ; j<3 ; j++)
1188 p->org[j] = start[j] + ((rand()&3)-2);
1194 VectorMA (start, dec, vec, start);
1196 ent->trail_leftover = t - cl.time;
1199 void R_RocketTrail2 (vec3_t start, vec3_t end, int color, entity_t *ent)
1204 static int tracercount;
1205 if (!r_particles.value) return; // LordHavoc: particles are optional
1207 VectorSubtract (end, start, vec);
1208 len = VectorNormalizeLength (vec);
1213 if (!free_particles)
1216 free_particles = p->next;
1217 p->next = active_particles;
1218 active_particles = p;
1220 VectorCopy (vec3_origin, p->vel);
1222 p->texnum = flareparticletexture;
1227 p->die = cl.time + 1;
1228 VectorCopy(start, p->org);
1229 // for (j=0 ; j<3 ; j++)
1230 // p->org[j] = start[j] + ((rand()&15)-8);
1232 VectorAdd (start, vec, start);
1237 extern qboolean lighthalf;
1244 extern cvar_t sv_gravity;
1246 void R_DrawParticles (void)
1248 particle_t *p, *kill;
1250 float grav, grav1, time1, time2, time3, dvel, frametime, scale, scale2;
1252 vec3_t up, right, uprightangles, forward2, up2, right2, v;
1254 // LordHavoc: early out condition
1255 if (!active_particles)
1258 VectorScale (vup, 1.5, up);
1259 VectorScale (vright, 1.5, right);
1261 uprightangles[0] = 0;
1262 uprightangles[1] = r_refdef.viewangles[1];
1263 uprightangles[2] = 0;
1264 AngleVectors (uprightangles, forward2, right2, up2);
1266 frametime = cl.time - cl.oldtime;
1267 time3 = frametime * 15;
1268 time2 = frametime * 10; // 15;
1269 time1 = frametime * 5;
1270 grav = (grav1 = frametime * sv_gravity.value) * 0.05;
1271 dvel = 1+4*frametime;
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)
1291 if (kill && kill->die < cl.time)
1293 p->next = kill->next;
1294 kill->next = free_particles;
1295 free_particles = kill;
1300 // LordHavoc: 'removed last in list' condition
1304 VectorSubtract(p->org, r_refdef.vieworg, v);
1305 if (DotProduct(v, v) >= 256.0f)
1307 scale = p->scale * -0.5;scale2 = p->scale * 0.5;
1308 color24 = (byte *) &d_8to24table[(int)p->color];
1319 transpolybegin(p->texnum, 0, p->texnum, TPOLYTYPE_ALPHA);
1320 if (p->texnum == rainparticletexture) // rain streak
1322 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);
1323 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);
1324 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);
1325 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);
1329 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);
1330 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);
1331 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);
1332 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);
1337 p->org[0] += p->vel[0]*frametime;
1338 p->org[1] += p->vel[1]*frametime;
1339 p->org[2] += p->vel[2]*frametime;
1344 if (Mod_PointInLeaf(p->org, cl.worldmodel)->contents == CONTENTS_SOLID)
1352 p->color = ramp3[(int)p->ramp];
1354 if (Mod_PointInLeaf(p->org, cl.worldmodel)->contents == CONTENTS_SOLID)
1363 p->color = ramp1[(int)p->ramp];
1364 // p->vel[2] -= grav1; // LordHavoc: apply full gravity to explosion sparks
1365 for (i=0 ; i<3 ; i++)
1367 // p->vel[2] -= grav;
1372 if (p->ramp >= 8 || Mod_PointInLeaf(p->org, cl.worldmodel)->contents == CONTENTS_SOLID)
1375 p->color = ramp2[(int)p->ramp];
1376 // p->vel[2] -= grav1; // LordHavoc: apply full gravity to explosion sparks
1377 for (i=0 ; i<3 ; i++)
1378 p->vel[i] -= p->vel[i]*frametime;
1379 // p->vel[2] -= grav;
1383 for (i=0 ; i<3 ; i++)
1384 p->vel[i] += p->vel[i]*dvel;
1386 if (Mod_PointInLeaf(p->org, cl.worldmodel)->contents == CONTENTS_SOLID)
1391 for (i=0 ; i<2 ; i++)
1392 p->vel[i] -= p->vel[i]*dvel;
1394 if (Mod_PointInLeaf(p->org, cl.worldmodel)->contents == CONTENTS_SOLID)
1400 if (Mod_PointInLeaf(p->org, cl.worldmodel)->contents == CONTENTS_SOLID)
1405 if (Mod_PointInLeaf(p->org, cl.worldmodel)->contents == CONTENTS_SOLID)
1408 // LordHavoc: gunshot spark showers
1411 p->scale -= frametime * 4;
1412 if (p->ramp >= 8 || p->scale <= 0 || Mod_PointInLeaf(p->org, cl.worldmodel)->contents == CONTENTS_SOLID)
1415 p->color = ramp3[(int)p->ramp];
1418 // LordHavoc: for smoke trails
1420 p->scale += frametime * 4;
1421 p->alpha -= frametime * 48;
1422 // p->vel[2] += grav;
1427 if (cl.time > p->time2)
1429 p->time2 = cl.time + (rand() & 3) * 0.1;
1430 p->vel[0] = (rand()&63)-32 + p->vel2[0];
1431 p->vel[1] = (rand()&63)-32 + p->vel2[1];
1432 p->vel[2] = (rand()&63)-32 + p->vel2[2];
1433 if (Mod_PointInLeaf(p->org, cl.worldmodel)->contents != CONTENTS_EMPTY)
1438 p->scale -= frametime * 64;
1439 p->alpha -= frametime * 1024;
1441 if (p->alpha < 1 || p->scale < 1)
1445 p->scale -= frametime * 24;
1446 p->alpha -= frametime * 128;
1448 if (p->alpha < 1 || p->scale < 1)
1452 p->alpha -= frametime * 256;
1454 if (p->alpha < 1 || Mod_PointInLeaf(p->org, cl.worldmodel)->contents == CONTENTS_SOLID)
1458 p->alpha -= frametime * 512;
1460 if (p->alpha < 1 || Mod_PointInLeaf(p->org, cl.worldmodel)->contents == CONTENTS_SOLID)
1463 case pt_fallfadespark:
1464 p->alpha -= frametime * 256;
1466 if (p->alpha < 1 || Mod_PointInLeaf(p->org, cl.worldmodel)->contents == CONTENTS_SOLID)
1469 case pt_fallfadespark2:
1470 p->alpha -= frametime * 512;
1472 if (p->alpha < 1 || Mod_PointInLeaf(p->org, cl.worldmodel)->contents == CONTENTS_SOLID)
1476 p->vel[2] += grav1 * 2;
1477 if (p->vel[2] >= 200)
1478 p->vel[2] = 136+rand()&63;
1479 if (cl.time > p->time2)
1481 p->time2 = cl.time + (rand()&7)*0.0625;
1482 p->vel[0] = (rand()&63)-32;
1483 p->vel[1] = (rand()&63)-32;
1485 p->alpha -= frametime * 64;
1486 if (p->alpha < 1 || Mod_PointInLeaf(p->org, cl.worldmodel)->contents == CONTENTS_EMPTY)