bsp.h 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232
  1. /*
  2. ==============================================================================
  3. Common stuff
  4. ==============================================================================
  5. */
  6. #define MAX_QPATH 64 // max length of a quake game pathname
  7. typedef float vec_t;
  8. typedef vec_t vec2_t[2];
  9. typedef vec_t vec3_t[3];
  10. typedef vec_t vec4_t[4];
  11. typedef vec_t vec5_t[5];
  12. typedef unsigned char byte;
  13. #define LIGHTMAP_SIZE 128
  14. #define LIGHTMAP_BY_VERTEX -3 // pre-lit triangle models
  15. #define POINTS_ST_SCALE 128.0f
  16. #define POINTS_LIGHT_SCALE 65536.0f
  17. /*
  18. ==============================================================================
  19. .BSP file format
  20. ==============================================================================
  21. */
  22. #define BSP_IDENT (('P'<<24)+('S'<<16)+('B'<<8)+'R')
  23. #define BSP_VERSION 1
  24. // there shouldn't be any problem with increasing these values at the
  25. // expense of more memory allocation in the utilities
  26. #define MAX_MAP_MODELS 0x400
  27. #define MAX_MAP_BRUSHES 0x8000
  28. #define MAX_MAP_ENTITIES 0x800
  29. #define MAX_MAP_ENTSTRING 0x40000
  30. #define MAX_MAP_SHADERS 0x400
  31. #define MAX_MAP_AREAS 0x100 // MAX_MAP_AREA_BYTES in q_shared must match!
  32. #define MAX_MAP_FOGS 0x100
  33. #define MAX_MAP_PLANES 0x20000
  34. #define MAX_MAP_NODES 0x20000
  35. #define MAX_MAP_BRUSHSIDES 0x20000
  36. #define MAX_MAP_LEAFS 0x20000
  37. #define MAX_MAP_LEAFFACES 0x20000
  38. #define MAX_MAP_LEAFBRUSHES 0x40000
  39. #define MAX_MAP_PORTALS 0x20000
  40. #define MAX_MAP_LIGHTING 0x800000
  41. #define MAX_MAP_LIGHTGRID 65535
  42. #define MAX_MAP_LIGHTGRID_ARRAY 0x100000
  43. #define MAX_MAP_VISIBILITY 0x400000
  44. #define MAX_MAP_DRAW_SURFS 0x20000
  45. #define MAX_MAP_DRAW_VERTS 0x80000
  46. #define MAX_MAP_DRAW_INDEXES 0x80000
  47. // key / value pair sizes in the entities lump
  48. #define MAX_KEY 32
  49. #define MAX_VALUE 1024
  50. // the editor uses these predefined yaw angles to orient entities up or down
  51. #define ANGLE_UP -1
  52. #define ANGLE_DOWN -2
  53. #define LIGHTMAP_WIDTH 128
  54. #define LIGHTMAP_HEIGHT 128
  55. //=============================================================================
  56. typedef struct {
  57. int fileofs, filelen;
  58. } lump_t;
  59. #define LUMP_ENTITIES 0
  60. #define LUMP_SHADERS 1
  61. #define LUMP_PLANES 2
  62. #define LUMP_NODES 3
  63. #define LUMP_LEAFS 4
  64. #define LUMP_LEAFSURFACES 5
  65. #define LUMP_LEAFBRUSHES 6
  66. #define LUMP_MODELS 7
  67. #define LUMP_BRUSHES 8
  68. #define LUMP_BRUSHSIDES 9
  69. #define LUMP_DRAWVERTS 10
  70. #define LUMP_DRAWINDEXES 11
  71. #define LUMP_FOGS 12
  72. #define LUMP_SURFACES 13
  73. #define LUMP_LIGHTMAPS 14
  74. #define LUMP_LIGHTGRID 15
  75. #define LUMP_VISIBILITY 16
  76. #define LUMP_LIGHTARRAY 17
  77. #define HEADER_LUMPS 18
  78. typedef struct {
  79. int ident;
  80. int version;
  81. lump_t lumps[HEADER_LUMPS];
  82. } dheader_t;
  83. typedef struct {
  84. float mins[3], maxs[3];
  85. int firstSurface, numSurfaces;
  86. int firstBrush, numBrushes;
  87. } dmodel_t;
  88. typedef struct {
  89. char shader[MAX_QPATH];
  90. int surfaceFlags;
  91. int contentFlags;
  92. } dshader_t;
  93. // planes x^1 is allways the opposite of plane x
  94. typedef struct {
  95. float normal[3];
  96. float dist;
  97. } dplane_t;
  98. typedef struct {
  99. int planeNum;
  100. int children[2]; // negative numbers are -(leafs+1), not nodes
  101. int mins[3]; // for frustom culling
  102. int maxs[3];
  103. } dnode_t;
  104. typedef struct {
  105. int cluster; // -1 = opaque cluster (do I still store these?)
  106. int area;
  107. int mins[3]; // for frustum culling
  108. int maxs[3];
  109. int firstLeafSurface;
  110. int numLeafSurfaces;
  111. int firstLeafBrush;
  112. int numLeafBrushes;
  113. } dleaf_t;
  114. typedef struct {
  115. int planeNum; // positive plane side faces out of the leaf
  116. int shaderNum;
  117. int drawSurfNum;
  118. } dbrushside_t;
  119. typedef struct {
  120. int firstSide;
  121. int numSides;
  122. int shaderNum; // the shader that determines the contents flags
  123. } dbrush_t;
  124. typedef struct {
  125. char shader[MAX_QPATH];
  126. int brushNum;
  127. int visibleSide; // the brush side that ray tests need to clip against (-1 == none)
  128. } dfog_t;
  129. // Light Style Constants
  130. #define MAXLIGHTMAPS 4
  131. #define LS_NORMAL 0x00
  132. #define LS_UNUSED 0xfe
  133. #define LS_NONE 0xff
  134. #define MAX_LIGHT_STYLES 64
  135. typedef struct {
  136. vec3_t xyz;
  137. float st[2];
  138. float lightmap[MAXLIGHTMAPS][2];
  139. vec3_t normal;
  140. byte color[MAXLIGHTMAPS][4];
  141. } mapVert_t;
  142. #define DRAWVERT_LIGHTMAP_SCALE 32768.0f
  143. #define DRAWVERT_ST_SCALE 16.0f
  144. typedef struct {
  145. vec3_t xyz;
  146. short dvst[2];
  147. short dvlightmap[MAXLIGHTMAPS][2];
  148. vec3_t normal;
  149. byte dvcolor[MAXLIGHTMAPS][2];
  150. } drawVert_t;
  151. typedef struct
  152. {
  153. byte ambientLight[MAXLIGHTMAPS][3];
  154. byte directLight[MAXLIGHTMAPS][3];
  155. byte styles[MAXLIGHTMAPS];
  156. byte latLong[2];
  157. } dgrid_t;
  158. typedef enum {
  159. MST_BAD,
  160. MST_PLANAR,
  161. MST_PATCH,
  162. MST_TRIANGLE_SOUP,
  163. MST_FLARE
  164. } mapSurfaceType_t;
  165. typedef struct {
  166. int shaderNum;
  167. int fogNum;
  168. int surfaceType;
  169. int firstVert;
  170. int numVerts;
  171. int firstIndex;
  172. int numIndexes;
  173. byte lightmapStyles[MAXLIGHTMAPS], vertexStyles[MAXLIGHTMAPS];
  174. int lightmapNum[MAXLIGHTMAPS];
  175. int lightmapX[MAXLIGHTMAPS], lightmapY[MAXLIGHTMAPS];
  176. int lightmapWidth, lightmapHeight;
  177. vec3_t lightmapOrigin;
  178. vec3_t lightmapVecs[3]; // for patches, [0] and [1] are lodbounds
  179. int patchWidth;
  180. int patchHeight;
  181. } dsurface_t;