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