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 typedef struct sizebuf_s
36 qboolean allowoverflow; // if false, do a Sys_Error
37 qboolean overflowed; // set to true if the buffer size failed
43 void SZ_Alloc (sizebuf_t *buf, int startsize);
44 void SZ_Free (sizebuf_t *buf);
45 void SZ_Clear (sizebuf_t *buf);
46 void *SZ_GetSpace (sizebuf_t *buf, int length);
47 void SZ_Write (sizebuf_t *buf, void *data, int length);
48 void SZ_Print (sizebuf_t *buf, char *data); // strcats onto the sizebuf
50 //============================================================================
54 struct link_s *prev, *next;
58 void ClearLink (link_t *l);
59 void RemoveLink (link_t *l);
60 void InsertLinkBefore (link_t *l, link_t *before);
61 void InsertLinkAfter (link_t *l, link_t *after);
63 // (type *)STRUCT_FROM_LINK(link_t *link, type, member)
64 // ent = STRUCT_FROM_LINK(link,entity_t,order)
65 // FIXME: remove this mess!
66 #define STRUCT_FROM_LINK(l,t,m) ((t *)((byte *)l - (int)&(((t *)0)->m)))
68 //============================================================================
71 #define NULL ((void *)0)
74 #define Q_MAXCHAR ((char)0x7f)
75 #define Q_MAXSHORT ((short)0x7fff)
76 #define Q_MAXINT ((int)0x7fffffff)
77 #define Q_MAXLONG ((int)0x7fffffff)
78 #define Q_MAXFLOAT ((int)0x7fffffff)
80 #define Q_MINCHAR ((char)0x80)
81 #define Q_MINSHORT ((short)0x8000)
82 #define Q_MININT ((int)0x80000000)
83 #define Q_MINLONG ((int)0x80000000)
84 #define Q_MINFLOAT ((int)0x7fffffff)
86 //============================================================================
88 short ShortSwap (short l);
90 float FloatSwap (float f);
91 #define BigShort(l) ShortSwap(l)
92 #define LittleShort(l) (l)
93 #define BigLong(l) LongSwap(l)
94 #define LittleLong(l) (l)
95 #define BigFloat(l) FloatSwap(l)
96 #define LittleFloat(l) (l)
98 extern short (*BigShort) (short l);
99 extern short (*LittleShort) (short l);
100 extern int (*BigLong) (int l);
101 extern int (*LittleLong) (int l);
102 extern float (*BigFloat) (float l);
103 extern float (*LittleFloat) (float l);
106 //============================================================================
108 void MSG_WriteChar (sizebuf_t *sb, int c);
109 void MSG_WriteByte (sizebuf_t *sb, int c);
110 void MSG_WriteShort (sizebuf_t *sb, int c);
111 void MSG_WriteLong (sizebuf_t *sb, int c);
112 void MSG_WriteFloat (sizebuf_t *sb, float f);
113 void MSG_WriteString (sizebuf_t *sb, char *s);
114 void MSG_WriteCoord (sizebuf_t *sb, float f);
115 void MSG_WriteAngle (sizebuf_t *sb, float f);
117 extern int msg_readcount;
118 extern qboolean msg_badread; // set if a read goes beyond end of message
120 void MSG_BeginReading (void);
121 //int MSG_ReadChar (void);
122 //int MSG_ReadByte (void);
123 int MSG_ReadShort (void);
124 int MSG_ReadLong (void);
125 float MSG_ReadFloat (void);
126 char *MSG_ReadString (void);
128 #define MSG_ReadChar() (msg_readcount >= net_message.cursize ? (msg_badread = true, -1) : (signed char)net_message.data[msg_readcount++])
129 #define MSG_ReadByte() (msg_readcount >= net_message.cursize ? (msg_badread = true, -1) : (unsigned char)net_message.data[msg_readcount++])
130 //#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))
131 //#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))
133 float MSG_ReadCoord (void);
134 //float MSG_ReadAngle (void);
136 #define MSG_ReadAngle() (dpprotocol ? MSG_ReadShort() * (360.0f / 65536.0f) : MSG_ReadByte() * (360.0f / 256.0f))
138 extern qboolean dpprotocol;
140 //============================================================================
143 void Q_memset (void *dest, int fill, int count);
144 void Q_memcpy (void *dest, void *src, int count);
145 int Q_memcmp (void *m1, void *m2, int count);
146 void Q_strcpy (char *dest, char *src);
147 void Q_strncpy (char *dest, char *src, int count);
148 int Q_strlen (char *str);
149 char *Q_strrchr (char *s, char c);
150 void Q_strcat (char *dest, char *src);
151 int Q_strcmp (char *s1, char *s2);
152 int Q_strncmp (char *s1, char *s2, int count);
154 int Q_strcasecmp (char *s1, char *s2);
155 int Q_strncasecmp (char *s1, char *s2, int n);
157 int Q_atoi (char *str);
158 float Q_atof (char *str);
161 //============================================================================
163 extern char com_token[1024];
164 extern qboolean com_eof;
166 char *COM_Parse (char *data);
170 extern char **com_argv;
172 int COM_CheckParm (char *parm);
173 void COM_Init (char *path);
174 void COM_InitArgv (int argc, char **argv);
176 char *COM_SkipPath (char *pathname);
177 void COM_StripExtension (char *in, char *out);
178 void COM_FileBase (char *in, char *out);
179 void COM_DefaultExtension (char *path, char *extension);
181 char *va(char *format, ...);
182 // does a varargs printf into a temp buffer
185 //============================================================================
187 extern int com_filesize;
190 extern char com_gamedir[MAX_OSPATH];
192 void COM_WriteFile (char *filename, void *data, int len);
193 int COM_OpenFile (char *filename, int *hndl, qboolean quiet);
194 int COM_FOpenFile (char *filename, FILE **file, qboolean quiet);
195 void COM_CloseFile (int h);
197 byte *COM_LoadStackFile (char *path, void *buffer, int bufsize, qboolean quiet);
198 byte *COM_LoadTempFile (char *path, qboolean quiet);
199 byte *COM_LoadHunkFile (char *path, qboolean quiet);
200 byte *COM_LoadMallocFile (char *path, qboolean quiet);
201 void COM_LoadCacheFile (char *path, struct cache_user_s *cu, qboolean quiet);
203 byte *COM_LoadFile (char *path, int usehunk, qboolean quiet);
205 int COM_FileExists(char *filename);
207 extern struct cvar_s registered;
209 extern qboolean standard_quake, rogue, hipnotic, nehahra;