Counter Strike : Global Offensive Source Code
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.

1305 lines
37 KiB

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