git-svn-id: http://bladebattles.com/kurok/SVN@11 20cd92bb-ff49-0410-b73e-96a06e42c3b9
[kurok.git] / bspfile.h
blob91499c8a6a23f5403ab31d2c2e53f3a433044fc0
1 /*
2 Copyright (C) 1996-1997 Id Software, Inc.
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.
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.
13 See the GNU General Public License for more details.
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.
22 // upper design bounds
24 #define MAX_MAP_HULLS 4
26 #define MAX_MAP_MODELS 256
27 #define MAX_MAP_BRUSHES 4096
28 #define MAX_MAP_ENTITIES 1024
29 #define MAX_MAP_ENTSTRING 65536
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 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
46 #define MAX_MAP_PORTALS 65536
48 // key / value pair sizes
50 #define MAX_KEY 32
51 #define MAX_VALUE 1024
53 //=============================================================================
56 #define BSPVERSION 29
57 #define TOOLVERSION 2
59 typedef struct
61 int fileofs, filelen;
62 } lump_t;
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
80 #define HEADER_LUMPS 15
82 typedef struct
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;
91 typedef struct
93 int version;
94 lump_t lumps[HEADER_LUMPS];
95 } dheader_t;
97 typedef struct
99 int nummiptex;
100 int dataofs[4]; // [nummiptex]
101 } dmiptexlump_t;
103 #define MIPLEVELS 4
104 typedef struct miptex_s
106 char name[16];
107 unsigned width, height;
108 unsigned offsets[MIPLEVELS]; // four mip maps stored
109 } miptex_t;
112 typedef struct
114 float point[3];
115 } dvertex_t;
118 // 0-2 are axial planes
119 #define PLANE_X 0
120 #define PLANE_Y 1
121 #define PLANE_Z 2
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
128 typedef struct
130 float normal[3];
131 float dist;
132 int type; // PLANE_X - PLANE_ANYZ ?remove? trivial to regenerate
133 } dplane_t;
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
146 #define CONTENTS_CURRENT_0 -9
147 #define CONTENTS_CURRENT_90 -10
148 #define CONTENTS_CURRENT_180 -11
149 #define CONTENTS_CURRENT_270 -12
150 #define CONTENTS_CURRENT_UP -13
151 #define CONTENTS_CURRENT_DOWN -14
154 // !!! if this is changed, it must be changed in asm_i386.h too !!!
155 typedef struct
157 int planenum;
158 short children[2]; // negative numbers are -(leafs+1), not nodes
159 short mins[3]; // for sphere culling
160 short maxs[3];
161 unsigned short firstface;
162 unsigned short numfaces; // counting both sides
163 } dnode_t;
165 typedef struct
167 int planenum;
168 short children[2]; // negative numbers are contents
169 } dclipnode_t;
172 typedef struct texinfo_s
174 float vecs[2][4]; // [s/t][xyz offset]
175 int miptex;
176 int flags;
177 } texinfo_t;
178 #define TEX_SPECIAL 1 // sky or slime, no lightmap or 256 subdivision
180 // note that edge 0 is never used, because negative edge nums are used for
181 // counterclockwise use of the edge in a face
182 typedef struct
184 unsigned short v[2]; // vertex numbers
185 } dedge_t;
187 #define MAXLIGHTMAPS 4
188 typedef struct
190 short planenum;
191 short side;
193 int firstedge; // we must support > 64k edges
194 short numedges;
195 short texinfo;
197 // lighting info
198 byte styles[MAXLIGHTMAPS];
199 int lightofs; // start of [numstyles*surfsize] samples
200 } dface_t;
204 #define AMBIENT_WATER 0
205 #define AMBIENT_SKY 1
206 #define AMBIENT_SLIME 2
207 #define AMBIENT_LAVA 3
209 #define NUM_AMBIENTS 4 // automatic ambient sounds
211 // leaf 0 is the generic CONTENTS_SOLID leaf, used for all solid areas
212 // all other leafs need visibility info
213 typedef struct
215 int contents;
216 int visofs; // -1 = no visibility info
218 short mins[3]; // for frustum culling
219 short maxs[3];
221 unsigned short firstmarksurface;
222 unsigned short nummarksurfaces;
224 byte ambient_level[NUM_AMBIENTS];
225 } dleaf_t;
228 //============================================================================
230 #ifndef QUAKE_GAME
232 #define ANGLE_UP -1
233 #define ANGLE_DOWN -2
236 // the utilities get to be lazy and just use large static arrays
238 extern int nummodels;
239 extern dmodel_t dmodels[MAX_MAP_MODELS];
241 extern int visdatasize;
242 extern byte dvisdata[MAX_MAP_VISIBILITY];
244 extern int lightdatasize;
245 extern byte dlightdata[MAX_MAP_LIGHTING];
247 extern int texdatasize;
248 extern byte dtexdata[MAX_MAP_MIPTEX]; // (dmiptexlump_t)
250 extern int entdatasize;
251 extern char dentdata[MAX_MAP_ENTSTRING];
253 extern int numleafs;
254 extern dleaf_t dleafs[MAX_MAP_LEAFS];
256 extern int numplanes;
257 extern dplane_t dplanes[MAX_MAP_PLANES];
259 extern int numvertexes;
260 extern dvertex_t dvertexes[MAX_MAP_VERTS];
262 extern int numnodes;
263 extern dnode_t dnodes[MAX_MAP_NODES];
265 extern int numtexinfo;
266 extern texinfo_t texinfo[MAX_MAP_TEXINFO];
268 extern int numfaces;
269 extern dface_t dfaces[MAX_MAP_FACES];
271 extern int numclipnodes;
272 extern dclipnode_t dclipnodes[MAX_MAP_CLIPNODES];
274 extern int numedges;
275 extern dedge_t dedges[MAX_MAP_EDGES];
277 extern int nummarksurfaces;
278 extern unsigned short dmarksurfaces[MAX_MAP_MARKSURFACES];
280 extern int numsurfedges;
281 extern int dsurfedges[MAX_MAP_SURFEDGES];
284 void DecompressVis (byte *in, byte *decompressed);
285 int CompressVis (byte *vis, byte *dest);
287 void LoadBSPFile (char *filename);
288 void WriteBSPFile (char *filename);
289 void PrintBSPFileSizes (void);
291 //===============
294 typedef struct epair_s
296 struct epair_s *next;
297 char *key;
298 char *value;
299 } epair_t;
301 typedef struct
303 vec3_t origin;
304 int firstbrush;
305 int numbrushes;
306 epair_t *epairs;
307 } entity_t;
309 extern int num_entities;
310 extern entity_t entities[MAX_MAP_ENTITIES];
312 void ParseEntities (void);
313 void UnparseEntities (void);
315 void SetKeyValue (entity_t *ent, char *key, char *value);
316 char *ValueForKey (entity_t *ent, char *key);
317 // will return "" if not present
319 vec_t FloatForKey (entity_t *ent, char *key);
320 void GetVectorForKey (entity_t *ent, char *key, vec3_t vec);
322 epair_t *ParseEpair (void);
324 #endif