/
cg_draw.c
4889 lines (4137 loc) · 115 KB
/
cg_draw.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
/*
* Wolfenstein: Enemy Territory GPL Source Code
* Copyright (C) 1999-2010 id Software LLC, a ZeniMax Media company.
*
* ET: Legacy
* Copyright (C) 2012 Jan Simek <mail@etlegacy.com>
*
* This file is part of ET: Legacy - http://www.etlegacy.com
*
* ET: Legacy 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 3 of the License, or
* (at your option) any later version.
*
* ET: Legacy 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 ET: Legacy. If not, see <http://www.gnu.org/licenses/>.
*
* In addition, Wolfenstein: Enemy Territory GPL Source Code is also
* subject to certain additional terms. You should have received a copy
* of these additional terms immediately following the terms and conditions
* of the GNU General Public License which accompanied the source code.
* If not, please request a copy in writing from id Software at the address below.
*
* id Software LLC, c/o ZeniMax Media Inc., Suite 120, Rockville, Maryland 20850 USA.
*
* @file cg_draw.c
* @brief draw all of the graphical elements during active (after loading)
* gameplay
*/
#include "cg_local.h"
// FIXME: use these in all functions below to have unique colors
vec4_t HUD_Background = { 0.16f, 0.2f, 0.17f, 0.8f };
vec4_t HUD_Border = { 0.5f, 0.5f, 0.5f, 0.5f };
vec4_t HUD_Text = { 0.625f, 0.625f, 0.6f, 1.0f };
#define STATUSBARHEIGHT 452
char *BindingFromName(const char *cvar);
void Controls_GetConfig(void);
void SetHeadOrigin(clientInfo_t *ci, playerInfo_t *pi);
void CG_DrawOverlays(void);
int activeFont;
///////////////////////
////// new hud stuff
///////////////////////
void CG_Text_SetActiveFont(int font)
{
activeFont = font;
}
int CG_Text_Width_Ext(const char *text, float scale, int limit, fontInfo_t *font)
{
const char *s = text;
float out = 0, useScale = scale * font->glyphScale;
if (text)
{
glyphInfo_t *glyph;
int count = 0;
int len = strlen(text);
if (limit > 0 && len > limit)
{
len = limit;
}
while (s && *s && count < len)
{
if (Q_IsColorString(s))
{
s += 2;
continue;
}
else
{
glyph = &font->glyphs[(unsigned char)*s];
out += glyph->xSkip;
s++;
count++;
}
}
}
return out * useScale;
}
int CG_Text_Width(const char *text, float scale, int limit)
{
fontInfo_t *font = &cgDC.Assets.fonts[activeFont];
return CG_Text_Width_Ext(text, scale, limit, font);
}
int CG_Text_Height_Ext(const char *text, float scale, int limit, fontInfo_t *font)
{
float max = 0;
float useScale = scale * font->glyphScale;
const char *s = text;
if (text)
{
glyphInfo_t *glyph;
int count = 0;
int len = strlen(text);
if (limit > 0 && len > limit)
{
len = limit;
}
while (s && *s && count < len)
{
if (Q_IsColorString(s))
{
s += 2;
continue;
}
else
{
glyph = &font->glyphs[(unsigned char)*s];
if (max < glyph->height)
{
max = glyph->height;
}
s++;
count++;
}
}
}
return max * useScale;
}
int CG_Text_Height(const char *text, float scale, int limit)
{
fontInfo_t *font = &cgDC.Assets.fonts[activeFont];
return CG_Text_Height_Ext(text, scale, limit, font);
}
void CG_Text_PaintChar_Ext(float x, float y, float w, float h, float scalex, float scaley, float s, float t, float s2, float t2, qhandle_t hShader)
{
w *= scalex;
h *= scaley;
CG_AdjustFrom640(&x, &y, &w, &h);
trap_R_DrawStretchPic(x, y, w, h, s, t, s2, t2, hShader);
}
void CG_Text_PaintChar(float x, float y, float width, float height, float scale, float s, float t, float s2, float t2, qhandle_t hShader)
{
float w = width * scale;
float h = height * scale;
CG_AdjustFrom640(&x, &y, &w, &h);
trap_R_DrawStretchPic(x, y, w, h, s, t, s2, t2, hShader);
}
void CG_Text_Paint_Centred_Ext(float x, float y, float scalex, float scaley, vec4_t color, const char *text, float adjust, int limit, int style, fontInfo_t *font)
{
x -= CG_Text_Width_Ext(text, scalex, limit, font) * 0.5f;
CG_Text_Paint_Ext(x, y, scalex, scaley, color, text, adjust, limit, style, font);
}
void CG_Text_Paint_Ext(float x, float y, float scalex, float scaley, vec4_t color, const char *text, float adjust, int limit, int style, fontInfo_t *font)
{
if (text)
{
vec4_t newColor;
glyphInfo_t *glyph;
const char *s = text;
float yadj;
int len, count = 0, ofs;
scalex *= font->glyphScale;
scaley *= font->glyphScale;
trap_R_SetColor(color);
memcpy(&newColor[0], &color[0], sizeof(vec4_t));
len = strlen(text);
if (limit > 0 && len > limit)
{
len = limit;
}
while (s && *s && count < len)
{
glyph = &font->glyphs[(unsigned char)*s];
if (Q_IsColorString(s))
{
if (*(s + 1) == COLOR_NULL)
{
memcpy(newColor, color, sizeof(newColor));
}
else
{
memcpy(newColor, g_color_table[ColorIndex(*(s + 1))], sizeof(newColor));
newColor[3] = color[3];
}
trap_R_SetColor(newColor);
s += 2;
continue;
}
else
{
yadj = scaley * glyph->top;
if (style == ITEM_TEXTSTYLE_SHADOWED || style == ITEM_TEXTSTYLE_SHADOWEDMORE)
{
ofs = style == ITEM_TEXTSTYLE_SHADOWED ? 1 : 2;
colorBlack[3] = newColor[3];
trap_R_SetColor(colorBlack);
CG_Text_PaintChar_Ext(x + (glyph->pitch * scalex) + ofs, y - yadj + ofs, glyph->imageWidth, glyph->imageHeight, scalex, scaley, glyph->s, glyph->t, glyph->s2, glyph->t2, glyph->glyph);
colorBlack[3] = 1.0;
trap_R_SetColor(newColor);
}
CG_Text_PaintChar_Ext(x + (glyph->pitch * scalex), y - yadj, glyph->imageWidth, glyph->imageHeight, scalex, scaley, glyph->s, glyph->t, glyph->s2, glyph->t2, glyph->glyph);
x += (glyph->xSkip * scalex) + adjust;
s++;
count++;
}
}
trap_R_SetColor(NULL);
}
}
void CG_Text_Paint(float x, float y, float scale, vec4_t color, const char *text, float adjust, int limit, int style)
{
fontInfo_t *font = &cgDC.Assets.fonts[activeFont];
CG_Text_Paint_Ext(x, y, scale, scale, color, text, adjust, limit, style, font);
}
int CG_DrawFieldWidth(int x, int y, int width, int value, int charWidth, int charHeight)
{
char num[16], *ptr;
int l;
int totalwidth = 0;
if (width < 1)
{
return 0;
}
// draw number string
if (width > 5)
{
width = 5;
}
switch (width)
{
case 1:
value = value > 9 ? 9 : value;
value = value < 0 ? 0 : value;
break;
case 2:
value = value > 99 ? 99 : value;
value = value < -9 ? -9 : value;
break;
case 3:
value = value > 999 ? 999 : value;
value = value < -99 ? -99 : value;
break;
case 4:
value = value > 9999 ? 9999 : value;
value = value < -999 ? -999 : value;
break;
}
Com_sprintf(num, sizeof(num), "%i", value);
l = strlen(num);
if (l > width)
{
l = width;
}
ptr = num;
while (*ptr && l)
{
totalwidth += charWidth;
ptr++;
l--;
}
return totalwidth;
}
int CG_DrawField(int x, int y, int width, int value, int charWidth, int charHeight, qboolean dodrawpic, qboolean leftAlign)
{
char num[16], *ptr;
int l;
int frame;
int startx;
if (width < 1)
{
return 0;
}
// draw number string
if (width > 5)
{
width = 5;
}
switch (width)
{
case 1:
value = value > 9 ? 9 : value;
value = value < 0 ? 0 : value;
break;
case 2:
value = value > 99 ? 99 : value;
value = value < -9 ? -9 : value;
break;
case 3:
value = value > 999 ? 999 : value;
value = value < -99 ? -99 : value;
break;
case 4:
value = value > 9999 ? 9999 : value;
value = value < -999 ? -999 : value;
break;
}
Com_sprintf(num, sizeof(num), "%i", value);
l = strlen(num);
if (l > width)
{
l = width;
}
if (!leftAlign)
{
x -= 2 + charWidth * (l);
}
startx = x;
ptr = num;
while (*ptr && l)
{
if (*ptr == '-')
{
frame = STAT_MINUS;
}
else
{
frame = *ptr - '0';
}
if (dodrawpic)
{
CG_DrawPic(x, y, charWidth, charHeight, cgs.media.numberShaders[frame]);
}
x += charWidth;
ptr++;
l--;
}
return startx;
}
/*
================
CG_DrawTeamBackground
================
*/
void CG_DrawTeamBackground(int x, int y, int w, int h, float alpha, int team)
{
vec4_t hcolor;
hcolor[3] = alpha;
if (team == TEAM_AXIS)
{
hcolor[0] = 1;
hcolor[1] = 0;
hcolor[2] = 0;
}
else if (team == TEAM_ALLIES)
{
hcolor[0] = 0;
hcolor[1] = 0;
hcolor[2] = 1;
}
else
{
return;
}
trap_R_SetColor(hcolor);
CG_DrawPic(x, y, w, h, cgs.media.teamStatusBar);
trap_R_SetColor(NULL);
}
/*
===========================================================================================
UPPER RIGHT CORNER
===========================================================================================
*/
#define UPPERRIGHT_X 634
#define UPPERRIGHT_W 50
/*
==================
CG_DrawSnapshot
==================
*/
static float CG_DrawSnapshot(float y)
{
char *s = va("t:%i sn:%i cmd:%i", cg.snap->serverTime, cg.latestSnapshotNum, cgs.serverCommandSequence);
int w = CG_Text_Width_Ext(s, 0.19f, 0, &cgs.media.limboFont1);
int w2 = (UPPERRIGHT_W > w) ? UPPERRIGHT_W : w;
int x = Ccg_WideX(UPPERRIGHT_X) - w2 - 2;
CG_FillRect(x, y, w2 + 5, 12 + 2, HUD_Background);
CG_DrawRect_FixedBorder(x, y, w2 + 5, 12 + 2, 1, HUD_Border);
CG_Text_Paint_Ext(x + ((w2 - w) / 2) + 2, y + 11, 0.19f, 0.19f, HUD_Text, s, 0, 0, 0, &cgs.media.limboFont1);
return y + 12 + 4;
}
/*
==================
CG_DrawFPS
==================
*/
#define MAX_FPS_FRAMES 500
static float CG_DrawFPS(float y)
{
static int previousTimes[MAX_FPS_FRAMES];
static int previous;
static int index;
static int oldSamples;
char *s;
int t = trap_Milliseconds(); // don't use serverTime, because that will be drifting to correct for internet lag changes, timescales, timedemos, etc
int frameTime = t - previous;
int x, w, w2;
int samples = cg_drawFPS.integer;
previous = t;
if (samples < 4)
{
samples = 4;
}
if (samples > MAX_FPS_FRAMES)
{
samples = MAX_FPS_FRAMES;
}
if (samples != oldSamples)
{
index = 0;
}
oldSamples = samples;
previousTimes[index % samples] = frameTime;
index++;
if (index > samples)
{
int i, fps;
// average multiple frames together to smooth changes out a bit
int total = 0;
for (i = 0 ; i < samples ; ++i)
{
total += previousTimes[i];
}
total = total ? total : 1;
fps = 1000 * samples / total;
s = va("%i FPS", fps);
}
else
{
s = "estimating";
}
w = CG_Text_Width_Ext(s, 0.19f, 0, &cgs.media.limboFont1);
w2 = (UPPERRIGHT_W > w) ? UPPERRIGHT_W : w;
x = (int)(Ccg_WideX(UPPERRIGHT_X)) - w2 - 2;
CG_FillRect(x, y, w2 + 5, 12 + 2, HUD_Background);
CG_DrawRect_FixedBorder(x, y, w2 + 5, 12 + 2, 1, HUD_Border);
CG_Text_Paint_Ext(x + ((w2 - w) / 2) + 2, y + 11, 0.19f, 0.19f, HUD_Text, s, 0, 0, 0, &cgs.media.limboFont1);
return y + 12 + 4;
}
/*
=================
CG_DrawTimer
=================
*/
static float CG_DrawTimer(float y)
{
char *s;
int w, w2;
vec4_t color = { 0.625f, 0.625f, 0.6f, 1.0f };
int tens;
char *rt = (cgs.gametype != GT_WOLF_LMS && (cgs.clientinfo[cg.clientNum].team != TEAM_SPECTATOR || cg.snap->ps.pm_flags & PMF_FOLLOW) && cg_drawReinforcementTime.integer > 0) ?
va("^F%d%s", CG_CalculateReinfTime(qfalse), ((cgs.timelimit <= 0.0f) ? "" : " ")) : "";
int x;
int msec = (cgs.timelimit * 60.f * 1000.f) - (cg.time - cgs.levelStartTime);
int seconds = msec / 1000;
int mins = seconds / 60;
seconds -= mins * 60;
tens = seconds / 10;
seconds -= tens * 10;
if (cgs.gamestate != GS_PLAYING)
{
s = "^7WARMUP"; // don't draw reinforcement time in warmup mode // ^*
color[3] = fabs(sin(cg.time * 0.002));
}
else if (msec < 0 && cgs.timelimit > 0.0f)
{
s = "^N0:00";
color[3] = fabs(sin(cg.time * 0.002));
}
else
{
if (cgs.timelimit <= 0.0f)
{
s = va("%s", rt);
}
else
{
s = va("%s^7%i:%i%i", rt, mins, tens, seconds); // ^*
}
color[3] = 1.f;
}
// spawntimer
seconds = msec / 1000;
if (cg_spawnTimer_set.integer != -1 && cg_spawnTimer_period.integer > 0)
{
s = va("^1%d %s", cg_spawnTimer_period.integer + (seconds - cg_spawnTimer_set.integer) % cg_spawnTimer_period.integer, s);
}
// end spawntimer
w = CG_Text_Width_Ext(s, 0.19f, 0, &cgs.media.limboFont1);
w2 = (UPPERRIGHT_W > w) ? UPPERRIGHT_W : w;
x = Ccg_WideX(UPPERRIGHT_X) - w2 - 2;
CG_FillRect(x, y, w2 + 5, 12 + 2, HUD_Background);
CG_DrawRect_FixedBorder(x, y, w2 + 5, 12 + 2, 1, HUD_Border);
CG_Text_Paint_Ext(x + ((w2 - w) / 2) + 2, y + 11, 0.19f, 0.19f, color, s, 0, 0, 0, &cgs.media.limboFont1);
return y + 12 + 4;
}
int maxCharsBeforeOverlay;
/*
=====================
CG_DrawUpperRight
=====================
*/
static void CG_DrawUpperRight(void)
{
float y = 20 + 100 + 32;
if (cg_drawFireteamOverlay.integer && CG_IsOnFireteam(cg.clientNum))
{
rectDef_t rect = { 10, 10, 100, 100 };
CG_DrawFireTeamOverlay(&rect);
}
if (!(cg.snap->ps.pm_flags & PMF_LIMBO) && (cg.snap->ps.persistant[PERS_TEAM] != TEAM_SPECTATOR) &&
(cgs.autoMapExpanded || (!cgs.autoMapExpanded && (cg.time - cgs.autoMapExpandTime < 250.f))))
{
return;
}
if (cg_drawRoundTimer.integer)
{
y = CG_DrawTimer(y);
}
if (cg_drawFPS.integer)
{
y = CG_DrawFPS(y);
}
if (cg_drawSnapshot.integer)
{
y = CG_DrawSnapshot(y);
}
}
/*
===========================================================================================
LOWER RIGHT CORNER
===========================================================================================
*/
#define CHATLOC_X 160
#define CHATLOC_Y 478
#define CHATLOC_TEXT_X (CHATLOC_X + 0.25f * TINYCHAR_WIDTH)
/*
=================
CG_DrawTeamInfo
=================
*/
static void CG_DrawTeamInfo(void)
{
int chatHeight = TEAMCHAT_HEIGHT;
// no need to adjust chat height for intermission here - CG_DrawTeamInfo is called from CG_Draw2D
if (cg_teamChatHeight.integer < TEAMCHAT_HEIGHT)
{
chatHeight = cg_teamChatHeight.integer;
}
if (chatHeight <= 0)
{
return; // disabled
}
if (cgs.teamLastChatPos != cgs.teamChatPos)
{
vec4_t hcolor;
int i;
float lineHeight = 9.f;
int x_offset = 0;
float alphapercent;
float scale = 0.2f;
float icon_width = 12.f;
float icon_height = 10.f;
int chatWidth = 640 - CHATLOC_X - 80 /*(cg_drawHUDHead.integer ? 80 : 0)*/;
int chatPosX = (cg.snap->ps.persistant[PERS_TEAM] == TEAM_SPECTATOR) ? 20 : CHATLOC_TEXT_X - x_offset;
if (cg.time - cgs.teamChatMsgTimes[cgs.teamLastChatPos % chatHeight] > cg_teamChatTime.integer)
{
cgs.teamLastChatPos++;
}
for (i = cgs.teamChatPos - 1; i >= cgs.teamLastChatPos; i--)
{
alphapercent = 1.0f - (cg.time - cgs.teamChatMsgTimes[i % chatHeight]) / (float)(cg_teamChatTime.integer);
if (alphapercent > 1.0f)
{
alphapercent = 1.0f;
}
else if (alphapercent < 0)
{
alphapercent = 0.f;
}
// chatter team instead
if (cgs.teamChatMsgTeams[i % chatHeight] == TEAM_AXIS)
{
hcolor[0] = 1;
hcolor[1] = 0;
hcolor[2] = 0;
}
else if (cgs.teamChatMsgTeams[i % chatHeight] == TEAM_ALLIES)
{
hcolor[0] = 0;
hcolor[1] = 0;
hcolor[2] = 1;
}
else
{
hcolor[0] = 0;
hcolor[1] = 1;
hcolor[2] = 0;
}
hcolor[3] = 0.33f * alphapercent;
trap_R_SetColor(hcolor);
CG_DrawPic(chatPosX, CHATLOC_Y - (cgs.teamChatPos - i) * lineHeight, chatWidth, lineHeight, cgs.media.teamStatusBar);
hcolor[0] = hcolor[1] = hcolor[2] = 1.0;
hcolor[3] = alphapercent;
trap_R_SetColor(hcolor);
// chat icons
if (cgs.teamChatMsgTeams[i % chatHeight] == TEAM_AXIS)
{
CG_DrawPic(chatPosX, CHATLOC_Y - (cgs.teamChatPos - i - 0.9f) * lineHeight - 8, icon_width, icon_height, cgs.media.axisFlag);
}
else if (cgs.teamChatMsgTeams[i % chatHeight] == TEAM_ALLIES)
{
CG_DrawPic(chatPosX, CHATLOC_Y - (cgs.teamChatPos - i - 0.9f) * lineHeight - 8, icon_width, icon_height, cgs.media.alliedFlag);
}
CG_Text_Paint_Ext(chatPosX + 16, CHATLOC_Y - (cgs.teamChatPos - i - 1) * lineHeight - 1, scale, scale, hcolor, cgs.teamChatMsgs[i % chatHeight], 0, 0, 0, &cgs.media.limboFont2);
}
}
}
const char *CG_PickupItemText(int item)
{
if (bg_itemlist[item].giType == IT_HEALTH)
{
if (bg_itemlist[item].world_model[2]) // this is a multi-stage item
{ // FIXME: print the correct amount for multi-stage
return va("a %s", bg_itemlist[item].pickup_name);
}
else
{
return va("%i %s", bg_itemlist[item].quantity, bg_itemlist[item].pickup_name);
}
}
else if (bg_itemlist[item].giType == IT_TEAM)
{
return "an Objective";
}
else
{
if (bg_itemlist[item].pickup_name[0] == 'a' || bg_itemlist[item].pickup_name[0] == 'A')
{
return va("an %s", bg_itemlist[item].pickup_name);
}
else
{
return va("a %s", bg_itemlist[item].pickup_name);
}
}
}
/*
=================
CG_DrawNotify
=================
*/
#define NOTIFYLOC_Y 42 // bottom end
#define NOTIFYLOC_X 0
#define NOTIFYLOC_Y_SP 128
static void CG_DrawNotify(void)
{
return; // FIXME: remove? early return ... commented the code
/*
int w, h;
int i, len;
vec4_t hcolor;
int chatHeight;
float alphapercent;
char var[MAX_TOKEN_CHARS];
float notifytime = 1.0f;
int yLoc;
yLoc = NOTIFYLOC_Y;
trap_Cvar_VariableStringBuffer("con_notifytime", var, sizeof(var));
notifytime = atof(var) * 1000;
if (notifytime <= 100.f)
{
notifytime = 100.0f;
}
chatHeight = NOTIFY_HEIGHT;
if (cgs.notifyLastPos != cgs.notifyPos)
{
if (cg.time - cgs.notifyMsgTimes[cgs.notifyLastPos % chatHeight] > notifytime)
{
cgs.notifyLastPos++;
}
h = (cgs.notifyPos - cgs.notifyLastPos) * TINYCHAR_HEIGHT;
w = 0;
for (i = cgs.notifyLastPos; i < cgs.notifyPos; i++)
{
len = CG_DrawStrlen(cgs.notifyMsgs[i % chatHeight]);
if (len > w)
{
w = len;
}
}
w *= TINYCHAR_WIDTH;
w += TINYCHAR_WIDTH * 2;
if (maxCharsBeforeOverlay <= 0)
{
maxCharsBeforeOverlay = 80;
}
for (i = cgs.notifyPos - 1; i >= cgs.notifyLastPos; i--)
{
alphapercent = 1.0f - ((cg.time - cgs.notifyMsgTimes[i % chatHeight]) / notifytime);
if (alphapercent > 0.5f)
{
alphapercent = 1.0f;
}
else
{
alphapercent *= 2;
}
if (alphapercent < 0.f)
{
alphapercent = 0.f;
}
hcolor[0] = hcolor[1] = hcolor[2] = 1.0;
hcolor[3] = alphapercent;
trap_R_SetColor(hcolor);
CG_DrawStringExt(NOTIFYLOC_X + TINYCHAR_WIDTH,
yLoc - (cgs.notifyPos - i) * TINYCHAR_HEIGHT,
cgs.notifyMsgs[i % chatHeight], hcolor, qfalse, qfalse,
TINYCHAR_WIDTH, TINYCHAR_HEIGHT, maxCharsBeforeOverlay);
}
}
*/
}
/*
===============================================================================
LAGOMETER
===============================================================================
*/
#define LAG_SAMPLES 128
typedef struct
{
int frameSamples[LAG_SAMPLES];
int frameCount;
int snapshotFlags[LAG_SAMPLES];
int snapshotSamples[LAG_SAMPLES];
int snapshotCount;
} lagometer_t;
lagometer_t lagometer;
/*
==============
CG_AddLagometerFrameInfo
Adds the current interpolate / extrapolate bar for this frame
==============
*/
void CG_AddLagometerFrameInfo(void)
{
lagometer.frameSamples[lagometer.frameCount & (LAG_SAMPLES - 1)] = cg.time - cg.latestSnapshotTime;
lagometer.frameCount++;
}
/*
==============
CG_AddLagometerSnapshotInfo
Each time a snapshot is received, log its ping time and
the number of snapshots that were dropped before it.
Pass NULL for a dropped packet.
==============
*/
void CG_AddLagometerSnapshotInfo(snapshot_t *snap)
{
// dropped packet
if (!snap)
{
lagometer.snapshotSamples[lagometer.snapshotCount & (LAG_SAMPLES - 1)] = -1;
lagometer.snapshotCount++;
return;
}
if (cg.demoPlayback)
{
snap->ping = (snap->serverTime - snap->ps.commandTime) - 50;
}
// add this snapshot's info
lagometer.snapshotSamples[lagometer.snapshotCount & (LAG_SAMPLES - 1)] = snap->ping;
lagometer.snapshotFlags[lagometer.snapshotCount & (LAG_SAMPLES - 1)] = snap->snapFlags;
lagometer.snapshotCount++;
}
/*
==============
CG_DrawDisconnect
Should we draw something differnet for long lag vs no packets?
==============
*/
static void CG_DrawDisconnect(void)
{
float x = Ccg_WideX(640) - 48; // disconnect icon
float y = 480 - 200; // disconnect icon
int cmdNum;
usercmd_t cmd;
const char *s;
int w; // bk010215 - FIXME char message[1024];
// dont draw if a demo and we're running at a different timescale
if (cg.demoPlayback && cg_timescale.value != 1.0f)
{
return;
}
// ydnar: don't draw if the server is respawning
if (cg.serverRespawning)
{
return;
}
// draw the phone jack if we are completely past our buffers
cmdNum = trap_GetCurrentCmdNumber() - CMD_BACKUP + 1;
trap_GetUserCmd(cmdNum, &cmd);
if (cmd.serverTime <= cg.snap->ps.commandTime
|| cmd.serverTime > cg.time) // special check for map_restart // bk 0102165 - FIXME
{
return;
}
// also add text in center of screen
s = CG_TranslateString("Connection Interrupted"); // bk 010215 - FIXME
w = CG_DrawStrlen(s) * BIGCHAR_WIDTH;
CG_DrawBigString(320 - w / 2, 100, s, 1.0F);
// blink the icon
if ((cg.time >> 9) & 1)
{
return;
}
CG_DrawPic(x, y, 48, 48, cgs.media.disconnectIcon);
}
#define MAX_LAGOMETER_PING 900
#define MAX_LAGOMETER_RANGE 300
/*
==============
CG_DrawLagometer
==============
*/
static void CG_DrawLagometer(void)
{
int a, x, y, i;
float v;
float ax, ay, aw, ah, mid, range;
int color;
float vscale;
if (!cg_lagometer.integer) // || cgs.localServer)
{
CG_DrawDisconnect();
return;
}
// draw the graph
x = Ccg_WideX(640) - 48;
y = 480 - 200;
trap_R_SetColor(NULL);
CG_DrawPic(x, y, 48, 48, cgs.media.lagometerShader);
ax = x;
ay = y;
aw = 48;
ah = 48;
CG_AdjustFrom640(&ax, &ay, &aw, &ah);
color = -1;
range = ah / 3;
mid = ay + range;
vscale = range / MAX_LAGOMETER_RANGE;
// draw the frame interpoalte / extrapolate graph
for (a = 0 ; a < aw ; a++)
{
i = (lagometer.frameCount - 1 - a) & (LAG_SAMPLES - 1);
v = lagometer.frameSamples[i];
v *= vscale;
if (v > 0)
{
if (color != 1)
{
color = 1;
trap_R_SetColor(colorYellow);
}
if (v > range)
{