forked from SpiritQuaddicted/reQuiem
-
Notifications
You must be signed in to change notification settings - Fork 0
/
gl_rmain.c
1793 lines (1495 loc) · 43.7 KB
/
gl_rmain.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.
*/
// gl_rmain.c
#include "quakedef.h"
#ifndef RQM_SV_ONLY
entity_t r_worldentity;
qboolean r_cache_thrash; // compatibility
vec3_t modelorg, r_entorigin;
qboolean OnChange_lightmaps (cvar_t *var, const char *value); // JDH
int r_visframecount; // bumped when going to a new PVS
int r_framecount; // used for dlight push checking
mplane_t frustum[4];
int c_brush_polys, c_alias_polys;
int particletexture; // little dot for particles
int playertextures; // base number for up to MAX_SCOREBOARD color translated skins
int skyboxtextures; // by joe
int underwatertexture = 0;
//int detailtexture = 0;
int detailtexture[NUM_DETAIL_LEVELS];
// view origin
vec3_t vup;
vec3_t vpn;
vec3_t vright;
vec3_t r_origin;
#ifdef SHINYWATER
int chrometexture2 = 0; // JT added chrometexture2
float r_world_matrix[16];
#endif
// screen size info
refdef_t r_refdef;
mleaf_t *r_viewleaf, *r_oldviewleaf;
mleaf_t *r_viewleaf2, *r_oldviewleaf2; // for watervis hack
texture_t *r_notexture_mip;
int d_lightstylevalue[256]; // 8.8 fraction of base light value
cvar_t r_drawentities = {"r_drawentities", "1"};
cvar_t r_drawviewmodel = {"r_drawviewmodel", "1"};
cvar_t r_viewmodelsize = {"r_viewmodelsize", "1", CVAR_FLAG_ARCHIVE};
cvar_t r_speeds = {"r_speeds", "0"};
cvar_t r_fullbright = {"r_fullbright", "0", 0, OnChange_lightmaps};
cvar_t r_lightmap = {"r_lightmap", "0"};
cvar_t r_shadows = {"r_shadows", "0", CVAR_FLAG_ARCHIVE};
cvar_t r_wateralpha = {"r_wateralpha", "1", CVAR_FLAG_ARCHIVE};
cvar_t r_dynamic = {"r_dynamic", "1", CVAR_FLAG_ARCHIVE};
cvar_t r_flatlightstyles = {"r_flatlightstyles", "0"}; // Fitz
cvar_t r_fullbrightskins = {"r_fullbrightskins", "0", CVAR_FLAG_ARCHIVE};
cvar_t r_skytype = {"r_skytype", "1", CVAR_FLAG_ARCHIVE};
cvar_t r_skycolor = {"r_skycolor", "auto", CVAR_FLAG_ARCHIVE | CVAR_FLAG_NOCASE};
cvar_t r_modelbrightness = {"r_modelbrightness", "1", CVAR_FLAG_ARCHIVE};
cvar_t r_farclip = {"r_farclip", "16384", CVAR_FLAG_ARCHIVE};
cvar_t gl_skyclip = {"gl_skyclip", "4608", CVAR_FLAG_ARCHIVE}; // from aguirRe's nehquake (original neh used 4096)
//cvar_t gl_skyfog = {"gl_skyfog", "0.5", CVAR_FLAG_ARCHIVE};
qboolean OnChange_r_skybox (cvar_t *var, const char *string);
cvar_t r_skybox = {"r_skybox", "", 0, OnChange_r_skybox};
// [email protected]: model interpolation
cvar_t gl_interpolate_animation = {"gl_interpolate_animation", "1", CVAR_FLAG_ARCHIVE};
cvar_t gl_interpolate_transform = {"gl_interpolate_transform", "1", CVAR_FLAG_ARCHIVE};
cvar_t gl_clear = {"gl_clear", "1", CVAR_FLAG_ARCHIVE};
cvar_t gl_cull = {"gl_cull", "1", CVAR_FLAG_ARCHIVE};
//cvar_t gl_ztrick = {"gl_ztrick", "1", CVAR_FLAG_ARCHIVE};
cvar_t gl_smoothmodels = {"gl_smoothmodels", "1", CVAR_FLAG_ARCHIVE};
cvar_t gl_affinemodels = {"gl_affinemodels", "0", CVAR_FLAG_ARCHIVE};
cvar_t gl_polyblend = {"gl_polyblend", "1", CVAR_FLAG_ARCHIVE};
cvar_t gl_flashblend = {"gl_flashblend", "0", CVAR_FLAG_ARCHIVE};
cvar_t gl_playermip = {"gl_playermip", "0", CVAR_FLAG_ARCHIVE};
cvar_t gl_nocolors = {"gl_nocolors", "0", CVAR_FLAG_ARCHIVE};
cvar_t gl_finish = {"gl_finish", "0", CVAR_FLAG_ARCHIVE};
cvar_t gl_loadlitfiles = {"gl_loadlitfiles", "1", CVAR_FLAG_ARCHIVE};
cvar_t gl_doubleeyes = {"gl_doubleeyes", "1", CVAR_FLAG_ARCHIVE};
cvar_t gl_interdist = {"gl_interpolate_distance", "17000", CVAR_FLAG_ARCHIVE};
cvar_t gl_waterfog = {"gl_waterfog", "0", CVAR_FLAG_ARCHIVE};
cvar_t gl_waterfog_density = {"gl_waterfog_density", "0.5", CVAR_FLAG_ARCHIVE};
cvar_t gl_detail = {"gl_detail", "0", CVAR_FLAG_ARCHIVE};
cvar_t gl_caustics = {"gl_caustics", "0", CVAR_FLAG_ARCHIVE};
cvar_t gl_ringalpha = {"gl_ringalpha", "0.4", CVAR_FLAG_ARCHIVE};
cvar_t gl_fb_world = {"gl_fb_world", "1", CVAR_FLAG_ARCHIVE};
cvar_t gl_fb_bmodels = {"gl_fb_bmodels", "1", CVAR_FLAG_ARCHIVE};
cvar_t gl_fb_models = {"gl_fb_models", "1", CVAR_FLAG_ARCHIVE};
cvar_t gl_solidparticles = {"gl_solidparticles", "0", CVAR_FLAG_ARCHIVE};
cvar_t gl_vertexlights = {"gl_vertexlights", "0", CVAR_FLAG_ARCHIVE};
cvar_t gl_subdivide_size = {"gl_subdivide_size", "128", CVAR_FLAG_ARCHIVE};
cvar_t gl_part_explosions = {"gl_part_explosions", "0", CVAR_FLAG_ARCHIVE};
cvar_t gl_part_trails = {"gl_part_trails", "0", CVAR_FLAG_ARCHIVE};
cvar_t gl_part_spikes = {"gl_part_spikes", "0", CVAR_FLAG_ARCHIVE};
cvar_t gl_part_gunshots = {"gl_part_gunshots", "0", CVAR_FLAG_ARCHIVE};
cvar_t gl_part_blood = {"gl_part_blood", "0", CVAR_FLAG_ARCHIVE};
cvar_t gl_part_telesplash = {"gl_part_telesplash", "0", CVAR_FLAG_ARCHIVE};
cvar_t gl_part_blobs = {"gl_part_blobs", "0", CVAR_FLAG_ARCHIVE};
cvar_t gl_part_lavasplash = {"gl_part_lavasplash", "0", CVAR_FLAG_ARCHIVE};
cvar_t gl_part_inferno = {"gl_part_inferno", "0", CVAR_FLAG_ARCHIVE};
cvar_t gl_part_flames = {"gl_part_flames", "0", CVAR_FLAG_ARCHIVE};
cvar_t gl_part_lightning = {"gl_part_lightning", "0", CVAR_FLAG_ARCHIVE};
cvar_t gl_part_spiketrails = {"gl_part_spiketrails", "0", CVAR_FLAG_ARCHIVE};
cvar_t gl_part_bubbles = {"gl_part_bubbles", "0", CVAR_FLAG_ARCHIVE};
cvar_t gl_part_other = {"gl_part_other", "0", CVAR_FLAG_ARCHIVE};
#ifdef SHINYWATER
cvar_t gl_shinywater = {"gl_shinywater", "0", CVAR_FLAG_ARCHIVE}; // JT030105 - add reflections
#endif
cvar_t gl_skyhack = {"gl_skyhack", "0", CVAR_FLAG_ARCHIVE};
// less than 0 --> use old, slow code **TEMP**
// 0 --> use new, faster code
// 1 --> use very fast, but buggy code on skyboxes only
// 2 --> use very fast, but buggy code on skyboxes & MH
/***********************JDH*********************/
#ifdef FITZWORLD
qboolean vis_changed = false;
qboolean OnChange_r_novis (cvar_t *var, const char *value)
{
vis_changed = true;
return false; // allow change
}
qboolean OnChange_r_fastworld (cvar_t *var, const char *string)
{
r_oldviewleaf = r_oldviewleaf2 = NULL; // force rebuilding of texture chains
return false; // allow change
}
cvar_t r_fastworld = {"r_fastworld", "0", 0, OnChange_r_fastworld}; // instead of RecursiveWorldNode
cvar_t r_novis = {"r_novis", "0", 0, OnChange_r_novis};
#else
cvar_t r_novis = {"r_novis", "0"};
#endif
// JDH
cvar_t r_showbboxes = {"r_showbboxes", "0"}; // from Fitz
cvar_t r_oldsky = {"r_oldsky", "0", CVAR_FLAG_ARCHIVE};
cvar_t gl_glows = {"gl_glows", "1", CVAR_FLAG_ARCHIVE}; // from nehahra
cvar_t gl_glows_flame = {"gl_glows_flame", "1", CVAR_FLAG_ARCHIVE};
cvar_t gl_glows_candle = {"gl_glows_candle", "1", CVAR_FLAG_ARCHIVE};
cvar_t gl_glows_shaft = {"gl_glows_shaft", "1", CVAR_FLAG_ARCHIVE};
cvar_t gl_glows_rocket = {"gl_glows_rocket", "1", CVAR_FLAG_ARCHIVE};
cvar_t gl_glows_quad = {"gl_glows_quad", "1", CVAR_FLAG_ARCHIVE};
cvar_t gl_glows_pent = {"gl_glows_pent", "1", CVAR_FLAG_ARCHIVE};
cvar_t gl_cache_ms2 = {"gl_cache_ms2", "0", CVAR_FLAG_ARCHIVE};
cvar_t gl_lightmode = {"gl_lightmode", "1", CVAR_FLAG_ARCHIVE, OnChange_lightmaps};
cvar_t gl_zfightfix = {"gl_zfightfix", "0", CVAR_FLAG_ARCHIVE};
qboolean r_drawskylast;
// JDH
//johnfitz -- polygon offset
#define OFFSET_BMODEL 1
#define OFFSET_NONE 0
#define OFFSET_DECAL -1
#define OFFSET_FOG -2
#define OFFSET_SHOWTRIS -3
/***********************JDH*********************/
void R_InitBubble (void);
/*
=================
R_CullBox
Returns true if the box is completely outside the frustum
=================
*/
qboolean R_CullBox (const vec3_t mins, const vec3_t maxs)
{
int i;
// JDH: code from DarkPlaces
/* mplane_t *p;
for (i = 0;i < 4;i++)
{
p = frustum + i;
switch(p->signbits)
{
default:
case 0:
if (p->normal[0]*maxs[0] + p->normal[1]*maxs[1] + p->normal[2]*maxs[2] < p->dist)
return true;
break;
case 1:
if (p->normal[0]*mins[0] + p->normal[1]*maxs[1] + p->normal[2]*maxs[2] < p->dist)
return true;
break;
case 2:
if (p->normal[0]*maxs[0] + p->normal[1]*mins[1] + p->normal[2]*maxs[2] < p->dist)
return true;
break;
case 3:
if (p->normal[0]*mins[0] + p->normal[1]*mins[1] + p->normal[2]*maxs[2] < p->dist)
return true;
break;
case 4:
if (p->normal[0]*maxs[0] + p->normal[1]*maxs[1] + p->normal[2]*mins[2] < p->dist)
return true;
break;
case 5:
if (p->normal[0]*mins[0] + p->normal[1]*maxs[1] + p->normal[2]*mins[2] < p->dist)
return true;
break;
case 6:
if (p->normal[0]*maxs[0] + p->normal[1]*mins[1] + p->normal[2]*mins[2] < p->dist)
return true;
break;
case 7:
if (p->normal[0]*mins[0] + p->normal[1]*mins[1] + p->normal[2]*mins[2] < p->dist)
return true;
break;
}
}
return false;
*/
for (i=0 ; i<4 ; i++)
if (BoxOnPlaneSide(mins, maxs, &frustum[i]) == 2)
return true;
return false;
}
#ifdef _WIN32
// JDH: this doesn't seem to work reliably on Linux when fov != 90
/*
=================
R_CullSphere
Returns true if the sphere is completely outside the frustum
=================
*/
qboolean R_CullSphere (const vec3_t centre, float radius)
{
int i;
mplane_t *p;
for (i=0, p=frustum ; i<4 ; i++, p++)
{
if (PlaneDiff(centre, p) <= -radius)
return true;
}
return false;
}
#endif
/*
=============
R_GLRotate
=============
*/
void R_RotateEntity (const entity_t *e, float yaw, float pitch, float rot)
{
// scale back pitch for player (otherwise when chase_active, model can be
// leaning forward all the way to the floor)
/******JDH-from Fitz*******/
if (e == &cl_entities[cl.viewentity])
{
pitch *= 0.3;
}
/******JDH-from Fitz*******/
glRotatef ( yaw, 0, 0, 1);
glRotatef (-pitch, 0, 1, 0);
glRotatef ( rot, 1, 0, 0);
}
/*
=============
R_RotateForEntity
=============
*/
void R_RotateForEntity (const entity_t *e)
{
glTranslatef (e->origin[0], e->origin[1], e->origin[2]);
R_RotateEntity (e, e->angles[1], e->angles[0], e->angles[2]);
}
/*
=============
R_CalcBlendedRotateVector
=============
*/
void R_CalcBlendedRotateVector (entity_t *e, vec3_t v)
{
float blend, timepassed;
int i;
timepassed = fabs(cl.time - e->rotate_start_time);
if (e->rotate_start_time == 0 || timepassed > 1)
{
e->rotate_start_time = cl.time;
VectorCopy (e->angles, e->angles1);
VectorCopy (e->angles, e->angles2);
blend = 1;
}
else if (!VectorCompare (e->angles, e->angles2))
{
e->rotate_start_time = cl.time;
VectorCopy (e->angles2, e->angles1);
VectorCopy (e->angles, e->angles2);
blend = 0;
}
else
{
blend = timepassed / 0.1;
if (/*cl.paused ||*/ blend > 1)
blend = 1;
}
VectorSubtract (e->angles2, e->angles1, v);
// always interpolate along the shortest path
for (i=0 ; i<3 ; i++)
{
if (v[i] > 180)
v[i] -= 360;
else if (v[i] < -180)
v[i] += 360;
}
v[0] *= blend;
v[1] *= blend;
v[2] *= blend;
}
/*
=============
R_DoBlendedTranslate
=============
*/
void R_DoBlendedTranslate (entity_t *e)
{
float blend, timepassed;
vec3_t d;
timepassed = fabs(cl.time - e->translate_start_time);
if (e->translate_start_time == 0 || timepassed > 1)
{
e->translate_start_time = cl.time;
VectorCopy (e->origin, e->origin1);
VectorCopy (e->origin, e->origin2);
blend = 1;
}
else if (!VectorCompare (e->origin, e->origin2))
{
#ifdef _DEBUG
if (cls.demoplayback && /*cl_demorewind.value &&*/ e->modelindex == cl_modelindex[mi_scrag])
blend = 0;
#endif
e->translate_start_time = cl.time;
VectorCopy (e->origin2, e->origin1);
VectorCopy (e->origin, e->origin2);
blend = 0;
}
else
{
#if 1
blend = timepassed / 0.1;
if (/*cl.paused ||*/ blend > 1)
blend = 1;
#else
// 2010/04/30 - demo scrags
if (cl.mtime == cl.mtime_prev)
blend = 1;
//else if (cl.mtime - cl.mtime_prev > 0.1)
// blend = timepassed / 0.1;
else
blend = timepassed / (cl.mtime - cl.mtime_prev);
if (/*cl.paused ||*/ blend > 1)
blend = 1;
#endif
}
VectorSubtract (e->origin2, e->origin1, d);
glTranslatef (e->origin1[0] + (blend * d[0]), e->origin1[1] + (blend * d[1]), e->origin1[2] + (blend * d[2]));
}
#ifdef HEXEN2_SUPPORT
/*
=============
R_DoEntityRotate
=============
*/
void R_DoEntityRotate (entity_t *e, vec3_t angles)
{
vec3_t v;
float yaw, pitch, forward;
if (e->model->flags & EF_FACE_VIEW)
{
VectorSubtract(r_origin,e->origin,v);
VectorNormalize(v);
if (v[1] == 0 && v[0] == 0)
{
yaw = 0;
if (v[2] > 0)
pitch = 90;
else
pitch = 270;
}
else
{
yaw = (int) (atan2(v[1], v[0]) * 180 / M_PI);
if (yaw < 0)
yaw += 360;
forward = sqrt (v[0]*v[0] + v[1]*v[1]);
pitch = (int) (atan2(v[2], forward) * 180 / M_PI);
if (pitch < 0)
pitch += 360;
}
glRotatef(-pitch, 0, 1, 0);
glRotatef( yaw, 0, 0, 1);
glRotatef(-angles[2], 1, 0, 0);
}
else
{
if (e->model->flags & EF_ROTATE)
{
yaw = anglemod((e->origin[0] + e->origin[1])*0.8 + (108*cl.time));
}
else
{
yaw = angles[1];
}
R_RotateEntity( e, yaw, angles[0], -angles[2] );
}
}
//==========================================================================
//
// R_RotateForEntity_H2
//
// Same as R_RotateForEntity(), but checks for EF_ROTATE and modifies
// yaw appropriately.
//
//==========================================================================
void R_RotateForEntity_H2 (entity_t *e)
{
glTranslatef (e->origin[0], e->origin[1], e->origin[2]);
R_DoEntityRotate (e, e->angles);
}
//==========================================================================
//
// R_BlendedRotateForEntity_H2 ****JDH**** MAY HAVE BUGS!!!!
//
// Same as R_BlendedRotateForEntity(), but checks for EF_ROTATE and modifies
// yaw appropriately.
//
//==========================================================================
void R_BlendedRotateForEntity_H2 (entity_t *e)
{
vec3_t d;
// positional interpolation
R_DoBlendedTranslate(e);
// orientation interpolation
R_CalcBlendedRotateVector(e, d);
d[0] += e->angles1[0];
d[1] += e->angles1[1];
d[2] += e->angles1[2];
R_DoEntityRotate(e, d);
}
#endif // #ifdef HEXEN2_SUPPORT
/*
=============
R_BlendedRotateForEntity
[email protected]: model transform interpolation
=============
*/
void R_BlendedRotateForEntity (entity_t *e)
{
vec3_t d;
// positional interpolation
R_DoBlendedTranslate (e);
// orientation interpolation (Euler angles, yuck!)
R_CalcBlendedRotateVector (e, d);
R_RotateEntity (e, e->angles1[1] + d[1], e->angles1[0] + d[0], e->angles1[2] + d[2]);
}
//==================================================================================
#ifdef HEXEN2_SUPPORT
typedef struct sortedent_s
{
entity_t *ent;
vec_t len;
} sortedent_t;
sortedent_t cl_transvisedicts[MAX_VISEDICTS];
sortedent_t cl_transwateredicts[MAX_VISEDICTS];
int cl_numtransvisedicts;
int cl_numtranswateredicts;
#endif
/*
=============
R_DrawEntitiesOnList
=============
*/
void R_DrawEntitiesOnList (void)
{
int i;
vec3_t liteorg;
/*******JDH*******/
entity_t *currententity;
#ifdef HEXEN2_SUPPORT
qboolean item_trans;
if (hexen2)
{
cl_numtransvisedicts = 0;
cl_numtranswateredicts = 0;
}
#endif
/*******JDH*******/
if (!r_drawentities.value)
return;
// draw sprites seperately, because of alpha blending
for (i=0 ; i<cl_numvisedicts ; i++)
{
/******JDH-from nehBJP*******/
if ((i + 1) % 100 == 0)
S_ExtraUpdateTime (); // don't let sound get messed up if going slow
/******JDH-from nehBJP*******/
currententity = cl_visedicts[i];
if (currententity->transparency != 1 && currententity->transparency != 0 && !gl_notrans.value)
{
currententity->transignore = false;
continue;
}
switch (currententity->model->type)
{
case mod_alias:
if (qmb_initialized)
{
if (!gl_part_flames.value && COM_FilenamesEqual(currententity->model->name, "progs/flame0.mdl"))
{
currententity->model = cl.model_precache[cl_modelindex[mi_flame1]];
}
else if (gl_part_flames.value)
{
VectorCopy (currententity->origin, liteorg);
if (currententity->baseline.modelindex == cl_modelindex[mi_flame0])
{
liteorg[2] += 5.5;
QMB_TorchFlame (liteorg, 8, 0.8); // changed from 7 to 8
}
else if (currententity->baseline.modelindex == cl_modelindex[mi_flame1])
{
liteorg[2] += 5.5;
QMB_TorchFlame (liteorg, 8, 0.8); // changed from 7 to 8
currententity->model = cl.model_precache[cl_modelindex[mi_flame0]];
}
else if (currententity->baseline.modelindex == cl_modelindex[mi_flame2])
{
liteorg[2] -= 1;
QMB_TorchFlame (liteorg, 15, 1); // changed from 12 to 15
continue;
}
}
}
#ifdef HEXEN2_SUPPORT
if (hexen2)
{
item_trans = ((currententity->drawflags & DRF_TRANSLUCENT) ||
(currententity->model->flags & (EF_TRANSPARENT|EF_HOLEY|EF_SPECIAL_TRANS))) != 0;
if (item_trans) break;
}
#endif
R_DrawAliasModel (currententity);
break;
case mod_brush:
#ifdef HEXEN2_SUPPORT
if (hexen2)
{
item_trans = ((currententity->drawflags & DRF_TRANSLUCENT) != 0);
if (item_trans) break;
}
#endif
R_DrawBrushModel (currententity);
break;
case mod_md3:
#ifdef HEXEN2_SUPPORT
item_trans = false;
#endif
R_DrawQ3Model (currententity);
break;
#ifdef HEXEN2_SUPPORT
case mod_sprite:
item_trans = true;
break;
#endif
default:
#ifdef HEXEN2_SUPPORT
item_trans = false;
#endif
break;
}
#ifdef HEXEN2_SUPPORT
if (hexen2 && item_trans)
{
mleaf_t *pLeaf = Mod_PointInLeaf (currententity->origin, cl.worldmodel);
if (pLeaf->contents != CONTENTS_WATER)
cl_transvisedicts[cl_numtransvisedicts++].ent = currententity;
else
cl_transwateredicts[cl_numtranswateredicts++].ent = currententity;
}
#endif
}
}
typedef struct distent_s
{
float dist;
entity_t *ent;
} distent_t;
static int distcomp (const void *arg1, const void *arg2)
{
return ((distent_t *)arg2)->dist - ((distent_t *)arg1)->dist;
}
/*
=============
R_DrawTransEntities
=============
*/
void GL_DrawAliasGlow (entity_t *currententity, model_t *clmodel);
void R_DrawTransEntities (void)
{
// need to draw back to front
// fixme: this isn't my favorite option
int i,j;
distent_t dent[MAX_VISEDICTS];
vec3_t start, test;
/*******JDH*******/
entity_t *currententity;
/*******JDH*******/
VectorCopy (r_refdef.vieworg, start);
if (!r_drawentities.value)
return;
for (i=j=0 ; i<cl_numvisedicts ; i++)
{
currententity = cl_visedicts[i];
if (!currententity->glow && (currententity->transignore || currententity->transparency == 1 || currententity->transparency == 0) )
continue;
VectorCopy (currententity->origin, test);
if (currententity->model->type == mod_brush)
{
test[0] += currententity->model->mins[0];
test[1] += currententity->model->mins[1];
test[2] += currententity->model->mins[2];
}
dent[j].dist = (((test[0] - start[0]) * (test[0] - start[0])) +
((test[1] - start[1]) * (test[1] - start[1])) +
((test[2] - start[2]) * (test[2] - start[2])));
dent[j++].ent = currententity;
}
// Sort in descending dist order, i.e. back to front
qsort (dent, j, sizeof(distent_t), distcomp);
for (i = 0; i < j; ++i)
{
currententity = dent[i].ent;
switch (currententity->model->type)
{
case mod_alias:
if (currententity->transparency != 0 && currententity->transparency != 1)
R_DrawAliasModel (currententity);
if (currententity->glow)
GL_DrawAliasGlow (currententity, currententity->model);
break;
case mod_brush:
R_DrawBrushModel (currententity);
break;
default:
break;
}
}
}
#ifdef HEXEN2_SUPPORT
int transCompare(const void *arg1, const void *arg2 )
{
const sortedent_t *a1, *a2;
a1 = (sortedent_t *) arg1;
a2 = (sortedent_t *) arg2;
return (a2->len - a1->len); // Sorted in reverse order. Neat, huh?
}
void R_DrawTransEntitiesOnList (qboolean inwater)
{
int i;
int numents;
sortedent_t *theents;
entity_t *currententity;
int depthMaskWrite = 0;
vec3_t result;
theents = (inwater) ? cl_transwateredicts : cl_transvisedicts;
numents = (inwater) ? cl_numtranswateredicts : cl_numtransvisedicts;
if ( numents == 0 ) return;
for (i=0; i<numents; i++)
{
VectorSubtract( theents[i].ent->origin, r_origin, result);
theents[i].len = DotProduct( result, result );
}
qsort((void *) theents, numents, sizeof(sortedent_t), transCompare);
// Add in BETTER sorting here
glDepthMask(0);
for (i=0; i<numents; i++)
{
currententity = theents[i].ent;
switch (currententity->model->type)
{
case mod_alias:
if (!depthMaskWrite)
{
depthMaskWrite = 1;
glDepthMask(1);
}
R_DrawAliasModel (currententity);
break;
case mod_brush:
if (!depthMaskWrite)
{
depthMaskWrite = 1;
glDepthMask(1);
}
R_DrawBrushModel (currententity);
break;
case mod_sprite:
if (depthMaskWrite)
{
depthMaskWrite = 0;
glDepthMask(0);
}
R_DrawSprite (currententity);
break;
#ifndef _WIN32
case mod_md3:
break; // shut up compiler warning
#endif
}
}
if (!depthMaskWrite)
glDepthMask(1);
}
#endif // #ifdef HEXEN2_SUPPORT
/*
=============
R_DrawViewModel
=============
*/
void R_DrawViewModel (void)
{
// [email protected]: model transform interpolation
float old_interpolate_transform;
/*******JDH*******/
entity_t *currententity;
/*******JDH*******/
currententity = &cl.viewent;
if (!r_drawviewmodel.value || chase_active.value || !r_drawentities.value || !currententity->model)
return;
#ifdef HEXEN2_SUPPORT
if (hexen2)
{
if (cl.v.health <= 0)
return;
}
else
#endif
if (cl.stats[STAT_HEALTH] <= 0) return;
// LordHavoc: if the player is transparent, so is his gun
currententity->transparency = r_modelalpha = cl_entities[cl.viewentity].transparency;
// hack the depth range to prevent view model from poking into walls
// glDepthRange (gldepthmin, gldepthmin + 0.3 * (gldepthmax - gldepthmin));
glDepthRange (0, 0.3);
// [email protected]: model transform interpolation
old_interpolate_transform = gl_interpolate_transform.value;
gl_interpolate_transform.value = false;
/******JDH******/
//R_DrawAliasModel (currententity);
/******JDH******/
switch (currententity->model->type)
{
case mod_alias:
R_DrawAliasModel (currententity);
break;
case mod_md3:
R_DrawQ3Model (currententity);
break;
#ifndef _WIN32
case mod_brush:
case mod_sprite:
break; // shut up compiler warning
#endif
}
gl_interpolate_transform.value = old_interpolate_transform;
// glDepthRange (gldepthmin, gldepthmax);
glDepthRange (0, 1);
}
/*************************JDH**************************/
/*
=============
VisibleToClient -- johnfitz
PVS test encapsulated in a nice function
=============
*/
qboolean VisibleToClient (const edict_t *client, const edict_t *test)
{
byte *pvs;
vec3_t org;
int i;
VectorAdd (client->v.origin, client->v.view_ofs, org);
pvs = SV_FatPVS (org);
for (i=0 ; i < test->num_leafs ; i++)
if (pvs[test->leafnums[i] >> 3] & (1 << (test->leafnums[i]&7) ))
return true;
return false;
}
/*
=============
GL_PolygonOffset -- johnfitz
negative offset moves polygon closer to camera
=============
*/
void GL_PolygonOffset (int offset)
{
if (offset > 0)
{
glEnable (GL_POLYGON_OFFSET_FILL);
glEnable (GL_POLYGON_OFFSET_LINE);
glPolygonOffset(1, offset);
}
else if (offset < 0)
{
glEnable (GL_POLYGON_OFFSET_FILL);
glEnable (GL_POLYGON_OFFSET_LINE);
glPolygonOffset(-1, offset);
}
else
{
glDisable (GL_POLYGON_OFFSET_FILL);
glDisable (GL_POLYGON_OFFSET_LINE);
}
}
/*
================
R_EmitWireBox -- johnfitz -- draws one axis aligned bounding box
================
*/
void R_EmitWireBox (const vec3_t mins, const vec3_t maxs)
{
glBegin (GL_QUAD_STRIP);
glVertex3f (mins[0], mins[1], mins[2]);
glVertex3f (mins[0], mins[1], maxs[2]);
glVertex3f (maxs[0], mins[1], mins[2]);
glVertex3f (maxs[0], mins[1], maxs[2]);
glVertex3f (maxs[0], maxs[1], mins[2]);
glVertex3f (maxs[0], maxs[1], maxs[2]);
glVertex3f (mins[0], maxs[1], mins[2]);
glVertex3f (mins[0], maxs[1], maxs[2]);
glVertex3f (mins[0], mins[1], mins[2]);
glVertex3f (mins[0], mins[1], maxs[2]);
glEnd ();
}
/*
================
R_ShowBoundingBoxes -- johnfitz
draw bounding boxes -- the server-side boxes, not the renderer cullboxes
================
*/
void R_ShowBoundingBoxes (void)
{
extern edict_t *sv_player;
vec3_t mins, maxs;
edict_t *ed;
entity_t *ent;