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_bloodcloud, pt_fallfadespark, pt_bubble, pt_fade, pt_smokecloud
31 typedef struct particle_s
38 // LordHavoc: added for improved particle effects
42 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 void R_InitParticleTexture (void)
75 float dx, dy, dz, f, dot;
76 byte data[32][32][4], noise1[32][32], noise2[32][32];
79 for (x=0 ; x<32 ; x++)
81 for (y=0 ; y<32 ; y++)
83 data[y][x][0] = data[y][x][1] = data[y][x][2] = 255;
86 d = (255 - (dx*dx+dy*dy));
88 data[y][x][3] = (byte) d;
91 particletexture = GL_LoadTexture ("particletexture", 32, 32, &data[0][0][0], true, true, 4);
95 fractalnoise(&noise1[0][0], 32);
96 fractalnoise(&noise2[0][0], 32);
97 for (y = 0;y < 32;y++)
98 for (x = 0;x < 32;x++)
100 data[y][x][0] = data[y][x][1] = data[y][x][2] = (noise1[y][x] >> 1) + 128;
103 d = noise2[y][x] * 4 - 512;
108 d = (d * (255 - (int) (dx*dx+dy*dy))) >> 8;
110 if (d > 255) d = 255;
111 data[y][x][3] = (byte) d;
117 smokeparticletexture[i] = GL_LoadTexture (va("smokeparticletexture%d", i), 32, 32, &data[0][0][0], true, true, 4);
120 for (x=0 ; x<32 ; x++)
122 for (y=0 ; y<32 ; y++)
124 data[y][x][0] = data[y][x][1] = data[y][x][2] = 255;
125 if (y < 24) // stretch the upper half to make a raindrop
129 d = (255 - (dx*dx+dy*dy))/2;
135 d = (255 - (dx*dx+dy*dy))/2;
138 data[y][x][3] = (byte) d;
141 rainparticletexture = GL_LoadTexture ("rainparticletexture", 32, 32, &data[0][0][0], true, true, 4);
143 light[0] = 1;light[1] = 1;light[2] = 1;
144 VectorNormalize(light);
145 for (x=0 ; x<32 ; x++)
147 for (y=0 ; y<32 ; y++)
149 data[y][x][0] = data[y][x][1] = data[y][x][2] = 255;
150 dx = x * (1.0 / 16.0) - 1.0;
151 dy = y * (1.0 / 16.0) - 1.0;
152 if (dx*dx+dy*dy < 1) // it does hit the sphere
154 dz = 1 - (dx*dx+dy*dy);
157 normal[0] = dx;normal[1] = dy;normal[2] = dz;
158 VectorNormalize(normal);
159 dot = DotProduct(normal, light);
160 if (dot > 0.5) // interior reflection
161 f += ((dot * 2) - 1);
162 else if (dot < -0.5) // exterior reflection
163 f += ((dot * -2) - 1);
165 normal[0] = dx;normal[1] = dy;normal[2] = -dz;
166 VectorNormalize(normal);
167 dot = DotProduct(normal, light);
168 if (dot > 0.5) // interior reflection
169 f += ((dot * 2) - 1);
170 else if (dot < -0.5) // exterior reflection
171 f += ((dot * -2) - 1);
173 f = bound(0, f, 255);
174 data[y][x][3] = (byte) f;
180 bubbleparticletexture = GL_LoadTexture ("bubbleparticletexture", 32, 32, &data[0][0][0], true, true, 4);
185 particles = (particle_t *) malloc (r_numparticles * sizeof(particle_t));
186 freeparticles = (void *) malloc (r_numparticles * sizeof(particle_t *));
187 R_InitParticleTexture ();
190 void r_part_shutdown()
201 void R_Particles_Init (void)
205 i = COM_CheckParm ("-particles");
209 r_numparticles = (int)(atoi(com_argv[i+1]));
210 if (r_numparticles < ABSOLUTE_MIN_PARTICLES)
211 r_numparticles = ABSOLUTE_MIN_PARTICLES;
215 r_numparticles = MAX_PARTICLES;
218 Cvar_RegisterVariable (&r_particles);
219 Cvar_RegisterVariable (&r_dynamicparticles);
221 R_RegisterModule("R_Particles", r_part_start, r_part_shutdown);
224 #define particle(ptype, pcolor, ptex, pscale, palpha, ptime, px, py, pz, pvx, pvy, pvz)\
229 p->color = (pcolor);\
231 p->scale = (pscale);\
232 p->alpha = (palpha);\
233 p->die = cl.time + (ptime);\
241 #define particle2(ptype, pcolor, ptex, pscale, palpha, ptime, pbase, poscale, pvscale)\
246 p->color = (pcolor);\
248 p->scale = (pscale);\
249 p->alpha = (palpha);\
250 p->die = cl.time + (ptime);\
251 p->org[0] = lhrandom(-(poscale), (poscale)) + (pbase)[0];\
252 p->org[1] = lhrandom(-(poscale), (poscale)) + (pbase)[1];\
253 p->org[2] = lhrandom(-(poscale), (poscale)) + (pbase)[2];\
254 p->vel[0] = lhrandom(-(pvscale), (pvscale));\
255 p->vel[1] = lhrandom(-(pvscale), (pvscale));\
256 p->vel[2] = lhrandom(-(pvscale), (pvscale));\
258 #define particle3(ptype, pcolor, ptex, pscale, palpha, ptime, pbase, pscalex, pscaley, pscalez, pvscalex, pvscaley, pvscalez)\
263 p->color = (pcolor);\
265 p->scale = (pscale);\
266 p->alpha = (palpha);\
267 p->die = cl.time + (ptime);\
268 p->org[0] = lhrandom(-(pscalex), (pscalex)) + (pbase)[0];\
269 p->org[1] = lhrandom(-(pscaley), (pscaley)) + (pbase)[1];\
270 p->org[2] = lhrandom(-(pscalez), (pscalez)) + (pbase)[2];\
271 p->vel[0] = lhrandom(-(pvscalex), (pvscalex));\
272 p->vel[1] = lhrandom(-(pvscaley), (pvscaley));\
273 p->vel[2] = lhrandom(-(pvscalez), (pvscalez));\
276 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)
286 p->die = cl.time + time;
294 void particle2(int type, int color, int tex, float scale, int alpha, float time, vec3_t base, float oscale, float vscale)
304 p->die = cl.time + time;
305 p->org[0] = lhrandom(-oscale, oscale) + base[0];
306 p->org[1] = lhrandom(-oscale, oscale) + base[1];
307 p->org[2] = lhrandom(-oscale, oscale) + base[2];
308 p->vel[0] = lhrandom(-vscale, vscale);
309 p->vel[1] = lhrandom(-vscale, vscale);
310 p->vel[2] = lhrandom(-vscale, vscale);
312 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)
322 p->die = cl.time + time;
323 p->org[0] = lhrandom(-scalex, scalex) + base[0];
324 p->org[1] = lhrandom(-scaley, scaley) + base[1];
325 p->org[2] = lhrandom(-scalez, scalez) + base[2];
326 p->vel[0] = lhrandom(-vscalex, vscalex);
327 p->vel[1] = lhrandom(-vscaley, vscaley);
328 p->vel[2] = lhrandom(-vscalez, vscalez);
338 #define NUMVERTEXNORMALS 162
339 extern float r_avertexnormals[NUMVERTEXNORMALS][3];
340 vec3_t avelocities[NUMVERTEXNORMALS];
341 float beamlength = 16;
342 vec3_t avelocity = {23, 7, 3};
343 float partstep = 0.01;
344 float timescale = 0.01;
346 void R_EntityParticles (entity_t *ent)
351 float sp, sy, cp, cy;
354 if (!r_particles.value) return; // LordHavoc: particles are optional
359 if (!avelocities[0][0])
360 for (i=0 ; i<NUMVERTEXNORMALS*3 ; i++)
361 avelocities[0][i] = (rand()&255) * 0.01;
363 for (i=0 ; i<NUMVERTEXNORMALS ; i++)
365 angle = cl.time * avelocities[i][0];
368 angle = cl.time * avelocities[i][1];
376 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);
386 void R_ClearParticles (void)
389 // free_particles = &particles[0];
390 // active_particles = NULL;
392 // for (i=0 ;i<r_numparticles ; i++)
393 // particles[i].next = &particles[i+1];
394 // particles[r_numparticles-1].next = NULL;
400 void R_ReadPointFile_f (void)
406 char name[MAX_OSPATH];
408 sprintf (name,"maps/%s.pts", sv.name);
410 COM_FOpenFile (name, &f, false);
413 Con_Printf ("couldn't open %s\n", name);
417 Con_Printf ("Reading %s...\n", name);
421 r = fscanf (f,"%f %f %f\n", &org[0], &org[1], &org[2]);
426 if (numparticles >= r_numparticles)
428 Con_Printf ("Not enough free particles\n");
431 particle(pt_static, (-c)&15, particletexture, 2, 255, 99999, org[0], org[1], org[2], 0, 0, 0);
435 Con_Printf ("%i points read\n", c);
440 R_ParseParticleEffect
442 Parse an effect out of the server message
445 void R_ParseParticleEffect (void)
448 int i, count, msgcount, color;
450 for (i=0 ; i<3 ; i++)
451 org[i] = MSG_ReadCoord ();
452 for (i=0 ; i<3 ; i++)
453 dir[i] = MSG_ReadChar () * (1.0/16);
454 msgcount = MSG_ReadByte ();
455 color = MSG_ReadByte ();
462 R_RunParticleEffect (org, dir, color, count);
471 void R_ParticleExplosion (vec3_t org, int smoke)
474 if (!r_particles.value) return; // LordHavoc: particles are optional
476 particle(pt_smokecloud, (rand()&7) + 8, smokeparticletexture[rand()&7], 30, 96, 2, org[0], org[1], org[2], 0, 0, 0);
478 i = Mod_PointInLeaf(org, cl.worldmodel)->contents;
479 if (i == CONTENTS_SLIME || i == CONTENTS_WATER)
480 for (i=0 ; i<32 ; i++)
481 particle2(pt_bubble, (rand()&3) + 12, bubbleparticletexture, lhrandom(1, 2), 255, 2, org, 16, 16);
490 void R_ParticleExplosion2 (vec3_t org, int colorStart, int colorLength)
493 if (!r_particles.value) return; // LordHavoc: particles are optional
495 for (i = 0;i < 512;i++)
496 particle2(pt_fade, colorStart + (i % colorLength), particletexture, 1.5, 255, 0.3, org, 8, 192);
505 void R_BlobExplosion (vec3_t org)
508 if (!r_particles.value) return; // LordHavoc: particles are optional
510 for (i=0 ; i<512 ; i++)
511 particle3(pt_blob, 66+(rand()%6), particletexture, 2, 255, lhrandom(1, 1.4), org, 16, 16, 16, 4, 4, 128);
512 for (i=0 ; i<512 ; i++)
513 particle3(pt_blob2, 150+(rand()%6), particletexture, 2, 255, lhrandom(1, 1.4), org, 16, 16, 16, 4, 4, 128);
522 void R_RunParticleEffect (vec3_t org, vec3_t dir, int color, int count)
524 if (!r_particles.value) return; // LordHavoc: particles are optional
528 R_ParticleExplosion(org, false);
534 particle2(pt_fade, color + (rand()&7), particletexture, 6, (count & 7) * 16 + (rand()&15), 1, org, 8, 15);
539 particle2(pt_fade, color + (rand()&7), particletexture, 6, 128, 1, org, 8, 15);
542 // LordHavoc: added this for spawning sparks/dust (which have strong gravity)
548 void R_SparkShower (vec3_t org, vec3_t dir, int count)
550 if (!r_particles.value) return; // LordHavoc: particles are optional
553 particle(pt_smokecloud, 12+(rand()&3), smokeparticletexture[rand()&7], 8, 64, 99, org[0], org[1], org[2], 0, 0, 0);
556 particle2(pt_fallfadespark, ramp3[rand()%6], particletexture, 1, lhrandom(0, 255), 5, org, 4, 96);
559 void R_BloodPuff (vec3_t org)
561 if (!r_particles.value) return; // LordHavoc: particles are optional
563 particle(pt_bloodcloud, 68+(rand()&3), smokeparticletexture[rand()&7], 12, 128, 99, org[0], org[1], org[2], 0, 0, 0);
566 void R_BloodShower (vec3_t mins, vec3_t maxs, float velspeed, int count)
573 if (!r_particles.value) return; // LordHavoc: particles are optional
575 VectorSubtract(maxs, mins, diff);
576 center[0] = (mins[0] + maxs[0]) * 0.5;
577 center[1] = (mins[1] + maxs[1]) * 0.5;
578 center[2] = (mins[2] + maxs[2]) * 0.5;
579 // FIXME: change velspeed back to 2.0x after fixing mod
580 velscale[0] = velspeed * 0.5 / diff[0];
581 velscale[1] = velspeed * 0.5 / diff[1];
582 velscale[2] = velspeed * 0.5 / diff[2];
588 p->texnum = smokeparticletexture[rand()&7];
589 p->scale = lhrandom(6, 8);
590 p->alpha = 96 + (rand()&63);
591 p->die = cl.time + 2;
592 p->type = pt_bloodcloud;
593 p->color = (rand()&3)+68;
594 for (j=0 ; j<3 ; j++)
596 p->org[j] = diff[j] * (float) (rand()%1024) * (1.0 / 1024.0) + mins[j];
597 p->vel[j] = (p->org[j] - center[j]) * velscale[j];
602 void R_ParticleCube (vec3_t mins, vec3_t maxs, vec3_t dir, int count, int colorbase, int gravity, int randomvel)
608 if (!r_particles.value) return; // LordHavoc: particles are optional
609 if (maxs[0] <= mins[0]) {t = mins[0];mins[0] = maxs[0];maxs[0] = t;}
610 if (maxs[1] <= mins[1]) {t = mins[1];mins[1] = maxs[1];maxs[1] = t;}
611 if (maxs[2] <= mins[2]) {t = mins[2];mins[2] = maxs[2];maxs[2] = t;}
613 VectorSubtract(maxs, mins, diff);
619 p->texnum = particletexture;
622 p->die = cl.time + 1 + (rand()&15)*0.0625;
627 p->color = colorbase + (rand()&3);
628 for (j=0 ; j<3 ; j++)
630 p->org[j] = diff[j] * (float) (rand()&1023) * (1.0 / 1024.0) + mins[j];
632 p->vel[j] = dir[j] + (rand()%randomvel)-(randomvel*0.5);
639 void R_ParticleRain (vec3_t mins, vec3_t maxs, vec3_t dir, int count, int colorbase, int type)
647 if (!r_particles.value) return; // LordHavoc: particles are optional
648 if (maxs[0] <= mins[0]) {t = mins[0];mins[0] = maxs[0];maxs[0] = t;}
649 if (maxs[1] <= mins[1]) {t = mins[1];mins[1] = maxs[1];maxs[1] = t;}
650 if (maxs[2] <= mins[2]) {t = mins[2];mins[2] = maxs[2];maxs[2] = t;}
651 if (dir[2] < 0) // falling
653 t = (maxs[2] - mins[2]) / -dir[2];
658 t = (maxs[2] - mins[2]) / dir[2];
661 if (t < 0 || t > 2) // sanity check
665 VectorSubtract(maxs, mins, diff);
667 for (i=0 ; i<count ; i++)
671 vel[0] = dir[0] + (rand()&31) - 16;
672 vel[1] = dir[1] + (rand()&31) - 16;
673 vel[2] = dir[2] + (rand()&63) - 32;
674 org[0] = diff[0] * (float) (rand()&1023) * (1.0 / 1024.0) + mins[0];
675 org[1] = diff[1] * (float) (rand()&1023) * (1.0 / 1024.0) + mins[1];
683 p->texnum = particletexture;
688 p->texnum = rainparticletexture;
691 p->color = colorbase + (rand()&3);
692 VectorCopy(org, p->org);
693 VectorCopy(vel, p->vel);
694 VectorCopy(vel, p->vel2);
705 void R_LavaSplash (vec3_t org)
711 if (!r_particles.value) return; // LordHavoc: particles are optional
713 for (i=-128 ; i<128 ; i+=16)
714 for (j=-128 ; j<128 ; j+=16)
718 p->texnum = particletexture;
721 p->die = cl.time + 2 + (rand()&31) * 0.02;
722 p->color = 224 + (rand()&7);
725 dir[0] = j + (rand()&7);
726 dir[1] = i + (rand()&7);
729 p->org[0] = org[0] + dir[0];
730 p->org[1] = org[1] + dir[1];
731 p->org[2] = org[2] + (rand()&63);
733 VectorNormalize (dir);
734 vel = 50 + (rand()&63);
735 VectorScale (dir, vel, p->vel);
745 void R_TeleportSplash (vec3_t org)
749 if (!r_particles.value) return; // LordHavoc: particles are optional
751 for (i=-16 ; i<16 ; i+=8)
752 for (j=-16 ; j<16 ; j+=8)
753 for (k=-24 ; k<32 ; k+=8)
757 p->texnum = particletexture;
759 p->alpha = lhrandom(32,128);
760 p->die = cl.time + 5;
764 p->org[0] = org[0] + i + (rand()&7);
765 p->org[1] = org[1] + j + (rand()&7);
766 p->org[2] = org[2] + k + (rand()&7);
768 p->vel[0] = i*2 + (rand()%25) - 12;
769 p->vel[1] = j*2 + (rand()%25) - 12;
770 p->vel[2] = k*2 + (rand()%25) - 12 + 40;
774 void R_RocketTrail (vec3_t start, vec3_t end, int type, entity_t *ent)
777 float len, dec = 0, t, nt, speed;
778 int j, contents, bubbles;
780 static int tracercount;
781 if (!r_particles.value) return; // LordHavoc: particles are optional
785 if (ent->trail_leftover < 0)
786 ent->trail_leftover = 0;
787 t += ent->trail_leftover;
788 ent->trail_leftover -= (cl.time - cl.oldtime);
792 contents = Mod_PointInLeaf(start, cl.worldmodel)->contents;
793 if (contents == CONTENTS_SKY || contents == CONTENTS_LAVA)
796 VectorSubtract (end, start, vec);
797 len = VectorNormalizeLength (vec);
800 speed = len / (nt - t);
802 bubbles = (contents == CONTENTS_WATER || contents == CONTENTS_SLIME);
808 p->vel[0] = p->vel[1] = p->vel[2] = 0;
809 p->die = cl.time + 2;
813 case 0: // rocket trail
814 case 1: // grenade trail
818 p->texnum = bubbleparticletexture;
819 p->scale = lhrandom(1,2);
821 p->color = (rand()&3)+12;
823 p->die = cl.time + 2;
824 for (j=0 ; j<3 ; j++)
826 p->vel[j] = (rand()&31)-16;
827 p->org[j] = start[j] + ((rand()&3)-2);
833 p->texnum = smokeparticletexture[rand()&7];
834 p->scale = lhrandom(8, 12);
835 p->alpha = 64 + (rand()&31);
836 p->color = (rand()&3)+12;
838 p->die = cl.time + 10000;
839 VectorCopy(start, p->org);
844 case 1: // smoke smoke
846 p->texnum = smokeparticletexture;
847 p->scale = lhrandom(6,9);
849 if (r_smokecolor.value)
850 p->color = r_smokecolor.value;
852 p->color = (rand()&3)+12;
854 p->die = cl.time + 1;
855 VectorCopy(start, p->org);
860 case 4: // slight blood
862 p->texnum = smokeparticletexture[rand()&7];
863 p->scale = lhrandom(6, 8);
864 p->alpha = type == 4 ? 192 : 255;
865 p->color = (rand()&3)+68;
866 p->type = pt_bloodcloud;
867 p->die = cl.time + 9999;
868 for (j=0 ; j<3 ; j++)
870 p->vel[j] = (rand()&15)-8;
871 p->org[j] = start[j] + ((rand()&3)-2);
878 p->texnum = smokeparticletexture[rand()&7];
880 p->alpha = 64 + (rand()&31);
881 p->color = type == 3 ? 56 : 234;
883 p->die = cl.time + 10000;
884 VectorCopy(start, p->org);
887 case 6: // voor trail
888 dec = 0.05f; // sparse trail
889 p->texnum = smokeparticletexture[rand()&7];
890 p->scale = lhrandom(3, 5);
892 p->color = 9*16 + 8 + (rand()&3);
894 p->die = cl.time + 2;
895 for (j=0 ; j<3 ; j++)
897 p->vel[j] = (rand()&15)-8;
898 p->org[j] = start[j] + ((rand()&3)-2);
902 case 7: // Nehahra smoke tracer
904 p->texnum = smokeparticletexture[rand()&7];
905 p->scale = lhrandom(8, 12);
907 p->color = (rand()&3)+12;
909 p->die = cl.time + 10000;
910 for (j=0 ; j<3 ; j++)
911 p->org[j] = start[j] + ((rand()&3)-2);
917 VectorMA (start, dec, vec, start);
919 ent->trail_leftover = t - cl.time;
922 void R_RocketTrail2 (vec3_t start, vec3_t end, int color, entity_t *ent)
926 if (!r_particles.value) return; // LordHavoc: particles are optional
928 VectorSubtract (end, start, vec);
929 len = (int) (VectorNormalizeLength (vec) * (1.0f / 3.0f));
930 VectorScale(vec, 3, vec);
933 particle(pt_smoke, color, particletexture, 8, 192, 99, start[0], start[1], start[2], 0, 0, 0);
934 VectorAdd (start, vec, start);
939 extern qboolean lighthalf;
946 extern cvar_t sv_gravity;
947 void R_CompleteLightPoint (vec3_t color, vec3_t p);
949 void R_DrawParticles (void)
953 float gravity, dvel, frametime, scale, scale2, minparticledist;
955 vec3_t up, right, uprightangles, forward2, up2, right2, tempcolor;
956 int activeparticles, maxparticle, j, k;
958 // LordHavoc: early out condition
962 VectorScale (vup, 1.5, up);
963 VectorScale (vright, 1.5, right);
965 uprightangles[0] = 0;
966 uprightangles[1] = r_refdef.viewangles[1];
967 uprightangles[2] = 0;
968 AngleVectors (uprightangles, forward2, right2, up2);
970 frametime = cl.time - cl.oldtime;
971 gravity = frametime * sv_gravity.value;
972 dvel = 1+4*frametime;
974 minparticledist = DotProduct(r_refdef.vieworg, vpn) + 16.0f;
979 for (k = 0, p = particles;k < numparticles;k++, p++)
981 if (p->die < cl.time)
983 freeparticles[j++] = p;
989 // LordHavoc: only render if not too close
990 if (DotProduct(p->org, vpn) >= minparticledist)
992 color24 = (byte *) &d_8to24table[(int)p->color];
997 if (r_dynamicparticles.value)
999 R_CompleteLightPoint(tempcolor, p->org);
1000 r = (r * (int) tempcolor[0]) >> 7;
1001 g = (g * (int) tempcolor[1]) >> 7;
1002 b = (b * (int) tempcolor[2]) >> 7;
1004 transpolybegin(p->texnum, 0, p->texnum, TPOLYTYPE_ALPHA);
1005 scale = p->scale * -0.5;scale2 = p->scale * 0.5;
1006 if (p->texnum == rainparticletexture) // rain streak
1008 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);
1009 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);
1010 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);
1011 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);
1015 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);
1016 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);
1017 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);
1018 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);
1023 p->org[0] += p->vel[0]*frametime;
1024 p->org[1] += p->vel[1]*frametime;
1025 p->org[2] += p->vel[2]*frametime;
1033 for (i=0 ; i<3 ; i++)
1038 for (i=0 ; i<2 ; i++)
1043 p->vel[2] -= gravity;
1045 // LordHavoc: for smoke trails
1047 p->scale += frametime * 6;
1048 p->alpha -= frametime * 128;
1053 if (cl.time > p->time2)
1055 p->time2 = cl.time + (rand() & 3) * 0.1;
1056 p->vel[0] = (rand()&63)-32 + p->vel2[0];
1057 p->vel[1] = (rand()&63)-32 + p->vel2[1];
1058 p->vel[2] = (rand()&63)-32 + p->vel2[2];
1062 if (Mod_PointInLeaf(p->org, cl.worldmodel)->contents != CONTENTS_EMPTY)
1067 p->scale += frametime * 4;
1068 p->alpha -= frametime * 64;
1069 if (p->alpha < 1 || p->scale < 1)
1072 case pt_fallfadespark:
1073 p->alpha -= frametime * 256;
1074 p->vel[2] -= gravity;
1079 p->alpha -= frametime * 512;
1084 a = Mod_PointInLeaf(p->org, cl.worldmodel)->contents;
1085 if (a != CONTENTS_WATER && a != CONTENTS_SLIME)
1087 p->vel[2] += gravity * 0.25;
1088 p->vel[0] *= (1 - (frametime * 0.0625));
1089 p->vel[1] *= (1 - (frametime * 0.0625));
1090 p->vel[2] *= (1 - (frametime * 0.0625));
1091 if (cl.time > p->time2)
1093 p->time2 = cl.time + lhrandom(0, 0.5);
1094 p->vel[0] += lhrandom(-32,32);
1095 p->vel[1] += lhrandom(-32,32);
1096 p->vel[2] += lhrandom(-32,32);
1098 p->alpha -= frametime * 64;
1103 p->scale += frametime * 60;
1104 p->alpha -= frametime * 96;
1110 // fill in gaps to compact the array
1112 while (maxparticle >= activeparticles)
1114 *freeparticles[i++] = particles[maxparticle--];
1115 while (maxparticle >= activeparticles && particles[maxparticle].die < cl.time)
1118 numparticles = activeparticles;