|
|
1.1 root 1: // common.c -- misc functions used in client and server
2: #include "qcommon.h"
3: #include <setjmp.h>
1.1.1.2 ! root 4:
1.1 root 5: #define MAXPRINTMSG 4096
1.1.1.2 ! root 6:
1.1 root 7: #define MAX_NUM_ARGVS 50
1.1.1.2 ! root 8:
! 9:
1.1 root 10: int com_argc;
11: char *com_argv[MAX_NUM_ARGVS+1];
1.1.1.2 ! root 12:
1.1 root 13: int realtime;
1.1.1.2 ! root 14:
1.1 root 15: jmp_buf abortframe; // an ERR_DROP occured, exit the entire frame
16:
1.1.1.2 ! root 17:
1.1 root 18: FILE *log_stats_file;
1.1.1.2 ! root 19:
1.1 root 20: cvar_t *host_speeds;
21: cvar_t *log_stats;
22: cvar_t *developer;
23: cvar_t *timescale;
24: cvar_t *fixedtime;
25: cvar_t *logfile_active; // 1 = buffer log, 2 = flush after each print
26: cvar_t *showtrace;
27: cvar_t *dedicated;
1.1.1.2 ! root 28:
1.1 root 29: FILE *logfile;
1.1.1.2 ! root 30:
1.1 root 31: int server_state;
1.1.1.2 ! root 32:
1.1 root 33: // host_speeds times
34: int time_before_game;
35: int time_after_game;
36: int time_before_ref;
37: int time_after_ref;
1.1.1.2 ! root 38:
1.1 root 39: /*
40: ============================================================================
1.1.1.2 ! root 41:
1.1 root 42: CLIENT / SERVER interactions
1.1.1.2 ! root 43:
1.1 root 44: ============================================================================
45: */
1.1.1.2 ! root 46:
1.1 root 47: static int rd_target;
48: static char *rd_buffer;
49: static int rd_buffersize;
50: static void (*rd_flush)(int target, char *buffer);
1.1.1.2 ! root 51:
1.1 root 52: void Com_BeginRedirect (int target, char *buffer, int buffersize, void (*flush))
53: {
54: if (!target || !buffer || !buffersize || !flush)
55: return;
56: rd_target = target;
57: rd_buffer = buffer;
58: rd_buffersize = buffersize;
59: rd_flush = flush;
60:
61: *rd_buffer = 0;
62: }
63:
64: void Com_EndRedirect (void)
65: {
66: rd_flush(rd_target, rd_buffer);
67:
68: rd_target = 0;
69: rd_buffer = NULL;
70: rd_buffersize = 0;
71: rd_flush = NULL;
72: }
73:
74: /*
75: =============
76: Com_Printf
1.1.1.2 ! root 77:
1.1 root 78: Both client and server can use this, and it will output
79: to the apropriate place.
80: =============
81: */
82: void Com_Printf (char *fmt, ...)
83: {
84: va_list argptr;
85: char msg[MAXPRINTMSG];
1.1.1.2 ! root 86:
1.1 root 87: va_start (argptr,fmt);
88: vsprintf (msg,fmt,argptr);
89: va_end (argptr);
1.1.1.2 ! root 90:
1.1 root 91: if (rd_target)
92: {
93: if ((strlen (msg) + strlen(rd_buffer)) > (rd_buffersize - 1))
94: {
95: rd_flush(rd_target, rd_buffer);
96: *rd_buffer = 0;
97: }
98: strcat (rd_buffer, msg);
99: return;
100: }
101:
102: Con_Print (msg);
103:
104: // also echo to debugging console
105: Sys_ConsoleOutput (msg);
1.1.1.2 ! root 106:
1.1 root 107: // logfile
108: if (logfile_active && logfile_active->value)
109: {
110: char name[MAX_QPATH];
111:
112: if (!logfile)
113: {
114: Com_sprintf (name, sizeof(name), "%s/qconsole.log", FS_Gamedir ());
115: logfile = fopen (name, "w");
116: }
117: if (logfile)
118: fprintf (logfile, "%s", msg);
119: if (logfile_active->value > 1)
120: fflush (logfile); // force it to save every time
121: }
122: }
1.1.1.2 ! root 123:
! 124:
1.1 root 125: /*
126: ================
127: Com_DPrintf
1.1.1.2 ! root 128:
1.1 root 129: A Com_Printf that only shows up if the "developer" cvar is set
130: ================
131: */
132: void Com_DPrintf (char *fmt, ...)
133: {
134: va_list argptr;
135: char msg[MAXPRINTMSG];
136:
137: if (!developer || !developer->value)
138: return; // don't confuse non-developers with techie stuff...
1.1.1.2 ! root 139:
1.1 root 140: va_start (argptr,fmt);
141: vsprintf (msg,fmt,argptr);
142: va_end (argptr);
143:
144: Com_Printf ("%s", msg);
145: }
1.1.1.2 ! root 146:
! 147:
1.1 root 148: /*
149: =============
150: Com_Error
1.1.1.2 ! root 151:
1.1 root 152: Both client and server can use this, and it will
153: do the apropriate things.
154: =============
155: */
156: void Com_Error (int code, char *fmt, ...)
157: {
158: va_list argptr;
159: static char msg[MAXPRINTMSG];
160: static qboolean recursive;
1.1.1.2 ! root 161:
1.1 root 162: if (recursive)
163: Sys_Error ("recursive error after: %s", msg);
164: recursive = true;
1.1.1.2 ! root 165:
1.1 root 166: va_start (argptr,fmt);
167: vsprintf (msg,fmt,argptr);
168: va_end (argptr);
169:
170: if (code == ERR_DISCONNECT)
171: {
172: CL_Drop ();
173: recursive = false;
174: longjmp (abortframe, -1);
175: }
176: else if (code == ERR_DROP)
177: {
178: Com_Printf ("********************\nERROR: %s\n********************\n", msg);
179: SV_Shutdown (va("Server crashed: %s\n", msg), false);
180: CL_Drop ();
181: recursive = false;
182: longjmp (abortframe, -1);
183: }
184: else
185: {
186: SV_Shutdown (va("Server fatal crashed: %s\n", msg), false);
187: CL_Shutdown ();
188: }
1.1.1.2 ! root 189:
1.1 root 190: if (logfile)
191: {
192: fclose (logfile);
193: logfile = NULL;
194: }
1.1.1.2 ! root 195:
1.1 root 196: Sys_Error ("%s", msg);
197: }
1.1.1.2 ! root 198:
! 199:
1.1 root 200: /*
201: =============
202: Com_Quit
1.1.1.2 ! root 203:
1.1 root 204: Both client and server can use this, and it will
205: do the apropriate things.
206: =============
207: */
208: void Com_Quit (void)
209: {
210: SV_Shutdown ("Server quit\n", false);
211: CL_Shutdown ();
1.1.1.2 ! root 212:
1.1 root 213: if (logfile)
214: {
215: fclose (logfile);
216: logfile = NULL;
217: }
1.1.1.2 ! root 218:
1.1 root 219: Sys_Quit ();
220: }
1.1.1.2 ! root 221:
! 222:
1.1 root 223: /*
224: ==================
225: Com_ServerState
226: ==================
227: */
228: int Com_ServerState (void)
229: {
230: return server_state;
231: }
1.1.1.2 ! root 232:
1.1 root 233: /*
234: ==================
235: Com_SetServerState
236: ==================
237: */
238: void Com_SetServerState (int state)
239: {
240: server_state = state;
241: }
1.1.1.2 ! root 242:
! 243:
1.1 root 244: /*
245: ==============================================================================
1.1.1.2 ! root 246:
1.1 root 247: MESSAGE IO FUNCTIONS
1.1.1.2 ! root 248:
1.1 root 249: Handles byte ordering and avoids alignment errors
250: ==============================================================================
251: */
1.1.1.2 ! root 252:
1.1 root 253: vec3_t bytedirs[NUMVERTEXNORMALS] =
254: {
255: #include "../client/anorms.h"
256: };
1.1.1.2 ! root 257:
1.1 root 258: //
259: // writing functions
260: //
1.1.1.2 ! root 261:
1.1 root 262: void MSG_WriteChar (sizebuf_t *sb, int c)
263: {
264: byte *buf;
265:
266: #ifdef PARANOID
267: if (c < -128 || c > 127)
268: Com_Error (ERR_FATAL, "MSG_WriteChar: range error");
269: #endif
1.1.1.2 ! root 270:
1.1 root 271: buf = SZ_GetSpace (sb, 1);
272: buf[0] = c;
273: }
1.1.1.2 ! root 274:
1.1 root 275: void MSG_WriteByte (sizebuf_t *sb, int c)
276: {
277: byte *buf;
278:
279: #ifdef PARANOID
280: if (c < 0 || c > 255)
281: Com_Error (ERR_FATAL, "MSG_WriteByte: range error");
282: #endif
1.1.1.2 ! root 283:
1.1 root 284: buf = SZ_GetSpace (sb, 1);
285: buf[0] = c;
286: }
1.1.1.2 ! root 287:
1.1 root 288: void MSG_WriteShort (sizebuf_t *sb, int c)
289: {
290: byte *buf;
291:
292: #ifdef PARANOID
293: if (c < ((short)0x8000) || c > (short)0x7fff)
294: Com_Error (ERR_FATAL, "MSG_WriteShort: range error");
295: #endif
1.1.1.2 ! root 296:
1.1 root 297: buf = SZ_GetSpace (sb, 2);
298: buf[0] = c&0xff;
299: buf[1] = c>>8;
300: }
1.1.1.2 ! root 301:
1.1 root 302: void MSG_WriteLong (sizebuf_t *sb, int c)
303: {
304: byte *buf;
305:
306: buf = SZ_GetSpace (sb, 4);
307: buf[0] = c&0xff;
308: buf[1] = (c>>8)&0xff;
309: buf[2] = (c>>16)&0xff;
310: buf[3] = c>>24;
311: }
1.1.1.2 ! root 312:
1.1 root 313: void MSG_WriteFloat (sizebuf_t *sb, float f)
314: {
315: union
316: {
317: float f;
318: int l;
319: } dat;
320:
321:
322: dat.f = f;
323: dat.l = LittleLong (dat.l);
324:
325: SZ_Write (sb, &dat.l, 4);
326: }
1.1.1.2 ! root 327:
1.1 root 328: void MSG_WriteString (sizebuf_t *sb, char *s)
329: {
330: if (!s)
331: SZ_Write (sb, "", 1);
332: else
333: SZ_Write (sb, s, strlen(s)+1);
334: }
1.1.1.2 ! root 335:
1.1 root 336: void MSG_WriteCoord (sizebuf_t *sb, float f)
337: {
338: MSG_WriteShort (sb, (int)(f*8));
339: }
1.1.1.2 ! root 340:
1.1 root 341: void MSG_WritePos (sizebuf_t *sb, vec3_t pos)
342: {
343: MSG_WriteShort (sb, (int)(pos[0]*8));
344: MSG_WriteShort (sb, (int)(pos[1]*8));
345: MSG_WriteShort (sb, (int)(pos[2]*8));
346: }
1.1.1.2 ! root 347:
1.1 root 348: void MSG_WriteAngle (sizebuf_t *sb, float f)
349: {
350: MSG_WriteByte (sb, (int)(f*256/360) & 255);
351: }
1.1.1.2 ! root 352:
1.1 root 353: void MSG_WriteAngle16 (sizebuf_t *sb, float f)
354: {
355: MSG_WriteShort (sb, ANGLE2SHORT(f));
356: }
357:
1.1.1.2 ! root 358:
1.1 root 359: void MSG_WriteDeltaUsercmd (sizebuf_t *buf, usercmd_t *from, usercmd_t *cmd)
360: {
361: int bits;
1.1.1.2 ! root 362:
1.1 root 363: //
364: // send the movement message
365: //
366: bits = 0;
367: if (cmd->angles[0] != from->angles[0])
368: bits |= CM_ANGLE1;
369: if (cmd->angles[1] != from->angles[1])
370: bits |= CM_ANGLE2;
371: if (cmd->angles[2] != from->angles[2])
372: bits |= CM_ANGLE3;
373: if (cmd->forwardmove != from->forwardmove)
374: bits |= CM_FORWARD;
375: if (cmd->sidemove != from->sidemove)
376: bits |= CM_SIDE;
377: if (cmd->upmove != from->upmove)
378: bits |= CM_UP;
379: if (cmd->buttons != from->buttons)
380: bits |= CM_BUTTONS;
381: if (cmd->impulse != from->impulse)
382: bits |= CM_IMPULSE;
1.1.1.2 ! root 383:
1.1 root 384: MSG_WriteByte (buf, bits);
1.1.1.2 ! root 385:
1.1 root 386: if (bits & CM_ANGLE1)
387: MSG_WriteShort (buf, cmd->angles[0]);
388: if (bits & CM_ANGLE2)
389: MSG_WriteShort (buf, cmd->angles[1]);
390: if (bits & CM_ANGLE3)
391: MSG_WriteShort (buf, cmd->angles[2]);
392:
393: if (bits & CM_FORWARD)
394: MSG_WriteShort (buf, cmd->forwardmove);
395: if (bits & CM_SIDE)
396: MSG_WriteShort (buf, cmd->sidemove);
397: if (bits & CM_UP)
398: MSG_WriteShort (buf, cmd->upmove);
1.1.1.2 ! root 399:
1.1 root 400: if (bits & CM_BUTTONS)
401: MSG_WriteByte (buf, cmd->buttons);
402: if (bits & CM_IMPULSE)
403: MSG_WriteByte (buf, cmd->impulse);
1.1.1.2 ! root 404:
1.1 root 405: MSG_WriteByte (buf, cmd->msec);
406: MSG_WriteByte (buf, cmd->lightlevel);
407: }
1.1.1.2 ! root 408:
! 409:
1.1 root 410: void MSG_WriteDir (sizebuf_t *sb, vec3_t dir)
411: {
412: int i, best;
413: float d, bestd;
414:
415: if (!dir)
416: {
417: MSG_WriteByte (sb, 0);
418: return;
419: }
1.1.1.2 ! root 420:
1.1 root 421: bestd = 0;
422: best = 0;
423: for (i=0 ; i<NUMVERTEXNORMALS ; i++)
424: {
425: d = DotProduct (dir, bytedirs[i]);
426: if (d > bestd)
427: {
428: bestd = d;
429: best = i;
430: }
431: }
432: MSG_WriteByte (sb, best);
433: }
1.1.1.2 ! root 434:
! 435:
1.1 root 436: void MSG_ReadDir (sizebuf_t *sb, vec3_t dir)
437: {
438: int b;
1.1.1.2 ! root 439:
1.1 root 440: b = MSG_ReadByte (sb);
441: if (b >= NUMVERTEXNORMALS)
442: Com_Error (ERR_DROP, "MSF_ReadDir: out of range");
443: VectorCopy (bytedirs[b], dir);
444: }
1.1.1.2 ! root 445:
! 446:
1.1 root 447: /*
448: ==================
449: MSG_WriteDeltaEntity
1.1.1.2 ! root 450:
1.1 root 451: Writes part of a packetentities message.
452: Can delta from either a baseline or a previous packet_entity
453: ==================
454: */
1.1.1.2 ! root 455: void MSG_WriteDeltaEntity (entity_state_t *from, entity_state_t *to, sizebuf_t *msg, qboolean force, qboolean newentity)
1.1 root 456: {
457: int bits;
458:
459: if (!to->number)
460: Com_Error (ERR_FATAL, "Unset entity number");
461: if (to->number >= MAX_EDICTS)
462: Com_Error (ERR_FATAL, "Entity number >= MAX_EDICTS");
1.1.1.2 ! root 463:
1.1 root 464: // send an update
465: bits = 0;
466:
467: if (to->number >= 256)
468: bits |= U_NUMBER16; // number8 is implicit otherwise
469:
470: if (to->origin[0] != from->origin[0])
471: bits |= U_ORIGIN1;
472: if (to->origin[1] != from->origin[1])
473: bits |= U_ORIGIN2;
474: if (to->origin[2] != from->origin[2])
475: bits |= U_ORIGIN3;
1.1.1.2 ! root 476:
1.1 root 477: if ( to->angles[0] != from->angles[0] )
478: bits |= U_ANGLE1;
479: if ( to->angles[1] != from->angles[1] )
480: bits |= U_ANGLE2;
481: if ( to->angles[2] != from->angles[2] )
482: bits |= U_ANGLE3;
483:
484: if ( to->skinnum != from->skinnum )
485: {
486: if ((unsigned)to->skinnum < 256)
487: bits |= U_SKIN8;
488: else if ((unsigned)to->skinnum < 0x10000)
489: bits |= U_SKIN16;
490: else
491: bits |= (U_SKIN8|U_SKIN16);
492: }
493:
494: if ( to->frame != from->frame )
495: {
496: if (to->frame < 256)
497: bits |= U_FRAME8;
498: else
499: bits |= U_FRAME16;
500: }
1.1.1.2 ! root 501:
1.1 root 502: if ( to->effects != from->effects )
503: {
504: if (to->effects < 256)
505: bits |= U_EFFECTS8;
506: else if (to->effects < 0x8000)
507: bits |= U_EFFECTS16;
508: else
509: bits |= U_EFFECTS8|U_EFFECTS16;
510: }
511:
512: if ( to->renderfx != from->renderfx )
513: {
514: if (to->renderfx < 256)
515: bits |= U_RENDERFX8;
516: else if (to->renderfx < 0x8000)
517: bits |= U_RENDERFX16;
518: else
519: bits |= U_RENDERFX8|U_RENDERFX16;
520: }
521:
522: if ( to->solid != from->solid )
523: bits |= U_SOLID;
524:
525: // event is not delta compressed, just 0 compressed
526: if ( to->event )
527: bits |= U_EVENT;
528:
529: if ( to->modelindex != from->modelindex )
530: bits |= U_MODEL;
531: if ( to->modelindex2 != from->modelindex2 )
532: bits |= U_MODEL2;
533: if ( to->modelindex3 != from->modelindex3 )
534: bits |= U_MODEL3;
535: if ( to->modelindex4 != from->modelindex4 )
536: bits |= U_MODEL4;
1.1.1.2 ! root 537:
1.1 root 538: if ( to->sound != from->sound )
539: bits |= U_SOUND;
540:
1.1.1.2 ! root 541: if (newentity || (to->renderfx & RF_BEAM))
! 542: bits |= U_OLDORIGIN;
! 543:
1.1 root 544: //
545: // write the message
546: //
547: if (!bits && !force)
548: return; // nothing to send!
1.1.1.2 ! root 549:
1.1 root 550: //----------
551:
552: if (bits & 0xff000000)
553: bits |= U_MOREBITS3 | U_MOREBITS2 | U_MOREBITS1;
554: else if (bits & 0x00ff0000)
555: bits |= U_MOREBITS2 | U_MOREBITS1;
556: else if (bits & 0x0000ff00)
557: bits |= U_MOREBITS1;
1.1.1.2 ! root 558:
1.1 root 559: MSG_WriteByte (msg, bits&255 );
1.1.1.2 ! root 560:
1.1 root 561: if (bits & 0xff000000)
562: {
563: MSG_WriteByte (msg, (bits>>8)&255 );
564: MSG_WriteByte (msg, (bits>>16)&255 );
565: MSG_WriteByte (msg, (bits>>24)&255 );
566: }
567: else if (bits & 0x00ff0000)
568: {
569: MSG_WriteByte (msg, (bits>>8)&255 );
570: MSG_WriteByte (msg, (bits>>16)&255 );
571: }
572: else if (bits & 0x0000ff00)
573: {
574: MSG_WriteByte (msg, (bits>>8)&255 );
575: }
1.1.1.2 ! root 576:
1.1 root 577: //----------
578:
579: if (bits & U_NUMBER16)
580: MSG_WriteShort (msg, to->number);
581: else
582: MSG_WriteByte (msg, to->number);
1.1.1.2 ! root 583:
1.1 root 584: if (bits & U_MODEL)
585: MSG_WriteByte (msg, to->modelindex);
586: if (bits & U_MODEL2)
587: MSG_WriteByte (msg, to->modelindex2);
588: if (bits & U_MODEL3)
589: MSG_WriteByte (msg, to->modelindex3);
590: if (bits & U_MODEL4)
591: MSG_WriteByte (msg, to->modelindex4);
1.1.1.2 ! root 592:
1.1 root 593: if (bits & U_FRAME8)
594: MSG_WriteByte (msg, to->frame);
595: if (bits & U_FRAME16)
596: MSG_WriteShort (msg, to->frame);
1.1.1.2 ! root 597:
1.1 root 598: if ((bits & U_SKIN8) && (bits & U_SKIN16)) //used for laser colors
599: MSG_WriteLong (msg, to->skinnum);
600: else if (bits & U_SKIN8)
601: MSG_WriteByte (msg, to->skinnum);
602: else if (bits & U_SKIN16)
603: MSG_WriteShort (msg, to->skinnum);
604:
1.1.1.2 ! root 605:
1.1 root 606: if ( (bits & (U_EFFECTS8|U_EFFECTS16)) == (U_EFFECTS8|U_EFFECTS16) )
607: MSG_WriteLong (msg, to->effects);
608: else if (bits & U_EFFECTS8)
609: MSG_WriteByte (msg, to->effects);
610: else if (bits & U_EFFECTS16)
611: MSG_WriteShort (msg, to->effects);
1.1.1.2 ! root 612:
1.1 root 613: if ( (bits & (U_RENDERFX8|U_RENDERFX16)) == (U_RENDERFX8|U_RENDERFX16) )
614: MSG_WriteLong (msg, to->renderfx);
615: else if (bits & U_RENDERFX8)
616: MSG_WriteByte (msg, to->renderfx);
617: else if (bits & U_RENDERFX16)
618: MSG_WriteShort (msg, to->renderfx);
1.1.1.2 ! root 619:
1.1 root 620: if (bits & U_ORIGIN1)
621: MSG_WriteCoord (msg, to->origin[0]);
622: if (bits & U_ORIGIN2)
623: MSG_WriteCoord (msg, to->origin[1]);
624: if (bits & U_ORIGIN3)
625: MSG_WriteCoord (msg, to->origin[2]);
1.1.1.2 ! root 626:
1.1 root 627: if (bits & U_ANGLE1)
628: MSG_WriteAngle(msg, to->angles[0]);
629: if (bits & U_ANGLE2)
630: MSG_WriteAngle(msg, to->angles[1]);
631: if (bits & U_ANGLE3)
632: MSG_WriteAngle(msg, to->angles[2]);
1.1.1.2 ! root 633:
1.1 root 634: if (bits & U_OLDORIGIN)
635: {
636: MSG_WriteCoord (msg, to->old_origin[0]);
637: MSG_WriteCoord (msg, to->old_origin[1]);
638: MSG_WriteCoord (msg, to->old_origin[2]);
639: }
1.1.1.2 ! root 640:
1.1 root 641: if (bits & U_SOUND)
642: MSG_WriteByte (msg, to->sound);
643: if (bits & U_EVENT)
644: MSG_WriteByte (msg, to->event);
645: if (bits & U_SOLID)
646: MSG_WriteShort (msg, to->solid);
647: }
1.1.1.2 ! root 648:
! 649:
1.1 root 650: //============================================================
1.1.1.2 ! root 651:
1.1 root 652: //
653: // reading functions
654: //
1.1.1.2 ! root 655:
1.1 root 656: void MSG_BeginReading (sizebuf_t *msg)
657: {
658: msg->readcount = 0;
659: }
1.1.1.2 ! root 660:
1.1 root 661: // returns -1 if no more characters are available
662: int MSG_ReadChar (sizebuf_t *msg_read)
663: {
664: int c;
665:
666: if (msg_read->readcount+1 > msg_read->cursize)
667: c = -1;
668: else
669: c = (signed char)msg_read->data[msg_read->readcount];
670: msg_read->readcount++;
671:
672: return c;
673: }
1.1.1.2 ! root 674:
1.1 root 675: int MSG_ReadByte (sizebuf_t *msg_read)
676: {
677: int c;
678:
679: if (msg_read->readcount+1 > msg_read->cursize)
680: c = -1;
681: else
682: c = (unsigned char)msg_read->data[msg_read->readcount];
683: msg_read->readcount++;
684:
685: return c;
686: }
1.1.1.2 ! root 687:
1.1 root 688: int MSG_ReadShort (sizebuf_t *msg_read)
689: {
690: int c;
691:
692: if (msg_read->readcount+2 > msg_read->cursize)
693: c = -1;
694: else
695: c = (short)(msg_read->data[msg_read->readcount]
696: + (msg_read->data[msg_read->readcount+1]<<8));
697:
698: msg_read->readcount += 2;
699:
700: return c;
701: }
1.1.1.2 ! root 702:
1.1 root 703: int MSG_ReadLong (sizebuf_t *msg_read)
704: {
705: int c;
706:
707: if (msg_read->readcount+4 > msg_read->cursize)
708: c = -1;
709: else
710: c = msg_read->data[msg_read->readcount]
711: + (msg_read->data[msg_read->readcount+1]<<8)
712: + (msg_read->data[msg_read->readcount+2]<<16)
713: + (msg_read->data[msg_read->readcount+3]<<24);
714:
715: msg_read->readcount += 4;
716:
717: return c;
718: }
1.1.1.2 ! root 719:
1.1 root 720: float MSG_ReadFloat (sizebuf_t *msg_read)
721: {
722: union
723: {
724: byte b[4];
725: float f;
726: int l;
727: } dat;
728:
729: if (msg_read->readcount+4 > msg_read->cursize)
730: dat.f = -1;
731: else
732: {
733: dat.b[0] = msg_read->data[msg_read->readcount];
734: dat.b[1] = msg_read->data[msg_read->readcount+1];
735: dat.b[2] = msg_read->data[msg_read->readcount+2];
736: dat.b[3] = msg_read->data[msg_read->readcount+3];
737: }
738: msg_read->readcount += 4;
739:
740: dat.l = LittleLong (dat.l);
1.1.1.2 ! root 741:
1.1 root 742: return dat.f;
743: }
1.1.1.2 ! root 744:
1.1 root 745: char *MSG_ReadString (sizebuf_t *msg_read)
746: {
747: static char string[2048];
748: int l,c;
749:
750: l = 0;
751: do
752: {
753: c = MSG_ReadChar (msg_read);
754: if (c == -1 || c == 0)
755: break;
756: string[l] = c;
757: l++;
758: } while (l < sizeof(string)-1);
759:
760: string[l] = 0;
761:
762: return string;
763: }
1.1.1.2 ! root 764:
1.1 root 765: char *MSG_ReadStringLine (sizebuf_t *msg_read)
766: {
767: static char string[2048];
768: int l,c;
769:
770: l = 0;
771: do
772: {
773: c = MSG_ReadChar (msg_read);
774: if (c == -1 || c == 0 || c == '\n')
775: break;
776: string[l] = c;
777: l++;
778: } while (l < sizeof(string)-1);
779:
780: string[l] = 0;
781:
782: return string;
783: }
1.1.1.2 ! root 784:
1.1 root 785: float MSG_ReadCoord (sizebuf_t *msg_read)
786: {
787: return MSG_ReadShort(msg_read) * (1.0/8);
788: }
1.1.1.2 ! root 789:
1.1 root 790: void MSG_ReadPos (sizebuf_t *msg_read, vec3_t pos)
791: {
792: pos[0] = MSG_ReadShort(msg_read) * (1.0/8);
793: pos[1] = MSG_ReadShort(msg_read) * (1.0/8);
794: pos[2] = MSG_ReadShort(msg_read) * (1.0/8);
795: }
1.1.1.2 ! root 796:
1.1 root 797: float MSG_ReadAngle (sizebuf_t *msg_read)
798: {
799: return MSG_ReadChar(msg_read) * (360.0/256);
800: }
1.1.1.2 ! root 801:
1.1 root 802: float MSG_ReadAngle16 (sizebuf_t *msg_read)
803: {
804: return SHORT2ANGLE(MSG_ReadShort(msg_read));
805: }
1.1.1.2 ! root 806:
1.1 root 807: void MSG_ReadDeltaUsercmd (sizebuf_t *msg_read, usercmd_t *from, usercmd_t *move)
808: {
809: int bits;
1.1.1.2 ! root 810:
1.1 root 811: memcpy (move, from, sizeof(*move));
1.1.1.2 ! root 812:
1.1 root 813: bits = MSG_ReadByte (msg_read);
814:
815: // read current angles
816: if (bits & CM_ANGLE1)
817: move->angles[0] = MSG_ReadShort (msg_read);
818: if (bits & CM_ANGLE2)
819: move->angles[1] = MSG_ReadShort (msg_read);
820: if (bits & CM_ANGLE3)
821: move->angles[2] = MSG_ReadShort (msg_read);
822:
823: // read movement
824: if (bits & CM_FORWARD)
825: move->forwardmove = MSG_ReadShort (msg_read);
826: if (bits & CM_SIDE)
827: move->sidemove = MSG_ReadShort (msg_read);
828: if (bits & CM_UP)
829: move->upmove = MSG_ReadShort (msg_read);
830:
831: // read buttons
832: if (bits & CM_BUTTONS)
833: move->buttons = MSG_ReadByte (msg_read);
1.1.1.2 ! root 834:
1.1 root 835: if (bits & CM_IMPULSE)
836: move->impulse = MSG_ReadByte (msg_read);
1.1.1.2 ! root 837:
1.1 root 838: // read time to run command
839: move->msec = MSG_ReadByte (msg_read);
1.1.1.2 ! root 840:
1.1 root 841: // read the light level
842: move->lightlevel = MSG_ReadByte (msg_read);
843: }
1.1.1.2 ! root 844:
! 845:
1.1 root 846: void MSG_ReadData (sizebuf_t *msg_read, void *data, int len)
847: {
848: int i;
1.1.1.2 ! root 849:
1.1 root 850: for (i=0 ; i<len ; i++)
851: ((byte *)data)[i] = MSG_ReadByte (msg_read);
852: }
1.1.1.2 ! root 853:
! 854:
1.1 root 855: //===========================================================================
1.1.1.2 ! root 856:
1.1 root 857: void SZ_Init (sizebuf_t *buf, byte *data, int length)
858: {
859: memset (buf, 0, sizeof(*buf));
860: buf->data = data;
861: buf->maxsize = length;
862: }
1.1.1.2 ! root 863:
1.1 root 864: void SZ_Clear (sizebuf_t *buf)
865: {
866: buf->cursize = 0;
867: buf->overflowed = false;
868: }
1.1.1.2 ! root 869:
1.1 root 870: void *SZ_GetSpace (sizebuf_t *buf, int length)
871: {
872: void *data;
873:
874: if (buf->cursize + length > buf->maxsize)
875: {
876: if (!buf->allowoverflow)
877: Com_Error (ERR_FATAL, "SZ_GetSpace: overflow without allowoverflow set");
878:
879: if (length > buf->maxsize)
880: Com_Error (ERR_FATAL, "SZ_GetSpace: %i is > full buffer size", length);
881:
882: Com_Printf ("SZ_GetSpace: overflow\n");
883: SZ_Clear (buf);
884: buf->overflowed = true;
885: }
1.1.1.2 ! root 886:
1.1 root 887: data = buf->data + buf->cursize;
888: buf->cursize += length;
889:
890: return data;
891: }
1.1.1.2 ! root 892:
1.1 root 893: void SZ_Write (sizebuf_t *buf, void *data, int length)
894: {
895: memcpy (SZ_GetSpace(buf,length),data,length);
896: }
1.1.1.2 ! root 897:
1.1 root 898: void SZ_Print (sizebuf_t *buf, char *data)
899: {
900: int len;
901:
902: len = strlen(data)+1;
1.1.1.2 ! root 903:
1.1 root 904: if (buf->cursize)
905: {
906: if (buf->data[buf->cursize-1])
907: memcpy ((byte *)SZ_GetSpace(buf, len),data,len); // no trailing 0
908: else
909: memcpy ((byte *)SZ_GetSpace(buf, len-1)-1,data,len); // write over trailing 0
910: }
911: else
912: memcpy ((byte *)SZ_GetSpace(buf, len),data,len);
913: }
1.1.1.2 ! root 914:
! 915:
1.1 root 916: //============================================================================
1.1.1.2 ! root 917:
! 918:
1.1 root 919: /*
920: ================
921: COM_CheckParm
1.1.1.2 ! root 922:
1.1 root 923: Returns the position (1 to argc-1) in the program's argument list
924: where the given parameter apears, or 0 if not present
925: ================
926: */
927: int COM_CheckParm (char *parm)
928: {
929: int i;
930:
931: for (i=1 ; i<com_argc ; i++)
932: {
933: if (!strcmp (parm,com_argv[i]))
934: return i;
935: }
936:
937: return 0;
938: }
1.1.1.2 ! root 939:
1.1 root 940: int COM_Argc (void)
941: {
942: return com_argc;
943: }
1.1.1.2 ! root 944:
1.1 root 945: char *COM_Argv (int arg)
946: {
947: if (arg < 0 || arg >= com_argc || !com_argv[arg])
948: return "";
949: return com_argv[arg];
950: }
1.1.1.2 ! root 951:
1.1 root 952: void COM_ClearArgv (int arg)
953: {
954: if (arg < 0 || arg >= com_argc || !com_argv[arg])
955: return;
956: com_argv[arg] = "";
957: }
1.1.1.2 ! root 958:
! 959:
1.1 root 960: /*
961: ================
962: COM_InitArgv
963: ================
964: */
965: void COM_InitArgv (int argc, char **argv)
966: {
967: int i;
1.1.1.2 ! root 968:
1.1 root 969: if (argc > MAX_NUM_ARGVS)
970: Com_Error (ERR_FATAL, "argc > MAX_NUM_ARGVS");
971: com_argc = argc;
972: for (i=0 ; i<argc ; i++)
973: {
974: if (!argv[i] || strlen(argv[i]) >= MAX_TOKEN_CHARS )
975: com_argv[i] = "";
976: else
977: com_argv[i] = argv[i];
978: }
979: }
1.1.1.2 ! root 980:
1.1 root 981: /*
982: ================
983: COM_AddParm
1.1.1.2 ! root 984:
1.1 root 985: Adds the given string at the end of the current argument list
986: ================
987: */
988: void COM_AddParm (char *parm)
989: {
990: if (com_argc == MAX_NUM_ARGVS)
991: Com_Error (ERR_FATAL, "COM_AddParm: MAX_NUM)ARGS");
992: com_argv[com_argc++] = parm;
993: }
1.1.1.2 ! root 994:
! 995:
! 996:
! 997:
1.1 root 998: /// just for debugging
999: int memsearch (byte *start, int count, int search)
1000: {
1001: int i;
1002:
1003: for (i=0 ; i<count ; i++)
1004: if (start[i] == search)
1005: return i;
1006: return -1;
1007: }
1.1.1.2 ! root 1008:
! 1009:
1.1 root 1010: char *CopyString (char *in)
1011: {
1012: char *out;
1013:
1014: out = Z_Malloc (strlen(in)+1);
1015: strcpy (out, in);
1016: return out;
1017: }
1.1.1.2 ! root 1018:
! 1019:
! 1020:
1.1 root 1021: void Info_Print (char *s)
1022: {
1023: char key[512];
1024: char value[512];
1025: char *o;
1026: int l;
1.1.1.2 ! root 1027:
1.1 root 1028: if (*s == '\\')
1029: s++;
1030: while (*s)
1031: {
1032: o = key;
1033: while (*s && *s != '\\')
1034: *o++ = *s++;
1.1.1.2 ! root 1035:
1.1 root 1036: l = o - key;
1037: if (l < 20)
1038: {
1039: memset (o, ' ', 20-l);
1040: key[20] = 0;
1041: }
1042: else
1043: *o = 0;
1044: Com_Printf ("%s", key);
1.1.1.2 ! root 1045:
1.1 root 1046: if (!*s)
1047: {
1048: Com_Printf ("MISSING VALUE\n");
1049: return;
1050: }
1.1.1.2 ! root 1051:
1.1 root 1052: o = value;
1053: s++;
1054: while (*s && *s != '\\')
1055: *o++ = *s++;
1056: *o = 0;
1.1.1.2 ! root 1057:
1.1 root 1058: if (*s)
1059: s++;
1060: Com_Printf ("%s\n", value);
1061: }
1062: }
1.1.1.2 ! root 1063:
! 1064:
1.1 root 1065: /*
1066: ==============================================================================
1.1.1.2 ! root 1067:
1.1 root 1068: ZONE MEMORY ALLOCATION
1.1.1.2 ! root 1069:
1.1 root 1070: just cleared malloc with counters now...
1.1.1.2 ! root 1071:
1.1 root 1072: ==============================================================================
1073: */
1.1.1.2 ! root 1074:
1.1 root 1075: #define Z_MAGIC 0x1d1d
1.1.1.2 ! root 1076:
! 1077:
1.1 root 1078: typedef struct zhead_s
1079: {
1080: struct zhead_s *prev, *next;
1081: short magic;
1082: short tag; // for group free
1083: int size;
1084: } zhead_t;
1.1.1.2 ! root 1085:
1.1 root 1086: zhead_t z_chain;
1087: int z_count, z_bytes;
1.1.1.2 ! root 1088:
1.1 root 1089: /*
1090: ========================
1091: Z_Free
1092: ========================
1093: */
1094: void Z_Free (void *ptr)
1095: {
1096: zhead_t *z;
1.1.1.2 ! root 1097:
1.1 root 1098: z = ((zhead_t *)ptr) - 1;
1.1.1.2 ! root 1099:
1.1 root 1100: if (z->magic != Z_MAGIC)
1101: Com_Error (ERR_FATAL, "Z_Free: bad magic");
1.1.1.2 ! root 1102:
1.1 root 1103: z->prev->next = z->next;
1104: z->next->prev = z->prev;
1.1.1.2 ! root 1105:
1.1 root 1106: z_count--;
1107: z_bytes -= z->size;
1108: free (z);
1109: }
1.1.1.2 ! root 1110:
! 1111:
1.1 root 1112: /*
1113: ========================
1114: Z_Stats_f
1115: ========================
1116: */
1117: void Z_Stats_f (void)
1118: {
1119: Com_Printf ("%i bytes in %i blocks\n", z_bytes, z_count);
1120: }
1.1.1.2 ! root 1121:
1.1 root 1122: /*
1123: ========================
1124: Z_FreeTags
1125: ========================
1126: */
1127: void Z_FreeTags (int tag)
1128: {
1129: zhead_t *z, *next;
1.1.1.2 ! root 1130:
1.1 root 1131: for (z=z_chain.next ; z != &z_chain ; z=next)
1132: {
1133: next = z->next;
1134: if (z->tag == tag)
1135: Z_Free ((void *)(z+1));
1136: }
1137: }
1.1.1.2 ! root 1138:
1.1 root 1139: /*
1140: ========================
1141: Z_TagMalloc
1142: ========================
1143: */
1144: void *Z_TagMalloc (int size, int tag)
1145: {
1146: zhead_t *z;
1147:
1148: size = size + sizeof(zhead_t);
1149: z = malloc(size);
1150: if (!z)
1151: Com_Error (ERR_FATAL, "Z_Malloc: failed on allocation of %i bytes",size);
1152: memset (z, 0, size);
1153: z_count++;
1154: z_bytes += size;
1155: z->magic = Z_MAGIC;
1156: z->tag = tag;
1157: z->size = size;
1.1.1.2 ! root 1158:
1.1 root 1159: z->next = z_chain.next;
1160: z->prev = &z_chain;
1161: z_chain.next->prev = z;
1162: z_chain.next = z;
1.1.1.2 ! root 1163:
1.1 root 1164: return (void *)(z+1);
1165: }
1.1.1.2 ! root 1166:
1.1 root 1167: /*
1168: ========================
1169: Z_Malloc
1170: ========================
1171: */
1172: void *Z_Malloc (int size)
1173: {
1174: return Z_TagMalloc (size, 0);
1175: }
1.1.1.2 ! root 1176:
! 1177:
1.1 root 1178: //============================================================================
1179:
1180:
1181: /*
1182: ====================
1183: COM_BlockSequenceCheckByte
1184:
1185: For proxy protecting
1.1.1.2 ! root 1186:
! 1187: // THIS IS MASSIVELY BROKEN! CHALLENGE MAY BE NEGATIVE
! 1188: // DON'T USE THIS FUNCTION!!!!!
! 1189:
1.1 root 1190: ====================
1191: */
1.1.1.2 ! root 1192: byte COM_BlockSequenceCheckByte (byte *base, int length, int sequence, int challenge)
1.1 root 1193: {
1.1.1.2 ! root 1194: Sys_Error("COM_BlockSequenceCheckByte called\n");
! 1195:
! 1196: #if 0
1.1 root 1197: int checksum;
1.1.1.2 ! root 1198: byte buf[68];
1.1 root 1199: byte *p;
1.1.1.2 ! root 1200: float temp;
! 1201: byte c;
! 1202:
! 1203: temp = bytedirs[(sequence/3) % NUMVERTEXNORMALS][sequence % 3];
! 1204: temp = LittleFloat(temp);
! 1205: p = ((byte *)&temp);
1.1 root 1206:
1207: if (length > 60)
1208: length = 60;
1209: memcpy (buf, base, length);
1210:
1.1.1.2 ! root 1211: buf[length] = (sequence & 0xff) ^ p[0];
! 1212: buf[length+1] = p[1];
! 1213: buf[length+2] = ((sequence>>8) & 0xff) ^ p[2];
! 1214: buf[length+3] = p[3];
! 1215:
! 1216: temp = bytedirs[((sequence+challenge)/3) % NUMVERTEXNORMALS][(sequence+challenge) % 3];
! 1217: temp = LittleFloat(temp);
! 1218: p = ((byte *)&temp);
! 1219:
! 1220: buf[length+4] = (sequence & 0xff) ^ p[3];
! 1221: buf[length+5] = (challenge & 0xff) ^ p[2];
! 1222: buf[length+6] = ((sequence>>8) & 0xff) ^ p[1];
! 1223: buf[length+7] = ((challenge >> 7) & 0xff) ^ p[0];
! 1224:
! 1225: length += 8;
! 1226:
! 1227: checksum = LittleLong(Com_BlockChecksum (buf, length));
1.1 root 1228:
1229: checksum &= 0xff;
1230:
1231: return checksum;
1.1.1.2 ! root 1232: #endif
! 1233: return 0;
! 1234: }
! 1235:
! 1236: static byte chktbl[1024] = {
! 1237: 0x84, 0x47, 0x51, 0xc1, 0x93, 0x22, 0x21, 0x24, 0x2f, 0x66, 0x60, 0x4d, 0xb0, 0x7c, 0xda,
! 1238: 0x88, 0x54, 0x15, 0x2b, 0xc6, 0x6c, 0x89, 0xc5, 0x9d, 0x48, 0xee, 0xe6, 0x8a, 0xb5, 0xf4,
! 1239: 0xcb, 0xfb, 0xf1, 0x0c, 0x2e, 0xa0, 0xd7, 0xc9, 0x1f, 0xd6, 0x06, 0x9a, 0x09, 0x41, 0x54,
! 1240: 0x67, 0x46, 0xc7, 0x74, 0xe3, 0xc8, 0xb6, 0x5d, 0xa6, 0x36, 0xc4, 0xab, 0x2c, 0x7e, 0x85,
! 1241: 0xa8, 0xa4, 0xa6, 0x4d, 0x96, 0x19, 0x19, 0x9a, 0xcc, 0xd8, 0xac, 0x39, 0x5e, 0x3c, 0xf2,
! 1242: 0xf5, 0x5a, 0x72, 0xe5, 0xa9, 0xd1, 0xb3, 0x23, 0x82, 0x6f, 0x29, 0xcb, 0xd1, 0xcc, 0x71,
! 1243: 0xfb, 0xea, 0x92, 0xeb, 0x1c, 0xca, 0x4c, 0x70, 0xfe, 0x4d, 0xc9, 0x67, 0x43, 0x47, 0x94,
! 1244: 0xb9, 0x47, 0xbc, 0x3f, 0x01, 0xab, 0x7b, 0xa6, 0xe2, 0x76, 0xef, 0x5a, 0x7a, 0x29, 0x0b,
! 1245: 0x51, 0x54, 0x67, 0xd8, 0x1c, 0x14, 0x3e, 0x29, 0xec, 0xe9, 0x2d, 0x48, 0x67, 0xff, 0xed,
! 1246: 0x54, 0x4f, 0x48, 0xc0, 0xaa, 0x61, 0xf7, 0x78, 0x12, 0x03, 0x7a, 0x9e, 0x8b, 0xcf, 0x83,
! 1247: 0x7b, 0xae, 0xca, 0x7b, 0xd9, 0xe9, 0x53, 0x2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0x43, 0xf2, 0xe3, 0x11, 0x7d, 0x80, 0x32, 0xc5, 0xfb, 0xc5, 0xd9, 0x27, 0xec, 0xc6,
! 1294: 0x4e, 0x65, 0x27, 0x76, 0x87, 0xa6, 0xee, 0xee, 0xd7, 0x8b, 0xd1, 0xa0, 0x5c, 0xb0, 0x42,
! 1295: 0x13, 0x0e, 0x95, 0x4a, 0xf2, 0x06, 0xc6, 0x43, 0x33, 0xf4, 0xc7, 0xf8, 0xe7, 0x1f, 0xdd,
! 1296: 0xe4, 0x46, 0x4a, 0x70, 0x39, 0x6c, 0xd0, 0xed, 0xca, 0xbe, 0x60, 0x3b, 0xd1, 0x7b, 0x57,
! 1297: 0x48, 0xe5, 0x3a, 0x79, 0xc1, 0x69, 0x33, 0x53, 0x1b, 0x80, 0xb8, 0x91, 0x7d, 0xb4, 0xf6,
! 1298: 0x17, 0x1a, 0x1d, 0x5a, 0x32, 0xd6, 0xcc, 0x71, 0x29, 0x3f, 0x28, 0xbb, 0xf3, 0x5e, 0x71,
! 1299: 0xb8, 0x43, 0xaf, 0xf8, 0xb9, 0x64, 0xef, 0xc4, 0xa5, 0x6c, 0x08, 0x53, 0xc7, 0x00, 0x10,
! 1300: 0x39, 0x4f, 0xdd, 0xe4, 0xb6, 0x19, 0x27, 0xfb, 0xb8, 0xf5, 0x32, 0x73, 0xe5, 0xcb, 0x32
! 1301: };
! 1302:
! 1303: /*
! 1304: ====================
! 1305: COM_BlockSequenceCRCByte
! 1306:
! 1307: For proxy protecting
! 1308: ====================
! 1309: */
! 1310: byte COM_BlockSequenceCRCByte (byte *base, int length, int sequence)
! 1311: {
! 1312: unsigned short crc;
! 1313: byte *p;
! 1314: byte chkb[60 + 4];
! 1315:
! 1316: if (sequence < 0)
! 1317: Sys_Error("sequence < 0, this shouldn't happen\n");
! 1318:
! 1319: p = chktbl + (sequence % (sizeof(chktbl) - 4));
! 1320:
! 1321: if (length > 60)
! 1322: length = 60;
! 1323: memcpy (chkb, base, length);
! 1324:
! 1325: chkb[length] = p[0];
! 1326: chkb[length+1] = p[1];
! 1327: chkb[length+2] = p[2];
! 1328: chkb[length+3] = p[3];
! 1329:
! 1330: length += 4;
! 1331:
! 1332: crc = CRC_Block(chkb, length);
! 1333:
! 1334: crc &= 0xff;
! 1335:
! 1336: return crc;
1.1 root 1337: }
1338:
1339: //========================================================
1.1.1.2 ! root 1340:
1.1 root 1341: float frand(void)
1342: {
1343: return (rand()&32767)* (1.0/32767);
1344: }
1.1.1.2 ! root 1345:
1.1 root 1346: float crand(void)
1347: {
1348: return (rand()&32767)* (2.0/32767) - 1;
1349: }
1.1.1.2 ! root 1350:
1.1 root 1351: void Key_Init (void);
1352: void SCR_EndLoadingPlaque (void);
1.1.1.2 ! root 1353:
1.1 root 1354: /*
1355: =============
1356: Com_Error_f
1.1.1.2 ! root 1357:
1.1 root 1358: Just throw a fatal error to
1359: test error shutdown procedures
1360: =============
1361: */
1362: void Com_Error_f (void)
1363: {
1364: Com_Error (ERR_FATAL, "%s", Cmd_Argv(1));
1365: }
1366:
1367:
1368: /*
1369: =================
1370: Qcommon_Init
1371: =================
1372: */
1373: void Qcommon_Init (int argc, char **argv)
1374: {
1375: char *s;
1.1.1.2 ! root 1376:
1.1 root 1377: if (setjmp (abortframe) )
1378: Sys_Error ("Error during initialization");
1.1.1.2 ! root 1379:
1.1 root 1380: z_chain.next = z_chain.prev = &z_chain;
1.1.1.2 ! root 1381:
1.1 root 1382: // prepare enough of the subsystems to handle
1383: // cvar and command buffer management
1384: COM_InitArgv (argc, argv);
1.1.1.2 ! root 1385:
1.1 root 1386: Swap_Init ();
1387: Cbuf_Init ();
1.1.1.2 ! root 1388:
1.1 root 1389: Cmd_Init ();
1390: Cvar_Init ();
1.1.1.2 ! root 1391:
1.1 root 1392: Key_Init ();
1.1.1.2 ! root 1393:
1.1 root 1394: // we need to add the early commands twice, because
1395: // a basedir or cddir needs to be set before execing
1396: // config files, but we want other parms to override
1397: // the settings of the config files
1398: Cbuf_AddEarlyCommands (false);
1399: Cbuf_Execute ();
1.1.1.2 ! root 1400:
1.1 root 1401: FS_InitFilesystem ();
1.1.1.2 ! root 1402:
1.1 root 1403: Cbuf_AddText ("exec default.cfg\n");
1404: Cbuf_AddText ("exec config.cfg\n");
1.1.1.2 ! root 1405:
1.1 root 1406: Cbuf_AddEarlyCommands (true);
1407: Cbuf_Execute ();
1.1.1.2 ! root 1408:
1.1 root 1409: //
1410: // init commands and vars
1411: //
1412: Cmd_AddCommand ("z_stats", Z_Stats_f);
1413: Cmd_AddCommand ("error", Com_Error_f);
1.1.1.2 ! root 1414:
1.1 root 1415: host_speeds = Cvar_Get ("host_speeds", "0", 0);
1416: log_stats = Cvar_Get ("log_stats", "0", 0);
1417: developer = Cvar_Get ("developer", "0", 0);
1418: timescale = Cvar_Get ("timescale", "1", 0);
1419: fixedtime = Cvar_Get ("fixedtime", "0", 0);
1420: logfile_active = Cvar_Get ("logfile", "0", 0);
1421: showtrace = Cvar_Get ("showtrace", "0", 0);
1.1.1.2 ! root 1422: #ifdef DEDICATED_ONLY
! 1423: dedicated = Cvar_Get ("dedicated", "1", CVAR_NOSET);
! 1424: #else
1.1 root 1425: dedicated = Cvar_Get ("dedicated", "0", CVAR_NOSET);
1.1.1.2 ! root 1426: #endif
! 1427:
1.1 root 1428: s = va("%4.2f %s %s %s", VERSION, CPUSTRING, __DATE__, BUILDSTRING);
1429: Cvar_Get ("version", s, CVAR_SERVERINFO|CVAR_NOSET);
1.1.1.2 ! root 1430:
! 1431:
1.1 root 1432: if (dedicated->value)
1433: Cmd_AddCommand ("quit", Com_Quit);
1.1.1.2 ! root 1434:
1.1 root 1435: Sys_Init ();
1.1.1.2 ! root 1436:
1.1 root 1437: NET_Init ();
1438: Netchan_Init ();
1.1.1.2 ! root 1439:
1.1 root 1440: SV_Init ();
1441: CL_Init ();
1.1.1.2 ! root 1442:
1.1 root 1443: // add + commands from command line
1444: if (!Cbuf_AddLateCommands ())
1445: { // if the user didn't give any commands, run default action
1446: if (!dedicated->value)
1447: Cbuf_AddText ("d1\n");
1448: else
1449: Cbuf_AddText ("dedicated_start\n");
1450: Cbuf_Execute ();
1451: }
1452: else
1453: { // the user asked for something explicit
1454: // so drop the loading plaque
1455: SCR_EndLoadingPlaque ();
1456: }
1.1.1.2 ! root 1457:
1.1 root 1458: Com_Printf ("====== Quake2 Initialized ======\n\n");
1459: }
1.1.1.2 ! root 1460:
1.1 root 1461: /*
1462: =================
1463: Qcommon_Frame
1464: =================
1465: */
1466: void Qcommon_Frame (int msec)
1467: {
1468: char *s;
1469: int time_before, time_between, time_after;
1.1.1.2 ! root 1470:
1.1 root 1471: if (setjmp (abortframe) )
1472: return; // an ERR_DROP was thrown
1473:
1474: if ( log_stats->modified )
1475: {
1476: log_stats->modified = false;
1477: if ( log_stats->value )
1478: {
1479: if ( log_stats_file )
1480: {
1481: fclose( log_stats_file );
1482: log_stats_file = 0;
1483: }
1484: log_stats_file = fopen( "stats.log", "w" );
1485: if ( log_stats_file )
1486: fprintf( log_stats_file, "entities,dlights,parts,frame time\n" );
1487: }
1488: else
1489: {
1490: if ( log_stats_file )
1491: {
1492: fclose( log_stats_file );
1493: log_stats_file = 0;
1494: }
1495: }
1496: }
1.1.1.2 ! root 1497:
1.1 root 1498: if (fixedtime->value)
1499: msec = fixedtime->value;
1500: else if (timescale->value)
1501: {
1502: msec *= timescale->value;
1503: if (msec < 1)
1504: msec = 1;
1505: }
1506:
1507: if (showtrace->value)
1508: {
1509: extern int c_traces, c_brush_traces;
1510: extern int c_pointcontents;
1.1.1.2 ! root 1511:
1.1 root 1512: Com_Printf ("%4i traces %4i points\n", c_traces, c_pointcontents);
1513: c_traces = 0;
1514: c_brush_traces = 0;
1515: c_pointcontents = 0;
1516: }
1.1.1.2 ! root 1517:
1.1 root 1518: do
1519: {
1520: s = Sys_ConsoleInput ();
1521: if (s)
1522: Cbuf_AddText (va("%s\n",s));
1523: } while (s);
1524: Cbuf_Execute ();
1.1.1.2 ! root 1525:
1.1 root 1526: if (host_speeds->value)
1527: time_before = Sys_Milliseconds ();
1.1.1.2 ! root 1528:
1.1 root 1529: SV_Frame (msec);
1.1.1.2 ! root 1530:
1.1 root 1531: if (host_speeds->value)
1532: time_between = Sys_Milliseconds ();
1.1.1.2 ! root 1533:
1.1 root 1534: CL_Frame (msec);
1.1.1.2 ! root 1535:
1.1 root 1536: if (host_speeds->value)
1537: time_after = Sys_Milliseconds ();
1.1.1.2 ! root 1538:
! 1539:
1.1 root 1540: if (host_speeds->value)
1541: {
1542: int all, sv, gm, cl, rf;
1.1.1.2 ! root 1543:
1.1 root 1544: all = time_after - time_before;
1545: sv = time_between - time_before;
1546: cl = time_after - time_between;
1547: gm = time_after_game - time_before_game;
1548: rf = time_after_ref - time_before_ref;
1549: sv -= gm;
1550: cl -= rf;
1551: Com_Printf ("all:%3i sv:%3i gm:%3i cl:%3i rf:%3i\n",
1552: all, sv, gm, cl, rf);
1553: }
1554: }
1.1.1.2 ! root 1555:
1.1 root 1556: /*
1557: =================
1558: Qcommon_Shutdown
1559: =================
1560: */
1561: void Qcommon_Shutdown (void)
1562: {
1563: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.