]> icculus.org git repositories - divverent/darkplaces.git/blob - bspfile.h
fix the off-by-one fix (oops)
[divverent/darkplaces.git] / bspfile.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
22 // upper design bounds
23
24 #define MAX_MAP_HULLS           4
25
26 #define MAX_MAP_MODELS          256
27 #define MAX_MAP_BRUSHES         4096
28 #define MAX_MAP_ENTITIES        1024
29 #define MAX_MAP_ENTSTRING       65536
30
31 #define MAX_MAP_PLANES          32767
32 #define MAX_MAP_NODES           32767           // because negative shorts are contents
33 #define MAX_MAP_CLIPNODES       32767           //
34 #define MAX_MAP_LEAFS           32767           // was 8192
35 #define MAX_MAP_VERTS           65535
36 #define MAX_MAP_FACES           65535
37 #define MAX_MAP_MARKSURFACES 65535
38 #define MAX_MAP_TEXINFO         4096
39 #define MAX_MAP_EDGES           256000
40 #define MAX_MAP_SURFEDGES       512000
41 #define MAX_MAP_TEXTURES        512
42 #define MAX_MAP_MIPTEX          0x200000
43 #define MAX_MAP_LIGHTING        0x100000
44 #define MAX_MAP_VISIBILITY      0x100000
45
46 #define MAX_MAP_PORTALS         65536
47
48 // key / value pair sizes
49
50 #define MAX_KEY         32
51 #define MAX_VALUE       1024
52
53 //=============================================================================
54
55
56 #define BSPVERSION      29
57 #define TOOLVERSION     2
58
59 typedef struct
60 {
61         int             fileofs, filelen;
62 } lump_t;
63
64 #define LUMP_ENTITIES   0
65 #define LUMP_PLANES             1
66 #define LUMP_TEXTURES   2
67 #define LUMP_VERTEXES   3
68 #define LUMP_VISIBILITY 4
69 #define LUMP_NODES              5
70 #define LUMP_TEXINFO    6
71 #define LUMP_FACES              7
72 #define LUMP_LIGHTING   8
73 #define LUMP_CLIPNODES  9
74 #define LUMP_LEAFS              10
75 #define LUMP_MARKSURFACES 11
76 #define LUMP_EDGES              12
77 #define LUMP_SURFEDGES  13
78 #define LUMP_MODELS             14
79
80 #define HEADER_LUMPS    15
81
82 typedef struct
83 {
84         float           mins[3], maxs[3];
85         float           origin[3];
86         int                     headnode[MAX_MAP_HULLS];
87         int                     visleafs;               // not including the solid leaf 0
88         int                     firstface, numfaces;
89 } dmodel_t;
90
91 typedef struct
92 {
93         int                     version;        
94         lump_t          lumps[HEADER_LUMPS];
95 } dheader_t;
96
97 typedef struct
98 {
99         int                     nummiptex;
100         int                     dataofs[4];             // [nummiptex]
101 } dmiptexlump_t;
102
103 #define MIPLEVELS       4
104 typedef struct miptex_s
105 {
106         char            name[16];
107         unsigned        width, height;
108         unsigned        offsets[MIPLEVELS];             // four mip maps stored
109 } miptex_t;
110
111
112 typedef struct
113 {
114         float   point[3];
115 } dvertex_t;
116
117
118 // 0-2 are axial planes
119 #define PLANE_X                 0
120 #define PLANE_Y                 1
121 #define PLANE_Z                 2
122
123 // 3-5 are non-axial planes snapped to the nearest
124 #define PLANE_ANYX              3
125 #define PLANE_ANYY              4
126 #define PLANE_ANYZ              5
127
128 typedef struct
129 {
130         float   normal[3];
131         float   dist;
132         int             type;           // PLANE_X - PLANE_ANYZ ?remove? trivial to regenerate
133 } dplane_t;
134
135
136
137 #define CONTENTS_EMPTY          -1
138 #define CONTENTS_SOLID          -2
139 #define CONTENTS_WATER          -3
140 #define CONTENTS_SLIME          -4
141 #define CONTENTS_LAVA           -5
142 #define CONTENTS_SKY            -6
143 #define CONTENTS_ORIGIN         -7              // removed at csg time
144 #define CONTENTS_CLIP           -8              // changed to contents_solid
145
146 // LordHavoc: Q2 water
147 /*
148 #define CONTENTS_CURRENT_0              -9
149 #define CONTENTS_CURRENT_90             -10
150 #define CONTENTS_CURRENT_180    -11
151 #define CONTENTS_CURRENT_270    -12
152 #define CONTENTS_CURRENT_UP             -13
153 #define CONTENTS_CURRENT_DOWN   -14
154 */
155
156
157 typedef struct
158 {
159         int                     planenum;
160         short           children[2];    // negative numbers are -(leafs+1), not nodes
161         short           mins[3];                // for sphere culling
162         short           maxs[3];
163         unsigned short  firstface;
164         unsigned short  numfaces;       // counting both sides
165 } dnode_t;
166
167 typedef struct
168 {
169         int                     planenum;
170         short           children[2];    // negative numbers are contents
171 } dclipnode_t;
172
173
174 typedef struct texinfo_s
175 {
176         float           vecs[2][4];             // [s/t][xyz offset]
177         int                     miptex;
178         int                     flags;
179 } texinfo_t;
180 #define TEX_SPECIAL             1               // sky or slime, no lightmap or 256 subdivision
181
182 // note that edge 0 is never used, because negative edge nums are used for
183 // counterclockwise use of the edge in a face
184 typedef struct
185 {
186         unsigned short  v[2];           // vertex numbers
187 } dedge_t;
188
189 #define MAXLIGHTMAPS    4
190 typedef struct
191 {
192         short           planenum;
193         short           side;
194
195         int                     firstedge;              // we must support > 64k edges
196         short           numedges;       
197         short           texinfo;
198
199 // lighting info
200         byte            styles[MAXLIGHTMAPS];
201         int                     lightofs;               // start of [numstyles*surfsize] samples
202 } dface_t;
203
204
205
206 #define AMBIENT_WATER   0
207 #define AMBIENT_SKY             1
208 #define AMBIENT_SLIME   2
209 #define AMBIENT_LAVA    3
210
211 #define NUM_AMBIENTS                    4               // automatic ambient sounds
212
213 // leaf 0 is the generic CONTENTS_SOLID leaf, used for all solid areas
214 // all other leafs need visibility info
215 typedef struct
216 {
217         int                     contents;
218         int                     visofs;                         // -1 = no visibility info
219
220         short           mins[3];                        // for frustum culling
221         short           maxs[3];
222
223         unsigned short          firstmarksurface;
224         unsigned short          nummarksurfaces;
225
226         byte            ambient_level[NUM_AMBIENTS];
227 } dleaf_t;
228
229
230 //============================================================================
231
232 #ifndef QUAKE_GAME
233
234 #define ANGLE_UP        -1
235 #define ANGLE_DOWN      -2
236
237
238 // the utilities get to be lazy and just use large static arrays
239
240 extern  int                     nummodels;
241 extern  dmodel_t        dmodels[MAX_MAP_MODELS];
242
243 extern  int                     visdatasize;
244 extern  byte            dvisdata[MAX_MAP_VISIBILITY];
245
246 extern  int                     lightdatasize;
247 extern  byte            dlightdata[MAX_MAP_LIGHTING];
248
249 extern  int                     texdatasize;
250 extern  byte            dtexdata[MAX_MAP_MIPTEX]; // (dmiptexlump_t)
251
252 extern  int                     entdatasize;
253 extern  char            dentdata[MAX_MAP_ENTSTRING];
254
255 extern  int                     numleafs;
256 extern  dleaf_t         dleafs[MAX_MAP_LEAFS];
257
258 extern  int                     numplanes;
259 extern  dplane_t        dplanes[MAX_MAP_PLANES];
260
261 extern  int                     numvertexes;
262 extern  dvertex_t       dvertexes[MAX_MAP_VERTS];
263
264 extern  int                     numnodes;
265 extern  dnode_t         dnodes[MAX_MAP_NODES];
266
267 extern  int                     numtexinfo;
268 extern  texinfo_t       texinfo[MAX_MAP_TEXINFO];
269
270 extern  int                     numfaces;
271 extern  dface_t         dfaces[MAX_MAP_FACES];
272
273 extern  int                     numclipnodes;
274 extern  dclipnode_t     dclipnodes[MAX_MAP_CLIPNODES];
275
276 extern  int                     numedges;
277 extern  dedge_t         dedges[MAX_MAP_EDGES];
278
279 extern  int                     nummarksurfaces;
280 extern  unsigned short  dmarksurfaces[MAX_MAP_MARKSURFACES];
281
282 extern  int                     numsurfedges;
283 extern  int                     dsurfedges[MAX_MAP_SURFEDGES];
284
285
286 void DecompressVis (byte *in, byte *decompressed);
287 int CompressVis (byte *vis, byte *dest);
288
289 void    LoadBSPFile (char *filename);
290 void    WriteBSPFile (char *filename);
291 void    PrintBSPFileSizes (void);
292
293 //===============
294
295
296 typedef struct epair_s
297 {
298         struct epair_s  *next;
299         char    *key;
300         char    *value;
301 } epair_t;
302
303 typedef struct
304 {
305         vec3_t          origin;
306         int                     firstbrush;
307         int                     numbrushes;
308         epair_t         *epairs;
309 } entity_t;
310
311 //extern        int                     num_entities;
312 extern  entity_t        entities[MAX_MAP_ENTITIES];
313
314 void    ParseEntities (void);
315 void    UnparseEntities (void);
316
317 void    SetKeyValue (entity_t *ent, char *key, char *value);
318 char    *ValueForKey (entity_t *ent, char *key);
319 // will return "" if not present
320
321 vec_t   FloatForKey (entity_t *ent, char *key);
322 void    GetVectorForKey (entity_t *ent, char *key, vec3_t vec);
323
324 epair_t *ParseEpair (void);
325
326 #endif