]> icculus.org git repositories - divverent/darkplaces.git/blob - common.h
fix loading savegames
[divverent/darkplaces.git] / common.h
1 /*
2 Copyright (C) 1996-1997 Id Software, Inc.
3
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.
8
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.  
12
13 See the GNU General Public License for more details.
14
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.
18
19 */
20 // comndef.h  -- general definitions
21
22 #if !defined BYTE_DEFINED
23 typedef unsigned char           byte;
24 #define BYTE_DEFINED 1
25 #endif
26
27 #undef true
28 #undef false
29
30 typedef enum {false, true}      qboolean;
31
32 #include "quakeio.h"
33
34 //============================================================================
35
36 extern void *qmalloc(unsigned int size);
37 extern void qfree(void *mem);
38
39 //============================================================================
40
41 typedef struct sizebuf_s
42 {
43         qboolean        allowoverflow;  // if false, do a Sys_Error
44         qboolean        overflowed;             // set to true if the buffer size failed
45         byte    *data;
46         int             maxsize;
47         int             cursize;
48 } sizebuf_t;
49
50 void SZ_Alloc (sizebuf_t *buf, int startsize);
51 void SZ_Free (sizebuf_t *buf);
52 void SZ_Clear (sizebuf_t *buf);
53 void *SZ_GetSpace (sizebuf_t *buf, int length);
54 void SZ_Write (sizebuf_t *buf, void *data, int length);
55 void SZ_Print (sizebuf_t *buf, char *data);     // strcats onto the sizebuf
56
57 //============================================================================
58
59 typedef struct link_s
60 {
61         struct link_s   *prev, *next;
62 } link_t;
63
64
65 void ClearLink (link_t *l);
66 void RemoveLink (link_t *l);
67 void InsertLinkBefore (link_t *l, link_t *before);
68 void InsertLinkAfter (link_t *l, link_t *after);
69
70 // (type *)STRUCT_FROM_LINK(link_t *link, type, member)
71 // ent = STRUCT_FROM_LINK(link,entity_t,order)
72 // FIXME: remove this mess!
73 #define STRUCT_FROM_LINK(l,t,m) ((t *)((byte *)l - (int)&(((t *)0)->m)))
74
75 //============================================================================
76
77 #ifndef NULL
78 #define NULL ((void *)0)
79 #endif
80
81 #define Q_MAXCHAR ((char)0x7f)
82 #define Q_MAXSHORT ((short)0x7fff)
83 #define Q_MAXINT        ((int)0x7fffffff)
84 #define Q_MAXLONG ((int)0x7fffffff)
85 #define Q_MAXFLOAT ((int)0x7fffffff)
86
87 #define Q_MINCHAR ((char)0x80)
88 #define Q_MINSHORT ((short)0x8000)
89 #define Q_MININT        ((int)0x80000000)
90 #define Q_MINLONG ((int)0x80000000)
91 #define Q_MINFLOAT ((int)0x7fffffff)
92
93 //============================================================================
94 #ifdef WIN32
95 short   ShortSwap (short l);
96 int    LongSwap (int l);
97 float FloatSwap (float f);
98 #define BigShort(l) ShortSwap(l)
99 #define LittleShort(l) (l)
100 #define BigLong(l) LongSwap(l)
101 #define LittleLong(l) (l)
102 #define BigFloat(l) FloatSwap(l)
103 #define LittleFloat(l) (l)
104 #else
105 extern  short   (*BigShort) (short l);
106 extern  short   (*LittleShort) (short l);
107 extern  int     (*BigLong) (int l);
108 extern  int     (*LittleLong) (int l);
109 extern  float   (*BigFloat) (float l);
110 extern  float   (*LittleFloat) (float l);
111 #endif
112
113 //============================================================================
114
115 void MSG_WriteChar (sizebuf_t *sb, int c);
116 void MSG_WriteByte (sizebuf_t *sb, int c);
117 void MSG_WriteShort (sizebuf_t *sb, int c);
118 void MSG_WriteLong (sizebuf_t *sb, int c);
119 void MSG_WriteFloat (sizebuf_t *sb, float f);
120 void MSG_WriteString (sizebuf_t *sb, char *s);
121 void MSG_WriteCoord (sizebuf_t *sb, float f);
122 void MSG_WriteAngle (sizebuf_t *sb, float f);
123 void MSG_WritePreciseAngle (sizebuf_t *sb, float f);
124
125 #define MSG_WriteFloatCoord MSG_WriteFloat
126
127 extern  int                     msg_readcount;
128 extern  qboolean        msg_badread;            // set if a read goes beyond end of message
129
130 void MSG_BeginReading (void);
131 //int MSG_ReadChar (void);
132 //int MSG_ReadByte (void);
133 int MSG_ReadShort (void);
134 int MSG_ReadLong (void);
135 float MSG_ReadFloat (void);
136 char *MSG_ReadString (void);
137
138 #define MSG_ReadChar() (msg_readcount >= net_message.cursize ? (msg_badread = true, -1) : (signed char)net_message.data[msg_readcount++])
139 #define MSG_ReadByte() (msg_readcount >= net_message.cursize ? (msg_badread = true, -1) : (unsigned char)net_message.data[msg_readcount++])
140 //#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))
141 //#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))
142
143 float MSG_ReadCoord (void);
144 //float MSG_ReadAngle (void);
145
146 #define MSG_ReadFloatCoord MSG_ReadFloat
147
148 #define MSG_ReadAngle() (MSG_ReadByte() * (360.0f / 256.0f))
149 #define MSG_ReadPreciseAngle() (MSG_ReadShort() * (360.0f / 65536.0f))
150
151 #define MSG_ReadVector(v) {(v)[0] = MSG_ReadCoord();(v)[1] = MSG_ReadCoord();(v)[2] = MSG_ReadCoord();}
152
153 extern qboolean dpprotocol;
154
155 //============================================================================
156
157 /*
158 void Q_memset (void *dest, int fill, int count);
159 void Q_memcpy (void *dest, void *src, int count);
160 int Q_memcmp (void *m1, void *m2, int count);
161 void Q_strcpy (char *dest, char *src);
162 void Q_strncpy (char *dest, char *src, int count);
163 int Q_strlen (char *str);
164 char *Q_strrchr (char *s, char c);
165 void Q_strcat (char *dest, char *src);
166 int Q_strcmp (char *s1, char *s2);
167 int Q_strncmp (char *s1, char *s2, int count);
168 */
169 int Q_strcasecmp (char *s1, char *s2);
170 int Q_strncasecmp (char *s1, char *s2, int n);
171 /*
172 int     Q_atoi (char *str);
173 float Q_atof (char *str);
174 */
175
176 //============================================================================
177
178 extern  char            com_token[1024];
179 extern  qboolean        com_eof;
180
181 char *COM_Parse (char *data);
182
183
184 extern  int             com_argc;
185 extern  char    **com_argv;
186
187 int COM_CheckParm (char *parm);
188 void COM_Init (char *path);
189 void COM_InitArgv (int argc, char **argv);
190
191 char *COM_SkipPath (char *pathname);
192 void COM_StripExtension (char *in, char *out);
193 void COM_FileBase (char *in, char *out);
194 void COM_DefaultExtension (char *path, char *extension);
195
196 char    *va(char *format, ...);
197 // does a varargs printf into a temp buffer
198
199
200 //============================================================================
201
202 extern int com_filesize;
203 struct cache_user_s;
204
205 extern  char    com_gamedir[MAX_OSPATH];
206
207 void COM_WriteFile (char *filename, void *data, int len);
208 int COM_FOpenFile (char *filename, QFile **file, qboolean quiet, qboolean zip);
209
210 // set by COM_LoadFile functions
211 extern int loadsize;
212 byte *COM_LoadHunkFile (char *path, qboolean quiet);
213 byte *COM_LoadMallocFile (char *path, qboolean quiet);
214 //void COM_LoadCacheFile (char *path, struct cache_user_s *cu, qboolean quiet);
215
216 byte *COM_LoadFile (char *path, int usehunk, qboolean quiet);
217
218 int COM_FileExists(char *filename);
219
220 extern  struct cvar_s   registered;
221
222 extern qboolean         standard_quake, rogue, hipnotic, nehahra;
223
224 // LordHavoc: useful...
225 extern void COM_ToLowerString(char *in, char *out);
226 extern void COM_ToUpperString(char *in, char *out);