2 Copyright (C) 1996-1997 Id Software, Inc.
4 This program is free software; you can redistribute it and/or
5 modify it under the terms of the GNU General Public License
6 as published by the Free Software Foundation; either version 2
7 of the License, or (at your option) any later version.
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
13 See the GNU General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the Free Software
17 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
20 // comndef.h -- general definitions
22 #if !defined BYTE_DEFINED
23 typedef unsigned char byte;
24 #define BYTE_DEFINED 1
30 typedef enum {false, true} qboolean;
32 //============================================================================
34 extern void *qmalloc(unsigned int size);
35 extern void qfree(void *mem);
37 //============================================================================
39 typedef struct sizebuf_s
41 qboolean allowoverflow; // if false, do a Sys_Error
42 qboolean overflowed; // set to true if the buffer size failed
48 void SZ_Alloc (sizebuf_t *buf, int startsize);
49 void SZ_Free (sizebuf_t *buf);
50 void SZ_Clear (sizebuf_t *buf);
51 void *SZ_GetSpace (sizebuf_t *buf, int length);
52 void SZ_Write (sizebuf_t *buf, void *data, int length);
53 void SZ_Print (sizebuf_t *buf, char *data); // strcats onto the sizebuf
55 //============================================================================
59 struct link_s *prev, *next;
63 void ClearLink (link_t *l);
64 void RemoveLink (link_t *l);
65 void InsertLinkBefore (link_t *l, link_t *before);
66 void InsertLinkAfter (link_t *l, link_t *after);
68 // (type *)STRUCT_FROM_LINK(link_t *link, type, member)
69 // ent = STRUCT_FROM_LINK(link,entity_t,order)
70 // FIXME: remove this mess!
71 #define STRUCT_FROM_LINK(l,t,m) ((t *)((byte *)l - (int)&(((t *)0)->m)))
73 //============================================================================
76 #define NULL ((void *)0)
79 #define Q_MAXCHAR ((char)0x7f)
80 #define Q_MAXSHORT ((short)0x7fff)
81 #define Q_MAXINT ((int)0x7fffffff)
82 #define Q_MAXLONG ((int)0x7fffffff)
83 #define Q_MAXFLOAT ((int)0x7fffffff)
85 #define Q_MINCHAR ((char)0x80)
86 #define Q_MINSHORT ((short)0x8000)
87 #define Q_MININT ((int)0x80000000)
88 #define Q_MINLONG ((int)0x80000000)
89 #define Q_MINFLOAT ((int)0x7fffffff)
91 //============================================================================
93 short ShortSwap (short l);
95 float FloatSwap (float f);
96 #define BigShort(l) ShortSwap(l)
97 #define LittleShort(l) (l)
98 #define BigLong(l) LongSwap(l)
99 #define LittleLong(l) (l)
100 #define BigFloat(l) FloatSwap(l)
101 #define LittleFloat(l) (l)
103 extern short (*BigShort) (short l);
104 extern short (*LittleShort) (short l);
105 extern int (*BigLong) (int l);
106 extern int (*LittleLong) (int l);
107 extern float (*BigFloat) (float l);
108 extern float (*LittleFloat) (float l);
111 //============================================================================
113 void MSG_WriteChar (sizebuf_t *sb, int c);
114 void MSG_WriteByte (sizebuf_t *sb, int c);
115 void MSG_WriteShort (sizebuf_t *sb, int c);
116 void MSG_WriteLong (sizebuf_t *sb, int c);
117 void MSG_WriteFloat (sizebuf_t *sb, float f);
118 void MSG_WriteString (sizebuf_t *sb, char *s);
119 void MSG_WriteCoord (sizebuf_t *sb, float f);
120 void MSG_WriteAngle (sizebuf_t *sb, float f);
121 void MSG_WritePreciseAngle (sizebuf_t *sb, float f);
123 extern int msg_readcount;
124 extern qboolean msg_badread; // set if a read goes beyond end of message
126 void MSG_BeginReading (void);
127 //int MSG_ReadChar (void);
128 //int MSG_ReadByte (void);
129 int MSG_ReadShort (void);
130 int MSG_ReadLong (void);
131 float MSG_ReadFloat (void);
132 char *MSG_ReadString (void);
134 #define MSG_ReadChar() (msg_readcount >= net_message.cursize ? (msg_badread = true, -1) : (signed char)net_message.data[msg_readcount++])
135 #define MSG_ReadByte() (msg_readcount >= net_message.cursize ? (msg_badread = true, -1) : (unsigned char)net_message.data[msg_readcount++])
136 //#define MSG_ReadShort() ((msg_readcount + 2) > net_message.cursize ? (msg_badread = true, -1) : (short)net_message.data[msg_readcount+=2, msg_readcount-2] | (net_message.data[msg_readcount-1] << 8))
137 //#define MSG_ReadLong() ((msg_readcount + 4) > net_message.cursize ? (msg_badread = true, -1) : (int)net_message.data[msg_readcount+=4, msg_readcount-4] | (net_message.data[msg_readcount-3] << 8) | (net_message.data[msg_readcount-2] << 16) | (net_message.data[msg_readcount-1] << 24))
139 float MSG_ReadCoord (void);
140 //float MSG_ReadAngle (void);
142 #define MSG_ReadAngle() (MSG_ReadByte() * (360.0f / 256.0f))
143 #define MSG_ReadPreciseAngle() (MSG_ReadShort() * (360.0f / 65536.0f))
145 extern qboolean dpprotocol;
147 //============================================================================
150 void Q_memset (void *dest, int fill, int count);
151 void Q_memcpy (void *dest, void *src, int count);
152 int Q_memcmp (void *m1, void *m2, int count);
153 void Q_strcpy (char *dest, char *src);
154 void Q_strncpy (char *dest, char *src, int count);
155 int Q_strlen (char *str);
156 char *Q_strrchr (char *s, char c);
157 void Q_strcat (char *dest, char *src);
158 int Q_strcmp (char *s1, char *s2);
159 int Q_strncmp (char *s1, char *s2, int count);
161 int Q_strcasecmp (char *s1, char *s2);
162 int Q_strncasecmp (char *s1, char *s2, int n);
164 int Q_atoi (char *str);
165 float Q_atof (char *str);
168 //============================================================================
170 extern char com_token[1024];
171 extern qboolean com_eof;
173 char *COM_Parse (char *data);
177 extern char **com_argv;
179 int COM_CheckParm (char *parm);
180 void COM_Init (char *path);
181 void COM_InitArgv (int argc, char **argv);
183 char *COM_SkipPath (char *pathname);
184 void COM_StripExtension (char *in, char *out);
185 void COM_FileBase (char *in, char *out);
186 void COM_DefaultExtension (char *path, char *extension);
188 char *va(char *format, ...);
189 // does a varargs printf into a temp buffer
192 //============================================================================
194 extern int com_filesize;
197 extern char com_gamedir[MAX_OSPATH];
199 void COM_WriteFile (char *filename, void *data, int len);
200 int COM_OpenFile (char *filename, int *hndl, qboolean quiet);
201 int COM_FOpenFile (char *filename, FILE **file, qboolean quiet);
202 void COM_CloseFile (int h);
204 byte *COM_LoadHunkFile (char *path, qboolean quiet);
205 byte *COM_LoadMallocFile (char *path, qboolean quiet);
206 void COM_LoadCacheFile (char *path, struct cache_user_s *cu, qboolean quiet);
208 byte *COM_LoadFile (char *path, int usehunk, qboolean quiet);
210 int COM_FileExists(char *filename);
212 extern struct cvar_s registered;
214 extern qboolean standard_quake, rogue, hipnotic, nehahra;