/
common.cpp
1589 lines (1290 loc) · 32.5 KB
/
common.cpp
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
/*
This file is part of Jedi Academy.
Jedi Academy 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.
Jedi Academy 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 Jedi Academy. If not, see <http://www.gnu.org/licenses/>.
*/
// Copyright 2001-2013 Raven Software
// common.c -- misc functions used in client and server
#include "../game/q_shared.h"
#include "qcommon.h"
#include "../qcommon/sstring.h" // to get Gil's string class, because MS's doesn't compile properly in here
#include "stv_version.h"
#ifdef _XBOX
#include "../win32/win_file.h"
#include "../ui/ui_splash.h"
#endif
#ifndef FINAL_BUILD
#include "platform.h"
#endif
#define MAXPRINTMSG 4096
#define MAX_NUM_ARGVS 50
int com_argc;
char *com_argv[MAX_NUM_ARGVS+1];
#ifndef _XBOX
static fileHandle_t logfile;
static fileHandle_t speedslog;
static fileHandle_t camerafile;
fileHandle_t com_journalFile;
fileHandle_t com_journalDataFile; // config files are written here
#endif
cvar_t *com_viewlog;
cvar_t *com_speeds;
cvar_t *com_developer;
cvar_t *com_timescale;
cvar_t *com_fixedtime;
cvar_t *com_maxfps;
cvar_t *com_sv_running;
cvar_t *com_cl_running;
cvar_t *com_logfile; // 1 = buffer log, 2 = flush after each print
cvar_t *com_showtrace;
cvar_t *com_terrainPhysics;
cvar_t *com_version;
cvar_t *com_buildScript; // for automated data building scripts
cvar_t *cl_paused;
cvar_t *sv_paused;
cvar_t *com_skippingcin;
cvar_t *com_speedslog; // 1 = buffer log, 2 = flush after each print
// Support for JK2 binaries --eez
cvar_t *com_jk2; // searches for jk2gamex86.dll instead of jagamex86.dll
#ifdef G2_PERFORMANCE_ANALYSIS
cvar_t *com_G2Report;
#endif
// com_speeds times
int time_game;
int time_frontend; // renderer frontend time
int time_backend; // renderer backend time
int timeInTrace;
int timeInPVSCheck;
int numTraces;
int com_frameTime;
int com_frameMsec;
int com_frameNumber = 0;
qboolean com_errorEntered;
qboolean com_fullyInitialized = qfalse;
char com_errorMessage[MAXPRINTMSG];
void Com_WriteConfig_f( void );
//JLF
//void G_DemoFrame();
//============================================================================
#ifndef _XBOX
static char *rd_buffer;
static int rd_buffersize;
static void (*rd_flush)( char *buffer );
void Com_BeginRedirect (char *buffer, int buffersize, void (*flush)( char *) )
{
if (!buffer || !buffersize || !flush)
return;
rd_buffer = buffer;
rd_buffersize = buffersize;
rd_flush = flush;
*rd_buffer = 0;
}
void Com_EndRedirect (void)
{
if ( rd_flush ) {
rd_flush(rd_buffer);
}
rd_buffer = NULL;
rd_buffersize = 0;
rd_flush = NULL;
}
#ifndef FINAL_BUILD
#define OUTPUT_TO_BUILD_WINDOW
#endif
#endif //not xbox
/*
=============
Com_Printf
Both client and server can use this, and it will output
to the apropriate place.
A raw string should NEVER be passed as fmt, because of "%f" type crashers.
=============
*/
void QDECL Com_Printf( const char *fmt, ... ) {
va_list argptr;
char msg[MAXPRINTMSG];
va_start (argptr,fmt);
vsprintf (msg,fmt,argptr);
va_end (argptr);
#ifndef _XBOX
if ( rd_buffer ) {
if ((strlen (msg) + strlen(rd_buffer)) > (rd_buffersize - 1)) {
rd_flush(rd_buffer);
*rd_buffer = 0;
}
strcat (rd_buffer, msg);
return;
}
#endif
CL_ConsolePrint( msg );
// echo to dedicated console and early console
Sys_Print( msg );
#ifdef OUTPUT_TO_BUILD_WINDOW
OutputDebugString(msg);
#endif
#ifndef _XBOX
// logfile
if ( com_logfile && com_logfile->integer ) {
if ( !logfile ) {
logfile = FS_FOpenFileWrite( "qconsole.log" );
if ( com_logfile->integer > 1 ) {
// force it to not buffer so we get valid
// data even if we are crashing
FS_ForceFlush(logfile);
}
}
if ( logfile ) {
FS_Write(msg, strlen(msg), logfile);
}
}
#endif
}
/*
================
Com_DPrintf
A Com_Printf that only shows up if the "developer" cvar is set
================
*/
void QDECL Com_DPrintf( const char *fmt, ...) {
va_list argptr;
char msg[MAXPRINTMSG];
if ( !com_developer || !com_developer->integer ) {
return; // don't confuse non-developers with techie stuff...
}
va_start (argptr,fmt);
vsprintf (msg,fmt,argptr);
va_end (argptr);
Com_Printf ("%s", msg);
}
void Com_WriteCam ( const char *text )
{
#ifndef _XBOX
static char mapname[MAX_QPATH];
// camerafile
if ( !camerafile )
{
extern cvar_t *sv_mapname;
//NOTE: always saves in working dir if using one...
sprintf( mapname, "maps/%s_cam.map", sv_mapname->string );
camerafile = FS_FOpenFileWrite( mapname );
}
if ( camerafile )
{
FS_Printf( camerafile, "%s", text );
}
Com_Printf( "%s\n", mapname );
#endif
}
void Com_FlushCamFile()
{
#ifndef _XBOX
if (!camerafile)
{
// nothing to flush, right?
Com_Printf("No cam file available\n");
return;
}
FS_ForceFlush(camerafile);
FS_FCloseFile (camerafile);
camerafile = 0;
static char flushedMapname[MAX_QPATH];
extern cvar_t *sv_mapname;
sprintf( flushedMapname, "maps/%s_cam.map", sv_mapname->string );
Com_Printf("flushed all cams to %s\n", flushedMapname);
#endif
}
/*
=============
Com_Error
Both client and server can use this, and it will
do the apropriate things.
=============
*/
void SG_WipeSavegame(const char *name); // pretty sucky, but that's how SoF did it...<g>
void SG_Shutdown();
//void SCR_UnprecacheScreenshot();
void QDECL Com_Error( int code, const char *fmt, ... ) {
va_list argptr;
#if defined(_WIN32) && defined(_DEBUG)
if ( code != ERR_DISCONNECT ) {
// if (com_noErrorInterrupt && !com_noErrorInterrupt->integer)
{
__asm {
int 0x03
}
}
}
#endif
// when we are running automated scripts, make sure we
// know if anything failed
if ( com_buildScript && com_buildScript->integer ) {
code = ERR_FATAL;
}
if ( com_errorEntered ) {
Sys_Error( "recursive error after: %s", com_errorMessage );
}
com_errorEntered = qtrue;
//reset some game stuff here
// SCR_UnprecacheScreenshot();
va_start (argptr,fmt);
vsprintf (com_errorMessage,fmt,argptr);
va_end (argptr);
if ( code != ERR_DISCONNECT ) {
Cvar_Get("com_errorMessage", "", CVAR_ROM); //give com_errorMessage a default so it won't come back to life after a resetDefaults
Cvar_Set("com_errorMessage", com_errorMessage);
}
SG_Shutdown(); // close any file pointers
if ( code == ERR_DISCONNECT ) {
SV_Shutdown("Disconnect");
CL_Disconnect();
CL_FlushMemory();
CL_StartHunkUsers();
com_errorEntered = qfalse;
throw ("DISCONNECTED\n");
} else if ( code == ERR_DROP ) {
// If loading/saving caused the crash/error - delete the temp file
SG_WipeSavegame("current"); // delete file
SV_Shutdown (va("Server crashed: %s\n", com_errorMessage));
CL_Disconnect();
CL_FlushMemory();
CL_StartHunkUsers();
Com_Printf (S_COLOR_RED"********************\n"S_COLOR_MAGENTA"ERROR: %s\n"S_COLOR_RED"********************\n", com_errorMessage);
com_errorEntered = qfalse;
throw ("DROPPED\n");
} else {
CL_Shutdown ();
SV_Shutdown (va(S_COLOR_RED"Server fatal crashed: %s\n", com_errorMessage));
}
Com_Shutdown ();
Sys_Error ("%s", com_errorMessage);
}
/*
=============
Com_Quit_f
Both client and server can use this, and it will
do the apropriate things.
=============
*/
void Com_Quit_f( void ) {
// don't try to shutdown if we are in a recursive error
if ( !com_errorEntered ) {
SV_Shutdown ("Server quit\n");
CL_Shutdown ();
Com_Shutdown ();
}
Sys_Quit ();
}
/*
============================================================================
COMMAND LINE FUNCTIONS
+ characters seperate the commandLine string into multiple console
command lines.
All of these are valid:
quake3 +set test blah +map test
quake3 set test blah+map test
quake3 set test blah + map test
============================================================================
*/
#define MAX_CONSOLE_LINES 32
int com_numConsoleLines;
char *com_consoleLines[MAX_CONSOLE_LINES];
/*
==================
Com_ParseCommandLine
Break it up into multiple console lines
==================
*/
void Com_ParseCommandLine( char *commandLine ) {
com_consoleLines[0] = commandLine;
com_numConsoleLines = 1;
while ( *commandLine ) {
// look for a + seperating character
// if commandLine came from a file, we might have real line seperators
if ( *commandLine == '+' || *commandLine == '\n' ) {
if ( com_numConsoleLines == MAX_CONSOLE_LINES ) {
return;
}
com_consoleLines[com_numConsoleLines] = commandLine + 1;
com_numConsoleLines++;
*commandLine = 0;
}
commandLine++;
}
}
/*
===================
Com_SafeMode
Check for "safe" on the command line, which will
skip loading of openjk_sp.cfg
===================
*/
qboolean Com_SafeMode( void ) {
int i;
for ( i = 0 ; i < com_numConsoleLines ; i++ ) {
Cmd_TokenizeString( com_consoleLines[i] );
if ( !Q_stricmp( Cmd_Argv(0), "safe" )
|| !Q_stricmp( Cmd_Argv(0), "cvar_restart" ) ) {
com_consoleLines[i][0] = 0;
return qtrue;
}
}
return qfalse;
}
/*
===============
Com_StartupVariable
Searches for command line parameters that are set commands.
If match is not NULL, only that cvar will be looked for.
That is necessary because cddir and basedir need to be set
before the filesystem is started, but all other sets should
be after execing the config and default.
===============
*/
void Com_StartupVariable( const char *match ) {
int i;
char *s;
cvar_t *cv;
for (i=0 ; i < com_numConsoleLines ; i++) {
Cmd_TokenizeString( com_consoleLines[i] );
if ( strcmp( Cmd_Argv(0), "set" ) ) {
continue;
}
s = Cmd_Argv(1);
if ( !match || !stricmp( s, match ) ) {
Cvar_Set( s, Cmd_Argv(2) );
cv = Cvar_Get( s, "", 0 );
cv->flags |= CVAR_USER_CREATED;
// com_consoleLines[i] = 0;
}
}
}
/*
=================
Com_AddStartupCommands
Adds command line parameters as script statements
Commands are seperated by + signs
Returns qtrue if any late commands were added, which
will keep the demoloop from immediately starting
=================
*/
qboolean Com_AddStartupCommands( void ) {
int i;
qboolean added;
added = qfalse;
// quote every token, so args with semicolons can work
for (i=0 ; i < com_numConsoleLines ; i++) {
if ( !com_consoleLines[i] || !com_consoleLines[i][0] ) {
continue;
}
// set commands won't override menu startup
if ( Q_stricmpn( com_consoleLines[i], "set", 3 ) ) {
added = qtrue;
}
Cbuf_AddText( com_consoleLines[i] );
Cbuf_AddText( "\n" );
}
return added;
}
//============================================================================
void Info_Print( const char *s ) {
char key[512];
char value[512];
char *o;
int l;
if (*s == '\\')
s++;
while (*s)
{
o = key;
while (*s && *s != '\\')
*o++ = *s++;
l = o - key;
if (l < 20)
{
memset (o, ' ', 20-l);
key[20] = 0;
}
else
*o = 0;
Com_Printf ("%s", key);
if (!*s)
{
Com_Printf ("MISSING VALUE\n");
return;
}
o = value;
s++;
while (*s && *s != '\\')
*o++ = *s++;
*o = 0;
if (*s)
s++;
Com_Printf ("%s\n", value);
}
}
/*
============
Com_StringContains
============
*/
char *Com_StringContains(char *str1, char *str2, int casesensitive) {
int len, i, j;
len = strlen(str1) - strlen(str2);
for (i = 0; i <= len; i++, str1++) {
for (j = 0; str2[j]; j++) {
if (casesensitive) {
if (str1[j] != str2[j]) {
break;
}
}
else {
if (toupper(str1[j]) != toupper(str2[j])) {
break;
}
}
}
if (!str2[j]) {
return str1;
}
}
return NULL;
}
/*
============
Com_Filter
============
*/
int Com_Filter(char *filter, char *name, int casesensitive) {
char buf[MAX_TOKEN_CHARS];
char *ptr;
int i;
while(*filter) {
if (*filter == '*') {
filter++;
for (i = 0; *filter; i++) {
if (*filter == '*' || *filter == '?') {
break;
}
buf[i] = *filter;
filter++;
}
buf[i] = '\0';
if (strlen(buf)) {
ptr = Com_StringContains(name, buf, casesensitive);
if (!ptr) {
return qfalse;
}
name = ptr + strlen(buf);
}
}
else if (*filter == '?') {
filter++;
name++;
}
else {
if (casesensitive) {
if (*filter != *name) {
return qfalse;
}
}
else {
if (toupper(*filter) != toupper(*name)) {
return qfalse;
}
}
filter++;
name++;
}
}
return qtrue;
}
/*
=================
Com_InitHunkMemory
=================
*/
void Com_InitHunkMemory( void )
{
Hunk_Clear();
// Cmd_AddCommand( "meminfo", Z_Details_f );
}
// I'm leaving this in just in case we ever need to remember where's a good place to hook something like this in.
//
void Com_ShutdownHunkMemory(void)
{
}
/*
===================
Hunk_SetMark
The server calls this after the level and game VM have been loaded
===================
*/
void Hunk_SetMark( void )
{
}
/*
=================
Hunk_ClearToMark
The client calls this before starting a vid_restart or snd_restart
=================
*/
void Hunk_ClearToMark( void )
{
Z_TagFree(TAG_HUNKALLOC);
Z_TagFree(TAG_HUNKMISCMODELS);
}
/*
=================
Hunk_Clear
The server calls this before shutting down or loading a new map
=================
*/
void Hunk_Clear( void )
{
Z_TagFree(TAG_HUNKALLOC);
Z_TagFree(TAG_HUNKMISCMODELS);
extern void CIN_CloseAllVideos();
CIN_CloseAllVideos();
extern void R_ClearStuffToStopGhoul2CrashingThings(void);
R_ClearStuffToStopGhoul2CrashingThings();
}
/*
===================================================================
EVENTS AND JOURNALING
In addition to these events, .cfg files are also copied to the
journaled file
===================================================================
*/
#define MAX_PUSHED_EVENTS 64
int com_pushedEventsHead, com_pushedEventsTail;
sysEvent_t com_pushedEvents[MAX_PUSHED_EVENTS];
/*
=================
Com_GetRealEvent
=================
*/
sysEvent_t Com_GetRealEvent( void ) {
sysEvent_t ev;
// get an event from the system
ev = Sys_GetEvent();
return ev;
}
/*
=================
Com_PushEvent
=================
*/
void Com_PushEvent( sysEvent_t *event ) {
sysEvent_t *ev;
static int printedWarning;
ev = &com_pushedEvents[ com_pushedEventsHead & (MAX_PUSHED_EVENTS-1) ];
if ( com_pushedEventsHead - com_pushedEventsTail >= MAX_PUSHED_EVENTS ) {
// don't print the warning constantly, or it can give time for more...
if ( !printedWarning ) {
printedWarning = qtrue;
Com_Printf( "WARNING: Com_PushEvent overflow\n" );
}
if ( ev->evPtr ) {
Z_Free( ev->evPtr );
}
com_pushedEventsTail++;
} else {
printedWarning = qfalse;
}
*ev = *event;
com_pushedEventsHead++;
}
/*
=================
Com_GetEvent
=================
*/
sysEvent_t Com_GetEvent( void ) {
if ( com_pushedEventsHead > com_pushedEventsTail ) {
com_pushedEventsTail++;
return com_pushedEvents[ (com_pushedEventsTail-1) & (MAX_PUSHED_EVENTS-1) ];
}
return Com_GetRealEvent();
}
/*
=================
Com_RunAndTimeServerPacket
=================
*/
void Com_RunAndTimeServerPacket( netadr_t *evFrom, msg_t *buf ) {
int t1, t2, msec;
t1 = 0;
if ( com_speeds->integer ) {
t1 = Sys_Milliseconds ();
}
SV_PacketEvent( *evFrom, buf );
if ( com_speeds->integer ) {
t2 = Sys_Milliseconds ();
msec = t2 - t1;
if ( com_speeds->integer == 3 ) {
Com_Printf( "SV_PacketEvent time: %i\n", msec );
}
}
}
/*
=================
Com_EventLoop
Returns last event time
=================
*/
int Com_EventLoop( void ) {
sysEvent_t ev;
netadr_t evFrom;
byte bufData[MAX_MSGLEN];
msg_t buf;
MSG_Init( &buf, bufData, sizeof( bufData ) );
while ( 1 ) {
ev = Com_GetEvent();
// if no more events are available
if ( ev.evType == SE_NONE ) {
// manually send packet events for the loopback channel
while ( NET_GetLoopPacket( NS_CLIENT, &evFrom, &buf ) ) {
CL_PacketEvent( evFrom, &buf );
}
while ( NET_GetLoopPacket( NS_SERVER, &evFrom, &buf ) ) {
// if the server just shut down, flush the events
if ( com_sv_running->integer ) {
Com_RunAndTimeServerPacket( &evFrom, &buf );
}
}
return ev.evTime;
}
switch ( ev.evType ) {
default:
Com_Error( ERR_FATAL, "Com_EventLoop: bad event type %i", ev.evTime );
break;
case SE_NONE:
break;
case SE_KEY:
CL_KeyEvent( ev.evValue, ev.evValue2, ev.evTime );
break;
case SE_CHAR:
CL_CharEvent( ev.evValue );
break;
case SE_MOUSE:
CL_MouseEvent( ev.evValue, ev.evValue2, ev.evTime );
break;
case SE_JOYSTICK_AXIS:
CL_JoystickEvent( ev.evValue, ev.evValue2, ev.evTime );
break;
case SE_CONSOLE:
Cbuf_AddText( (char *)ev.evPtr );
Cbuf_AddText( "\n" );
break;
case SE_PACKET:
evFrom = *(netadr_t *)ev.evPtr;
buf.cursize = ev.evPtrLength - sizeof( evFrom );
// we must copy the contents of the message out, because
// the event buffers are only large enough to hold the
// exact payload, but channel messages need to be large
// enough to hold fragment reassembly
if ( (unsigned)buf.cursize > buf.maxsize ) {
Com_Printf("Com_EventLoop: oversize packet\n");
continue;
}
memcpy( buf.data, (byte *)((netadr_t *)ev.evPtr + 1), buf.cursize );
if ( com_sv_running->integer ) {
Com_RunAndTimeServerPacket( &evFrom, &buf );
} else {
CL_PacketEvent( evFrom, &buf );
}
break;
}
// free any block data
if ( ev.evPtr ) {
Z_Free( ev.evPtr );
}
}
}
/*
================
Com_Milliseconds
Can be used for profiling, but will be journaled accurately
================
*/
int Com_Milliseconds (void) {
sysEvent_t ev;
// get events and push them until we get a null event with the current time
do {
ev = Com_GetRealEvent();
if ( ev.evType != SE_NONE ) {
Com_PushEvent( &ev );
}
} while ( ev.evType != SE_NONE );
return ev.evTime;
}
//============================================================================
/*
=============
Com_Error_f
Just throw a fatal error to
test error shutdown procedures
=============
*/
static void Com_Error_f (void) {
if ( Cmd_Argc() > 1 ) {
Com_Error( ERR_DROP, "Testing drop error" );
} else {
Com_Error( ERR_FATAL, "Testing fatal error" );
}
}
/*
=============
Com_Freeze_f
Just freeze in place for a given number of seconds to test
error recovery
=============
*/
static void Com_Freeze_f (void) {
float s;
int start, now;
if ( Cmd_Argc() != 2 ) {
Com_Printf( "freeze <seconds>\n" );
return;
}
s = atof( Cmd_Argv(1) );
start = Com_Milliseconds();
while ( 1 ) {
now = Com_Milliseconds();
if ( ( now - start ) * 0.001 > s ) {
break;
}
}
}
/*
=================
Com_Crash_f
A way to force a bus error for development reasons
=================
*/
static void Com_Crash_f( void ) {
* ( int * ) 0 = 0x12345678;
}
/*
=================
Com_Init
=================
*/
extern void Com_InitZoneMemory();
extern void R_InitWorldEffects();
void Com_Init( char *commandLine ) {
char *s;
Com_Printf( "%s %s %s\n", Q3_VERSION, CPUSTRING, __DATE__ );
try {
// prepare enough of the subsystems to handle
// cvar and command buffer management
Com_ParseCommandLine( commandLine );
Swap_Init ();
Cbuf_Init ();
Com_InitZoneMemory();
#ifdef _XBOX
WF_Init();
// set up ri
extern void CL_InitRef( void );
CL_InitRef();
// register renderer cvars
extern void R_Register(void);
R_Register();
// start the gl render layer
extern void GLimp_Init(void);
GLimp_Init();
// put up the license screen
SP_DoLicense();
#endif
Cmd_Init ();
Cvar_Init ();
// get the commandline cvars set
Com_StartupVariable( NULL );
// done early so bind command exists
CL_InitKeyCommands();