]> icculus.org git repositories - divverent/darkplaces.git/blob - common.h
-Added video streaming support to the new VM
[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
21 #ifndef COMMON_H
22 #define COMMON_H
23
24
25 // MSVC has a different name for several standard functions
26 #ifdef WIN32
27 # define snprintf _snprintf
28 # define vsnprintf _vsnprintf
29 # define strcasecmp stricmp
30 # define strncasecmp strnicmp
31 #endif
32
33 // Create our own define for Mac OS X
34 #if defined(__APPLE__) && defined(__MACH__)
35 # define MACOSX
36 #endif
37
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         qbyte           *data;
46         mempool_t       *mempool;
47         int                     maxsize;
48         int                     cursize;
49 } sizebuf_t;
50
51 void SZ_Alloc (sizebuf_t *buf, int startsize, const char *name);
52 void SZ_Free (sizebuf_t *buf);
53 void SZ_Clear (sizebuf_t *buf);
54 void *SZ_GetSpace (sizebuf_t *buf, int length);
55 void SZ_Write (sizebuf_t *buf, const void *data, int length);
56 void SZ_Print(sizebuf_t *buf, const char *data);        // strcats onto the sizebuf
57 void SZ_HexDumpToConsole(const sizebuf_t *buf);
58
59 void Com_HexDumpToConsole(const qbyte *data, int size);
60
61 unsigned short CRC_Block(qbyte *data, int size);
62
63
64 //============================================================================
65 //                                                      Endianess handling
66 //============================================================================
67
68 // We use BSD-style defines: BYTE_ORDER is defined to either BIG_ENDIAN or LITTLE_ENDIAN
69
70 // Initializations
71 #if !defined(BYTE_ORDER) || !defined(LITTLE_ENDIAN) || !defined(BIG_ENDIAN) || (BYTE_ORDER != LITTLE_ENDIAN && BYTE_ORDER != BIG_ENDIAN)
72 # undef BYTE_ORDER
73 # undef LITTLE_ENDIAN
74 # undef BIG_ENDIAN
75 # define LITTLE_ENDIAN 1234
76 # define BIG_ENDIAN 4321
77 #endif
78
79 // If we still don't know the CPU endianess at this point, we try to guess
80 #ifndef BYTE_ORDER
81 # if defined(WIN32)
82 #  define BYTE_ORDER LITTLE_ENDIAN
83 # else
84 #  warning "Unable to determine the CPU endianess. Defaulting to little endian"
85 #  define BYTE_ORDER LITTLE_ENDIAN
86 # endif
87 #endif
88
89
90 short ShortSwap (short l);
91 int LongSwap (int l);
92 float FloatSwap (float f);
93
94 #if BYTE_ORDER == LITTLE_ENDIAN
95 // little endian
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)
102 #else
103 // big endian
104 #define BigShort(l) (l)
105 #define LittleShort(l) ShortSwap(l)
106 #define BigLong(l) (l)
107 #define LittleLong(l) LongSwap(l)
108 #define BigFloat(l) (l)
109 #define LittleFloat(l) FloatSwap(l)
110 #endif
111
112 unsigned int BuffBigLong (const qbyte *buffer);
113 unsigned short BuffBigShort (const qbyte *buffer);
114 unsigned int BuffLittleLong (const qbyte *buffer);
115 unsigned short BuffLittleShort (const qbyte *buffer);
116
117
118 //============================================================================
119
120 void MSG_WriteChar (sizebuf_t *sb, int c);
121 void MSG_WriteByte (sizebuf_t *sb, int c);
122 void MSG_WriteShort (sizebuf_t *sb, int c);
123 void MSG_WriteLong (sizebuf_t *sb, int c);
124 void MSG_WriteFloat (sizebuf_t *sb, float f);
125 void MSG_WriteString (sizebuf_t *sb, const char *s);
126 void MSG_WriteAngle8i (sizebuf_t *sb, float f);
127 void MSG_WriteAngle16i (sizebuf_t *sb, float f);
128 void MSG_WriteAngle32f (sizebuf_t *sb, float f);
129 void MSG_WriteCoord13i (sizebuf_t *sb, float f);
130 void MSG_WriteCoord16i (sizebuf_t *sb, float f);
131 void MSG_WriteCoord32f (sizebuf_t *sb, float f);
132 void MSG_WriteCoord (sizebuf_t *sb, float f, int protocol);
133 void MSG_WriteVector (sizebuf_t *sb, float *v, int protocol);
134 void MSG_WriteAngle (sizebuf_t *sb, float f, int protocol);
135
136 extern  int                     msg_readcount;
137 extern  qboolean        msg_badread;            // set if a read goes beyond end of message
138
139 void MSG_BeginReading (void);
140 int MSG_ReadLittleShort (void);
141 int MSG_ReadBigShort (void);
142 int MSG_ReadLittleLong (void);
143 int MSG_ReadBigLong (void);
144 float MSG_ReadLittleFloat (void);
145 float MSG_ReadBigFloat (void);
146 char *MSG_ReadString (void);
147 int MSG_ReadBytes (int numbytes, unsigned char *out);
148
149 #define MSG_ReadChar() (msg_readcount >= net_message.cursize ? (msg_badread = true, -1) : (signed char)net_message.data[msg_readcount++])
150 #define MSG_ReadByte() (msg_readcount >= net_message.cursize ? (msg_badread = true, -1) : (unsigned char)net_message.data[msg_readcount++])
151 #define MSG_ReadShort MSG_ReadLittleShort
152 #define MSG_ReadLong MSG_ReadLittleLong
153 #define MSG_ReadFloat MSG_ReadLittleFloat
154
155 float MSG_ReadAngle8i (void);
156 float MSG_ReadAngle16i (void);
157 float MSG_ReadAngle32f (void);
158 float MSG_ReadCoord13i (void);
159 float MSG_ReadCoord16i (void);
160 float MSG_ReadCoord32f (void);
161 float MSG_ReadCoord (int protocol);
162 void MSG_ReadVector (float *v, int protocol);
163 float MSG_ReadAngle (int protocol);
164
165 //============================================================================
166
167 extern char com_token[1024];
168
169 int COM_ParseToken(const char **datapointer, int returnnewline);
170 int COM_ParseTokenConsole(const char **datapointer);
171
172 extern int com_argc;
173 extern const char **com_argv;
174
175 int COM_CheckParm (const char *parm);
176 void COM_Init (void);
177 void COM_InitArgv (void);
178 void COM_InitGameType (void);
179
180 char    *va(const char *format, ...);
181 // does a varargs printf into a temp buffer
182
183
184 //============================================================================
185
186 extern  struct cvar_s   registered;
187 extern  struct cvar_s   cmdline;
188
189 #define GAME_NORMAL 0
190 #define GAME_HIPNOTIC 1
191 #define GAME_ROGUE 2
192 #define GAME_NEHAHRA 3
193 #define GAME_NEXUIZ 4
194 #define GAME_TRANSFUSION 5
195 #define GAME_GOODVSBAD2 6
196 #define GAME_TEU 7
197 #define GAME_BATTLEMECH 8
198 #define GAME_ZYMOTIC 9
199 #define GAME_FNIGGIUM 10
200 #define GAME_SETHERAL 11
201 #define GAME_SOM 12
202 #define GAME_TENEBRAE 13 // full of evil hackery
203 #define GAME_NEOTERIC 14
204 #define GAME_OPENQUARTZ 15 //this game sucks
205 #define GAME_PRYDON 16
206 #define GAME_NETHERWORLD 17
207
208 extern int gamemode;
209 extern const char *gamename;
210 extern const char *gamedirname;
211 extern const char *gamescreenshotname;
212 extern char com_modname[MAX_OSPATH];
213
214 void COM_ToLowerString (const char *in, char *out, size_t size_out);
215 void COM_ToUpperString (const char *in, char *out, size_t size_out);
216 int COM_StringBeginsWith(const char *s, const char *match);
217
218 int COM_ReadAndTokenizeLine(const char **text, char **argv, int maxargc, char *tokenbuf, int tokenbufsize, const char *commentprefix);
219
220 typedef struct stringlist_s
221 {
222         struct stringlist_s *next;
223         char *text;
224 } stringlist_t;
225
226 int matchpattern(char *in, char *pattern, int caseinsensitive);
227 stringlist_t *stringlistappend(stringlist_t *current, char *text);
228 void stringlistfree(stringlist_t *current);
229 stringlist_t *stringlistsort(stringlist_t *start);
230 stringlist_t *listdirectory(char *path);
231 void freedirectory(stringlist_t *list);
232
233 char *SearchInfostring(const char *infostring, const char *key);
234
235
236 // strlcat and strlcpy, from OpenBSD
237 // Most (all?) BSDs already have them
238 #if defined(__OpenBSD__) || defined(__NetBSD__) || defined(__FreeBSD__) || defined(MACOSX)
239 # define HAVE_STRLCAT 1
240 # define HAVE_STRLCPY 1
241 #endif
242
243 #ifndef HAVE_STRLCAT
244 /*
245  * Appends src to string dst of size siz (unlike strncat, siz is the
246  * full size of dst, not space left).  At most siz-1 characters
247  * will be copied.  Always NUL terminates (unless siz <= strlen(dst)).
248  * Returns strlen(src) + MIN(siz, strlen(initial dst)).
249  * If retval >= siz, truncation occurred.
250  */
251 size_t strlcat(char *dst, const char *src, size_t siz);
252 #endif  // #ifndef HAVE_STRLCAT
253
254 #ifndef HAVE_STRLCPY
255 /*
256  * Copy src to string dst of size siz.  At most siz-1 characters
257  * will be copied.  Always NUL terminates (unless siz == 0).
258  * Returns strlen(src); if retval >= siz, truncation occurred.
259  */
260 size_t strlcpy(char *dst, const char *src, size_t siz);
261
262 #endif  // #ifndef HAVE_STRLCPY
263
264 #endif
265