Team Fortress 2 Source Code as on 22/4/2020
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

310 lines
6.4 KiB

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