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