/
con_console.c
3030 lines (2677 loc) · 89.9 KB
/
con_console.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
//**************************************************************************
//**
//** CON_CONSOLE.C
//**
//** Should be completely redesigned.
//**
//**************************************************************************
// HEADER FILES ------------------------------------------------------------
#include <stdio.h>
#include <stdlib.h>
#include <stdarg.h>
#include <math.h>
#include <process.h>
#include "de_base.h"
#include "de_console.h"
#include "de_system.h"
#include "de_network.h"
#include "de_graphics.h"
#include "de_refresh.h"
#include "de_render.h"
#include "de_play.h"
#include "de_audio.h"
#include "de_ui.h"
#include "de_misc.h"
#ifdef TextOut
// Windows has its own TextOut.
#undef TextOut
#endif
// MACROS ------------------------------------------------------------------
#define SC_EMPTY_QUOTE -1
// Length of the print buffer. Used in Con_Printf. If console messages are
// longer than this, an error will occur.
#define PRBUFF_LEN 8000
#define OBSOLETE CVF_NO_ARCHIVE|CVF_HIDE
// Macros for accessing the console command values through the void ptr.
#define CV_INT(var) (*(int*) var->ptr)
#define CV_BYTE(var) (*(byte*) var->ptr)
#define CV_FLOAT(var) (*(float*) var->ptr)
#define CV_CHARPTR(var) (*(char**) var->ptr)
// Operators for the "if" command.
enum
{
IF_EQUAL,
IF_NOT_EQUAL,
IF_GREATER,
IF_LESS,
IF_GEQUAL,
IF_LEQUAL
};
// TYPES -------------------------------------------------------------------
typedef struct
{
char *name;
char *command;
} calias_t;
typedef struct
{
unsigned int marker : 31; // The tic on which the cmd should be executed.
unsigned int used : 1; // Is this in use?
char subcmd[1024]; // A single command w/args.
} execbuff_t;
typedef struct
{
char word[64]; // 64 chars MAX for words.
} knownword_t;
// EXTERNAL FUNCTION PROTOTYPES --------------------------------------------
// PUBLIC FUNCTION PROTOTYPES ----------------------------------------------
D_CMD(ListCmds);
D_CMD(ListVars);
D_CMD(Console);
D_CMD(Version);
D_CMD(Quit);
D_CMD(LoadFile);
D_CMD(UnloadFile);
D_CMD(ResetLumps);
D_CMD(ListFiles);
D_CMD(BackgroundTurn);
D_CMD(Dump);
D_CMD(SkyDetail);
D_CMD(Fog);
D_CMD(Bind);
D_CMD(ListBindings);
D_CMD(Font);
D_CMD(Alias);
D_CMD(ListAliases);
D_CMD(SetGamma);
D_CMD(SetRes);
D_CMD(Chat);
D_CMD(Parse);
D_CMD(DeleteBind);
D_CMD(Wait);
D_CMD(Repeat);
D_CMD(Echo);
D_CMD(FlareConfig);
D_CMD(ListActs);
D_CMD(ClearBindings);
D_CMD(AddSub);
D_CMD(Ping);
D_CMD(Login);
D_CMD(Logout);
D_CMD(Dir);
D_CMD(Toggle);
D_CMD(If);
#ifdef _DEBUG
D_CMD(TranslateFont);
#endif
// PRIVATE FUNCTION PROTOTYPES ---------------------------------------------
static int executeSubCmd(char *subcmd);
static void SplitIntoSubCommands(char *command, int markerOffset);
calias_t *Con_GetAlias(const char *name);
// EXTERNAL DATA DECLARATIONS ----------------------------------------------
extern HWND hWndMain;
extern boolean paletted, r_s3tc; // Use GL_EXT_paletted_texture
extern cvar_t netCVars[], inputCVars[];
// PUBLIC DATA DEFINITIONS -------------------------------------------------
ddfont_t Cfont; // The console font.
float CcolYellow[3] = { 1, .85f, .3f };
boolean ConsoleSilent = false;
int CmdReturnValue = 0;
float ConsoleOpenY; // Where the console bottom is when open.
int consoleTurn; // The rotation variable.
int consoleLight = 50, consoleAlpha = 75;
int conCompMode = 0; // Completion mode.
int conSilentCVars = 1;
boolean consoleDump = true;
int consoleActiveKey = '`'; // Tilde.
boolean consoleShowKeys = false;
boolean consoleShowFPS = false;
boolean consoleShadowText = true;
cvar_t *cvars = NULL;
int numCVars = 0;
ccmd_t *ccmds = NULL; // The list of console commands.
int numCCmds = 0; // Number of console commands.
calias_t *caliases = NULL;
int numCAliases = 0;
// Console variables (old <= 1.5.x versions first, 1.6.0 below).
// (Cvars provide access to global variables via the console.)
// FIXME: These don't really all belong here.
cvar_t engineCVars[] =
{
"bgAlpha", OBSOLETE, CVT_INT, &consoleAlpha, 0, 100, "Console background translucency.",
"bgLight", OBSOLETE, CVT_INT, &consoleLight, 0, 100, "Console background light level.",
"CompletionMode", OBSOLETE, CVT_INT, &conCompMode, 0, 1, "How to complete words when pressing Tab:\n0=Show completions, 1=Cycle through them.",
"ConsoleDump", OBSOLETE, CVT_BYTE, &consoleDump, 0, 1, "1=Dump all console messages to Doomsday.out.",
"ConsoleKey", OBSOLETE, CVT_INT, &consoleActiveKey, 0, 255, "Key to activate the console (ASCII code, default is tilde, 96).",
"ConsoleShowKeys", OBSOLETE, CVT_BYTE, &consoleShowKeys, 0, 1, "1=Show ASCII codes of pressed keys in the console.",
"SilentCVars", OBSOLETE, CVT_BYTE, &conSilentCVars,0, 1, "1=Don't show the value of a cvar when setting it.",
"dlBlend", OBSOLETE, CVT_INT, &dlBlend, 0, 3, "Dynamic lights color blending mode:\n0=normal, 1=additive, 2=no blending.",
"dlClip", OBSOLETE, CVT_INT, &clipLights, 0, 1, "1=Clip dynamic lights (try using with dlblend 2).",
"dlFactor", OBSOLETE, CVT_FLOAT, &dlFactor, 0, 1, "Intensity factor for dynamic lights.",
"DynLights", OBSOLETE, CVT_INT, &useDynLights, 0, 1, "1=Render dynamic lights.",
"WallGlow", OBSOLETE, CVT_INT, &useWallGlow, 0, 1, "1=Render glow on walls.",
"GlowHeight", OBSOLETE, CVT_INT, &glowHeight, 0, 1024,"Height of wall glow.",
"i_JoySensi", OBSOLETE, CVT_INT, &joySensitivity,0, 9, "Joystick sensitivity.",
"i_MouseInvY", OBSOLETE, CVT_INT, &mouseInverseY, 0, 1, "1=Inversed mouse Y axis.",
"i_mWheelSensi",OBSOLETE|CVF_NO_MAX, CVT_INT, &mouseWheelSensi, 0, 0, "Mouse wheel sensitivity.",
"i_KeyWait1", OBSOLETE|CVF_NO_MAX, CVT_INT, &repWait1, 6, 0, "The number of 35 Hz ticks to wait before first key repeat.",
"i_KeyWait2", OBSOLETE|CVF_NO_MAX, CVT_INT, &repWait2, 1, 0, "The number of 35 Hz ticks to wait between key repeats.",
"i_MouseDisX", OBSOLETE, CVT_INT, &mouseDisableX, 0, 1, "1=Disable mouse X axis.",
"i_MouseDisY", OBSOLETE, CVT_INT, &mouseDisableY, 0, 1, "1=Disable mouse Y axis.",
"MaxDl", OBSOLETE|CVF_NO_MAX, CVT_INT, &maxDynLights, 0, 0, "The maximum number of dynamic lights. 0=no limit.",
"n_ServerName", OBSOLETE, CVT_CHARPTR, &serverName, 0, 0, "The name of this computer if it's a server.",
"n_ServerInfo", OBSOLETE, CVT_CHARPTR, &serverInfo, 0, 0, "The description given of this computer if it's a server.",
"n_PlrName", OBSOLETE, CVT_CHARPTR, &playerName, 0, 0, "Your name in multiplayer games.",
"npt_Active", OBSOLETE, CVT_INT, &nptActive, 0, 3, "Network protocol: 0=TCP/IP, 1=IPX, 2=Modem, 3=Serial link.",
"npt_IPAddress", OBSOLETE, CVT_CHARPTR, &nptIPAddress, 0, 0, "TCP/IP address for searching servers.",
"npt_IPPort", OBSOLETE|CVF_NO_MAX, CVT_INT, &nptIPPort, 0, 0, "TCP/IP port to use for all data traffic.",
"npt_Modem", OBSOLETE|CVF_NO_MAX, CVT_INT, &nptModem, 0, 0, "Index of the selected modem.",
"npt_PhoneNum", OBSOLETE, CVT_CHARPTR, &nptPhoneNum, 0, 0, "Phone number to dial to when connecting.",
"npt_SerialPort", OBSOLETE, CVT_INT, &nptSerialPort, 1, 8, "COM port to use for serial link connection.",
"npt_SerialBaud", OBSOLETE|CVF_NO_MAX, CVT_INT, &nptSerialBaud, 0, 0, "Baud rate for serial link connections.",
"npt_SerialStopBits", OBSOLETE, CVT_INT, &nptSerialStopBits, 0, 2, "0=1 bit, 1=1.5 bits, 2=2 bits.",
"npt_SerialParity", OBSOLETE, CVT_INT, &nptSerialParity, 0, 3, "0=None, 1=odd, 2=even, 3=mark parity.",
"npt_SerialFlowCtrl", OBSOLETE, CVT_INT, &nptSerialFlowCtrl, 0, 4, "0=None, 1=XON/XOFF, 2=RTS, 3=DTR, 4=RTS/DTR flow control.",
"r_Ambient", OBSOLETE, CVT_INT, &r_ambient, 0, 255, "Ambient light level.",
"r_FOV", OBSOLETE, CVT_FLOAT, &fieldOfView, 1, 179, "Field of view.",
"r_Gamma", OBSOLETE|CVF_PROTECTED, CVT_INT, &usegamma, 0, 4, "The gamma correction level (0-4).",
"r_SmoothRaw", OBSOLETE|CVF_PROTECTED, CVT_INT, &linearRaw, 0, 1, "1=Fullscreen images (320x200) use linear interpolation.",
"r_Mipmapping", OBSOLETE|CVF_PROTECTED, CVT_INT, &mipmapping, 0, 5, "The mipmapping mode for textures.",
"r_SkyDetail", OBSOLETE|CVF_PROTECTED, CVT_INT, &skyDetail, 3, 7, "Number of sky sphere quadrant subdivisions.",
"r_SkyRows", OBSOLETE|CVF_PROTECTED, CVT_INT, &skyRows, 1, 8, "Number of sky sphere rows.",
"r_SkyDist", OBSOLETE|CVF_NO_MAX, CVT_FLOAT, &skyDist, 1, 0, "Sky sphere radius.",
"r_FullSky", OBSOLETE, CVT_INT, &r_fullsky, 0, 1, "1=Always render the full sky sphere.",
"r_Paletted", OBSOLETE|CVF_PROTECTED, CVT_BYTE, &paletted, 0, 1, "1=Use the GL_EXT_shared_texture_palette extension.",
"r_SpriteFilter", OBSOLETE, CVT_INT, &filterSprites, 0, 1, "1=Render smooth sprites.",
"r_Textures", OBSOLETE|CVF_NO_ARCHIVE, CVT_BYTE, &renderTextures,0, 1, "1=Render with textures.",
"r_TexQuality", OBSOLETE, CVT_INT, &texQuality, 0, 8, "The quality of textures (0-8).",
"r_MaxSpriteAngle", OBSOLETE, CVT_FLOAT, &maxSpriteAngle, 0, 90, "Maximum angle for slanted sprites (spralign 2).",
"r_dlMaxRad", OBSOLETE, CVT_INT, &dlMaxRad, 64, 512, "Maximum radius of dynamic lights (default: 128).",
"r_dlRadFactor", OBSOLETE, CVT_FLOAT, &dlRadFactor, 0.1f, 10, "A multiplier for dynlight radii (default: 1).",
"r_TexGlow", OBSOLETE, CVT_INT, &r_texglow, 0, 1, "1=Enable glowing textures.",
"r_WeaponOffsetScale", OBSOLETE|CVF_NO_MAX, CVT_FLOAT, &weaponOffsetScale, 0, 0, "Scaling of player weapon (x,y) offset.",
"r_NoSpriteZ", OBSOLETE, CVT_INT, &r_nospritez, 0, 1, "1=Don't write sprites in the Z buffer.",
"r_Precache", OBSOLETE, CVT_BYTE, &r_precache_sprites, 0, 1, "1=Precache sprites at level setup (slow).",
"r_UseSRVO", OBSOLETE, CVT_INT, &r_use_srvo, 0, 2, "1=Use short-range visual offsets for models.\n2=Use SRVO for sprites, too (unjags actor movement).",
"r_UseVisAngle", OBSOLETE, CVT_INT, &r_use_srvo_angle, 0, 1, "1=Use separate visual angle for mobjs (unjag actors).",
"r_Detail", OBSOLETE, CVT_INT, &r_detail, 0, 1, "1=Render with detail textures.",
"DefaultWads", OBSOLETE, CVT_CHARPTR, &defaultWads, 0, 0, "The list of WADs to be loaded at startup.",
"DefResX", OBSOLETE|CVF_NO_MAX, CVT_INT, &defResX, 320, 0, "Default resolution (X).",
"DefResY", OBSOLETE|CVF_NO_MAX, CVT_INT, &defResY, 240, 0, "Default resolution (Y).",
"SimpleSky", OBSOLETE, CVT_INT, &simpleSky, 0, 2, "Sky rendering mode: 0=normal, 1=quads.",
"SprAlign", OBSOLETE, CVT_INT, &alwaysAlign, 0, 3, "1=Always align sprites with the view plane.\n2=Align to camera, unless slant > r_maxSpriteAngle.",
"SprBlend", OBSOLETE, CVT_INT, &missileBlend, 0, 1, "1=Use additive blending for explosions.",
"SprLight", OBSOLETE, CVT_INT, &litSprites, 0, 1, "1=Sprites lit using dynamic lights.",
"s_VolMIDI", OBSOLETE|CVF_PROTECTED, CVT_INT, &mus_volume/*&snd_MusicVolume*/, 0, 255, "MIDI music volume (0-255).",
"s_VolSFX", OBSOLETE, CVT_INT, &sfx_volume/*&snd_SfxVolume*/, 0, 255, "Sound effects volume (0-255).",
"UseModels", OBSOLETE|CVF_NO_MAX, CVT_INT, &useModels, 0, 1, "Render using 3D models when possible.",
"UseParticles", OBSOLETE, CVT_INT, &r_use_particles, 0, 1, "1=Render particle effects.",
"MaxParticles", OBSOLETE|CVF_NO_MAX, CVT_INT, &r_max_particles, 0, 0, "Maximum number of particles to render. 0=no limit.",
"PtcSpawnRate", OBSOLETE, CVT_FLOAT, &r_particle_spawn_rate, 0, 5, "Particle spawn rate multiplier (default: 1).",
"ModelLight", OBSOLETE, CVT_INT, &modelLight, 0, 10, "Maximum number of light sources on models.",
"ModelInter", OBSOLETE, CVT_INT, &frameInter, 0, 1, "1=Interpolate frames.",
"ModelAspectMod", OBSOLETE|CVF_NO_MAX|CVF_NO_MIN, CVT_FLOAT, &rModelAspectMod, 0, 0, "Scale for MD2 z-axis when model is loaded.",
"ModelMaxZ", OBSOLETE|CVF_NO_MAX, CVT_INT, &r_maxmodelz, 0, 0, "Farther than this models revert back to sprites.",
// "PredictTics", OBSOLETE|CVF_NO_MAX, CVT_INT, &predict_tics, 0, 0, "Max tics to predict ahead.",
"MaxQueuePackets", OBSOLETE, CVT_INT, &maxQueuePackets, 0, 16, "Max packets in send queue.",
"sv_MasterAware", OBSOLETE, CVT_INT, &masterAware, 0, 1, "1=Send info to master server.",
"MasterAddress", OBSOLETE, CVT_CHARPTR, &masterAddress, 0, 0, "Master server IP address / name.",
"MasterPort", OBSOLETE, CVT_INT, &masterPort, 0, 65535, "Master server TCP/IP port.",
"vid_Gamma", OBSOLETE, CVT_FLOAT, &vid_gamma, 0.1f, 6, "Display gamma correction factor: 1=normal.",
"vid_Contrast", OBSOLETE, CVT_FLOAT, &vid_contrast, 0, 10, "Display contrast: 1=normal.",
"vid_Bright", OBSOLETE, CVT_FLOAT, &vid_bright, -2, 2, "Display brightness: -1=dark, 0=normal, 1=light.",
//===========================================================================
// The new, consistent names (1.6.0 ->)
//===========================================================================
// Console
"con-alpha", 0, CVT_INT, &consoleAlpha, 0, 100, "Console background translucency.",
"con-light", 0, CVT_INT, &consoleLight, 0, 100, "Console background light level.",
"con-completion", 0, CVT_INT, &conCompMode, 0, 1, "How to complete words when pressing Tab:\n0=Show completions, 1=Cycle through them.",
"con-dump", 0, CVT_BYTE, &consoleDump, 0, 1, "1=Dump all console messages to Doomsday.out.",
"con-key-activate", 0, CVT_INT, &consoleActiveKey, 0, 255, "Key to activate the console (ASCII code, default is tilde, 96).",
"con-key-show", 0, CVT_BYTE, &consoleShowKeys, 0, 1, "1=Show ASCII codes of pressed keys in the console.",
"con-var-silent", 0, CVT_BYTE, &conSilentCVars,0, 1, "1=Don't show the value of a cvar when setting it.",
"con-progress", 0, CVT_BYTE, &progress_enabled, 0, 1, "1=Show progress bar.",
"con-fps", 0, CVT_BYTE, &consoleShowFPS, 0, 1, "1=Show FPS counter on screen.",
"con-text-shadow", 0, CVT_BYTE, &consoleShadowText, 0, 1, "1=Text in the console has a shadow (might be slow).",
// User Interface
"ui-panel-help", 0, CVT_BYTE, &panel_show_help, 0, 1, "1=Enable help window in Control Panel.",
"ui-panel-tips", 0, CVT_BYTE, &panel_show_tips, 0, 1, "1=Show help indicators in Control Panel.",
// Video
"vid-res-x", CVF_NO_MAX, CVT_INT, &defResX, 320, 0, "Default resolution (X).",
"vid-res-y", CVF_NO_MAX, CVT_INT, &defResY, 240, 0, "Default resolution (Y).",
"vid-gamma", 0, CVT_FLOAT, &vid_gamma, 0.1f, 6, "Display gamma correction factor: 1=normal.",
"vid-contrast", 0, CVT_FLOAT, &vid_contrast, 0, 10, "Display contrast: 1=normal.",
"vid-bright", 0, CVT_FLOAT, &vid_bright, -2, 2, "Display brightness: -1=dark, 0=normal, 1=light.",
// Render
// * Render-Info
"rend-info-tris", 0, CVT_BYTE, &rend_info_tris, 0, 1, "1=Print triangle count after rendering a frame.",
"rend-info-lums", 0, CVT_BYTE, &rend_info_lums, 0, 1, "1=Print lumobj count after rendering a frame.",
// * Render-Light
"rend-light-ambient", 0, CVT_INT, &r_ambient, 0, 255, "Ambient light level.",
"rend-light", 0, CVT_INT, &useDynLights, 0, 1, "1=Render dynamic lights.",
"rend-light-blend", 0, CVT_INT, &dlBlend, 0, 3, "Dynamic lights color blending mode:\n0=normal, 1=additive, 2=no blending.",
"rend-light-clip", 0, CVT_INT, &clipLights, 0, 1, "1=Clip dynamic lights (try using with dlblend 2).",
"rend-light-bright", 0, CVT_FLOAT, &dlFactor, 0, 1, "Intensity factor for dynamic lights.",
"rend-light-num", 0, CVT_INT, &maxDynLights, 0, 8000, "The maximum number of dynamic lights. 0=no limit.",
// "rend-light-shrink", 0, CVT_FLOAT, &dlContract, 0, 1, "Shrink dynlight wall polygons horizontally.",
"rend-light-radius-scale", 0, CVT_FLOAT, &dlRadFactor, 0.1f, 10, "A multiplier for dynlight radii (default: 1).",
"rend-light-radius-max", 0, CVT_INT, &dlMaxRad, 64, 512, "Maximum radius of dynamic lights (default: 128).",
"rend-light-wall-angle", CVF_NO_MAX, CVT_FLOAT, &rend_light_wall_angle, 0, 0, "Intensity of angle-based wall light.",
"rend-light-multitex", 0, CVT_INT, &useMultiTexLights, 0, 1, "1=Use multitexturing when rendering dynamic lights.",
// * Render-Light-Decor
"rend-light-decor", 0, CVT_BYTE, &useDecorations, 0, 1, "1=Enable surface light decorations.",
"rend-light-decor-plane-far", CVF_NO_MAX, CVT_FLOAT, &decorPlaneMaxDist, 0, 0, "Maximum distance at which plane light decorations are visible.",
"rend-light-decor-wall-far", CVF_NO_MAX, CVT_FLOAT, &decorWallMaxDist, 0, 0, "Maximum distance at which wall light decorations are visible.",
"rend-light-decor-plane-bright", 0, CVT_FLOAT, &decorPlaneFactor, 0, 10, "Brightness of plane light decorations.",
"rend-light-decor-wall-bright", 0, CVT_FLOAT, &decorWallFactor, 0, 10, "Brightness of wall light decorations.",
// * Render-Glow
"rend-glow", 0, CVT_INT, &r_texglow, 0, 1, "1=Enable glowing textures.",
"rend-glow-wall", 0, CVT_INT, &useWallGlow, 0, 1, "1=Render glow on walls.",
"rend-glow-height", 0, CVT_INT, &glowHeight, 0, 1024,"Height of wall glow.",
// * Render-Halo
"rend-halo", 0, CVT_INT, &haloMode, 0, 5, "Number of flares to draw per light.",
"rend-halo-bright", 0, CVT_INT, &haloBright, 0, 100, "Halo/flare brightness.",
"rend-halo-occlusion", CVF_NO_MAX, CVT_INT, &haloOccludeSpeed, 0, 0, "Rate at which occluded halos fade.",
"rend-halo-size", 0, CVT_INT, &haloSize, 0, 100, "Size of halos.",
"rend-halo-secondary-limit", CVF_NO_MAX, CVT_FLOAT, &minHaloSize, 0, 0, "Minimum halo size.",
"rend-halo-fade-far", CVF_NO_MAX, CVT_FLOAT, &haloFadeMax, 0, 0, "Distance at which halos are no longer visible.",
"rend-halo-fade-near", CVF_NO_MAX, CVT_FLOAT, &haloFadeMin, 0, 0, "Distance to begin fading halos.",
// * Render-Camera
"rend-camera-fov", 0, CVT_FLOAT, &fieldOfView, 1, 179, "Field of view.",
"rend-camera-smooth", 0, CVT_INT, &rend_camera_smooth, 0, 1, "1=Filter camera movement between game tics.",
// * Render-Texture
"rend-tex", CVF_NO_ARCHIVE, CVT_INT, &renderTextures,0, 1, "1=Render with textures.",
"rend-tex-gamma", CVF_PROTECTED, CVT_INT, &usegamma, 0, 4, "The gamma correction level (0-4).",
"rend-tex-mipmap", CVF_PROTECTED, CVT_INT, &mipmapping, 0, 5, "The mipmapping mode for textures.",
"rend-tex-paletted", CVF_PROTECTED, CVT_BYTE, &paletted, 0, 1, "1=Use the GL_EXT_shared_texture_palette extension.",
"rend-tex-external-always", 0, CVT_BYTE, &loadExtAlways, 0, 1, "1=Always use external texture resources (overrides -pwadtex).",
"rend-tex-quality", 0, CVT_INT, &texQuality, 0, 8, "The quality of textures (0-8).",
"rend-tex-filter-sprite", 0, CVT_INT, &filterSprites, 0, 1, "1=Render smooth sprites.",
"rend-tex-filter-raw", CVF_PROTECTED, CVT_INT, &linearRaw, 0, 1, "1=Fullscreen images (320x200) use linear interpolation.",
"rend-tex-detail", 0, CVT_INT, &r_detail, 0, 1, "1=Render with detail textures.",
"rend-tex-detail-scale", CVF_NO_MIN|CVF_NO_MAX, CVT_FLOAT, &detailScale, 0, 0, "Global detail texture factor.",
"rend-tex-detail-strength", 0, CVT_FLOAT, &detailFactor, 0, 10, "Global detail texture strength factor.",
"rend-tex-detail-far", CVF_NO_MAX, CVT_FLOAT, &detailMaxDist, 1, 0, "Maximum distance where detail textures are visible.",
"rend-tex-detail-multitex", 0, CVT_INT, &useMultiTexDetails, 0, 1, "1=Use multitexturing when rendering detail textures.",
// * Render-Sky
"rend-sky-detail", CVF_PROTECTED, CVT_INT, &skyDetail, 3, 7, "Number of sky sphere quadrant subdivisions.",
"rend-sky-rows", CVF_PROTECTED, CVT_INT, &skyRows, 1, 8, "Number of sky sphere rows.",
"rend-sky-distance", CVF_NO_MAX, CVT_FLOAT, &skyDist, 1, 0, "Sky sphere radius.",
"rend-sky-full", 0, CVT_INT, &r_fullsky, 0, 1, "1=Always render the full sky sphere.",
"rend-sky-simple", 0, CVT_INT, &simpleSky, 0, 2, "Sky rendering mode: 0=normal, 1=quads.",
// * Render-Sprite
"rend-sprite-align-angle", 0, CVT_FLOAT, &maxSpriteAngle, 0, 90, "Maximum angle for slanted sprites (spralign 2).",
"rend-sprite-noz", 0, CVT_INT, &r_nospritez, 0, 1, "1=Don't write sprites in the Z buffer.",
"rend-sprite-precache", 0, CVT_BYTE, &r_precache_sprites, 0, 1, "1=Precache sprites at level setup (slow).",
"rend-sprite-align", 0, CVT_INT, &alwaysAlign, 0, 3, "1=Always align sprites with the view plane.\n2=Align to camera, unless slant > r_maxSpriteAngle.",
"rend-sprite-blend", 0, CVT_INT, &missileBlend, 0, 1, "1=Use additive blending for explosions.",
"rend-sprite-lit", 0, CVT_INT, &litSprites, 0, 1, "1=Sprites lit using dynamic lights.",
// * Render-Model
"rend-model", CVF_NO_MAX, CVT_INT, &useModels, 0, 1, "Render using 3D models when possible.",
"rend-model-lights", 0, CVT_INT, &modelLight, 0, 10, "Maximum number of light sources on models.",
"rend-model-inter", 0, CVT_INT, &frameInter, 0, 1, "1=Interpolate frames.",
"rend-model-aspect", CVF_NO_MAX|CVF_NO_MIN, CVT_FLOAT, &rModelAspectMod, 0, 0, "Scale for MD2 z-axis when model is loaded.",
"rend-model-distance", CVF_NO_MAX, CVT_INT, &r_maxmodelz, 0, 0, "Farther than this models revert back to sprites.",
"rend-model-precache", 0, CVT_BYTE, &r_precache_skins, 0, 1, "1=Precache 3D models at level setup (slow).",
"rend-model-shiny-near", CVF_NO_MAX, CVT_INT, &rend_model_shiny_near, 0, 0, "Shininess reduction start distance (full shininess).",
"rend-model-shiny-far", CVF_NO_MAX, CVT_INT, &rend_model_shiny_far, 0, 0, "Shininess reduction end distance (no shininess).",
"rend-model-lod", CVF_NO_MAX, CVT_FLOAT, &rend_model_lod, 0, 0, "Custom level of detail factor. 0=LOD disabled, 1=normal.",
// * Render-HUD
"rend-hud-offset-scale", CVF_NO_MAX, CVT_FLOAT, &weaponOffsetScale, 0, 0, "Scaling of player weapon (x,y) offset.",
"rend-hud-fov-shift", CVF_NO_MAX, CVT_FLOAT, &weaponFOVShift, 0, 1, "When FOV > 90 player weapon is shifted downward.",
// * Render-Mobj
"rend-mobj-smooth-move", 0, CVT_INT, &r_use_srvo, 0, 2, "1=Use short-range visual offsets for models.\n2=Use SRVO for sprites, too (unjags actor movement).",
"rend-mobj-smooth-turn", 0, CVT_INT, &r_use_srvo_angle, 0, 1, "1=Use separate visual angle for mobjs (unjag actors).",
// * Rend-Particle
"rend-particle", 0, CVT_INT, &r_use_particles, 0, 1, "1=Render particle effects.",
"rend-particle-max", CVF_NO_MAX, CVT_INT, &r_max_particles, 0, 0, "Maximum number of particles to render. 0=no limit.",
"rend-particle-rate", 0, CVT_FLOAT, &r_particle_spawn_rate, 0, 5, "Particle spawn rate multiplier (default: 1).",
"rend-particle-diffuse", CVF_NO_MAX, CVT_FLOAT, &rend_particle_diffuse, 0, 0, "Diffuse factor for particles near the camera.",
"rend-particle-visible-near", CVF_NO_MAX, CVT_INT, &rend_particle_nearlimit, 0, 0, "Minimum visible distance for a particle.",
// * Rend-Shadow
"rend-shadow", 0, CVT_INT, &useShadows, 0, 1, "1=Render shadows under objects.",
"rend-shadow-darkness", 0, CVT_FLOAT, &shadowFactor, 0, 1, "Darkness factor for object shadows.",
"rend-shadow-far", CVF_NO_MAX, CVT_INT, &shadowMaxDist, 0, 0, "Maximum distance where shadows are visible.",
"rend-shadow-radius-max", CVF_NO_MAX, CVT_INT, &shadowMaxRad, 0, 0, "Maximum radius of object shadows.",
// Server
"server-name", 0, CVT_CHARPTR, &serverName, 0, 0, "The name of this computer if it's a server.",
"server-info", 0, CVT_CHARPTR, &serverInfo, 0, 0, "The description given of this computer if it's a server.",
"server-public", 0, CVT_INT, &masterAware, 0, 1, "1=Send info to master server.",
// Client
// "client-predict", CVF_NO_MAX, CVT_INT, &predict_tics, 0, 0, "Max tics to predict ahead.",
// Network
"net-name", 0, CVT_CHARPTR, &playerName, 0, 0, "Your name in multiplayer games.",
"net-protocol", 0, CVT_INT, &nptActive, 0, 3, "Network protocol: 0=TCP/IP, 1=IPX, 2=Modem, 3=Serial link.",
"net-ip-address", 0, CVT_CHARPTR, &nptIPAddress, 0, 0, "TCP/IP address for searching servers.",
"net-ip-port", CVF_NO_MAX, CVT_INT, &nptIPPort, 0, 0, "TCP/IP port to use for all data traffic on this computer.",
"net-modem", CVF_NO_MAX, CVT_INT, &nptModem, 0, 0, "Index of the selected modem.",
"net-modem-phone", 0, CVT_CHARPTR, &nptPhoneNum, 0, 0, "Phone number to dial to when connecting.",
"net-serial-port", CVF_NO_MAX, CVT_INT, &nptSerialPort, 0, 0, "COM port to use for serial link connection.",
"net-serial-baud", CVF_NO_MAX, CVT_INT, &nptSerialBaud, 0, 0, "Baud rate for serial link connections.",
"net-serial-stopbits", 0, CVT_INT, &nptSerialStopBits, 0, 2, "0=1 bit, 1=1.5 bits, 2=2 bits.",
"net-serial-parity", 0, CVT_INT, &nptSerialParity, 0, 3, "0=None, 1=odd, 2=even, 3=mark parity.",
"net-serial-flowctrl", 0, CVT_INT, &nptSerialFlowCtrl, 0, 4, "0=None, 1=XON/XOFF, 2=RTS, 3=DTR, 4=RTS/DTR flow control.",
"net-master-address", 0, CVT_CHARPTR, &masterAddress, 0, 0, "Master server IP address / name.",
"net-master-port", 0, CVT_INT, &masterPort, 0, 65535, "Master server TCP/IP port.",
"net-master-path", 0, CVT_CHARPTR, &masterPath, 0, 0, "Master server path name.",
"net-queue-packets", 0, CVT_INT, &maxQueuePackets, 0, 16, "Max packets in send queue.",
// Sound
"sound-volume", 0, CVT_INT, &sfx_volume, 0, 255, "Sound effects volume (0-255).",
"sound-info", 0, CVT_INT, &sound_info, 0, 1, "1=Show sound debug information.",
"sound-rate", 0, CVT_INT, &sound_rate, 11025, 44100, "Sound effects sample rate (11025, 22050, 44100).",
"sound-16bit", 0, CVT_INT, &sound_16bit, 0, 1, "1=16-bit sound effects/resampling.",
"sound-3d", 0, CVT_INT, &sound_3dmode, 0, 1, "1=Play sound effects in 3D.",
"sound-reverb-volume", 0, CVT_FLOAT, &sfx_reverb_strength, 0, 10, "Reverb effects general volume (0=disable).",
// Music
"music-volume", 0, CVT_INT, &mus_volume, 0, 255, "Music volume (0-255).",
"music-source", 0, CVT_INT, &mus_preference, 0, 2, "Preferred music source: 0=Original MUS, 1=External files, 2=CD.",
// Input
// * Input-Key
"input-key-wait1", CVF_NO_MAX, CVT_INT, &repWait1, 6, 0, "The number of 35 Hz ticks to wait before first key repeat.",
"input-key-wait2", CVF_NO_MAX, CVT_INT, &repWait2, 1, 0, "The number of 35 Hz ticks to wait between key repeats.",
"input-key-show-scancodes", 0, CVT_BYTE, &showScanCodes, 0, 1, "1=Show scancodes of all pressed keys in the console.",
// * Input-Joy
"input-joy-sensi", 0, CVT_INT, &joySensitivity,0, 9, "Joystick sensitivity.",
"input-joy-deadzone", 0, CVT_INT, &joyDeadZone, 0, 90, "Joystick dead zone, in percents.",
// * Input-Mouse
"input-mouse-wheel-sensi", CVF_NO_MAX, CVT_INT, &mouseWheelSensi, 0, 0, "Mouse wheel sensitivity.",
"input-mouse-x-disable", 0, CVT_INT, &mouseDisableX, 0, 1, "1=Disable mouse X axis.",
"input-mouse-y-disable", 0, CVT_INT, &mouseDisableY, 0, 1, "1=Disable mouse Y axis.",
"input-mouse-y-inverse", 0, CVT_INT, &mouseInverseY, 0, 1, "1=Inversed mouse Y axis.",
"input-mouse-filter", 0, CVT_BYTE, &mouseFilter, 0, 1, "1=Filter mouse X and Y axes.",
// File
"file-startup", 0, CVT_CHARPTR, &defaultWads, 0, 0, "The list of WADs to be loaded at startup.",
NULL
};
// Console commands. Names in LOWER CASE (yeah, that's cOnsISteNt).
ccmd_t engineCCmds[] =
{
"actions", CCmdListActs, "List all action commands.",
"add", CCmdAddSub, "Add something to a cvar.",
"after", CCmdWait, "Execute the specified command after a delay.",
"alias", CCmdAlias, "Create aliases for a (set of) console commands.",
"bgturn", CCmdBackgroundTurn, "Set console background rotation speed.",
"bind", CCmdBind, "Bind a console command to an event.",
"bindr", CCmdBind, "Bind a console command to an event (keys with repeat).",
"chat", CCmdChat, "Broadcast a chat message.",
"chatnum", CCmdChat, "Send a chat message to the specified player.",
"chatto", CCmdChat, "Send a chat message to the specified player.",
"clear", CCmdConsole, "Clear the console buffer.",
"clearbinds", CCmdClearBindings, "Deletes all existing bindings.",
"conlocp", CCmdMakeCamera, "Connect a local player.",
"connect", CCmdConnect, "Connect to a server using TCP/IP.",
"dec", CCmdAddSub, "Subtract 1 from a cvar.",
"delbind", CCmdDeleteBind, "Deletes all bindings to the given console command.",
"demolump", CCmdDemoLump, "Write a reference lump file for a demo.",
"dir", CCmdDir, "Print contents of directories.",
"dump", CCmdDump, "Dump a data lump currently loaded in memory.",
"dumpkeymap", CCmdDumpKeyMap, "Write the current keymap to a file.",
"echo", CCmdEcho, "Echo the parameters on separate lines.",
"exec", CCmdParse, "Loads and executes a file containing console commands.",
"flareconfig", CCmdFlareConfig, "Configure lens flares.",
"fog", CCmdFog, "Modify fog settings.",
"font", CCmdFont, "Modify console font settings.",
"help", CCmdConsole, "Show information about the console.",
"huffman", CCmdHuffmanStats, "Print Huffman efficiency and number of bytes sent.",
"if", CCmdIf, "Execute a command if the condition is true.",
"inc", CCmdAddSub, "Add 1 to a cvar.",
"keymap", CCmdKeyMap, "Load a DKM keymap file.",
"kick", CCmdKick, "Kick client out of the game.",
"listaliases", CCmdListAliases, "List all aliases and their expanded forms.",
"listbindings", CCmdListBindings, "List all event bindings.",
"listcmds", CCmdListCmds, "List all console commands.",
"listfiles", CCmdListFiles, "List all the loaded data files and show information about them.",
"listvars", CCmdListVars, "List all console variables and their values.",
"load", CCmdLoadFile, "Load a data file (a WAD or a lump).",
"login", CCmdLogin, "Log in to server console.",
"logout", CCmdLogout, "Terminate remote connection to server console.",
"lowres", CCmdLowRes, "Select the poorest rendering quality.",
"ls", CCmdDir, "Print contents of directories.",
"mipmap", CCmdMipMap, "Set the mipmapping mode.",
"net", CCmdNet, "Network setup and control.",
"panel", CCmdOpenPanel, "Open the Doomsday Control Panel.",
"pausedemo", CCmdPauseDemo, "Pause/resume demo recording.",
"ping", CCmdPing, "Ping the server (or a player if you're the server).",
"playdemo", CCmdPlayDemo, "Play a demo.",
"playext", CCmdPlayExt, "Play an external music file.",
"playmusic", CCmdPlayMusic, "Play a song, an external music file or a CD track.",
"quit!", CCmdQuit, "Exit the game immediately.",
"recorddemo", CCmdRecordDemo, "Start recording a demo.",
"repeat", CCmdRepeat, "Repeat a command at given intervals.",
"reset", CCmdResetLumps, "Reset the data files into what they were at startup.",
"safebind", CCmdBind, "Bind a command to an event, unless the event is already bound.",
"safebindr", CCmdBind, "Bind a command to an event, unless the event is already bound.",
"say", CCmdChat, "Broadcast a chat message.",
"saynum", CCmdChat, "Send a chat message to the specified player.",
"sayto", CCmdChat, "Send a chat message to the specified player.",
"setcon", CCmdSetConsole, "Set console and viewplayer.",
"setgamma", CCmdSetGamma, "Set the gamma correction level.",
"setname", CCmdSetName, "Set your name.",
"setres", CCmdSetRes, "Change video mode resolution or window size.",
"settics", CCmdSetTicks, "Set number of game tics per second (default: 35).",
"setvidramp", CCmdUpdateGammaRamp, "Update display's hardware gamma ramp.",
"skydetail", CCmdSkyDetail, "Set the number of sky sphere quadrant subdivisions.",
"skyrows", CCmdSkyDetail, "Set the number of sky sphere rows.",
"smoothscr", CCmdSmoothRaw, "Set the rendering mode of fullscreen images.",
"stopdemo", CCmdStopDemo, "Stop currently playing demo.",
"stopmusic", CCmdStopMusic, "Stop any currently playing music.",
"sub", CCmdAddSub, "Subtract something from a cvar.",
"texreset", CCmdResetTextures, "Force a texture reload.",
"toggle", CCmdToggle, "Toggle the value of a cvar between zero and nonzero.",
"uicolor", CCmdUIColor, "Change Doomsday user interface colors.",
"unload", CCmdUnloadFile, "Unload a data file from memory.",
"version", CCmdVersion, "Show detailed version information.",
"write", CCmdWriteConsole, "Write variables, bindings and aliases to a file.",
#ifdef _DEBUG
"TranslateFont", CCmdTranslateFont, "Ha ha.",
#endif
NULL
};
knownword_t *knownWords = 0; // The list of known words (for completion).
int numKnownWords = 0;
char trimmed_float_buffer[32]; // Returned by TrimmedFloat().
// PRIVATE DATA DEFINITIONS ------------------------------------------------
static boolean ConsoleActive; // Is the console active?
static float ConsoleY; // Where the console bottom is currently?
static float ConsoleDestY; // Where the console bottom should be?
static int ConsoleTime; // How many ticks has the console been open?
static int ConsoleBlink; // Cursor blink timer.
static float funnyAng;
static boolean openingOrClosing = true;
static float fontFx, fontSy; // Font x factor and y size.
static cbline_t *cbuffer; // This is the buffer.
int bufferLines; // How many lines are there in the buffer?
static int maxBufferLines; // Maximum number of lines in the buffer.
static int maxLineLen; // Maximum length of a line.
static int bPos; // Where the write cursor is? (which line)
static int bFirst; // The first visible line.
static int bLineOff; // How many lines from bPos? (+vislines)
static char cmdLine[256]; // The command line.
static int cmdCursor; // Position of the cursor on the command line.
static cbline_t *oldCmds; // The old commands buffer.
static int numOldCmds;
static int ocPos; // Old commands buffer position.
static int complPos; // Where is the completion cursor?
static int lastCompletion; // The index of the last completion (in knownWords).
static execbuff_t *exBuff;
static int exBuffSize;
static execbuff_t *curExec;
// CODE --------------------------------------------------------------------
void PrepareCmdArgs(cmdargs_t *cargs, char *lpCmdLine)
{
int i, len = strlen(lpCmdLine);
// Prepare the data.
memset(cargs, 0, sizeof(cmdargs_t));
strcpy(cargs->cmdLine, lpCmdLine);
// Prepare.
for(i=0; i<len; i++)
{
#define IS_ESC_CHAR(x) ((x) == '"' || (x) == '\\' || (x) == '{' || (x) == '}')
// Whitespaces are separators.
if(ISSPACE(cargs->cmdLine[i])) cargs->cmdLine[i] = 0;
if(cargs->cmdLine[i] == '\\'
&& IS_ESC_CHAR(cargs->cmdLine[i+1])) // Escape sequence?
{
memmove(cargs->cmdLine+i, cargs->cmdLine+i+1, sizeof(cargs->cmdLine)-i-1);
len--;
continue;
}
if(cargs->cmdLine[i] == '"') // Find the end.
{
int start = i;
cargs->cmdLine[i] = 0;
for(++i; i<len && cargs->cmdLine[i] != '"'; i++)
{
if(cargs->cmdLine[i] == '\\'
&& IS_ESC_CHAR(cargs->cmdLine[i+1])) // Escape sequence?
{
memmove(cargs->cmdLine+i, cargs->cmdLine+i+1, sizeof(cargs->cmdLine)-i-1);
len--;
continue;
}
}
// Quote not terminated?
if(i == len) break;
// An empty set of quotes?
if(i == start+1)
cargs->cmdLine[i] = SC_EMPTY_QUOTE;
else
cargs->cmdLine[i] = 0;
}
if(cargs->cmdLine[i] == '{') // Find matching end.
{
// Braces are another notation for quotes.
int level = 0;
int start = i;
cargs->cmdLine[i] = 0;
for(++i; i < len; i++)
{
if(cargs->cmdLine[i] == '\\'
&& IS_ESC_CHAR(cargs->cmdLine[i+1])) // Escape sequence?
{
memmove(cargs->cmdLine+i, cargs->cmdLine+i+1,
sizeof(cargs->cmdLine)-i-1);
len--;
i++;
continue;
}
if(cargs->cmdLine[i] == '}')
{
if(!level) break;
level--;
}
if(cargs->cmdLine[i] == '{') level++;
}
// Quote not terminated?
if(i == len) break;
// An empty set of braces?
if(i == start + 1)
cargs->cmdLine[i] = SC_EMPTY_QUOTE;
else
cargs->cmdLine[i] = 0;
}
}
// Scan through the cmdLine and get the beginning of each token.
cargs->argc = 0;
for(i = 0; i < len; i++)
{
if(!cargs->cmdLine[i]) continue;
// Is this an empty quote?
if(cargs->cmdLine[i] == SC_EMPTY_QUOTE)
cargs->cmdLine[i] = 0; // Just an empty string.
cargs->argv[cargs->argc++] = cargs->cmdLine + i;
i += strlen(cargs->cmdLine+i);
}
}
char *TrimmedFloat(float val)
{
char *ptr = trimmed_float_buffer;
sprintf(ptr, "%f", val);
// Get rid of the extra zeros.
for(ptr += strlen(ptr)-1; ptr >= trimmed_float_buffer; ptr--)
{
if(*ptr == '0') *ptr = 0;
else if(*ptr == '.')
{
*ptr = 0;
break;
}
else break;
}
return trimmed_float_buffer;
}
//--------------------------------------------------------------------------
//
// Console Variable Handling
//
//--------------------------------------------------------------------------
//===========================================================================
// Con_SetString
//===========================================================================
void Con_SetString(char *name, char *text)
{
cvar_t *cvar = Con_GetVariable(name);
if(!cvar) return;
if(cvar->type == CVT_CHARPTR)
{
// Free the old string, if one exists.
if(cvar->flags & CVF_CAN_FREE && CV_CHARPTR(cvar))
free(CV_CHARPTR(cvar));
// Allocate a new string.
cvar->flags |= CVF_CAN_FREE;
CV_CHARPTR(cvar) = malloc(strlen(text) + 1);
strcpy(CV_CHARPTR(cvar), text);
}
else
Con_Error("Con_SetString: cvar is not of type char*.\n");
}
cvar_t *Con_GetVariable(char *name)
{
int i;
for(i = 0; i < numCVars; i++)
if(!stricmp(name, cvars[i].name))
return cvars+i;
// No match...
return NULL;
}
//===========================================================================
// Con_SetInteger
// Also works with bytes.
//===========================================================================
void Con_SetInteger(char *name, int value)
{
cvar_t *var = Con_GetVariable(name);
if(!var) return;
if(var->type == CVT_INT) CV_INT(var) = value;
if(var->type == CVT_BYTE) CV_BYTE(var) = value;
if(var->type == CVT_FLOAT) CV_FLOAT(var) = value;
}
//===========================================================================
// Con_SetFloat
//===========================================================================
void Con_SetFloat(char *name, float value)
{
cvar_t *var = Con_GetVariable(name);
if(!var) return;
if(var->type == CVT_INT) CV_INT(var) = (int) value;
if(var->type == CVT_BYTE) CV_BYTE(var) = (byte) value;
if(var->type == CVT_FLOAT) CV_FLOAT(var) = value;
}
//===========================================================================
// Con_GetInteger
//===========================================================================
int Con_GetInteger(char *name)
{
cvar_t *var = Con_GetVariable(name);
if(!var) return 0;
if(var->type == CVT_BYTE) return CV_BYTE(var);
if(var->type == CVT_FLOAT) return CV_FLOAT(var);
if(var->type == CVT_CHARPTR) return strtol(CV_CHARPTR(var), 0, 0);
return CV_INT(var);
}
//===========================================================================
// Con_GetFloat
//===========================================================================
float Con_GetFloat(char *name)
{
cvar_t *var = Con_GetVariable(name);
if(!var) return 0;
if(var->type == CVT_INT) return CV_INT(var);
if(var->type == CVT_BYTE) return CV_BYTE(var);
if(var->type == CVT_CHARPTR) return strtod(CV_CHARPTR(var), 0);
return CV_FLOAT(var);
}
//===========================================================================
// Con_GetByte
//===========================================================================
byte Con_GetByte(char *name)
{
cvar_t *var = Con_GetVariable(name);
if(!var) return 0;
if(var->type == CVT_INT) return CV_INT(var);
if(var->type == CVT_FLOAT) return CV_FLOAT(var);
if(var->type == CVT_CHARPTR) return strtol(CV_CHARPTR(var), 0, 0);
return CV_BYTE(var);
}
//===========================================================================
// Con_GetString
//===========================================================================
char *Con_GetString(char *name)
{
cvar_t *var = Con_GetVariable(name);
if(!var || var->type != CVT_CHARPTR) return "";
return CV_CHARPTR(var);
}
//--------------------------------------------------------------------------
//--------------------------------------------------------------------------
static int C_DECL wordListSorter(const void *e1, const void *e2)
{
return stricmp(*(char**)e1, *(char**)e2);
}
static int C_DECL knownWordListSorter(const void *e1, const void *e2)
{
return stricmp(( (knownword_t*) e1)->word,
( (knownword_t*) e2)->word);
}
//===========================================================================
// Con_Init
//===========================================================================
void Con_Init()
{
ConsoleActive = false;
ConsoleY = 0;
ConsoleOpenY = 90;
ConsoleDestY = 0;
ConsoleTime = 0;
funnyAng = 0;
// Font size in VGA coordinates. (Everything is in VGA coords.)
fontFx = 1;
fontSy = 9;
// The buffer.
cbuffer = 0;
bufferLines = 0;
maxBufferLines = 512; //256;
maxLineLen = 70; // Should fit the screen (adjusted later).
cmdCursor = 0;
// The old commands buffer.
oldCmds = 0;
numOldCmds = 0;
ocPos = 0; // No commands yet.
bPos = 0;
bFirst = 0;
bLineOff = 0;
complPos = 0;
lastCompletion = -1;
exBuff = NULL;
exBuffSize = 0;
// Register the engine commands and variables.
Con_AddCommandList(engineCCmds);
Con_AddVariableList(engineCVars);
Con_AddVariableList(netCVars);
Con_AddVariableList(inputCVars);
H_Register();
}
//===========================================================================
// Con_MaxLineLength
//===========================================================================
void Con_MaxLineLength(void)
{
int cw = FR_TextWidth("A");
if(!cw)
{
maxLineLen = 70;
return;
}
maxLineLen = screenWidth/cw - 2;
if(maxLineLen > 250) maxLineLen = 250;
}
//===========================================================================
// Con_UpdateKnownWords
// Variables with CVF_HIDE are not considered known words.
//===========================================================================
void Con_UpdateKnownWords()
{
int i, c, known_vars;
int len;
// Count the number of visible console variables.
for(i = known_vars = 0; i < numCVars; i++)
if(!(cvars[i].flags & CVF_HIDE)) known_vars++;
// Fill the known words table.
numKnownWords = numCCmds + known_vars + numCAliases;
knownWords = realloc(knownWords,
len = sizeof(knownword_t) * numKnownWords);
memset(knownWords, 0, len);
// Commands, variables and aliases are known words.
for(i = 0, c = 0; i < numCCmds; i++, c++)
{
strncpy(knownWords[c].word, ccmds[i].name, 63);
}
for(i = 0; i < numCVars; i++)
{
if(!(cvars[i].flags & CVF_HIDE))
strncpy(knownWords[c++].word, cvars[i].name, 63);
}
for(i = 0; i < numCAliases; i++, c++)
{
strncpy(knownWords[c].word, caliases[i].name, 63);
}
// Sort it so we get nice alphabetical word completions.
qsort(knownWords, numKnownWords, sizeof(knownword_t), knownWordListSorter);
}
void Con_AddCommandList(ccmd_t *cmdlist)
{
for(; cmdlist->name; cmdlist++) Con_AddCommand(cmdlist);
}
void Con_AddCommand(ccmd_t *cmd)
{
numCCmds++;
ccmds = realloc(ccmds, sizeof(ccmd_t) * numCCmds);
memcpy(ccmds + numCCmds-1, cmd, sizeof(ccmd_t));
// Sort them.
qsort(ccmds, numCCmds, sizeof(ccmd_t), wordListSorter);
// Update the list of known words.
// This must be done right away because ccmds' address can change.
//Con_UpdateKnownWords();
}
/*
* Returns a pointer to the ccmd_t with the specified name, or NULL.
*/
ccmd_t *Con_GetCommand(const char *name)
{
int i;
for(i = 0; i < numCCmds; i++)
{
if(!stricmp(ccmds[i].name, name)) return &ccmds[i];
}
return NULL;
}
/*
* Returns true if the given string is a valid command or alias.
*/
boolean Con_IsValidCommand(const char *name)
{
return Con_GetCommand(name) || Con_GetAlias(name);
}
void Con_AddVariableList(cvar_t *varlist)
{
for(; varlist->name; varlist++) Con_AddVariable(varlist);
}
void Con_AddVariable(cvar_t *var)
{
numCVars++;
cvars = realloc(cvars, sizeof(cvar_t) * numCVars);
memcpy(cvars+numCVars-1, var, sizeof(cvar_t));
// Sort them.
qsort(cvars, numCVars, sizeof(cvar_t), wordListSorter);
// Update the list of known words.
// This must be done right away because ccmds' address can change.
//Con_UpdateKnownWords();
}
// Returns NULL if the specified alias can't be found.
calias_t *Con_GetAlias(const char *name)
{
int i;
// Try to find the alias.
for(i=0; i<numCAliases; i++)
if(!stricmp(caliases[i].name, name))
return caliases+i;
return NULL;
}
//===========================================================================
// Con_Alias
// Create an alias.
//===========================================================================
void Con_Alias(char *aName, char *command)
{
calias_t *cal = Con_GetAlias(aName);
boolean remove = false;
// Will we remove this alias?
if(command == NULL)
remove = true;
else if(command[0] == 0)
remove = true;
if(cal && remove)
{
// This alias will be removed.
int idx = cal - caliases;
free(cal->name);
free(cal->command);
if(idx < numCAliases-1)
memmove(caliases+idx, caliases+idx+1, sizeof(calias_t)*(numCAliases-idx-1));
caliases = realloc(caliases, sizeof(calias_t) * --numCAliases);
// We're done.
return;
}
// Does the alias already exist?