bsp5.h 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278
  1. #ifndef HLBSP_H__
  2. #define HLBSP_H__
  3. #if _MSC_VER >= 1000
  4. #pragma once
  5. #endif
  6. #include "cmdlib.h"
  7. #include "messages.h"
  8. #include "win32fix.h"
  9. #include "log.h"
  10. #include "hlassert.h"
  11. #include "mathlib.h"
  12. #include "bspfile.h"
  13. #include "blockmem.h"
  14. #include "filelib.h"
  15. #include "threads.h"
  16. #include "winding.h"
  17. #define ENTITIES_VOID "entities.void"
  18. #define ENTITIES_VOID_EXT ".void"
  19. #define BOGUS_RANGE 18000
  20. // the exact bounding box of the brushes is expanded some for the headnode
  21. // volume. is this still needed?
  22. #define SIDESPACE 24
  23. //============================================================================
  24. #define MIN_SUBDIVIDE_SIZE 64
  25. #ifdef ZHLT_GENERAL
  26. #define MAX_SUBDIVIDE_SIZE 512
  27. #else
  28. #define MAX_SUBDIVIDE_SIZE 240
  29. #endif
  30. #define DEFAULT_SUBDIVIDE_SIZE 240
  31. #define MIN_MAXNODE_SIZE 64
  32. #define MAX_MAXNODE_SIZE 8192
  33. #define DEFAULT_MAXNODE_SIZE 1024
  34. #define DEFAULT_NOFILL false
  35. #define DEFAULT_NOTJUNC false
  36. #define DEFAULT_NOCLIP false
  37. #define DEFAULT_NOOPT false
  38. #define DEFAULT_LEAKONLY false
  39. #define DEFAULT_WATERVIS false
  40. #define DEFAULT_CHART false
  41. #define DEFAULT_INFO true
  42. #ifdef ZHLT_NULLTEX // AJM
  43. #define DEFAULT_NULLTEX true
  44. #endif
  45. #ifdef ZHLT_PROGRESSFILE // AJM
  46. #define DEFAULT_PROGRESSFILE NULL // progress file is only used if g_progressfile is non-null
  47. #endif
  48. #ifdef SYSTEM_WIN32
  49. #define DEFAULT_ESTIMATE false
  50. #endif
  51. #ifdef SYSTEM_POSIX
  52. #define DEFAULT_ESTIMATE true
  53. #endif
  54. #ifdef ZHLT_DETAIL // AJM
  55. #define DEFAULT_DETAIL true
  56. #endif
  57. #define MAXEDGES 48 // 32
  58. #define MAXPOINTS 28 // don't let a base face get past this
  59. // because it can be split more later
  60. #define MAXNODESIZE 1024 // Valve default is 1024
  61. typedef enum
  62. {
  63. face_normal = 0,
  64. face_hint,
  65. face_skip,
  66. #ifdef ZHLT_NULLTEX // AJM
  67. face_null,
  68. #endif
  69. #ifdef ZHLT_DETAIL // AJM
  70. face_detail
  71. #endif
  72. //face_blocklight
  73. }
  74. facestyle_e;
  75. typedef struct face_s // This structure is layed out so 'pts' is on a quad-word boundary (and the pointers are as well)
  76. {
  77. struct face_s* next;
  78. int planenum;
  79. int texturenum;
  80. int contents; // contents in front of face
  81. struct face_s* original; // face on node
  82. int outputnumber; // only valid for original faces after write surfaces
  83. int numpoints;
  84. facestyle_e facestyle;
  85. // vector quad word aligned
  86. vec3_t pts[MAXEDGES]; // FIXME: change to use winding_t
  87. }
  88. face_t;
  89. typedef struct surface_s
  90. {
  91. struct surface_s* next;
  92. int planenum;
  93. vec3_t mins, maxs;
  94. struct node_s* onnode; // true if surface has already been used
  95. // as a splitting node
  96. face_t* faces; // links to all the faces on either side of the surf
  97. }
  98. surface_t;
  99. typedef struct
  100. {
  101. vec3_t mins, maxs;
  102. surface_t* surfaces;
  103. }
  104. surfchain_t;
  105. //
  106. // there is a node_t structure for every node and leaf in the bsp tree
  107. //
  108. #define PLANENUM_LEAF -1
  109. typedef struct node_s
  110. {
  111. surface_t* surfaces;
  112. vec3_t mins, maxs; // bounding volume of portals;
  113. // information for decision nodes
  114. int planenum; // -1 = leaf node
  115. struct node_s* children[2]; // only valid for decision nodes
  116. face_t* faces; // decision nodes only, list for both sides
  117. // information for leafs
  118. int contents; // leaf nodes (0 for decision nodes)
  119. face_t** markfaces; // leaf nodes only, point to node faces
  120. struct portal_s* portals;
  121. int visleafnum; // -1 = solid
  122. int valid; // for flood filling
  123. int occupied; // light number in leaf for outside filling
  124. }
  125. node_t;
  126. #define NUM_HULLS 4
  127. //=============================================================================
  128. // solidbsp.c
  129. extern void SubdivideFace(face_t* f, face_t** prevptr);
  130. extern node_t* SolidBSP(const surfchain_t* const surfhead, bool report_progress);
  131. //=============================================================================
  132. // merge.c
  133. extern void MergePlaneFaces(surface_t* plane);
  134. extern void MergeAll(surface_t* surfhead);
  135. //=============================================================================
  136. // surfaces.c
  137. extern void MakeFaceEdges();
  138. extern int GetEdge(const vec3_t p1, const vec3_t p2, face_t* f);
  139. //=============================================================================
  140. // portals.c
  141. typedef struct portal_s
  142. {
  143. dplane_t plane;
  144. node_t* onnode; // NULL = outside box
  145. node_t* nodes[2]; // [0] = front side of plane
  146. struct portal_s* next[2];
  147. Winding* winding;
  148. }
  149. portal_t;
  150. extern node_t g_outside_node; // portals outside the world face this
  151. extern void AddPortalToNodes(portal_t* p, node_t* front, node_t* back);
  152. extern void RemovePortalFromNode(portal_t* portal, node_t* l);
  153. extern void MakeHeadnodePortals(node_t* node, const vec3_t mins, const vec3_t maxs);
  154. extern void FreePortals(node_t* node);
  155. extern void WritePortalfile(node_t* headnode);
  156. //=============================================================================
  157. // tjunc.c
  158. void tjunc(node_t* headnode);
  159. //=============================================================================
  160. // writebsp.c
  161. extern void WriteClipNodes(node_t* headnode);
  162. extern void WriteDrawNodes(node_t* headnode);
  163. extern void BeginBSPFile();
  164. extern void FinishBSPFile();
  165. //=============================================================================
  166. // outside.c
  167. extern node_t* FillOutside(node_t* node, bool leakfile, unsigned hullnum);
  168. extern void LoadAllowableOutsideList(const char* const filename);
  169. extern void FreeAllowableOutsideList();
  170. //=============================================================================
  171. // misc functions
  172. extern void GetParamsFromEnt(entity_t* mapent);
  173. extern face_t* AllocFace();
  174. extern void FreeFace(face_t* f);
  175. extern struct portal_s* AllocPortal();
  176. extern void FreePortal(struct portal_s* p);
  177. extern surface_t* AllocSurface();
  178. extern void FreeSurface(surface_t* s);
  179. extern node_t* AllocNode();
  180. extern bool CheckFaceForHint(const face_t* const f);
  181. extern bool CheckFaceForSkip(const face_t* const f);
  182. #ifdef ZHLT_NULLTEX// AJM
  183. extern bool CheckFaceForNull(const face_t* const f);
  184. #endif
  185. // =====================================================================================
  186. //Cpt_Andrew - UTSky Check
  187. // =====================================================================================
  188. extern bool CheckFaceForEnv_Sky(const face_t* const f);
  189. // =====================================================================================
  190. #ifdef ZHLT_DETAIL // AJM
  191. extern bool CheckFaceForDetail(const face_t* const f);
  192. #endif
  193. //=============================================================================
  194. // cull.c
  195. extern void CullStuff();
  196. //=============================================================================
  197. // qbsp.c
  198. extern bool g_nofill;
  199. extern bool g_notjunc;
  200. extern bool g_watervis;
  201. extern bool g_chart;
  202. extern bool g_estimate;
  203. extern int g_maxnode_size;
  204. extern int g_subdivide_size;
  205. extern int g_hullnum;
  206. extern bool g_bLeakOnly;
  207. extern bool g_bLeaked;
  208. extern char g_portfilename[_MAX_PATH];
  209. extern char g_pointfilename[_MAX_PATH];
  210. extern char g_linefilename[_MAX_PATH];
  211. extern char g_bspfilename[_MAX_PATH];
  212. #ifdef ZHLT_DETAIL // AJM
  213. extern bool g_bDetailBrushes;
  214. #endif
  215. #ifdef ZHLT_NULLTEX // AJM
  216. extern bool g_bUseNullTex;
  217. #endif
  218. extern face_t* NewFaceFromFace(const face_t* const in);
  219. extern void SplitFace(face_t* in, const dplane_t* const split, face_t** front, face_t** back);
  220. #endif // qbsp.c====================================================================== HLBSP_H__