]> de.git.xonotic.org Git - xonotic/darkplaces.git/blob - common.h
optional portal based determination of lit surfaces (good speed gain, enough to make...
[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, const 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, const void *data, int length);
46 void SZ_Print (sizebuf_t *buf, const char *data);       // strcats onto the sizebuf
47 void SZ_HexDumpToConsole(const sizebuf_t *buf);
48
49 void Com_HexDumpToConsole(const qbyte *data, int size);
50
51 //============================================================================
52 #if !defined(ENDIAN_LITTLE) && !defined(ENDIAN_BIG)
53 #if  defined(__i386__) || defined(__ia64__) || defined(WIN32) || (defined(__alpha__) || defined(__alpha)) || defined(__arm__) || (defined(__mips__) && defined(__MIPSEL__)) || defined(__LITTLE_ENDIAN__)
54 #define ENDIAN_LITTLE
55 #else
56 #define ENDIAN_BIG
57 #endif
58 #endif
59
60 short ShortSwap (short l);
61 int LongSwap (int l);
62 float FloatSwap (float f);
63
64 #ifdef ENDIAN_LITTLE
65 // little endian
66 #define BigShort(l) ShortSwap(l)
67 #define LittleShort(l) (l)
68 #define BigLong(l) LongSwap(l)
69 #define LittleLong(l) (l)
70 #define BigFloat(l) FloatSwap(l)
71 #define LittleFloat(l) (l)
72 #elif ENDIAN_BIG
73 // big endian
74 #define BigShort(l) (l)
75 #define LittleShort(l) ShortSwap(l)
76 #define BigLong(l) (l)
77 #define LittleLong(l) LongSwap(l)
78 #define BigFloat(l) (l)
79 #define LittleFloat(l) FloatSwap(l)
80 #else
81 // figure it out at runtime
82 extern short (*BigShort) (short l);
83 extern short (*LittleShort) (short l);
84 extern int (*BigLong) (int l);
85 extern int (*LittleLong) (int l);
86 extern float (*BigFloat) (float l);
87 extern float (*LittleFloat) (float l);
88 #endif
89
90 //============================================================================
91
92 void MSG_WriteChar (sizebuf_t *sb, int c);
93 void MSG_WriteByte (sizebuf_t *sb, int c);
94 void MSG_WriteShort (sizebuf_t *sb, int c);
95 void MSG_WriteLong (sizebuf_t *sb, int c);
96 void MSG_WriteFloat (sizebuf_t *sb, float f);
97 void MSG_WriteString (sizebuf_t *sb, const char *s);
98 void MSG_WriteCoord (sizebuf_t *sb, float f);
99 void MSG_WriteAngle (sizebuf_t *sb, float f);
100 void MSG_WritePreciseAngle (sizebuf_t *sb, float f);
101 void MSG_WriteDPCoord (sizebuf_t *sb, float f);
102
103 extern  int                     msg_readcount;
104 extern  qboolean        msg_badread;            // set if a read goes beyond end of message
105
106 void MSG_BeginReading (void);
107 int MSG_ReadShort (void);
108 int MSG_ReadLong (void);
109 float MSG_ReadFloat (void);
110 char *MSG_ReadString (void);
111
112 #define MSG_ReadChar() (msg_readcount >= net_message.cursize ? (msg_badread = true, -1) : (signed char)net_message.data[msg_readcount++])
113 #define MSG_ReadByte() (msg_readcount >= net_message.cursize ? (msg_badread = true, -1) : (unsigned char)net_message.data[msg_readcount++])
114
115 float MSG_ReadCoord (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 int Q_strcasecmp (const char *s1, const char *s2);
129 int Q_strncasecmp (const char *s1, const char *s2, int n);
130
131 //============================================================================
132
133 extern char com_token[1024];
134 extern qboolean com_eof;
135
136 int COM_ParseToken (const char **data);
137
138 extern char com_basedir[MAX_OSPATH];
139 extern int com_argc;
140 extern const char **com_argv;
141
142 int COM_CheckParm (const char *parm);
143 void COM_Init (void);
144 void COM_InitArgv (void);
145 void COM_InitGameType (void);
146
147 void COM_StripExtension (const char *in, char *out);
148 void COM_FileBase (const char *in, char *out);
149 void COM_DefaultExtension (char *path, const char *extension);
150
151 char    *va(const char *format, ...);
152 // does a varargs printf into a temp buffer
153
154
155 //============================================================================
156
157 extern int com_filesize;
158
159 extern  char    com_gamedir[MAX_OSPATH];
160
161 qboolean COM_WriteFile (const char *filename, void *data, int len);
162 int COM_FOpenFile (const char *filename, QFile **file, qboolean quiet, qboolean zip);
163
164 // set by COM_LoadFile functions
165 extern int loadsize;
166 qbyte *COM_LoadFile (const char *path, qboolean quiet);
167
168 int COM_FileExists(const char *filename);
169
170 extern  struct cvar_s   registered;
171
172 #define GAME_NORMAL 0
173 #define GAME_HIPNOTIC 1
174 #define GAME_ROGUE 2
175 #define GAME_NEHAHRA 3
176 #define GAME_NEXIUZ 4
177 #define GAME_TRANSFUSION 5
178
179 extern int gamemode;
180 extern char *gamename;
181 extern char com_modname[MAX_OSPATH];
182
183 // LordHavoc: useful...
184 void COM_ToLowerString(const char *in, char *out);
185 void COM_ToUpperString(const char *in, char *out);
186 int COM_StringBeginsWith(const char *s, const char *match);
187
188 typedef struct stringlist_s
189 {
190         struct stringlist_s *next;
191         char *text;
192 } stringlist_t;
193
194 int matchpattern(char *in, char *pattern, int caseinsensitive);
195 stringlist_t *listdirectory(char *path);
196 void freedirectory(stringlist_t *list);
197
198 #endif
199