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.
24 #define lhrandom(MIN,MAX) ((rand() & 32767) * (((MAX)-(MIN)) * (1.0f / 32767.0f)) + (MIN))
25 #define NUMVERTEXNORMALS 162
26 siextern float r_avertexnormals[NUMVERTEXNORMALS][3];
27 #define m_bytenormals r_avertexnormals
28 #define VectorNormalizeFast VectorNormalize
29 #define Mod_PointContents(v,m) (Mod_PointInLeaf(v,m)->contents)
30 typedef unsigned char qbyte;
31 #define cl_stainmaps.integer 0
32 void R_Stain (vec3_t origin, float radius, int cr1, int cg1, int cb1, int ca1, int cr2, int cg2, int cb2, int ca2)
35 #define CL_EntityParticles R_EntityParticles
36 #define CL_ReadPointFile_f R_ReadPointFile_f
37 #define CL_ParseParticleEffect R_ParseParticleEffect
38 #define CL_ParticleExplosion R_ParticleExplosion
39 #define CL_ParticleExplosion2 R_ParticleExplosion2
40 #define CL_BlobExplosion R_BlobExplosion
41 #define CL_RunParticleEffect R_RunParticleEffect
42 #define CL_LavaSplash R_LavaSplash
43 #define CL_RocketTrail2 R_RocketTrail2
44 void R_CalcBeamVerts (float *vert, vec3_t org1, vec3_t org2, float width)
46 vec3_t right1, right2, diff, normal;
48 VectorSubtract (org2, org1, normal);
49 VectorNormalizeFast (normal);
51 // calculate 'right' vector for start
52 VectorSubtract (r_origin, org1, diff);
53 VectorNormalizeFast (diff);
54 CrossProduct (normal, diff, right1);
56 // calculate 'right' vector for end
57 VectorSubtract (r_origin, org2, diff);
58 VectorNormalizeFast (diff);
59 CrossProduct (normal, diff, right2);
61 vert[ 0] = org1[0] + width * right1[0];
62 vert[ 1] = org1[1] + width * right1[1];
63 vert[ 2] = org1[2] + width * right1[2];
64 vert[ 4] = org1[0] - width * right1[0];
65 vert[ 5] = org1[1] - width * right1[1];
66 vert[ 6] = org1[2] - width * right1[2];
67 vert[ 8] = org2[0] - width * right2[0];
68 vert[ 9] = org2[1] - width * right2[1];
69 vert[10] = org2[2] - width * right2[2];
70 vert[12] = org2[0] + width * right2[0];
71 vert[13] = org2[1] + width * right2[1];
72 vert[14] = org2[2] + width * right2[2];
74 void fractalnoise(qbyte *noise, int size, int startgrid)
76 int x, y, g, g2, amplitude, min, max, size1 = size - 1, sizepower, gridpower;
78 #define n(x,y) noisebuf[((y)&size1)*size+((x)&size1)]
80 for (sizepower = 0;(1 << sizepower) < size;sizepower++);
81 if (size != (1 << sizepower))
82 Sys_Error("fractalnoise: size must be power of 2\n");
84 for (gridpower = 0;(1 << gridpower) < startgrid;gridpower++);
85 if (startgrid != (1 << gridpower))
86 Sys_Error("fractalnoise: grid must be power of 2\n");
88 startgrid = bound(0, startgrid, size);
90 amplitude = 0xFFFF; // this gets halved before use
91 noisebuf = malloc(size*size*sizeof(int));
92 memset(noisebuf, 0, size*size*sizeof(int));
94 for (g2 = startgrid;g2;g2 >>= 1)
96 // brownian motion (at every smaller level there is random behavior)
98 for (y = 0;y < size;y += g2)
99 for (x = 0;x < size;x += g2)
100 n(x,y) += (rand()&litude);
105 // subdivide, diamond-square algorithm (really this has little to do with squares)
107 for (y = 0;y < size;y += g2)
108 for (x = 0;x < size;x += g2)
109 n(x+g,y+g) = (n(x,y) + n(x+g2,y) + n(x,y+g2) + n(x+g2,y+g2)) >> 2;
111 for (y = 0;y < size;y += g2)
112 for (x = 0;x < size;x += g2)
114 n(x+g,y) = (n(x,y) + n(x+g2,y) + n(x+g,y-g) + n(x+g,y+g)) >> 2;
115 n(x,y+g) = (n(x,y) + n(x,y+g2) + n(x-g,y+g) + n(x+g,y+g)) >> 2;
119 // find range of noise values
121 for (y = 0;y < size;y++)
122 for (x = 0;x < size;x++)
124 if (n(x,y) < min) min = n(x,y);
125 if (n(x,y) > max) max = n(x,y);
129 // normalize noise and copy to output
130 for (y = 0;y < size;y++)
131 for (x = 0;x < size;x++)
132 *noise++ = (qbyte) (((n(x,y) - min) * 256) / max);
136 void VectorVectors(const vec3_t forward, vec3_t right, vec3_t up)
140 right[0] = forward[2];
141 right[1] = -forward[0];
142 right[2] = forward[1];
144 d = DotProduct(forward, right);
145 right[0] -= d * forward[0];
146 right[1] -= d * forward[1];
147 right[2] -= d * forward[2];
148 VectorNormalizeFast(right);
149 CrossProduct(right, forward, up);
152 #include "cl_collision.h"
155 #define MAX_PARTICLES 8192 // default max # of particles at one time
156 #define ABSOLUTE_MIN_PARTICLES 512 // no fewer than this no matter what's on the command line
160 pt_static, pt_rain, pt_bubble, pt_blood, pt_grow
164 #define PARTICLE_INVALID 0
165 #define PARTICLE_BILLBOARD 1
166 #define PARTICLE_BEAM 2
167 #define PARTICLE_ORIENTED_DOUBLESIDED 3
169 #define P_TEXNUM_FIRSTBIT 0
170 #define P_TEXNUM_BITS 6
171 #define P_ORIENTATION_FIRSTBIT (P_TEXNUM_FIRSTBIT + P_TEXNUM_BITS)
172 #define P_ORIENTATION_BITS 2
173 #define P_FLAGS_FIRSTBIT (P_ORIENTATION_FIRSTBIT + P_ORIENTATION_BITS)
174 //#define P_DYNLIGHT (1 << (P_FLAGS_FIRSTBIT + 0))
175 #define P_ADDITIVE (1 << (P_FLAGS_FIRSTBIT + 1))
177 typedef struct particle_s
180 unsigned int flags; // dynamically lit, orientation, additive blending, texnum
186 float alpha; // 0-255
187 float alphafade; // how much alpha reduces per second
188 float time2; // used for various things (snow fluttering, for example)
189 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)
190 float gravity; // how much gravity affects this particle (1.0 = normal gravity, 0.0 = none)
192 vec3_t vel2; // used for snow fluttering (base velocity, wind for instance)
193 float friction; // how much air friction affects this object (objects with a low mass/size ratio tend to get more air friction)
194 float pressure; // if non-zero, apply pressure to other particles
199 static int particlepalette[256] =
201 0x000000,0x0f0f0f,0x1f1f1f,0x2f2f2f,0x3f3f3f,0x4b4b4b,0x5b5b5b,0x6b6b6b,
202 0x7b7b7b,0x8b8b8b,0x9b9b9b,0xababab,0xbbbbbb,0xcbcbcb,0xdbdbdb,0xebebeb,
203 0x0f0b07,0x170f0b,0x1f170b,0x271b0f,0x2f2313,0x372b17,0x3f2f17,0x4b371b,
204 0x533b1b,0x5b431f,0x634b1f,0x6b531f,0x73571f,0x7b5f23,0x836723,0x8f6f23,
205 0x0b0b0f,0x13131b,0x1b1b27,0x272733,0x2f2f3f,0x37374b,0x3f3f57,0x474767,
206 0x4f4f73,0x5b5b7f,0x63638b,0x6b6b97,0x7373a3,0x7b7baf,0x8383bb,0x8b8bcb,
207 0x000000,0x070700,0x0b0b00,0x131300,0x1b1b00,0x232300,0x2b2b07,0x2f2f07,
208 0x373707,0x3f3f07,0x474707,0x4b4b0b,0x53530b,0x5b5b0b,0x63630b,0x6b6b0f,
209 0x070000,0x0f0000,0x170000,0x1f0000,0x270000,0x2f0000,0x370000,0x3f0000,
210 0x470000,0x4f0000,0x570000,0x5f0000,0x670000,0x6f0000,0x770000,0x7f0000,
211 0x131300,0x1b1b00,0x232300,0x2f2b00,0x372f00,0x433700,0x4b3b07,0x574307,
212 0x5f4707,0x6b4b0b,0x77530f,0x835713,0x8b5b13,0x975f1b,0xa3631f,0xaf6723,
213 0x231307,0x2f170b,0x3b1f0f,0x4b2313,0x572b17,0x632f1f,0x733723,0x7f3b2b,
214 0x8f4333,0x9f4f33,0xaf632f,0xbf772f,0xcf8f2b,0xdfab27,0xefcb1f,0xfff31b,
215 0x0b0700,0x1b1300,0x2b230f,0x372b13,0x47331b,0x533723,0x633f2b,0x6f4733,
216 0x7f533f,0x8b5f47,0x9b6b53,0xa77b5f,0xb7876b,0xc3937b,0xd3a38b,0xe3b397,
217 0xab8ba3,0x9f7f97,0x937387,0x8b677b,0x7f5b6f,0x775363,0x6b4b57,0x5f3f4b,
218 0x573743,0x4b2f37,0x43272f,0x371f23,0x2b171b,0x231313,0x170b0b,0x0f0707,
219 0xbb739f,0xaf6b8f,0xa35f83,0x975777,0x8b4f6b,0x7f4b5f,0x734353,0x6b3b4b,
220 0x5f333f,0x532b37,0x47232b,0x3b1f23,0x2f171b,0x231313,0x170b0b,0x0f0707,
221 0xdbc3bb,0xcbb3a7,0xbfa39b,0xaf978b,0xa3877b,0x977b6f,0x876f5f,0x7b6353,
222 0x6b5747,0x5f4b3b,0x533f33,0x433327,0x372b1f,0x271f17,0x1b130f,0x0f0b07,
223 0x6f837b,0x677b6f,0x5f7367,0x576b5f,0x4f6357,0x475b4f,0x3f5347,0x374b3f,
224 0x2f4337,0x2b3b2f,0x233327,0x1f2b1f,0x172317,0x0f1b13,0x0b130b,0x070b07,
225 0xfff31b,0xefdf17,0xdbcb13,0xcbb70f,0xbba70f,0xab970b,0x9b8307,0x8b7307,
226 0x7b6307,0x6b5300,0x5b4700,0x4b3700,0x3b2b00,0x2b1f00,0x1b0f00,0x0b0700,
227 0x0000ff,0x0b0bef,0x1313df,0x1b1bcf,0x2323bf,0x2b2baf,0x2f2f9f,0x2f2f8f,
228 0x2f2f7f,0x2f2f6f,0x2f2f5f,0x2b2b4f,0x23233f,0x1b1b2f,0x13131f,0x0b0b0f,
229 0x2b0000,0x3b0000,0x4b0700,0x5f0700,0x6f0f00,0x7f1707,0x931f07,0xa3270b,
230 0xb7330f,0xc34b1b,0xcf632b,0xdb7f3b,0xe3974f,0xe7ab5f,0xefbf77,0xf7d38b,
231 0xa77b3b,0xb79b37,0xc7c337,0xe7e357,0x7fbfff,0xabe7ff,0xd7ffff,0x670000,
232 0x8b0000,0xb30000,0xd70000,0xff0000,0xfff393,0xfff7c7,0xffffff,0x9f5b53
235 //static int explosparkramp[8] = {0x4b0700, 0x6f0f00, 0x931f07, 0xb7330f, 0xcf632b, 0xe3974f, 0xffe7b5, 0xffffff};
237 // these must match r_part.c's textures
238 static const int tex_smoke[8] = {0, 1, 2, 3, 4, 5, 6, 7};
239 //static const int tex_rainsplash[16] = {8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23};
240 static const int tex_particle = 24;
241 //static const int tex_rain = 25;
242 static const int tex_bubble = 26;
244 static int cl_maxparticles;
245 static int cl_numparticles;
246 static particle_t *particles;
247 static particle_t **freeparticles; // list used only in compacting particles array
249 cvar_t cl_particles = {CVAR_SAVE, "cl_particles", "1"};
250 cvar_t cl_particles_size = {CVAR_SAVE, "cl_particles_size", "1"};
251 cvar_t cl_particles_bloodshowers = {CVAR_SAVE, "cl_particles_bloodshowers", "1"};
252 cvar_t cl_particles_blood = {CVAR_SAVE, "cl_particles_blood", "1"};
253 cvar_t cl_particles_blood_size = {CVAR_SAVE, "cl_particles_blood_size", "8"};
254 cvar_t cl_particles_blood_alpha = {CVAR_SAVE, "cl_particles_blood_alpha", "0.5"};
255 cvar_t cl_particles_bulletimpacts = {CVAR_SAVE, "cl_particles_bulletimpacts", "1"};
256 cvar_t cl_particles_smoke = {CVAR_SAVE, "cl_particles_smoke", "1"};
257 cvar_t cl_particles_sparks = {CVAR_SAVE, "cl_particles_sparks", "1"};
258 cvar_t cl_particles_bubbles = {CVAR_SAVE, "cl_particles_bubbles", "1"};
260 #ifndef WORKINGLQUAKE
261 static mempool_t *cl_part_mempool;
264 void CL_Particles_Clear(void)
274 void CL_ReadPointFile_f (void);
275 void CL_Particles_Init (void)
279 i = COM_CheckParm ("-particles");
281 if (i && i < com_argc - 1)
283 cl_maxparticles = (int)(atoi(com_argv[i+1]));
284 if (cl_maxparticles < ABSOLUTE_MIN_PARTICLES)
285 cl_maxparticles = ABSOLUTE_MIN_PARTICLES;
288 cl_maxparticles = MAX_PARTICLES;
290 Cmd_AddCommand ("pointfile", CL_ReadPointFile_f);
292 Cvar_RegisterVariable (&cl_particles);
293 Cvar_RegisterVariable (&cl_particles_size);
294 Cvar_RegisterVariable (&cl_particles_bloodshowers);
295 Cvar_RegisterVariable (&cl_particles_blood);
296 Cvar_RegisterVariable (&cl_particles_blood_size);
297 Cvar_RegisterVariable (&cl_particles_blood_alpha);
298 Cvar_RegisterVariable (&cl_particles_bulletimpacts);
299 Cvar_RegisterVariable (&cl_particles_smoke);
300 Cvar_RegisterVariable (&cl_particles_sparks);
301 Cvar_RegisterVariable (&cl_particles_bubbles);
304 particles = (particle_t *) Hunk_AllocName(cl_maxparticles * sizeof(particle_t), "particles");
305 freeparticles = (void *) Hunk_AllocName(cl_maxparticles * sizeof(particle_t *), "particles");
307 cl_part_mempool = Mem_AllocPool("CL_Part");
308 particles = (particle_t *) Mem_Alloc(cl_part_mempool, cl_maxparticles * sizeof(particle_t));
309 freeparticles = (void *) Mem_Alloc(cl_part_mempool, cl_maxparticles * sizeof(particle_t *));
314 #define particle(ptype, porientation, pcolor1, pcolor2, ptex, plight, padditive, pscalex, pscaley, palpha, palphafade, ptime, pgravity, pbounce, px, py, pz, pvx, pvy, pvz, ptime2, pvx2, pvy2, pvz2, pfriction, ppressure)\
316 if (cl_numparticles >= cl_maxparticles)\
320 int tempcolor, tempcolor2, cr1, cg1, cb1, cr2, cg2, cb2;\
321 unsigned int partflags;\
322 partflags = ((porientation) << P_ORIENTATION_FIRSTBIT) | ((ptex) << P_TEXNUM_FIRSTBIT);\
324 partflags |= P_ADDITIVE;\
326 /* partflags |= P_DYNLIGHT;*/\
327 tempcolor = (pcolor1);\
328 tempcolor2 = (pcolor2);\
329 cr2 = ((tempcolor2) >> 16) & 0xFF;\
330 cg2 = ((tempcolor2) >> 8) & 0xFF;\
331 cb2 = (tempcolor2) & 0xFF;\
332 if (tempcolor != tempcolor2)\
334 cr1 = ((tempcolor) >> 16) & 0xFF;\
335 cg1 = ((tempcolor) >> 8) & 0xFF;\
336 cb1 = (tempcolor) & 0xFF;\
337 tempcolor = rand() & 0xFF;\
338 cr2 = (((cr2 - cr1) * tempcolor) >> 8) + cr1;\
339 cg2 = (((cg2 - cg1) * tempcolor) >> 8) + cg1;\
340 cb2 = (((cb2 - cb1) * tempcolor) >> 8) + cb1;\
342 part = &particles[cl_numparticles++];\
343 part->type = (ptype);\
344 part->color[0] = cr2;\
345 part->color[1] = cg2;\
346 part->color[2] = cb2;\
347 part->color[3] = 0xFF;\
348 part->flags = partflags;\
349 part->scalex = (pscalex);\
350 part->scaley = (pscaley);\
351 part->alpha = (palpha);\
352 part->alphafade = (palphafade);\
353 part->die = cl.time + (ptime);\
354 part->gravity = (pgravity);\
355 part->bounce = (pbounce);\
356 part->org[0] = (px);\
357 part->org[1] = (py);\
358 part->org[2] = (pz);\
359 part->vel[0] = (pvx);\
360 part->vel[1] = (pvy);\
361 part->vel[2] = (pvz);\
362 part->time2 = (ptime2);\
363 part->vel2[0] = (pvx2);\
364 part->vel2[1] = (pvy2);\
365 part->vel2[2] = (pvz2);\
366 part->friction = (pfriction);\
367 part->pressure = (ppressure);\
376 void CL_EntityParticles (entity_t *ent)
380 float sp, sy, cp, cy;
384 static vec3_t avelocities[NUMVERTEXNORMALS];
385 if (!cl_particles.integer) return;
390 if (!avelocities[0][0])
391 for (i=0 ; i<NUMVERTEXNORMALS*3 ; i++)
392 avelocities[0][i] = (rand()&255) * 0.01;
394 for (i=0 ; i<NUMVERTEXNORMALS ; i++)
396 angle = cl.time * avelocities[i][0];
399 angle = cl.time * avelocities[i][1];
408 particle(pt_static, PARTICLE_BILLBOARD, particlepalette[0x6f], particlepalette[0x6f], tex_particle, false, false, 2, 2, 255, 0, 0, 0, 0, ent->origin[0] + m_bytenormals[i][0]*dist + forward[0]*beamlength, ent->origin[1] + m_bytenormals[i][1]*dist + forward[1]*beamlength, ent->origin[2] + m_bytenormals[i][2]*dist + forward[2]*beamlength, 0, 0, 0, 0, 0, 0, 0, 0, 0);
410 particle(pt_static, PARTICLE_BILLBOARD, particlepalette[0x6f], particlepalette[0x6f], tex_particle, false, false, 2, 2, 255, 0, 0, 0, 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);
416 void CL_ReadPointFile_f (void)
420 char *pointfile = NULL, *pointfilepos, *t, tchar;
422 char name[MAX_OSPATH];
424 sprintf (name,"maps/%s.pts", cl.worldmodel->name);
425 COM_FOpenFile (name, &f);
429 fseek(f, 0, SEEK_END);
430 pointfilelength = ftell(f);
431 fseek(f, 0, SEEK_SET);
432 pointfile = malloc(pointfilelength + 1);
433 fread(pointfile, 1, pointfilelength, f);
434 pointfile[pointfilelength] = 0;
438 pointfile = COM_LoadFile(va("maps/%s.pts", cl.worldmodel->name), true);
442 Con_Printf ("couldn't open %s.pts\n", cl.worldmodel->name);
446 Con_Printf ("Reading %s.pts...\n", cl.worldmodel->name);
448 pointfilepos = pointfile;
449 while (*pointfilepos)
451 while (*pointfilepos == '\n' || *pointfilepos == '\r')
456 while (*t && *t != '\n' && *t != '\r')
460 r = sscanf (pointfilepos,"%f %f %f", &org[0], &org[1], &org[2]);
467 if (cl_numparticles >= cl_maxparticles)
469 Con_Printf ("Not enough free particles\n");
472 particle(pt_static, PARTICLE_BILLBOARD, particlepalette[(-c)&15], particlepalette[(-c)&15], tex_particle, false, false, 2, 2, 255, 0, 99999, 0, 0, org[0], org[1], org[2], 0, 0, 0, 0, 0, 0, 0, 0, 0);
480 Con_Printf ("%i points read\n", c);
485 CL_ParseParticleEffect
487 Parse an effect out of the server message
490 void CL_ParseParticleEffect (void)
493 int i, count, msgcount, color;
495 for (i=0 ; i<3 ; i++)
496 org[i] = MSG_ReadCoord ();
497 for (i=0 ; i<3 ; i++)
498 dir[i] = MSG_ReadChar () * (1.0/16);
499 msgcount = MSG_ReadByte ();
500 color = MSG_ReadByte ();
507 CL_RunParticleEffect (org, dir, color, count);
516 void CL_ParticleExplosion (vec3_t org)
521 if (cl_stainmaps.integer)
522 R_Stain(org, 96, 80, 80, 80, 64, 176, 176, 176, 64);
524 i = Mod_PointContents(org, cl.worldmodel);
525 if ((i == CONTENTS_SLIME || i == CONTENTS_WATER) && cl_particles.integer && cl_particles_bubbles.integer)
527 for (i = 0;i < 128;i++)
529 particle(pt_bubble, PARTICLE_BILLBOARD, 0x404040, 0x808080, tex_bubble, false, true, 2, 2, lhrandom(128, 255), 256, 9999, -0.25, 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, (1.0 / 16.0), 0);
535 // LordHavoc: smoke effect similar to UT2003, chews fillrate too badly up close
537 if (cl_particles_smoke.integer)
539 for (i = 0;i < 64;i++)
542 v2[0] = lhrandom(-64, 64);
543 v2[1] = lhrandom(-64, 64);
544 v2[2] = lhrandom(-8, 24);
546 for (k = 0;k < 16;k++)
548 v[0] = org[0] + lhrandom(-64, 64);
549 v[1] = org[1] + lhrandom(-64, 64);
550 v[2] = org[2] + lhrandom(-8, 24);
551 if (CL_TraceLine(org, v, v2, NULL, 0, true, NULL) >= 0.1)
554 VectorSubtract(v2, org, v2);
556 VectorScale(v2, 2.0f, v2);
557 particle(pt_static, PARTICLE_BILLBOARD, 0x101010, 0x202020, tex_smoke[rand()&7], true, true, 12, 12, 255, 512, 9999, 0, 0, org[0], org[1], org[2], v2[0], v2[1], v2[2], 0, 0, 0, 0, 0, 0);
562 if (cl_particles_sparks.integer)
565 for (i = 0;i < 256;i++)
567 k = particlepalette[0x68 + (rand() & 7)];
568 particle(pt_static, PARTICLE_BEAM, k, k, tex_particle, false, true, 1.5f, 0.05f, lhrandom(0, 255), 512, 9999, 1, 0, org[0], org[1], org[2], lhrandom(-192, 192), lhrandom(-192, 192), lhrandom(-192, 192) + 160, 0, 0, 0, 0, 0, 0);
573 if (cl_explosions.integer)
579 CL_ParticleExplosion2
583 void CL_ParticleExplosion2 (vec3_t org, int colorStart, int colorLength)
586 if (!cl_particles.integer) return;
588 for (i = 0;i < 512;i++)
590 k = particlepalette[colorStart + (i % colorLength)];
591 particle(pt_static, PARTICLE_BILLBOARD, k, k, tex_particle, false, false, 1.5, 1.5, 255, 384, 0.3, 0, 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), 0, 0, 0, 0, 1, 0);
601 void CL_BlobExplosion (vec3_t org)
603 if (cl_stainmaps.integer)
604 R_Stain(org, 96, 80, 80, 80, 64, 176, 176, 176, 64);
606 if (cl_explosions.integer)
616 void CL_RunParticleEffect (vec3_t org, vec3_t dir, int color, int count)
622 CL_ParticleExplosion(org);
625 if (!cl_particles.integer) return;
628 k = particlepalette[color + (rand()&7)];
629 particle(pt_static, PARTICLE_BILLBOARD, k, k, tex_particle, false, false, 1, 1, 255, 512, 9999, 0, 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), 0, 0, 0, 0, 0, 0);
633 // LordHavoc: added this for spawning sparks/dust (which have strong gravity)
639 void CL_SparkShower (vec3_t org, vec3_t dir, int count)
642 if (!cl_particles.integer) return;
644 if (cl_stainmaps.integer)
645 R_Stain(org, 32, 96, 96, 96, 24, 128, 128, 128, 24);
647 if (cl_particles_bulletimpacts.integer)
650 if (cl_particles_smoke.integer)
655 particle(pt_grow, PARTICLE_BILLBOARD, 0x101010, 0x202020, tex_smoke[rand()&7], true, true, 3, 3, 255, 1024, 9999, -0.2, 0, org[0] + 0.125f * lhrandom(-count, count), org[1] + 0.125f * lhrandom (-count, count), org[2] + 0.125f * lhrandom(-count, count), lhrandom(-8, 8), lhrandom(-8, 8), lhrandom(0, 16), 15, 0, 0, 0, 0, 0);
659 if (cl_particles_sparks.integer)
664 k = particlepalette[0x68 + (rand() & 7)];
665 particle(pt_static, PARTICLE_BEAM, k, k, tex_particle, false, true, 0.4f, 0.015f, lhrandom(64, 255), 512, 9999, 1, 0, org[0], org[1], org[2], lhrandom(-64, 64) + dir[0], lhrandom(-64, 64) + dir[1], lhrandom(0, 128) + dir[2], 0, 0, 0, 0, 0, 0);
671 void CL_PlasmaBurn (vec3_t org)
673 if (cl_stainmaps.integer)
674 R_Stain(org, 48, 96, 96, 96, 32, 128, 128, 128, 32);
677 static float bloodcount = 0;
678 void CL_BloodPuff (vec3_t org, vec3_t vel, int count)
681 // bloodcount is used to accumulate counts too small to cause a blood particle
682 if (!cl_particles.integer) return;
683 if (!cl_particles_blood.integer) return;
690 r = cl_particles_blood_size.value;
691 a = cl_particles_blood_alpha.value * 255;
692 while(bloodcount > 0)
694 particle(pt_blood, PARTICLE_BILLBOARD, 0x000000, 0x200000, tex_smoke[rand()&7], true, false, r, r, a, a * 0.5, 9999, 0, -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);
699 void CL_BloodShower (vec3_t mins, vec3_t maxs, float velspeed, int count)
703 vec3_t diff, center, velscale;
704 if (!cl_particles.integer) return;
705 if (!cl_particles_bloodshowers.integer) return;
706 if (!cl_particles_blood.integer) return;
708 VectorSubtract(maxs, mins, diff);
709 center[0] = (mins[0] + maxs[0]) * 0.5;
710 center[1] = (mins[1] + maxs[1]) * 0.5;
711 center[2] = (mins[2] + maxs[2]) * 0.5;
712 // FIXME: change velspeed back to 2.0x after fixing mod
713 velscale[0] = velspeed * 2.0 / diff[0];
714 velscale[1] = velspeed * 2.0 / diff[1];
715 velscale[2] = velspeed * 2.0 / diff[2];
717 bloodcount += count * 5.0f;
718 r = cl_particles_blood_size.value;
719 a = cl_particles_blood_alpha.value * 255;
720 while (bloodcount > 0)
723 org[0] = lhrandom(mins[0], maxs[0]);
724 org[1] = lhrandom(mins[1], maxs[1]);
725 org[2] = lhrandom(mins[2], maxs[2]);
726 vel[0] = (org[0] - center[0]) * velscale[0];
727 vel[1] = (org[1] - center[1]) * velscale[1];
728 vel[2] = (org[2] - center[2]) * velscale[2];
730 particle(pt_blood, PARTICLE_BILLBOARD, 0x000000, 0x200000, tex_smoke[rand()&7], true, false, r, r, a, a * 0.5, 9999, 0, -1, org[0], org[1], org[2], vel[0], vel[1], vel[2], 0, 0, 0, 0, 1, 0);
734 void CL_ParticleCube (vec3_t mins, vec3_t maxs, vec3_t dir, int count, int colorbase, int gravity, int randomvel)
738 if (!cl_particles.integer) return;
739 if (maxs[0] <= mins[0]) {t = mins[0];mins[0] = maxs[0];maxs[0] = t;}
740 if (maxs[1] <= mins[1]) {t = mins[1];mins[1] = maxs[1];maxs[1] = t;}
741 if (maxs[2] <= mins[2]) {t = mins[2];mins[2] = maxs[2];maxs[2] = t;}
745 k = particlepalette[colorbase + (rand()&3)];
746 particle(pt_static, PARTICLE_BILLBOARD, k, k, tex_particle, false, false, 2, 2, 255, 0, lhrandom(1, 2), gravity ? 1 : 0, 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);
750 void CL_ParticleRain (vec3_t mins, vec3_t maxs, vec3_t dir, int count, int colorbase, int type)
753 float t, z, minz, maxz;
754 if (!cl_particles.integer) return;
755 if (maxs[0] <= mins[0]) {t = mins[0];mins[0] = maxs[0];maxs[0] = t;}
756 if (maxs[1] <= mins[1]) {t = mins[1];mins[1] = maxs[1];maxs[1] = t;}
757 if (maxs[2] <= mins[2]) {t = mins[2];mins[2] = maxs[2];maxs[2] = t;}
758 if (dir[2] < 0) // falling
760 t = (maxs[2] - mins[2]) / -dir[2];
765 t = (maxs[2] - mins[2]) / dir[2];
768 if (t < 0 || t > 2) // sanity check
771 minz = z - fabs(dir[2]) * 0.1;
772 maxz = z + fabs(dir[2]) * 0.1;
773 minz = bound(mins[2], minz, maxs[2]);
774 maxz = bound(mins[2], maxz, maxs[2]);
779 count *= 4; // ick, this should be in the mod or maps?
783 k = particlepalette[colorbase + (rand()&3)];
784 particle(pt_rain, PARTICLE_BEAM, k, k, tex_particle, true, true, 0.5, 0.02, lhrandom(8, 16), 0, t, 0, 0, lhrandom(mins[0], maxs[0]), lhrandom(mins[1], maxs[1]), lhrandom(minz, maxz), dir[0], dir[1], dir[2], cl.time + 9999, dir[0], dir[1], dir[2], 0, 0);
790 k = particlepalette[colorbase + (rand()&3)];
791 particle(pt_rain, PARTICLE_BILLBOARD, k, k, tex_particle, false, true, 1, 1, lhrandom(64, 128), 0, t, 0, 0, lhrandom(mins[0], maxs[0]), lhrandom(mins[1], maxs[1]), lhrandom(minz, maxz), dir[0], dir[1], dir[2], 0, dir[0], dir[1], dir[2], 0, 0);
795 Host_Error("CL_ParticleRain: unknown type %i (0 = rain, 1 = snow)\n", type);
799 void CL_Stardust (vec3_t mins, vec3_t maxs, int count)
804 if (!cl_particles.integer) return;
806 if (maxs[0] <= mins[0]) {t = mins[0];mins[0] = maxs[0];maxs[0] = t;}
807 if (maxs[1] <= mins[1]) {t = mins[1];mins[1] = maxs[1];maxs[1] = t;}
808 if (maxs[2] <= mins[2]) {t = mins[2];mins[2] = maxs[2];maxs[2] = t;}
810 center[0] = (mins[0] + maxs[0]) * 0.5f;
811 center[1] = (mins[1] + maxs[1]) * 0.5f;
812 center[2] = (mins[2] + maxs[2]) * 0.5f;
816 k = particlepalette[224 + (rand()&15)];
817 o[0] = lhrandom(mins[0], maxs[0]);
818 o[1] = lhrandom(mins[1], maxs[1]);
819 o[2] = lhrandom(mins[2], maxs[2]);
820 VectorSubtract(o, center, v);
821 VectorNormalizeFast(v);
822 VectorScale(v, 100, v);
823 v[2] += sv_gravity.value * 0.15f;
824 particle(pt_static, PARTICLE_BILLBOARD, 0x903010, 0xFFD030, tex_particle, false, true, 1.5, 1.5, lhrandom(64, 128), 128, 9999, 1, 0, o[0], o[1], o[2], v[0], v[1], v[2], 0, 0, 0, 0, 0, 0);
828 void CL_FlameCube (vec3_t mins, vec3_t maxs, int count)
832 if (!cl_particles.integer) return;
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;}
839 k = particlepalette[224 + (rand()&15)];
840 particle(pt_static, PARTICLE_BILLBOARD, k, k, tex_particle, false, true, 4, 4, lhrandom(64, 128), 384, 9999, -1, 0, lhrandom(mins[0], maxs[0]), lhrandom(mins[1], maxs[1]), lhrandom(mins[2], maxs[2]), lhrandom(-32, 32), lhrandom(-32, 32), lhrandom(0, 64), 0, 0, 0, 0, 1, 0);
842 particle(pt_static, PARTICLE_BILLBOARD, 0x303030, 0x606060, tex_smoke[rand()&7], false, true, 6, 6, lhrandom(48, 96), 64, 9999, 0, 0, lhrandom(mins[0], maxs[0]), lhrandom(mins[1], maxs[1]), lhrandom(mins[2], maxs[2]), lhrandom(-8, 8), lhrandom(-8, 8), lhrandom(0, 32), 0, 0, 0, 0, 0, 0);
846 void CL_Flames (vec3_t org, vec3_t vel, int count)
849 if (!cl_particles.integer) return;
853 k = particlepalette[224 + (rand()&15)];
854 particle(pt_static, PARTICLE_BILLBOARD, k, k, tex_particle, false, true, 4, 4, lhrandom(64, 128), 384, 9999, -1, 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);
866 void CL_LavaSplash (vec3_t origin)
871 if (!cl_particles.integer) return;
873 for (i=-128 ; i<128 ; i+=16)
875 for (j=-128 ; j<128 ; j+=16)
877 dir[0] = j + lhrandom(0, 8);
878 dir[1] = i + lhrandom(0, 8);
880 org[0] = origin[0] + dir[0];
881 org[1] = origin[1] + dir[1];
882 org[2] = origin[2] + lhrandom(0, 64);
883 vel = lhrandom(50, 120) / VectorLength(dir); // normalize and scale
884 k = particlepalette[224 + (rand()&7)];
885 particle(pt_static, PARTICLE_BILLBOARD, k, k, tex_particle, false, true, 7, 7, 255, 192, 9999, 0.05, 0, org[0], org[1], org[2], dir[0] * vel, dir[1] * vel, dir[2] * vel, 0, 0, 0, 0, 0, 0);
897 void R_TeleportSplash (vec3_t org)
900 if (!cl_particles.integer) return;
902 for (i=-16 ; i<16 ; i+=8)
903 for (j=-16 ; j<16 ; j+=8)
904 for (k=-24 ; k<32 ; k+=8)
905 particle(pt_static, PARTICLE_BILLBOARD, 0xA0A0A0, 0xFFFFFF, tex_particle, false, true, 10, 10, lhrandom(64, 128), 256, 9999, 0, 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), 0, 0, 0, 0, 1, 0);
910 void R_RocketTrail (vec3_t start, vec3_t end, int type)
912 void CL_RocketTrail (vec3_t start, vec3_t end, int type, entity_t *ent)
915 vec3_t vec, dir, vel, pos;
916 float len, dec, speed, r;
917 int contents, smoke, blood, bubbles;
919 VectorSubtract(end, start, dir);
920 VectorNormalize(dir);
922 VectorSubtract (end, start, vec);
924 len = VectorNormalize (vec);
926 speed = 1.0f / cl.frametime;
927 VectorSubtract(end, start, vel);
929 len = VectorNormalizeLength (vec);
930 dec = -ent->persistent.trail_time;
931 ent->persistent.trail_time += len;
932 if (ent->persistent.trail_time < 0.01f)
935 // if we skip out, leave it reset
936 ent->persistent.trail_time = 0.0f;
938 speed = 1.0f / (ent->state_current.time - ent->state_previous.time);
939 VectorSubtract(ent->state_current.origin, ent->state_previous.origin, vel);
941 VectorScale(vel, speed, vel);
943 // advance into this frame to reach the first puff location
944 VectorMA(start, dec, vec, pos);
947 contents = Mod_PointContents(pos, cl.worldmodel);
948 if (contents == CONTENTS_SKY || contents == CONTENTS_LAVA)
951 smoke = cl_particles.integer && cl_particles_smoke.integer;
952 blood = cl_particles.integer && cl_particles_blood.integer;
953 bubbles = cl_particles.integer && cl_particles_bubbles.integer && (contents == CONTENTS_WATER || contents == CONTENTS_SLIME);
959 case 0: // rocket trail
963 particle(pt_grow, PARTICLE_BILLBOARD, 0x303030, 0x606060, tex_smoke[rand()&7], false, true, dec, dec, 32, 64, 9999, 0, 0, pos[0], pos[1], pos[2], lhrandom(-5, 5), lhrandom(-5, 5), lhrandom(-5, 5), 6, 0, 0, 0, 0, 0);
964 particle(pt_static, PARTICLE_BILLBOARD, 0x801010, 0xFFA020, tex_smoke[rand()&7], false, true, dec, dec, 128, 768, 9999, 0, 0, pos[0], pos[1], pos[2], lhrandom(-20, 20), lhrandom(-20, 20), lhrandom(-20, 20), 0, 0, 0, 0, 0, 0);
969 particle(pt_bubble, PARTICLE_BILLBOARD, 0x404040, 0x808080, tex_bubble, false, true, r, r, lhrandom(64, 255), 256, 9999, -0.25, 1.5, pos[0], pos[1], pos[2], lhrandom(-16, 16), lhrandom(-16, 16), lhrandom(-16, 16), 0, 0, 0, 0, (1.0 / 16.0), 0);
973 case 1: // grenade trail
974 // FIXME: make it gradually stop smoking
976 if (cl_particles.integer && cl_particles_smoke.integer)
978 particle(pt_static, PARTICLE_BILLBOARD, 0x303030, 0x606060, tex_smoke[rand()&7], false, true, dec, dec, 32, 96, 9999, 0, 0, pos[0], pos[1], pos[2], lhrandom(-5, 5), lhrandom(-5, 5), lhrandom(-5, 5), 0, 0, 0, 0, 0, 0);
984 case 4: // slight blood
985 dec = cl_particles_blood_size.value;
988 particle(pt_blood, PARTICLE_BILLBOARD, 0x100000, 0x280000, tex_smoke[rand()&7], true, false, dec, dec, cl_particles_blood_alpha.value * 255.0f, cl_particles_blood_alpha.value * 255.0f * 0.5, 9999, 0, -1, pos[0], pos[1], pos[2], vel[0] * 0.5f + lhrandom(-64, 64), vel[1] * 0.5f + lhrandom(-64, 64), vel[2] * 0.5f + lhrandom(-64, 64), 0, 0, 0, 0, 1, 0);
992 case 3: // green tracer
996 particle(pt_static, PARTICLE_BILLBOARD, 0x002000, 0x003000, tex_particle, false, true, dec, dec, 128, 384, 9999, 0, 0, pos[0], pos[1], pos[2], lhrandom(-8, 8), lhrandom(-8, 8), lhrandom(-8, 8), 0, 0, 0, 0, 0, 0);
1000 case 5: // flame tracer
1004 particle(pt_static, PARTICLE_BILLBOARD, 0x301000, 0x502000, tex_particle, false, true, dec, dec, 128, 384, 9999, 0, 0, pos[0], pos[1], pos[2], lhrandom(-8, 8), lhrandom(-8, 8), lhrandom(-8, 8), 0, 0, 0, 0, 0, 0);
1008 case 6: // voor trail
1012 particle(pt_static, PARTICLE_BILLBOARD, 0x502030, 0x502030, tex_particle, false, true, dec, dec, 128, 384, 9999, 0, 0, pos[0], pos[1], pos[2], lhrandom(-8, 8), lhrandom(-8, 8), lhrandom(-8, 8), 0, 0, 0, 0, 0, 0);
1016 case 7: // Nehahra smoke tracer
1020 particle(pt_static, PARTICLE_BILLBOARD, 0x303030, 0x606060, tex_smoke[rand()&7], true, false, dec, dec, 64, 320, 9999, 0, 0, pos[0], pos[1], pos[2], lhrandom(-4, 4), lhrandom(-4, 4), lhrandom(0, 16), 0, 0, 0, 0, 0, 0);
1025 // advance to next time and position
1027 VectorMA (pos, dec, vec, pos);
1029 #ifndef WORKINGLQUAKE
1030 ent->persistent.trail_time = len;
1034 void CL_RocketTrail2 (vec3_t start, vec3_t end, int color, entity_t *ent)
1038 if (!cl_particles.integer) return;
1039 if (!cl_particles_smoke.integer) return;
1041 VectorCopy(start, pos);
1042 VectorSubtract (end, start, vec);
1043 #ifdef WORKINGLQUAKE
1044 len = (int) (VectorNormalize (vec) * (1.0f / 3.0f));
1046 len = (int) (VectorNormalizeLength (vec) * (1.0f / 3.0f));
1048 VectorScale(vec, 3, vec);
1049 color = particlepalette[color];
1052 particle(pt_static, PARTICLE_BILLBOARD, color, color, tex_particle, false, false, 5, 5, 128, 320, 9999, 0, 0, pos[0], pos[1], pos[2], 0, 0, 0, 0, 0, 0, 0, 0, 0);
1053 VectorAdd (pos, vec, pos);
1063 void CL_MoveParticles (void)
1066 int i, activeparticles, maxparticle, j, a, pressureused = false, content;
1067 float gravity, dvel, bloodwaterfade, frametime, f, dist, normal[3], v[3], org[3];
1069 // LordHavoc: early out condition
1070 if (!cl_numparticles)
1073 #ifdef WORKINGLQUAKE
1074 frametime = cl.frametime;
1076 frametime = cl.time - cl.oldtime;
1078 gravity = frametime * sv_gravity.value;
1079 dvel = 1+4*frametime;
1080 bloodwaterfade = max(cl_particles_blood_alpha.value, 0.01f) * frametime * 128.0f;
1082 activeparticles = 0;
1085 for (i = 0, p = particles;i < cl_numparticles;i++, p++)
1088 VectorCopy(p->org, p->oldorg);
1089 VectorMA(p->org, frametime, p->vel, p->org);
1090 VectorCopy(p->org, org);
1091 #ifndef WORKINGLQUAKE
1094 if (CL_TraceLine(p->oldorg, p->org, v, normal, 0, true, NULL) < 1)
1096 VectorCopy(v, p->org);
1099 // assume it's blood (lame, but...)
1100 if (cl_stainmaps.integer)
1101 R_Stain(v, 32, 32, 16, 16, p->alpha * p->scalex * (1.0f / 40.0f), 192, 48, 48, p->alpha * p->scalex * (1.0f / 40.0f));
1103 freeparticles[j++] = p;
1108 dist = DotProduct(p->vel, normal) * -p->bounce;
1109 VectorMA(p->vel, dist, normal, p->vel);
1110 if (DotProduct(p->vel, p->vel) < 0.03)
1111 VectorClear(p->vel);
1116 p->vel[2] -= p->gravity * gravity;
1117 p->alpha -= p->alphafade * frametime;
1120 f = p->friction * frametime;
1122 content = Mod_PointContents(p->org, cl.worldmodel);
1123 if (content != CONTENTS_EMPTY)
1126 VectorScale(p->vel, f, p->vel);
1129 if (p->type != pt_static)
1135 content = Mod_PointContents(p->org, cl.worldmodel);
1137 if (a != CONTENTS_EMPTY)
1139 if (a == CONTENTS_WATER || a == CONTENTS_SLIME)
1141 p->scalex += frametime * cl_particles_blood_size.value;
1142 p->scaley += frametime * cl_particles_blood_size.value;
1143 //p->alpha -= bloodwaterfade;
1149 p->vel[2] -= gravity;
1153 content = Mod_PointContents(p->org, cl.worldmodel);
1154 if (content != CONTENTS_WATER && content != CONTENTS_SLIME)
1161 if (cl.time > p->time2)
1164 p->time2 = cl.time + (rand() & 3) * 0.1;
1165 p->vel[0] = lhrandom(-32, 32) + p->vel2[0];
1166 p->vel[1] = lhrandom(-32, 32) + p->vel2[1];
1167 p->vel[2] = /*lhrandom(-32, 32) +*/ p->vel2[2];
1170 content = Mod_PointContents(p->org, cl.worldmodel);
1172 if (a != CONTENTS_EMPTY && a != CONTENTS_SKY)
1176 p->scalex += frametime * p->time2;
1177 p->scaley += frametime * p->time2;
1180 printf("unknown particle type %i\n", p->type);
1186 // remove dead particles
1187 if (p->alpha < 1 || p->die < cl.time)
1188 freeparticles[j++] = p;
1194 pressureused = true;
1197 // fill in gaps to compact the array
1199 while (maxparticle >= activeparticles)
1201 *freeparticles[i++] = particles[maxparticle--];
1202 while (maxparticle >= activeparticles && particles[maxparticle].die < cl.time)
1205 cl_numparticles = activeparticles;
1209 activeparticles = 0;
1210 for (i = 0, p = particles;i < cl_numparticles;i++, p++)
1212 freeparticles[activeparticles++] = p;
1214 if (activeparticles)
1216 for (i = 0, p = particles;i < cl_numparticles;i++, p++)
1218 for (j = 0;j < activeparticles;j++)
1220 if (freeparticles[j] != p)
1222 float dist, diff[3];
1223 VectorSubtract(p->org, freeparticles[j]->org, diff);
1224 dist = DotProduct(diff, diff);
1225 if (dist < 4096 && dist >= 1)
1227 dist = freeparticles[j]->scalex * 4.0f * frametime / sqrt(dist);
1228 VectorMA(p->vel, dist, diff, p->vel);
1237 #define MAX_PARTICLETEXTURES 64
1238 // particletexture_t is a rectangle in the particlefonttexture
1241 float s1, t1, s2, t2;
1246 static int particlefonttexture;
1248 static rtexturepool_t *particletexturepool;
1249 static rtexture_t *particlefonttexture;
1251 static particletexture_t particletexture[MAX_PARTICLETEXTURES];
1253 static cvar_t r_drawparticles = {0, "r_drawparticles", "1"};
1255 static qbyte shadebubble(float dx, float dy, vec3_t light)
1259 dz = 1 - (dx*dx+dy*dy);
1260 if (dz > 0) // it does hit the sphere
1264 normal[0] = dx;normal[1] = dy;normal[2] = dz;
1265 VectorNormalize(normal);
1266 dot = DotProduct(normal, light);
1267 if (dot > 0.5) // interior reflection
1268 f += ((dot * 2) - 1);
1269 else if (dot < -0.5) // exterior reflection
1270 f += ((dot * -2) - 1);
1272 normal[0] = dx;normal[1] = dy;normal[2] = -dz;
1273 VectorNormalize(normal);
1274 dot = DotProduct(normal, light);
1275 if (dot > 0.5) // interior reflection
1276 f += ((dot * 2) - 1);
1277 else if (dot < -0.5) // exterior reflection
1278 f += ((dot * -2) - 1);
1280 f += 16; // just to give it a haze so you can see the outline
1281 f = bound(0, f, 255);
1288 static void setuptex(int cltexnum, int rtexnum, qbyte *data, qbyte *particletexturedata)
1290 int basex, basey, y;
1291 basex = ((rtexnum >> 0) & 7) * 32;
1292 basey = ((rtexnum >> 3) & 7) * 32;
1293 particletexture[cltexnum].s1 = (basex + 1) / 256.0f;
1294 particletexture[cltexnum].t1 = (basey + 1) / 256.0f;
1295 particletexture[cltexnum].s2 = (basex + 31) / 256.0f;
1296 particletexture[cltexnum].t2 = (basey + 31) / 256.0f;
1297 for (y = 0;y < 32;y++)
1298 memcpy(particletexturedata + ((basey + y) * 256 + basex) * 4, data + y * 32 * 4, 32 * 4);
1301 static void R_InitParticleTexture (void)
1304 float dx, dy, radius, f, f2;
1305 qbyte data[32][32][4], noise1[64][64], noise2[64][64];
1307 qbyte particletexturedata[256*256*4];
1309 memset(particletexturedata, 255, sizeof(particletexturedata));
1311 // the particletexture[][] array numbers must match the cl_part.c textures
1313 for (i = 0;i < 8;i++)
1317 fractalnoise(&noise1[0][0], 64, 4);
1318 fractalnoise(&noise2[0][0], 64, 8);
1320 for (y = 0;y < 32;y++)
1323 for (x = 0;x < 32;x++)
1325 data[y][x][0] = data[y][x][1] = data[y][x][2] = 255;
1327 d = (noise2[y][x] - 128) * 3 + 192;
1329 d = (d * (256 - (int) (dx*dx+dy*dy))) >> 8;
1330 d = (d * noise1[y][x]) >> 7;
1331 d = bound(0, d, 255);
1332 data[y][x][3] = (qbyte) d;
1340 setuptex(i + 0, i + 0, &data[0][0][0], particletexturedata);
1344 for (i = 0;i < 16;i++)
1346 radius = i * 3.0f / 16.0f;
1347 f2 = 255.0f * ((15.0f - i) / 15.0f);
1348 for (y = 0;y < 32;y++)
1350 dy = (y - 16) * 0.25f;
1351 for (x = 0;x < 32;x++)
1353 dx = (x - 16) * 0.25f;
1354 data[y][x][0] = data[y][x][1] = data[y][x][2] = 255;
1355 f = (1.0 - fabs(radius - sqrt(dx*dx+dy*dy))) * f2;
1356 f = bound(0.0f, f, 255.0f);
1357 data[y][x][3] = (int) f;
1360 setuptex(i + 8, i + 16, &data[0][0][0], particletexturedata);
1364 for (y = 0;y < 32;y++)
1367 for (x = 0;x < 32;x++)
1369 data[y][x][0] = data[y][x][1] = data[y][x][2] = 255;
1371 d = (256 - (dx*dx+dy*dy));
1372 d = bound(0, d, 255);
1373 data[y][x][3] = (qbyte) d;
1376 setuptex(24, 32, &data[0][0][0], particletexturedata);
1379 light[0] = 1;light[1] = 1;light[2] = 1;
1380 VectorNormalize(light);
1381 for (y = 0;y < 32;y++)
1383 for (x = 0;x < 32;x++)
1385 data[y][x][0] = data[y][x][1] = data[y][x][2] = 255;
1386 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);
1389 setuptex(25, 33, &data[0][0][0], particletexturedata);
1392 light[0] = 1;light[1] = 1;light[2] = 1;
1393 VectorNormalize(light);
1394 for (y = 0;y < 32;y++)
1396 for (x = 0;x < 32;x++)
1398 data[y][x][0] = data[y][x][1] = data[y][x][2] = 255;
1399 data[y][x][3] = shadebubble((x - 16) * (1.0 / 16.0), (y - 16) * (1.0 / 16.0), light);
1402 setuptex(26, 34, &data[0][0][0], particletexturedata);
1405 glBindTexture(GL_TEXTURE_2D, (particlefonttexture = gl_extension_number++));
1406 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
1407 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
1409 particlefonttexture = R_LoadTexture2D(particletexturepool, "particlefont", 256, 256, particletexturedata, TEXTYPE_RGBA, TEXF_ALPHA | TEXF_PRECACHE, NULL);
1413 static void r_part_start(void)
1415 particletexturepool = R_AllocTexturePool();
1416 R_InitParticleTexture ();
1419 static void r_part_shutdown(void)
1421 R_FreeTexturePool(&particletexturepool);
1424 static void r_part_newmap(void)
1426 cl_numparticles = 0;
1429 void R_Particles_Init (void)
1431 Cvar_RegisterVariable(&r_drawparticles);
1432 #ifdef WORKINGLQUAKE
1435 R_RegisterModule("R_Particles", r_part_start, r_part_shutdown, r_part_newmap);
1439 #ifdef WORKINGLQUAKE
1440 void R_InitParticles(void)
1442 CL_Particles_Init();
1446 float varray_vertex[16];
1449 void R_DrawParticleCallback(const void *calldata1, int calldata2)
1451 int additive, texnum, orientation;
1452 float org[3], up2[3], v[3], right[3], up[3], fog, ifog, fogvec[3], cr, cg, cb, ca;
1453 particletexture_t *tex;
1454 #ifndef WORKINGLQUAKE
1457 const particle_t *p = calldata1;
1459 VectorCopy(p->org, org);
1460 orientation = (p->flags >> P_ORIENTATION_FIRSTBIT) & ((1 << P_ORIENTATION_BITS) - 1);
1461 texnum = (p->flags >> P_TEXNUM_FIRSTBIT) & ((1 << P_TEXNUM_BITS) - 1);
1462 //dynlight = p->flags & P_DYNLIGHT;
1463 additive = p->flags & P_ADDITIVE;
1465 #ifdef WORKINGLQUAKE
1467 glBlendFunc(GL_SRC_ALPHA, GL_ONE);
1469 glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
1471 memset(&m, 0, sizeof(m));
1472 m.blendfunc1 = GL_SRC_ALPHA;
1474 m.blendfunc2 = GL_ONE;
1476 m.blendfunc2 = GL_ONE_MINUS_SRC_ALPHA;
1477 m.tex[0] = R_GetTexture(particlefonttexture);
1478 R_Mesh_Matrix(&r_identitymatrix);
1482 tex = &particletexture[texnum];
1483 cr = p->color[0] * (1.0f / 255.0f);
1484 cg = p->color[1] * (1.0f / 255.0f);
1485 cb = p->color[2] * (1.0f / 255.0f);
1486 ca = p->alpha * (1.0f / 255.0f);
1487 #ifndef WORKINGLQUAKE
1490 VectorSubtract(org, r_origin, fogvec);
1491 fog = exp(fogdensity/DotProduct(fogvec,fogvec));
1498 cr += fogcolor[0] * fog;
1499 cg += fogcolor[1] * fog;
1500 cb += fogcolor[2] * fog;
1507 varray_texcoord[0][0] = tex->s2;varray_texcoord[0][1] = tex->t1;
1508 varray_texcoord[0][4] = tex->s1;varray_texcoord[0][5] = tex->t1;
1509 varray_texcoord[0][8] = tex->s1;varray_texcoord[0][9] = tex->t2;
1510 varray_texcoord[0][12] = tex->s2;varray_texcoord[0][13] = tex->t2;
1513 if (orientation == PARTICLE_BEAM)
1515 VectorMA(p->org, -p->scaley, p->vel, v);
1516 VectorMA(p->org, p->scaley, p->vel, up2);
1517 R_CalcBeamVerts(varray_vertex, v, up2, p->scalex);
1519 else if (orientation == PARTICLE_BILLBOARD)
1521 VectorScale(vright, p->scalex, right);
1522 VectorScale(vup, p->scaley, up);
1523 varray_vertex[ 0] = org[0] + right[0] - up[0];
1524 varray_vertex[ 1] = org[1] + right[1] - up[1];
1525 varray_vertex[ 2] = org[2] + right[2] - up[2];
1526 varray_vertex[ 4] = org[0] - right[0] - up[0];
1527 varray_vertex[ 5] = org[1] - right[1] - up[1];
1528 varray_vertex[ 6] = org[2] - right[2] - up[2];
1529 varray_vertex[ 8] = org[0] - right[0] + up[0];
1530 varray_vertex[ 9] = org[1] - right[1] + up[1];
1531 varray_vertex[10] = org[2] - right[2] + up[2];
1532 varray_vertex[12] = org[0] + right[0] + up[0];
1533 varray_vertex[13] = org[1] + right[1] + up[1];
1534 varray_vertex[14] = org[2] + right[2] + up[2];
1536 else if (orientation == PARTICLE_ORIENTED_DOUBLESIDED)
1539 if (DotProduct(p->vel2, r_origin) > DotProduct(p->vel2, org))
1541 VectorNegate(p->vel2, v);
1542 VectorVectors(v, right, up);
1545 VectorVectors(p->vel2, right, up);
1546 VectorScale(right, p->scalex, right);
1547 VectorScale(up, p->scaley, up);
1548 varray_vertex[ 0] = org[0] + right[0] - up[0];
1549 varray_vertex[ 1] = org[1] + right[1] - up[1];
1550 varray_vertex[ 2] = org[2] + right[2] - up[2];
1551 varray_vertex[ 4] = org[0] - right[0] - up[0];
1552 varray_vertex[ 5] = org[1] - right[1] - up[1];
1553 varray_vertex[ 6] = org[2] - right[2] - up[2];
1554 varray_vertex[ 8] = org[0] - right[0] + up[0];
1555 varray_vertex[ 9] = org[1] - right[1] + up[1];
1556 varray_vertex[10] = org[2] - right[2] + up[2];
1557 varray_vertex[12] = org[0] + right[0] + up[0];
1558 varray_vertex[13] = org[1] + right[1] + up[1];
1559 varray_vertex[14] = org[2] + right[2] + up[2];
1562 Host_Error("R_DrawParticles: unknown particle orientation %i\n", orientation);
1565 glColor4f(cr, cg, cb, ca);
1566 glTexCoord2f(tex->s2, tex->t1);glVertex3f(varray_vertex[ 0], varray_vertex[ 1], varray_vertex[ 2]);
1567 glTexCoord2f(tex->s1, tex->t1);glVertex3f(varray_vertex[ 4], varray_vertex[ 5], varray_vertex[ 6]);
1568 glTexCoord2f(tex->s1, tex->t2);glVertex3f(varray_vertex[ 8], varray_vertex[ 9], varray_vertex[10]);
1569 glTexCoord2f(tex->s2, tex->t2);glVertex3f(varray_vertex[12], varray_vertex[13], varray_vertex[14]);
1572 GL_Color(cr, cg, cb, ca);
1573 R_Mesh_Draw(4, 2, polygonelements);
1577 void R_DrawParticles (void)
1580 float minparticledist;
1583 #ifdef WORKINGLQUAKE
1587 // LordHavoc: early out conditions
1588 if ((!cl_numparticles) || (!r_drawparticles.integer))
1591 minparticledist = DotProduct(r_origin, vpn) + 16.0f;
1593 #ifdef WORKINGLQUAKE
1594 glBindTexture(GL_TEXTURE_2D, particlefonttexture);
1596 glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
1598 // LordHavoc: only render if not too close
1599 for (i = 0, p = particles;i < cl_numparticles;i++, p++)
1600 if (DotProduct(p->org, vpn) >= minparticledist)
1601 R_DrawParticleCallback(p, 0);
1603 glDisable(GL_BLEND);
1604 glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
1606 // LordHavoc: only render if not too close
1607 c_particles += cl_numparticles;
1608 for (i = 0, p = particles;i < cl_numparticles;i++, p++)
1609 if (DotProduct(p->org, vpn) >= minparticledist)
1610 R_MeshQueue_AddTransparent(p->org, R_DrawParticleCallback, p, 0);