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 // 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
439 void R_BlastParticles(vec3_t org, vec_t radius, vec_t power)
443 vec_t radius2 = radius * radius, speed, dist, scale = 2.5 * power / radius;
444 p = active_particles;
449 VectorSubtract(p->org, org, v);
450 dist = DotProduct(v,v);
453 speed = (radius - sqrt(dist)) * scale;
455 VectorMA(p->pushvel, speed, v, p->pushvel);
463 R_ParseParticleEffect
465 Parse an effect out of the server message
468 void R_ParseParticleEffect (void)
471 int i, count, msgcount, color;
473 for (i=0 ; i<3 ; i++)
474 org[i] = MSG_ReadCoord ();
475 for (i=0 ; i<3 ; i++)
476 dir[i] = MSG_ReadChar () * (1.0/16);
477 msgcount = MSG_ReadByte ();
478 color = MSG_ReadByte ();
485 R_RunParticleEffect (org, dir, color, count);
494 void R_ParticleExplosion (vec3_t org, int smoke)
498 if (!r_particles.value) return; // LordHavoc: particles are optional
500 for (i=0 ; i<1024 ; i++)
504 p->pushvel[0] = p->pushvel[1] = p->pushvel[2] = 0;
505 p->texnum = particletexture;
506 p->scale = lhrandom(1,3);
507 p->alpha = rand()&255;
508 p->die = cl.time + 5;
510 p->ramp = lhrandom(0, 4);
512 // p->type = pt_explode;
514 // p->type = pt_explode2;
515 p->color = ramp1[rand()&7];
516 p->type = pt_fallfadespark;
517 for (j=0 ; j<3 ; j++)
519 p->org[j] = org[j] + lhrandom(-8,8);
520 p->vel[j] = lhrandom(-192, 192);
525 i = Mod_PointInLeaf(org, cl.worldmodel)->contents;
526 if (i == CONTENTS_SLIME || i == CONTENTS_WATER)
528 for (i=0 ; i<32 ; i++)
532 p->pushvel[0] = p->pushvel[1] = p->pushvel[2] = 0;
533 p->texnum = bubbleparticletexture;
534 p->scale = lhrandom(1,2);
536 p->color = (rand()&3)+12;
538 p->die = cl.time + 2;
539 for (j=0 ; j<3 ; j++)
541 p->org[j] = org[j] + lhrandom(-16,16);
542 p->vel[j] = lhrandom(-16,16);
548 for (i=0 ; i<32 ; i++)
552 p->pushvel[0] = p->pushvel[1] = p->pushvel[2] = 0;
553 p->texnum = smokeparticletexture[rand()&7];
556 p->die = cl.time + 2;
558 p->color = (rand()&7) + 8;
559 for (j=0 ; j<3 ; j++)
561 p->org[j] = org[j] + ((rand()%96)-48);
562 p->vel[j] = (rand()&63)-32;
574 void R_ParticleExplosion2 (vec3_t org, int colorStart, int colorLength)
579 if (!r_particles.value) return; // LordHavoc: particles are optional
581 for (i=0; i<512; i++)
585 p->pushvel[0] = p->pushvel[1] = p->pushvel[2] = 0;
586 p->texnum = smokeparticletexture[rand()&7];
589 p->die = cl.time + 0.3;
590 p->color = colorStart + (colorMod % colorLength);
594 for (j=0 ; j<3 ; j++)
596 p->org[j] = org[j] + ((rand()&15)-8);
597 p->vel[j] = lhrandom(-192, 192);
608 void R_BlobExplosion (vec3_t org)
612 if (!r_particles.value) return; // LordHavoc: particles are optional
614 for (i=0 ; i<1024 ; i++)
618 p->pushvel[0] = p->pushvel[1] = p->pushvel[2] = 0;
619 p->texnum = smokeparticletexture[rand()&7];
622 p->die = cl.time + 1 + (rand()&8)*0.05;
627 p->color = 66 + rand()%6;
628 for (j=0 ; j<3 ; j++)
630 p->org[j] = org[j] + ((rand()%32)-16);
631 p->vel[j] = lhrandom(-128, 128);
637 p->color = 150 + rand()%6;
638 for (j=0 ; j<3 ; j++)
640 p->org[j] = org[j] + ((rand()%32)-16);
641 p->vel[j] = lhrandom(-128, 128);
655 void R_RunParticleEffect (vec3_t org, vec3_t dir, int color, int count)
659 if (!r_particles.value) return; // LordHavoc: particles are optional
663 R_ParticleExplosion(org, false);
671 p->alpha = (count & 7) * 16 + (rand()&15);
680 p->pushvel[0] = p->pushvel[1] = p->pushvel[2] = 0;
681 p->texnum = particletexture;
683 p->die = cl.time + 1; //lhrandom(0.1, 0.5);
684 p->color = (color&~7) + (rand()&7);
685 p->type = pt_fade; //static; //slowgrav;
686 for (j=0 ; j<3 ; j++)
688 p->org[j] = org[j] + ((rand()&15)-8);
689 p->vel[j] = dir[j]*15;// + (rand()%300)-150;
694 // LordHavoc: added this for spawning sparks/dust (which have strong gravity)
701 void R_SparkShower (vec3_t org, vec3_t dir, int count, int type)
705 if (!r_particles.value) return; // LordHavoc: particles are optional
708 p->pushvel[0] = p->pushvel[1] = p->pushvel[2] = 0;
709 if (type == 0) // sparks
711 p->texnum = smokeparticletexture[rand()&7];
714 p->color = (rand()&3)+12;
715 p->type = pt_bulletpuff;
716 p->die = cl.time + 1;
717 VectorCopy(org, p->org);
718 p->vel[0] = p->vel[1] = p->vel[2] = 0;
722 p->texnum = smokeparticletexture[rand()&7];
725 p->color = (rand()&3)+68;
726 p->type = pt_bloodcloud;
727 p->die = cl.time + 0.5;
728 VectorCopy(org, p->org);
729 p->vel[0] = p->vel[1] = p->vel[2] = 0;
732 for (i=0 ; i<count ; i++)
736 p->pushvel[0] = p->pushvel[1] = p->pushvel[2] = 0;
737 p->texnum = flareparticletexture;
740 p->die = cl.time + 0.0625 * (rand()&15);
742 if (type == 0) // sparks
746 p->ramp = (rand()&3);
747 p->color = ramp1[(int)p->ramp];
748 for (j=0 ; j<3 ; j++)
750 p->org[j] = org[j] + ((rand()&7)-4);
751 p->vel[j] = dir[j] + (rand()%192)-96;
757 p->type = pt_fadespark2;
758 p->color = 67 + (rand()&3);
759 for (j=0 ; j<3 ; j++)
761 p->org[j] = org[j] + (rand()&7)-4;
762 p->vel[j] = dir[j] + (rand()&63)-32;
769 void R_BloodShower (vec3_t mins, vec3_t maxs, float velspeed, int count)
776 if (!r_particles.value) return; // LordHavoc: particles are optional
778 VectorSubtract(maxs, mins, diff);
779 center[0] = (mins[0] + maxs[0]) * 0.5;
780 center[1] = (mins[1] + maxs[1]) * 0.5;
781 center[2] = (mins[2] + maxs[2]) * 0.5;
782 velscale[0] = velspeed * 2.0 / diff[0];
783 velscale[1] = velspeed * 2.0 / diff[1];
784 velscale[2] = velspeed * 2.0 / diff[2];
786 for (i=0 ; i<count ; i++)
790 p->pushvel[0] = p->pushvel[1] = p->pushvel[2] = 0;
791 p->texnum = bloodcloudparticletexture;
793 p->alpha = 96 + (rand()&63);
794 p->die = cl.time + 2; //0.015625 * (rand()%128);
795 p->type = pt_fadespark;
796 p->color = (rand()&3)+68;
797 // p->color = 67 + (rand()&3);
798 for (j=0 ; j<3 ; j++)
800 p->org[j] = diff[j] * (float) (rand()%1024) * (1.0 / 1024.0) + mins[j];
801 p->vel[j] = (p->org[j] - center[j]) * velscale[j];
806 void R_ParticleCube (vec3_t mins, vec3_t maxs, vec3_t dir, int count, int colorbase, int gravity, int randomvel)
812 if (!r_particles.value) return; // LordHavoc: particles are optional
813 if (maxs[0] <= mins[0]) {t = mins[0];mins[0] = maxs[0];maxs[0] = t;}
814 if (maxs[1] <= mins[1]) {t = mins[1];mins[1] = maxs[1];maxs[1] = t;}
815 if (maxs[2] <= mins[2]) {t = mins[2];mins[2] = maxs[2];maxs[2] = t;}
817 VectorSubtract(maxs, mins, diff);
819 for (i=0 ; i<count ; i++)
823 p->pushvel[0] = p->pushvel[1] = p->pushvel[2] = 0;
824 p->texnum = flareparticletexture;
827 p->die = cl.time + 1 + (rand()&15)*0.0625;
832 p->color = colorbase + (rand()&3);
833 for (j=0 ; j<3 ; j++)
835 p->org[j] = diff[j] * (float) (rand()&1023) * (1.0 / 1024.0) + mins[j];
837 p->vel[j] = dir[j] + (rand()%randomvel)-(randomvel*0.5);
844 void R_ParticleRain (vec3_t mins, vec3_t maxs, vec3_t dir, int count, int colorbase, int type)
852 if (!r_particles.value) return; // LordHavoc: particles are optional
853 if (maxs[0] <= mins[0]) {t = mins[0];mins[0] = maxs[0];maxs[0] = t;}
854 if (maxs[1] <= mins[1]) {t = mins[1];mins[1] = maxs[1];maxs[1] = t;}
855 if (maxs[2] <= mins[2]) {t = mins[2];mins[2] = maxs[2];maxs[2] = t;}
856 if (dir[2] < 0) // falling
858 t = (maxs[2] - mins[2]) / -dir[2];
863 t = (maxs[2] - mins[2]) / dir[2];
866 if (t < 0 || t > 2) // sanity check
870 VectorSubtract(maxs, mins, diff);
872 for (i=0 ; i<count ; i++)
876 vel[0] = dir[0] + (rand()&31) - 16;
877 vel[1] = dir[1] + (rand()&31) - 16;
878 vel[2] = dir[2] + (rand()&63) - 32;
879 org[0] = diff[0] * (float) (rand()&1023) * (1.0 / 1024.0) + mins[0];
880 org[1] = diff[1] * (float) (rand()&1023) * (1.0 / 1024.0) + mins[1];
883 p->pushvel[0] = p->pushvel[1] = p->pushvel[2] = 0;
889 p->texnum = particletexture;
894 p->texnum = rainparticletexture;
897 p->color = colorbase + (rand()&3);
898 VectorCopy(org, p->org);
899 VectorCopy(vel, p->vel);
900 VectorCopy(vel, p->vel2);
911 void R_LavaSplash (vec3_t org)
917 if (!r_particles.value) return; // LordHavoc: particles are optional
919 for (i=-16 ; i<16 ; i+=2)
920 for (j=-16 ; j<16 ; j+=2)
921 for (k=0 ; k<1 ; k++)
925 p->pushvel[0] = p->pushvel[1] = p->pushvel[2] = 0;
926 p->texnum = flareparticletexture;
929 p->die = cl.time + 2 + (rand()&31) * 0.02;
930 p->color = 224 + (rand()&7);
931 p->type = pt_slowgrav;
933 dir[0] = j*8 + (rand()&7);
934 dir[1] = i*8 + (rand()&7);
937 p->org[0] = org[0] + dir[0];
938 p->org[1] = org[1] + dir[1];
939 p->org[2] = org[2] + (rand()&63);
941 VectorNormalize (dir);
942 vel = 50 + (rand()&63);
943 VectorScale (dir, vel, p->vel);
953 void R_TeleportSplash (vec3_t org)
958 if (!r_particles.value) return; // LordHavoc: particles are optional
961 for (i=-16 ; i<16 ; i+=4)
962 for (j=-16 ; j<16 ; j+=4)
963 for (k=-24 ; k<32 ; k+=4)
967 p->pushvel[0] = p->pushvel[1] = p->pushvel[2] = 0;
969 p->texnum = particletexture;
972 p->die = cl.time + 0.2 + (rand()&7) * 0.02;
973 p->color = 7 + (rand()&7);
974 p->type = pt_slowgrav;
980 p->org[0] = org[0] + i + (rand()&3);
981 p->org[1] = org[1] + j + (rand()&3);
982 p->org[2] = org[2] + k + (rand()&3);
984 VectorNormalize (dir);
985 vel = 50 + (rand()&63);
986 VectorScale (dir, vel, p->vel);
990 for (i=-24 ; i<24 ; i+=8)
991 for (j=-24 ; j<24 ; j+=8)
992 for (k=-24 ; k<32 ; k+=8)
996 p->pushvel[0] = p->pushvel[1] = p->pushvel[2] = 0;
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);
1048 p->pushvel[0] = p->pushvel[1] = p->pushvel[2] = p->vel[0] = p->vel[1] = p->vel[2] = 0;
1049 p->die = cl.time + 2;
1053 case 0: // rocket trail
1054 case 1: // grenade trail
1058 p->texnum = bubbleparticletexture;
1059 p->scale = lhrandom(1,2);
1061 p->color = (rand()&3)+12;
1062 p->type = pt_bubble;
1063 p->die = cl.time + 2;
1064 for (j=0 ; j<3 ; j++)
1066 p->vel[j] = (rand()&31)-16;
1067 p->org[j] = start[j] + ((rand()&3)-2);
1073 p->texnum = smokeparticletexture[rand()&7];
1074 p->scale = lhrandom(6, 10);
1075 p->alpha = 64 + (rand()&31);
1076 p->color = (rand()&3)+12;
1078 p->die = cl.time + 10000;
1079 VectorCopy(start, p->org);
1084 case 1: // smoke smoke
1086 p->texnum = smokeparticletexture;
1087 p->scale = lhrandom(6,9);
1089 if (r_smokecolor.value)
1090 p->color = r_smokecolor.value;
1092 p->color = (rand()&3)+12;
1094 p->die = cl.time + 1;
1095 VectorCopy(start, p->org);
1101 p->texnum = smokeparticletexture[rand()&7];
1102 p->scale = lhrandom(6, 8);
1104 p->color = (rand()&3)+68;
1105 p->type = pt_bloodcloud;
1106 p->die = cl.time + 2;
1107 for (j=0 ; j<3 ; j++)
1109 p->vel[j] = (rand()&15)-8;
1110 p->org[j] = start[j] + ((rand()&3)-2);
1117 p->texnum = flareparticletexture;
1120 p->die = cl.time + 0.2; //5;
1121 p->type = pt_static;
1123 p->color = 52 + ((tracercount&4)<<1);
1125 p->color = 230 + ((tracercount&4)<<1);
1129 VectorCopy (start, p->org);
1130 if (tracercount & 1)
1132 p->vel[0] = 30*vec[1];
1133 p->vel[1] = 30*-vec[0];
1137 p->vel[0] = 30*-vec[1];
1138 p->vel[1] = 30*vec[0];
1142 case 4: // slight blood
1143 dec = 0.025f; // sparse trail
1144 p->texnum = smokeparticletexture[rand()&7];
1145 p->scale = lhrandom(6, 8);
1147 p->color = (rand()&3)+68;
1148 p->type = pt_fadespark2;
1149 p->die = cl.time + 2;
1150 for (j=0 ; j<3 ; j++)
1152 p->vel[j] = (rand()&15)-8;
1153 p->org[j] = start[j] + ((rand()&3)-2);
1157 case 6: // voor trail
1158 dec = 0.05f; // sparse trail
1159 p->texnum = smokeparticletexture[rand()&7];
1160 p->scale = lhrandom(3, 5);
1162 p->color = 9*16 + 8 + (rand()&3);
1163 p->type = pt_fadespark2;
1164 p->die = cl.time + 2;
1165 for (j=0 ; j<3 ; j++)
1167 p->vel[j] = (rand()&15)-8;
1168 p->org[j] = start[j] + ((rand()&3)-2);
1172 case 7: // Nehahra smoke tracer
1174 p->texnum = smokeparticletexture[rand()&7];
1175 p->scale = lhrandom(8, 12);
1177 p->color = (rand()&3)+12;
1179 p->die = cl.time + 10000;
1180 for (j=0 ; j<3 ; j++)
1181 p->org[j] = start[j] + ((rand()&3)-2);
1187 VectorMA (start, dec, vec, start);
1189 ent->trail_leftover = t - cl.time;
1192 void R_RocketTrail2 (vec3_t start, vec3_t end, int color, entity_t *ent)
1197 if (!r_particles.value) return; // LordHavoc: particles are optional
1199 VectorSubtract (end, start, vec);
1200 len = VectorNormalizeLength (vec);
1207 p->pushvel[0] = p->pushvel[1] = p->pushvel[2] = p->vel[0] = p->vel[1] = p->vel[2] = 0;
1209 p->texnum = flareparticletexture;
1214 p->die = cl.time + 1;
1215 VectorCopy(start, p->org);
1216 // for (j=0 ; j<3 ; j++)
1217 // p->org[j] = start[j] + ((rand()&15)-8);
1219 VectorAdd (start, vec, start);
1224 extern qboolean lighthalf;
1231 extern cvar_t sv_gravity;
1232 void R_CompleteLightPoint (vec3_t color, vec3_t p);
1234 void R_DrawParticles (void)
1236 particle_t *p, *kill;
1238 float grav, grav1, time1, time2, time3, dvel, frametime, scale, scale2, f1, f2;
1240 vec3_t up, right, uprightangles, forward2, up2, right2, v, tempcolor;
1242 // LordHavoc: early out condition
1243 if (!active_particles)
1246 VectorScale (vup, 1.5, up);
1247 VectorScale (vright, 1.5, right);
1249 uprightangles[0] = 0;
1250 uprightangles[1] = r_refdef.viewangles[1];
1251 uprightangles[2] = 0;
1252 AngleVectors (uprightangles, forward2, right2, up2);
1254 frametime = cl.time - cl.oldtime;
1255 time3 = frametime * 15;
1256 time2 = frametime * 10; // 15;
1257 time1 = frametime * 5;
1258 grav = (grav1 = frametime * sv_gravity.value) * 0.05;
1259 dvel = 1+4*frametime;
1263 kill = active_particles;
1264 if (kill && kill->die < cl.time)
1266 active_particles = kill->next;
1267 kill->next = free_particles;
1268 free_particles = kill;
1274 for (p=active_particles ; p ; p=p->next)
1279 if (kill && kill->die < cl.time)
1281 p->next = kill->next;
1282 kill->next = free_particles;
1283 free_particles = kill;
1288 // LordHavoc: 'removed last in list' condition
1292 VectorSubtract(p->org, r_refdef.vieworg, v);
1293 if (DotProduct(v, v) >= 256.0f)
1295 scale = p->scale * -0.5;scale2 = p->scale * 0.5;
1296 color24 = (byte *) &d_8to24table[(int)p->color];
1307 if (r_dynamicparticles.value)
1309 R_CompleteLightPoint(tempcolor, p->org);
1310 r = (r * (int) tempcolor[0]) >> 7;
1311 g = (g * (int) tempcolor[1]) >> 7;
1312 b = (b * (int) tempcolor[2]) >> 7;
1314 transpolybegin(p->texnum, 0, p->texnum, TPOLYTYPE_ALPHA);
1315 if (p->texnum == rainparticletexture) // rain streak
1317 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);
1318 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);
1319 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);
1320 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);
1324 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);
1325 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);
1326 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);
1327 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);
1332 if (p->pushvel[0] || p->pushvel[1] || p->pushvel[2])
1334 p->org[0] += (p->vel[0]+p->pushvel[0])*frametime;
1335 p->org[1] += (p->vel[1]+p->pushvel[1])*frametime;
1336 p->org[2] += (p->vel[2]+p->pushvel[2])*frametime;
1337 f1 = sqrt(DotProduct(p->pushvel,p->pushvel));
1338 f2 = f1 - frametime * 32;
1340 p->pushvel[0] = p->pushvel[1] = p->pushvel[2] = 0;
1344 p->pushvel[0] *= f2;
1345 p->pushvel[1] *= f2;
1346 p->pushvel[2] *= f2;
1351 p->org[0] += p->vel[0]*frametime;
1352 p->org[1] += p->vel[1]*frametime;
1353 p->org[2] += p->vel[2]*frametime;
1365 p->color = ramp3[(int)p->ramp];
1374 p->color = ramp1[(int)p->ramp];
1375 // p->vel[2] -= grav1; // LordHavoc: apply full gravity to explosion sparks
1376 for (i=0 ; i<3 ; i++)
1378 // p->vel[2] -= grav;
1386 p->color = ramp2[(int)p->ramp];
1387 // p->vel[2] -= grav1; // LordHavoc: apply full gravity to explosion sparks
1388 for (i=0 ; i<3 ; i++)
1389 // p->vel[i] -= p->vel[i]*frametime;
1391 //// p->vel[2] -= grav;
1395 for (i=0 ; i<3 ; i++)
1396 p->vel[i] += p->vel[i]*dvel;
1401 for (i=0 ; i<2 ; i++)
1402 p->vel[i] -= p->vel[i]*dvel;
1412 // LordHavoc: gunshot spark showers
1415 p->scale -= frametime * 4;
1416 if (p->ramp >= 8 || p->scale <= 0)
1419 p->color = ramp3[(int)p->ramp];
1422 // LordHavoc: for smoke trails
1424 p->scale += frametime * 4;
1425 p->alpha -= frametime * 128;
1426 // p->vel[2] += grav;
1431 if (cl.time > p->time2)
1433 p->time2 = cl.time + (rand() & 3) * 0.1;
1434 p->vel[0] = (rand()&63)-32 + p->vel2[0];
1435 p->vel[1] = (rand()&63)-32 + p->vel2[1];
1436 p->vel[2] = (rand()&63)-32 + p->vel2[2];
1440 p->scale -= frametime * 64;
1441 p->alpha -= frametime * 1024;
1443 if (p->alpha < 1 || p->scale < 1)
1447 p->scale += frametime * 4;
1448 p->alpha -= frametime * 64;
1450 if (p->alpha < 1 || p->scale < 1)
1454 p->alpha -= frametime * 256;
1460 p->alpha -= frametime * 512;
1465 case pt_fallfadespark:
1466 p->alpha -= frametime * 256;
1471 case pt_fallfadespark2:
1472 p->alpha -= frametime * 512;
1478 p->alpha -= frametime * 512;
1483 if (Mod_PointInLeaf(p->org, cl.worldmodel)->contents == CONTENTS_EMPTY)
1485 p->vel[2] += grav1 * 2;
1486 if (p->vel[2] >= 200)
1487 p->vel[2] = lhrandom(130, 200);
1488 if (cl.time > p->time2)
1490 p->time2 = cl.time + lhrandom(0, 0.5);
1491 p->vel[0] = lhrandom(-32,32);
1492 p->vel[1] = lhrandom(-32,32);
1494 p->alpha -= frametime * 64;