common.h 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223
  1. /*
  2. Copyright (C) 1996-1997 Id Software, Inc.
  3. This program is free software; you can redistribute it and/or
  4. modify it under the terms of the GNU General Public License
  5. as published by the Free Software Foundation; either version 2
  6. of the License, or (at your option) any later version.
  7. This program is distributed in the hope that it will be useful,
  8. but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  10. See the GNU General Public License for more details.
  11. You should have received a copy of the GNU General Public License
  12. along with this program; if not, write to the Free Software
  13. Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  14. */
  15. // comndef.h -- general definitions
  16. typedef unsigned char byte;
  17. #define _DEF_BYTE_
  18. // KJB Undefined true and false defined in SciTech's DEBUG.H header
  19. #undef true
  20. #undef false
  21. typedef enum {false, true} qboolean;
  22. #define MAX_INFO_STRING 196
  23. #define MAX_SERVERINFO_STRING 512
  24. #define MAX_LOCALINFO_STRING 32768
  25. //============================================================================
  26. typedef struct sizebuf_s
  27. {
  28. qboolean allowoverflow; // if false, do a Sys_Error
  29. qboolean overflowed; // set to true if the buffer size failed
  30. byte *data;
  31. int maxsize;
  32. int cursize;
  33. } sizebuf_t;
  34. void SZ_Clear (sizebuf_t *buf);
  35. void *SZ_GetSpace (sizebuf_t *buf, int length);
  36. void SZ_Write (sizebuf_t *buf, void *data, int length);
  37. void SZ_Print (sizebuf_t *buf, char *data); // strcats onto the sizebuf
  38. //============================================================================
  39. typedef struct link_s
  40. {
  41. struct link_s *prev, *next;
  42. } link_t;
  43. void ClearLink (link_t *l);
  44. void RemoveLink (link_t *l);
  45. void InsertLinkBefore (link_t *l, link_t *before);
  46. void InsertLinkAfter (link_t *l, link_t *after);
  47. // (type *)STRUCT_FROM_LINK(link_t *link, type, member)
  48. // ent = STRUCT_FROM_LINK(link,entity_t,order)
  49. // FIXME: remove this mess!
  50. #define STRUCT_FROM_LINK(l,t,m) ((t *)((byte *)l - (int)&(((t *)0)->m)))
  51. //============================================================================
  52. #ifndef NULL
  53. #define NULL ((void *)0)
  54. #endif
  55. #define Q_MAXCHAR ((char)0x7f)
  56. #define Q_MAXSHORT ((short)0x7fff)
  57. #define Q_MAXINT ((int)0x7fffffff)
  58. #define Q_MAXLONG ((int)0x7fffffff)
  59. #define Q_MAXFLOAT ((int)0x7fffffff)
  60. #define Q_MINCHAR ((char)0x80)
  61. #define Q_MINSHORT ((short)0x8000)
  62. #define Q_MININT ((int)0x80000000)
  63. #define Q_MINLONG ((int)0x80000000)
  64. #define Q_MINFLOAT ((int)0x7fffffff)
  65. //============================================================================
  66. extern qboolean bigendien;
  67. extern short (*BigShort) (short l);
  68. extern short (*LittleShort) (short l);
  69. extern int (*BigLong) (int l);
  70. extern int (*LittleLong) (int l);
  71. extern float (*BigFloat) (float l);
  72. extern float (*LittleFloat) (float l);
  73. //============================================================================
  74. struct usercmd_s;
  75. extern struct usercmd_s nullcmd;
  76. void MSG_WriteChar (sizebuf_t *sb, int c);
  77. void MSG_WriteByte (sizebuf_t *sb, int c);
  78. void MSG_WriteShort (sizebuf_t *sb, int c);
  79. void MSG_WriteLong (sizebuf_t *sb, int c);
  80. void MSG_WriteFloat (sizebuf_t *sb, float f);
  81. void MSG_WriteString (sizebuf_t *sb, char *s);
  82. void MSG_WriteCoord (sizebuf_t *sb, float f);
  83. void MSG_WriteAngle (sizebuf_t *sb, float f);
  84. void MSG_WriteAngle16 (sizebuf_t *sb, float f);
  85. void MSG_WriteDeltaUsercmd (sizebuf_t *sb, struct usercmd_s *from, struct usercmd_s *cmd);
  86. extern int msg_readcount;
  87. extern qboolean msg_badread; // set if a read goes beyond end of message
  88. void MSG_BeginReading (void);
  89. int MSG_GetReadCount(void);
  90. int MSG_ReadChar (void);
  91. int MSG_ReadByte (void);
  92. int MSG_ReadShort (void);
  93. int MSG_ReadLong (void);
  94. float MSG_ReadFloat (void);
  95. char *MSG_ReadString (void);
  96. char *MSG_ReadStringLine (void);
  97. float MSG_ReadCoord (void);
  98. float MSG_ReadAngle (void);
  99. float MSG_ReadAngle16 (void);
  100. void MSG_ReadDeltaUsercmd (struct usercmd_s *from, struct usercmd_s *cmd);
  101. //============================================================================
  102. #define Q_memset(d, f, c) memset((d), (f), (c))
  103. #define Q_memcpy(d, s, c) memcpy((d), (s), (c))
  104. #define Q_memcmp(m1, m2, c) memcmp((m1), (m2), (c))
  105. #define Q_strcpy(d, s) strcpy((d), (s))
  106. #define Q_strncpy(d, s, n) strncpy((d), (s), (n))
  107. #define Q_strlen(s) ((int)strlen(s))
  108. #define Q_strrchr(s, c) strrchr((s), (c))
  109. #define Q_strcat(d, s) strcat((d), (s))
  110. #define Q_strcmp(s1, s2) strcmp((s1), (s2))
  111. #define Q_strncmp(s1, s2, n) strncmp((s1), (s2), (n))
  112. #ifdef _WIN32
  113. #define Q_strcasecmp(s1, s2) _stricmp((s1), (s2))
  114. #define Q_strncasecmp(s1, s2, n) _strnicmp((s1), (s2), (n))
  115. #else
  116. #define Q_strcasecmp(s1, s2) strcasecmp((s1), (s2))
  117. #define Q_strncasecmp(s1, s2, n) strncasecmp((s1), (s2), (n))
  118. #endif
  119. int Q_atoi (char *str);
  120. float Q_atof (char *str);
  121. //============================================================================
  122. extern char com_token[1024];
  123. extern qboolean com_eof;
  124. char *COM_Parse (char *data);
  125. extern int com_argc;
  126. extern char **com_argv;
  127. int COM_CheckParm (char *parm);
  128. void COM_AddParm (char *parm);
  129. void COM_Init (void);
  130. void COM_InitArgv (int argc, char **argv);
  131. char *COM_SkipPath (char *pathname);
  132. void COM_StripExtension (char *in, char *out);
  133. void COM_FileBase (char *in, char *out);
  134. void COM_DefaultExtension (char *path, char *extension);
  135. char *va(char *format, ...);
  136. // does a varargs printf into a temp buffer
  137. //============================================================================
  138. extern int com_filesize;
  139. struct cache_user_s;
  140. extern char com_gamedir[MAX_OSPATH];
  141. void COM_WriteFile (char *filename, void *data, int len);
  142. int COM_FOpenFile (char *filename, FILE **file);
  143. void COM_CloseFile (FILE *h);
  144. byte *COM_LoadStackFile (char *path, void *buffer, int bufsize);
  145. byte *COM_LoadTempFile (char *path);
  146. byte *COM_LoadHunkFile (char *path);
  147. void COM_LoadCacheFile (char *path, struct cache_user_s *cu);
  148. void COM_CreatePath (char *path);
  149. void COM_Gamedir (char *dir);
  150. extern struct cvar_s registered;
  151. extern qboolean standard_quake, rogue, hipnotic;
  152. char *Info_ValueForKey (char *s, char *key);
  153. void Info_RemoveKey (char *s, char *key);
  154. void Info_RemovePrefixedKeys (char *start, char prefix);
  155. void Info_SetValueForKey (char *s, char *key, char *value, int maxsize);
  156. void Info_SetValueForStarKey (char *s, char *key, char *value, int maxsize);
  157. void Info_Print (char *s);
  158. unsigned Com_BlockChecksum (void *buffer, int length);
  159. void Com_BlockFullChecksum (void *buffer, int len, unsigned char *outbuf);
  160. byte COM_BlockSequenceCheckByte (byte *base, int length, int sequence, unsigned mapchecksum);
  161. byte COM_BlockSequenceCRCByte (byte *base, int length, int sequence);
  162. int build_number( void );