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.

1156 lines
32 KiB

  1. //========= Copyright Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose: Defines and structures for the BSP file format.
  4. //
  5. // $NoKeywords: $
  6. //=============================================================================//
  7. #ifndef BSPFILE_H
  8. #define BSPFILE_H
  9. #pragma once
  10. #ifndef MATHLIB_H
  11. #include "mathlib/mathlib.h"
  12. #endif
  13. #include "datamap.h"
  14. #include "mathlib/bumpvects.h"
  15. #include "mathlib/compressed_light_cube.h"
  16. // little-endian "VBSP"
  17. #define IDBSPHEADER (('P'<<24)+('S'<<16)+('B'<<8)+'V')
  18. // MINBSPVERSION is the minimum acceptable version. The engine will load MINBSPVERSION through BSPVERSION
  19. #define MINBSPVERSION 19
  20. #define BSPVERSION 20
  21. // This needs to match the value in gl_lightmap.h
  22. // Need to dynamically allocate the weights and light values in radial_t to make this variable.
  23. #define MAX_BRUSH_LIGHTMAP_DIM_WITHOUT_BORDER 32
  24. // This is one more than what vbsp cuts for to allow for rounding errors
  25. #define MAX_BRUSH_LIGHTMAP_DIM_INCLUDING_BORDER 35
  26. // We can have larger lightmaps on displacements
  27. #define MAX_DISP_LIGHTMAP_DIM_WITHOUT_BORDER 125
  28. #define MAX_DISP_LIGHTMAP_DIM_INCLUDING_BORDER 128
  29. // This is the actual max.. (change if you change the brush lightmap dim or disp lightmap dim
  30. #define MAX_LIGHTMAP_DIM_WITHOUT_BORDER MAX_DISP_LIGHTMAP_DIM_WITHOUT_BORDER
  31. #define MAX_LIGHTMAP_DIM_INCLUDING_BORDER MAX_DISP_LIGHTMAP_DIM_INCLUDING_BORDER
  32. #define MAX_LIGHTSTYLES 64
  33. // upper design bounds
  34. #define MIN_MAP_DISP_POWER 2 // Minimum and maximum power a displacement can be.
  35. #define MAX_MAP_DISP_POWER 4
  36. // Max # of neighboring displacement touching a displacement's corner.
  37. #define MAX_DISP_CORNER_NEIGHBORS 4
  38. #define NUM_DISP_POWER_VERTS(power) ( ((1 << (power)) + 1) * ((1 << (power)) + 1) )
  39. #define NUM_DISP_POWER_TRIS(power) ( (1 << (power)) * (1 << (power)) * 2 )
  40. #if !defined( BSP_USE_LESS_MEMORY )
  41. // Common limits
  42. // leaffaces, leafbrushes, planes, and verts are still bounded by
  43. // 16 bit short limits
  44. #define MAX_MAP_MODELS 1024
  45. #define MAX_MAP_BRUSHES 8192
  46. #define MAX_MAP_ENTITIES 8192
  47. #define MAX_MAP_TEXINFO 12288
  48. #define MAX_MAP_TEXDATA 2048
  49. #define MAX_MAP_DISPINFO 2048
  50. #define MAX_MAP_DISP_VERTS ( MAX_MAP_DISPINFO * ((1<<MAX_MAP_DISP_POWER)+1) * ((1<<MAX_MAP_DISP_POWER)+1) )
  51. #define MAX_MAP_DISP_TRIS ( (1 << MAX_MAP_DISP_POWER) * (1 << MAX_MAP_DISP_POWER) * 2 )
  52. #define MAX_DISPVERTS NUM_DISP_POWER_VERTS( MAX_MAP_DISP_POWER )
  53. #define MAX_DISPTRIS NUM_DISP_POWER_TRIS( MAX_MAP_DISP_POWER )
  54. #define MAX_MAP_AREAS 256
  55. #define MAX_MAP_AREA_BYTES (MAX_MAP_AREAS/8)
  56. #define MAX_MAP_AREAPORTALS 1024
  57. // Planes come in pairs, thus an even number.
  58. #define MAX_MAP_PLANES 65536
  59. #define MAX_MAP_NODES 65536
  60. #define MAX_MAP_BRUSHSIDES 65536
  61. #define MAX_MAP_LEAFS 65536
  62. #define MAX_MAP_VERTS 65536
  63. #define MAX_MAP_VERTNORMALS 256000
  64. #define MAX_MAP_VERTNORMALINDICES 256000
  65. #define MAX_MAP_FACES 65536
  66. #define MAX_MAP_LEAFFACES 65536
  67. #define MAX_MAP_LEAFBRUSHES 65536
  68. #define MAX_MAP_PORTALS 65536
  69. #define MAX_MAP_CLUSTERS 65536
  70. #define MAX_MAP_LEAFWATERDATA 32768
  71. #define MAX_MAP_PORTALVERTS 128000
  72. #define MAX_MAP_EDGES 256000
  73. #define MAX_MAP_SURFEDGES 512000
  74. #define MAX_MAP_LIGHTING 0x1000000
  75. #define MAX_MAP_VISIBILITY 0x1000000 // increased BSPVERSION 7
  76. #define MAX_MAP_TEXTURES 1024
  77. #define MAX_MAP_WORLDLIGHTS 8192
  78. #define MAX_MAP_CUBEMAPSAMPLES 1024
  79. #define MAX_MAP_OVERLAYS 512
  80. #define MAX_MAP_WATEROVERLAYS 16384
  81. #define MAX_MAP_TEXDATA_STRING_DATA 256000
  82. #define MAX_MAP_TEXDATA_STRING_TABLE 65536
  83. // this is stuff for trilist/tristrips, etc.
  84. #define MAX_MAP_PRIMITIVES 32768
  85. #define MAX_MAP_PRIMVERTS 65536
  86. #define MAX_MAP_PRIMINDICES 65536
  87. #else
  88. // Xbox 360 - Force static arrays to be very small
  89. #define MAX_MAP_MODELS 2
  90. #define MAX_MAP_BRUSHES 2
  91. #define MAX_MAP_ENTITIES 2
  92. #define MAX_MAP_TEXINFO 2
  93. #define MAX_MAP_TEXDATA 2
  94. #define MAX_MAP_DISPINFO 2
  95. #define MAX_MAP_DISP_VERTS ( MAX_MAP_DISPINFO * ((1<<MAX_MAP_DISP_POWER)+1) * ((1<<MAX_MAP_DISP_POWER)+1) )
  96. #define MAX_MAP_DISP_TRIS ( (1 << MAX_MAP_DISP_POWER) * (1 << MAX_MAP_DISP_POWER) * 2 )
  97. #define MAX_DISPVERTS NUM_DISP_POWER_VERTS( MAX_MAP_DISP_POWER )
  98. #define MAX_DISPTRIS NUM_DISP_POWER_TRIS( MAX_MAP_DISP_POWER )
  99. #define MAX_MAP_AREAS 2
  100. #define MAX_MAP_AREA_BYTES 2
  101. #define MAX_MAP_AREAPORTALS 2
  102. #define MAX_MAP_PLANES 2
  103. #define MAX_MAP_NODES 2
  104. #define MAX_MAP_BRUSHSIDES 2
  105. #define MAX_MAP_LEAFS 2
  106. #define MAX_MAP_VERTS 2
  107. #define MAX_MAP_VERTNORMALS 2
  108. #define MAX_MAP_VERTNORMALINDICES 2
  109. #define MAX_MAP_FACES 2
  110. #define MAX_MAP_LEAFFACES 2
  111. #define MAX_MAP_LEAFBRUSHES 2
  112. #define MAX_MAP_PORTALS 2
  113. #define MAX_MAP_CLUSTERS 2
  114. #define MAX_MAP_LEAFWATERDATA 2
  115. #define MAX_MAP_PORTALVERTS 2
  116. #define MAX_MAP_EDGES 2
  117. #define MAX_MAP_SURFEDGES 2
  118. #define MAX_MAP_LIGHTING 2
  119. #define MAX_MAP_VISIBILITY 2
  120. #define MAX_MAP_TEXTURES 2
  121. #define MAX_MAP_WORLDLIGHTS 2
  122. #define MAX_MAP_CUBEMAPSAMPLES 2
  123. #define MAX_MAP_OVERLAYS 2
  124. #define MAX_MAP_WATEROVERLAYS 2
  125. #define MAX_MAP_TEXDATA_STRING_DATA 2
  126. #define MAX_MAP_TEXDATA_STRING_TABLE 2
  127. #define MAX_MAP_PRIMITIVES 2
  128. #define MAX_MAP_PRIMVERTS 2
  129. #define MAX_MAP_PRIMINDICES 2
  130. #endif // BSP_USE_LESS_MEMORY
  131. // key / value pair sizes
  132. #define MAX_KEY 32
  133. #define MAX_VALUE 1024
  134. // ------------------------------------------------------------------------------------------------ //
  135. // Displacement neighbor rules
  136. // ------------------------------------------------------------------------------------------------ //
  137. //
  138. // Each displacement is considered to be in its own space:
  139. //
  140. // NEIGHBOREDGE_TOP
  141. //
  142. // 1 --- 2
  143. // | |
  144. // NEIGHBOREDGE_LEFT | | NEIGHBOREDGE_RIGHT
  145. // | |
  146. // 0 --- 3
  147. //
  148. // NEIGHBOREDGE_BOTTOM
  149. //
  150. //
  151. // Edge edge of a displacement can have up to two neighbors. If it only has one neighbor
  152. // and the neighbor fills the edge, then SubNeighbor 0 uses CORNER_TO_CORNER (and SubNeighbor 1
  153. // is undefined).
  154. //
  155. // CORNER_TO_MIDPOINT means that it spans [bottom edge,midpoint] or [left edge,midpoint] depending
  156. // on which edge you're on.
  157. //
  158. // MIDPOINT_TO_CORNER means that it spans [midpoint,top edge] or [midpoint,right edge] depending
  159. // on which edge you're on.
  160. //
  161. // Here's an illustration (where C2M=CORNER_TO_MIDPOINT and M2C=MIDPOINT_TO_CORNER
  162. //
  163. //
  164. // C2M M2C
  165. //
  166. // 1 --------------> x --------------> 2
  167. //
  168. // ^ ^
  169. // | |
  170. // | |
  171. // M2C | | M2C
  172. // | |
  173. // | |
  174. //
  175. // x x x
  176. //
  177. // ^ ^
  178. // | |
  179. // | |
  180. // C2M | | C2M
  181. // | |
  182. // | |
  183. //
  184. // 0 --------------> x --------------> 3
  185. //
  186. // C2M M2C
  187. //
  188. //
  189. // The CHILDNODE_ defines can be used to refer to a node's child nodes (this is for when you're
  190. // recursing into the node tree inside a displacement):
  191. //
  192. // ---------
  193. // | | |
  194. // | 1 | 0 |
  195. // | | |
  196. // |---x---|
  197. // | | |
  198. // | 2 | 3 |
  199. // | | |
  200. // ---------
  201. //
  202. // ------------------------------------------------------------------------------------------------ //
  203. // These can be used to index g_ChildNodeIndexMul.
  204. enum
  205. {
  206. CHILDNODE_UPPER_RIGHT=0,
  207. CHILDNODE_UPPER_LEFT=1,
  208. CHILDNODE_LOWER_LEFT=2,
  209. CHILDNODE_LOWER_RIGHT=3
  210. };
  211. // Corner indices. Used to index m_CornerNeighbors.
  212. enum
  213. {
  214. CORNER_LOWER_LEFT=0,
  215. CORNER_UPPER_LEFT=1,
  216. CORNER_UPPER_RIGHT=2,
  217. CORNER_LOWER_RIGHT=3
  218. };
  219. // These edge indices must match the edge indices of the CCoreDispSurface.
  220. enum
  221. {
  222. NEIGHBOREDGE_LEFT=0,
  223. NEIGHBOREDGE_TOP=1,
  224. NEIGHBOREDGE_RIGHT=2,
  225. NEIGHBOREDGE_BOTTOM=3
  226. };
  227. // These denote where one dispinfo fits on another.
  228. // Note: tables are generated based on these indices so make sure to update
  229. // them if these indices are changed.
  230. typedef enum
  231. {
  232. CORNER_TO_CORNER=0,
  233. CORNER_TO_MIDPOINT=1,
  234. MIDPOINT_TO_CORNER=2
  235. } NeighborSpan;
  236. // These define relative orientations of displacement neighbors.
  237. typedef enum
  238. {
  239. ORIENTATION_CCW_0=0,
  240. ORIENTATION_CCW_90=1,
  241. ORIENTATION_CCW_180=2,
  242. ORIENTATION_CCW_270=3
  243. } NeighborOrientation;
  244. //=============================================================================
  245. enum
  246. {
  247. LUMP_ENTITIES = 0, // *
  248. LUMP_PLANES = 1, // *
  249. LUMP_TEXDATA = 2, // *
  250. LUMP_VERTEXES = 3, // *
  251. LUMP_VISIBILITY = 4, // *
  252. LUMP_NODES = 5, // *
  253. LUMP_TEXINFO = 6, // *
  254. LUMP_FACES = 7, // *
  255. LUMP_LIGHTING = 8, // *
  256. LUMP_OCCLUSION = 9,
  257. LUMP_LEAFS = 10, // *
  258. LUMP_FACEIDS = 11,
  259. LUMP_EDGES = 12, // *
  260. LUMP_SURFEDGES = 13, // *
  261. LUMP_MODELS = 14, // *
  262. LUMP_WORLDLIGHTS = 15, //
  263. LUMP_LEAFFACES = 16, // *
  264. LUMP_LEAFBRUSHES = 17, // *
  265. LUMP_BRUSHES = 18, // *
  266. LUMP_BRUSHSIDES = 19, // *
  267. LUMP_AREAS = 20, // *
  268. LUMP_AREAPORTALS = 21, // *
  269. LUMP_UNUSED0 = 22,
  270. LUMP_UNUSED1 = 23,
  271. LUMP_UNUSED2 = 24,
  272. LUMP_UNUSED3 = 25,
  273. LUMP_DISPINFO = 26,
  274. LUMP_ORIGINALFACES = 27,
  275. LUMP_PHYSDISP = 28,
  276. LUMP_PHYSCOLLIDE = 29,
  277. LUMP_VERTNORMALS = 30,
  278. LUMP_VERTNORMALINDICES = 31,
  279. LUMP_DISP_LIGHTMAP_ALPHAS = 32,
  280. LUMP_DISP_VERTS = 33, // CDispVerts
  281. LUMP_DISP_LIGHTMAP_SAMPLE_POSITIONS = 34, // For each displacement
  282. // For each lightmap sample
  283. // byte for index
  284. // if 255, then index = next byte + 255
  285. // 3 bytes for barycentric coordinates
  286. // The game lump is a method of adding game-specific lumps
  287. // FIXME: Eventually, all lumps could use the game lump system
  288. LUMP_GAME_LUMP = 35,
  289. LUMP_LEAFWATERDATA = 36,
  290. LUMP_PRIMITIVES = 37,
  291. LUMP_PRIMVERTS = 38,
  292. LUMP_PRIMINDICES = 39,
  293. // A pak file can be embedded in a .bsp now, and the file system will search the pak
  294. // file first for any referenced names, before deferring to the game directory
  295. // file system/pak files and finally the base directory file system/pak files.
  296. LUMP_PAKFILE = 40,
  297. LUMP_CLIPPORTALVERTS = 41,
  298. // A map can have a number of cubemap entities in it which cause cubemap renders
  299. // to be taken after running vrad.
  300. LUMP_CUBEMAPS = 42,
  301. LUMP_TEXDATA_STRING_DATA = 43,
  302. LUMP_TEXDATA_STRING_TABLE = 44,
  303. LUMP_OVERLAYS = 45,
  304. LUMP_LEAFMINDISTTOWATER = 46,
  305. LUMP_FACE_MACRO_TEXTURE_INFO = 47,
  306. LUMP_DISP_TRIS = 48,
  307. LUMP_PHYSCOLLIDESURFACE = 49, // deprecated. We no longer use win32-specific havok compression on terrain
  308. LUMP_WATEROVERLAYS = 50,
  309. LUMP_LEAF_AMBIENT_INDEX_HDR = 51, // index of LUMP_LEAF_AMBIENT_LIGHTING_HDR
  310. LUMP_LEAF_AMBIENT_INDEX = 52, // index of LUMP_LEAF_AMBIENT_LIGHTING
  311. // optional lumps for HDR
  312. LUMP_LIGHTING_HDR = 53,
  313. LUMP_WORLDLIGHTS_HDR = 54,
  314. LUMP_LEAF_AMBIENT_LIGHTING_HDR = 55, // NOTE: this data overrides part of the data stored in LUMP_LEAFS.
  315. LUMP_LEAF_AMBIENT_LIGHTING = 56, // NOTE: this data overrides part of the data stored in LUMP_LEAFS.
  316. LUMP_XZIPPAKFILE = 57, // deprecated. xbox 1: xzip version of pak file
  317. LUMP_FACES_HDR = 58, // HDR maps may have different face data.
  318. LUMP_MAP_FLAGS = 59, // extended level-wide flags. not present in all levels
  319. LUMP_OVERLAY_FADES = 60, // Fade distances for overlays
  320. };
  321. // Lumps that have versions are listed here
  322. enum
  323. {
  324. LUMP_LIGHTING_VERSION = 1,
  325. LUMP_FACES_VERSION = 1,
  326. LUMP_OCCLUSION_VERSION = 2,
  327. LUMP_LEAFS_VERSION = 1,
  328. LUMP_LEAF_AMBIENT_LIGHTING_VERSION = 1,
  329. };
  330. #define HEADER_LUMPS 64
  331. #include "zip_uncompressed.h"
  332. struct lump_t
  333. {
  334. DECLARE_BYTESWAP_DATADESC();
  335. int fileofs, filelen;
  336. int version; // default to zero
  337. // this field was char fourCC[4] previously, but was unused, favoring the LUMP IDs above instead. It has been
  338. // repurposed for compression. 0 implies the lump is not compressed.
  339. int uncompressedSize; // default to zero
  340. };
  341. struct dheader_t
  342. {
  343. DECLARE_BYTESWAP_DATADESC();
  344. int ident;
  345. int version;
  346. lump_t lumps[HEADER_LUMPS];
  347. int mapRevision; // the map's revision (iteration, version) number (added BSPVERSION 6)
  348. };
  349. // level feature flags
  350. #define LVLFLAGS_BAKED_STATIC_PROP_LIGHTING_NONHDR 0x00000001 // was processed by vrad with -staticproplighting, no hdr data
  351. #define LVLFLAGS_BAKED_STATIC_PROP_LIGHTING_HDR 0x00000002 // was processed by vrad with -staticproplighting, in hdr
  352. struct dflagslump_t
  353. {
  354. DECLARE_BYTESWAP_DATADESC();
  355. uint32 m_LevelFlags; // LVLFLAGS_xxx
  356. };
  357. struct lumpfileheader_t
  358. {
  359. int lumpOffset;
  360. int lumpID;
  361. int lumpVersion;
  362. int lumpLength;
  363. int mapRevision; // the map's revision (iteration, version) number (added BSPVERSION 6)
  364. };
  365. struct dgamelumpheader_t
  366. {
  367. DECLARE_BYTESWAP_DATADESC();
  368. int lumpCount;
  369. // dgamelump_t follow this
  370. };
  371. // This is expected to be a four-CC code ('lump')
  372. typedef int GameLumpId_t;
  373. // game lump is compressed, filelen reflects original size
  374. // use next entry fileofs to determine actual disk lump compressed size
  375. // compression stage ensures a terminal null dictionary entry
  376. #define GAMELUMPFLAG_COMPRESSED 0x0001
  377. struct dgamelump_t
  378. {
  379. DECLARE_BYTESWAP_DATADESC();
  380. GameLumpId_t id;
  381. unsigned short flags;
  382. unsigned short version;
  383. int fileofs;
  384. int filelen;
  385. };
  386. extern int g_MapRevision;
  387. struct dmodel_t
  388. {
  389. DECLARE_BYTESWAP_DATADESC();
  390. Vector mins, maxs;
  391. Vector origin; // for sounds or lights
  392. int headnode;
  393. int firstface, numfaces; // submodels just draw faces without walking the bsp tree
  394. };
  395. struct dphysmodel_t
  396. {
  397. DECLARE_BYTESWAP_DATADESC()
  398. int modelIndex;
  399. int dataSize;
  400. int keydataSize;
  401. int solidCount;
  402. };
  403. // contains the binary blob for each displacement surface's virtual hull
  404. struct dphysdisp_t
  405. {
  406. DECLARE_BYTESWAP_DATADESC()
  407. unsigned short numDisplacements;
  408. //unsigned short dataSize[numDisplacements];
  409. };
  410. struct dvertex_t
  411. {
  412. DECLARE_BYTESWAP_DATADESC();
  413. Vector point;
  414. };
  415. // planes (x&~1) and (x&~1)+1 are always opposites
  416. struct dplane_t
  417. {
  418. DECLARE_BYTESWAP_DATADESC();
  419. Vector normal;
  420. float dist;
  421. int type; // PLANE_X - PLANE_ANYZ ?remove? trivial to regenerate
  422. };
  423. #ifndef BSPFLAGS_H
  424. #include "bspflags.h"
  425. #endif
  426. struct dnode_t
  427. {
  428. DECLARE_BYTESWAP_DATADESC();
  429. int planenum;
  430. int children[2]; // negative numbers are -(leafs+1), not nodes
  431. short mins[3]; // for frustom culling
  432. short maxs[3];
  433. unsigned short firstface;
  434. unsigned short numfaces; // counting both sides
  435. short area; // If all leaves below this node are in the same area, then
  436. // this is the area index. If not, this is -1.
  437. };
  438. typedef struct texinfo_s
  439. {
  440. DECLARE_BYTESWAP_DATADESC();
  441. float textureVecsTexelsPerWorldUnits[2][4]; // [s/t][xyz offset]
  442. float lightmapVecsLuxelsPerWorldUnits[2][4]; // [s/t][xyz offset] - length is in units of texels/area
  443. int flags; // miptex flags + overrides
  444. int texdata; // Pointer to texture name, size, etc.
  445. } texinfo_t;
  446. #define TEXTURE_NAME_LENGTH 128 // changed from 64 BSPVERSION 8
  447. struct dtexdata_t
  448. {
  449. DECLARE_BYTESWAP_DATADESC();
  450. Vector reflectivity;
  451. int nameStringTableID; // index into g_StringTable for the texture name
  452. int width, height; // source image
  453. int view_width, view_height; //
  454. };
  455. //-----------------------------------------------------------------------------
  456. // Occluders are simply polygons
  457. //-----------------------------------------------------------------------------
  458. // Flags field of doccluderdata_t
  459. enum
  460. {
  461. OCCLUDER_FLAGS_INACTIVE = 0x1,
  462. };
  463. struct doccluderdata_t
  464. {
  465. DECLARE_BYTESWAP_DATADESC();
  466. int flags;
  467. int firstpoly; // index into doccluderpolys
  468. int polycount;
  469. Vector mins;
  470. Vector maxs;
  471. int area;
  472. };
  473. struct doccluderdataV1_t
  474. {
  475. int flags;
  476. int firstpoly; // index into doccluderpolys
  477. int polycount;
  478. Vector mins;
  479. Vector maxs;
  480. };
  481. struct doccluderpolydata_t
  482. {
  483. DECLARE_BYTESWAP_DATADESC();
  484. int firstvertexindex; // index into doccludervertindices
  485. int vertexcount;
  486. int planenum;
  487. };
  488. // NOTE: see the section above titled "displacement neighbor rules".
  489. struct CDispSubNeighbor
  490. {
  491. public:
  492. DECLARE_BYTESWAP_DATADESC();
  493. unsigned short GetNeighborIndex() const { return m_iNeighbor; }
  494. NeighborSpan GetSpan() const { return (NeighborSpan)m_Span; }
  495. NeighborSpan GetNeighborSpan() const { return (NeighborSpan)m_NeighborSpan; }
  496. NeighborOrientation GetNeighborOrientation() const { return (NeighborOrientation)m_NeighborOrientation; }
  497. bool IsValid() const { return m_iNeighbor != 0xFFFF; }
  498. void SetInvalid() { m_iNeighbor = 0xFFFF; }
  499. public:
  500. unsigned short m_iNeighbor; // This indexes into ddispinfos.
  501. // 0xFFFF if there is no neighbor here.
  502. unsigned char m_NeighborOrientation; // (CCW) rotation of the neighbor wrt this displacement.
  503. // These use the NeighborSpan type.
  504. unsigned char m_Span; // Where the neighbor fits onto this side of our displacement.
  505. unsigned char m_NeighborSpan; // Where we fit onto our neighbor.
  506. };
  507. // NOTE: see the section above titled "displacement neighbor rules".
  508. class CDispNeighbor
  509. {
  510. public:
  511. DECLARE_BYTESWAP_DATADESC();
  512. void SetInvalid() { m_SubNeighbors[0].SetInvalid(); m_SubNeighbors[1].SetInvalid(); }
  513. // Returns false if there isn't anything touching this edge.
  514. bool IsValid() { return m_SubNeighbors[0].IsValid() || m_SubNeighbors[1].IsValid(); }
  515. public:
  516. // Note: if there is a neighbor that fills the whole side (CORNER_TO_CORNER),
  517. // then it will always be in CDispNeighbor::m_Neighbors[0]
  518. CDispSubNeighbor m_SubNeighbors[2];
  519. };
  520. class CDispCornerNeighbors
  521. {
  522. public:
  523. DECLARE_BYTESWAP_DATADESC();
  524. void SetInvalid() { m_nNeighbors = 0; }
  525. public:
  526. unsigned short m_Neighbors[MAX_DISP_CORNER_NEIGHBORS]; // indices of neighbors.
  527. unsigned char m_nNeighbors;
  528. };
  529. class CDispVert
  530. {
  531. public:
  532. DECLARE_BYTESWAP_DATADESC();
  533. Vector m_vVector; // Vector field defining displacement volume.
  534. float m_flDist; // Displacement distances.
  535. float m_flAlpha; // "per vertex" alpha values.
  536. };
  537. #define DISPTRI_TAG_SURFACE (1<<0)
  538. #define DISPTRI_TAG_WALKABLE (1<<1)
  539. #define DISPTRI_TAG_BUILDABLE (1<<2)
  540. #define DISPTRI_FLAG_SURFPROP1 (1<<3)
  541. #define DISPTRI_FLAG_SURFPROP2 (1<<4)
  542. #define DISPTRI_TAG_REMOVE (1<<5)
  543. class CDispTri
  544. {
  545. public:
  546. DECLARE_BYTESWAP_DATADESC();
  547. unsigned short m_uiTags; // Displacement triangle tags.
  548. };
  549. class ddispinfo_t
  550. {
  551. public:
  552. DECLARE_BYTESWAP_DATADESC();
  553. int NumVerts() const { return NUM_DISP_POWER_VERTS(power); }
  554. int NumTris() const { return NUM_DISP_POWER_TRIS(power); }
  555. public:
  556. Vector startPosition; // start position used for orientation -- (added BSPVERSION 6)
  557. int m_iDispVertStart; // Index into LUMP_DISP_VERTS.
  558. int m_iDispTriStart; // Index into LUMP_DISP_TRIS.
  559. int power; // power - indicates size of map (2^power + 1)
  560. int minTess; // minimum tesselation allowed
  561. float smoothingAngle; // lighting smoothing angle
  562. int contents; // surface contents
  563. unsigned short m_iMapFace; // Which map face this displacement comes from.
  564. int m_iLightmapAlphaStart; // Index into ddisplightmapalpha.
  565. // The count is m_pParent->lightmapTextureSizeInLuxels[0]*m_pParent->lightmapTextureSizeInLuxels[1].
  566. int m_iLightmapSamplePositionStart; // Index into LUMP_DISP_LIGHTMAP_SAMPLE_POSITIONS.
  567. CDispNeighbor m_EdgeNeighbors[4]; // Indexed by NEIGHBOREDGE_ defines.
  568. CDispCornerNeighbors m_CornerNeighbors[4]; // Indexed by CORNER_ defines.
  569. enum unnamed { ALLOWEDVERTS_SIZE = PAD_NUMBER( MAX_DISPVERTS, 32 ) / 32 };
  570. unsigned long m_AllowedVerts[ALLOWEDVERTS_SIZE]; // This is built based on the layout and sizes of our neighbors
  571. // and tells us which vertices are allowed to be active.
  572. };
  573. // note that edge 0 is never used, because negative edge nums are used for
  574. // counterclockwise use of the edge in a face
  575. struct dedge_t
  576. {
  577. DECLARE_BYTESWAP_DATADESC();
  578. unsigned short v[2]; // vertex numbers
  579. };
  580. #define MAXLIGHTMAPS 4
  581. enum dprimitive_type
  582. {
  583. PRIM_TRILIST=0,
  584. PRIM_TRISTRIP=1,
  585. };
  586. struct dprimitive_t
  587. {
  588. DECLARE_BYTESWAP_DATADESC();
  589. unsigned char type;
  590. unsigned short firstIndex;
  591. unsigned short indexCount;
  592. unsigned short firstVert;
  593. unsigned short vertCount;
  594. };
  595. struct dprimvert_t
  596. {
  597. DECLARE_BYTESWAP_DATADESC();
  598. Vector pos;
  599. };
  600. struct dface_t
  601. {
  602. DECLARE_BYTESWAP_DATADESC();
  603. unsigned short planenum;
  604. byte side; // faces opposite to the node's plane direction
  605. byte onNode; // 1 of on node, 0 if in leaf
  606. int firstedge; // we must support > 64k edges
  607. short numedges;
  608. short texinfo;
  609. // This is a union under the assumption that a fog volume boundary (ie. water surface)
  610. // isn't a displacement map.
  611. // FIXME: These should be made a union with a flags or type field for which one it is
  612. // if we can add more to this.
  613. // union
  614. // {
  615. short dispinfo;
  616. // This is only for surfaces that are the boundaries of fog volumes
  617. // (ie. water surfaces)
  618. // All of the rest of the surfaces can look at their leaf to find out
  619. // what fog volume they are in.
  620. short surfaceFogVolumeID;
  621. // };
  622. // lighting info
  623. byte styles[MAXLIGHTMAPS];
  624. int lightofs; // start of [numstyles*surfsize] samples
  625. float area;
  626. // TODO: make these unsigned chars?
  627. int m_LightmapTextureMinsInLuxels[2];
  628. int m_LightmapTextureSizeInLuxels[2];
  629. int origFace; // reference the original face this face was derived from
  630. public:
  631. unsigned short GetNumPrims() const;
  632. void SetNumPrims( unsigned short nPrims );
  633. bool AreDynamicShadowsEnabled();
  634. void SetDynamicShadowsEnabled( bool bEnabled );
  635. // non-polygon primitives (strips and lists)
  636. private:
  637. unsigned short m_NumPrims; // Top bit, if set, disables shadows on this surface (this is why there are accessors).
  638. public:
  639. unsigned short firstPrimID;
  640. unsigned int smoothingGroups;
  641. };
  642. inline unsigned short dface_t::GetNumPrims() const
  643. {
  644. return m_NumPrims & 0x7FFF;
  645. }
  646. inline void dface_t::SetNumPrims( unsigned short nPrims )
  647. {
  648. Assert( (nPrims & 0x8000) == 0 );
  649. m_NumPrims &= ~0x7FFF;
  650. m_NumPrims |= (nPrims & 0x7FFF);
  651. }
  652. inline bool dface_t::AreDynamicShadowsEnabled()
  653. {
  654. return (m_NumPrims & 0x8000) == 0;
  655. }
  656. inline void dface_t::SetDynamicShadowsEnabled( bool bEnabled )
  657. {
  658. if ( bEnabled )
  659. m_NumPrims &= ~0x8000;
  660. else
  661. m_NumPrims |= 0x8000;
  662. }
  663. struct dfaceid_t
  664. {
  665. DECLARE_BYTESWAP_DATADESC();
  666. unsigned short hammerfaceid;
  667. };
  668. // NOTE: Only 7-bits stored!!!
  669. #define LEAF_FLAGS_SKY 0x01 // This leaf has 3D sky in its PVS
  670. #define LEAF_FLAGS_RADIAL 0x02 // This leaf culled away some portals due to radial vis
  671. #define LEAF_FLAGS_SKY2D 0x04 // This leaf has 2D sky in its PVS
  672. #if defined( _X360 )
  673. #pragma bitfield_order( push, lsb_to_msb )
  674. #endif
  675. #pragma warning( disable:4201 ) // C4201: nonstandard extension used: nameless struct/union
  676. struct dleaf_version_0_t
  677. {
  678. DECLARE_BYTESWAP_DATADESC();
  679. int contents; // OR of all brushes (not needed?)
  680. short cluster;
  681. BEGIN_BITFIELD( bf );
  682. short area:9;
  683. short flags:7; // Per leaf flags.
  684. END_BITFIELD();
  685. short mins[3]; // for frustum culling
  686. short maxs[3];
  687. unsigned short firstleafface;
  688. unsigned short numleaffaces;
  689. unsigned short firstleafbrush;
  690. unsigned short numleafbrushes;
  691. short leafWaterDataID; // -1 for not in water
  692. // Precaculated light info for entities.
  693. CompressedLightCube m_AmbientLighting;
  694. };
  695. // version 1
  696. struct dleaf_t
  697. {
  698. DECLARE_BYTESWAP_DATADESC();
  699. int contents; // OR of all brushes (not needed?)
  700. short cluster;
  701. BEGIN_BITFIELD( bf );
  702. short area:9;
  703. short flags:7; // Per leaf flags.
  704. END_BITFIELD();
  705. short mins[3]; // for frustum culling
  706. short maxs[3];
  707. unsigned short firstleafface;
  708. unsigned short numleaffaces;
  709. unsigned short firstleafbrush;
  710. unsigned short numleafbrushes;
  711. short leafWaterDataID; // -1 for not in water
  712. // NOTE: removed this for version 1 and moved into separate lump "LUMP_LEAF_AMBIENT_LIGHTING" or "LUMP_LEAF_AMBIENT_LIGHTING_HDR"
  713. // Precaculated light info for entities.
  714. // CompressedLightCube m_AmbientLighting;
  715. };
  716. #pragma warning( default:4201 ) // C4201: nonstandard extension used: nameless struct/union
  717. #if defined( _X360 )
  718. #pragma bitfield_order( pop )
  719. #endif
  720. // each leaf contains N samples of the ambient lighting
  721. // each sample contains a cube of ambient light projected on to each axis
  722. // and a sampling position encoded as a 0.8 fraction (mins=0,maxs=255) of the leaf's bounding box
  723. struct dleafambientlighting_t
  724. {
  725. DECLARE_BYTESWAP_DATADESC();
  726. CompressedLightCube cube;
  727. byte x; // fixed point fraction of leaf bounds
  728. byte y; // fixed point fraction of leaf bounds
  729. byte z; // fixed point fraction of leaf bounds
  730. byte pad; // unused
  731. };
  732. struct dleafambientindex_t
  733. {
  734. DECLARE_BYTESWAP_DATADESC();
  735. unsigned short ambientSampleCount;
  736. unsigned short firstAmbientSample;
  737. };
  738. struct dbrushside_t
  739. {
  740. DECLARE_BYTESWAP_DATADESC();
  741. unsigned short planenum; // facing out of the leaf
  742. short texinfo;
  743. short dispinfo; // displacement info (BSPVERSION 7)
  744. short bevel; // is the side a bevel plane? (BSPVERSION 7)
  745. };
  746. struct dbrush_t
  747. {
  748. DECLARE_BYTESWAP_DATADESC();
  749. int firstside;
  750. int numsides;
  751. int contents;
  752. };
  753. #define ANGLE_UP -1
  754. #define ANGLE_DOWN -2
  755. // the visibility lump consists of a header with a count, then
  756. // byte offsets for the PVS and PHS of each cluster, then the raw
  757. // compressed bit vectors
  758. #define DVIS_PVS 0
  759. #define DVIS_PAS 1
  760. struct dvis_t
  761. {
  762. int numclusters;
  763. int bitofs[8][2]; // bitofs[numclusters][2]
  764. };
  765. // each area has a list of portals that lead into other areas
  766. // when portals are closed, other areas may not be visible or
  767. // hearable even if the vis info says that it should be
  768. struct dareaportal_t
  769. {
  770. DECLARE_BYTESWAP_DATADESC();
  771. unsigned short m_PortalKey; // Entities have a key called portalnumber (and in vbsp a variable
  772. // called areaportalnum) which is used
  773. // to bind them to the area portals by comparing with this value.
  774. unsigned short otherarea; // The area this portal looks into.
  775. unsigned short m_FirstClipPortalVert; // Portal geometry.
  776. unsigned short m_nClipPortalVerts;
  777. int planenum;
  778. };
  779. struct darea_t
  780. {
  781. DECLARE_BYTESWAP_DATADESC();
  782. int numareaportals;
  783. int firstareaportal;
  784. };
  785. struct dleafwaterdata_t
  786. {
  787. DECLARE_BYTESWAP_DATADESC();
  788. float surfaceZ;
  789. float minZ;
  790. short surfaceTexInfoID;
  791. };
  792. class CFaceMacroTextureInfo
  793. {
  794. public:
  795. DECLARE_BYTESWAP_DATADESC();
  796. // This looks up into g_TexDataStringTable, which looks up into g_TexDataStringData.
  797. // 0xFFFF if the face has no macro texture.
  798. unsigned short m_MacroTextureNameID;
  799. };
  800. // lights that were used to illuminate the world
  801. enum emittype_t
  802. {
  803. emit_surface, // 90 degree spotlight
  804. emit_point, // simple point light source
  805. emit_spotlight, // spotlight with penumbra
  806. emit_skylight, // directional light with no falloff (surface must trace to SKY texture)
  807. emit_quakelight, // linear falloff, non-lambertian
  808. emit_skyambient, // spherical light source with no falloff (surface must trace to SKY texture)
  809. };
  810. // Flags for dworldlight_t::flags
  811. #define DWL_FLAGS_INAMBIENTCUBE 0x0001 // This says that the light was put into the per-leaf ambient cubes.
  812. struct dworldlight_t
  813. {
  814. DECLARE_BYTESWAP_DATADESC();
  815. Vector origin;
  816. Vector intensity;
  817. Vector normal; // for surfaces and spotlights
  818. int cluster;
  819. emittype_t type;
  820. int style;
  821. float stopdot; // start of penumbra for emit_spotlight
  822. float stopdot2; // end of penumbra for emit_spotlight
  823. float exponent; //
  824. float radius; // cutoff distance
  825. // falloff for emit_spotlight + emit_point:
  826. // 1 / (constant_attn + linear_attn * dist + quadratic_attn * dist^2)
  827. float constant_attn;
  828. float linear_attn;
  829. float quadratic_attn;
  830. int flags; // Uses a combination of the DWL_FLAGS_ defines.
  831. int texinfo; //
  832. int owner; // entity that this light it relative to
  833. };
  834. struct dcubemapsample_t
  835. {
  836. DECLARE_BYTESWAP_DATADESC();
  837. int origin[3]; // position of light snapped to the nearest integer
  838. // the filename for the vtf file is derived from the position
  839. unsigned char size; // 0 - default
  840. // otherwise, 1<<(size-1)
  841. };
  842. #define OVERLAY_BSP_FACE_COUNT 64
  843. #define OVERLAY_NUM_RENDER_ORDERS (1<<OVERLAY_RENDER_ORDER_NUM_BITS)
  844. #define OVERLAY_RENDER_ORDER_NUM_BITS 2
  845. #define OVERLAY_RENDER_ORDER_MASK 0xC000 // top 2 bits set
  846. struct doverlay_t
  847. {
  848. DECLARE_BYTESWAP_DATADESC();
  849. int nId;
  850. short nTexInfo;
  851. // Accessors..
  852. void SetFaceCount( unsigned short count );
  853. unsigned short GetFaceCount() const;
  854. void SetRenderOrder( unsigned short order );
  855. unsigned short GetRenderOrder() const;
  856. private:
  857. unsigned short m_nFaceCountAndRenderOrder;
  858. public:
  859. int aFaces[OVERLAY_BSP_FACE_COUNT];
  860. float flU[2];
  861. float flV[2];
  862. Vector vecUVPoints[4];
  863. Vector vecOrigin;
  864. Vector vecBasisNormal;
  865. };
  866. inline void doverlay_t::SetFaceCount( unsigned short count )
  867. {
  868. m_nFaceCountAndRenderOrder &= OVERLAY_RENDER_ORDER_MASK;
  869. m_nFaceCountAndRenderOrder |= (count & ~OVERLAY_RENDER_ORDER_MASK);
  870. }
  871. inline unsigned short doverlay_t::GetFaceCount() const
  872. {
  873. return m_nFaceCountAndRenderOrder & ~OVERLAY_RENDER_ORDER_MASK;
  874. }
  875. inline void doverlay_t::SetRenderOrder( unsigned short order )
  876. {
  877. m_nFaceCountAndRenderOrder &= ~OVERLAY_RENDER_ORDER_MASK;
  878. m_nFaceCountAndRenderOrder |= (order << (16 - OVERLAY_RENDER_ORDER_NUM_BITS)); // leave 2 bits for render order.
  879. }
  880. inline unsigned short doverlay_t::GetRenderOrder() const
  881. {
  882. return (m_nFaceCountAndRenderOrder >> (16 - OVERLAY_RENDER_ORDER_NUM_BITS));
  883. }
  884. struct doverlayfade_t
  885. {
  886. DECLARE_BYTESWAP_DATADESC();
  887. float flFadeDistMinSq;
  888. float flFadeDistMaxSq;
  889. };
  890. #define WATEROVERLAY_BSP_FACE_COUNT 256
  891. #define WATEROVERLAY_RENDER_ORDER_NUM_BITS 2
  892. #define WATEROVERLAY_NUM_RENDER_ORDERS (1<<WATEROVERLAY_RENDER_ORDER_NUM_BITS)
  893. #define WATEROVERLAY_RENDER_ORDER_MASK 0xC000 // top 2 bits set
  894. struct dwateroverlay_t
  895. {
  896. DECLARE_BYTESWAP_DATADESC();
  897. int nId;
  898. short nTexInfo;
  899. // Accessors..
  900. void SetFaceCount( unsigned short count );
  901. unsigned short GetFaceCount() const;
  902. void SetRenderOrder( unsigned short order );
  903. unsigned short GetRenderOrder() const;
  904. private:
  905. unsigned short m_nFaceCountAndRenderOrder;
  906. public:
  907. int aFaces[WATEROVERLAY_BSP_FACE_COUNT];
  908. float flU[2];
  909. float flV[2];
  910. Vector vecUVPoints[4];
  911. Vector vecOrigin;
  912. Vector vecBasisNormal;
  913. };
  914. inline void dwateroverlay_t::SetFaceCount( unsigned short count )
  915. {
  916. m_nFaceCountAndRenderOrder &= WATEROVERLAY_RENDER_ORDER_MASK;
  917. m_nFaceCountAndRenderOrder |= (count & ~WATEROVERLAY_RENDER_ORDER_MASK);
  918. }
  919. inline unsigned short dwateroverlay_t::GetFaceCount() const
  920. {
  921. return m_nFaceCountAndRenderOrder & ~WATEROVERLAY_RENDER_ORDER_MASK;
  922. }
  923. inline void dwateroverlay_t::SetRenderOrder( unsigned short order )
  924. {
  925. m_nFaceCountAndRenderOrder &= ~WATEROVERLAY_RENDER_ORDER_MASK;
  926. m_nFaceCountAndRenderOrder |= ( order << ( 16 - WATEROVERLAY_RENDER_ORDER_NUM_BITS ) ); // leave 2 bits for render order.
  927. }
  928. inline unsigned short dwateroverlay_t::GetRenderOrder() const
  929. {
  930. return ( m_nFaceCountAndRenderOrder >> ( 16 - WATEROVERLAY_RENDER_ORDER_NUM_BITS ) );
  931. }
  932. #ifndef _DEF_BYTE_
  933. #define _DEF_BYTE_
  934. typedef unsigned char byte;
  935. typedef unsigned short word;
  936. #endif
  937. #define ANGLE_UP -1
  938. #define ANGLE_DOWN -2
  939. //===============
  940. struct epair_t
  941. {
  942. epair_t *next;
  943. char *key;
  944. char *value;
  945. };
  946. // finalized page of surface's lightmaps
  947. #define MAX_LIGHTMAPPAGE_WIDTH 256
  948. #define MAX_LIGHTMAPPAGE_HEIGHT 128
  949. typedef struct nameForDatadesc_dlightmappage_t // unnamed structs collide in the datadesc macros
  950. {
  951. DECLARE_BYTESWAP_DATADESC();
  952. byte data[MAX_LIGHTMAPPAGE_WIDTH*MAX_LIGHTMAPPAGE_HEIGHT];
  953. byte palette[256*4];
  954. } dlightmappage_t;
  955. typedef struct nameForDatadesc_dlightmappageinfo_t // unnamed structs collide in the datadesc macros
  956. {
  957. DECLARE_BYTESWAP_DATADESC();
  958. byte page; // lightmap page [0..?]
  959. byte offset[2]; // offset into page (s,t)
  960. byte pad; // unused
  961. ColorRGBExp32 avgColor; // average used for runtime lighting calcs
  962. } dlightmappageinfo_t;
  963. #endif // BSPFILE_H