forked from kristus/Doombringer_Darkplaces
-
Notifications
You must be signed in to change notification settings - Fork 0
/
cl_main.c
3095 lines (2786 loc) · 103 KB
/
cl_main.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.
*/
// cl_main.c -- client main loop
#include "quakedef.h"
#include "cl_collision.h"
#include "cl_video.h"
#include "image.h"
#include "csprogs.h"
#include "r_shadow.h"
#include "libcurl.h"
#include "snd_main.h"
#include "cdaudio.h"
// we need to declare some mouse variables here, because the menu system
// references them even when on a unix system.
cvar_t csqc_progname = {CF_CLIENT | CF_SERVER, "csqc_progname","csprogs.dat","name of csprogs.dat file to load"};
cvar_t csqc_progcrc = {CF_CLIENT | CF_READONLY, "csqc_progcrc","-1","CRC of csprogs.dat file to load (-1 is none), only used during level changes and then reset to -1"};
cvar_t csqc_progsize = {CF_CLIENT | CF_READONLY, "csqc_progsize","-1","file size of csprogs.dat file to load (-1 is none), only used during level changes and then reset to -1"};
cvar_t csqc_usedemoprogs = {CF_CLIENT, "csqc_usedemoprogs","1","use csprogs stored in demos"};
cvar_t csqc_polygons_defaultmaterial_nocullface = {CF_CLIENT, "csqc_polygons_defaultmaterial_nocullface", "0", "use 'cull none' behavior in the default shader for rendering R_PolygonBegin - warning: enabling this is not consistent with FTEQW behavior on this feature"};
cvar_t cl_shownet = {CF_CLIENT, "cl_shownet","0","1 = print packet size, 2 = print packet message list"};
cvar_t cl_nolerp = {CF_CLIENT, "cl_nolerp", "0","network update smoothing"};
cvar_t cl_lerpexcess = {CF_CLIENT, "cl_lerpexcess", "0","maximum allowed lerp excess (hides, not fixes, some packet loss)"};
cvar_t cl_lerpanim_maxdelta_server = {CF_CLIENT, "cl_lerpanim_maxdelta_server", "0.1","maximum frame delta for smoothing between server-controlled animation frames (when 0, one network frame)"};
cvar_t cl_lerpanim_maxdelta_framegroups = {CF_CLIENT, "cl_lerpanim_maxdelta_framegroups", "0.1","maximum frame delta for smoothing between framegroups (when 0, one network frame)"};
cvar_t cl_itembobheight = {CF_CLIENT, "cl_itembobheight", "0","how much items bob up and down (try 8)"};
cvar_t cl_itembobspeed = {CF_CLIENT, "cl_itembobspeed", "0.5","how frequently items bob up and down"};
cvar_t lookspring = {CF_CLIENT | CF_ARCHIVE, "lookspring","0","returns pitch to level with the floor when no longer holding a pitch key"};
cvar_t lookstrafe = {CF_CLIENT | CF_ARCHIVE, "lookstrafe","0","move instead of turning"};
cvar_t sensitivity = {CF_CLIENT | CF_ARCHIVE, "sensitivity","3","mouse speed multiplier"};
cvar_t m_pitch = {CF_CLIENT | CF_ARCHIVE, "m_pitch","0.022","mouse pitch speed multiplier"};
cvar_t m_yaw = {CF_CLIENT | CF_ARCHIVE, "m_yaw","0.022","mouse yaw speed multiplier"};
cvar_t m_forward = {CF_CLIENT | CF_ARCHIVE, "m_forward","1","mouse forward speed multiplier"};
cvar_t m_side = {CF_CLIENT | CF_ARCHIVE, "m_side","0.8","mouse side speed multiplier"};
cvar_t freelook = {CF_CLIENT | CF_ARCHIVE, "freelook", "1","mouse controls pitch instead of forward/back"};
cvar_t cl_autodemo = {CF_CLIENT | CF_ARCHIVE, "cl_autodemo", "0", "records every game played, using the date/time and map name to name the demo file" };
cvar_t cl_autodemo_nameformat = {CF_CLIENT | CF_ARCHIVE, "cl_autodemo_nameformat", "autodemos/%Y-%m-%d_%H-%M", "The format of the cl_autodemo filename, followed by the map name (the date is encoded using strftime escapes)" };
cvar_t cl_autodemo_delete = {CF_CLIENT, "cl_autodemo_delete", "0", "Delete demos after recording. This is a bitmask, bit 1 gives the default, bit 0 the value for the current demo. Thus, the values are: 0 = disabled; 1 = delete current demo only; 2 = delete all demos except the current demo; 3 = delete all demos from now on" };
cvar_t r_draweffects = {CF_CLIENT, "r_draweffects", "1","renders temporary sprite effects"};
cvar_t cl_explosions_alpha_start = {CF_CLIENT | CF_ARCHIVE, "cl_explosions_alpha_start", "1.5","starting alpha of an explosion shell"};
cvar_t cl_explosions_alpha_end = {CF_CLIENT | CF_ARCHIVE, "cl_explosions_alpha_end", "0","end alpha of an explosion shell (just before it disappears)"};
cvar_t cl_explosions_size_start = {CF_CLIENT | CF_ARCHIVE, "cl_explosions_size_start", "16","starting size of an explosion shell"};
cvar_t cl_explosions_size_end = {CF_CLIENT | CF_ARCHIVE, "cl_explosions_size_end", "128","ending alpha of an explosion shell (just before it disappears)"};
cvar_t cl_explosions_lifetime = {CF_CLIENT | CF_ARCHIVE, "cl_explosions_lifetime", "0.5","how long an explosion shell lasts"};
cvar_t cl_stainmaps = {CF_CLIENT | CF_ARCHIVE, "cl_stainmaps", "0","stains lightmaps, much faster than decals but blurred"};
cvar_t cl_stainmaps_clearonload = {CF_CLIENT | CF_ARCHIVE, "cl_stainmaps_clearonload", "1","clear stainmaps on map restart"};
cvar_t cl_beams_polygons = {CF_CLIENT | CF_ARCHIVE, "cl_beams_polygons", "1","use beam polygons instead of models"};
cvar_t cl_beams_quakepositionhack = {CF_CLIENT | CF_ARCHIVE, "cl_beams_quakepositionhack", "1", "makes your lightning gun appear to fire from your waist (as in Quake and QuakeWorld)"};
cvar_t cl_beams_instantaimhack = {CF_CLIENT | CF_ARCHIVE, "cl_beams_instantaimhack", "0", "makes your lightning gun aiming update instantly"};
cvar_t cl_beams_lightatend = {CF_CLIENT | CF_ARCHIVE, "cl_beams_lightatend", "0", "make a light at the end of the beam"};
cvar_t cl_deathfade = {CF_CLIENT | CF_ARCHIVE, "cl_deathfade", "0", "fade screen to dark red when dead, value represents how fast the fade is (higher is faster)"};
cvar_t cl_noplayershadow = {CF_CLIENT | CF_ARCHIVE, "cl_noplayershadow", "0","hide player shadow"};
cvar_t cl_dlights_decayradius = {CF_CLIENT | CF_ARCHIVE, "cl_dlights_decayradius", "1", "reduces size of light flashes over time"};
cvar_t cl_dlights_decaybrightness = {CF_CLIENT | CF_ARCHIVE, "cl_dlights_decaybrightness", "1", "reduces brightness of light flashes over time"};
cvar_t qport = {CF_CLIENT, "qport", "0", "identification key for playing on qw servers (allows you to maintain a connection to a quakeworld server even if your port changes)"};
cvar_t cl_prydoncursor = {CF_CLIENT, "cl_prydoncursor", "0", "enables a mouse pointer which is able to click on entities in the world, useful for point and click mods, see PRYDON_CLIENTCURSOR extension in dpextensions.qc"};
cvar_t cl_prydoncursor_notrace = {CF_CLIENT, "cl_prydoncursor_notrace", "0", "disables traceline used in prydon cursor reporting to the game, saving some cpu time"};
cvar_t cl_deathnoviewmodel = {CF_CLIENT, "cl_deathnoviewmodel", "1", "hides gun model when dead"};
cvar_t cl_locs_enable = {CF_CLIENT | CF_ARCHIVE, "locs_enable", "1", "enables replacement of certain % codes in chat messages: %l (location), %d (last death location), %h (health), %a (armor), %x (rockets), %c (cells), %r (rocket launcher status), %p (powerup status), %w (weapon status), %t (current time in level)"};
cvar_t cl_locs_show = {CF_CLIENT, "locs_show", "0", "shows defined locations for editing purposes"};
cvar_t cl_minfps = {CF_CLIENT | CF_ARCHIVE, "cl_minfps", "40", "minimum fps target - while the rendering performance is below this, it will drift toward lower quality"};
cvar_t cl_minfps_fade = {CF_CLIENT | CF_ARCHIVE, "cl_minfps_fade", "1", "how fast the quality adapts to varying framerate"};
cvar_t cl_minfps_qualitymax = {CF_CLIENT | CF_ARCHIVE, "cl_minfps_qualitymax", "1", "highest allowed drawdistance multiplier"};
cvar_t cl_minfps_qualitymin = {CF_CLIENT | CF_ARCHIVE, "cl_minfps_qualitymin", "0.25", "lowest allowed drawdistance multiplier"};
cvar_t cl_minfps_qualitymultiply = {CF_CLIENT | CF_ARCHIVE, "cl_minfps_qualitymultiply", "0.2", "multiplier for quality changes in quality change per second render time (1 assumes linearity of quality and render time)"};
cvar_t cl_minfps_qualityhysteresis = {CF_CLIENT | CF_ARCHIVE, "cl_minfps_qualityhysteresis", "0.05", "reduce all quality increments by this to reduce flickering"};
cvar_t cl_minfps_qualitystepmax = {CF_CLIENT | CF_ARCHIVE, "cl_minfps_qualitystepmax", "0.1", "maximum quality change in a single frame"};
cvar_t cl_minfps_force = {CF_CLIENT, "cl_minfps_force", "0", "also apply quality reductions in timedemo/capturevideo"};
cvar_t cl_maxfps = {CF_CLIENT | CF_ARCHIVE, "cl_maxfps", "0", "maximum fps cap, 0 = unlimited, if game is running faster than this it will wait before running another frame (useful to make cpu time available to other programs)"};
cvar_t cl_maxfps_alwayssleep = {CF_CLIENT | CF_ARCHIVE, "cl_maxfps_alwayssleep","1", "gives up some processing time to other applications each frame, value in milliseconds, disabled if cl_maxfps is 0"};
cvar_t cl_maxidlefps = {CF_CLIENT | CF_ARCHIVE, "cl_maxidlefps", "20", "maximum fps cap when the game is not the active window (makes cpu time available to other programs"};
client_static_t cls;
client_state_t cl;
/*
=====================
CL_ClearState
=====================
*/
void CL_ClearState(void)
{
int i;
entity_t *ent;
CL_VM_ShutDown();
// wipe the entire cl structure
Mem_EmptyPool(cls.levelmempool);
memset (&cl, 0, sizeof(cl));
S_StopAllSounds();
// reset the view zoom interpolation
cl.mviewzoom[0] = cl.mviewzoom[1] = 1;
cl.sensitivityscale = 1.0f;
// enable rendering of the world and such
cl.csqc_vidvars.drawworld = r_drawworld.integer != 0;
cl.csqc_vidvars.drawenginesbar = true;
cl.csqc_vidvars.drawcrosshair = true;
// set up the float version of the stats array for easier access to float stats
cl.statsf = (float *)cl.stats;
cl.num_entities = 0;
cl.num_static_entities = 0;
cl.num_brushmodel_entities = 0;
// tweak these if the game runs out
cl.max_csqcrenderentities = 0;
cl.max_entities = MAX_ENTITIES_INITIAL;
cl.max_static_entities = MAX_STATICENTITIES;
cl.max_effects = MAX_EFFECTS;
cl.max_beams = MAX_BEAMS;
cl.max_dlights = MAX_DLIGHTS;
cl.max_lightstyle = MAX_LIGHTSTYLES;
cl.max_brushmodel_entities = MAX_EDICTS;
cl.max_particles = MAX_PARTICLES_INITIAL; // grows dynamically
cl.max_showlmps = 0;
cl.num_dlights = 0;
cl.num_effects = 0;
cl.num_beams = 0;
cl.csqcrenderentities = NULL;
cl.entities = (entity_t *)Mem_Alloc(cls.levelmempool, cl.max_entities * sizeof(entity_t));
cl.entities_active = (unsigned char *)Mem_Alloc(cls.levelmempool, cl.max_brushmodel_entities * sizeof(unsigned char));
cl.static_entities = (entity_t *)Mem_Alloc(cls.levelmempool, cl.max_static_entities * sizeof(entity_t));
cl.effects = (cl_effect_t *)Mem_Alloc(cls.levelmempool, cl.max_effects * sizeof(cl_effect_t));
cl.beams = (beam_t *)Mem_Alloc(cls.levelmempool, cl.max_beams * sizeof(beam_t));
cl.dlights = (dlight_t *)Mem_Alloc(cls.levelmempool, cl.max_dlights * sizeof(dlight_t));
cl.lightstyle = (lightstyle_t *)Mem_Alloc(cls.levelmempool, cl.max_lightstyle * sizeof(lightstyle_t));
cl.brushmodel_entities = (int *)Mem_Alloc(cls.levelmempool, cl.max_brushmodel_entities * sizeof(int));
cl.particles = (particle_t *) Mem_Alloc(cls.levelmempool, cl.max_particles * sizeof(particle_t));
cl.showlmps = NULL;
// LadyHavoc: have to set up the baseline info for alpha and other stuff
for (i = 0;i < cl.max_entities;i++)
{
cl.entities[i].state_baseline = defaultstate;
cl.entities[i].state_previous = defaultstate;
cl.entities[i].state_current = defaultstate;
}
if (IS_NEXUIZ_DERIVED(gamemode))
{
VectorSet(cl.playerstandmins, -16, -16, -24);
VectorSet(cl.playerstandmaxs, 16, 16, 45);
VectorSet(cl.playercrouchmins, -16, -16, -24);
VectorSet(cl.playercrouchmaxs, 16, 16, 25);
}
else
{
VectorSet(cl.playerstandmins, -16, -16, -24);
VectorSet(cl.playerstandmaxs, 16, 16, 24);
VectorSet(cl.playercrouchmins, -16, -16, -24);
VectorSet(cl.playercrouchmaxs, 16, 16, 24);
}
// disable until we get textures for it
R_ResetSkyBox();
ent = &cl.entities[0];
// entire entity array was cleared, so just fill in a few fields
ent->state_current.active = true;
ent->render.model = cl.worldmodel = NULL; // no world model yet
ent->render.alpha = 1;
ent->render.flags = RENDER_SHADOW | RENDER_LIGHT;
Matrix4x4_CreateFromQuakeEntity(&ent->render.matrix, 0, 0, 0, 0, 0, 0, 1);
ent->render.allowdecals = true;
CL_UpdateRenderEntity(&ent->render);
// noclip is turned off at start
noclip_anglehack = false;
// mark all frames invalid for delta
memset(cl.qw_deltasequence, -1, sizeof(cl.qw_deltasequence));
// set bestweapon data back to Quake data
IN_BestWeapon_ResetData();
CL_Screen_NewMap();
}
extern cvar_t cl_topcolor;
extern cvar_t cl_bottomcolor;
void CL_SetInfo(const char *key, const char *value, qbool send, qbool allowstarkey, qbool allowmodel, qbool quiet)
{
int i;
qbool fail = false;
char vabuf[1024];
if (!allowstarkey && key[0] == '*')
fail = true;
if (!allowmodel && (!strcasecmp(key, "pmodel") || !strcasecmp(key, "emodel")))
fail = true;
for (i = 0;key[i];i++)
if (ISWHITESPACE(key[i]) || key[i] == '\"')
fail = true;
for (i = 0;value[i];i++)
if (value[i] == '\r' || value[i] == '\n' || value[i] == '\"')
fail = true;
if (fail)
{
if (!quiet)
Con_Printf("Can't setinfo \"%s\" \"%s\"\n", key, value);
return;
}
InfoString_SetValue(cls.userinfo, sizeof(cls.userinfo), key, value);
if (cls.state == ca_connected && cls.netcon)
{
if (cls.protocol == PROTOCOL_QUAKEWORLD)
{
MSG_WriteByte(&cls.netcon->message, qw_clc_stringcmd);
MSG_WriteString(&cls.netcon->message, va(vabuf, sizeof(vabuf), "setinfo \"%s\" \"%s\"", key, value));
}
else if (!strcasecmp(key, "name"))
{
MSG_WriteByte(&cls.netcon->message, clc_stringcmd);
MSG_WriteString(&cls.netcon->message, va(vabuf, sizeof(vabuf), "name \"%s\"", value));
}
else if (!strcasecmp(key, "playermodel"))
{
MSG_WriteByte(&cls.netcon->message, clc_stringcmd);
MSG_WriteString(&cls.netcon->message, va(vabuf, sizeof(vabuf), "playermodel \"%s\"", value));
}
else if (!strcasecmp(key, "playerskin"))
{
MSG_WriteByte(&cls.netcon->message, clc_stringcmd);
MSG_WriteString(&cls.netcon->message, va(vabuf, sizeof(vabuf), "playerskin \"%s\"", value));
}
else if (!strcasecmp(key, "topcolor"))
{
MSG_WriteByte(&cls.netcon->message, clc_stringcmd);
MSG_WriteString(&cls.netcon->message, va(vabuf, sizeof(vabuf), "color %i %i", atoi(value), cl_bottomcolor.integer));
}
else if (!strcasecmp(key, "bottomcolor"))
{
MSG_WriteByte(&cls.netcon->message, clc_stringcmd);
MSG_WriteString(&cls.netcon->message, va(vabuf, sizeof(vabuf), "color %i %i", cl_topcolor.integer, atoi(value)));
}
else if (!strcasecmp(key, "rate"))
{
MSG_WriteByte(&cls.netcon->message, clc_stringcmd);
MSG_WriteString(&cls.netcon->message, va(vabuf, sizeof(vabuf), "rate \"%s\"", value));
}
else if (!strcasecmp(key, "rate_burstsize"))
{
MSG_WriteByte(&cls.netcon->message, clc_stringcmd);
MSG_WriteString(&cls.netcon->message, va(vabuf, sizeof(vabuf), "rate_burstsize \"%s\"", value));
}
}
}
void CL_ExpandEntities(int num)
{
int i, oldmaxentities;
entity_t *oldentities;
if (num >= cl.max_entities)
{
if (!cl.entities)
Sys_Error("CL_ExpandEntities: cl.entities not initialized");
if (num >= MAX_EDICTS)
Host_Error("CL_ExpandEntities: num %i >= %i", num, MAX_EDICTS);
oldmaxentities = cl.max_entities;
oldentities = cl.entities;
cl.max_entities = (num & ~255) + 256;
cl.entities = (entity_t *)Mem_Alloc(cls.levelmempool, cl.max_entities * sizeof(entity_t));
memcpy(cl.entities, oldentities, oldmaxentities * sizeof(entity_t));
Mem_Free(oldentities);
for (i = oldmaxentities;i < cl.max_entities;i++)
{
cl.entities[i].state_baseline = defaultstate;
cl.entities[i].state_previous = defaultstate;
cl.entities[i].state_current = defaultstate;
}
}
}
void CL_ExpandCSQCRenderEntities(int num)
{
int i;
int oldmaxcsqcrenderentities;
entity_render_t *oldcsqcrenderentities;
if (num >= cl.max_csqcrenderentities)
{
if (num >= MAX_EDICTS)
Host_Error("CL_ExpandEntities: num %i >= %i", num, MAX_EDICTS);
oldmaxcsqcrenderentities = cl.max_csqcrenderentities;
oldcsqcrenderentities = cl.csqcrenderentities;
cl.max_csqcrenderentities = (num & ~255) + 256;
cl.csqcrenderentities = (entity_render_t *)Mem_Alloc(cls.levelmempool, cl.max_csqcrenderentities * sizeof(entity_render_t));
if (oldcsqcrenderentities)
{
memcpy(cl.csqcrenderentities, oldcsqcrenderentities, oldmaxcsqcrenderentities * sizeof(entity_render_t));
for (i = 0;i < r_refdef.scene.numentities;i++)
if(r_refdef.scene.entities[i] >= oldcsqcrenderentities && r_refdef.scene.entities[i] < (oldcsqcrenderentities + oldmaxcsqcrenderentities))
r_refdef.scene.entities[i] = cl.csqcrenderentities + (r_refdef.scene.entities[i] - oldcsqcrenderentities);
Mem_Free(oldcsqcrenderentities);
}
}
}
static void CL_ToggleMenu_Hook(void)
{
#ifdef CONFIG_MENU
// remove menu
if (key_dest == key_menu || key_dest == key_menu_grabbed)
MR_ToggleMenu(0);
#endif
key_dest = key_game;
}
extern cvar_t rcon_secure;
/*
=====================
CL_Disconnect
Sends a disconnect message to the server
This is also called on Host_Error, so it shouldn't cause any errors
=====================
*/
void CL_Disconnect(void)
{
if (cls.state == ca_dedicated)
return;
if (Sys_CheckParm("-profilegameonly"))
Sys_AllowProfiling(false);
Curl_Clear_forthismap();
Con_DPrintf("CL_Disconnect\n");
Cvar_SetValueQuick(&csqc_progcrc, -1);
Cvar_SetValueQuick(&csqc_progsize, -1);
CL_VM_ShutDown();
// stop sounds (especially looping!)
S_StopAllSounds ();
cl.parsingtextexpectingpingforscores = 0; // just in case no reply has come yet
// clear contents blends
cl.cshifts[0].percent = 0;
cl.cshifts[1].percent = 0;
cl.cshifts[2].percent = 0;
cl.cshifts[3].percent = 0;
cl.worldmodel = NULL;
CL_Parse_ErrorCleanUp();
if (cls.demoplayback)
CL_StopPlayback();
else if (cls.netcon)
{
sizebuf_t buf;
unsigned char bufdata[8];
if (cls.demorecording)
CL_Stop_f(cmd_local);
// send disconnect message 3 times to improve chances of server
// receiving it (but it still fails sometimes)
memset(&buf, 0, sizeof(buf));
buf.data = bufdata;
buf.maxsize = sizeof(bufdata);
if (cls.protocol == PROTOCOL_QUAKEWORLD)
{
Con_DPrint("Sending drop command\n");
MSG_WriteByte(&buf, qw_clc_stringcmd);
MSG_WriteString(&buf, "drop");
}
else
{
Con_DPrint("Sending clc_disconnect\n");
MSG_WriteByte(&buf, clc_disconnect);
}
NetConn_SendUnreliableMessage(cls.netcon, &buf, cls.protocol, 10000, 0, false);
NetConn_SendUnreliableMessage(cls.netcon, &buf, cls.protocol, 10000, 0, false);
NetConn_SendUnreliableMessage(cls.netcon, &buf, cls.protocol, 10000, 0, false);
NetConn_Close(cls.netcon);
cls.netcon = NULL;
Con_Printf("Disconnected\n");
}
cls.state = ca_disconnected;
cl.islocalgame = false;
cls.demoplayback = cls.timedemo = host.restless = false;
cls.signon = 0;
Cvar_Callback(&cl_netport);
// If we're dropped mid-connection attempt, it won't clear otherwise.
SCR_ClearLoadingScreen(false);
if(host.hook.SV_Shutdown)
host.hook.SV_Shutdown();
}
/*
==================
CL_Reconnect_f
This command causes the client to wait for the signon messages again.
This is sent just before a server changes levels
==================
*/
static void CL_Reconnect_f(cmd_state_t *cmd)
{
char temp[128];
// if not connected, reconnect to the most recent server
if (!cls.netcon)
{
// if we have connected to a server recently, the userinfo
// will still contain its IP address, so get the address...
InfoString_GetValue(cls.userinfo, "*ip", temp, sizeof(temp));
if (temp[0])
CL_EstablishConnection(temp, -1);
else
Con_Printf("Reconnect to what server? (you have not connected to a server yet)\n");
return;
}
// if connected, do something based on protocol
if (cls.protocol == PROTOCOL_QUAKEWORLD)
{
// quakeworld can just re-login
if (cls.qw_downloadmemory) // don't change when downloading
return;
S_StopAllSounds();
if (cls.state == ca_connected)
{
Con_Printf("Server is changing level...\n");
MSG_WriteChar(&cls.netcon->message, qw_clc_stringcmd);
MSG_WriteString(&cls.netcon->message, "new");
}
}
else
{
// netquake uses reconnect on level changes (silly)
if (Cmd_Argc(cmd) != 1)
{
Con_Print("reconnect : wait for signon messages again\n");
return;
}
if (!cls.signon)
{
Con_Print("reconnect: no signon, ignoring reconnect\n");
return;
}
cls.signon = 0; // need new connection messages
}
}
/*
=====================
CL_Connect_f
User command to connect to server
=====================
*/
static void CL_Connect_f(cmd_state_t *cmd)
{
if (Cmd_Argc(cmd) < 2)
{
Con_Print("connect <serveraddress> [<key> <value> ...]: connect to a multiplayer game\n");
return;
}
// clear the rcon password, to prevent vulnerability by stuffcmd-ing a connect command
if(rcon_secure.integer <= 0)
Cvar_SetQuick(&rcon_password, "");
CL_EstablishConnection(Cmd_Argv(cmd, 1), 2);
}
void CL_Disconnect_f(cmd_state_t *cmd)
{
CL_Disconnect();
}
/*
=====================
CL_EstablishConnection
Host should be either "local" or a net address
=====================
*/
void CL_EstablishConnection(const char *address, int firstarg)
{
if (cls.state == ca_dedicated)
return;
// don't connect to a server if we're benchmarking a demo
if (Sys_CheckParm("-benchmark"))
return;
// clear menu's connect error message
#ifdef CONFIG_MENU
M_Update_Return_Reason("");
#endif
// make sure the client ports are open before attempting to connect
NetConn_UpdateSockets();
if (LHNETADDRESS_FromString(&cls.connect_address, address, 26000) && (cls.connect_mysocket = NetConn_ChooseClientSocketForAddress(&cls.connect_address)))
{
cls.connect_trying = true;
cls.connect_remainingtries = 3;
cls.connect_nextsendtime = 0;
// only NOW, set connect_userinfo
if(firstarg >= 0)
{
int i;
*cls.connect_userinfo = 0;
for(i = firstarg; i+2 <= Cmd_Argc(cmd_local); i += 2)
InfoString_SetValue(cls.connect_userinfo, sizeof(cls.connect_userinfo), Cmd_Argv(cmd_local, i), Cmd_Argv(cmd_local, i+1));
}
else if(firstarg < -1)
{
// -1: keep as is (reconnect)
// -2: clear
*cls.connect_userinfo = 0;
}
#ifdef CONFIG_MENU
M_Update_Return_Reason("Trying to connect...");
#endif
}
else
{
Con_Print("Unable to find a suitable network socket to connect to server.\n");
#ifdef CONFIG_MENU
M_Update_Return_Reason("No network");
#endif
}
}
static void CL_EstablishConnection_Local(void)
{
if(cls.state == ca_disconnected)
CL_EstablishConnection("local:1", -2);
}
static qbool CL_Intermission(void)
{
return cl.intermission;
}
/*
==============
CL_PrintEntities_f
==============
*/
static void CL_PrintEntities_f(cmd_state_t *cmd)
{
entity_t *ent;
int i;
for (i = 0, ent = cl.entities;i < cl.num_entities;i++, ent++)
{
const char* modelname;
if (!ent->state_current.active)
continue;
if (ent->render.model)
modelname = ent->render.model->name;
else
modelname = "--no model--";
Con_Printf("%3i: %-25s:%4i (%5i %5i %5i) [%3i %3i %3i] %4.2f %5.3f\n", i, modelname, ent->render.framegroupblend[0].frame, (int) ent->state_current.origin[0], (int) ent->state_current.origin[1], (int) ent->state_current.origin[2], (int) ent->state_current.angles[0] % 360, (int) ent->state_current.angles[1] % 360, (int) ent->state_current.angles[2] % 360, ent->render.scale, ent->render.alpha);
}
}
/*
===============
CL_ModelIndexList_f
List information on all models in the client modelindex
===============
*/
static void CL_ModelIndexList_f(cmd_state_t *cmd)
{
int i;
model_t *model;
// Print Header
Con_Printf("%3s: %-30s %-8s %-8s\n", "ID", "Name", "Type", "Triangles");
for (i = -MAX_MODELS;i < MAX_MODELS;i++)
{
model = CL_GetModelByIndex(i);
if (!model)
continue;
if(model->loaded || i == 1)
Con_Printf("%3i: %-30s %-8s %-10i\n", i, model->name, model->modeldatatypestring, model->surfmesh.num_triangles);
else
Con_Printf("%3i: %-30s %-30s\n", i, model->name, "--no local model found--");
i++;
}
}
/*
===============
CL_SoundIndexList_f
List all sounds in the client soundindex
===============
*/
static void CL_SoundIndexList_f(cmd_state_t *cmd)
{
int i = 1;
while(cl.sound_precache[i] && i != MAX_SOUNDS)
{ // Valid Sound
Con_Printf("%i : %s\n", i, cl.sound_precache[i]->name);
i++;
}
}
/*
===============
CL_UpdateRenderEntity
Updates inversematrix, animation interpolation factors, scale, and mins/maxs
===============
*/
void CL_UpdateRenderEntity(entity_render_t *ent)
{
vec3_t org;
vec_t scale;
model_t *model = ent->model;
// update the inverse matrix for the renderer
Matrix4x4_Invert_Simple(&ent->inversematrix, &ent->matrix);
// update the animation blend state
VM_FrameBlendFromFrameGroupBlend(ent->frameblend, ent->framegroupblend, ent->model, cl.time);
// we need the matrix origin to center the box
Matrix4x4_OriginFromMatrix(&ent->matrix, org);
// update entity->render.scale because the renderer needs it
ent->scale = scale = Matrix4x4_ScaleFromMatrix(&ent->matrix);
if (model)
{
// NOTE: this directly extracts vector components from the matrix, which relies on the matrix orientation!
#ifdef MATRIX4x4_OPENGLORIENTATION
if (ent->matrix.m[0][2] != 0 || ent->matrix.m[1][2] != 0)
#else
if (ent->matrix.m[2][0] != 0 || ent->matrix.m[2][1] != 0)
#endif
{
// pitch or roll
VectorMA(org, scale, model->rotatedmins, ent->mins);
VectorMA(org, scale, model->rotatedmaxs, ent->maxs);
}
#ifdef MATRIX4x4_OPENGLORIENTATION
else if (ent->matrix.m[1][0] != 0 || ent->matrix.m[0][1] != 0)
#else
else if (ent->matrix.m[0][1] != 0 || ent->matrix.m[1][0] != 0)
#endif
{
// yaw
VectorMA(org, scale, model->yawmins, ent->mins);
VectorMA(org, scale, model->yawmaxs, ent->maxs);
}
else
{
VectorMA(org, scale, model->normalmins, ent->mins);
VectorMA(org, scale, model->normalmaxs, ent->maxs);
}
}
else
{
ent->mins[0] = org[0] - 16;
ent->mins[1] = org[1] - 16;
ent->mins[2] = org[2] - 16;
ent->maxs[0] = org[0] + 16;
ent->maxs[1] = org[1] + 16;
ent->maxs[2] = org[2] + 16;
}
}
/*
===============
CL_LerpPoint
Determines the fraction between the last two messages that the objects
should be put at.
===============
*/
static float CL_LerpPoint(void)
{
float f;
if (cl_nettimesyncboundmode.integer == 1)
cl.time = bound(cl.mtime[1], cl.time, cl.mtime[0]);
// LadyHavoc: lerp in listen games as the server is being capped below the client (usually)
if (cl.mtime[0] <= cl.mtime[1])
{
cl.time = cl.mtime[0];
return 1;
}
f = (cl.time - cl.mtime[1]) / (cl.mtime[0] - cl.mtime[1]);
return bound(0, f, 1 + cl_lerpexcess.value);
}
void CL_ClearTempEntities (void)
{
r_refdef.scene.numtempentities = 0;
// grow tempentities buffer on request
if (r_refdef.scene.expandtempentities)
{
Con_Printf("CL_NewTempEntity: grow maxtempentities from %i to %i\n", r_refdef.scene.maxtempentities, r_refdef.scene.maxtempentities * 2);
r_refdef.scene.maxtempentities *= 2;
r_refdef.scene.tempentities = (entity_render_t *)Mem_Realloc(cls.permanentmempool, r_refdef.scene.tempentities, sizeof(entity_render_t) * r_refdef.scene.maxtempentities);
r_refdef.scene.expandtempentities = false;
}
}
entity_render_t *CL_NewTempEntity(double shadertime)
{
entity_render_t *render;
if (r_refdef.scene.numentities >= r_refdef.scene.maxentities)
return NULL;
if (r_refdef.scene.numtempentities >= r_refdef.scene.maxtempentities)
{
r_refdef.scene.expandtempentities = true; // will be reallocated next frame since current frame may have pointers set already
return NULL;
}
render = &r_refdef.scene.tempentities[r_refdef.scene.numtempentities++];
memset (render, 0, sizeof(*render));
r_refdef.scene.entities[r_refdef.scene.numentities++] = render;
render->shadertime = shadertime;
render->alpha = 1;
VectorSet(render->colormod, 1, 1, 1);
VectorSet(render->glowmod, 1, 1, 1);
return render;
}
void CL_Effect(vec3_t org, model_t *model, int startframe, int framecount, float framerate)
{
int i;
cl_effect_t *e;
if (!model) // sanity check
return;
if (framerate < 1)
{
Con_Printf("CL_Effect: framerate %f is < 1\n", framerate);
return;
}
if (framecount < 1)
{
Con_Printf("CL_Effect: framecount %i is < 1\n", framecount);
return;
}
for (i = 0, e = cl.effects;i < cl.max_effects;i++, e++)
{
if (e->active)
continue;
e->active = true;
VectorCopy(org, e->origin);
e->model = model;
e->starttime = cl.time;
e->startframe = startframe;
e->endframe = startframe + framecount;
e->framerate = framerate;
e->frame = 0;
e->frame1time = cl.time;
e->frame2time = cl.time;
cl.num_effects = max(cl.num_effects, i + 1);
break;
}
}
void CL_AllocLightFlash(entity_render_t *ent, matrix4x4_t *matrix, float radius, float red, float green, float blue, float decay, float lifetime, char *cubemapname, int style, int shadowenable, vec_t corona, vec_t coronasizescale, vec_t ambientscale, vec_t diffusescale, vec_t specularscale, int flags)
{
int i;
dlight_t *dl;
// then look for anything else
dl = cl.dlights;
for (i = 0;i < cl.max_dlights;i++, dl++)
if (!dl->radius)
break;
// unable to find one
if (i == cl.max_dlights)
return;
//Con_Printf("dlight %i : %f %f %f : %f %f %f\n", i, org[0], org[1], org[2], red * radius, green * radius, blue * radius);
memset (dl, 0, sizeof(*dl));
cl.num_dlights = max(cl.num_dlights, i + 1);
Matrix4x4_Normalize(&dl->matrix, matrix);
dl->ent = ent;
Matrix4x4_OriginFromMatrix(&dl->matrix, dl->origin);
CL_FindNonSolidLocation(dl->origin, dl->origin, 6);
Matrix4x4_SetOrigin(&dl->matrix, dl->origin[0], dl->origin[1], dl->origin[2]);
dl->radius = radius;
dl->color[0] = red;
dl->color[1] = green;
dl->color[2] = blue;
dl->initialradius = radius;
dl->initialcolor[0] = red;
dl->initialcolor[1] = green;
dl->initialcolor[2] = blue;
dl->decay = decay / radius; // changed decay to be a percentage decrease
dl->intensity = 1; // this is what gets decayed
if (lifetime)
dl->die = cl.time + lifetime;
else
dl->die = 0;
dl->cubemapname[0] = 0;
if (cubemapname && cubemapname[0])
strlcpy(dl->cubemapname, cubemapname, sizeof(dl->cubemapname));
dl->style = style;
dl->shadow = shadowenable;
dl->corona = corona;
dl->flags = flags;
dl->coronasizescale = coronasizescale;
dl->ambientscale = ambientscale;
dl->diffusescale = diffusescale;
dl->specularscale = specularscale;
}
static void CL_DecayLightFlashes(void)
{
int i, oldmax;
dlight_t *dl;
float time;
time = bound(0, cl.time - cl.oldtime, 0.1);
oldmax = cl.num_dlights;
cl.num_dlights = 0;
for (i = 0, dl = cl.dlights;i < oldmax;i++, dl++)
{
if (dl->radius)
{
dl->intensity -= time * dl->decay;
if (cl.time < dl->die && dl->intensity > 0)
{
if (cl_dlights_decayradius.integer)
dl->radius = dl->initialradius * dl->intensity;
else
dl->radius = dl->initialradius;
if (cl_dlights_decaybrightness.integer)
VectorScale(dl->initialcolor, dl->intensity, dl->color);
else
VectorCopy(dl->initialcolor, dl->color);
cl.num_dlights = i + 1;
}
else
dl->radius = 0;
}
}
}
// called before entity relinking
void CL_RelinkLightFlashes(void)
{
int i, j, k, l;
dlight_t *dl;
float frac, f;
matrix4x4_t tempmatrix;
if (r_dynamic.integer)
{
for (i = 0, dl = cl.dlights;i < cl.num_dlights && r_refdef.scene.numlights < MAX_DLIGHTS;i++, dl++)
{
if (dl->radius)
{
tempmatrix = dl->matrix;
Matrix4x4_Scale(&tempmatrix, dl->radius, 1);
// we need the corona fading to be persistent
R_RTLight_Update(&dl->rtlight, false, &tempmatrix, dl->color, dl->style, dl->cubemapname, dl->shadow, dl->corona, dl->coronasizescale, dl->ambientscale, dl->diffusescale, dl->specularscale, dl->flags);
r_refdef.scene.lights[r_refdef.scene.numlights++] = &dl->rtlight;
}
}
}
if (!cl.lightstyle)
{
for (j = 0;j < cl.max_lightstyle;j++)
{
r_refdef.scene.rtlightstylevalue[j] = 1;
r_refdef.scene.lightstylevalue[j] = 256;
}
return;
}
// light animations
// 'm' is normal light, 'a' is no light, 'z' is double bright
f = cl.time * 10;
i = (int)floor(f);
frac = f - i;
for (j = 0;j < cl.max_lightstyle;j++)
{
if (!cl.lightstyle[j].length)
{
r_refdef.scene.rtlightstylevalue[j] = 1;
r_refdef.scene.lightstylevalue[j] = 256;
continue;
}
// static lightstyle "=value"
if (cl.lightstyle[j].map[0] == '=')
{
r_refdef.scene.rtlightstylevalue[j] = atof(cl.lightstyle[j].map + 1);
if ( r_lerplightstyles.integer || ((int)f - f) < 0.01)
r_refdef.scene.lightstylevalue[j] = r_refdef.scene.rtlightstylevalue[j];
continue;
}
k = i % cl.lightstyle[j].length;
l = (i-1) % cl.lightstyle[j].length;
k = cl.lightstyle[j].map[k] - 'a';
l = cl.lightstyle[j].map[l] - 'a';
// rtlightstylevalue is always interpolated because it has no bad
// consequences for performance
// lightstylevalue is subject to a cvar for performance reasons;
// skipping lightmap updates on most rendered frames substantially
// improves framerates (but makes light fades look bad)
r_refdef.scene.rtlightstylevalue[j] = ((k*frac)+(l*(1-frac)))*(22/256.0f);
r_refdef.scene.lightstylevalue[j] = r_lerplightstyles.integer ? (unsigned short)(((k*frac)+(l*(1-frac)))*22) : k*22;
}
}
static void CL_AddQWCTFFlagModel(entity_t *player, int skin)
{
int frame = player->render.framegroupblend[0].frame;
float f;
entity_render_t *flagrender;
matrix4x4_t flagmatrix;
// this code taken from QuakeWorld
f = 14;
if (frame >= 29 && frame <= 40)
{
if (frame >= 29 && frame <= 34)
{ //axpain
if (frame == 29) f = f + 2;
else if (frame == 30) f = f + 8;
else if (frame == 31) f = f + 12;
else if (frame == 32) f = f + 11;
else if (frame == 33) f = f + 10;
else if (frame == 34) f = f + 4;
}
else if (frame >= 35 && frame <= 40)
{ // pain
if (frame == 35) f = f + 2;
else if (frame == 36) f = f + 10;
else if (frame == 37) f = f + 10;
else if (frame == 38) f = f + 8;
else if (frame == 39) f = f + 4;
else if (frame == 40) f = f + 2;
}
}