bspfile.h 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325
  1. /*
  2. Copyright (C) 1996-1997 Id Software, Inc.
  3. This program is free software; you can redistribute it and/or
  4. modify it under the terms of the GNU General Public License
  5. as published by the Free Software Foundation; either version 2
  6. of the License, or (at your option) any later version.
  7. This program is distributed in the hope that it will be useful,
  8. but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  10. See the GNU General Public License for more details.
  11. You should have received a copy of the GNU General Public License
  12. along with this program; if not, write to the Free Software
  13. Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  14. */
  15. // upper design bounds
  16. #define MAX_MAP_HULLS 4
  17. #define MAX_MAP_MODELS 256
  18. #define MAX_MAP_BRUSHES 4096
  19. #define MAX_MAP_ENTITIES 1024
  20. #define MAX_MAP_ENTSTRING 65536
  21. #define MAX_MAP_PLANES 32767
  22. #define MAX_MAP_NODES 32767 // because negative shorts are contents
  23. #define MAX_MAP_CLIPNODES 32767 //
  24. #define MAX_MAP_LEAFS 8192
  25. #define MAX_MAP_VERTS 65535
  26. #define MAX_MAP_FACES 65535
  27. #define MAX_MAP_MARKSURFACES 65535
  28. #define MAX_MAP_TEXINFO 4096
  29. #define MAX_MAP_EDGES 256000
  30. #define MAX_MAP_SURFEDGES 512000
  31. #define MAX_MAP_TEXTURES 512
  32. #define MAX_MAP_MIPTEX 0x200000
  33. #define MAX_MAP_LIGHTING 0x100000
  34. #define MAX_MAP_VISIBILITY 0x100000
  35. #define MAX_MAP_PORTALS 65536
  36. // key / value pair sizes
  37. #define MAX_KEY 32
  38. #define MAX_VALUE 1024
  39. //=============================================================================
  40. #define BSPVERSION 29
  41. #define TOOLVERSION 2
  42. typedef struct
  43. {
  44. int fileofs, filelen;
  45. } lump_t;
  46. #define LUMP_ENTITIES 0
  47. #define LUMP_PLANES 1
  48. #define LUMP_TEXTURES 2
  49. #define LUMP_VERTEXES 3
  50. #define LUMP_VISIBILITY 4
  51. #define LUMP_NODES 5
  52. #define LUMP_TEXINFO 6
  53. #define LUMP_FACES 7
  54. #define LUMP_LIGHTING 8
  55. #define LUMP_CLIPNODES 9
  56. #define LUMP_LEAFS 10
  57. #define LUMP_MARKSURFACES 11
  58. #define LUMP_EDGES 12
  59. #define LUMP_SURFEDGES 13
  60. #define LUMP_MODELS 14
  61. #define HEADER_LUMPS 15
  62. typedef struct
  63. {
  64. float mins[3], maxs[3];
  65. float origin[3];
  66. int headnode[MAX_MAP_HULLS];
  67. int visleafs; // not including the solid leaf 0
  68. int firstface, numfaces;
  69. } dmodel_t;
  70. typedef struct
  71. {
  72. int version;
  73. lump_t lumps[HEADER_LUMPS];
  74. } dheader_t;
  75. typedef struct
  76. {
  77. int nummiptex;
  78. int dataofs[4]; // [nummiptex]
  79. } dmiptexlump_t;
  80. #define MIPLEVELS 4
  81. typedef struct miptex_s
  82. {
  83. char name[16];
  84. unsigned width, height;
  85. unsigned offsets[MIPLEVELS]; // four mip maps stored
  86. } miptex_t;
  87. typedef struct
  88. {
  89. float point[3];
  90. } dvertex_t;
  91. // 0-2 are axial planes
  92. #define PLANE_X 0
  93. #define PLANE_Y 1
  94. #define PLANE_Z 2
  95. // 3-5 are non-axial planes snapped to the nearest
  96. #define PLANE_ANYX 3
  97. #define PLANE_ANYY 4
  98. #define PLANE_ANYZ 5
  99. typedef struct
  100. {
  101. float normal[3];
  102. float dist;
  103. int type; // PLANE_X - PLANE_ANYZ ?remove? trivial to regenerate
  104. } dplane_t;
  105. #define CONTENTS_EMPTY -1
  106. #define CONTENTS_SOLID -2
  107. #define CONTENTS_WATER -3
  108. #define CONTENTS_SLIME -4
  109. #define CONTENTS_LAVA -5
  110. #define CONTENTS_SKY -6
  111. #define CONTENTS_ORIGIN -7 // removed at csg time
  112. #define CONTENTS_CLIP -8 // changed to contents_solid
  113. #define CONTENTS_CURRENT_0 -9
  114. #define CONTENTS_CURRENT_90 -10
  115. #define CONTENTS_CURRENT_180 -11
  116. #define CONTENTS_CURRENT_270 -12
  117. #define CONTENTS_CURRENT_UP -13
  118. #define CONTENTS_CURRENT_DOWN -14
  119. // !!! if this is changed, it must be changed in asm_i386.h too !!!
  120. typedef struct
  121. {
  122. int planenum;
  123. short children[2]; // negative numbers are -(leafs+1), not nodes
  124. short mins[3]; // for sphere culling
  125. short maxs[3];
  126. unsigned short firstface;
  127. unsigned short numfaces; // counting both sides
  128. } dnode_t;
  129. typedef struct
  130. {
  131. int planenum;
  132. short children[2]; // negative numbers are contents
  133. } dclipnode_t;
  134. typedef struct texinfo_s
  135. {
  136. float vecs[2][4]; // [s/t][xyz offset]
  137. int miptex;
  138. int flags;
  139. } texinfo_t;
  140. #define TEX_SPECIAL 1 // sky or slime, no lightmap or 256 subdivision
  141. // note that edge 0 is never used, because negative edge nums are used for
  142. // counterclockwise use of the edge in a face
  143. typedef struct
  144. {
  145. unsigned short v[2]; // vertex numbers
  146. } dedge_t;
  147. #define MAXLIGHTMAPS 4
  148. typedef struct
  149. {
  150. short planenum;
  151. short side;
  152. int firstedge; // we must support > 64k edges
  153. short numedges;
  154. short texinfo;
  155. // lighting info
  156. byte styles[MAXLIGHTMAPS];
  157. int lightofs; // start of [numstyles*surfsize] samples
  158. } dface_t;
  159. #define AMBIENT_WATER 0
  160. #define AMBIENT_SKY 1
  161. #define AMBIENT_SLIME 2
  162. #define AMBIENT_LAVA 3
  163. #define NUM_AMBIENTS 4 // automatic ambient sounds
  164. // leaf 0 is the generic CONTENTS_SOLID leaf, used for all solid areas
  165. // all other leafs need visibility info
  166. typedef struct
  167. {
  168. int contents;
  169. int visofs; // -1 = no visibility info
  170. short mins[3]; // for frustum culling
  171. short maxs[3];
  172. unsigned short firstmarksurface;
  173. unsigned short nummarksurfaces;
  174. byte ambient_level[NUM_AMBIENTS];
  175. } dleaf_t;
  176. //============================================================================
  177. #ifndef QUAKE_GAME
  178. #define ANGLE_UP -1
  179. #define ANGLE_DOWN -2
  180. // the utilities get to be lazy and just use large static arrays
  181. extern int nummodels;
  182. extern dmodel_t dmodels[MAX_MAP_MODELS];
  183. extern int visdatasize;
  184. extern byte dvisdata[MAX_MAP_VISIBILITY];
  185. extern int lightdatasize;
  186. extern byte dlightdata[MAX_MAP_LIGHTING];
  187. extern int texdatasize;
  188. extern byte dtexdata[MAX_MAP_MIPTEX]; // (dmiptexlump_t)
  189. extern int entdatasize;
  190. extern char dentdata[MAX_MAP_ENTSTRING];
  191. extern int numleafs;
  192. extern dleaf_t dleafs[MAX_MAP_LEAFS];
  193. extern int numplanes;
  194. extern dplane_t dplanes[MAX_MAP_PLANES];
  195. extern int numvertexes;
  196. extern dvertex_t dvertexes[MAX_MAP_VERTS];
  197. extern int numnodes;
  198. extern dnode_t dnodes[MAX_MAP_NODES];
  199. extern int numtexinfo;
  200. extern texinfo_t texinfo[MAX_MAP_TEXINFO];
  201. extern int numfaces;
  202. extern dface_t dfaces[MAX_MAP_FACES];
  203. extern int numclipnodes;
  204. extern dclipnode_t dclipnodes[MAX_MAP_CLIPNODES];
  205. extern int numedges;
  206. extern dedge_t dedges[MAX_MAP_EDGES];
  207. extern int nummarksurfaces;
  208. extern unsigned short dmarksurfaces[MAX_MAP_MARKSURFACES];
  209. extern int numsurfedges;
  210. extern int dsurfedges[MAX_MAP_SURFEDGES];
  211. void DecompressVis (byte *in, byte *decompressed);
  212. int CompressVis (byte *vis, byte *dest);
  213. void LoadBSPFile (char *filename);
  214. void WriteBSPFile (char *filename);
  215. void PrintBSPFileSizes (void);
  216. //===============
  217. typedef struct epair_s
  218. {
  219. struct epair_s *next;
  220. char *key;
  221. char *value;
  222. } epair_t;
  223. typedef struct
  224. {
  225. vec3_t origin;
  226. int firstbrush;
  227. int numbrushes;
  228. epair_t *epairs;
  229. } entity_t;
  230. extern int num_entities;
  231. extern entity_t entities[MAX_MAP_ENTITIES];
  232. void ParseEntities (void);
  233. void UnparseEntities (void);
  234. void SetKeyValue (entity_t *ent, char *key, char *value);
  235. char *ValueForKey (entity_t *ent, char *key);
  236. // will return "" if not present
  237. vec_t FloatForKey (entity_t *ent, char *key);
  238. void GetVectorForKey (entity_t *ent, char *key, vec3_t vec);
  239. epair_t *ParseEpair (void);
  240. #endif