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 time
24 #define ABSOLUTE_MIN_PARTICLES 512 // no fewer than this no matter what's on the command line
26 // LordHavoc: added dust, smoke, snow, bloodcloud, and many others
28 pt_static, pt_grav, pt_slowgrav, pt_fire, /*pt_explode, pt_explode2, */pt_blob, pt_blob2,
29 pt_dust, pt_smoke, pt_snow, pt_bulletpuff, pt_bloodcloud, pt_fadespark, pt_fadespark2,
30 pt_fallfadespark, pt_fallfadespark2, pt_bubble, pt_fade, pt_smokecloud
33 typedef struct particle_s
37 // struct particle_s *next;
42 // LordHavoc: added for improved particle effects
46 float time2; // used for various things (snow fluttering, for example)
47 vec3_t vel2; // used for snow fluttering (base velocity, wind for instance)
50 int ramp1[8] = {0x6f, 0x6d, 0x6b, 0x69, 0x67, 0x65, 0x63, 0x61};
51 int ramp2[8] = {0x6f, 0x6e, 0x6d, 0x6c, 0x6b, 0x6a, 0x68, 0x66};
52 int ramp3[8] = {0x6d, 0x6b, 6, 5, 4, 3};
55 int smokeparticletexture[8];
56 int flareparticletexture;
57 int rainparticletexture;
58 int bloodcloudparticletexture;
59 int bubbleparticletexture;
61 particle_t *particles;
64 vec3_t r_pright, r_pup, r_ppn;
67 particle_t **freeparticles; // list used only in compacting particles array
69 // LordHavoc: reduced duplicate code, and allow particle allocation system independence
70 #define ALLOCPARTICLE \
71 if (numparticles >= r_numparticles)\
73 p = &particles[numparticles++];
75 cvar_t r_particles = {"r_particles", "1"};
76 cvar_t r_dynamicparticles = {"r_dynamicparticles", "0", TRUE};
78 void fractalnoise(char *noise, int size);
79 void fractalnoise_zeroedge(char *noise, int size);
81 void R_InitParticleTexture (void)
84 float dx, dy, dz, f, dot;
85 byte data[32][32][4], noise1[32][32], noise2[32][32];
88 particletexture = texture_extension_number++;
89 glBindTexture(GL_TEXTURE_2D, particletexture);
91 for (x=0 ; x<32 ; x++)
93 for (y=0 ; y<32 ; y++)
95 data[y][x][0] = data[y][x][1] = data[y][x][2] = 255;
98 d = (255 - (dx*dx+dy*dy));
100 data[y][x][3] = (byte) d;
103 glTexImage2D (GL_TEXTURE_2D, 0, 4, 32, 32, 0, GL_RGBA, GL_UNSIGNED_BYTE, data);
105 glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
107 glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
108 glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
111 for (i = 0;i < 8;i++)
113 fractalnoise(&noise1[0][0], 32);
114 fractalnoise(&noise2[0][0], 32);
115 for (y = 0;y < 32;y++)
116 for (x = 0;x < 32;x++)
118 data[y][x][0] = data[y][x][1] = data[y][x][2] = (noise1[y][x] >> 1) + 128;
121 d = noise2[y][x] * 4 - 512;
126 d = (d * (255 - (int) (dx*dx+dy*dy))) >> 8;
128 if (d > 255) d = 255;
129 data[y][x][3] = (byte) d;
136 for (x=0 ; x<34 ; x+=2)
137 for (y=0 ; y<34 ; y+=2)
138 data[y][x][0] = data[y][x][1] = data[y][x][2] = (rand()%32)+192;
139 for (x=0 ; x<32 ; x+=2)
140 for (y=0 ; y<32 ; y+=2)
142 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;
143 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;
144 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;
146 for (x=0 ; x<32 ; x++)
148 for (y=0 ; y<32 ; y++)
150 //data[y][x][0] = data[y][x][1] = data[y][x][2] = (rand()%192)+32;
153 d = (255 - (dx*dx+dy*dy));
155 data[y][x][3] = (byte) d;
159 smokeparticletexture[i] = texture_extension_number++;
160 glBindTexture(GL_TEXTURE_2D, smokeparticletexture[i]);
161 glTexImage2D (GL_TEXTURE_2D, 0, 4, 32, 32, 0, GL_RGBA, GL_UNSIGNED_BYTE, data);
162 glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
163 glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
164 glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
167 fractalnoise(&noise1[0][0], 32);
168 fractalnoise(&noise2[0][0], 32);
169 for (y = 0;y < 32;y++)
170 for (x = 0;x < 32;x++)
172 data[y][x][0] = data[y][x][1] = data[y][x][2] = (noise1[y][x] >> 1) + 128;
175 d = (noise2[y][x] * (255 - (dx*dx+dy*dy))) * (1.0f / 255.0f);
177 if (d > 255) d = 255;
178 data[y][x][3] = (byte) d;
181 bloodcloudparticletexture = texture_extension_number++;
182 glBindTexture(GL_TEXTURE_2D, bloodcloudparticletexture);
183 glTexImage2D (GL_TEXTURE_2D, 0, 4, 32, 32, 0, GL_RGBA, GL_UNSIGNED_BYTE, data);
184 glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
185 glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
186 glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
188 flareparticletexture = texture_extension_number++;
189 glBindTexture(GL_TEXTURE_2D, flareparticletexture);
191 for (x=0 ; x<32 ; x++)
193 for (y=0 ; y<32 ; y++)
195 data[y][x][0] = data[y][x][1] = data[y][x][2] = 255;
198 d = 2048 / (dx*dx+dy*dy+1) - 32;
199 d = bound(0, d, 255);
200 data[y][x][3] = (byte) d;
203 glTexImage2D (GL_TEXTURE_2D, 0, 4, 32, 32, 0, GL_RGBA, GL_UNSIGNED_BYTE, data);
205 glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
207 glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
208 glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
210 rainparticletexture = texture_extension_number++;
211 glBindTexture(GL_TEXTURE_2D, rainparticletexture);
213 for (x=0 ; x<32 ; x++)
215 for (y=0 ; y<32 ; y++)
217 data[y][x][0] = data[y][x][1] = data[y][x][2] = 255;
218 if (y < 24) // stretch the upper half to make a raindrop
222 d = (255 - (dx*dx+dy*dy))/2;
228 d = (255 - (dx*dx+dy*dy))/2;
231 data[y][x][3] = (byte) d;
234 glTexImage2D (GL_TEXTURE_2D, 0, 4, 32, 32, 0, GL_RGBA, GL_UNSIGNED_BYTE, data);
236 glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
238 glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
239 glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
241 bubbleparticletexture = texture_extension_number++;
242 glBindTexture(GL_TEXTURE_2D, bubbleparticletexture);
244 light[0] = 1;light[1] = 1;light[2] = 1;
245 VectorNormalize(light);
246 for (x=0 ; x<32 ; x++)
248 for (y=0 ; y<32 ; y++)
250 data[y][x][0] = data[y][x][1] = data[y][x][2] = 255;
251 dx = x * (1.0 / 16.0) - 1.0;
252 dy = y * (1.0 / 16.0) - 1.0;
253 if (dx*dx+dy*dy < 1) // it does hit the sphere
255 dz = 1 - (dx*dx+dy*dy);
258 normal[0] = dx;normal[1] = dy;normal[2] = dz;
259 VectorNormalize(normal);
260 dot = DotProduct(normal, light);
261 if (dot > 0.5) // interior reflection
262 f += ((dot * 2) - 1);
263 else if (dot < -0.5) // exterior reflection
264 f += ((dot * -2) - 1);
266 normal[0] = dx;normal[1] = dy;normal[2] = -dz;
267 VectorNormalize(normal);
268 dot = DotProduct(normal, light);
269 if (dot > 0.5) // interior reflection
270 f += ((dot * 2) - 1);
271 else if (dot < -0.5) // exterior reflection
272 f += ((dot * -2) - 1);
274 f = bound(0, f, 255);
275 data[y][x][3] = (byte) f;
281 glTexImage2D (GL_TEXTURE_2D, 0, 4, 32, 32, 0, GL_RGBA, GL_UNSIGNED_BYTE, data);
283 glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
285 glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
286 glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
294 void R_InitParticles (void)
298 i = COM_CheckParm ("-particles");
302 r_numparticles = (int)(atoi(com_argv[i+1]));
303 if (r_numparticles < ABSOLUTE_MIN_PARTICLES)
304 r_numparticles = ABSOLUTE_MIN_PARTICLES;
308 r_numparticles = MAX_PARTICLES;
311 particles = (particle_t *) Hunk_AllocName (r_numparticles * sizeof(particle_t), "particles");
312 freeparticles = (void *) Hunk_AllocName (r_numparticles * sizeof(particle_t *), "particles");
314 Cvar_RegisterVariable (&r_particles);
315 Cvar_RegisterVariable (&r_dynamicparticles);
316 R_InitParticleTexture ();
325 #define NUMVERTEXNORMALS 162
326 extern float r_avertexnormals[NUMVERTEXNORMALS][3];
327 vec3_t avelocities[NUMVERTEXNORMALS];
328 float beamlength = 16;
329 vec3_t avelocity = {23, 7, 3};
330 float partstep = 0.01;
331 float timescale = 0.01;
333 void R_EntityParticles (entity_t *ent)
339 float sp, sy, cp, cy;
342 if (!r_particles.value) return; // LordHavoc: particles are optional
347 if (!avelocities[0][0])
349 for (i=0 ; i<NUMVERTEXNORMALS*3 ; i++)
350 avelocities[0][i] = (rand()&255) * 0.01;
354 for (i=0 ; i<NUMVERTEXNORMALS ; i++)
356 angle = cl.time * avelocities[i][0];
359 angle = cl.time * avelocities[i][1];
369 p->vel[0] = p->vel[1] = p->vel[2] = 0;
370 p->texnum = flareparticletexture;
375 p->type = pt_static; //explode;
377 p->org[0] = ent->origin[0] + r_avertexnormals[i][0]*dist + forward[0]*beamlength;
378 p->org[1] = ent->origin[1] + r_avertexnormals[i][1]*dist + forward[1]*beamlength;
379 p->org[2] = ent->origin[2] + r_avertexnormals[i][2]*dist + forward[2]*beamlength;
389 void R_ClearParticles (void)
392 // free_particles = &particles[0];
393 // active_particles = NULL;
395 // for (i=0 ;i<r_numparticles ; i++)
396 // particles[i].next = &particles[i+1];
397 // particles[r_numparticles-1].next = NULL;
403 void R_ReadPointFile_f (void)
410 char name[MAX_OSPATH];
412 sprintf (name,"maps/%s.pts", sv.name);
414 COM_FOpenFile (name, &f, false);
417 Con_Printf ("couldn't open %s\n", name);
421 Con_Printf ("Reading %s...\n", name);
425 r = fscanf (f,"%f %f %f\n", &org[0], &org[1], &org[2]);
430 // if (!free_particles)
431 if (numparticles >= r_numparticles)
433 Con_Printf ("Not enough free particles\n");
438 p->texnum = particletexture;
444 p->vel[0] = p->vel[1] = p->vel[2] = 0;
445 VectorCopy (org, p->org);
449 Con_Printf ("%i points read\n", c);
454 R_ParseParticleEffect
456 Parse an effect out of the server message
459 void R_ParseParticleEffect (void)
462 int i, count, msgcount, color;
464 for (i=0 ; i<3 ; i++)
465 org[i] = MSG_ReadCoord ();
466 for (i=0 ; i<3 ; i++)
467 dir[i] = MSG_ReadChar () * (1.0/16);
468 msgcount = MSG_ReadByte ();
469 color = MSG_ReadByte ();
476 R_RunParticleEffect (org, dir, color, count);
485 void R_ParticleExplosion (vec3_t org, int smoke)
489 if (!r_particles.value) return; // LordHavoc: particles are optional
492 for (i=0 ; i<1024 ; i++)
496 p->texnum = particletexture;
497 p->scale = lhrandom(1,3);
498 p->alpha = rand()&255;
499 p->die = cl.time + 5;
501 p->ramp = lhrandom(0, 4);
503 // p->type = pt_explode;
505 // p->type = pt_explode2;
506 p->color = ramp1[rand()&7];
507 p->type = pt_fallfadespark;
508 for (j=0 ; j<3 ; j++)
510 p->org[j] = org[j] + lhrandom(-8,8);
511 p->vel[j] = lhrandom(-192, 192);
517 i = Mod_PointInLeaf(org, cl.worldmodel)->contents;
518 if (i == CONTENTS_SLIME || i == CONTENTS_WATER)
520 for (i=0 ; i<32 ; i++)
524 p->texnum = bubbleparticletexture;
525 p->scale = lhrandom(1,2);
527 p->color = (rand()&3)+12;
529 p->die = cl.time + 2;
530 for (j=0 ; j<3 ; j++)
532 p->org[j] = org[j] + lhrandom(-16,16);
533 p->vel[j] = lhrandom(-16,16);
541 p->texnum = smokeparticletexture[rand()&7];
544 p->die = cl.time + 2;
545 p->type = pt_smokecloud;
546 p->color = (rand()&7) + 8;
547 for (j=0 ; j<3 ; j++)
561 void R_ParticleExplosion2 (vec3_t org, int colorStart, int colorLength)
566 if (!r_particles.value) return; // LordHavoc: particles are optional
568 for (i=0; i<512; i++)
572 p->texnum = particletexture;
575 p->die = cl.time + 0.3;
576 p->color = colorStart + (colorMod % colorLength);
580 for (j=0 ; j<3 ; j++)
582 p->org[j] = org[j] + ((rand()&15)-8);
583 p->vel[j] = lhrandom(-192, 192);
594 void R_BlobExplosion (vec3_t org)
598 if (!r_particles.value) return; // LordHavoc: particles are optional
600 for (i=0 ; i<1024 ; i++)
604 p->texnum = particletexture;
607 p->die = cl.time + 1 + (rand()&8)*0.05;
612 p->color = 66 + rand()%6;
613 for (j=0 ; j<3 ; j++)
615 p->org[j] = org[j] + ((rand()%32)-16);
616 p->vel[j] = lhrandom(-128, 128);
622 p->color = 150 + rand()%6;
623 for (j=0 ; j<3 ; j++)
625 p->org[j] = org[j] + ((rand()%32)-16);
626 p->vel[j] = lhrandom(-128, 128);
640 void R_RunParticleEffect (vec3_t org, vec3_t dir, int color, int count)
644 if (!r_particles.value) return; // LordHavoc: particles are optional
648 R_ParticleExplosion(org, false);
656 p->alpha = (count & 7) * 16 + (rand()&15);
665 p->texnum = particletexture;
667 p->die = cl.time + 1; //lhrandom(0.1, 0.5);
668 p->color = (color&~7) + (rand()&7);
669 p->type = pt_fade; //static; //slowgrav;
670 for (j=0 ; j<3 ; j++)
672 p->org[j] = org[j] + ((rand()&15)-8);
673 p->vel[j] = dir[j]*15;// + (rand()%300)-150;
678 // LordHavoc: added this for spawning sparks/dust (which have strong gravity)
685 void R_SparkShower (vec3_t org, vec3_t dir, int count, int type)
689 if (!r_particles.value) return; // LordHavoc: particles are optional
692 if (type == 0) // sparks
694 p->texnum = smokeparticletexture[rand()&7];
697 p->color = (rand()&3)+12;
698 p->type = pt_bulletpuff;
699 p->die = cl.time + 1;
700 VectorCopy(org, p->org);
701 p->vel[0] = p->vel[1] = p->vel[2] = 0;
705 p->texnum = smokeparticletexture[rand()&7];
708 p->color = (rand()&3)+68;
709 p->type = pt_bloodcloud;
710 p->die = cl.time + 0.5;
711 VectorCopy(org, p->org);
712 p->vel[0] = p->vel[1] = p->vel[2] = 0;
715 for (i=0 ; i<count ; i++)
719 p->texnum = flareparticletexture;
722 p->die = cl.time + 0.0625 * (rand()&15);
724 if (type == 0) // sparks
728 p->ramp = (rand()&3);
729 p->color = ramp1[(int)p->ramp];
730 for (j=0 ; j<3 ; j++)
732 p->org[j] = org[j] + ((rand()&7)-4);
733 p->vel[j] = dir[j] + (rand()%192)-96;
739 p->type = pt_fadespark2;
740 p->color = 67 + (rand()&3);
741 for (j=0 ; j<3 ; j++)
743 p->org[j] = org[j] + (rand()&7)-4;
744 p->vel[j] = dir[j] + (rand()&63)-32;
751 void R_BloodShower (vec3_t mins, vec3_t maxs, float velspeed, int count)
758 if (!r_particles.value) return; // LordHavoc: particles are optional
760 VectorSubtract(maxs, mins, diff);
761 center[0] = (mins[0] + maxs[0]) * 0.5;
762 center[1] = (mins[1] + maxs[1]) * 0.5;
763 center[2] = (mins[2] + maxs[2]) * 0.5;
764 velscale[0] = velspeed * 2.0 / diff[0];
765 velscale[1] = velspeed * 2.0 / diff[1];
766 velscale[2] = velspeed * 2.0 / diff[2];
768 for (i=0 ; i<count ; i++)
772 p->texnum = bloodcloudparticletexture;
774 p->alpha = 96 + (rand()&63);
775 p->die = cl.time + 2; //0.015625 * (rand()%128);
776 p->type = pt_fadespark;
777 p->color = (rand()&3)+68;
778 // p->color = 67 + (rand()&3);
779 for (j=0 ; j<3 ; j++)
781 p->org[j] = diff[j] * (float) (rand()%1024) * (1.0 / 1024.0) + mins[j];
782 p->vel[j] = (p->org[j] - center[j]) * velscale[j];
787 void R_ParticleCube (vec3_t mins, vec3_t maxs, vec3_t dir, int count, int colorbase, int gravity, int randomvel)
793 if (!r_particles.value) return; // LordHavoc: particles are optional
794 if (maxs[0] <= mins[0]) {t = mins[0];mins[0] = maxs[0];maxs[0] = t;}
795 if (maxs[1] <= mins[1]) {t = mins[1];mins[1] = maxs[1];maxs[1] = t;}
796 if (maxs[2] <= mins[2]) {t = mins[2];mins[2] = maxs[2];maxs[2] = t;}
798 VectorSubtract(maxs, mins, diff);
800 for (i=0 ; i<count ; i++)
804 p->texnum = flareparticletexture;
807 p->die = cl.time + 1 + (rand()&15)*0.0625;
812 p->color = colorbase + (rand()&3);
813 for (j=0 ; j<3 ; j++)
815 p->org[j] = diff[j] * (float) (rand()&1023) * (1.0 / 1024.0) + mins[j];
817 p->vel[j] = dir[j] + (rand()%randomvel)-(randomvel*0.5);
824 void R_ParticleRain (vec3_t mins, vec3_t maxs, vec3_t dir, int count, int colorbase, int type)
832 if (!r_particles.value) return; // LordHavoc: particles are optional
833 if (maxs[0] <= mins[0]) {t = mins[0];mins[0] = maxs[0];maxs[0] = t;}
834 if (maxs[1] <= mins[1]) {t = mins[1];mins[1] = maxs[1];maxs[1] = t;}
835 if (maxs[2] <= mins[2]) {t = mins[2];mins[2] = maxs[2];maxs[2] = t;}
836 if (dir[2] < 0) // falling
838 t = (maxs[2] - mins[2]) / -dir[2];
843 t = (maxs[2] - mins[2]) / dir[2];
846 if (t < 0 || t > 2) // sanity check
850 VectorSubtract(maxs, mins, diff);
852 for (i=0 ; i<count ; i++)
856 vel[0] = dir[0] + (rand()&31) - 16;
857 vel[1] = dir[1] + (rand()&31) - 16;
858 vel[2] = dir[2] + (rand()&63) - 32;
859 org[0] = diff[0] * (float) (rand()&1023) * (1.0 / 1024.0) + mins[0];
860 org[1] = diff[1] * (float) (rand()&1023) * (1.0 / 1024.0) + mins[1];
868 p->texnum = particletexture;
873 p->texnum = rainparticletexture;
876 p->color = colorbase + (rand()&3);
877 VectorCopy(org, p->org);
878 VectorCopy(vel, p->vel);
879 VectorCopy(vel, p->vel2);
890 void R_LavaSplash (vec3_t org)
896 if (!r_particles.value) return; // LordHavoc: particles are optional
898 for (i=-16 ; i<16 ; i+=2)
899 for (j=-16 ; j<16 ; j+=2)
900 for (k=0 ; k<1 ; k++)
904 p->texnum = flareparticletexture;
907 p->die = cl.time + 2 + (rand()&31) * 0.02;
908 p->color = 224 + (rand()&7);
909 p->type = pt_slowgrav;
911 dir[0] = j*8 + (rand()&7);
912 dir[1] = i*8 + (rand()&7);
915 p->org[0] = org[0] + dir[0];
916 p->org[1] = org[1] + dir[1];
917 p->org[2] = org[2] + (rand()&63);
919 VectorNormalize (dir);
920 vel = 50 + (rand()&63);
921 VectorScale (dir, vel, p->vel);
931 void R_TeleportSplash (vec3_t org)
936 if (!r_particles.value) return; // LordHavoc: particles are optional
939 for (i=-16 ; i<16 ; i+=4)
940 for (j=-16 ; j<16 ; j+=4)
941 for (k=-24 ; k<32 ; k+=4)
946 p->texnum = particletexture;
949 p->die = cl.time + 0.2 + (rand()&7) * 0.02;
950 p->color = 7 + (rand()&7);
951 p->type = pt_slowgrav;
957 p->org[0] = org[0] + i + (rand()&3);
958 p->org[1] = org[1] + j + (rand()&3);
959 p->org[2] = org[2] + k + (rand()&3);
961 VectorNormalize (dir);
962 vel = 50 + (rand()&63);
963 VectorScale (dir, vel, p->vel);
967 for (i=-24 ; i<24 ; i+=8)
968 for (j=-24 ; j<24 ; j+=8)
969 for (k=-24 ; k<32 ; k+=8)
973 p->texnum = flareparticletexture;
975 p->alpha = lhrandom(32,256);
976 p->die = cl.time + 5;
977 p->color = 254; //8 + (rand()&7);
978 p->type = pt_fadespark;
980 p->org[0] = org[0] + i + (rand()&7);
981 p->org[1] = org[1] + j + (rand()&7);
982 p->org[2] = org[2] + k + (rand()&7);
984 p->vel[0] = i*2 + (rand()%25) - 12;
985 p->vel[1] = j*2 + (rand()%25) - 12;
986 p->vel[2] = k*2 + (rand()%25) - 12 + 40;
990 void R_RocketTrail (vec3_t start, vec3_t end, int type, entity_t *ent)
993 float len, dec = 0, t, nt, speed;
994 int j, contents, bubbles;
996 static int tracercount;
997 if (!r_particles.value) return; // LordHavoc: particles are optional
1001 if (ent->trail_leftover < 0)
1002 ent->trail_leftover = 0;
1003 t += ent->trail_leftover;
1004 ent->trail_leftover -= (cl.time - cl.oldtime);
1008 contents = Mod_PointInLeaf(start, cl.worldmodel)->contents;
1009 if (contents == CONTENTS_SKY || contents == CONTENTS_LAVA)
1012 VectorSubtract (end, start, vec);
1013 len = VectorNormalizeLength (vec);
1016 speed = len / (nt - t);
1018 bubbles = (contents == CONTENTS_WATER || contents == CONTENTS_SLIME);
1024 p->vel[0] = p->vel[1] = p->vel[2] = 0;
1025 p->die = cl.time + 2;
1029 case 0: // rocket trail
1030 case 1: // grenade trail
1034 p->texnum = bubbleparticletexture;
1035 p->scale = lhrandom(1,2);
1037 p->color = (rand()&3)+12;
1038 p->type = pt_bubble;
1039 p->die = cl.time + 2;
1040 for (j=0 ; j<3 ; j++)
1042 p->vel[j] = (rand()&31)-16;
1043 p->org[j] = start[j] + ((rand()&3)-2);
1049 p->texnum = smokeparticletexture[rand()&7];
1050 p->scale = lhrandom(8, 12);
1051 p->alpha = 64 + (rand()&31);
1052 p->color = (rand()&3)+12;
1054 p->die = cl.time + 10000;
1055 VectorCopy(start, p->org);
1060 case 1: // smoke smoke
1062 p->texnum = smokeparticletexture;
1063 p->scale = lhrandom(6,9);
1065 if (r_smokecolor.value)
1066 p->color = r_smokecolor.value;
1068 p->color = (rand()&3)+12;
1070 p->die = cl.time + 1;
1071 VectorCopy(start, p->org);
1077 p->texnum = smokeparticletexture[rand()&7];
1078 p->scale = lhrandom(6, 8);
1080 p->color = (rand()&3)+68;
1081 p->type = pt_bloodcloud;
1082 p->die = cl.time + 9999;
1083 for (j=0 ; j<3 ; j++)
1085 p->vel[j] = (rand()&15)-8;
1086 p->org[j] = start[j] + ((rand()&3)-2);
1093 p->texnum = flareparticletexture;
1096 p->die = cl.time + 0.2; //5;
1097 p->type = pt_static;
1099 p->color = 52 + ((tracercount&4)<<1);
1101 p->color = 230 + ((tracercount&4)<<1);
1105 VectorCopy (start, p->org);
1106 if (tracercount & 1)
1108 p->vel[0] = 30*vec[1];
1109 p->vel[1] = 30*-vec[0];
1113 p->vel[0] = 30*-vec[1];
1114 p->vel[1] = 30*vec[0];
1118 case 4: // slight blood
1119 dec = 0.025f; // sparse trail
1120 p->texnum = smokeparticletexture[rand()&7];
1121 p->scale = lhrandom(6, 8);
1123 p->color = (rand()&3)+68;
1124 p->type = pt_fadespark2;
1125 p->die = cl.time + 9999;
1126 for (j=0 ; j<3 ; j++)
1128 p->vel[j] = (rand()&15)-8;
1129 p->org[j] = start[j] + ((rand()&3)-2);
1133 case 6: // voor trail
1134 dec = 0.05f; // sparse trail
1135 p->texnum = smokeparticletexture[rand()&7];
1136 p->scale = lhrandom(3, 5);
1138 p->color = 9*16 + 8 + (rand()&3);
1139 p->type = pt_fadespark2;
1140 p->die = cl.time + 2;
1141 for (j=0 ; j<3 ; j++)
1143 p->vel[j] = (rand()&15)-8;
1144 p->org[j] = start[j] + ((rand()&3)-2);
1148 case 7: // Nehahra smoke tracer
1150 p->texnum = smokeparticletexture[rand()&7];
1151 p->scale = lhrandom(8, 12);
1153 p->color = (rand()&3)+12;
1155 p->die = cl.time + 10000;
1156 for (j=0 ; j<3 ; j++)
1157 p->org[j] = start[j] + ((rand()&3)-2);
1163 VectorMA (start, dec, vec, start);
1165 ent->trail_leftover = t - cl.time;
1168 void R_RocketTrail2 (vec3_t start, vec3_t end, int color, entity_t *ent)
1173 if (!r_particles.value) return; // LordHavoc: particles are optional
1175 VectorSubtract (end, start, vec);
1176 len = VectorNormalizeLength (vec);
1183 p->vel[0] = p->vel[1] = p->vel[2] = 0;
1185 p->texnum = flareparticletexture;
1190 p->die = cl.time + 1;
1191 VectorCopy(start, p->org);
1192 // for (j=0 ; j<3 ; j++)
1193 // p->org[j] = start[j] + ((rand()&15)-8);
1195 VectorAdd (start, vec, start);
1200 extern qboolean lighthalf;
1207 extern cvar_t sv_gravity;
1208 void R_CompleteLightPoint (vec3_t color, vec3_t p);
1210 void R_DrawParticles (void)
1214 float grav, grav1, time1, time2, time3, dvel, frametime, scale, scale2, minparticledist;
1216 vec3_t up, right, uprightangles, forward2, up2, right2, tempcolor;
1217 int activeparticles, maxparticle, j, k;
1219 // LordHavoc: early out condition
1223 VectorScale (vup, 1.5, up);
1224 VectorScale (vright, 1.5, right);
1226 uprightangles[0] = 0;
1227 uprightangles[1] = r_refdef.viewangles[1];
1228 uprightangles[2] = 0;
1229 AngleVectors (uprightangles, forward2, right2, up2);
1231 frametime = cl.time - cl.oldtime;
1232 time3 = frametime * 15;
1233 time2 = frametime * 10; // 15;
1234 time1 = frametime * 5;
1235 grav = (grav1 = frametime * sv_gravity.value) * 0.05;
1236 dvel = 1+4*frametime;
1238 minparticledist = DotProduct(r_refdef.vieworg, vpn) + 16.0f;
1240 activeparticles = 0;
1243 for (k = 0, p = particles;k < numparticles;k++, p++)
1245 if (p->die < cl.time)
1247 freeparticles[j++] = p;
1253 // LordHavoc: only render if not too close
1254 if (DotProduct(p->org, vpn) >= minparticledist)
1256 color24 = (byte *) &d_8to24table[(int)p->color];
1267 if (r_dynamicparticles.value)
1269 R_CompleteLightPoint(tempcolor, p->org);
1270 r = (r * (int) tempcolor[0]) >> 7;
1271 g = (g * (int) tempcolor[1]) >> 7;
1272 b = (b * (int) tempcolor[2]) >> 7;
1274 transpolybegin(p->texnum, 0, p->texnum, TPOLYTYPE_ALPHA);
1275 scale = p->scale * -0.5;scale2 = p->scale * 0.5;
1276 if (p->texnum == rainparticletexture) // rain streak
1278 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);
1279 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);
1280 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);
1281 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);
1285 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);
1286 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);
1287 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);
1288 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);
1293 p->org[0] += p->vel[0]*frametime;
1294 p->org[1] += p->vel[1]*frametime;
1295 p->org[2] += p->vel[2]*frametime;
1306 p->color = ramp3[(int)p->ramp];
1316 p->color = ramp1[(int)p->ramp];
1317 // p->vel[2] -= grav1; // LordHavoc: apply full gravity to explosion sparks
1318 for (i=0 ; i<3 ; i++)
1320 // p->vel[2] -= grav;
1328 p->color = ramp2[(int)p->ramp];
1329 // p->vel[2] -= grav1; // LordHavoc: apply full gravity to explosion sparks
1330 for (i=0 ; i<3 ; i++)
1331 // p->vel[i] -= p->vel[i]*frametime;
1333 //// p->vel[2] -= grav;
1338 for (i=0 ; i<3 ; i++)
1339 p->vel[i] += p->vel[i]*dvel;
1344 for (i=0 ; i<2 ; i++)
1345 p->vel[i] -= p->vel[i]*dvel;
1355 // LordHavoc: gunshot spark showers
1358 p->scale -= frametime * 4;
1359 p->alpha -= frametime * 48;
1360 if (p->ramp >= 8 || p->scale < 1 || p->alpha < 1)
1363 p->color = ramp3[(int)p->ramp];
1366 // LordHavoc: for smoke trails
1368 p->scale += frametime * 6;
1369 p->alpha -= frametime * 128;
1370 // p->vel[2] += grav;
1375 if (cl.time > p->time2)
1377 p->time2 = cl.time + (rand() & 3) * 0.1;
1378 p->vel[0] = (rand()&63)-32 + p->vel2[0];
1379 p->vel[1] = (rand()&63)-32 + p->vel2[1];
1380 p->vel[2] = (rand()&63)-32 + p->vel2[2];
1384 p->scale -= frametime * 64;
1385 p->alpha -= frametime * 1024;
1387 if (p->alpha < 1 || p->scale < 1)
1391 if (Mod_PointInLeaf(p->org, cl.worldmodel)->contents != CONTENTS_EMPTY)
1396 p->scale += frametime * 4;
1397 p->alpha -= frametime * 64;
1399 if (p->alpha < 1 || p->scale < 1)
1403 p->alpha -= frametime * 256;
1409 p->alpha -= frametime * 512;
1414 case pt_fallfadespark:
1415 p->alpha -= frametime * 256;
1420 case pt_fallfadespark2:
1421 p->alpha -= frametime * 512;
1427 p->alpha -= frametime * 512;
1432 if (Mod_PointInLeaf(p->org, cl.worldmodel)->contents == CONTENTS_EMPTY)
1434 p->vel[2] += grav1 * 2;
1435 if (p->vel[2] >= 200)
1436 p->vel[2] = lhrandom(130, 200);
1437 if (cl.time > p->time2)
1439 p->time2 = cl.time + lhrandom(0, 0.5);
1440 p->vel[0] = lhrandom(-32,32);
1441 p->vel[1] = lhrandom(-32,32);
1443 p->alpha -= frametime * 64;
1448 p->scale += frametime * 60;
1449 p->alpha -= frametime * 96;
1455 // fill in gaps to compact the array
1457 while (maxparticle >= activeparticles)
1459 *freeparticles[i++] = particles[maxparticle--];
1460 while (maxparticle >= activeparticles && particles[maxparticle].die < cl.time)
1463 numparticles = activeparticles;