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_blob, pt_blob2, pt_smoke, pt_snow, pt_rain, pt_bloodcloud, pt_fallfadespark, pt_bubble, pt_fade, pt_smokecloud, pt_splash
31 typedef struct particle_s
41 float time2; // used for various things (snow fluttering, for example)
43 vec3_t vel2; // used for snow fluttering (base velocity, wind for instance)
46 int ramp1[8] = {0x6f, 0x6d, 0x6b, 0x69, 0x67, 0x65, 0x63, 0x61};
47 int ramp2[8] = {0x6f, 0x6e, 0x6d, 0x6c, 0x6b, 0x6a, 0x68, 0x66};
48 int ramp3[8] = {0x6d, 0x6b, 0x06, 0x05, 0x04, 0x03, 0x02, 0x01};
51 int smokeparticletexture[8];
52 int rainparticletexture;
53 int bubbleparticletexture;
55 particle_t *particles;
58 vec3_t r_pright, r_pup, r_ppn;
61 particle_t **freeparticles; // list used only in compacting particles array
63 // LordHavoc: reduced duplicate code, and allow particle allocation system independence
64 #define ALLOCPARTICLE \
65 if (numparticles >= r_numparticles)\
67 p = &particles[numparticles++];
69 cvar_t r_particles = {"r_particles", "1"};
70 cvar_t r_dynamicparticles = {"r_dynamicparticles", "0", TRUE};
72 byte shadebubble(float dx, float dy, vec3_t light)
76 if ((dx*dx+dy*dy) < 1) // it does hit the sphere
78 dz = 1 - (dx*dx+dy*dy);
81 normal[0] = dx;normal[1] = dy;normal[2] = dz;
82 VectorNormalize(normal);
83 dot = DotProduct(normal, light);
84 if (dot > 0.5) // interior reflection
86 else if (dot < -0.5) // exterior reflection
87 f += ((dot * -2) - 1);
89 normal[0] = dx;normal[1] = dy;normal[2] = -dz;
90 VectorNormalize(normal);
91 dot = DotProduct(normal, light);
92 if (dot > 0.5) // interior reflection
94 else if (dot < -0.5) // exterior reflection
95 f += ((dot * -2) - 1);
97 f += 16; // just to give it a haze so you can see the outline
105 void R_InitParticleTexture (void)
109 byte data[32][32][4], noise1[32][32], noise2[32][32];
112 for (x=0 ; x<32 ; x++)
114 for (y=0 ; y<32 ; y++)
116 data[y][x][0] = data[y][x][1] = data[y][x][2] = 255;
119 d = (255 - (dx*dx+dy*dy));
121 data[y][x][3] = (byte) d;
124 particletexture = GL_LoadTexture ("particletexture", 32, 32, &data[0][0][0], true, true, 4);
126 for (i = 0;i < 8;i++)
128 fractalnoise(&noise1[0][0], 32, 1);
129 fractalnoise(&noise2[0][0], 32, 8);
130 for (y = 0;y < 32;y++)
131 for (x = 0;x < 32;x++)
133 data[y][x][0] = data[y][x][1] = data[y][x][2] = (noise1[y][x] >> 1) + 128;
136 d = ((noise2[y][x] * 384) >> 8) - 128;
141 d = (d * (255 - (int) (dx*dx+dy*dy))) >> 8;
143 if (d > 255) d = 255;
144 data[y][x][3] = (byte) d;
150 smokeparticletexture[i] = GL_LoadTexture (va("smokeparticletexture%d", i), 32, 32, &data[0][0][0], true, true, 4);
153 light[0] = 1;light[1] = 1;light[2] = 1;
154 VectorNormalize(light);
155 for (x=0 ; x<32 ; x++)
157 for (y=0 ; y<32 ; y++)
159 data[y][x][0] = data[y][x][1] = data[y][x][2] = 255;
160 data[y][x][3] = shadebubble((x - 16) * (1.0 / 8.0), y < 24 ? (y - 24) * (1.0 / 24.0) : (y - 24) * (1.0 / 8.0), light);
163 rainparticletexture = GL_LoadTexture ("rainparticletexture", 32, 32, &data[0][0][0], true, true, 4);
165 light[0] = 1;light[1] = 1;light[2] = 1;
166 VectorNormalize(light);
167 for (x=0 ; x<32 ; x++)
169 for (y=0 ; y<32 ; y++)
171 data[y][x][0] = data[y][x][1] = data[y][x][2] = 255;
172 data[y][x][3] = shadebubble((x - 16) * (1.0 / 16.0), (y - 16) * (1.0 / 16.0), light);
175 bubbleparticletexture = GL_LoadTexture ("bubbleparticletexture", 32, 32, &data[0][0][0], true, true, 4);
180 particles = (particle_t *) malloc (r_numparticles * sizeof(particle_t));
181 freeparticles = (void *) malloc (r_numparticles * sizeof(particle_t *));
182 R_InitParticleTexture ();
185 void r_part_shutdown()
196 void R_Particles_Init (void)
200 i = COM_CheckParm ("-particles");
204 r_numparticles = (int)(atoi(com_argv[i+1]));
205 if (r_numparticles < ABSOLUTE_MIN_PARTICLES)
206 r_numparticles = ABSOLUTE_MIN_PARTICLES;
210 r_numparticles = MAX_PARTICLES;
213 Cvar_RegisterVariable (&r_particles);
214 Cvar_RegisterVariable (&r_dynamicparticles);
216 R_RegisterModule("R_Particles", r_part_start, r_part_shutdown);
219 #define particle(ptype, pcolor, ptex, pscale, palpha, ptime, px, py, pz, pvx, pvy, pvz)\
224 p->color = (pcolor);\
226 p->scale = (pscale);\
227 p->alpha = (palpha);\
228 p->die = cl.time + (ptime);\
236 #define particle2(ptype, pcolor, ptex, pscale, palpha, ptime, pbase, poscale, pvscale)\
241 p->color = (pcolor);\
243 p->scale = (pscale);\
244 p->alpha = (palpha);\
245 p->die = cl.time + (ptime);\
246 p->org[0] = lhrandom(-(poscale), (poscale)) + (pbase)[0];\
247 p->org[1] = lhrandom(-(poscale), (poscale)) + (pbase)[1];\
248 p->org[2] = lhrandom(-(poscale), (poscale)) + (pbase)[2];\
249 p->vel[0] = lhrandom(-(pvscale), (pvscale));\
250 p->vel[1] = lhrandom(-(pvscale), (pvscale));\
251 p->vel[2] = lhrandom(-(pvscale), (pvscale));\
253 #define particle3(ptype, pcolor, ptex, pscale, palpha, ptime, pbase, pscalex, pscaley, pscalez, pvscalex, pvscaley, pvscalez)\
258 p->color = (pcolor);\
260 p->scale = (pscale);\
261 p->alpha = (palpha);\
262 p->die = cl.time + (ptime);\
263 p->org[0] = lhrandom(-(pscalex), (pscalex)) + (pbase)[0];\
264 p->org[1] = lhrandom(-(pscaley), (pscaley)) + (pbase)[1];\
265 p->org[2] = lhrandom(-(pscalez), (pscalez)) + (pbase)[2];\
266 p->vel[0] = lhrandom(-(pvscalex), (pvscalex));\
267 p->vel[1] = lhrandom(-(pvscaley), (pvscaley));\
268 p->vel[2] = lhrandom(-(pvscalez), (pvscalez));\
271 void particle(int type, int color, int tex, float scale, int alpha, float time, float x, float y, float z, float vx, float vy, float vz)
281 p->die = cl.time + time;
289 void particle2(int type, int color, int tex, float scale, int alpha, float time, vec3_t base, float oscale, float vscale)
299 p->die = cl.time + time;
300 p->org[0] = lhrandom(-oscale, oscale) + base[0];
301 p->org[1] = lhrandom(-oscale, oscale) + base[1];
302 p->org[2] = lhrandom(-oscale, oscale) + base[2];
303 p->vel[0] = lhrandom(-vscale, vscale);
304 p->vel[1] = lhrandom(-vscale, vscale);
305 p->vel[2] = lhrandom(-vscale, vscale);
307 void particle3(int type, int color, int tex, float scale, int alpha, float time, vec3_t base, float scalex, float scaley, float scalez, float vscalex, float vscaley, float vscalez)
317 p->die = cl.time + time;
318 p->org[0] = lhrandom(-scalex, scalex) + base[0];
319 p->org[1] = lhrandom(-scaley, scaley) + base[1];
320 p->org[2] = lhrandom(-scalez, scalez) + base[2];
321 p->vel[0] = lhrandom(-vscalex, vscalex);
322 p->vel[1] = lhrandom(-vscaley, vscaley);
323 p->vel[2] = lhrandom(-vscalez, vscalez);
333 #define NUMVERTEXNORMALS 162
334 extern float r_avertexnormals[NUMVERTEXNORMALS][3];
335 vec3_t avelocities[NUMVERTEXNORMALS];
336 float beamlength = 16;
337 vec3_t avelocity = {23, 7, 3};
338 float partstep = 0.01;
339 float timescale = 0.01;
341 void R_EntityParticles (entity_t *ent)
346 float sp, sy, cp, cy;
349 if (!r_particles.value) return; // LordHavoc: particles are optional
354 if (!avelocities[0][0])
355 for (i=0 ; i<NUMVERTEXNORMALS*3 ; i++)
356 avelocities[0][i] = (rand()&255) * 0.01;
358 for (i=0 ; i<NUMVERTEXNORMALS ; i++)
360 angle = cl.time * avelocities[i][0];
363 angle = cl.time * avelocities[i][1];
371 particle(pt_static, 0x6f, particletexture, 2, 255, 0, ent->origin[0] + r_avertexnormals[i][0]*dist + forward[0]*beamlength, ent->origin[1] + r_avertexnormals[i][1]*dist + forward[1]*beamlength, ent->origin[2] + r_avertexnormals[i][2]*dist + forward[2]*beamlength, 0, 0, 0);
381 void R_ClearParticles (void)
384 // free_particles = &particles[0];
385 // active_particles = NULL;
387 // for (i=0 ;i<r_numparticles ; i++)
388 // particles[i].next = &particles[i+1];
389 // particles[r_numparticles-1].next = NULL;
395 void R_ReadPointFile_f (void)
401 char name[MAX_OSPATH];
403 sprintf (name,"maps/%s.pts", sv.name);
405 COM_FOpenFile (name, &f, false);
408 Con_Printf ("couldn't open %s\n", name);
412 Con_Printf ("Reading %s...\n", name);
416 r = fscanf (f,"%f %f %f\n", &org[0], &org[1], &org[2]);
421 if (numparticles >= r_numparticles)
423 Con_Printf ("Not enough free particles\n");
426 particle(pt_static, (-c)&15, particletexture, 2, 255, 99999, org[0], org[1], org[2], 0, 0, 0);
430 Con_Printf ("%i points read\n", c);
435 R_ParseParticleEffect
437 Parse an effect out of the server message
440 void R_ParseParticleEffect (void)
443 int i, count, msgcount, color;
445 for (i=0 ; i<3 ; i++)
446 org[i] = MSG_ReadCoord ();
447 for (i=0 ; i<3 ; i++)
448 dir[i] = MSG_ReadChar () * (1.0/16);
449 msgcount = MSG_ReadByte ();
450 color = MSG_ReadByte ();
457 R_RunParticleEffect (org, dir, color, count);
466 void R_ParticleExplosion (vec3_t org, int smoke)
469 if (!r_particles.value) return; // LordHavoc: particles are optional
471 particle(pt_smokecloud, (rand()&7) + 8, smokeparticletexture[rand()&7], 30, 160, 2, org[0], org[1], org[2], 0, 0, 0);
473 i = Mod_PointInLeaf(org, cl.worldmodel)->contents;
474 if (i == CONTENTS_SLIME || i == CONTENTS_WATER)
475 for (i=0 ; i<128 ; i++)
476 particle2(pt_bubble, (rand()&3) + 12, bubbleparticletexture, lhrandom(1, 2), 255, 2, org, 16, 96);
485 void R_ParticleExplosion2 (vec3_t org, int colorStart, int colorLength)
488 if (!r_particles.value) return; // LordHavoc: particles are optional
490 for (i = 0;i < 512;i++)
491 particle2(pt_fade, colorStart + (i % colorLength), particletexture, 1.5, 255, 0.3, org, 8, 192);
500 void R_BlobExplosion (vec3_t org)
503 if (!r_particles.value) return; // LordHavoc: particles are optional
505 for (i=0 ; i<512 ; i++)
506 particle3(pt_blob, 66+(rand()%6), particletexture, 2, 255, lhrandom(1, 1.4), org, 16, 16, 16, 4, 4, 128);
507 for (i=0 ; i<512 ; i++)
508 particle3(pt_blob2, 150+(rand()%6), particletexture, 2, 255, lhrandom(1, 1.4), org, 16, 16, 16, 4, 4, 128);
517 void R_RunParticleEffect (vec3_t org, vec3_t dir, int color, int count)
519 if (!r_particles.value) return; // LordHavoc: particles are optional
523 R_ParticleExplosion(org, false);
529 particle2(pt_fade, color + (rand()&7), particletexture, 6, (count & 7) * 16 + (rand()&15), 1, org, 8, 15);
534 particle2(pt_fade, color + (rand()&7), particletexture, 6, 128, 1, org, 8, 15);
537 // LordHavoc: added this for spawning sparks/dust (which have strong gravity)
543 void R_SparkShower (vec3_t org, vec3_t dir, int count)
545 if (!r_particles.value) return; // LordHavoc: particles are optional
548 particle(pt_smokecloud, 12+(rand()&3), smokeparticletexture[rand()&7], 8, 64, 99, org[0], org[1], org[2], 0, 0, 0);
551 particle2(pt_fallfadespark, ramp3[rand()%6], particletexture, 1, lhrandom(0, 255), 5, org, 4, 96);
554 void R_BloodPuff (vec3_t org)
556 if (!r_particles.value) return; // LordHavoc: particles are optional
558 particle(pt_bloodcloud, 68+(rand()&3), smokeparticletexture[rand()&7], 12, 128, 99, org[0], org[1], org[2], 0, 0, 0);
561 void R_BloodShower (vec3_t mins, vec3_t maxs, float velspeed, int count)
568 if (!r_particles.value) return; // LordHavoc: particles are optional
570 VectorSubtract(maxs, mins, diff);
571 center[0] = (mins[0] + maxs[0]) * 0.5;
572 center[1] = (mins[1] + maxs[1]) * 0.5;
573 center[2] = (mins[2] + maxs[2]) * 0.5;
574 // FIXME: change velspeed back to 2.0x after fixing mod
575 velscale[0] = velspeed * 0.5 / diff[0];
576 velscale[1] = velspeed * 0.5 / diff[1];
577 velscale[2] = velspeed * 0.5 / diff[2];
583 p->texnum = smokeparticletexture[rand()&7];
584 p->scale = lhrandom(6, 8);
585 p->alpha = 96 + (rand()&63);
586 p->die = cl.time + 2;
587 p->type = pt_bloodcloud;
588 p->color = (rand()&3)+68;
589 for (j=0 ; j<3 ; j++)
591 p->org[j] = diff[j] * (float) (rand()%1024) * (1.0 / 1024.0) + mins[j];
592 p->vel[j] = (p->org[j] - center[j]) * velscale[j];
597 void R_ParticleCube (vec3_t mins, vec3_t maxs, vec3_t dir, int count, int colorbase, int gravity, int randomvel)
603 if (!r_particles.value) return; // LordHavoc: particles are optional
604 if (maxs[0] <= mins[0]) {t = mins[0];mins[0] = maxs[0];maxs[0] = t;}
605 if (maxs[1] <= mins[1]) {t = mins[1];mins[1] = maxs[1];maxs[1] = t;}
606 if (maxs[2] <= mins[2]) {t = mins[2];mins[2] = maxs[2];maxs[2] = t;}
608 VectorSubtract(maxs, mins, diff);
614 p->texnum = particletexture;
617 p->die = cl.time + 1 + (rand()&15)*0.0625;
622 p->color = colorbase + (rand()&3);
623 for (j=0 ; j<3 ; j++)
625 p->org[j] = diff[j] * (float) (rand()&1023) * (1.0 / 1024.0) + mins[j];
627 p->vel[j] = dir[j] + (rand()%randomvel)-(randomvel*0.5);
634 void R_ParticleRain (vec3_t mins, vec3_t maxs, vec3_t dir, int count, int colorbase, int type)
642 if (!r_particles.value) return; // LordHavoc: particles are optional
643 if (maxs[0] <= mins[0]) {t = mins[0];mins[0] = maxs[0];maxs[0] = t;}
644 if (maxs[1] <= mins[1]) {t = mins[1];mins[1] = maxs[1];maxs[1] = t;}
645 if (maxs[2] <= mins[2]) {t = mins[2];mins[2] = maxs[2];maxs[2] = t;}
646 if (dir[2] < 0) // falling
648 t = (maxs[2] - mins[2]) / -dir[2];
653 t = (maxs[2] - mins[2]) / dir[2];
656 if (t < 0 || t > 2) // sanity check
660 VectorSubtract(maxs, mins, diff);
662 for (i=0 ; i<count ; i++)
666 vel[0] = dir[0] + (rand()&31) - 16;
667 vel[1] = dir[1] + (rand()&31) - 16;
668 vel[2] = dir[2] + (rand()&63) - 32;
669 org[0] = diff[0] * (float) (rand()&1023) * (1.0 / 1024.0) + mins[0];
670 org[1] = diff[1] * (float) (rand()&1023) * (1.0 / 1024.0) + mins[1];
678 p->texnum = particletexture;
684 p->texnum = rainparticletexture;
687 p->color = colorbase + (rand()&3);
688 VectorCopy(org, p->org);
689 VectorCopy(vel, p->vel);
690 VectorCopy(vel, p->vel2);
701 void R_LavaSplash (vec3_t org)
707 if (!r_particles.value) return; // LordHavoc: particles are optional
709 for (i=-128 ; i<128 ; i+=16)
710 for (j=-128 ; j<128 ; j+=16)
714 p->texnum = particletexture;
717 p->die = cl.time + 2 + (rand()&31) * 0.02;
718 p->color = 224 + (rand()&7);
721 dir[0] = j + (rand()&7);
722 dir[1] = i + (rand()&7);
725 p->org[0] = org[0] + dir[0];
726 p->org[1] = org[1] + dir[1];
727 p->org[2] = org[2] + (rand()&63);
729 VectorNormalize (dir);
730 vel = 50 + (rand()&63);
731 VectorScale (dir, vel, p->vel);
741 void R_TeleportSplash (vec3_t org)
745 if (!r_particles.value) return; // LordHavoc: particles are optional
747 for (i=-16 ; i<16 ; i+=8)
748 for (j=-16 ; j<16 ; j+=8)
749 for (k=-24 ; k<32 ; k+=8)
753 p->texnum = particletexture;
755 p->alpha = lhrandom(32,128);
756 p->die = cl.time + 5;
760 p->org[0] = org[0] + i + (rand()&7);
761 p->org[1] = org[1] + j + (rand()&7);
762 p->org[2] = org[2] + k + (rand()&7);
764 p->vel[0] = i*2 + (rand()%25) - 12;
765 p->vel[1] = j*2 + (rand()%25) - 12;
766 p->vel[2] = k*2 + (rand()%25) - 12 + 40;
770 void R_RocketTrail (vec3_t start, vec3_t end, int type, entity_t *ent)
773 float len, dec = 0, t, nt, speed;
774 int j, contents, bubbles;
776 static int tracercount;
777 if (!r_particles.value) return; // LordHavoc: particles are optional
781 if (ent->trail_leftover < 0)
782 ent->trail_leftover = 0;
783 t += ent->trail_leftover;
784 ent->trail_leftover -= (cl.time - cl.oldtime);
788 contents = Mod_PointInLeaf(start, cl.worldmodel)->contents;
789 if (contents == CONTENTS_SKY || contents == CONTENTS_LAVA)
792 VectorSubtract (end, start, vec);
793 len = VectorNormalizeLength (vec);
796 speed = len / (nt - t);
798 bubbles = (contents == CONTENTS_WATER || contents == CONTENTS_SLIME);
804 p->vel[0] = p->vel[1] = p->vel[2] = 0;
805 p->die = cl.time + 2;
809 case 0: // rocket trail
810 case 1: // grenade trail
814 p->texnum = bubbleparticletexture;
815 p->scale = lhrandom(1,2);
817 p->color = (rand()&3)+12;
819 p->die = cl.time + 2;
820 for (j=0 ; j<3 ; j++)
822 p->vel[j] = (rand()&31)-16;
823 p->org[j] = start[j] + ((rand()&3)-2);
829 p->texnum = smokeparticletexture[rand()&7];
830 p->scale = lhrandom(8, 12);
831 p->alpha = 64 + (rand()&31);
832 p->color = (rand()&3)+12;
834 p->die = cl.time + 10000;
835 VectorCopy(start, p->org);
840 case 1: // smoke smoke
842 p->texnum = smokeparticletexture;
843 p->scale = lhrandom(6,9);
845 if (r_smokecolor.value)
846 p->color = r_smokecolor.value;
848 p->color = (rand()&3)+12;
850 p->die = cl.time + 1;
851 VectorCopy(start, p->org);
856 case 4: // slight blood
858 p->texnum = smokeparticletexture[rand()&7];
859 p->scale = lhrandom(6, 8);
860 p->alpha = type == 4 ? 192 : 255;
861 p->color = (rand()&3)+68;
862 p->type = pt_bloodcloud;
863 p->die = cl.time + 9999;
864 for (j=0 ; j<3 ; j++)
866 p->vel[j] = (rand()&15)-8;
867 p->org[j] = start[j] + ((rand()&3)-2);
874 p->texnum = smokeparticletexture[rand()&7];
876 p->alpha = 64 + (rand()&31);
877 p->color = type == 3 ? 56 : 234;
879 p->die = cl.time + 10000;
880 VectorCopy(start, p->org);
883 case 6: // voor trail
884 dec = 0.05f; // sparse trail
885 p->texnum = smokeparticletexture[rand()&7];
886 p->scale = lhrandom(3, 5);
888 p->color = 9*16 + 8 + (rand()&3);
890 p->die = cl.time + 2;
891 for (j=0 ; j<3 ; j++)
893 p->vel[j] = (rand()&15)-8;
894 p->org[j] = start[j] + ((rand()&3)-2);
898 case 7: // Nehahra smoke tracer
900 p->texnum = smokeparticletexture[rand()&7];
901 p->scale = lhrandom(8, 12);
903 p->color = (rand()&3)+12;
905 p->die = cl.time + 10000;
906 for (j=0 ; j<3 ; j++)
907 p->org[j] = start[j] + ((rand()&3)-2);
913 VectorMA (start, dec, vec, start);
915 ent->trail_leftover = t - cl.time;
918 void R_RocketTrail2 (vec3_t start, vec3_t end, int color, entity_t *ent)
922 if (!r_particles.value) return; // LordHavoc: particles are optional
924 VectorSubtract (end, start, vec);
925 len = (int) (VectorNormalizeLength (vec) * (1.0f / 3.0f));
926 VectorScale(vec, 3, vec);
929 particle(pt_smoke, color, particletexture, 8, 192, 99, start[0], start[1], start[2], 0, 0, 0);
930 VectorAdd (start, vec, start);
935 extern qboolean lighthalf;
942 extern cvar_t sv_gravity;
943 void R_CompleteLightPoint (vec3_t color, vec3_t p);
945 void TraceLine (vec3_t start, vec3_t end, vec3_t impact);
947 void R_DrawParticles (void)
951 float gravity, dvel, frametime, scale, scale2, minparticledist;
953 vec3_t up, right, uprightangles, forward2, up2, right2, tempcolor, v;
954 int activeparticles, maxparticle, j, k;
956 // LordHavoc: early out condition
960 VectorScale (vup, 1.5, up);
961 VectorScale (vright, 1.5, right);
963 uprightangles[0] = 0;
964 uprightangles[1] = r_refdef.viewangles[1];
965 uprightangles[2] = 0;
966 AngleVectors (uprightangles, forward2, right2, up2);
968 frametime = cl.time - cl.oldtime;
969 gravity = frametime * sv_gravity.value;
970 dvel = 1+4*frametime;
972 minparticledist = DotProduct(r_refdef.vieworg, vpn) + 16.0f;
977 for (k = 0, p = particles;k < numparticles;k++, p++)
979 if (p->die < cl.time)
981 freeparticles[j++] = p;
987 // LordHavoc: only render if not too close
988 if (DotProduct(p->org, vpn) >= minparticledist)
990 color24 = (byte *) &d_8to24table[(int)p->color];
995 if (r_dynamicparticles.value)
997 R_CompleteLightPoint(tempcolor, p->org);
998 r = (r * (int) tempcolor[0]) >> 7;
999 g = (g * (int) tempcolor[1]) >> 7;
1000 b = (b * (int) tempcolor[2]) >> 7;
1002 transpolybegin(p->texnum, 0, p->texnum, TPOLYTYPE_ALPHA);
1003 scale = p->scale * -0.5;scale2 = p->scale * 0.5;
1004 if (p->texnum == rainparticletexture) // rain streak
1006 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);
1007 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);
1008 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);
1009 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);
1013 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);
1014 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);
1015 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);
1016 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);
1021 VectorCopy(p->org, p->oldorg);
1022 p->org[0] += p->vel[0]*frametime;
1023 p->org[1] += p->vel[1]*frametime;
1024 p->org[2] += p->vel[2]*frametime;
1032 for (i=0 ; i<3 ; i++)
1037 for (i=0 ; i<2 ; i++)
1042 p->vel[2] -= gravity;
1044 // LordHavoc: for smoke trails
1046 p->scale += frametime * 6;
1047 p->alpha -= frametime * 128;
1052 if (cl.time > p->time2)
1054 p->time2 = cl.time + (rand() & 3) * 0.1;
1055 p->vel[0] = (rand()&63)-32 + p->vel2[0];
1056 p->vel[1] = (rand()&63)-32 + p->vel2[1];
1057 p->vel[2] = (rand()&63)-32 + p->vel2[2];
1061 // if (Mod_PointInLeaf(p->org, cl.worldmodel)->contents != CONTENTS_EMPTY)
1066 p->scale += frametime * 4;
1067 p->alpha -= frametime * 64;
1068 if (p->alpha < 1 || p->scale < 1)
1071 case pt_fallfadespark:
1072 p->alpha -= frametime * 256;
1073 p->vel[2] -= gravity;
1078 p->alpha -= frametime * 512;
1083 a = Mod_PointInLeaf(p->org, cl.worldmodel)->contents;
1084 if (a != CONTENTS_WATER && a != CONTENTS_SLIME)
1086 p->texnum = smokeparticletexture[rand()&7];
1087 p->type = pt_splash;
1090 p->vel[0] = p->vel[1] = p->vel[2] = 0;
1091 p->die = cl.time + 1000;
1094 p->vel[2] += gravity * 0.25;
1095 p->vel[0] *= (1 - (frametime * 0.0625));
1096 p->vel[1] *= (1 - (frametime * 0.0625));
1097 p->vel[2] *= (1 - (frametime * 0.0625));
1098 if (cl.time > p->time2)
1100 p->time2 = cl.time + lhrandom(0, 0.5);
1101 p->vel[0] += lhrandom(-32,32);
1102 p->vel[1] += lhrandom(-32,32);
1103 p->vel[2] += lhrandom(-32,32);
1105 p->alpha -= frametime * 64;
1110 p->scale += frametime * 60;
1111 p->alpha -= frametime * 96;
1116 p->scale += frametime * 24;
1117 p->alpha -= frametime * 256;
1122 a = Mod_PointInLeaf(p->org, cl.worldmodel)->contents;
1123 if (a != CONTENTS_EMPTY && a != CONTENTS_SKY)
1125 if (a == CONTENTS_SOLID && Mod_PointInLeaf(p->oldorg, cl.worldmodel)->contents == CONTENTS_SOLID)
1126 break; // still in solid
1127 p->die = cl.time + 1000;
1131 case CONTENTS_SLIME:
1132 p->texnum = smokeparticletexture[rand()&7];
1133 p->type = pt_smokecloud;
1137 case CONTENTS_WATER:
1138 p->texnum = smokeparticletexture[rand()&7];
1139 p->type = pt_splash;
1142 p->vel[0] = p->vel[1] = p->vel[2] = 0;
1143 // p->texnum = bubbleparticletexture;
1144 // p->type = pt_bubble;
1145 // p->vel[2] *= 0.1;
1147 default: // CONTENTS_SOLID and any others
1148 TraceLine(p->oldorg, p->org, v);
1149 VectorCopy(v, p->org);
1150 p->texnum = smokeparticletexture[rand()&7];
1151 p->type = pt_splash;
1154 p->vel[0] = p->vel[1] = p->vel[2] = 0;
1155 p->die = cl.time + 1000;
1162 // fill in gaps to compact the array
1164 while (maxparticle >= activeparticles)
1166 *freeparticles[i++] = particles[maxparticle--];
1167 while (maxparticle >= activeparticles && particles[maxparticle].die < cl.time)
1170 numparticles = activeparticles;