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 16384 // 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
28 pt_static, pt_grav, pt_blob, pt_blob2, pt_bulletsmoke, pt_smoke, pt_snow, pt_rain, pt_spark, pt_bubble, pt_fade, pt_steam, pt_splash, pt_splashpuff, pt_flame, pt_blood, pt_oneframe, pt_lavasplash, pt_raindropsplash, pt_underwaterspark, pt_explosionsplash
32 typedef struct particle_s
35 int orientation; // typically PARTICLE_BILLBOARD
44 float time2; // used for various things (snow fluttering, for example)
45 float bounce; // how much bounce-back from a surface the particle hits (0 = no physics, 1 = stop and slide, 2 = keep bouncing forever, 1.5 is typical)
47 vec3_t vel2; // used for snow fluttering (base velocity, wind for instance)
48 float friction; // how much air friction affects this object (objects with a low mass/size ratio tend to get more air friction)
49 float pressure; // if non-zero, apply pressure to other particles
50 int dynlight; // if set the particle will be dynamically lit (if cl_dynamicparticles is on), used for smoke and blood
55 static int particlepalette[256] =
57 0x000000,0x0f0f0f,0x1f1f1f,0x2f2f2f,0x3f3f3f,0x4b4b4b,0x5b5b5b,0x6b6b6b,
58 0x7b7b7b,0x8b8b8b,0x9b9b9b,0xababab,0xbbbbbb,0xcbcbcb,0xdbdbdb,0xebebeb,
59 0x0f0b07,0x170f0b,0x1f170b,0x271b0f,0x2f2313,0x372b17,0x3f2f17,0x4b371b,
60 0x533b1b,0x5b431f,0x634b1f,0x6b531f,0x73571f,0x7b5f23,0x836723,0x8f6f23,
61 0x0b0b0f,0x13131b,0x1b1b27,0x272733,0x2f2f3f,0x37374b,0x3f3f57,0x474767,
62 0x4f4f73,0x5b5b7f,0x63638b,0x6b6b97,0x7373a3,0x7b7baf,0x8383bb,0x8b8bcb,
63 0x000000,0x070700,0x0b0b00,0x131300,0x1b1b00,0x232300,0x2b2b07,0x2f2f07,
64 0x373707,0x3f3f07,0x474707,0x4b4b0b,0x53530b,0x5b5b0b,0x63630b,0x6b6b0f,
65 0x070000,0x0f0000,0x170000,0x1f0000,0x270000,0x2f0000,0x370000,0x3f0000,
66 0x470000,0x4f0000,0x570000,0x5f0000,0x670000,0x6f0000,0x770000,0x7f0000,
67 0x131300,0x1b1b00,0x232300,0x2f2b00,0x372f00,0x433700,0x4b3b07,0x574307,
68 0x5f4707,0x6b4b0b,0x77530f,0x835713,0x8b5b13,0x975f1b,0xa3631f,0xaf6723,
69 0x231307,0x2f170b,0x3b1f0f,0x4b2313,0x572b17,0x632f1f,0x733723,0x7f3b2b,
70 0x8f4333,0x9f4f33,0xaf632f,0xbf772f,0xcf8f2b,0xdfab27,0xefcb1f,0xfff31b,
71 0x0b0700,0x1b1300,0x2b230f,0x372b13,0x47331b,0x533723,0x633f2b,0x6f4733,
72 0x7f533f,0x8b5f47,0x9b6b53,0xa77b5f,0xb7876b,0xc3937b,0xd3a38b,0xe3b397,
73 0xab8ba3,0x9f7f97,0x937387,0x8b677b,0x7f5b6f,0x775363,0x6b4b57,0x5f3f4b,
74 0x573743,0x4b2f37,0x43272f,0x371f23,0x2b171b,0x231313,0x170b0b,0x0f0707,
75 0xbb739f,0xaf6b8f,0xa35f83,0x975777,0x8b4f6b,0x7f4b5f,0x734353,0x6b3b4b,
76 0x5f333f,0x532b37,0x47232b,0x3b1f23,0x2f171b,0x231313,0x170b0b,0x0f0707,
77 0xdbc3bb,0xcbb3a7,0xbfa39b,0xaf978b,0xa3877b,0x977b6f,0x876f5f,0x7b6353,
78 0x6b5747,0x5f4b3b,0x533f33,0x433327,0x372b1f,0x271f17,0x1b130f,0x0f0b07,
79 0x6f837b,0x677b6f,0x5f7367,0x576b5f,0x4f6357,0x475b4f,0x3f5347,0x374b3f,
80 0x2f4337,0x2b3b2f,0x233327,0x1f2b1f,0x172317,0x0f1b13,0x0b130b,0x070b07,
81 0xfff31b,0xefdf17,0xdbcb13,0xcbb70f,0xbba70f,0xab970b,0x9b8307,0x8b7307,
82 0x7b6307,0x6b5300,0x5b4700,0x4b3700,0x3b2b00,0x2b1f00,0x1b0f00,0x0b0700,
83 0x0000ff,0x0b0bef,0x1313df,0x1b1bcf,0x2323bf,0x2b2baf,0x2f2f9f,0x2f2f8f,
84 0x2f2f7f,0x2f2f6f,0x2f2f5f,0x2b2b4f,0x23233f,0x1b1b2f,0x13131f,0x0b0b0f,
85 0x2b0000,0x3b0000,0x4b0700,0x5f0700,0x6f0f00,0x7f1707,0x931f07,0xa3270b,
86 0xb7330f,0xc34b1b,0xcf632b,0xdb7f3b,0xe3974f,0xe7ab5f,0xefbf77,0xf7d38b,
87 0xa77b3b,0xb79b37,0xc7c337,0xe7e357,0x7fbfff,0xabe7ff,0xd7ffff,0x670000,
88 0x8b0000,0xb30000,0xd70000,0xff0000,0xfff393,0xfff7c7,0xffffff,0x9f5b53
91 static int explosparkramp[8] = {0x4b0700, 0x6f0f00, 0x931f07, 0xb7330f, 0xcf632b, 0xe3974f, 0xffe7b5, 0xffffff};
92 //static int explounderwatersparkramp[8] = {0x00074b, 0x000f6f, 0x071f93, 0x0f33b7, 0x2b63cf, 0x4f97e3, 0xb5e7ff, 0xffffff};
94 // these must match r_part.c's textures
95 static const int tex_smoke[8] = {0, 1, 2, 3, 4, 5, 6, 7};
96 static const int tex_rainsplash[16] = {8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23};
97 static const int tex_particle = 24;
98 static const int tex_rain = 25;
99 static const int tex_bubble = 26;
100 static const int tex_rocketglow = 27;
102 static int cl_maxparticles;
103 static int cl_numparticles;
104 static particle_t *particles;
105 static particle_t **freeparticles; // list used only in compacting particles array
106 static renderparticle_t *cl_renderparticles;
108 static cvar_t cl_particles = {CVAR_SAVE, "cl_particles", "1"};
109 static cvar_t cl_particles_size = {CVAR_SAVE, "cl_particles_size", "1"};
110 static cvar_t cl_particles_bloodshowers = {CVAR_SAVE, "cl_particles_bloodshowers", "1"};
111 static cvar_t cl_particles_blood = {CVAR_SAVE, "cl_particles_blood", "1"};
112 static cvar_t cl_particles_blood_size_min = {CVAR_SAVE, "cl_particles_blood_size_min", "3"};
113 static cvar_t cl_particles_blood_size_max = {CVAR_SAVE, "cl_particles_blood_size_max", "15"};
114 static cvar_t cl_particles_blood_alpha = {CVAR_SAVE, "cl_particles_blood_alpha", "1"};
115 static cvar_t cl_particles_smoke = {CVAR_SAVE, "cl_particles_smoke", "1"};
116 static cvar_t cl_particles_sparks = {CVAR_SAVE, "cl_particles_sparks", "1"};
117 static cvar_t cl_particles_bubbles = {CVAR_SAVE, "cl_particles_bubbles", "1"};
118 static cvar_t cl_particles_explosions = {CVAR_SAVE, "cl_particles_explosions", "0"};
120 static mempool_t *cl_part_mempool;
122 void CL_Particles_Clear(void)
132 void CL_ReadPointFile_f (void);
133 void CL_Particles_Init (void)
137 i = COM_CheckParm ("-particles");
141 cl_maxparticles = (int)(atoi(com_argv[i+1]));
142 if (cl_maxparticles < ABSOLUTE_MIN_PARTICLES)
143 cl_maxparticles = ABSOLUTE_MIN_PARTICLES;
146 cl_maxparticles = MAX_PARTICLES;
148 Cmd_AddCommand ("pointfile", CL_ReadPointFile_f);
150 Cvar_RegisterVariable (&cl_particles);
151 Cvar_RegisterVariable (&cl_particles_size);
152 Cvar_RegisterVariable (&cl_particles_bloodshowers);
153 Cvar_RegisterVariable (&cl_particles_blood);
154 Cvar_RegisterVariable (&cl_particles_blood_size_min);
155 Cvar_RegisterVariable (&cl_particles_blood_size_max);
156 Cvar_RegisterVariable (&cl_particles_blood_alpha);
157 Cvar_RegisterVariable (&cl_particles_smoke);
158 Cvar_RegisterVariable (&cl_particles_sparks);
159 Cvar_RegisterVariable (&cl_particles_bubbles);
160 Cvar_RegisterVariable (&cl_particles_explosions);
162 cl_part_mempool = Mem_AllocPool("CL_Part");
163 particles = (particle_t *) Mem_Alloc(cl_part_mempool, cl_maxparticles * sizeof(particle_t));
164 freeparticles = (void *) Mem_Alloc(cl_part_mempool, cl_maxparticles * sizeof(particle_t *));
167 // FIXME: r_refdef stuff should be allocated somewhere else?
168 r_refdef.particles = cl_renderparticles = Mem_Alloc(cl_refdef_mempool, cl_maxparticles * sizeof(renderparticle_t));
171 #define particle(ptype, porientation, pcolor, ptex, plight, padditive, pscalex, pscaley, palpha, ptime, pbounce, px, py, pz, pvx, pvy, pvz, ptime2, pvx2, pvy2, pvz2, pfriction, ppressure)\
175 if (cl_numparticles >= cl_maxparticles)\
177 part = &particles[cl_numparticles++];\
178 part->type = (ptype);\
179 tempcolor = (pcolor);\
180 part->color[0] = ((tempcolor) >> 16) & 0xFF;\
181 part->color[1] = ((tempcolor) >> 8) & 0xFF;\
182 part->color[2] = (tempcolor) & 0xFF;\
183 part->color[3] = 0xFF;\
185 part->orientation = (porientation);\
186 part->dynlight = (plight);\
187 part->additive = (padditive);\
188 part->scalex = (pscalex);\
189 part->scaley = (pscaley);\
190 part->alpha = (palpha);\
191 part->die = cl.time + (ptime);\
192 part->bounce = (pbounce);\
193 part->org[0] = (px);\
194 part->org[1] = (py);\
195 part->org[2] = (pz);\
196 part->vel[0] = (pvx);\
197 part->vel[1] = (pvy);\
198 part->vel[2] = (pvz);\
199 part->time2 = (ptime2);\
200 part->vel2[0] = (pvx2);\
201 part->vel2[1] = (pvy2);\
202 part->vel2[2] = (pvz2);\
203 part->friction = (pfriction);\
204 part->pressure = (ppressure);\
212 void CL_EntityParticles (entity_t *ent)
216 float sp, sy, cp, cy;
220 static vec3_t avelocities[NUMVERTEXNORMALS];
221 if (!cl_particles.integer) return;
226 if (!avelocities[0][0])
227 for (i=0 ; i<NUMVERTEXNORMALS*3 ; i++)
228 avelocities[0][i] = (rand()&255) * 0.01;
230 for (i=0 ; i<NUMVERTEXNORMALS ; i++)
232 angle = cl.time * avelocities[i][0];
235 angle = cl.time * avelocities[i][1];
243 particle(pt_oneframe, PARTICLE_BILLBOARD, particlepalette[0x6f], tex_particle, false, false, 2, 2, 255, 9999, 0, ent->render.origin[0] + m_bytenormals[i][0]*dist + forward[0]*beamlength, ent->render.origin[1] + m_bytenormals[i][1]*dist + forward[1]*beamlength, ent->render.origin[2] + m_bytenormals[i][2]*dist + forward[2]*beamlength, 0, 0, 0, 0, 0, 0, 0, 0, 0);
248 void CL_ReadPointFile_f (void)
252 char *pointfile, *pointfilepos, *t, tchar;
254 pointfile = COM_LoadFile(va("maps/%s.pts", sv.name), true);
257 Con_Printf ("couldn't open %s.pts\n", sv.name);
261 Con_Printf ("Reading %s.pts...\n", sv.name);
263 pointfilepos = pointfile;
264 while (*pointfilepos)
266 while (*pointfilepos == '\n' || *pointfilepos == '\r')
271 while (*t && *t != '\n' && *t != '\r')
275 r = sscanf (pointfilepos,"%f %f %f", &org[0], &org[1], &org[2]);
282 if (cl_numparticles >= cl_maxparticles)
284 Con_Printf ("Not enough free particles\n");
287 particle(pt_static, PARTICLE_BILLBOARD, particlepalette[(-c)&15], tex_particle, false, false, 2, 2, 255, 99999, 0, org[0], org[1], org[2], 0, 0, 0, 0, 0, 0, 0, 0, 0);
291 Con_Printf ("%i points read\n", c);
296 CL_ParseParticleEffect
298 Parse an effect out of the server message
301 void CL_ParseParticleEffect (void)
304 int i, count, msgcount, color;
306 for (i=0 ; i<3 ; i++)
307 org[i] = MSG_ReadCoord ();
308 for (i=0 ; i<3 ; i++)
309 dir[i] = MSG_ReadChar () * (1.0/16);
310 msgcount = MSG_ReadByte ();
311 color = MSG_ReadByte ();
318 CL_RunParticleEffect (org, dir, color, count);
327 void CL_ParticleExplosion (vec3_t org, int smoke)
329 R_Stain(org, 96, 80, 80, 80, 128, 176, 176, 176, 128);
330 if (cl_particles.integer && cl_particles_explosions.integer)
335 qbyte noise1[32*32], noise2[32*32];
337 VectorClear(end); // hush MSVC
338 i = Mod_PointInLeaf(org, cl.worldmodel)->contents;
339 if (i == CONTENTS_SLIME || i == CONTENTS_WATER)
341 for (i = 0;i < 128;i++)
342 particle(pt_bubble, PARTICLE_BILLBOARD, 0xFFFFFF, tex_bubble, false, true, 2, 2, 255, 9999, 1.5, org[0] + lhrandom(-16, 16), org[1] + lhrandom(-16, 16), org[2] + lhrandom(-16, 16), lhrandom(-96, 96), lhrandom(-96, 96), lhrandom(-96, 96), 0, 0, 0, 0, 0, 0);
344 ang[2] = lhrandom(0, 360);
345 fractalnoisequick(noise1, 32, 4);
346 fractalnoisequick(noise2, 32, 8);
347 for (i = 0;i < 32;i++)
349 for (j = 0;j < 32;j++)
352 VectorMA(org, 16, v, v);
353 TraceLine(org, v, end, NULL, 0, true);
354 ang[0] = (j + 0.5f) * (360.0f / 32.0f);
355 ang[1] = (i + 0.5f) * (360.0f / 32.0f);
356 AngleVectors(ang, v, NULL, NULL);
357 f = noise1[j*32+i] * 1.5f;
358 VectorScale(v, f, v);
359 particle(pt_underwaterspark, PARTICLE_BILLBOARD, noise2[j*32+i] * 0x010101, tex_smoke[rand()&7], false, true, 10, 10, lhrandom(128, 255), 9999, 1.5, end[0], end[1], end[2], v[0], v[1], v[2], 512.0f, 0, 0, 0, 2, 0);
360 VectorScale(v, 0.75, v);
361 particle(pt_underwaterspark, PARTICLE_BILLBOARD, explosparkramp[(noise2[j*32+i] >> 5)], tex_particle, false, true, 10, 10, lhrandom(128, 255), 9999, 1.5, end[0], end[1], end[2], v[0], v[1], v[2], 512.0f, 0, 0, 0, 2, 0);
367 ang[2] = lhrandom(0, 360);
368 fractalnoisequick(noise1, 32, 4);
369 fractalnoisequick(noise2, 32, 8);
370 for (i = 0;i < 32;i++)
372 for (j = 0;j < 32;j++)
375 VectorMA(org, 16, v, v);
376 TraceLine(org, v, end, NULL, 0, true);
377 ang[0] = (j + 0.5f) * (360.0f / 32.0f);
378 ang[1] = (i + 0.5f) * (360.0f / 32.0f);
379 AngleVectors(ang, v, NULL, NULL);
380 f = noise1[j*32+i] * 1.5f;
381 VectorScale(v, f, v);
382 particle(pt_spark, PARTICLE_BILLBOARD, noise2[j*32+i] * 0x010101, tex_smoke[rand()&7], false, true, 10, 10, lhrandom(128, 255), 9999, 1.5, end[0], end[1], end[2], v[0], v[1], v[2] + 160.0f, 512.0f, 0, 0, 0, 2, 0);
383 VectorScale(v, 0.75, v);
384 particle(pt_spark, PARTICLE_BILLBOARD, explosparkramp[(noise2[j*32+i] >> 5)], tex_particle, false, true, 10, 10, lhrandom(128, 255), 9999, 1.5, end[0], end[1], end[2], v[0], v[1], v[2] + 160.0f, 512.0f, 0, 0, 0, 2, 0);
386 // VectorScale(v, 384, v);
387 // particle(pt_spark, PARTICLE_BILLBOARD, explosparkramp[rand()&7], tex_particle, false, true, 2, 2, lhrandom(16, 255), 9999, 1.5, end[0], end[1], end[2], v[0], v[1], v[2] + 160.0f, 512.0f, 0, 0, 0, 2, 0);
397 for (i = 0;i < 256;i++)
403 while(DotProduct(v,v) < 0.75);
404 VectorScale(v, 512, v);
405 particle(pt_spark, PARTICLE_BILLBOARD, explosparkramp[rand()&7], tex_particle, false, true, 4, 4, 255, 9999, 1.5, org[0], org[1], org[2], v[0], v[1], v[2] + 160.0f, 512.0f, 0, 0, 0, 2, 0);
414 CL_ParticleExplosion2
418 void CL_ParticleExplosion2 (vec3_t org, int colorStart, int colorLength)
421 if (!cl_particles.integer) return;
423 for (i = 0;i < 512;i++)
424 particle(pt_fade, PARTICLE_BILLBOARD, particlepalette[colorStart + (i % colorLength)], tex_particle, false, false, 1.5, 1.5, 255, 0.3, 0, org[0] + lhrandom(-8, 8), org[1] + lhrandom(-8, 8), org[2] + lhrandom(-8, 8), lhrandom(-192, 192), lhrandom(-192, 192), lhrandom(-192, 192), 384, 0, 0, 0, 1, 0);
433 void CL_BlobExplosion (vec3_t org)
436 if (!cl_particles.integer) return;
438 R_Stain(org, 96, 80, 80, 80, 128, 176, 176, 176, 128);
439 //R_Stain(org, 96, 96, 64, 96, 128, 160, 128, 160, 128);
443 //for (i = 0;i < 256;i++)
444 // particle(pt_blob , PARTICLE_BILLBOARD, particlepalette[ 66+(rand()%6)], tex_particle, false, true, 4, 4, 255, 9999, 0, org[0] + lhrandom(-16, 16), org[1] + lhrandom(-16, 16), org[2] + lhrandom(-16, 16), lhrandom(-4, 4), lhrandom(-4, 4), lhrandom(-128, 128), 0, 0, 0, 0, 0, 0);
445 //for (i = 0;i < 256;i++)
446 // particle(pt_blob2, PARTICLE_BILLBOARD, particlepalette[150+(rand()%6)], tex_particle, false, true, 4, 4, 255, 9999, 0, org[0] + lhrandom(-16, 16), org[1] + lhrandom(-16, 16), org[2] + lhrandom(-16, 16), lhrandom(-4, 4), lhrandom(-4, 4), lhrandom(-128, 128), 0, 0, 0, 0, 0, 0);
455 void CL_RunParticleEffect (vec3_t org, vec3_t dir, int color, int count)
457 if (!cl_particles.integer) return;
461 CL_ParticleExplosion(org, false);
465 particle(pt_fade, PARTICLE_BILLBOARD, particlepalette[color + (rand()&7)], tex_particle, false, false, 1, 1, 128, 9999, 0, org[0] + lhrandom(-8, 8), org[1] + lhrandom(-8, 8), org[2] + lhrandom(-8, 8), lhrandom(-15, 15), lhrandom(-15, 15), lhrandom(-15, 15), 384, 0, 0, 0, 0, 0);
468 // LordHavoc: added this for spawning sparks/dust (which have strong gravity)
474 void CL_SparkShower (vec3_t org, vec3_t dir, int count)
476 if (!cl_particles.integer) return;
478 R_Stain(org, 32, 96, 96, 96, 32, 128, 128, 128, 32);
481 if (cl_particles_smoke.integer)
482 particle(pt_bulletsmoke, PARTICLE_BILLBOARD, 0xFFFFFF /*0xA0A0A0*/, tex_smoke[rand()&7], true, true, 2, 2, 255, 9999, 0, org[0], org[1], org[2], lhrandom(-8, 8), lhrandom(-8, 8), lhrandom(0, 16), 0, 0, 0, 0, 0, 0);
484 if (cl_particles_sparks.integer)
488 particle(pt_spark, PARTICLE_BILLBOARD, particlepalette[0x68 + (rand() & 7)], tex_particle, false, true, 1, 1, lhrandom(64, 128), 9999, 0, org[0], org[1], org[2], lhrandom(-64, 64) + dir[0], lhrandom(-64, 64) + dir[1], lhrandom(0, 128) + dir[2], 480, 0, 0, 0, 1, 0);
492 void CL_PlasmaBurn (vec3_t org)
494 if (!cl_particles.integer) return;
496 R_Stain(org, 48, 96, 96, 96, 48, 128, 128, 128, 48);
499 void CL_BloodPuff (vec3_t org, vec3_t vel, int count)
502 // bloodcount is used to accumulate counts too small to cause a blood particle
503 static int bloodcount = 0;
504 if (!cl_particles.integer) return;
505 if (!cl_particles_blood.integer) return;
512 while(bloodcount > 0)
514 r = lhrandom(cl_particles_blood_size_min.value, cl_particles_blood_size_max.value);
515 particle(pt_blood, PARTICLE_BILLBOARD, 0x300000, tex_smoke[rand()&7], true, false, r, r, cl_particles_blood_alpha.value * 255, 9999, -1, org[0], org[1], org[2], vel[0] + lhrandom(-s, s), vel[1] + lhrandom(-s, s), vel[2] + lhrandom(-s, s), 0, 0, 0, 0, 1, 0);
520 void CL_BloodShower (vec3_t mins, vec3_t maxs, float velspeed, int count)
524 vec3_t diff, center, velscale;
525 if (!cl_particles.integer) return;
526 if (!cl_particles_bloodshowers.integer) return;
527 if (!cl_particles_blood.integer) return;
529 VectorSubtract(maxs, mins, diff);
530 center[0] = (mins[0] + maxs[0]) * 0.5;
531 center[1] = (mins[1] + maxs[1]) * 0.5;
532 center[2] = (mins[2] + maxs[2]) * 0.5;
533 // FIXME: change velspeed back to 2.0x after fixing mod
534 velscale[0] = velspeed * 2.0 / diff[0];
535 velscale[1] = velspeed * 2.0 / diff[1];
536 velscale[2] = velspeed * 2.0 / diff[2];
542 org[0] = lhrandom(mins[0], maxs[0]);
543 org[1] = lhrandom(mins[1], maxs[1]);
544 org[2] = lhrandom(mins[2], maxs[2]);
545 vel[0] = (org[0] - center[0]) * velscale[0];
546 vel[1] = (org[1] - center[1]) * velscale[1];
547 vel[2] = (org[2] - center[2]) * velscale[2];
548 r = lhrandom(cl_particles_blood_size_min.value, cl_particles_blood_size_max.value);
550 particle(pt_blood, PARTICLE_BILLBOARD, 0x300000, tex_smoke[rand()&7], true, false, r, r, cl_particles_blood_alpha.value * 255, 9999, -1, org[0], org[1], org[2], vel[0], vel[1], vel[2], 0, 0, 0, 0, 1, 0);
554 void CL_ParticleCube (vec3_t mins, vec3_t maxs, vec3_t dir, int count, int colorbase, int gravity, int randomvel)
557 if (!cl_particles.integer) return;
558 if (maxs[0] <= mins[0]) {t = mins[0];mins[0] = maxs[0];maxs[0] = t;}
559 if (maxs[1] <= mins[1]) {t = mins[1];mins[1] = maxs[1];maxs[1] = t;}
560 if (maxs[2] <= mins[2]) {t = mins[2];mins[2] = maxs[2];maxs[2] = t;}
563 particle(gravity ? pt_grav : pt_static, PARTICLE_BILLBOARD, particlepalette[colorbase + (rand()&3)], tex_particle, false, false, 2, 2, 255, lhrandom(1, 2), 0, lhrandom(mins[0], maxs[0]), lhrandom(mins[1], maxs[1]), lhrandom(mins[2], maxs[2]), dir[0] + lhrandom(-randomvel, randomvel), dir[1] + lhrandom(-randomvel, randomvel), dir[2] + lhrandom(-randomvel, randomvel), 0, 0, 0, 0, 0, 0);
566 void CL_ParticleRain (vec3_t mins, vec3_t maxs, vec3_t dir, int count, int colorbase, int type)
570 if (!cl_particles.integer) return;
571 if (maxs[0] <= mins[0]) {t = mins[0];mins[0] = maxs[0];maxs[0] = t;}
572 if (maxs[1] <= mins[1]) {t = mins[1];mins[1] = maxs[1];maxs[1] = t;}
573 if (maxs[2] <= mins[2]) {t = mins[2];mins[2] = maxs[2];maxs[2] = t;}
574 if (dir[2] < 0) // falling
576 t = (maxs[2] - mins[2]) / -dir[2];
581 t = (maxs[2] - mins[2]) / dir[2];
584 if (t < 0 || t > 2) // sanity check
590 count *= 4; // ick, this should be in the mod or maps?
594 vel[0] = dir[0] + lhrandom(-16, 16);
595 vel[1] = dir[1] + lhrandom(-16, 16);
596 vel[2] = dir[2] + lhrandom(-32, 32);
597 particle(pt_rain, PARTICLE_UPRIGHT_FACING, particlepalette[colorbase + (rand()&3)], tex_particle, true, true, 1, 64, 64, t, 0, lhrandom(mins[0], maxs[0]), lhrandom(mins[1], maxs[1]), z, vel[0], vel[1], vel[2], 0, vel[0], vel[1], vel[2], 0, 0);
603 vel[0] = dir[0] + lhrandom(-16, 16);
604 vel[1] = dir[1] + lhrandom(-16, 16);
605 vel[2] = dir[2] + lhrandom(-32, 32);
606 particle(pt_snow, PARTICLE_BILLBOARD, particlepalette[colorbase + (rand()&3)], tex_particle, false, true, 2, 2, 255, t, 0, lhrandom(mins[0], maxs[0]), lhrandom(mins[1], maxs[1]), z, vel[0], vel[1], vel[2], 0, vel[0], vel[1], vel[2], 0, 0);
610 Host_Error("CL_ParticleRain: unknown type %i (0 = rain, 1 = snow)\n", type);
614 void CL_FlameCube (vec3_t mins, vec3_t maxs, int count)
617 if (!cl_particles.integer) return;
618 if (maxs[0] <= mins[0]) {t = mins[0];mins[0] = maxs[0];maxs[0] = t;}
619 if (maxs[1] <= mins[1]) {t = mins[1];mins[1] = maxs[1];maxs[1] = t;}
620 if (maxs[2] <= mins[2]) {t = mins[2];mins[2] = maxs[2];maxs[2] = t;}
623 particle(pt_flame, PARTICLE_BILLBOARD, particlepalette[224 + (rand()&15)], tex_particle, false, true, 8, 8, 255, 9999, 1.1, lhrandom(mins[0], maxs[0]), lhrandom(mins[1], maxs[1]), lhrandom(mins[2], maxs[2]), lhrandom(-32, 32), lhrandom(-32, 32), lhrandom(-32, 64), 0, 0, 0, 0, 1, 0);
626 void CL_Flames (vec3_t org, vec3_t vel, int count)
628 if (!cl_particles.integer) return;
631 particle(pt_flame, PARTICLE_BILLBOARD, particlepalette[224 + (rand()&15)], tex_particle, false, true, 8, 8, 255, 9999, 1.1, org[0], org[1], org[2], vel[0] + lhrandom(-128, 128), vel[1] + lhrandom(-128, 128), vel[2] + lhrandom(-128, 128), 0, 0, 0, 0, 1, 0);
642 void CL_LavaSplash (vec3_t origin)
647 if (!cl_particles.integer) return;
649 for (i=-128 ; i<128 ; i+=16)
651 for (j=-128 ; j<128 ; j+=16)
653 dir[0] = j + lhrandom(0, 8);
654 dir[1] = i + lhrandom(0, 8);
656 org[0] = origin[0] + dir[0];
657 org[1] = origin[1] + dir[1];
658 org[2] = origin[2] + lhrandom(0, 64);
659 vel = lhrandom(50, 120) / VectorLength(dir); // normalize and scale
660 particle(pt_lavasplash, PARTICLE_BILLBOARD, particlepalette[224 + (rand()&7)], tex_particle, false, true, 7, 7, 255, 9999, 0, org[0], org[1], org[2], dir[0] * vel, dir[1] * vel, dir[2] * vel, 0, 0, 0, 0, 0, 0);
671 void CL_TeleportSplash (vec3_t org)
674 if (!cl_particles.integer) return;
676 for (i=-16 ; i<16 ; i+=8)
677 for (j=-16 ; j<16 ; j+=8)
678 for (k=-24 ; k<32 ; k+=8)
679 //particle(pt_fade, PARTICLE_BILLBOARD, 0xFFFFFF, tex_particle, false, true, 1.5, 1.5, lhrandom(64, 128), 9999, 0, org[0] + i + lhrandom(0, 8), org[1] + j + lhrandom(0, 8), org[2] + k + lhrandom(0, 8), i*2 + lhrandom(-12.5, 12.5), j*2 + lhrandom(-12.5, 12.5), k*2 + lhrandom(27.5, 52.5), 384.0f, 0, 0, 0, 1, 0);
680 particle(pt_fade, PARTICLE_BILLBOARD, 0xFFFFFF, tex_particle, false, true, 10, 10, lhrandom(64, 128), 9999, 0, org[0] + i + lhrandom(0, 8), org[1] + j + lhrandom(0, 8), org[2] + k + lhrandom(0, 8), lhrandom(-64, 64), lhrandom(-64, 64), lhrandom(-256, 256), 256.0f, 0, 0, 0, 1, 0);
683 void CL_RocketTrail (vec3_t start, vec3_t end, int type, entity_t *ent)
685 vec3_t vec, dir, vel, pos;
686 float len, dec, speed;
687 int contents, bubbles/*, c*/;
688 if (!cl_particles.integer) return;
690 VectorSubtract(end, start, dir);
691 VectorNormalize(dir);
693 //if (type == 0 && host_frametime != 0) // rocket glow
694 // particle(pt_oneframe, PARTICLE_BILLBOARD, 0xFFFFFF, tex_rocketglow, false, true, 24, 24, 255, 9999, 0, end[0] - 12 * dir[0], end[1] - 12 * dir[1], end[2] - 12 * dir[2], 0, 0, 0, 0, 0, 0, 0, 0, 0);
696 VectorSubtract (end, start, vec);
697 len = VectorNormalizeLength (vec);
698 dec = -ent->persistent.trail_time;
699 ent->persistent.trail_time += len;
700 if (ent->persistent.trail_time < 0.01f)
703 speed = 1.0f / (ent->state_current.time - ent->state_previous.time);
704 VectorSubtract(ent->state_current.origin, ent->state_previous.origin, vel);
705 VectorScale(vel, speed, vel);
707 // advance into this frame to reach the first puff location
708 VectorMA(start, dec, vec, pos);
711 // if we skip out, leave it reset
712 ent->persistent.trail_time = 0.0f;
714 contents = Mod_PointInLeaf(pos, cl.worldmodel)->contents;
715 if (contents == CONTENTS_SKY || contents == CONTENTS_LAVA)
718 bubbles = (contents == CONTENTS_WATER || contents == CONTENTS_SLIME);
724 case 0: // rocket trail
725 if (!cl_particles_smoke.integer)
728 //particle(pt_fade, PARTICLE_BILLBOARD, 0x707070, tex_particle, true, false, dec, dec, 128, 9999, 0, pos[0], pos[1], pos[2], lhrandom(-8, 8), lhrandom(-8, 8), lhrandom(-8, 8), 256.0f, 0, 0, 0, 0, 0);
730 particle(pt_fade, PARTICLE_BILLBOARD, 0x404040, tex_smoke[rand()&7], true, true, dec, dec, 128, 9999, 0, pos[0], pos[1], pos[2], lhrandom(-5, 5), lhrandom(-5, 5), lhrandom(-5, 5), 256.0f, 0, 0, 0, 0, 0);
731 //particle(pt_fade, PARTICLE_BILLBOARD, 0x707070, tex_smoke[rand()&7], false, true, dec, dec, 128, 9999, 0, pos[0], pos[1], pos[2], lhrandom(-10, 10), lhrandom(-10, 10), lhrandom(-10, 10), 128.0f, 0, 0, 0, 0, 0);
733 //particle(pt_smoke, PARTICLE_BILLBOARD, 0x707070, tex_smoke[rand()&7], false, true, 2, 2, 160, 9999, 0, pos[0], pos[1], pos[2], 0, 0, 0, 0, 0, 0, 0, 0, 0);
734 if (bubbles && cl_particles_bubbles.integer)
736 particle(pt_bubble, PARTICLE_BILLBOARD, 0xFFFFFF, tex_bubble, false, true, 2, 2, 255, 9999, 1.5, pos[0], pos[1], pos[2], lhrandom(-16, 16), lhrandom(-16, 16), lhrandom(-16, 16), 0, 0, 0, 0, 0, 0);
737 //particle(pt_bubble, PARTICLE_BILLBOARD, 0xFFFFFF, tex_bubble, false, true, 2, 2, 255, 9999, 1.5, pos[0], pos[1], pos[2], lhrandom(-16, 16), lhrandom(-16, 16), lhrandom(-16, 16), 0, 0, 0, 0, 0, 0);
741 //particle(pt_spark, PARTICLE_BILLBOARD, particlepalette[0x68 + (rand() & 7)], tex_particle, false, true, 2, 2, lhrandom(128, 255), 9999, 1.5, pos[0], pos[1], pos[2], lhrandom(-64, 64), lhrandom(-64, 64), lhrandom(-64, 64), 512.0f, 0, 0, 0, 1, 0);
742 //particle(pt_spark, PARTICLE_BILLBOARD, particlepalette[0x68 + (rand() & 7)], tex_particle, false, true, 2, 2, lhrandom(128, 255), 9999, 1.5, pos[0], pos[1], pos[2], lhrandom(-64, 64), lhrandom(-64, 64), lhrandom(-64, 64), 512.0f, 0, 0, 0, 1, 0);
743 //particle(pt_spark, PARTICLE_BILLBOARD, particlepalette[0x68 + (rand() & 7)], tex_particle, false, true, 1, 1, lhrandom(128, 255), 9999, 1.5, pos[0], pos[1], pos[2], lhrandom(-64, 64) - vel[0] * 0.0625, lhrandom(-64, 64) - vel[1] * 0.0625, lhrandom(-64, 64) - vel[2] * 0.0625, 512.0f, 0, 0, 0, 1, 0);
744 //particle(pt_spark, PARTICLE_BILLBOARD, particlepalette[0x68 + (rand() & 7)], tex_particle, false, true, 1, 1, lhrandom(128, 255), 9999, 1.5, pos[0], pos[1], pos[2], lhrandom(-64, 64) - vel[0] * 0.0625, lhrandom(-64, 64) - vel[1] * 0.0625, lhrandom(-64, 64) - vel[2] * 0.0625, 512.0f, 0, 0, 0, 1, 0);
745 //particle(pt_spark, PARTICLE_BILLBOARD, particlepalette[0x68 + (rand() & 7)], tex_particle, false, true, 1, 1, lhrandom(128, 255), 9999, 1.5, pos[0], pos[1], pos[2], lhrandom(-64, 64) - vel[0] * 0.0625, lhrandom(-64, 64) - vel[1] * 0.0625, lhrandom(-64, 64) - vel[2] * 0.0625, 512.0f, 0, 0, 0, 1, 0);
746 //particle(pt_spark, PARTICLE_BILLBOARD, particlepalette[0x68 + (rand() & 7)], tex_particle, false, true, 1, 1, lhrandom(128, 255), 9999, 1.5, pos[0], pos[1], pos[2], lhrandom(-64, 64) - vel[0] * 0.0625, lhrandom(-64, 64) - vel[1] * 0.0625, lhrandom(-64, 64) - vel[2] * 0.0625, 512.0f, 0, 0, 0, 1, 0);
750 case 1: // grenade trail
751 // FIXME: make it gradually stop smoking
752 if (!cl_particles_smoke.integer)
755 //particle(pt_fade, PARTICLE_BILLBOARD, 0x707070, tex_particle, true, false, dec, dec, 128, 9999, 0, pos[0], pos[1], pos[2], lhrandom(-8, 8), lhrandom(-8, 8), lhrandom(-8, 8), 256.0f, 0, 0, 0, 0, 0);
757 particle(pt_fade, PARTICLE_BILLBOARD, 0x404040, tex_smoke[rand()&7], true, true, dec, dec, 128, 9999, 0, pos[0], pos[1], pos[2], lhrandom(-5, 5), lhrandom(-5, 5), lhrandom(-5, 5), 256.0f, 0, 0, 0, 0, 0);
758 //particle(pt_smoke, PARTICLE_BILLBOARD, 0x404040, tex_smoke[rand()&7], false, true, 2, 2, 160, 9999, 0, pos[0], pos[1], pos[2], 0, 0, 0, 0, 0, 0, 0, 0, 0);
759 if (bubbles && cl_particles_bubbles.integer)
761 particle(pt_bubble, PARTICLE_BILLBOARD, 0xFFFFFF, tex_bubble, false, true, 2, 2, 255, 9999, 1.5, pos[0], pos[1], pos[2], lhrandom(-16, 16), lhrandom(-16, 16), lhrandom(-16, 16), 0, 0, 0, 0, 0, 0);
762 //particle(pt_bubble, PARTICLE_BILLBOARD, 0xFFFFFF, tex_bubble, false, true, 2, 2, 255, 9999, 1.5, pos[0], pos[1], pos[2], lhrandom(-16, 16), lhrandom(-16, 16), lhrandom(-16, 16), 0, 0, 0, 0, 0, 0);
768 if (!cl_particles_blood.integer)
770 dec = lhrandom(cl_particles_blood_size_min.value, cl_particles_blood_size_max.value);
771 //particle(pt_blood, PARTICLE_BILLBOARD, 0x300000, tex_smoke[rand()&7], true, false, dec, dec, cl_particles_blood_alpha.value * 255.0f, 9999, -1, pos[0], pos[1], pos[2], vel[0] + lhrandom(-64, 64), vel[1] + lhrandom(-64, 64), vel[2] + lhrandom(-64, 64), 0, 0, 0, 0, 1, 0);
772 particle(pt_blood, PARTICLE_BILLBOARD, 0x300000, tex_smoke[rand()&7], true, false, dec, dec, cl_particles_blood_alpha.value * 255.0f, 9999, -1, pos[0], pos[1], pos[2], lhrandom(-64, 64), lhrandom(-64, 64), lhrandom(-64, 64), 0, 0, 0, 0, 1, 0);
773 //c = ((rand() & 15) + 16) << 16;
774 //particle(pt_blood, PARTICLE_BILLBOARD, c, tex_particle, true, false, dec, dec, cl_particles_blood_alpha.value * 255.0f, 9999, -1, pos[0], pos[1], pos[2], lhrandom(-64, 64), lhrandom(-64, 64), lhrandom(-64, 64), 0, 0, 0, 0, 1, 0);
777 case 4: // slight blood
778 if (!cl_particles_blood.integer)
780 dec = lhrandom(cl_particles_blood_size_min.value, cl_particles_blood_size_max.value);
781 //particle(pt_blood, PARTICLE_BILLBOARD, 0x300000, tex_smoke[rand()&7], true, false, dec, dec, cl_particles_blood_alpha.value * 128.0f, 9999, -1, pos[0], pos[1], pos[2], vel[0] + lhrandom(-64, 64), vel[1] + lhrandom(-64, 64), vel[2] + lhrandom(-64, 64), 0, 0, 0, 0, 1, 0);
782 particle(pt_blood, PARTICLE_BILLBOARD, 0x300000, tex_smoke[rand()&7], true, false, dec, dec, cl_particles_blood_alpha.value * 128.0f, 9999, -1, pos[0], pos[1], pos[2], lhrandom(-64, 64), lhrandom(-64, 64), lhrandom(-64, 64), 0, 0, 0, 0, 1, 0);
783 //c = ((rand() & 15) + 16) << 16;
784 //particle(pt_blood, PARTICLE_BILLBOARD, c, tex_particle, true, false, dec, dec, cl_particles_blood_alpha.value * 128.0f, 9999, -1, pos[0], pos[1], pos[2], lhrandom(-64, 64), lhrandom(-64, 64), lhrandom(-64, 64), 0, 0, 0, 0, 1, 0);
787 case 3: // green tracer
789 //particle(pt_fade, PARTICLE_BILLBOARD, 0x373707, tex_particle, false, true, dec, dec, 128, 9999, 0, pos[0], pos[1], pos[2], 0, 0, 0, 384.0f, 0, 0, 0, 0, 0);
790 particle(pt_fade, PARTICLE_BILLBOARD, 0x373707, tex_particle, false, true, dec, dec, 128, 9999, 0, pos[0], pos[1], pos[2], lhrandom(-8, 8), lhrandom(-8, 8), lhrandom(-8, 8), 384.0f, 0, 0, 0, 0, 0);
793 case 5: // flame tracer
795 //particle(pt_fade, PARTICLE_BILLBOARD, 0xCF632B, tex_particle, false, true, dec, dec, 128, 9999, 0, pos[0], pos[1], pos[2], 0, 0, 0, 384.0f, 0, 0, 0, 0, 0);
796 particle(pt_fade, PARTICLE_BILLBOARD, 0xCF632B, tex_particle, false, true, dec, dec, 128, 9999, 0, pos[0], pos[1], pos[2], lhrandom(-8, 8), lhrandom(-8, 8), lhrandom(-8, 8), 384.0f, 0, 0, 0, 0, 0);
799 case 6: // voor trail
801 //particle(pt_fade, PARTICLE_BILLBOARD, 0x47232B, tex_particle, false, true, dec, dec, 128, 9999, 0, pos[0], pos[1], pos[2], 0, 0, 0, 384.0f, 0, 0, 0, 0, 0);
802 particle(pt_fade, PARTICLE_BILLBOARD, 0x47232B, tex_particle, false, true, dec, dec, 128, 9999, 0, pos[0], pos[1], pos[2], lhrandom(-8, 8), lhrandom(-8, 8), lhrandom(-8, 8), 384.0f, 0, 0, 0, 0, 0);
805 case 7: // Nehahra smoke tracer
806 if (!cl_particles_smoke.integer)
809 particle(pt_smoke, PARTICLE_BILLBOARD, 0xC0C0C0, tex_smoke[rand()&7], true, false, dec, dec, 64, 9999, 0, pos[0], pos[1], pos[2], 0, 0, 0, 0, 0, 0, 0, 0, 0);
813 // advance to next time and position
815 VectorMA (pos, dec, vec, pos);
817 ent->persistent.trail_time = len;
820 void CL_RocketTrail2 (vec3_t start, vec3_t end, int color, entity_t *ent)
824 if (!cl_particles.integer) return;
825 if (!cl_particles_smoke.integer) return;
827 VectorCopy(start, pos);
828 VectorSubtract (end, start, vec);
829 len = (int) (VectorNormalizeLength (vec) * (1.0f / 3.0f));
830 VectorScale(vec, 3, vec);
831 color = particlepalette[color];
834 particle(pt_smoke, PARTICLE_BILLBOARD, color, tex_particle, false, false, 5, 5, 128, 9999, 0, pos[0], pos[1], pos[2], 0, 0, 0, 0, 0, 0, 0, 0, 0);
835 VectorAdd (pos, vec, pos);
845 void CL_MoveParticles (void)
848 renderparticle_t *r, *rend;
849 int i, activeparticles, maxparticle, j, a, pressureused = false, content;
850 float gravity, dvel, frametime, f, dist, normal[3], v[3], org[3];
852 // LordHavoc: early out condition
853 if (!cl_numparticles)
855 r_refdef.numparticles = 0;
859 frametime = cl.time - cl.oldtime;
861 return; // if absolutely still, don't update particles
862 gravity = frametime * sv_gravity.value;
863 dvel = 1+4*frametime;
868 for (i = 0, p = particles, r = r_refdef.particles, rend = r + cl_maxparticles;i < cl_numparticles;i++, p++)
870 if (p->die < cl.time)
872 freeparticles[j++] = p;
877 VectorCopy(p->org, p->oldorg);
878 VectorMA(p->org, frametime, p->vel, p->org);
879 VectorCopy(p->org, org);
882 if (TraceLine(p->oldorg, p->org, v, normal, 0, true) < 1)
884 VectorCopy(v, p->org);
887 // assume it's blood (lame, but...)
888 R_Stain(v, 48, 64, 24, 24, p->alpha * p->scalex * p->scaley * (1.0f / 2048.0f), 192, 48, 48, p->alpha * p->scalex * p->scaley * (1.0f / 2048.0f));
890 freeparticles[j++] = p;
895 dist = DotProduct(p->vel, normal) * -p->bounce;
896 VectorMA(p->vel, dist, normal, p->vel);
897 if (DotProduct(p->vel, p->vel) < 0.03)
904 f = p->friction * frametime;
906 content = Mod_PointInLeaf(p->org, cl.worldmodel)->contents;
907 if (content != CONTENTS_EMPTY)
910 VectorScale(p->vel, f, p->vel);
918 // LordHavoc: drop-through because of shared code
924 p->alpha -= frametime * 256;
930 p->vel[2] -= gravity;
933 p->vel[2] -= gravity * 0.05;
934 p->alpha -= frametime * 192;
939 if (cl.time > p->time2)
941 p->time2 = cl.time + (rand() & 3) * 0.1;
942 p->vel[0] = (rand()&63)-32 + p->vel2[0];
943 p->vel[1] = (rand()&63)-32 + p->vel2[1];
944 p->vel[2] = (rand()&63)-32 + p->vel2[2];
947 content = Mod_PointInLeaf(p->org, cl.worldmodel)->contents;
949 if (a != CONTENTS_EMPTY && a != CONTENTS_SKY)
953 if (a == CONTENTS_SOLID && Mod_PointInLeaf(p->oldorg, cl.worldmodel)->contents == CONTENTS_SOLID)
954 break; // still in solid
955 p->die = cl.time + 1000;
956 p->vel[0] = p->vel[1] = p->vel[2] = 0;
961 p->tex = tex_smoke[rand()&7];
962 p->orientation = PARTICLE_BILLBOARD;
970 p->tex = tex_smoke[rand()&7];
971 p->orientation = PARTICLE_BILLBOARD;
978 default: // CONTENTS_SOLID and any others
979 TraceLine(p->oldorg, p->org, v, normal, 0, true);
980 VectorCopy(v, p->org);
981 p->tex = tex_smoke[rand()&7];
982 p->orientation = PARTICLE_BILLBOARD;
996 content = Mod_PointInLeaf(p->org, cl.worldmodel)->contents;
998 if (a != CONTENTS_EMPTY)
1000 if (a == CONTENTS_WATER || a == CONTENTS_SLIME)
1003 p->scalex += frametime * (cl_particles_blood_size_min.value + cl_particles_blood_size_max.value);
1004 p->scaley += frametime * (cl_particles_blood_size_min.value + cl_particles_blood_size_max.value);
1005 p->alpha -= frametime * max(cl_particles_blood_alpha.value, 0.01f) * 128.0f;
1006 //p->vel[2] += gravity * 0.25f;
1014 p->vel[2] -= gravity;
1017 p->alpha -= frametime * p->time2;
1018 p->vel[2] -= gravity;
1024 content = Mod_PointInLeaf(p->org, cl.worldmodel)->contents;
1025 if (content != CONTENTS_EMPTY)
1029 case pt_explosionsplash:
1030 if (Mod_PointInLeaf(p->org, cl.worldmodel)->contents == CONTENTS_EMPTY)
1031 p->vel[2] -= gravity;
1034 p->scalex += frametime * 64.0f;
1035 p->scaley += frametime * 64.0f;
1036 p->alpha -= frametime * 1024.0f;
1041 p->alpha -= frametime * p->time2;
1047 content = Mod_PointInLeaf(p->org, cl.worldmodel)->contents;
1048 if (content != CONTENTS_WATER && content != CONTENTS_SLIME)
1050 p->tex = tex_smoke[rand()&7];
1051 p->orientation = PARTICLE_BILLBOARD;
1052 p->type = pt_splashpuff;
1055 p->vel[0] = p->vel[1] = p->vel[2] = 0;
1058 p->vel[0] *= (1 - (frametime * 0.0625));
1059 p->vel[1] *= (1 - (frametime * 0.0625));
1060 p->vel[2] = (p->vel[2] + gravity * 0.25) * (1 - (frametime * 0.0625));
1061 if (cl.time > p->time2)
1063 p->time2 = cl.time + lhrandom(0, 0.5);
1064 p->vel[0] += lhrandom(-32,32);
1065 p->vel[1] += lhrandom(-32,32);
1066 p->vel[2] += lhrandom(-32,32);
1068 p->alpha -= frametime * 256;
1072 case pt_bulletsmoke:
1073 p->scalex += frametime * 16;
1074 p->scaley += frametime * 16;
1075 p->alpha -= frametime * 1024;
1076 p->vel[2] += gravity * 0.2;
1081 p->scalex += frametime * 16;
1082 p->scaley += frametime * 16;
1083 p->alpha -= frametime * 320;
1084 //p->vel[2] += gravity * 0.2;
1089 p->scalex += frametime * 48;
1090 p->scaley += frametime * 48;
1091 p->alpha -= frametime * 512;
1092 p->vel[2] += gravity * 0.05;
1097 p->alpha -= frametime * 1024;
1103 content = Mod_PointInLeaf(p->org, cl.worldmodel)->contents;
1105 if (a != CONTENTS_EMPTY && a != CONTENTS_SKY)
1109 b = Mod_PointInLeaf(p->oldorg, cl.worldmodel)->contents;
1110 VectorCopy(p->oldorg, o);
1114 f = TraceLine(o, p->org, v, normal, a, true);
1115 b = traceline_endcontents;
1116 if (f < 1 && b != CONTENTS_EMPTY && b != CONTENTS_SKY)
1121 p->die = cl.time + 1000;
1122 p->vel[0] = p->vel[1] = p->vel[2] = 0;
1123 VectorCopy(v, p->org);
1127 case CONTENTS_SLIME:
1128 p->tex = tex_smoke[rand()&7];
1129 p->orientation = PARTICLE_BILLBOARD;
1135 default: // water, solid, and anything else
1136 p->tex = tex_rainsplash[0];
1137 p->orientation = PARTICLE_ORIENTED_DOUBLESIDED;
1139 VectorCopy(normal, p->vel2);
1140 // VectorAdd(p->org, normal, p->org);
1141 p->type = pt_raindropsplash;
1153 case pt_raindropsplash:
1154 p->time2 += frametime * 64.0f;
1155 if (p->time2 >= 16.0f)
1160 p->tex = tex_rainsplash[(int) p->time2];
1161 p->orientation = PARTICLE_ORIENTED_DOUBLESIDED;
1165 p->alpha -= frametime * 512;
1166 p->vel[2] += gravity;
1176 printf("unknown particle type %i\n", p->type);
1181 // LordHavoc: immediate removal of unnecessary particles (must be done to ensure compactor below operates properly in all cases)
1182 if (p->die < cl.time)
1183 freeparticles[j++] = p;
1189 pressureused = true;
1191 // build renderparticle for renderer to use
1192 r->orientation = p->orientation;
1193 r->additive = p->additive;
1194 r->dir[0] = p->vel2[0];
1195 r->dir[1] = p->vel2[1];
1196 r->dir[2] = p->vel2[2];
1197 r->org[0] = p->org[0];
1198 r->org[1] = p->org[1];
1199 r->org[2] = p->org[2];
1201 r->scalex = p->scalex * cl_particles_size.value;
1202 r->scaley = p->scaley * cl_particles_size.value;
1203 r->dynlight = p->dynlight;
1204 r->color[0] = p->color[0] * (1.0f / 255.0f);
1205 r->color[1] = p->color[1] * (1.0f / 255.0f);
1206 r->color[2] = p->color[2] * (1.0f / 255.0f);
1207 r->color[3] = p->alpha * (1.0f / 255.0f);
1211 r_refdef.numparticles = r - r_refdef.particles;
1212 // fill in gaps to compact the array
1214 while (maxparticle >= activeparticles)
1216 *freeparticles[i++] = particles[maxparticle--];
1217 while (maxparticle >= activeparticles && particles[maxparticle].die < cl.time)
1220 cl_numparticles = activeparticles;
1224 activeparticles = 0;
1225 for (i = 0, p = particles;i < cl_numparticles;i++, p++)
1227 freeparticles[activeparticles++] = p;
1229 if (activeparticles)
1231 for (i = 0, p = particles;i < cl_numparticles;i++, p++)
1233 for (j = 0;j < activeparticles;j++)
1235 if (freeparticles[j] != p)
1237 float dist, diff[3];
1238 VectorSubtract(p->org, freeparticles[j]->org, diff);
1239 dist = DotProduct(diff, diff);
1240 if (dist < 4096 && dist >= 1)
1242 dist = freeparticles[j]->scalex * 4.0f * frametime / sqrt(dist);
1243 VectorMA(p->vel, dist, diff, p->vel);
1244 //dist = freeparticles[j]->scalex * 4.0f * frametime / dist;
1245 //VectorMA(p->vel, dist, freeparticles[j]->vel, p->vel);