bspfile.h 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379
  1. /*
  2. ===========================================================================
  3. Copyright (C) 1997-2006 Id Software, Inc.
  4. This file is part of Quake 2 Tools source code.
  5. Quake 2 Tools source code is free software; you can redistribute it
  6. and/or modify it under the terms of the GNU General Public License as
  7. published by the Free Software Foundation; either version 2 of the License,
  8. or (at your option) any later version.
  9. Quake 2 Tools source code is distributed in the hope that it will be
  10. useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. GNU General Public License for more details.
  13. You should have received a copy of the GNU General Public License
  14. along with Quake 2 Tools source code; if not, write to the Free Software
  15. Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
  16. ===========================================================================
  17. */
  18. // upper design bounds
  19. // leaffaces, leafbrushes, planes, and verts are still bounded by
  20. // 16 bit short limits
  21. #define MAX_MAP_MODELS 1024
  22. #define MAX_MAP_BRUSHES 8192
  23. #define MAX_MAP_ENTITIES 2048
  24. #define MAX_MAP_PATHS 2048
  25. #define MAX_MAP_ENTSTRING 0x20000
  26. #define MAX_MAP_TEXTURES 1024
  27. #define MAX_MAP_TEXINFO 8192
  28. #define MAX_MAP_PLANES 65536
  29. #define MAX_MAP_NODES 65536
  30. #define MAX_MAP_BRUSHSIDES 65536
  31. #define MAX_MAP_LEAFS 65536
  32. #define MAX_MAP_VERTS 65536
  33. #define MAX_MAP_FACES 65536
  34. #define MAX_MAP_LEAFFACES 65536
  35. #define MAX_MAP_LEAFBRUSHES 65536
  36. #define MAX_MAP_PORTALS 65536
  37. #define MAX_MAP_EDGES 128000
  38. #define MAX_MAP_SURFEDGES 256000
  39. #define MAX_MAP_MIPTEX 0x200000
  40. #define MAX_MAP_LIGHTING 0x200000
  41. #define MAX_MAP_VISIBILITY 0x100000
  42. // key / value pair sizes
  43. #define MAX_KEY 32
  44. #define MAX_VALUE 1024
  45. //=============================================================================
  46. #define BSPVERSION 34
  47. typedef struct
  48. {
  49. int fileofs, filelen;
  50. } lump_t;
  51. #define LUMP_ENTITIES 0
  52. #define LUMP_PLANES 1
  53. #define LUMP_TEXTURES 2
  54. #define LUMP_VERTEXES 3
  55. #define LUMP_VISIBILITY 4
  56. #define LUMP_NODES 5
  57. #define LUMP_TEXINFO 6
  58. #define LUMP_FACES 7
  59. #define LUMP_LIGHTING 8
  60. #define LUMP_LEAFS 9
  61. #define LUMP_LEAFFACES 10
  62. #define LUMP_LEAFBRUSHES 11
  63. #define LUMP_EDGES 12
  64. #define LUMP_SURFEDGES 13
  65. #define LUMP_MODELS 14
  66. #define LUMP_PATHS 15
  67. #define LUMP_BRUSHES 16
  68. #define LUMP_BRUSHSIDES 17
  69. #define LUMP_POP 18
  70. #define HEADER_LUMPS 18
  71. typedef struct
  72. {
  73. int version;
  74. lump_t lumps[HEADER_LUMPS];
  75. } dheader_t;
  76. typedef struct
  77. {
  78. float mins[3], maxs[3];
  79. float origin[3]; // for sounds or lights
  80. int headnode;
  81. int visleafs; // not including the solid leaf 0
  82. int firstface, numfaces;
  83. } dmodel_t;
  84. typedef struct
  85. {
  86. int nummiptex;
  87. int dataofs[4]; // [nummiptex]
  88. } dmiptexlump_t;
  89. #define MIPLEVELS 4
  90. typedef struct miptex_s
  91. {
  92. char name[16];
  93. unsigned width, height;
  94. unsigned offsets[MIPLEVELS]; // four mip maps stored
  95. int flags;
  96. int value;
  97. } miptex_t;
  98. typedef struct
  99. {
  100. float point[3];
  101. } dvertex_t;
  102. // 0-2 are axial planes
  103. #define PLANE_X 0
  104. #define PLANE_Y 1
  105. #define PLANE_Z 2
  106. // 3-5 are non-axial planes snapped to the nearest
  107. #define PLANE_ANYX 3
  108. #define PLANE_ANYY 4
  109. #define PLANE_ANYZ 5
  110. // planes (x&~1) and (x&~1)+1 are allways opposites
  111. typedef struct
  112. {
  113. float normal[3];
  114. float dist;
  115. int type; // PLANE_X - PLANE_ANYZ ?remove? trivial to regenerate
  116. } dplane_t;
  117. // contents flags are seperate bits
  118. // a given brush can contribute multiple content bits
  119. // multiple brushes can be in a single leaf
  120. // lower bits are stronger, and will eat weaker brushes completely
  121. #define CONTENTS_SOLID 1 // an eye is never valid in a solid
  122. #define CONTENTS_WINDOW 2 // translucent, but not watery
  123. #define CONTENTS_LAVA 8
  124. #define CONTENTS_SLIME 16
  125. #define CONTENTS_WATER 32
  126. #define CONTENTS_THINWATER 64 // translucent faces
  127. #define LAST_VISIBLE_CONTENTS 64
  128. // remaining contents are non-visible, and don't eat brushes
  129. #define CONTENTS_MONSTER 128
  130. #define CONTENTS_PLAYERCLIP 256
  131. #define CONTENTS_MONSTERCLIP 512
  132. // currents can be added to any other contents, and may be mixed
  133. #define CONTENTS_CURRENT_0 1024
  134. #define CONTENTS_CURRENT_90 2048
  135. #define CONTENTS_CURRENT_180 4096
  136. #define CONTENTS_CURRENT_270 8192
  137. #define CONTENTS_CURRENT_UP 16384
  138. #define CONTENTS_CURRENT_DOWN 32768
  139. #define CONTENTS_ORIGIN 65536 // removed before processing
  140. // !!! if this is changed, it must be changed in asm_i386.h too !!!
  141. typedef struct
  142. {
  143. int planenum;
  144. int children[2]; // negative numbers are -(leafs+1), not nodes
  145. short mins[3]; // for frustom culling
  146. short maxs[3];
  147. unsigned short firstface;
  148. unsigned short numfaces; // counting both sides
  149. } dnode_t;
  150. typedef struct texinfo_s
  151. {
  152. float vecs[2][4]; // [s/t][xyz offset]
  153. int miptex;
  154. int flags; // miptex flags + overrides
  155. int value; // light emition, etc
  156. } texinfo_t;
  157. #define TEX_SPECIAL 1 // sky or slime, no lightmap or 256 subdivision
  158. #define SURF_LIGHT 2
  159. #define SURF_WATER 4
  160. #define SURF_SLIME 8
  161. #define SURF_LAVA 16
  162. #define SURF_WINDOW 32
  163. #define SURF_SKY 64
  164. #define SURF_MIRROR 128
  165. #define SURF_SLIPPERY 256
  166. // note that edge 0 is never used, because negative edge nums are used for
  167. // counterclockwise use of the edge in a face
  168. typedef struct
  169. {
  170. unsigned short v[2]; // vertex numbers
  171. } dedge_t;
  172. #define MAXLIGHTMAPS 4
  173. typedef struct
  174. {
  175. unsigned short planenum;
  176. short side;
  177. int firstedge; // we must support > 64k edges
  178. short numedges;
  179. short texinfo;
  180. // lighting info
  181. byte styles[MAXLIGHTMAPS];
  182. int lightofs; // start of [numstyles*surfsize] samples
  183. } dface_t;
  184. typedef struct
  185. {
  186. int contents; // OR of all brushes
  187. int visofs; // -1 = no visibility info
  188. short mins[3]; // for frustum culling
  189. short maxs[3];
  190. unsigned short firstleafface;
  191. unsigned short numleaffaces;
  192. unsigned short firstleafbrush;
  193. unsigned short numleafbrushes;
  194. } dleaf_t;
  195. typedef struct
  196. {
  197. unsigned short planenum; // facing out of the leaf
  198. short texinfo;
  199. } dbrushside_t;
  200. typedef struct
  201. {
  202. int firstside;
  203. int numsides;
  204. int contents;
  205. } dbrush_t;
  206. typedef struct
  207. {
  208. float origin[3];
  209. float angles[3];
  210. int next, prev;
  211. int flags;
  212. float speed;
  213. } dpath_t;
  214. //============================================================================
  215. #ifndef QUAKE_GAME
  216. #define ANGLE_UP -1
  217. #define ANGLE_DOWN -2
  218. // the utilities get to be lazy and just use large static arrays
  219. extern int nummodels;
  220. extern dmodel_t dmodels[MAX_MAP_MODELS];
  221. extern int visdatasize;
  222. extern byte dvisdata[MAX_MAP_VISIBILITY];
  223. extern int lightdatasize;
  224. extern byte dlightdata[MAX_MAP_LIGHTING];
  225. extern int texdatasize;
  226. extern byte dtexdata[MAX_MAP_MIPTEX]; // (dmiptexlump_t)
  227. extern int entdatasize;
  228. extern char dentdata[MAX_MAP_ENTSTRING];
  229. extern int numleafs;
  230. extern dleaf_t dleafs[MAX_MAP_LEAFS];
  231. extern int numplanes;
  232. extern dplane_t dplanes[MAX_MAP_PLANES];
  233. extern int numvertexes;
  234. extern dvertex_t dvertexes[MAX_MAP_VERTS];
  235. extern int numnodes;
  236. extern dnode_t dnodes[MAX_MAP_NODES];
  237. extern int numtexinfo;
  238. extern texinfo_t texinfo[MAX_MAP_TEXINFO];
  239. extern int numfaces;
  240. extern dface_t dfaces[MAX_MAP_FACES];
  241. extern int numedges;
  242. extern dedge_t dedges[MAX_MAP_EDGES];
  243. extern int numleaffaces;
  244. extern unsigned short dleaffaces[MAX_MAP_LEAFFACES];
  245. extern int numleafbrushes;
  246. extern unsigned short dleafbrushes[MAX_MAP_LEAFBRUSHES];
  247. extern int numsurfedges;
  248. extern int dsurfedges[MAX_MAP_SURFEDGES];
  249. extern int numpaths;
  250. extern dpath_t dpaths[MAX_MAP_PATHS];
  251. extern int numbrushes;
  252. extern dbrush_t dbrushes[MAX_MAP_BRUSHES];
  253. extern int numbrushsides;
  254. extern dbrushside_t dbrushsides[MAX_MAP_BRUSHSIDES];
  255. void DecompressVis (byte *in, byte *decompressed);
  256. int CompressVis (byte *vis, byte *dest);
  257. void LoadBSPFile (char *filename);
  258. void WriteBSPFile (char *filename);
  259. void PrintBSPFileSizes (void);
  260. //===============
  261. typedef struct epair_s
  262. {
  263. struct epair_s *next;
  264. char *key;
  265. char *value;
  266. } epair_t;
  267. typedef struct
  268. {
  269. vec3_t origin;
  270. int firstbrush;
  271. int numbrushes;
  272. epair_t *epairs;
  273. } entity_t;
  274. extern int num_entities;
  275. extern entity_t entities[MAX_MAP_ENTITIES];
  276. void ParseEntities (void);
  277. void UnparseEntities (void);
  278. void SetKeyValue (entity_t *ent, char *key, char *value);
  279. char *ValueForKey (entity_t *ent, char *key);
  280. // will return "" if not present
  281. vec_t FloatForKey (entity_t *ent, char *key);
  282. void GetVectorForKey (entity_t *ent, char *key, vec3_t vec);
  283. epair_t *ParseEpair (void);
  284. void PrintEntity (entity_t *ent);
  285. extern int r_leaftovis[MAX_MAP_LEAFS];
  286. extern int r_vistoleaf[MAX_MAP_LEAFS];
  287. extern int r_numvisleafs;
  288. #endif