]> icculus.org git repositories - divverent/darkplaces.git/blob - common.h
added R_TextureHasAlpha function to check if a loaded texture has alpha
[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 // LordHavoc: MSVC has a different name for snprintf
35 #ifdef WIN32
36 #define snprintf _snprintf
37 #endif
38
39 //============================================================================
40
41 extern void *qmalloc(unsigned int size);
42 extern void qfree(void *mem);
43
44 //============================================================================
45
46 typedef struct sizebuf_s
47 {
48         qboolean        allowoverflow;  // if false, do a Sys_Error
49         qboolean        overflowed;             // set to true if the buffer size failed
50         byte    *data;
51         int             maxsize;
52         int             cursize;
53 } sizebuf_t;
54
55 void SZ_Alloc (sizebuf_t *buf, int startsize);
56 void SZ_Free (sizebuf_t *buf);
57 void SZ_Clear (sizebuf_t *buf);
58 void *SZ_GetSpace (sizebuf_t *buf, int length);
59 void SZ_Write (sizebuf_t *buf, void *data, int length);
60 void SZ_Print (sizebuf_t *buf, char *data);     // strcats onto the sizebuf
61
62 //============================================================================
63
64 #ifndef NULL
65 #define NULL ((void *)0)
66 #endif
67
68 //============================================================================
69 #if !defined(ENDIAN_LITTLE) && !defined(ENDIAN_BIG)
70 #if  defined(__i386__) || defined(__ia64__) || defined(WIN32) || (defined(__alpha__) || defined(__alpha)) || defined(__arm__) || (defined(__mips__) && defined(__MIPSEL__)) || defined(__LITTLE_ENDIAN__)
71 #define ENDIAN_LITTLE
72 #else
73 #define ENDIAN_BIG
74 #endif
75 #endif
76
77 short ShortSwap (short l);
78 int LongSwap (int l);
79 float FloatSwap (float f);
80
81 #ifdef ENDIAN_LITTLE
82 // little endian
83 #define BigShort(l) ShortSwap(l)
84 #define LittleShort(l) (l)
85 #define BigLong(l) LongSwap(l)
86 #define LittleLong(l) (l)
87 #define BigFloat(l) FloatSwap(l)
88 #define LittleFloat(l) (l)
89 #elif ENDIAN_BIG
90 // big endian
91 #define BigShort(l) (l)
92 #define LittleShort(l) ShortSwap(l)
93 #define BigLong(l) (l)
94 #define LittleLong(l) LongSwap(l)
95 #define BigFloat(l) (l)
96 #define LittleFloat(l) FloatSwap(l)
97 #else
98 // figure it out at runtime
99 extern short (*BigShort) (short l);
100 extern short (*LittleShort) (short l);
101 extern int (*BigLong) (int l);
102 extern int (*LittleLong) (int l);
103 extern float (*BigFloat) (float l);
104 extern float (*LittleFloat) (float l);
105 #endif
106
107 //============================================================================
108
109 void MSG_WriteChar (sizebuf_t *sb, int c);
110 void MSG_WriteByte (sizebuf_t *sb, int c);
111 void MSG_WriteShort (sizebuf_t *sb, int c);
112 void MSG_WriteLong (sizebuf_t *sb, int c);
113 void MSG_WriteFloat (sizebuf_t *sb, float f);
114 void MSG_WriteString (sizebuf_t *sb, char *s);
115 void MSG_WriteCoord (sizebuf_t *sb, float f);
116 void MSG_WriteAngle (sizebuf_t *sb, float f);
117 void MSG_WritePreciseAngle (sizebuf_t *sb, float f);
118
119 #define MSG_WriteFloatCoord MSG_WriteFloat
120
121 extern  int                     msg_readcount;
122 extern  qboolean        msg_badread;            // set if a read goes beyond end of message
123
124 void MSG_BeginReading (void);
125 //int MSG_ReadChar (void);
126 //int MSG_ReadByte (void);
127 int MSG_ReadShort (void);
128 int MSG_ReadLong (void);
129 float MSG_ReadFloat (void);
130 char *MSG_ReadString (void);
131
132 #define MSG_ReadChar() (msg_readcount >= net_message.cursize ? (msg_badread = true, -1) : (signed char)net_message.data[msg_readcount++])
133 #define MSG_ReadByte() (msg_readcount >= net_message.cursize ? (msg_badread = true, -1) : (unsigned char)net_message.data[msg_readcount++])
134 //#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))
135 //#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))
136
137 float MSG_ReadCoord (void);
138 //float MSG_ReadAngle (void);
139
140 #define MSG_ReadFloatCoord MSG_ReadFloat
141
142 #define MSG_ReadAngle() (MSG_ReadByte() * (360.0f / 256.0f))
143 #define MSG_ReadPreciseAngle() (MSG_ReadShort() * (360.0f / 65536.0f))
144
145 #define MSG_ReadVector(v) {(v)[0] = MSG_ReadCoord();(v)[1] = MSG_ReadCoord();(v)[2] = MSG_ReadCoord();}
146
147 extern qboolean dpprotocol;
148
149 //============================================================================
150
151 /*
152 void Q_memset (void *dest, int fill, int count);
153 void Q_memcpy (void *dest, void *src, int count);
154 int Q_memcmp (void *m1, void *m2, int count);
155 void Q_strcpy (char *dest, char *src);
156 void Q_strncpy (char *dest, char *src, int count);
157 int Q_strlen (char *str);
158 char *Q_strrchr (char *s, char c);
159 void Q_strcat (char *dest, char *src);
160 int Q_strcmp (char *s1, char *s2);
161 int Q_strncmp (char *s1, char *s2, int count);
162 */
163 int Q_strcasecmp (char *s1, char *s2);
164 int Q_strncasecmp (char *s1, char *s2, int n);
165 /*
166 int     Q_atoi (char *str);
167 float Q_atof (char *str);
168 */
169
170 //============================================================================
171
172 extern  char            com_token[1024];
173 extern  qboolean        com_eof;
174
175 char *COM_Parse (char *data);
176
177
178 extern  int             com_argc;
179 extern  char    **com_argv;
180
181 int COM_CheckParm (char *parm);
182 void COM_Init (char *path);
183 void COM_InitArgv (int argc, char **argv);
184
185 char *COM_SkipPath (char *pathname);
186 void COM_StripExtension (char *in, char *out);
187 void COM_FileBase (char *in, char *out);
188 void COM_DefaultExtension (char *path, char *extension);
189
190 char    *va(char *format, ...);
191 // does a varargs printf into a temp buffer
192
193
194 //============================================================================
195
196 extern int com_filesize;
197 struct cache_user_s;
198
199 extern  char    com_gamedir[MAX_OSPATH];
200
201 void COM_WriteFile (char *filename, void *data, int len);
202 int COM_FOpenFile (char *filename, QFile **file, qboolean quiet, qboolean zip);
203
204 // set by COM_LoadFile functions
205 extern int loadsize;
206 byte *COM_LoadHunkFile (char *path, qboolean quiet);
207 byte *COM_LoadMallocFile (char *path, qboolean quiet);
208 //void COM_LoadCacheFile (char *path, struct cache_user_s *cu, qboolean quiet);
209
210 byte *COM_LoadFile (char *path, int usehunk, qboolean quiet);
211
212 int COM_FileExists(char *filename);
213
214 extern  struct cvar_s   registered;
215
216 extern qboolean         standard_quake, rogue, hipnotic, nehahra;
217
218 // LordHavoc: useful...
219 extern void COM_ToLowerString(char *in, char *out);
220 extern void COM_ToUpperString(char *in, char *out);