-
Notifications
You must be signed in to change notification settings - Fork 42
/
cl_particles.c
3182 lines (2986 loc) · 134 KB
/
cl_particles.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*
Copyright (C) 1996-1997 Id Software, Inc.
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
#include "quakedef.h"
#include "cl_collision.h"
#include "image.h"
#include "r_shadow.h"
// must match ptype_t values
particletype_t particletype[pt_total] =
{
{PBLEND_INVALID, PARTICLE_INVALID, false}, //pt_dead (should never happen)
{PBLEND_ALPHA, PARTICLE_BILLBOARD, false}, //pt_alphastatic
{PBLEND_ADD, PARTICLE_BILLBOARD, false}, //pt_static
{PBLEND_ADD, PARTICLE_SPARK, false}, //pt_spark
{PBLEND_ADD, PARTICLE_HBEAM, false}, //pt_beam
{PBLEND_ADD, PARTICLE_SPARK, false}, //pt_rain
{PBLEND_ADD, PARTICLE_ORIENTED_DOUBLESIDED, false}, //pt_raindecal
{PBLEND_ADD, PARTICLE_BILLBOARD, false}, //pt_snow
{PBLEND_ADD, PARTICLE_BILLBOARD, false}, //pt_bubble
{PBLEND_INVMOD, PARTICLE_BILLBOARD, false}, //pt_blood
{PBLEND_ADD, PARTICLE_BILLBOARD, false}, //pt_smoke
{PBLEND_INVMOD, PARTICLE_ORIENTED_DOUBLESIDED, false}, //pt_decal
{PBLEND_ALPHA, PARTICLE_BILLBOARD, false}, //pt_entityparticle
};
#define PARTICLEEFFECT_UNDERWATER 1
#define PARTICLEEFFECT_NOTUNDERWATER 2
#define PARTICLEEFFECT_FORCENEAREST 4
#define PARTICLEEFFECT_DEFINED 2147483648U
typedef struct particleeffectinfo_s
{
int effectnameindex; // which effect this belongs to
// PARTICLEEFFECT_* bits
int flags;
// blood effects may spawn very few particles, so proper fraction-overflow
// handling is very important, this variable keeps track of the fraction
double particleaccumulator;
// the math is: countabsolute + requestedcount * countmultiplier * quality
// absolute number of particles to spawn, often used for decals
// (unaffected by quality and requestedcount)
float countabsolute;
// multiplier for the number of particles CL_ParticleEffect was told to
// spawn, most effects do not really have a count and hence use 1, so
// this is often the actual count to spawn, not merely a multiplier
float countmultiplier;
// if > 0 this causes the particle to spawn in an evenly spaced line from
// originmins to originmaxs (causing them to describe a trail, not a box)
float trailspacing;
// type of particle to spawn (defines some aspects of behavior)
ptype_t particletype;
// blending mode used on this particle type
pblend_t blendmode;
// orientation of this particle type (BILLBOARD, SPARK, BEAM, etc)
porientation_t orientation;
// range of colors to choose from in hex RRGGBB (like HTML color tags),
// randomly interpolated at spawn
unsigned int color[2];
// a random texture is chosen in this range (note the second value is one
// past the last choosable, so for example 8,16 chooses any from 8 up and
// including 15)
// if start and end of the range are the same, no randomization is done
int tex[2];
// range of size values randomly chosen when spawning, plus size increase over time
float size[3];
// range of alpha values randomly chosen when spawning, plus alpha fade
float alpha[3];
// how long the particle should live (note it is also removed if alpha drops to 0)
float time[2];
// how much gravity affects this particle (negative makes it fly up!)
float gravity;
// how much bounce the particle has when it hits a surface
// if negative the particle is removed on impact
float bounce;
// if in air this friction is applied
// if negative the particle accelerates
float airfriction;
// if in liquid (water/slime/lava) this friction is applied
// if negative the particle accelerates
float liquidfriction;
// these offsets are added to the values given to particleeffect(), and
// then an ellipsoid-shaped jitter is added as defined by these
// (they are the 3 radii)
float stretchfactor;
// stretch velocity factor (used for sparks)
float originoffset[3];
float relativeoriginoffset[3];
float velocityoffset[3];
float relativevelocityoffset[3];
float originjitter[3];
float velocityjitter[3];
float velocitymultiplier;
// an effect can also spawn a dlight
float lightradiusstart;
float lightradiusfade;
float lighttime;
float lightcolor[3];
qbool lightshadow;
int lightcubemapnum;
float lightcorona[2];
unsigned int staincolor[2]; // note: 0x808080 = neutral (particle's own color), these are modding factors for the particle's original color!
int staintex[2];
float stainalpha[2];
float stainsize[2];
// other parameters
float rotate[4]; // min/max base angle, min/max rotation over time
}
particleeffectinfo_t;
char particleeffectname[MAX_PARTICLEEFFECTNAME][64];
int numparticleeffectinfo;
particleeffectinfo_t particleeffectinfo[MAX_PARTICLEEFFECTINFO];
static int particlepalette[256];
/*
0x000000,0x0f0f0f,0x1f1f1f,0x2f2f2f,0x3f3f3f,0x4b4b4b,0x5b5b5b,0x6b6b6b, // 0-7
0x7b7b7b,0x8b8b8b,0x9b9b9b,0xababab,0xbbbbbb,0xcbcbcb,0xdbdbdb,0xebebeb, // 8-15
0x0f0b07,0x170f0b,0x1f170b,0x271b0f,0x2f2313,0x372b17,0x3f2f17,0x4b371b, // 16-23
0x533b1b,0x5b431f,0x634b1f,0x6b531f,0x73571f,0x7b5f23,0x836723,0x8f6f23, // 24-31
0x0b0b0f,0x13131b,0x1b1b27,0x272733,0x2f2f3f,0x37374b,0x3f3f57,0x474767, // 32-39
0x4f4f73,0x5b5b7f,0x63638b,0x6b6b97,0x7373a3,0x7b7baf,0x8383bb,0x8b8bcb, // 40-47
0x000000,0x070700,0x0b0b00,0x131300,0x1b1b00,0x232300,0x2b2b07,0x2f2f07, // 48-55
0x373707,0x3f3f07,0x474707,0x4b4b0b,0x53530b,0x5b5b0b,0x63630b,0x6b6b0f, // 56-63
0x070000,0x0f0000,0x170000,0x1f0000,0x270000,0x2f0000,0x370000,0x3f0000, // 64-71
0x470000,0x4f0000,0x570000,0x5f0000,0x670000,0x6f0000,0x770000,0x7f0000, // 72-79
0x131300,0x1b1b00,0x232300,0x2f2b00,0x372f00,0x433700,0x4b3b07,0x574307, // 80-87
0x5f4707,0x6b4b0b,0x77530f,0x835713,0x8b5b13,0x975f1b,0xa3631f,0xaf6723, // 88-95
0x231307,0x2f170b,0x3b1f0f,0x4b2313,0x572b17,0x632f1f,0x733723,0x7f3b2b, // 96-103
0x8f4333,0x9f4f33,0xaf632f,0xbf772f,0xcf8f2b,0xdfab27,0xefcb1f,0xfff31b, // 104-111
0x0b0700,0x1b1300,0x2b230f,0x372b13,0x47331b,0x533723,0x633f2b,0x6f4733, // 112-119
0x7f533f,0x8b5f47,0x9b6b53,0xa77b5f,0xb7876b,0xc3937b,0xd3a38b,0xe3b397, // 120-127
0xab8ba3,0x9f7f97,0x937387,0x8b677b,0x7f5b6f,0x775363,0x6b4b57,0x5f3f4b, // 128-135
0x573743,0x4b2f37,0x43272f,0x371f23,0x2b171b,0x231313,0x170b0b,0x0f0707, // 136-143
0xbb739f,0xaf6b8f,0xa35f83,0x975777,0x8b4f6b,0x7f4b5f,0x734353,0x6b3b4b, // 144-151
0x5f333f,0x532b37,0x47232b,0x3b1f23,0x2f171b,0x231313,0x170b0b,0x0f0707, // 152-159
0xdbc3bb,0xcbb3a7,0xbfa39b,0xaf978b,0xa3877b,0x977b6f,0x876f5f,0x7b6353, // 160-167
0x6b5747,0x5f4b3b,0x533f33,0x433327,0x372b1f,0x271f17,0x1b130f,0x0f0b07, // 168-175
0x6f837b,0x677b6f,0x5f7367,0x576b5f,0x4f6357,0x475b4f,0x3f5347,0x374b3f, // 176-183
0x2f4337,0x2b3b2f,0x233327,0x1f2b1f,0x172317,0x0f1b13,0x0b130b,0x070b07, // 184-191
0xfff31b,0xefdf17,0xdbcb13,0xcbb70f,0xbba70f,0xab970b,0x9b8307,0x8b7307, // 192-199
0x7b6307,0x6b5300,0x5b4700,0x4b3700,0x3b2b00,0x2b1f00,0x1b0f00,0x0b0700, // 200-207
0x0000ff,0x0b0bef,0x1313df,0x1b1bcf,0x2323bf,0x2b2baf,0x2f2f9f,0x2f2f8f, // 208-215
0x2f2f7f,0x2f2f6f,0x2f2f5f,0x2b2b4f,0x23233f,0x1b1b2f,0x13131f,0x0b0b0f, // 216-223
0x2b0000,0x3b0000,0x4b0700,0x5f0700,0x6f0f00,0x7f1707,0x931f07,0xa3270b, // 224-231
0xb7330f,0xc34b1b,0xcf632b,0xdb7f3b,0xe3974f,0xe7ab5f,0xefbf77,0xf7d38b, // 232-239
0xa77b3b,0xb79b37,0xc7c337,0xe7e357,0x7fbfff,0xabe7ff,0xd7ffff,0x670000, // 240-247
0x8b0000,0xb30000,0xd70000,0xff0000,0xfff393,0xfff7c7,0xffffff,0x9f5b53 // 248-255
*/
int ramp1[8] = {0x6f, 0x6d, 0x6b, 0x69, 0x67, 0x65, 0x63, 0x61};
int ramp2[8] = {0x6f, 0x6e, 0x6d, 0x6c, 0x6b, 0x6a, 0x68, 0x66};
int ramp3[8] = {0x6d, 0x6b, 6, 5, 4, 3};
//static int explosparkramp[8] = {0x4b0700, 0x6f0f00, 0x931f07, 0xb7330f, 0xcf632b, 0xe3974f, 0xffe7b5, 0xffffff};
// particletexture_t is a rectangle in the particlefonttexture
typedef struct particletexture_s
{
rtexture_t *texture;
float s1, t1, s2, t2;
}
particletexture_t;
static rtexturepool_t *particletexturepool;
static rtexture_t *particlefonttexture;
static particletexture_t particletexture[MAX_PARTICLETEXTURES];
skinframe_t *decalskinframe;
// texture numbers in particle font
static const int tex_smoke[8] = {0, 1, 2, 3, 4, 5, 6, 7};
static const int tex_bulletdecal[8] = {8, 9, 10, 11, 12, 13, 14, 15};
static const int tex_blooddecal[8] = {16, 17, 18, 19, 20, 21, 22, 23};
static const int tex_bloodparticle[8] = {24, 25, 26, 27, 28, 29, 30, 31};
static const int tex_rainsplash = 32;
static const int tex_square = 33;
static const int tex_beam = 60;
static const int tex_bubble = 62;
static const int tex_raindrop = 61;
static const int tex_particle = 63;
particleeffectinfo_t baselineparticleeffectinfo =
{
0, //int effectnameindex; // which effect this belongs to
// PARTICLEEFFECT_* bits
0, //int flags;
// blood effects may spawn very few particles, so proper fraction-overflow
// handling is very important, this variable keeps track of the fraction
0.0, //double particleaccumulator;
// the math is: countabsolute + requestedcount * countmultiplier * quality
// absolute number of particles to spawn, often used for decals
// (unaffected by quality and requestedcount)
0.0f, //float countabsolute;
// multiplier for the number of particles CL_ParticleEffect was told to
// spawn, most effects do not really have a count and hence use 1, so
// this is often the actual count to spawn, not merely a multiplier
0.0f, //float countmultiplier;
// if > 0 this causes the particle to spawn in an evenly spaced line from
// originmins to originmaxs (causing them to describe a trail, not a box)
0.0f, //float trailspacing;
// type of particle to spawn (defines some aspects of behavior)
pt_alphastatic, //ptype_t particletype;
// blending mode used on this particle type
PBLEND_ALPHA, //pblend_t blendmode;
// orientation of this particle type (BILLBOARD, SPARK, BEAM, etc)
PARTICLE_BILLBOARD, //porientation_t orientation;
// range of colors to choose from in hex RRGGBB (like HTML color tags),
// randomly interpolated at spawn
{0xFFFFFF, 0xFFFFFF}, //unsigned int color[2];
// a random texture is chosen in this range (note the second value is one
// past the last choosable, so for example 8,16 chooses any from 8 up and
// including 15)
// if start and end of the range are the same, no randomization is done
{63, 63 /* tex_particle */}, //int tex[2];
// range of size values randomly chosen when spawning, plus size increase over time
{1, 1, 0.0f}, //float size[3];
// range of alpha values randomly chosen when spawning, plus alpha fade
{0.0f, 256.0f, 256.0f}, //float alpha[3];
// how long the particle should live (note it is also removed if alpha drops to 0)
{16777216.0f, 16777216.0f}, //float time[2];
// how much gravity affects this particle (negative makes it fly up!)
0.0f, //float gravity;
// how much bounce the particle has when it hits a surface
// if negative the particle is removed on impact
0.0f, //float bounce;
// if in air this friction is applied
// if negative the particle accelerates
0.0f, //float airfriction;
// if in liquid (water/slime/lava) this friction is applied
// if negative the particle accelerates
0.0f, //float liquidfriction;
// these offsets are added to the values given to particleeffect(), and
// then an ellipsoid-shaped jitter is added as defined by these
// (they are the 3 radii)
1.0f, //float stretchfactor;
// stretch velocity factor (used for sparks)
{0.0f, 0.0f, 0.0f}, //float originoffset[3];
{0.0f, 0.0f, 0.0f}, //float relativeoriginoffset[3];
{0.0f, 0.0f, 0.0f}, //float velocityoffset[3];
{0.0f, 0.0f, 0.0f}, //float relativevelocityoffset[3];
{0.0f, 0.0f, 0.0f}, //float originjitter[3];
{0.0f, 0.0f, 0.0f}, //float velocityjitter[3];
0.0f, //float velocitymultiplier;
// an effect can also spawn a dlight
0.0f, //float lightradiusstart;
0.0f, //float lightradiusfade;
16777216.0f, //float lighttime;
{1.0f, 1.0f, 1.0f}, //float lightcolor[3];
true, //qbool lightshadow;
0, //int lightcubemapnum;
{1.0f, 0.25f}, //float lightcorona[2];
{(unsigned int)-1, (unsigned int)-1}, //unsigned int staincolor[2]; // note: 0x808080 = neutral (particle's own color), these are modding factors for the particle's original color!
{-1, -1}, //int staintex[2];
{1.0f, 1.0f}, //float stainalpha[2];
{2.0f, 2.0f}, //float stainsize[2];
// other parameters
{0.0f, 360.0f, 0.0f, 0.0f}, //float rotate[4]; // min/max base angle, min/max rotation over time
};
cvar_t cl_particles = {CF_CLIENT | CF_ARCHIVE, "cl_particles", "1", "enables particle effects"};
cvar_t cl_particles_quality = {CF_CLIENT | CF_ARCHIVE, "cl_particles_quality", "1", "multiplies number of particles"};
cvar_t cl_particles_alpha = {CF_CLIENT | CF_ARCHIVE, "cl_particles_alpha", "1", "multiplies opacity of particles"};
cvar_t cl_particles_size = {CF_CLIENT | CF_ARCHIVE, "cl_particles_size", "1", "multiplies particle size"};
cvar_t cl_particles_quake = {CF_CLIENT | CF_ARCHIVE, "cl_particles_quake", "0", "0: Fancy particles; 1: Disc particles like GLQuake; 2: Square particles like software-rendered Quake"};
cvar_t cl_particles_blood = {CF_CLIENT | CF_ARCHIVE, "cl_particles_blood", "1", "enables blood effects"};
cvar_t cl_particles_blood_alpha = {CF_CLIENT | CF_ARCHIVE, "cl_particles_blood_alpha", "1", "opacity of blood, does not affect decals"};
cvar_t cl_particles_blood_decal_alpha = {CF_CLIENT | CF_ARCHIVE, "cl_particles_blood_decal_alpha", "1", "opacity of blood decal"};
cvar_t cl_particles_blood_decal_scalemin = {CF_CLIENT | CF_ARCHIVE, "cl_particles_blood_decal_scalemin", "1.5", "minimal random scale of decal"};
cvar_t cl_particles_blood_decal_scalemax = {CF_CLIENT | CF_ARCHIVE, "cl_particles_blood_decal_scalemax", "2", "maximal random scale of decal"};
cvar_t cl_particles_blood_bloodhack = {CF_CLIENT | CF_ARCHIVE, "cl_particles_blood_bloodhack", "1", "make certain quake particle() calls create blood effects instead"};
cvar_t cl_particles_bulletimpacts = {CF_CLIENT | CF_ARCHIVE, "cl_particles_bulletimpacts", "1", "enables bulletimpact effects"};
cvar_t cl_particles_explosions_sparks = {CF_CLIENT | CF_ARCHIVE, "cl_particles_explosions_sparks", "1", "enables sparks from explosions"};
cvar_t cl_particles_explosions_shell = {CF_CLIENT | CF_ARCHIVE, "cl_particles_explosions_shell", "0", "enables polygonal shell from explosions"};
cvar_t cl_particles_rain = {CF_CLIENT | CF_ARCHIVE, "cl_particles_rain", "1", "enables rain effects"};
cvar_t cl_particles_snow = {CF_CLIENT | CF_ARCHIVE, "cl_particles_snow", "1", "enables snow effects"};
cvar_t cl_particles_smoke = {CF_CLIENT | CF_ARCHIVE, "cl_particles_smoke", "1", "enables smoke (used by multiple effects)"};
cvar_t cl_particles_smoke_alpha = {CF_CLIENT | CF_ARCHIVE, "cl_particles_smoke_alpha", "0.5", "smoke brightness"};
cvar_t cl_particles_smoke_alphafade = {CF_CLIENT | CF_ARCHIVE, "cl_particles_smoke_alphafade", "0.55", "brightness fade per second"};
cvar_t cl_particles_sparks = {CF_CLIENT | CF_ARCHIVE, "cl_particles_sparks", "1", "enables sparks (used by multiple effects)"};
cvar_t cl_particles_bubbles = {CF_CLIENT | CF_ARCHIVE, "cl_particles_bubbles", "1", "enables bubbles (used by multiple effects)"};
cvar_t cl_particles_visculling = {CF_CLIENT | CF_ARCHIVE, "cl_particles_visculling", "0", "perform a costly check if each particle is visible before drawing"};
cvar_t cl_particles_collisions = {CF_CLIENT | CF_ARCHIVE, "cl_particles_collisions", "1", "allow costly collision detection on particles (sparks that bounce, particles not going through walls, blood hitting surfaces, etc)"};
cvar_t cl_particles_forcetraileffects = {CF_CLIENT, "cl_particles_forcetraileffects", "0", "force trails to be displayed even if a non-trail draw primitive was used (debug/compat feature)"};
cvar_t cl_decals = {CF_CLIENT | CF_ARCHIVE, "cl_decals", "1", "enables decals (bullet holes, blood, etc)"};
cvar_t cl_decals_time = {CF_CLIENT | CF_ARCHIVE, "cl_decals_time", "20", "how long before decals start to fade away"};
cvar_t cl_decals_fadetime = {CF_CLIENT | CF_ARCHIVE, "cl_decals_fadetime", "1", "how long decals take to fade away"};
cvar_t cl_decals_newsystem_intensitymultiplier = {CF_CLIENT | CF_ARCHIVE, "cl_decals_newsystem_intensitymultiplier", "2", "boosts intensity of decals (because the distance fade can make them hard to see otherwise)"};
cvar_t cl_decals_newsystem_immediatebloodstain = {CF_CLIENT | CF_ARCHIVE, "cl_decals_newsystem_immediatebloodstain", "2", "0: no on-spawn blood stains; 1: on-spawn blood stains for pt_blood; 2: always use on-spawn blood stains"};
cvar_t cl_decals_newsystem_bloodsmears = {CF_CLIENT | CF_ARCHIVE, "cl_decals_newsystem_bloodsmears", "1", "enable use of particle velocity as decal projection direction rather than surface normal"};
cvar_t cl_decals_models = {CF_CLIENT | CF_ARCHIVE, "cl_decals_models", "0", "enables decals on animated models"};
cvar_t cl_decals_bias = {CF_CLIENT | CF_ARCHIVE, "cl_decals_bias", "0.125", "distance to bias decals from surface to prevent depth fighting"};
cvar_t cl_decals_max = {CF_CLIENT | CF_ARCHIVE, "cl_decals_max", "4096", "maximum number of decals allowed to exist in the world at once"};
static void CL_Particles_ParseEffectInfo(const char *textstart, const char *textend, const char *filename)
{
int arrayindex;
int argc;
int i;
int linenumber;
particleeffectinfo_t *info = NULL;
const char *text = textstart;
char argv[16][1024];
for (linenumber = 1;;linenumber++)
{
argc = 0;
for (arrayindex = 0;arrayindex < 16;arrayindex++)
argv[arrayindex][0] = 0;
for (;;)
{
if (!COM_ParseToken_Simple(&text, true, false, true))
return;
if (!strcmp(com_token, "\n"))
break;
if (argc < 16)
{
dp_strlcpy(argv[argc], com_token, sizeof(argv[argc]));
argc++;
}
}
if (argc < 1)
continue;
#define checkparms(n) if (argc != (n)) {Con_Printf("%s:%i: error while parsing: %s given %i parameters, should be %i parameters\n", filename, linenumber, argv[0], argc, (n));break;}
#define readints(array, n) checkparms(n+1);for (arrayindex = 0;arrayindex < argc - 1;arrayindex++) array[arrayindex] = strtol(argv[1+arrayindex], NULL, 0)
#define readfloats(array, n) checkparms(n+1);for (arrayindex = 0;arrayindex < argc - 1;arrayindex++) array[arrayindex] = atof(argv[1+arrayindex])
#define readint(var) checkparms(2);var = strtol(argv[1], NULL, 0)
#define readfloat(var) checkparms(2);var = atof(argv[1])
#define readbool(var) checkparms(2);var = strtol(argv[1], NULL, 0) != 0
if (!strcmp(argv[0], "effect"))
{
int effectnameindex;
checkparms(2);
if (numparticleeffectinfo >= MAX_PARTICLEEFFECTINFO)
{
Con_Printf("%s:%i: too many effects!\n", filename, linenumber);
break;
}
for (effectnameindex = 1;effectnameindex < MAX_PARTICLEEFFECTNAME;effectnameindex++)
{
if (particleeffectname[effectnameindex][0])
{
if (!strcmp(particleeffectname[effectnameindex], argv[1]))
break;
}
else
{
dp_strlcpy(particleeffectname[effectnameindex], argv[1], sizeof(particleeffectname[effectnameindex]));
break;
}
}
// if we run out of names, abort
if (effectnameindex == MAX_PARTICLEEFFECTNAME)
{
Con_Printf("%s:%i: too many effects!\n", filename, linenumber);
break;
}
for(i = 0; i < numparticleeffectinfo; ++i)
{
info = particleeffectinfo + i;
if(!(info->flags & PARTICLEEFFECT_DEFINED))
if(info->effectnameindex == effectnameindex)
break;
}
if(i < numparticleeffectinfo)
continue;
info = particleeffectinfo + numparticleeffectinfo++;
// copy entire info from baseline, then fix up the nameindex
*info = baselineparticleeffectinfo;
info->effectnameindex = effectnameindex;
continue;
}
else if (info == NULL)
{
Con_Printf("%s:%i: command %s encountered before effect\n", filename, linenumber, argv[0]);
break;
}
info->flags |= PARTICLEEFFECT_DEFINED;
if (!strcmp(argv[0], "countabsolute")) {readfloat(info->countabsolute);}
else if (!strcmp(argv[0], "count")) {readfloat(info->countmultiplier);}
else if (!strcmp(argv[0], "type"))
{
checkparms(2);
if (!strcmp(argv[1], "alphastatic")) info->particletype = pt_alphastatic;
else if (!strcmp(argv[1], "static")) info->particletype = pt_static;
else if (!strcmp(argv[1], "spark")) info->particletype = pt_spark;
else if (!strcmp(argv[1], "beam")) info->particletype = pt_beam;
else if (!strcmp(argv[1], "rain")) info->particletype = pt_rain;
else if (!strcmp(argv[1], "raindecal")) info->particletype = pt_raindecal;
else if (!strcmp(argv[1], "snow")) info->particletype = pt_snow;
else if (!strcmp(argv[1], "bubble")) info->particletype = pt_bubble;
else if (!strcmp(argv[1], "blood")) {info->particletype = pt_blood;info->gravity = 1;}
else if (!strcmp(argv[1], "smoke")) info->particletype = pt_smoke;
else if (!strcmp(argv[1], "decal")) info->particletype = pt_decal;
else if (!strcmp(argv[1], "entityparticle")) info->particletype = pt_entityparticle;
else Con_Printf("%s:%i: unrecognized particle type %s\n", filename, linenumber, argv[1]);
info->blendmode = particletype[info->particletype].blendmode;
info->orientation = particletype[info->particletype].orientation;
}
else if (!strcmp(argv[0], "blend"))
{
checkparms(2);
if (!strcmp(argv[1], "alpha")) info->blendmode = PBLEND_ALPHA;
else if (!strcmp(argv[1], "add")) info->blendmode = PBLEND_ADD;
else if (!strcmp(argv[1], "invmod")) info->blendmode = PBLEND_INVMOD;
else Con_Printf("%s:%i: unrecognized blendmode %s\n", filename, linenumber, argv[1]);
}
else if (!strcmp(argv[0], "orientation"))
{
checkparms(2);
if (!strcmp(argv[1], "billboard")) info->orientation = PARTICLE_BILLBOARD;
else if (!strcmp(argv[1], "spark")) info->orientation = PARTICLE_SPARK;
else if (!strcmp(argv[1], "oriented")) info->orientation = PARTICLE_ORIENTED_DOUBLESIDED;
else if (!strcmp(argv[1], "beam")) info->orientation = PARTICLE_HBEAM;
else Con_Printf("%s:%i: unrecognized orientation %s\n", filename, linenumber, argv[1]);
}
else if (!strcmp(argv[0], "color")) {readints(info->color, 2);}
else if (!strcmp(argv[0], "tex")) {readints(info->tex, 2);}
else if (!strcmp(argv[0], "size")) {readfloats(info->size, 2);}
else if (!strcmp(argv[0], "sizeincrease")) {readfloat(info->size[2]);}
else if (!strcmp(argv[0], "alpha")) {readfloats(info->alpha, 3);}
else if (!strcmp(argv[0], "time")) {readfloats(info->time, 2);}
else if (!strcmp(argv[0], "gravity")) {readfloat(info->gravity);}
else if (!strcmp(argv[0], "bounce")) {readfloat(info->bounce);}
else if (!strcmp(argv[0], "airfriction")) {readfloat(info->airfriction);}
else if (!strcmp(argv[0], "liquidfriction")) {readfloat(info->liquidfriction);}
else if (!strcmp(argv[0], "originoffset")) {readfloats(info->originoffset, 3);}
else if (!strcmp(argv[0], "relativeoriginoffset")) {readfloats(info->relativeoriginoffset, 3);}
else if (!strcmp(argv[0], "velocityoffset")) {readfloats(info->velocityoffset, 3);}
else if (!strcmp(argv[0], "relativevelocityoffset")) {readfloats(info->relativevelocityoffset, 3);}
else if (!strcmp(argv[0], "originjitter")) {readfloats(info->originjitter, 3);}
else if (!strcmp(argv[0], "velocityjitter")) {readfloats(info->velocityjitter, 3);}
else if (!strcmp(argv[0], "velocitymultiplier")) {readfloat(info->velocitymultiplier);}
else if (!strcmp(argv[0], "lightradius")) {readfloat(info->lightradiusstart);}
else if (!strcmp(argv[0], "lightradiusfade")) {readfloat(info->lightradiusfade);}
else if (!strcmp(argv[0], "lighttime")) {readfloat(info->lighttime);}
else if (!strcmp(argv[0], "lightcolor")) {readfloats(info->lightcolor, 3);}
else if (!strcmp(argv[0], "lightshadow")) {readbool(info->lightshadow);}
else if (!strcmp(argv[0], "lightcubemapnum")) {readint(info->lightcubemapnum);}
else if (!strcmp(argv[0], "lightcorona")) {readints(info->lightcorona, 2);}
else if (!strcmp(argv[0], "underwater")) {checkparms(1);info->flags |= PARTICLEEFFECT_UNDERWATER;}
else if (!strcmp(argv[0], "notunderwater")) {checkparms(1);info->flags |= PARTICLEEFFECT_NOTUNDERWATER;}
else if (!strcmp(argv[0], "trailspacing")) {readfloat(info->trailspacing);if (info->trailspacing > 0) info->countmultiplier = 1.0f / info->trailspacing;}
else if (!strcmp(argv[0], "stretchfactor")) {readfloat(info->stretchfactor);}
else if (!strcmp(argv[0], "staincolor")) {readints(info->staincolor, 2);}
else if (!strcmp(argv[0], "stainalpha")) {readfloats(info->stainalpha, 2);}
else if (!strcmp(argv[0], "stainsize")) {readfloats(info->stainsize, 2);}
else if (!strcmp(argv[0], "staintex")) {readints(info->staintex, 2);}
else if (!strcmp(argv[0], "stainless")) {info->staintex[0] = -2; info->staincolor[0] = (unsigned int)-1; info->staincolor[1] = (unsigned int)-1; info->stainalpha[0] = 1; info->stainalpha[1] = 1; info->stainsize[0] = 2; info->stainsize[1] = 2; }
else if (!strcmp(argv[0], "rotate")) {readfloats(info->rotate, 4);}
else if (!strcmp(argv[0], "forcenearest")) {checkparms(1);info->flags |= PARTICLEEFFECT_FORCENEAREST;}
else
Con_Printf("%s:%i: skipping unknown command %s\n", filename, linenumber, argv[0]);
#undef checkparms
#undef readints
#undef readfloats
#undef readint
#undef readfloat
}
}
int CL_ParticleEffectIndexForName(const char *name)
{
int i;
for (i = 1;i < MAX_PARTICLEEFFECTNAME && particleeffectname[i][0];i++)
if (!strcmp(particleeffectname[i], name))
return i;
return 0;
}
const char *CL_ParticleEffectNameForIndex(int i)
{
if (i < 1 || i >= MAX_PARTICLEEFFECTNAME)
return NULL;
return particleeffectname[i];
}
// MUST match effectnameindex_t in client.h
static const char *standardeffectnames[EFFECT_TOTAL] =
{
"",
"TE_GUNSHOT",
"TE_GUNSHOTQUAD",
"TE_SPIKE",
"TE_SPIKEQUAD",
"TE_SUPERSPIKE",
"TE_SUPERSPIKEQUAD",
"TE_WIZSPIKE",
"TE_KNIGHTSPIKE",
"TE_EXPLOSION",
"TE_EXPLOSIONQUAD",
"TE_TAREXPLOSION",
"TE_TELEPORT",
"TE_LAVASPLASH",
"TE_SMALLFLASH",
"TE_FLAMEJET",
"EF_FLAME",
"TE_BLOOD",
"TE_SPARK",
"TE_PLASMABURN",
"TE_TEI_G3",
"TE_TEI_SMOKE",
"TE_TEI_BIGEXPLOSION",
"TE_TEI_PLASMAHIT",
"EF_STARDUST",
"TR_ROCKET",
"TR_GRENADE",
"TR_BLOOD",
"TR_WIZSPIKE",
"TR_SLIGHTBLOOD",
"TR_KNIGHTSPIKE",
"TR_VORESPIKE",
"TR_NEHAHRASMOKE",
"TR_NEXUIZPLASMA",
"TR_GLOWTRAIL",
"SVC_PARTICLE"
};
static void CL_Particles_LoadEffectInfo(const char *customfile)
{
int i;
int filepass;
unsigned char *filedata;
fs_offset_t filesize;
char filename[MAX_QPATH];
numparticleeffectinfo = 0;
memset(particleeffectinfo, 0, sizeof(particleeffectinfo));
memset(particleeffectname, 0, sizeof(particleeffectname));
for (i = 0;i < EFFECT_TOTAL;i++)
dp_strlcpy(particleeffectname[i], standardeffectnames[i], sizeof(particleeffectname[i]));
for (filepass = 0;;filepass++)
{
if (filepass == 0)
{
if (customfile)
dp_strlcpy(filename, customfile, sizeof(filename));
else
dp_strlcpy(filename, "effectinfo.txt", sizeof(filename));
}
else if (filepass == 1)
{
if (!cl.worldbasename[0] || customfile)
continue;
dpsnprintf(filename, sizeof(filename), "%s_effectinfo.txt", cl.worldnamenoextension);
}
else
break;
filedata = FS_LoadFile(filename, tempmempool, true, &filesize);
if (!filedata)
continue;
CL_Particles_ParseEffectInfo((const char *)filedata, (const char *)filedata + filesize, filename);
Mem_Free(filedata);
}
}
static void CL_Particles_LoadEffectInfo_f(cmd_state_t *cmd)
{
CL_Particles_LoadEffectInfo(Cmd_Argc(cmd) > 1 ? Cmd_Argv(cmd, 1) : NULL);
}
/*
===============
CL_InitParticles
===============
*/
void CL_ReadPointFile_f(cmd_state_t *cmd);
void CL_Particles_Init (void)
{
Cmd_AddCommand(CF_CLIENT, "pointfile", CL_ReadPointFile_f, "display point file produced by qbsp when a leak was detected in the map (a line leading through the leak hole, to an entity inside the level)");
Cmd_AddCommand(CF_CLIENT, "cl_particles_reloadeffects", CL_Particles_LoadEffectInfo_f, "reloads effectinfo.txt and maps/levelname_effectinfo.txt (where levelname is the current map) if parameter is given, loads from custom file (no levelname_effectinfo are loaded in this case)");
Cvar_RegisterVariable (&cl_particles);
Cvar_RegisterVariable (&cl_particles_quality);
Cvar_RegisterVariable (&cl_particles_alpha);
Cvar_RegisterVariable (&cl_particles_size);
Cvar_RegisterVariable (&cl_particles_quake);
Cvar_RegisterVariable (&cl_particles_blood);
Cvar_RegisterVariable (&cl_particles_blood_alpha);
Cvar_RegisterVariable (&cl_particles_blood_decal_alpha);
Cvar_RegisterVariable (&cl_particles_blood_decal_scalemin);
Cvar_RegisterVariable (&cl_particles_blood_decal_scalemax);
Cvar_RegisterVariable (&cl_particles_blood_bloodhack);
Cvar_RegisterVariable (&cl_particles_explosions_sparks);
Cvar_RegisterVariable (&cl_particles_explosions_shell);
Cvar_RegisterVariable (&cl_particles_bulletimpacts);
Cvar_RegisterVariable (&cl_particles_rain);
Cvar_RegisterVariable (&cl_particles_snow);
Cvar_RegisterVariable (&cl_particles_smoke);
Cvar_RegisterVariable (&cl_particles_smoke_alpha);
Cvar_RegisterVariable (&cl_particles_smoke_alphafade);
Cvar_RegisterVariable (&cl_particles_sparks);
Cvar_RegisterVariable (&cl_particles_bubbles);
Cvar_RegisterVariable (&cl_particles_visculling);
Cvar_RegisterVariable (&cl_particles_collisions);
Cvar_RegisterVariable (&cl_particles_forcetraileffects);
Cvar_RegisterVariable (&cl_decals);
Cvar_RegisterVariable (&cl_decals_time);
Cvar_RegisterVariable (&cl_decals_fadetime);
Cvar_RegisterVariable (&cl_decals_newsystem_intensitymultiplier);
Cvar_RegisterVariable (&cl_decals_newsystem_immediatebloodstain);
Cvar_RegisterVariable (&cl_decals_newsystem_bloodsmears);
Cvar_RegisterVariable (&cl_decals_models);
Cvar_RegisterVariable (&cl_decals_bias);
Cvar_RegisterVariable (&cl_decals_max);
}
void CL_Particles_Shutdown (void)
{
}
void CL_SpawnDecalParticleForSurface(int hitent, const vec3_t org, const vec3_t normal, int color1, int color2, int texnum, float size, float alpha);
void CL_SpawnDecalParticleForPoint(const vec3_t org, float maxdist, float size, float alpha, int texnum, int color1, int color2);
/**
* @brief Creates a new particle and returns a pointer to it
*
* @param[in] sortorigin ?
* @param[in] ptypeindex Any of the pt_ enum values (pt_static, pt_blood, etc), see ptype_t near the top of this file
* @param[in] pcolor1,pcolor2 Minimum and maximum range of color, randomly interpolated with pcolor2 to decide particle color
* @param[in] ptex Any of the tex_ values such as tex_smoke[rand()&7] or tex_particle
* @param[in] psize Size of particle (or thickness for PARTICLE_SPARK and PARTICLE_*BEAM)
* @param[in] psizeincrease ?
* @param[in] palpha Opacity of particle as 0-255 (can be more than 255)
* @param[in] palphafade Rate of fade per second (so 256 would mean a 256 alpha particle would fade to nothing in 1 second)
* @param[in] pgravity How much effect gravity has on the particle (0-1)
* @param[in] pbounce How much bounce the particle has when it hits a surface (0-1), -1 makes a blood splat when it hits a surface, 0 does not even check for collisions
* @param[in] px,py,pz Starting origin of particle
* @param[in] pvx,pvy,pvz Starting velocity of particle
* @param[in] pairfriction How much the particle slows down, in air, per second (0-1 typically, can slowdown faster than 1)
* @param[in] pliquidfriction How much the particle slows down, in liquids, per second (0-1 typically, can slowdown faster than 1)
* @param[in] originjitter ?
* @param[in] velocityjitter ?
* @param[in] pqualityreduction ?
* @param[in] lifetime How long the particle can live (note it is also removed if alpha drops to nothing)
* @param[in] stretch ?
* @param[in] blendmode One of the PBLEND_ values
* @param[in] orientation One of the PARTICLE_ values
* @param[in] staincolor1 Minimum and maximum ranges of stain color, randomly interpolated to decide stain color (-1 to use none)
* @param[in] staincolor2 Minimum and maximum ranges of stain color, randomly interpolated to decide stain color (-1 to use none)
* @param[in] staintex Any of the tex_ values such as tex_smoke[rand()&7] or tex_particle
* @param[in] angle Base rotation of the particle geometry around its center normal
* @param[in] spin Rotation speed of the particle geometry around its center normal
* @param[in] tint The tint
*
* @return Pointer to the new particle
*/
particle_t *CL_NewParticle(
const vec3_t sortorigin,
unsigned short ptypeindex,
int pcolor1, int pcolor2,
int ptex,
float psize,
float psizeincrease,
float palpha,
float palphafade,
float pgravity,
float pbounce,
float px, float py, float pz,
float pvx, float pvy, float pvz,
float pairfriction,
float pliquidfriction,
float originjitter,
float velocityjitter,
qbool pqualityreduction,
float lifetime,
float stretch,
pblend_t blendmode,
porientation_t orientation,
int staincolor1,
int staincolor2,
int staintex,
float stainalpha,
float stainsize,
float angle,
float spin,
float tint[4])
{
int l1, l2, r, g, b;
particle_t *part;
vec3_t v;
if (!cl_particles.integer)
return NULL;
for (;cl.free_particle < cl.max_particles && cl.particles[cl.free_particle].typeindex;cl.free_particle++);
if (cl.free_particle >= cl.max_particles)
return NULL;
if (!lifetime)
lifetime = palpha / min(1, palphafade);
part = &cl.particles[cl.free_particle++];
if (cl.num_particles < cl.free_particle)
cl.num_particles = cl.free_particle;
memset(part, 0, sizeof(*part));
VectorCopy(sortorigin, part->sortorigin);
part->typeindex = ptypeindex;
part->blendmode = blendmode;
if(orientation == PARTICLE_HBEAM || orientation == PARTICLE_VBEAM)
{
particletexture_t *tex = &particletexture[ptex];
if(tex->t1 == 0 && tex->t2 == 1) // full height of texture?
part->orientation = PARTICLE_VBEAM;
else
part->orientation = PARTICLE_HBEAM;
}
else
part->orientation = orientation;
l2 = (int)lhrandom(0.5, 256.5);
l1 = 256 - l2;
part->color[0] = ((((pcolor1 >> 16) & 0xFF) * l1 + ((pcolor2 >> 16) & 0xFF) * l2) >> 8) & 0xFF;
part->color[1] = ((((pcolor1 >> 8) & 0xFF) * l1 + ((pcolor2 >> 8) & 0xFF) * l2) >> 8) & 0xFF;
part->color[2] = ((((pcolor1 >> 0) & 0xFF) * l1 + ((pcolor2 >> 0) & 0xFF) * l2) >> 8) & 0xFF;
if (vid.sRGB3D)
{
part->color[0] = (unsigned char)floor(Image_LinearFloatFromsRGB(part->color[0]) * 255.0f + 0.5f);
part->color[1] = (unsigned char)floor(Image_LinearFloatFromsRGB(part->color[1]) * 255.0f + 0.5f);
part->color[2] = (unsigned char)floor(Image_LinearFloatFromsRGB(part->color[2]) * 255.0f + 0.5f);
}
part->alpha = palpha;
part->alphafade = palphafade;
part->staintexnum = staintex;
if(staincolor1 >= 0 && staincolor2 >= 0)
{
l2 = (int)lhrandom(0.5, 256.5);
l1 = 256 - l2;
if(blendmode == PBLEND_INVMOD)
{
r = ((((staincolor1 >> 16) & 0xFF) * l1 + ((staincolor2 >> 16) & 0xFF) * l2) * (255 - part->color[0])) / 0x8000; // staincolor 0x808080 keeps color invariant
g = ((((staincolor1 >> 8) & 0xFF) * l1 + ((staincolor2 >> 8) & 0xFF) * l2) * (255 - part->color[1])) / 0x8000;
b = ((((staincolor1 >> 0) & 0xFF) * l1 + ((staincolor2 >> 0) & 0xFF) * l2) * (255 - part->color[2])) / 0x8000;
}
else
{
r = ((((staincolor1 >> 16) & 0xFF) * l1 + ((staincolor2 >> 16) & 0xFF) * l2) * part->color[0]) / 0x8000; // staincolor 0x808080 keeps color invariant
g = ((((staincolor1 >> 8) & 0xFF) * l1 + ((staincolor2 >> 8) & 0xFF) * l2) * part->color[1]) / 0x8000;
b = ((((staincolor1 >> 0) & 0xFF) * l1 + ((staincolor2 >> 0) & 0xFF) * l2) * part->color[2]) / 0x8000;
}
if(r > 0xFF) r = 0xFF;
if(g > 0xFF) g = 0xFF;
if(b > 0xFF) b = 0xFF;
}
else
{
r = part->color[0]; // -1 is shorthand for stain = particle color
g = part->color[1];
b = part->color[2];
}
part->staincolor[0] = r;
part->staincolor[1] = g;
part->staincolor[2] = b;
part->stainalpha = palpha * stainalpha;
part->stainsize = psize * stainsize;
if(tint)
{
if(blendmode != PBLEND_INVMOD) // invmod is immune to tinting
{
part->color[0] *= tint[0];
part->color[1] *= tint[1];
part->color[2] *= tint[2];
}
part->alpha *= tint[3];
part->alphafade *= tint[3];
part->stainalpha *= tint[3];
}
part->texnum = ptex;
part->size = psize;
part->sizeincrease = psizeincrease;
part->gravity = pgravity;
part->bounce = pbounce;
part->stretch = stretch;
VectorRandom(v);
part->org[0] = px + originjitter * v[0];
part->org[1] = py + originjitter * v[1];
part->org[2] = pz + originjitter * v[2];
part->vel[0] = pvx + velocityjitter * v[0];
part->vel[1] = pvy + velocityjitter * v[1];
part->vel[2] = pvz + velocityjitter * v[2];
part->airfriction = pairfriction;
part->liquidfriction = pliquidfriction;
part->die = cl.time + lifetime;
part->delayedspawn = cl.time;
// part->delayedcollisions = 0;
part->qualityreduction = pqualityreduction;
part->angle = angle;
part->spin = spin;
// if it is rain or snow, trace ahead and shut off collisions until an actual collision event needs to occur to improve performance
if (part->typeindex == pt_rain)
{
int i;
particle_t *part2;
vec3_t endvec;
trace_t trace;
// turn raindrop into simple spark and create delayedspawn splash effect
part->typeindex = pt_spark;
part->bounce = 0;
VectorMA(part->org, lifetime, part->vel, endvec);
trace = CL_TraceLine(part->org, endvec, MOVE_NOMONSTERS, NULL, SUPERCONTENTS_SOLID | SUPERCONTENTS_LIQUIDSMASK, 0, 0, collision_extendmovelength.value, true, false, NULL, false, false);
part->die = cl.time + lifetime * trace.fraction;
part2 = CL_NewParticle(endvec, pt_raindecal, pcolor1, pcolor2, tex_rainsplash, part->size, part->size * 20, part->alpha, part->alpha / 0.4, 0, 0, trace.endpos[0] + trace.plane.normal[0], trace.endpos[1] + trace.plane.normal[1], trace.endpos[2] + trace.plane.normal[2], trace.plane.normal[0], trace.plane.normal[1], trace.plane.normal[2], 0, 0, 0, 0, pqualityreduction, 0, 1, PBLEND_ADD, PARTICLE_ORIENTED_DOUBLESIDED, -1, -1, -1, 1, 1, 0, 0, NULL);
if (part2)
{
part2->delayedspawn = part->die;
part2->die += part->die - cl.time;
for (i = rand() & 7;i < 10;i++)
{
part2 = CL_NewParticle(endvec, pt_spark, pcolor1, pcolor2, tex_particle, 0.25f, 0, part->alpha * 2, part->alpha * 4, 1, 0.1, trace.endpos[0] + trace.plane.normal[0], trace.endpos[1] + trace.plane.normal[1], trace.endpos[2] + trace.plane.normal[2], trace.plane.normal[0] * 16, trace.plane.normal[1] * 16, trace.plane.normal[2] * 16 + cl.movevars_gravity * 0.04, 0, 0, 0, 32, pqualityreduction, 0, 1, PBLEND_ADD, PARTICLE_SPARK, -1, -1, -1, 1, 1, 0, 0, NULL);
if (part2)
{
part2->delayedspawn = part->die;
part2->die += part->die - cl.time;
}
}
}
}
else if (part->typeindex == pt_explode || part->typeindex == pt_explode2)
part->time2 = rand()&3; // time2 is used to progress the colour ramp index
#if 0
else if (part->bounce != 0 && part->gravity == 0 && part->typeindex != pt_snow)
{
float lifetime = part->alpha / (part->alphafade ? part->alphafade : 1);
vec3_t endvec;
trace_t trace;
VectorMA(part->org, lifetime, part->vel, endvec);
trace = CL_TraceLine(part->org, endvec, MOVE_NOMONSTERS, NULL, SUPERCONTENTS_SOLID | SUPERCONTENTS_BODY, true, false, NULL, false);
part->delayedcollisions = cl.time + lifetime * trace.fraction - 0.1;
}
#endif
return part;
}
/**
* @brief Creates a simple particle, a square like Quake, or a disc like GLQuake
*
* @param[in] origin ?
* @param[in] color_1,color_2 Minimum and maximum range of color, randomly interpolated with pcolor2 to decide particle color
* @param[in] gravity How much effect gravity has on the particle (0-1)
* @param[in] offset_x,offset_y,offset_z Starting origin of particle
* @param[in] velocity_offset_x,velocity_offset_y,velocity_offset_z Starting velocity of particle
* @param[in] air_friction How much the particle slows down, in air, per second (0-1 typically, can slowdown faster than 1)
* @param[in] liquid_friction How much the particle slows down, in liquids, per second (0-1 typically, can slowdown faster than 1)
* @param[in] origin_jitter ?
* @param[in] velocity_jitter ?
* @param[in] lifetime How long the particle can live (note it is also removed if alpha drops to nothing)
*
* @return Pointer to the new particle
*/
particle_t *CL_NewQuakeParticle(
const vec3_t origin,
const unsigned short ptypeindex,
const int color_1,
const int color_2,
const float gravity,
const float offset_x,
const float offset_y,
const float offset_z,
const float velocity_offset_x,
const float velocity_offset_y,
const float velocity_offset_z,
const float air_friction,
const float liquid_friction,
const float origin_jitter,
const float velocity_jitter,
const float lifetime)
{
int texture;
// Set the particle texture based on the value of cl_particles_quake; defaulting to the GLQuake disc
if (cl_particles_quake.integer == 2)
texture = tex_square;
else
texture = tex_particle;
return CL_NewParticle(
origin,
ptypeindex, // type
color_1,
color_2,
texture,
0.8f, // size
0, // size increase
255, // alpha
0, // alpha fade
gravity,
0, // bounce
offset_x,
offset_y,
offset_z,
velocity_offset_x,
velocity_offset_y,
velocity_offset_z,
air_friction,
liquid_friction,
origin_jitter,
velocity_jitter,
true, // quality reduction
lifetime,
1, // stretch
PBLEND_ALPHA, // blend mode
PARTICLE_BILLBOARD, // orientation
-1, // stain color 1
-1, // stain color 2
-1, // stain texture
1, // stain alpha
1, // stain size
0, // angle
0, // spin
NULL // tint
);
}
static void CL_ImmediateBloodStain(particle_t *part)
{
vec3_t v;
int staintex;
// blood creates a splash at spawn, not just at impact, this makes monsters bloody where they are shot
if (part->staintexnum >= 0 && cl_decals.integer)
{
VectorCopy(part->vel, v);
VectorNormalize(v);
staintex = part->staintexnum;
R_DecalSystem_SplatEntities(part->org, v, 1-part->staincolor[0]*(1.0f/255.0f), 1-part->staincolor[1]*(1.0f/255.0f), 1-part->staincolor[2]*(1.0f/255.0f), part->stainalpha*(1.0f/255.0f), particletexture[staintex].s1, particletexture[staintex].t1, particletexture[staintex].s2, particletexture[staintex].t2, part->stainsize);
}
// blood creates a splash at spawn, not just at impact, this makes monsters bloody where they are shot
if (part->typeindex == pt_blood && cl_decals.integer)
{
VectorCopy(part->vel, v);
VectorNormalize(v);
staintex = tex_blooddecal[rand()&7];
R_DecalSystem_SplatEntities(part->org, v, part->color[0]*(1.0f/255.0f), part->color[1]*(1.0f/255.0f), part->color[2]*(1.0f/255.0f), part->alpha*(1.0f/255.0f), particletexture[staintex].s1, particletexture[staintex].t1, particletexture[staintex].s2, particletexture[staintex].t2, part->size * 2);
}
}
void CL_SpawnDecalParticleForSurface(int hitent, const vec3_t org, const vec3_t normal, int color1, int color2, int texnum, float size, float alpha)
{
int l1, l2;
entity_render_t *ent = &cl.entities[hitent].render;
unsigned char color[3];
if (!cl_decals.integer)
return;
if (!ent->allowdecals)
return;
l2 = (int)lhrandom(0.5, 256.5);
l1 = 256 - l2;
color[0] = ((((color1 >> 16) & 0xFF) * l1 + ((color2 >> 16) & 0xFF) * l2) >> 8) & 0xFF;
color[1] = ((((color1 >> 8) & 0xFF) * l1 + ((color2 >> 8) & 0xFF) * l2) >> 8) & 0xFF;
color[2] = ((((color1 >> 0) & 0xFF) * l1 + ((color2 >> 0) & 0xFF) * l2) >> 8) & 0xFF;
if (vid.sRGB3D)
R_DecalSystem_SplatEntities(org, normal, Image_LinearFloatFromsRGB(color[0]), Image_LinearFloatFromsRGB(color[1]), Image_LinearFloatFromsRGB(color[2]), alpha*(1.0f/255.0f), particletexture[texnum].s1, particletexture[texnum].t1, particletexture[texnum].s2, particletexture[texnum].t2, size);
else
R_DecalSystem_SplatEntities(org, normal, color[0]*(1.0f/255.0f), color[1]*(1.0f/255.0f), color[2]*(1.0f/255.0f), alpha*(1.0f/255.0f), particletexture[texnum].s1, particletexture[texnum].t1, particletexture[texnum].s2, particletexture[texnum].t2, size);
}
void CL_SpawnDecalParticleForPoint(const vec3_t org, float maxdist, float size, float alpha, int texnum, int color1, int color2)
{
int i;
vec_t bestfrac;
vec3_t bestorg;
vec3_t bestnormal;
vec3_t org2;
int besthitent = 0, hitent;
trace_t trace;
bestfrac = 10;
for (i = 0;i < 32;i++)
{
VectorRandom(org2);
VectorMA(org, maxdist, org2, org2);
trace = CL_TraceLine(org, org2, MOVE_NOMONSTERS, NULL, SUPERCONTENTS_SOLID | SUPERCONTENTS_SKY, 0, 0, collision_extendmovelength.value, true, false, &hitent, false, true);
// take the closest trace result that doesn't end up hitting a NOMARKS
// surface (sky for example)
if (bestfrac > trace.fraction && !(trace.hitq3surfaceflags & Q3SURFACEFLAG_NOMARKS))
{
bestfrac = trace.fraction;