bspfile.h 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422
  1. #ifndef BSPFILE_H__
  2. #define BSPFILE_H__
  3. #if _MSC_VER >= 1000
  4. #pragma once
  5. #endif
  6. // upper design bounds
  7. #define MAX_MAP_HULLS 4
  8. // hard limit
  9. #define MAX_MAP_MODELS 512 //400 //PROTECTOR
  10. // variable, but 400 brush entities is very stressful on the engine and network code as it is.
  11. // note that 512 is the absolute limit - maps won't load if that many models are precached.
  12. // models include unqiue *.mdl- and *.spr-files appearing in the map as well as one model for
  13. // each unique brush entity. For the *.mdl and *.spr-files, there are exceptions, though.
  14. // E.g., player models and HUD sprites & targas don't fall under the limit.
  15. #define MAX_MAP_BRUSHES 131072 //32768 //SILENCER
  16. // arbitrary, but large numbers of brushes generally require more lightmap's than the compiler can handle
  17. #define MAX_ENGINE_ENTITIES 523264 //1024 //SILENCER
  18. #define MAX_MAP_ENTITIES 1046528 //2048 //SILENCER
  19. // variable, since the -num_edcits # parameter has been added
  20. // in actuallity it is too much, as temporary entities in the game plus static map entities can overflow
  21. #define MAX_MAP_ENTSTRING 16384*1024 //(512*1024) //SILENCER
  22. // abitrary, 512Kb of string data should be plenty even with TFC FGD's
  23. // SILENCER: You can NEVER have enough of this,
  24. // especially not in Sven Co-op, with all those squadmakers and game_text entities
  25. // SILENCER: The following two are hard limits. Tried doing more, but just as said in that
  26. // mail from ages ago, some faces just don't show up and ocassionally, the game crashes.
  27. // Note: The integrated plane optimization by XP-Cagey takes action before the limit check.
  28. #define MAX_MAP_PLANES 32767 //32768 //SILENCER: Considering the high chance of shorts being used for this
  29. #define MAX_INTERNAL_MAP_PLANES 256*1024
  30. // (from email): I have been building a rather complicated map, and using your latest
  31. // tools (1.61) it seemed to compile fine. However, in game, the engine was dropping
  32. // a lot of faces from almost every FUNC_WALL, and also caused a strange texture
  33. // phenomenon in software mode (see attached screen shot). When I compiled with v1.41,
  34. // I noticed that it hit the MAX_MAP_PLANES limit of 32k. After deleting some brushes
  35. // I was able to bring the map under the limit, and all of the previous errors went away.
  36. #define MAX_MAP_NODES 32767
  37. // hard limit (negative short's are used as contents values)
  38. #define MAX_MAP_CLIPNODES 65535 //32767 //SILENCER
  39. // hard limit (negative short's are used as contents values)
  40. // SILENCER: If you go over the clipnodes limit, some brushes
  41. // in your map won't be solid, so you can fall outside world.
  42. // Sending a warning to the mapper if he exceeds the limit,
  43. // but not stopping the compiler later, so he can see how far he is
  44. // over the limit.
  45. #define MAX_MAP_LEAFS 32767 //8192
  46. // Old: ( 8192 is hard limit - halflife depends on it to setup pvs bits correctly )
  47. // SILENCER: This is not a straight hard limit (anymore (?))
  48. // At least it is true that I made a testmap with ca. 16000
  49. // leafs and it did not crash or show weird problems at any point.
  50. // Added a warning being thrown at the user when he exceeds 8192, though.
  51. #define MAX_MAP_VERTS 65535
  52. #define MAX_MAP_FACES 65535
  53. #define MAX_MAP_MARKSURFACES 65535
  54. // hard limit (data structures store them as unsigned shorts)
  55. #define MAX_MAP_TEXTURES 512
  56. // hard limit (halflife limitation)
  57. #define MAX_MAP_TEXINFO 32767
  58. // hard limit (face.texinfo is signed short)
  59. #define MAX_MAP_EDGES 524287 //256000 //SILENCER
  60. #define MAX_MAP_SURFEDGES 1048575 //512000 //SILENCER
  61. // (not so(?)) arbitrary
  62. #define DEFAULT_MAX_MAP_MIPTEX 0x2000000 //0x400000 //PROTECTOR//SILENCER
  63. // 4Mb of textures is enough especially considering the number of people playing the game
  64. // still with voodoo 1 and 2 class cards with limited local memory.
  65. //PROTECTOR: blahblahblah voodoo foo. welcome to the 21st century, buy yourself a graphics card with 1024mb ram for 100$.
  66. //SILENCER: We don't have to overdo it THAT much. It still is just Goldsource. Lowered to 32 MB.
  67. #define DEFAULT_MAX_MAP_LIGHTDATA 0x2000000 //0x600000 (6 MB) //SILENCER: New is 32 MB
  68. // arbitrary
  69. #define MAX_MAP_VISIBILITY 0x1000000 //0x200000 //SILENCER
  70. // arbitrary
  71. // these are for entity key:value pairs
  72. #define MAX_KEY 64 //32 //SILENCER
  73. #define ZHLT3_MAX_VALUE 4096
  74. // quote from yahn: 'probably can raise these values if needed'
  75. // texture size limit
  76. #define MAX_TEXTURE_SIZE (256 * 256 * sizeof(short) * 3) / 2
  77. // this is arbitrary, and needs space for the largest realistic texture plus
  78. // room for its mipmaps. This value is primarily used to catch damaged or
  79. // invalid textures in a wad file
  80. //=============================================================================
  81. #define BSPVERSION 30
  82. #define TOOLVERSION 2
  83. //
  84. // BSP File Structures
  85. //
  86. typedef struct
  87. {
  88. int fileofs, filelen;
  89. }
  90. lump_t;
  91. #define LUMP_ENTITIES 0
  92. #define LUMP_PLANES 1
  93. #define LUMP_TEXTURES 2
  94. #define LUMP_VERTEXES 3
  95. #define LUMP_VISIBILITY 4
  96. #define LUMP_NODES 5
  97. #define LUMP_TEXINFO 6
  98. #define LUMP_FACES 7
  99. #define LUMP_LIGHTING 8
  100. #define LUMP_CLIPNODES 9
  101. #define LUMP_LEAFS 10
  102. #define LUMP_MARKSURFACES 11
  103. #define LUMP_EDGES 12
  104. #define LUMP_SURFEDGES 13
  105. #define LUMP_MODELS 14
  106. #define HEADER_LUMPS 15
  107. //#define LUMP_MISCPAD -1
  108. //#define LUMP_ZEROPAD -2
  109. typedef struct
  110. {
  111. float mins[3], maxs[3];
  112. float origin[3];
  113. int headnode[MAX_MAP_HULLS];
  114. int visleafs; // not including the solid leaf 0
  115. int firstface, numfaces;
  116. }
  117. dmodel_t;
  118. typedef struct
  119. {
  120. int version;
  121. lump_t lumps[HEADER_LUMPS];
  122. }
  123. dheader_t;
  124. typedef struct
  125. {
  126. int nummiptex;
  127. int dataofs[4]; // [nummiptex]
  128. }
  129. dmiptexlump_t;
  130. #define MIPLEVELS 4
  131. typedef struct miptex_s
  132. {
  133. char name[16];
  134. unsigned width, height;
  135. unsigned offsets[MIPLEVELS]; // four mip maps stored
  136. }
  137. miptex_t;
  138. typedef struct
  139. {
  140. float point[3];
  141. }
  142. dvertex_t;
  143. typedef struct
  144. {
  145. float normal[3];
  146. float dist;
  147. planetypes type; // PLANE_X - PLANE_ANYZ ?remove? trivial to regenerate
  148. }
  149. dplane_t;
  150. typedef enum
  151. {
  152. CONTENTS_EMPTY = -1,
  153. CONTENTS_SOLID = -2,
  154. CONTENTS_WATER = -3,
  155. CONTENTS_SLIME = -4,
  156. CONTENTS_LAVA = -5,
  157. CONTENTS_SKY = -6,
  158. CONTENTS_ORIGIN = -7, // removed at csg time
  159. CONTENTS_CLIP = -8, // changed to contents_solid
  160. CONTENTS_CURRENT_0 = -9,
  161. CONTENTS_CURRENT_90 = -10,
  162. CONTENTS_CURRENT_180 = -11,
  163. CONTENTS_CURRENT_270 = -12,
  164. CONTENTS_CURRENT_UP = -13,
  165. CONTENTS_CURRENT_DOWN = -14,
  166. CONTENTS_TRANSLUCENT = -15,
  167. CONTENTS_HINT = -16, // Filters down to CONTENTS_EMPTY by bsp, ENGINE SHOULD NEVER SEE THIS
  168. #ifdef ZHLT_NULLTEX
  169. CONTENTS_NULL = -17, // AJM // removed in csg and bsp, VIS or RAD shouldnt have to deal with this, only clip planes!
  170. #endif
  171. #ifdef ZHLT_DETAIL // AJM
  172. CONTENTS_DETAIL = -18,
  173. #endif
  174. }
  175. contents_t;
  176. // !!! if this is changed, it must be changed in asm_i386.h too !!!
  177. typedef struct
  178. {
  179. int planenum;
  180. short children[2]; // negative numbers are -(leafs+1), not nodes
  181. short mins[3]; // for sphere culling
  182. short maxs[3];
  183. unsigned short firstface;
  184. unsigned short numfaces; // counting both sides
  185. }
  186. dnode_t;
  187. typedef struct
  188. {
  189. int planenum;
  190. short children[2]; // negative numbers are contents
  191. }
  192. dclipnode_t;
  193. typedef struct texinfo_s
  194. {
  195. float vecs[2][4]; // [s/t][xyz offset]
  196. int miptex;
  197. int flags;
  198. }
  199. texinfo_t;
  200. #define TEX_SPECIAL 1 // sky or slime or null, no lightmap or 256 subdivision
  201. // note that edge 0 is never used, because negative edge nums are used for
  202. // counterclockwise use of the edge in a face
  203. typedef struct
  204. {
  205. unsigned short v[2]; // vertex numbers
  206. }
  207. dedge_t;
  208. #define MAXLIGHTMAPS 4
  209. typedef struct
  210. {
  211. unsigned short planenum;
  212. short side;
  213. int firstedge; // we must support > 64k edges
  214. short numedges;
  215. short texinfo;
  216. // lighting info
  217. byte styles[MAXLIGHTMAPS];
  218. int lightofs; // start of [numstyles*surfsize] samples
  219. }
  220. dface_t;
  221. #define AMBIENT_WATER 0
  222. #define AMBIENT_SKY 1
  223. #define AMBIENT_SLIME 2
  224. #define AMBIENT_LAVA 3
  225. #define NUM_AMBIENTS 4 // automatic ambient sounds
  226. // leaf 0 is the generic CONTENTS_SOLID leaf, used for all solid areas
  227. // all other leafs need visibility info
  228. typedef struct
  229. {
  230. int contents;
  231. int visofs; // -1 = no visibility info
  232. short mins[3]; // for frustum culling
  233. short maxs[3];
  234. unsigned short firstmarksurface;
  235. unsigned short nummarksurfaces;
  236. byte ambient_level[NUM_AMBIENTS];
  237. }
  238. dleaf_t;
  239. //============================================================================
  240. #define ANGLE_UP -1
  241. #define ANGLE_DOWN -2
  242. //
  243. // BSP File Data
  244. //
  245. extern int g_nummodels;
  246. extern dmodel_t g_dmodels[MAX_MAP_MODELS];
  247. extern int g_dmodels_checksum;
  248. extern int g_visdatasize;
  249. extern byte g_dvisdata[MAX_MAP_VISIBILITY];
  250. extern int g_dvisdata_checksum;
  251. extern int g_lightdatasize;
  252. extern byte* g_dlightdata;
  253. extern int g_dlightdata_checksum;
  254. extern int g_texdatasize;
  255. extern byte* g_dtexdata; // (dmiptexlump_t)
  256. extern int g_dtexdata_checksum;
  257. extern int g_entdatasize;
  258. extern char g_dentdata[MAX_MAP_ENTSTRING];
  259. extern int g_dentdata_checksum;
  260. extern int g_numleafs;
  261. extern dleaf_t g_dleafs[MAX_MAP_LEAFS];
  262. extern int g_dleafs_checksum;
  263. extern int g_numplanes;
  264. extern dplane_t g_dplanes[MAX_INTERNAL_MAP_PLANES];
  265. extern int g_dplanes_checksum;
  266. extern int g_numvertexes;
  267. extern dvertex_t g_dvertexes[MAX_MAP_VERTS];
  268. extern int g_dvertexes_checksum;
  269. extern int g_numnodes;
  270. extern dnode_t g_dnodes[MAX_MAP_NODES];
  271. extern int g_dnodes_checksum;
  272. extern int g_numtexinfo;
  273. extern texinfo_t g_texinfo[MAX_MAP_TEXINFO];
  274. extern int g_texinfo_checksum;
  275. extern int g_numfaces;
  276. extern dface_t g_dfaces[MAX_MAP_FACES];
  277. extern int g_dfaces_checksum;
  278. extern int g_numclipnodes;
  279. extern dclipnode_t g_dclipnodes[MAX_MAP_CLIPNODES];
  280. extern int g_dclipnodes_checksum;
  281. extern int g_numedges;
  282. extern dedge_t g_dedges[MAX_MAP_EDGES];
  283. extern int g_dedges_checksum;
  284. extern int g_nummarksurfaces;
  285. extern unsigned short g_dmarksurfaces[MAX_MAP_MARKSURFACES];
  286. extern int g_dmarksurfaces_checksum;
  287. extern int g_numsurfedges;
  288. extern int g_dsurfedges[MAX_MAP_SURFEDGES];
  289. extern int g_dsurfedges_checksum;
  290. extern void DecompressVis(const byte* src, byte* const dest, const unsigned int dest_length);
  291. extern int CompressVis(const byte* const src, const unsigned int src_length, byte* dest, unsigned int dest_length);
  292. extern void LoadBSPImage(dheader_t* header);
  293. extern void LoadBSPFile(const char* const filename);
  294. extern void WriteBSPFile(const char* const filename);
  295. extern void PrintBSPFileSizes();
  296. //
  297. // Entity Related Stuff
  298. //
  299. typedef struct epair_s
  300. {
  301. struct epair_s* next;
  302. char* key;
  303. char* value;
  304. }
  305. epair_t;
  306. typedef struct
  307. {
  308. vec3_t origin;
  309. int firstbrush;
  310. int numbrushes;
  311. epair_t* epairs;
  312. }
  313. entity_t;
  314. extern int g_numentities;
  315. extern entity_t g_entities[MAX_MAP_ENTITIES];
  316. extern void ParseEntities();
  317. extern void UnparseEntities();
  318. extern void strins(char* srcDestStr, const int maxNewLen, const char* insStr, const int insAtPos, const bool overwrite, const char fillGap);
  319. extern void MarkEntityAsRedundant(entity_t* ent);
  320. extern entity_t* AddEntity(const char* const classname, int neworigin[3]);
  321. extern void RemoveKeyValue(entity_t* ent, const char* const key);
  322. extern void SetKeyValue(entity_t* ent, const char* const key, const char* const value);
  323. extern const char* ValueForKey(const entity_t* const ent, const char* const key);
  324. extern int IntForKey(const entity_t* const ent, const char* const key);
  325. extern vec_t FloatForKey(const entity_t* const ent, const char* const key);
  326. extern bool BoolForKey(const entity_t* const ent, const char* const key);
  327. extern void GetVectorForKey(const entity_t* const ent, const char* const key, vec3_t vec);
  328. extern void GetIntVectorForKey(const entity_t* const ent, const char* const key, int vec[3]);
  329. extern entity_t* FindTargetEntity(const char* const target);
  330. extern epair_t* ParseEpair();
  331. extern entity_t* EntityForModel(int modnum);
  332. //
  333. // Texture Related Stuff
  334. //
  335. extern int g_max_map_miptex;
  336. extern int g_max_map_lightdata;
  337. extern void dtexdata_init();
  338. extern void CDECL dtexdata_free();
  339. extern char* GetTextureByNumber(int texturenumber);
  340. #endif //BSPFILE_H__