Pvs.h 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  1. /*
  2. ===========================================================================
  3. Doom 3 GPL Source Code
  4. Copyright (C) 1999-2011 id Software LLC, a ZeniMax Media company.
  5. This file is part of the Doom 3 GPL Source Code (?Doom 3 Source Code?).
  6. Doom 3 Source Code is free software: you can redistribute it and/or modify
  7. it under the terms of the GNU General Public License as published by
  8. the Free Software Foundation, either version 3 of the License, or
  9. (at your option) any later version.
  10. Doom 3 Source Code is distributed in the hope that it will be useful,
  11. but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. GNU General Public License for more details.
  14. You should have received a copy of the GNU General Public License
  15. along with Doom 3 Source Code. If not, see <http://www.gnu.org/licenses/>.
  16. In addition, the Doom 3 Source Code is also subject to certain additional terms. You should have received a copy of these additional terms immediately following the terms and conditions of the GNU General Public License which accompanied the Doom 3 Source Code. If not, please request a copy in writing from id Software at the address below.
  17. If you have questions concerning this license or the applicable additional terms, you may contact in writing id Software LLC, c/o ZeniMax Media Inc., Suite 120, Rockville, Maryland 20850 USA.
  18. ===========================================================================
  19. */
  20. #ifndef __GAME_PVS_H__
  21. #define __GAME_PVS_H__
  22. /*
  23. ===================================================================================
  24. PVS
  25. Note: mirrors and other special view portals are not taken into account
  26. ===================================================================================
  27. */
  28. typedef struct pvsHandle_s {
  29. int i; // index to current pvs
  30. unsigned int h; // handle for current pvs
  31. } pvsHandle_t;
  32. typedef struct pvsCurrent_s {
  33. pvsHandle_t handle; // current pvs handle
  34. byte * pvs; // current pvs bit string
  35. } pvsCurrent_t;
  36. #define MAX_CURRENT_PVS 8 // must be a power of 2
  37. typedef enum {
  38. PVS_NORMAL = 0, // PVS through portals taking portal states into account
  39. PVS_ALL_PORTALS_OPEN = 1, // PVS through portals assuming all portals are open
  40. PVS_CONNECTED_AREAS = 2 // PVS considering all topologically connected areas visible
  41. } pvsType_t;
  42. class idPVS {
  43. public:
  44. idPVS( void );
  45. ~idPVS( void );
  46. // setup for the current map
  47. void Init( void );
  48. void Shutdown( void );
  49. // get the area(s) the source is in
  50. int GetPVSArea( const idVec3 &point ) const; // returns the area number
  51. int GetPVSAreas( const idBounds &bounds, int *areas, int maxAreas ) const; // returns number of areas
  52. // setup current PVS for the source
  53. pvsHandle_t SetupCurrentPVS( const idVec3 &source, const pvsType_t type = PVS_NORMAL ) const;
  54. pvsHandle_t SetupCurrentPVS( const idBounds &source, const pvsType_t type = PVS_NORMAL ) const;
  55. pvsHandle_t SetupCurrentPVS( const int sourceArea, const pvsType_t type = PVS_NORMAL ) const;
  56. pvsHandle_t SetupCurrentPVS( const int *sourceAreas, const int numSourceAreas, const pvsType_t type = PVS_NORMAL ) const;
  57. pvsHandle_t MergeCurrentPVS( pvsHandle_t pvs1, pvsHandle_t pvs2 ) const;
  58. void FreeCurrentPVS( pvsHandle_t handle ) const;
  59. // returns true if the target is within the current PVS
  60. bool InCurrentPVS( const pvsHandle_t handle, const idVec3 &target ) const;
  61. bool InCurrentPVS( const pvsHandle_t handle, const idBounds &target ) const;
  62. bool InCurrentPVS( const pvsHandle_t handle, const int targetArea ) const;
  63. bool InCurrentPVS( const pvsHandle_t handle, const int *targetAreas, int numTargetAreas ) const;
  64. // draw all portals that are within the PVS of the source
  65. void DrawPVS( const idVec3 &source, const pvsType_t type = PVS_NORMAL ) const;
  66. void DrawPVS( const idBounds &source, const pvsType_t type = PVS_NORMAL ) const;
  67. // visualize the PVS the handle points to
  68. void DrawCurrentPVS( const pvsHandle_t handle, const idVec3 &source ) const;
  69. #if ASYNC_WRITE_PVS
  70. void WritePVS( const pvsHandle_t handle, idBitMsg &msg );
  71. void ReadPVS( const pvsHandle_t handle, const idBitMsg &msg );
  72. #endif
  73. #ifdef _D3XP
  74. bool CheckAreasForPortalSky( const pvsHandle_t handle, const idVec3 &origin );
  75. #endif
  76. private:
  77. int numAreas;
  78. int numPortals;
  79. bool * connectedAreas;
  80. int * areaQueue;
  81. byte * areaPVS;
  82. // current PVS for a specific source possibly taking portal states (open/closed) into account
  83. mutable pvsCurrent_t currentPVS[MAX_CURRENT_PVS];
  84. // used to create PVS
  85. int portalVisBytes;
  86. int portalVisLongs;
  87. int areaVisBytes;
  88. int areaVisLongs;
  89. struct pvsPortal_s *pvsPortals;
  90. struct pvsArea_s * pvsAreas;
  91. private:
  92. int GetPortalCount( void ) const;
  93. void CreatePVSData( void );
  94. void DestroyPVSData( void );
  95. void CopyPortalPVSToMightSee( void ) const;
  96. void FloodFrontPortalPVS_r( struct pvsPortal_s *portal, int areaNum ) const;
  97. void FrontPortalPVS( void ) const;
  98. struct pvsStack_s * FloodPassagePVS_r( struct pvsPortal_s *source, const struct pvsPortal_s *portal, struct pvsStack_s *prevStack ) const;
  99. void PassagePVS( void ) const;
  100. void AddPassageBoundaries( const idWinding &source, const idWinding &pass, bool flipClip, idPlane *bounds, int &numBounds, int maxBounds ) const;
  101. void CreatePassages( void ) const;
  102. void DestroyPassages( void ) const;
  103. int AreaPVSFromPortalPVS( void ) const;
  104. void GetConnectedAreas( int srcArea, bool *connectedAreas ) const;
  105. pvsHandle_t AllocCurrentPVS( unsigned int h ) const;
  106. };
  107. #endif /* !__GAME_PVS_H__ */