-
Notifications
You must be signed in to change notification settings - Fork 124
/
Copy pathgl_rpart.c
3023 lines (2691 loc) · 80.9 KB
/
gl_rpart.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) 2002-2003, Dr Labman, A. Nourai
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 "gl_model.h"
#include "gl_local.h"
#include "vx_stuff.h"
#include "pmove.h"
#include "utils.h"
#include "qsound.h"
//VULT
static float alphatrail_s;
static float alphatrail_l;
static float varray_vertex[16];
//#define DEFAULT_NUM_PARTICLES 2048 // 4096
#define ABSOLUTE_MIN_PARTICLES 256
#define ABSOLUTE_MAX_PARTICLES 32768
/*
//VULT - Welcome to the 21st century
#define DEFAULT_NUM_PARTICLES 16384
#define ABSOLUTE_MIN_PARTICLES 256
#define ABSOLUTE_MAX_PARTICLES 65536
*/
//Better rand nums
#define lhrandom(MIN,MAX) ((rand() & 32767) * (((MAX)-(MIN)) * (1.0f / 32767.0f)) + (MIN))
typedef byte col_t[4];
//VULT PARTICLES
void RainSplash(vec3_t org);
void ParticleStats (int change);
void VX_ParticleTrail (vec3_t start, vec3_t end, float size, float time, col_t color);
void InfernoTrail (vec3_t start, vec3_t end, vec3_t vel);
void R_CalcBeamVerts (float *vert, vec3_t org1, vec3_t org2, float width);
typedef enum {
p_spark, p_smoke, p_fire, p_bubble, p_lavasplash, p_gunblast, p_chunk, p_shockwave,
p_inferno_flame, p_inferno_trail, p_sparkray, p_staticbubble, p_trailpart,
p_dpsmoke, p_dpfire, p_teleflare, p_blood1, p_blood2, p_blood3,
//VULT PARTICLES
p_rain,
p_alphatrail,
p_railtrail,
p_streak,
p_streaktrail,
p_streakwave,
p_lightningbeam,
p_vxblood,
p_lavatrail,
p_vxsmoke,
p_muzzleflash,
p_inferno, //VULT - NOT TO BE CONFUSED WITH THE 0.36 FIREBALL
p_2dshockwave,
p_vxrocketsmoke,
p_trailbleed,
p_bleedspike,
p_flame,
p_bubble2,
p_bloodcloud,
p_chunkdir,
p_smallspark,
//[HyperNewbie] - particles!
p_slimeglow, //slime glow
p_slimebubble, //slime yellowish growing popping bubble
p_blacklavasmoke,
num_particletypes,
} part_type_t;
typedef enum {
pm_static, pm_normal, pm_bounce, pm_die, pm_nophysics, pm_float,
//VULT PARTICLES
pm_rain,
pm_streak,
pm_streakwave,
pm_inferno,
} part_move_t;
typedef enum {
ptex_none, ptex_smoke, ptex_bubble, ptex_generic, ptex_dpsmoke, ptex_lava,
ptex_blueflare, ptex_blood1, ptex_blood2, ptex_blood3,
//VULT PARTICLES
ptex_shockwave,
ptex_lightning,
ptex_spark,
num_particletextures,
} part_tex_t;
typedef enum {
pd_spark, pd_sparkray, pd_billboard, pd_billboard_vel,
//VULT PARTICLES
pd_beam,
pd_hide,
pd_normal,
} part_draw_t;
typedef struct particle_s {
struct particle_s *next;
vec3_t org, endorg;
col_t color;
float growth;
vec3_t vel;
float rotangle;
float rotspeed;
float size;
float start;
float die;
byte hit;
byte texindex;
byte bounces;
} particle_t;
typedef struct particle_tree_s {
particle_t *start;
part_type_t id;
part_draw_t drawtype;
int SrcBlend;
int DstBlend;
part_tex_t texture;
float startalpha;
float grav;
float accel;
part_move_t move;
float custom;
} particle_type_t;
#define MAX_PTEX_COMPONENTS 8
typedef struct particle_texture_s {
int texnum;
int components;
float coords[MAX_PTEX_COMPONENTS][4];
} particle_texture_t;
static float sint[7] = {0.000000, 0.781832, 0.974928, 0.433884, -0.433884, -0.974928, -0.781832};
static float cost[7] = {1.000000, 0.623490, -0.222521, -0.900969, -0.900969, -0.222521, 0.623490};
static particle_t *particles, *free_particles;
static particle_type_t particle_types[num_particletypes];
static int particle_type_index[num_particletypes];
static particle_texture_t particle_textures[num_particletextures];
static int r_numparticles;
static vec3_t zerodir = {22, 22, 22};
static int particle_count = 0;
static float particle_time;
static vec3_t trail_stop;
qbool qmb_initialized = false;
cvar_t gl_clipparticles = {"gl_clipparticles", "1"};
cvar_t gl_bounceparticles = {"gl_bounceparticles", "1"};
cvar_t amf_part_fulldetail = {"gl_particle_fulldetail", "0", CVAR_LATCH};
static qbool TraceLineN (vec3_t start, vec3_t end, vec3_t impact, vec3_t normal)
{
trace_t trace = PM_TraceLine (start, end);
VectorCopy (trace.endpos, impact);
if (normal)
VectorCopy (trace.plane.normal, normal);
if (!trace.allsolid)
return false;
if (trace.startsolid)
return false;
return true;
}
static byte *ColorForParticle(part_type_t type) {
int lambda;
static col_t color;
switch (type) {
case p_spark:
color[0] = 224 + (rand() & 31); color[1] = 100 + (rand() & 31); color[2] = 0;
break;
case p_smoke:
color[0] = color[1] = color[2] = 255;
break;
case p_fire:
color[0] = 255; color[1] = 142; color[2] = 62;
break;
case p_slimebubble:
case p_bubble:
case p_staticbubble:
color[0] = color[1] = color[2] = 192 + (rand() & 63);
break;
case p_teleflare:
case p_slimeglow:
case p_lavasplash:
color[0] = color[1] = color[2] = 128 + (rand() & 127);
break;
case p_gunblast:
color[0]= 224 + (rand() & 31); color[1] = 170 + (rand() & 31); color[2] = 0;
break;
case p_chunk:
color[0] = color[1] = color[2] = (32 + (rand() & 127));
break;
case p_shockwave:
color[0] = color[1] = color[2] = 64 + (rand() & 31);
break;
case p_inferno_flame:
case p_inferno_trail:
color[0] = 255; color[1] = 77; color[2] = 13;
break;
case p_sparkray:
color[0] = 255; color[1] = 102; color[2] = 25;
break;
case p_dpsmoke:
color[0] = color[1] = color[2] = 48 + (((rand() & 0xFF) * 48) >> 8);
break;
case p_dpfire:
lambda = rand() & 0xFF;
color[0] = 160 + ((lambda * 48) >> 8); color[1] = 16 + ((lambda * 148) >> 8); color[2] = 16 + ((lambda * 16) >> 8);
break;
case p_blood1:
case p_blood2:
color[0] = color[1] = color[2] = 180 + (rand() & 63);
break;
case p_blood3:
color[0] = (100 + (rand() & 31)); color[1] = color[2] = 0;
break;
case p_smallspark:
color[0] = color[1] = color[2] = color[3] = 255;
default:
//assert(!"ColorForParticle: unexpected type"); -> hexum - FIXME not all types are handled, seems to work ok though
break;
}
return color;
}
#define ADD_PARTICLE_TEXTURE(_ptex, _texnum, _texindex, _components, _s1, _t1, _s2, _t2) \
do { \
particle_textures[_ptex].texnum = _texnum; \
particle_textures[_ptex].components = _components; \
particle_textures[_ptex].coords[_texindex][0] = (_s1 + 1) / 256.0; \
particle_textures[_ptex].coords[_texindex][1] = (_t1 + 1) / 256.0; \
particle_textures[_ptex].coords[_texindex][2] = (_s2 - 1) / 256.0; \
particle_textures[_ptex].coords[_texindex][3] = (_t2 - 1) / 256.0; \
} while(0);
#define ADD_PARTICLE_TYPE(_id, _drawtype, _SrcBlend, _DstBlend, _texture, _startalpha, _grav, _accel, _move, _custom) \
do { \
particle_types[count].id = (_id); \
particle_types[count].drawtype = (_drawtype); \
particle_types[count].SrcBlend = (_SrcBlend); \
particle_types[count].DstBlend = (_DstBlend); \
particle_types[count].texture = (_texture); \
particle_types[count].startalpha = (_startalpha); \
particle_types[count].grav = 9.8 * (_grav); \
particle_types[count].accel = (_accel); \
particle_types[count].move = (_move); \
particle_types[count].custom = (_custom); \
particle_type_index[_id] = count; \
count++; \
} while(0);
void QMB_AllocParticles (void) {
extern cvar_t r_particles_count;
r_numparticles = bound(ABSOLUTE_MIN_PARTICLES, r_particles_count.integer, ABSOLUTE_MAX_PARTICLES);
if (particles || r_numparticles < 1) // seems QMB_AllocParticles() called from wrong place
Sys_Error("QMB_AllocParticles: internal error");
// can't alloc on Hunk, using native memory
particles = (particle_t *) Q_malloc (r_numparticles * sizeof(particle_t));
}
void QMB_InitParticles (void) {
int i, count = 0, particlefont;
int shockwave_texture, lightning_texture, spark_texture; // VULT
Cvar_Register (&amf_part_fulldetail);
if (!host_initialized)
if (COM_CheckParm ("-detailtrails"))
Cvar_LatchedSetValue (&amf_part_fulldetail, 1);
if (!qmb_initialized) {
if (!host_initialized) {
Cvar_SetCurrentGroup(CVAR_GROUP_PARTICLES);
Cvar_Register (&gl_clipparticles);
Cvar_Register (&gl_bounceparticles);
Cvar_ResetCurrentGroup();
}
Q_free (particles); // yeah, shit happens, work around
QMB_AllocParticles ();
}
else {
QMB_ClearParticles (); // also re-allocc particles
qmb_initialized = false; // so QMB particle system will be turned off if we fail to load some texture
}
if (!(particlefont = GL_LoadTextureImage ("textures/particles/particlefont", "qmb:particlefont", 256, 256, TEX_ALPHA | TEX_COMPLAIN | TEX_NOSCALE | TEX_MIPMAP)))
return;
ADD_PARTICLE_TEXTURE(ptex_none, 0, 0, 1, 0, 0, 0, 0);
ADD_PARTICLE_TEXTURE(ptex_blood1, particlefont, 0, 1, 0, 0, 64, 64);
ADD_PARTICLE_TEXTURE(ptex_blood2, particlefont, 0, 1, 64, 0, 128, 64);
ADD_PARTICLE_TEXTURE(ptex_lava, particlefont, 0, 1, 128, 0, 192, 64);
ADD_PARTICLE_TEXTURE(ptex_blueflare, particlefont, 0, 1, 192, 0, 256, 64);
ADD_PARTICLE_TEXTURE(ptex_generic, particlefont, 0, 1, 0, 96, 96, 192);
ADD_PARTICLE_TEXTURE(ptex_smoke, particlefont, 0, 1, 96, 96, 192, 192);
ADD_PARTICLE_TEXTURE(ptex_blood3, particlefont, 0, 1, 192, 96, 256, 160);
ADD_PARTICLE_TEXTURE(ptex_bubble, particlefont, 0, 1, 192, 160, 224, 192);
for (i = 0; i < 8; i++)
ADD_PARTICLE_TEXTURE(ptex_dpsmoke, particlefont, i, 8, i * 32, 64, (i + 1) * 32, 96);
//VULT PARTICLES
if (!(shockwave_texture = GL_LoadTextureImage ("textures/shockwavetex", NULL, 0, 0, TEX_ALPHA | TEX_COMPLAIN | TEX_NOSCALE | TEX_MIPMAP)))
return;
ADD_PARTICLE_TEXTURE(ptex_shockwave, shockwave_texture, 0, 1, 0, 0, 128, 128);
if (!(lightning_texture = GL_LoadTextureImage ("textures/zing1", NULL, 0, 0, TEX_ALPHA | TEX_COMPLAIN | TEX_NOSCALE | TEX_MIPMAP)))
return;
ADD_PARTICLE_TEXTURE(ptex_lightning, lightning_texture, 0, 1, 0, 0, 32, 32);
if (!(spark_texture = GL_LoadTextureImage ("textures/sparktex", NULL, 0, 0, TEX_ALPHA | TEX_COMPLAIN | TEX_NOSCALE | TEX_MIPMAP)))
return;
ADD_PARTICLE_TEXTURE(ptex_spark, spark_texture, 0, 1, 0, 0, 32, 32);
ADD_PARTICLE_TYPE(p_spark, pd_spark, GL_SRC_ALPHA, GL_ONE, ptex_none, 255, -32, 0, pm_bounce, 1.3);
ADD_PARTICLE_TYPE(p_sparkray, pd_sparkray, GL_SRC_ALPHA, GL_ONE, ptex_none, 255, -0, 0, pm_nophysics, 0);
ADD_PARTICLE_TYPE(p_gunblast, pd_spark, GL_SRC_ALPHA, GL_ONE, ptex_none, 255, -16, 0, pm_bounce, 1.3);
ADD_PARTICLE_TYPE(p_fire, pd_billboard, GL_SRC_ALPHA, GL_ONE, ptex_generic, 204, 0, -2.95, pm_die, 0);
ADD_PARTICLE_TYPE(p_chunk, pd_billboard, GL_SRC_ALPHA, GL_ONE, ptex_generic, 255, -16, 0, pm_bounce, 1.475);
ADD_PARTICLE_TYPE(p_shockwave, pd_billboard, GL_SRC_ALPHA, GL_ONE, ptex_generic, 255, 0, -4.85, pm_nophysics, 0);
ADD_PARTICLE_TYPE(p_inferno_flame, pd_billboard, GL_SRC_ALPHA, GL_ONE, ptex_generic, 153, 0, 0, pm_static, 0);
ADD_PARTICLE_TYPE(p_inferno_trail, pd_billboard, GL_SRC_ALPHA, GL_ONE, ptex_generic, 204, 0, 0, pm_die, 0);
ADD_PARTICLE_TYPE(p_trailpart, pd_billboard, GL_SRC_ALPHA, GL_ONE, ptex_generic, 230, 0, 0, pm_static, 0);
ADD_PARTICLE_TYPE(p_smoke, pd_billboard, GL_SRC_ALPHA, GL_ONE, ptex_smoke, 140, 3, 0, pm_normal, 0);
ADD_PARTICLE_TYPE(p_dpfire, pd_billboard, GL_SRC_ALPHA, GL_ONE, ptex_dpsmoke, 144, 0, 0, pm_die, 0);
ADD_PARTICLE_TYPE(p_dpsmoke, pd_billboard, GL_SRC_ALPHA, GL_ONE, ptex_dpsmoke, 85, 3, 0, pm_die, 0);
ADD_PARTICLE_TYPE(p_teleflare, pd_billboard, GL_ONE, GL_ONE, ptex_blueflare, 255, 0, 0, pm_die, 0);
ADD_PARTICLE_TYPE(p_blood1, pd_billboard, GL_ZERO, GL_ONE_MINUS_SRC_COLOR, ptex_blood1, 255, -20, 0, pm_die, 0);
ADD_PARTICLE_TYPE(p_blood2, pd_billboard_vel, GL_ZERO, GL_ONE_MINUS_SRC_COLOR, ptex_blood2, 255, -25, 0, pm_die, 0.018);
ADD_PARTICLE_TYPE(p_lavasplash, pd_billboard, GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA, ptex_lava, 170, 0, 0, pm_nophysics, 0);
ADD_PARTICLE_TYPE(p_blood3, pd_billboard, GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA, ptex_blood3, 255, -20, 0, pm_normal, 0);
ADD_PARTICLE_TYPE(p_bubble, pd_billboard, GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA, ptex_bubble, 204, 8, 0, pm_float, 0);
ADD_PARTICLE_TYPE(p_staticbubble, pd_billboard, GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA, ptex_bubble, 204, 0, 0, pm_static, 0);
//VULT PARTICLES
ADD_PARTICLE_TYPE(p_rain, pd_hide, GL_SRC_ALPHA, GL_ONE, ptex_none, 100, 0, 0, pm_rain, 0);
ADD_PARTICLE_TYPE(p_alphatrail, pd_billboard, GL_SRC_ALPHA, GL_ONE, ptex_generic, 100, 0, 0, pm_static, 0);
ADD_PARTICLE_TYPE(p_railtrail, pd_billboard, GL_SRC_ALPHA, GL_ONE, ptex_generic, 255, 0, 0, pm_die, 0);
ADD_PARTICLE_TYPE(p_vxblood, pd_billboard, GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA, ptex_blood3, 255, -38, 0, pm_normal, 0); //HyperNewbie - Blood does NOT glow like fairy light
ADD_PARTICLE_TYPE(p_streak, pd_hide, GL_SRC_ALPHA, GL_ONE, ptex_none, 255, -64, 0, pm_streak, 1.5); //grav was -64
ADD_PARTICLE_TYPE(p_streakwave, pd_hide, GL_SRC_ALPHA, GL_ONE, ptex_none, 255, 0, 0, pm_streakwave, 0);
ADD_PARTICLE_TYPE(p_lavatrail, pd_billboard, GL_SRC_ALPHA, GL_ONE, ptex_generic, 255, 3, 0, pm_normal, 0);
ADD_PARTICLE_TYPE(p_vxsmoke, pd_billboard, GL_ZERO, GL_ONE_MINUS_SRC_COLOR, ptex_smoke, 140, 3, 0, pm_normal, 0);
ADD_PARTICLE_TYPE(p_muzzleflash, pd_billboard, GL_SRC_ALPHA, GL_ONE, ptex_generic, 128, 0, 0, pm_die, 0);
ADD_PARTICLE_TYPE(p_inferno, pd_hide, GL_SRC_ALPHA, GL_ONE, ptex_none, 0, 0, 0, pm_inferno, 0);
ADD_PARTICLE_TYPE(p_2dshockwave, pd_normal, GL_SRC_ALPHA, GL_ONE, ptex_shockwave, 255, 0, 0, pm_static, 0);
ADD_PARTICLE_TYPE(p_vxrocketsmoke, pd_billboard, GL_SRC_ALPHA, GL_ONE, ptex_generic, 128, 0, 0, pm_normal, 0);
ADD_PARTICLE_TYPE(p_flame, pd_billboard, GL_SRC_ALPHA, GL_ONE, ptex_generic, 200, 10, 0, pm_die, 0);
ADD_PARTICLE_TYPE(p_trailbleed, pd_billboard, GL_SRC_ALPHA, GL_ONE, ptex_generic, 200, 0, 0, pm_static, 0);
ADD_PARTICLE_TYPE(p_bleedspike, pd_billboard, GL_SRC_ALPHA, GL_ONE, ptex_generic, 200, 0, 0, pm_static, 0);
ADD_PARTICLE_TYPE(p_lightningbeam, pd_beam, GL_SRC_ALPHA, GL_ONE, ptex_lightning, 128, 0, 0, pm_die, 0);
ADD_PARTICLE_TYPE(p_bubble2, pd_billboard, GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA, ptex_bubble, 204, 1, 0, pm_float, 0);
ADD_PARTICLE_TYPE(p_bloodcloud, pd_billboard, GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA, ptex_generic, 255, -3, 0, pm_normal, 0);
ADD_PARTICLE_TYPE(p_chunkdir, pd_billboard, GL_SRC_ALPHA, GL_ONE, ptex_generic, 255, -32, 0, pm_bounce, 1.475);
ADD_PARTICLE_TYPE(p_smallspark, pd_beam, GL_SRC_ALPHA, GL_ONE, ptex_spark, 255, -64, 0, pm_bounce, 1.5); //grav was -64
//HyperNewbie particles
ADD_PARTICLE_TYPE(p_slimeglow, pd_billboard, GL_SRC_ALPHA, GL_ONE, ptex_lava, 72, 0, 0, pm_nophysics, 0); //Glow
ADD_PARTICLE_TYPE(p_slimebubble, pd_billboard, GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA, ptex_bubble, 204, 0, 0, pm_static, 0);
ADD_PARTICLE_TYPE(p_blacklavasmoke, pd_billboard, GL_ZERO, GL_ONE_MINUS_SRC_COLOR, ptex_smoke, 140, 3, 0, pm_normal, 0);
//Allow overkill trails
if (amf_part_fulldetail.integer)
{
ADD_PARTICLE_TYPE(p_streaktrail, pd_billboard, GL_SRC_ALPHA, GL_ONE, ptex_generic, 128, 0, 0, pm_die, 0);
}
else
{
ADD_PARTICLE_TYPE(p_streaktrail, pd_beam, GL_SRC_ALPHA, GL_ONE, ptex_none, 128, 0, 0, pm_die, 0);
}
qmb_initialized = true;
}
void QMB_ClearParticles (void) {
int i;
if (!qmb_initialized)
return;
Q_free (particles); // free
QMB_AllocParticles (); // and alloc again
particle_count = 0;
memset(particles, 0, r_numparticles * sizeof(particle_t));
free_particles = &particles[0];
for (i = 0; i + 1 < r_numparticles; i++)
particles[i].next = &particles[i + 1];
particles[r_numparticles - 1].next = NULL;
for (i = 0; i < num_particletypes; i++)
particle_types[i].start = NULL;
//VULT STATS
ParticleCount = 0;
ParticleCountHigh = 0;
}
// TODO: Split up
static void QMB_UpdateParticles(void)
{
int i, contents;
float grav, bounce;
vec3_t oldorg, stop, normal;
particle_type_t *pt;
particle_t *p, *kill;
if (!qmb_initialized)
return;
particle_count = 0;
grav = movevars.gravity / 800.0;
//VULT PARTICLES
WeatherEffect();
for (i = 0; i < num_particletypes; i++)
{
pt = &particle_types[i];
#ifdef _WIN32
if (pt && ((int) pt->start == 1))
{
/* hack! fixme!
* for some reason in some occasions - MS VS 2005 compiler
* this address doesn't point to 0 as other unitialized do, but to 0x00000001 */
pt->start = NULL;
Com_DPrintf("ERROR: particle_type[%i].start == 1\n", i);
}
#endif // _WIN32
if (pt->start)
{
for (p = pt->start; p && p->next; )
{
kill = p->next;
if (kill->die <= particle_time)
{
p->next = kill->next;
kill->next = free_particles;
free_particles = kill;
//VULT STATS
ParticleStats(-1);
}
else
{
p = p->next;
}
}
if (pt->start->die <= particle_time)
{
kill = pt->start;
pt->start = kill->next;
kill->next = free_particles;
free_particles = kill;
//VULT STATS
ParticleStats(-1);
}
}
for (p = pt->start; p; p = p->next)
{
if (particle_time < p->start)
continue;
particle_count++;
p->size += p->growth * cls.frametime;
if (p->size <= 0)
{
p->die = 0;
continue;
}
//VULT PARTICLE
if (pt->id == p_streaktrail || pt->id == p_lightningbeam)
p->color[3] = p->bounces * ((p->die - particle_time) / (p->die - p->start));
else
p->color[3] = pt->startalpha * ((p->die - particle_time) / (p->die - p->start));
p->rotangle += p->rotspeed * cls.frametime;
if (p->hit)
continue;
//VULT - switched these around so velocity is scaled before gravity is applied
VectorScale(p->vel, 1 + pt->accel * cls.frametime, p->vel)
p->vel[2] += pt->grav * grav * cls.frametime;
//VectorScale(p->vel, 1 + pt->accel * cls.frametime, p->vel)
switch (pt->move)
{
case pm_static:
break;
case pm_normal:
VectorCopy(p->org, oldorg);
VectorMA(p->org, cls.frametime, p->vel, p->org);
if (CONTENTS_SOLID == TruePointContents (p->org)) {
p->hit = 1;
VectorCopy(oldorg, p->org);
VectorClear(p->vel);
}
break;
case pm_float:
VectorMA(p->org, cls.frametime, p->vel, p->org);
p->org[2] += p->size + 1;
contents = TruePointContents(p->org);
if (!ISUNDERWATER(contents))
p->die = 0;
p->org[2] -= p->size + 1;
break;
case pm_nophysics:
VectorMA(p->org, cls.frametime, p->vel, p->org);
break;
case pm_die:
VectorMA(p->org, cls.frametime, p->vel, p->org);
if (CONTENTS_SOLID == TruePointContents (p->org))
p->die = 0;
break;
case pm_bounce:
if (!gl_bounceparticles.value || p->bounces)
{
if (pt->id == p_smallspark)
VectorCopy(p->org, p->endorg);
VectorMA(p->org, cls.frametime, p->vel, p->org);
if (CONTENTS_SOLID == TruePointContents (p->org))
p->die = 0;
}
else
{
VectorCopy(p->org, oldorg);
if (pt->id == p_smallspark)
VectorCopy(oldorg, p->endorg);
VectorMA(p->org, cls.frametime, p->vel, p->org);
if (CONTENTS_SOLID == TruePointContents (p->org))
{
if (TraceLineN(oldorg, p->org, stop, normal))
{
VectorCopy(stop, p->org);
bounce = -pt->custom * DotProduct(p->vel, normal);
VectorMA(p->vel, bounce, normal, p->vel);
p->bounces++;
if (pt->id == p_smallspark)
VectorCopy(stop, p->endorg);
}
}
}
break;
//VULT PARTICLES
case pm_rain:
VectorCopy(p->org, oldorg);
VectorMA(p->org, cls.frametime, p->vel, p->org);
contents = TruePointContents(p->org);
if (ISUNDERWATER(contents) || contents == CONTENTS_SOLID)
{
if (!amf_weather_rain_fast.value || amf_weather_rain_fast.value == 2)
{
vec3_t rorg;
VectorCopy(oldorg, rorg);
//Find out where the rain should actually hit
//This is a slow way of doing it, I'll fix it later maybe...
while (1)
{
rorg[2] = rorg[2] - 0.5f;
contents = TruePointContents(rorg);
if (contents == CONTENTS_WATER)
{
if (amf_weather_rain_fast.value == 2)
break;
RainSplash(rorg);
break;
}
else if (contents == CONTENTS_SOLID)
{
byte col[3] = {128,128,128};
SparkGen (rorg, col, 3, 50, 0.15);
break;
}
}
VectorCopy(rorg, p->org);
VX_ParticleTrail (oldorg, p->org, p->size, 0.2, p->color);
}
p->die = 0;
}
else
VX_ParticleTrail (oldorg, p->org, p->size, 0.2, p->color);
break;
//VULT PARTICLES
case pm_streak:
VectorCopy(p->org, oldorg);
VectorMA(p->org, cls.frametime, p->vel, p->org);
if (CONTENTS_SOLID == TruePointContents (p->org))
{
if (TraceLineN(oldorg, p->org, stop, normal))
{
VectorCopy(stop, p->org);
bounce = -pt->custom * DotProduct(p->vel, normal);
VectorMA(p->vel, bounce, normal, p->vel);
//VULT - Prevent crazy sliding
/* p->vel[0] = 2 * p->vel[0] / 3;
p->vel[1] = 2 * p->vel[1] / 3;
p->vel[2] = 2 * p->vel[2] / 3;*/
}
}
VX_ParticleTrail (oldorg, p->org, p->size, 0.2, p->color);
if (VectorLength(p->vel) == 0)
p->die = 0;
break;
case pm_streakwave:
VectorCopy(p->org, oldorg);
VectorMA(p->org, cls.frametime, p->vel, p->org);
VX_ParticleTrail (oldorg, p->org, p->size, 0.5, p->color);
p->vel[0] = 19 * p->vel[0] / 20;
p->vel[1] = 19 * p->vel[1] / 20;
p->vel[2] = 19 * p->vel[2] / 20;
break;
case pm_inferno:
VectorCopy(p->org, oldorg);
VectorMA(p->org, cls.frametime, p->vel, p->org);
/* if (CONTENTS_SOLID == TruePointContents (p->org))
{*/
if (TraceLineN(oldorg, p->org, stop, normal))
{
VectorCopy(stop, p->org);
CL_FakeExplosion(p->org);
p->die = 0;
}
//}
VectorCopy(p->org, p->endorg);
InfernoTrail(oldorg, p->endorg, p->vel);
break;
default:
assert(!"QMB_UpdateParticles: unexpected pt->move");
break;
}
}
}
}
__inline static void DRAW_PARTICLE_BILLBOARD(particle_texture_t * ptex, particle_t * p, vec3_t coord[4])
{
vec3_t verts[4];
float scale = p->size;
if (p->rotspeed)
{
matrix3x3_t rotate_matrix;
Matrix3x3_CreateRotate(rotate_matrix, DEG2RAD(p->rotangle), vpn);
Matrix3x3_MultiplyByVector(verts[0], (const vec_t (*)[3]) rotate_matrix, coord[0]);
Matrix3x3_MultiplyByVector(verts[1], (const vec_t (*)[3]) rotate_matrix, coord[1]);
// do some fast math for verts[2] and verts[3].
VectorNegate(verts[0], verts[2]);
VectorNegate(verts[1], verts[3]);
VectorMA(p->org, scale, verts[0], verts[0]);
VectorMA(p->org, scale, verts[1], verts[1]);
VectorMA(p->org, scale, verts[2], verts[2]);
VectorMA(p->org, scale, verts[3], verts[3]);
}
else
{
VectorMA(p->org, scale, coord[0], verts[0]);
VectorMA(p->org, scale, coord[1], verts[1]);
VectorMA(p->org, scale, coord[2], verts[2]);
VectorMA(p->org, scale, coord[3], verts[3]);
}
glColor4ubv(p->color);
glBegin(GL_QUADS);
glTexCoord2f(ptex->coords[p->texindex][0], ptex->coords[p->texindex][3]);
glVertex3fv(verts[0]);
glTexCoord2f(ptex->coords[p->texindex][0], ptex->coords[p->texindex][1]);
glVertex3fv(verts[1]);
glTexCoord2f(ptex->coords[p->texindex][2], ptex->coords[p->texindex][1]);
glVertex3fv(verts[2]);
glTexCoord2f(ptex->coords[p->texindex][2], ptex->coords[p->texindex][3]);
glVertex3fv(verts[3]);
glEnd();
}
void QMB_DrawParticles (void) {
int i, j, k, drawncount;
vec3_t v, up, right, billboard[4], velcoord[4], neworg;
particle_t *p;
particle_type_t *pt;
particle_texture_t *ptex;
int texture = 0, l;
if (!qmb_initialized)
return;
particle_time = r_refdef2.time;
if (!ISPAUSED)
QMB_UpdateParticles();
if (gl_fogenable.value)
{
glDisable(GL_FOG);
}
VectorAdd(vup, vright, billboard[2]);
VectorSubtract(vright, vup, billboard[3]);
VectorNegate(billboard[2], billboard[0]);
VectorNegate(billboard[3], billboard[1]);
glDepthMask(GL_FALSE);
glEnable(GL_BLEND);
glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
glShadeModel(GL_SMOOTH);
for (i = 0; i < num_particletypes; i++) {
pt = &particle_types[i];
if (!pt->start)
continue;
if (pt->drawtype == pd_hide)
continue;
glBlendFunc(pt->SrcBlend, pt->DstBlend);
switch(pt->drawtype) {
//VULT PARTICLES
case pd_beam:
ptex = &particle_textures[pt->texture];
glEnable(GL_TEXTURE_2D);
//VULT PARTICLES
if (texture != ptex->texnum)
{
GL_Bind(ptex->texnum);
texture = ptex->texnum;
}
for (p = pt->start; p; p = p->next)
{
if (particle_time < p->start || particle_time >= p->die)
continue;
glColor4ubv(p->color);
for (l=amf_part_traildetail.value; l>0 ;l--)
{
R_CalcBeamVerts(varray_vertex, p->org, p->endorg, p->size/(l*amf_part_trailwidth.value));
glBegin (GL_QUADS);
glTexCoord2f (1,0);
glVertex3f(varray_vertex[ 0], varray_vertex[ 1], varray_vertex[ 2]);
glTexCoord2f (1,1);
glVertex3f(varray_vertex[ 4], varray_vertex[ 5], varray_vertex[ 6]);
glTexCoord2f (0,1);
glVertex3f(varray_vertex[ 8], varray_vertex[ 9], varray_vertex[10]);
glTexCoord2f (0,0);
glVertex3f(varray_vertex[12], varray_vertex[13], varray_vertex[14]);
glEnd();
}
}
break;
case pd_spark:
glDisable(GL_TEXTURE_2D);
for (p = pt->start; p; p = p->next) {
if (particle_time < p->start || particle_time >= p->die)
continue;
if (!TraceLineN(p->endorg, p->org, neworg, NULL))
VectorCopy(p->org, neworg);
glBegin(GL_TRIANGLE_FAN);
glColor4ubv(p->color);
glVertex3fv(p->org);
glColor4ub(p->color[0] >> 1, p->color[1] >> 1, p->color[2] >> 1, 0);
for (j = 7; j >= 0; j--) {
for (k = 0; k < 3; k++)
v[k] = p->org[k] - p->vel[k] / 8 + vright[k] * cost[j % 7] * p->size + vup[k] * sint[j % 7] * p->size;
glVertex3fv(v);
}
glEnd();
}
break;
case pd_sparkray:
glDisable(GL_TEXTURE_2D);
for (p = pt->start; p; p = p->next) {
if (particle_time < p->start || particle_time >= p->die)
continue;
if (!TraceLineN(p->endorg, p->org, neworg, NULL))
VectorCopy(p->org, neworg);
glBegin (GL_TRIANGLE_FAN);
glColor4ubv(p->color);
glVertex3fv(p->endorg);
glColor4ub(p->color[0] >> 1, p->color[1] >> 1, p->color[2] >> 1, 0);
for (j = 7; j >= 0; j--) {
for (k = 0; k < 3; k++)
v[k] = neworg[k] + vright[k] * cost[j % 7] * p->size + vup[k] * sint[j % 7] * p->size;
glVertex3fv (v);
}
glEnd();
}
break;
case pd_billboard:
ptex = &particle_textures[pt->texture];
glEnable(GL_TEXTURE_2D);
//VULT PARTICLES - I gather this speeds it up, but I haven't really checked
if (texture != ptex->texnum)
{
GL_Bind(ptex->texnum);
texture = ptex->texnum;
}
drawncount = 0;
for (p = pt->start; p; p = p->next) {
if (particle_time < p->start || particle_time >= p->die)
continue;
if (gl_clipparticles.value) {
if (drawncount >= 3 && VectorSupCompare(p->org, r_origin, 30))
continue;
drawncount++;
}
DRAW_PARTICLE_BILLBOARD(ptex, p, billboard);
}
break;
case pd_billboard_vel:
ptex = &particle_textures[pt->texture];
glEnable(GL_TEXTURE_2D);
//VULT PARTICLES
if (texture != ptex->texnum)
{
GL_Bind(ptex->texnum);
texture = ptex->texnum;
}
for (p = pt->start; p; p = p->next) {
if (particle_time < p->start || particle_time >= p->die)
continue;
VectorCopy (p->vel, up);
CrossProduct(vpn, up, right);
VectorNormalizeFast(right);
VectorScale(up, pt->custom, up);
VectorAdd(up, right, velcoord[2]);
VectorSubtract(right, up, velcoord[3]);
VectorNegate(velcoord[2], velcoord[0]);
VectorNegate(velcoord[3], velcoord[1]);
DRAW_PARTICLE_BILLBOARD(ptex, p, velcoord);
}
break;
//VULT PARTICLES - This produces the shockwave effect
//Mind you it can be used for more than that... Decals come to mind first
case pd_normal:
ptex = &particle_textures[pt->texture];
glEnable(GL_TEXTURE_2D);
//VULT PARTICLES
if (texture != ptex->texnum)
{
GL_Bind(ptex->texnum);
texture = ptex->texnum;
}
for (p = pt->start; p; p = p->next)
{
if (particle_time < p->start || particle_time >= p->die)
continue;
glPushMatrix();
glTranslatef(p->org[0], p->org[1], p->org[2]);
glScalef(p->size, p->size, p->size);
glRotatef(p->endorg[0], 0, 1, 0);
glRotatef(p->endorg[1], 0, 0, 1);
glRotatef(p->endorg[2], 1, 0, 0);
glColor4ubv(p->color);
glBegin (GL_QUADS);
glTexCoord2f (0,0);
glVertex3f (-p->size, -p->size, 0);
glTexCoord2f (1,0);
glVertex3f (p->size, -p->size, 0);
glTexCoord2f (1,1);
glVertex3f (p->size, p->size, 0);
glTexCoord2f (0,1);
glVertex3f (-p->size, p->size, 0);
glEnd();
//And since quads seem to be one sided...
glRotatef(180, 1, 0, 0);
glColor4ubv(p->color);
glBegin (GL_QUADS);
glTexCoord2f (0,0);
glVertex3f (-p->size, -p->size, 0);
glTexCoord2f (1,0);
glVertex3f (p->size, -p->size, 0);
glTexCoord2f (1,1);
glVertex3f (p->size, p->size, 0);
glTexCoord2f (0,1);
glVertex3f (-p->size, p->size, 0);
glEnd();
glPopMatrix();
}
break;
default:
assert(!"QMB_DrawParticles: unexpected drawtype");
break;
}
}
glEnable(GL_TEXTURE_2D);
glDepthMask(GL_TRUE);
glDisable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);
glShadeModel(GL_FLAT);
if (gl_fogenable.value)
{
glEnable(GL_FOG);
}
}
#define INIT_NEW_PARTICLE(_pt, _p, _color, _size, _time) \
_p = free_particles; \
free_particles = _p->next; \
_p->next = _pt->start; \
_pt->start = _p; \
_p->size = _size; \
_p->hit = 0; \
_p->start = r_refdef2.time; \
_p->die = _p->start + _time; \
_p->growth = 0; \
_p->rotspeed = 0; \
_p->texindex = (rand() % particle_textures[_pt->texture].components); \
_p->bounces = 0; \
VectorCopy(_color, _p->color); \
ParticleStats(1); //VULT PARTICLES
__inline static void AddParticle(part_type_t type, vec3_t org, int count, float size, float time, col_t col, vec3_t dir) {
byte *color;
int i, j;
float tempSize;
particle_t *p;
particle_type_t *pt;
if (!qmb_initialized)
Sys_Error("QMB particle added without initialization");
if (size <= 0 || time <= 0)
{
Con_DPrintf("AddParticle() failed, type %d, size %f, time %f\n", type, size, time);
return;
}
if (type < 0 || type >= num_particletypes)
Sys_Error("AddParticle: Invalid type (%d)", type);
pt = &particle_types[particle_type_index[type]];