]> de.git.xonotic.org Git - xonotic/darkplaces.git/blob - common.h
Updated Transfusion map list
[xonotic/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 // LordHavoc: MSVC has a different name for snprintf
25 #ifdef WIN32
26 #define snprintf _snprintf
27 #endif
28
29 //============================================================================
30
31 typedef struct sizebuf_s
32 {
33         qboolean        allowoverflow;  // if false, do a Sys_Error
34         qboolean        overflowed;             // set to true if the buffer size failed
35         qbyte           *data;
36         mempool_t       *mempool;
37         int                     maxsize;
38         int                     cursize;
39 } sizebuf_t;
40
41 void SZ_Alloc (sizebuf_t *buf, int startsize, char *name);
42 void SZ_Free (sizebuf_t *buf);
43 void SZ_Clear (sizebuf_t *buf);
44 void *SZ_GetSpace (sizebuf_t *buf, int length);
45 void SZ_Write (sizebuf_t *buf, void *data, int length);
46 void SZ_Print (sizebuf_t *buf, char *data);     // strcats onto the sizebuf
47
48 //============================================================================
49 #if !defined(ENDIAN_LITTLE) && !defined(ENDIAN_BIG)
50 #if  defined(__i386__) || defined(__ia64__) || defined(WIN32) || (defined(__alpha__) || defined(__alpha)) || defined(__arm__) || (defined(__mips__) && defined(__MIPSEL__)) || defined(__LITTLE_ENDIAN__)
51 #define ENDIAN_LITTLE
52 #else
53 #define ENDIAN_BIG
54 #endif
55 #endif
56
57 short ShortSwap (short l);
58 int LongSwap (int l);
59 float FloatSwap (float f);
60
61 #ifdef ENDIAN_LITTLE
62 // little endian
63 #define BigShort(l) ShortSwap(l)
64 #define LittleShort(l) (l)
65 #define BigLong(l) LongSwap(l)
66 #define LittleLong(l) (l)
67 #define BigFloat(l) FloatSwap(l)
68 #define LittleFloat(l) (l)
69 #elif ENDIAN_BIG
70 // big endian
71 #define BigShort(l) (l)
72 #define LittleShort(l) ShortSwap(l)
73 #define BigLong(l) (l)
74 #define LittleLong(l) LongSwap(l)
75 #define BigFloat(l) (l)
76 #define LittleFloat(l) FloatSwap(l)
77 #else
78 // figure it out at runtime
79 extern short (*BigShort) (short l);
80 extern short (*LittleShort) (short l);
81 extern int (*BigLong) (int l);
82 extern int (*LittleLong) (int l);
83 extern float (*BigFloat) (float l);
84 extern float (*LittleFloat) (float l);
85 #endif
86
87 //============================================================================
88
89 void MSG_WriteChar (sizebuf_t *sb, int c);
90 void MSG_WriteByte (sizebuf_t *sb, int c);
91 void MSG_WriteShort (sizebuf_t *sb, int c);
92 void MSG_WriteLong (sizebuf_t *sb, int c);
93 void MSG_WriteFloat (sizebuf_t *sb, float f);
94 void MSG_WriteString (sizebuf_t *sb, char *s);
95 void MSG_WriteCoord (sizebuf_t *sb, float f);
96 void MSG_WriteAngle (sizebuf_t *sb, float f);
97 void MSG_WritePreciseAngle (sizebuf_t *sb, float f);
98 void MSG_WriteDPCoord (sizebuf_t *sb, float f);
99
100 extern  int                     msg_readcount;
101 extern  qboolean        msg_badread;            // set if a read goes beyond end of message
102
103 void MSG_BeginReading (void);
104 int MSG_ReadShort (void);
105 int MSG_ReadLong (void);
106 float MSG_ReadFloat (void);
107 char *MSG_ReadString (void);
108
109 #define MSG_ReadChar() (msg_readcount >= net_message.cursize ? (msg_badread = true, -1) : (signed char)net_message.data[msg_readcount++])
110 #define MSG_ReadByte() (msg_readcount >= net_message.cursize ? (msg_badread = true, -1) : (unsigned char)net_message.data[msg_readcount++])
111
112 float MSG_ReadCoord (void);
113
114 float MSG_ReadDPCoord (void);
115
116 #define MSG_ReadAngle() (MSG_ReadByte() * (360.0f / 256.0f))
117 #define MSG_ReadPreciseAngle() (MSG_ReadShort() * (360.0f / 65536.0f))
118
119 #define MSG_ReadVector(v) {(v)[0] = MSG_ReadCoord();(v)[1] = MSG_ReadCoord();(v)[2] = MSG_ReadCoord();}
120
121 extern int dpprotocol;
122
123 //============================================================================
124
125 int Q_strcasecmp (char *s1, char *s2);
126 int Q_strncasecmp (char *s1, char *s2, int n);
127
128 //============================================================================
129
130 extern  char            com_token[1024];
131 extern  qboolean        com_eof;
132
133 char *COM_Parse (char *data);
134
135 extern char com_basedir[MAX_OSPATH];
136 extern int com_argc;
137 extern char **com_argv;
138
139 int COM_CheckParm (char *parm);
140 void COM_Init (void);
141 void COM_InitArgv (void);
142 void COM_InitGameType (void);
143
144 char *COM_SkipPath (char *pathname);
145 void COM_StripExtension (char *in, char *out);
146 void COM_FileBase (char *in, char *out);
147 void COM_DefaultExtension (char *path, char *extension);
148
149 char    *va(char *format, ...);
150 // does a varargs printf into a temp buffer
151
152
153 //============================================================================
154
155 extern int com_filesize;
156
157 extern  char    com_gamedir[MAX_OSPATH];
158
159 qboolean COM_WriteFile (char *filename, void *data, int len);
160 int COM_FOpenFile (char *filename, QFile **file, qboolean quiet, qboolean zip);
161
162 // set by COM_LoadFile functions
163 extern int loadsize;
164 qbyte *COM_LoadFile (char *path, qboolean quiet);
165
166 int COM_FileExists(char *filename);
167
168 extern  struct cvar_s   registered;
169
170 #define GAME_NORMAL 0
171 #define GAME_HIPNOTIC 1
172 #define GAME_ROGUE 2
173 #define GAME_NEHAHRA 3
174 #define GAME_TRANSFUSION 4
175
176 extern int gamemode;
177 extern char *gamename;
178
179 // LordHavoc: useful...
180 void COM_ToLowerString(char *in, char *out);
181 void COM_ToUpperString(char *in, char *out);
182 int COM_StringBeginsWith(const char *s, const char *match);
183
184 typedef struct stringlist_s
185 {
186         struct stringlist_s *next;
187         char *text;
188 } stringlist_t;
189
190 int matchpattern(char *in, char *pattern);
191 stringlist_t *listdirectory(char *path);
192 void freedirectory(stringlist_t *list);
193
194 #endif
195