2 ===========================================================================
5 Copyright (C) 1999-2011 id Software LLC, a ZeniMax Media company.
7 This file is part of the Doom 3 GPL Source Code (?Doom 3 Source Code?).
9 Doom 3 Source Code is free software: you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation, either version 3 of the License, or
12 (at your option) any later version.
14 Doom 3 Source Code is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
19 You should have received a copy of the GNU General Public License
20 along with Doom 3 Source Code. If not, see <http://www.gnu.org/licenses/>.
22 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.
24 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.
26 ===========================================================================
29 #ifndef __GAME_PVS_H__
30 #define __GAME_PVS_H__
33 ===================================================================================
37 Note: mirrors and other special view portals are not taken into account
39 ===================================================================================
43 typedef struct pvsHandle_s {
44 int i; // index to current pvs
45 unsigned int h; // handle for current pvs
49 typedef struct pvsCurrent_s {
50 pvsHandle_t handle; // current pvs handle
51 byte * pvs; // current pvs bit string
54 #define MAX_CURRENT_PVS 8 // must be a power of 2
57 PVS_NORMAL = 0, // PVS through portals taking portal states into account
58 PVS_ALL_PORTALS_OPEN = 1, // PVS through portals assuming all portals are open
59 PVS_CONNECTED_AREAS = 2 // PVS considering all topologically connected areas visible
67 // setup for the current map
69 void Shutdown( void );
70 // get the area(s) the source is in
71 int GetPVSArea( const idVec3 &point ) const; // returns the area number
72 int GetPVSAreas( const idBounds &bounds, int *areas, int maxAreas ) const; // returns number of areas
73 // setup current PVS for the source
74 pvsHandle_t SetupCurrentPVS( const idVec3 &source, const pvsType_t type = PVS_NORMAL ) const;
75 pvsHandle_t SetupCurrentPVS( const idBounds &source, const pvsType_t type = PVS_NORMAL ) const;
76 pvsHandle_t SetupCurrentPVS( const int sourceArea, const pvsType_t type = PVS_NORMAL ) const;
77 pvsHandle_t SetupCurrentPVS( const int *sourceAreas, const int numSourceAreas, const pvsType_t type = PVS_NORMAL ) const;
78 pvsHandle_t MergeCurrentPVS( pvsHandle_t pvs1, pvsHandle_t pvs2 ) const;
79 void FreeCurrentPVS( pvsHandle_t handle ) const;
80 // returns true if the target is within the current PVS
81 bool InCurrentPVS( const pvsHandle_t handle, const idVec3 &target ) const;
82 bool InCurrentPVS( const pvsHandle_t handle, const idBounds &target ) const;
83 bool InCurrentPVS( const pvsHandle_t handle, const int targetArea ) const;
84 bool InCurrentPVS( const pvsHandle_t handle, const int *targetAreas, int numTargetAreas ) const;
85 // draw all portals that are within the PVS of the source
86 void DrawPVS( const idVec3 &source, const pvsType_t type = PVS_NORMAL ) const;
87 void DrawPVS( const idBounds &source, const pvsType_t type = PVS_NORMAL ) const;
88 // visualize the PVS the handle points to
89 void DrawCurrentPVS( const pvsHandle_t handle, const idVec3 &source ) const;
92 void WritePVS( const pvsHandle_t handle, idBitMsg &msg );
93 void ReadPVS( const pvsHandle_t handle, const idBitMsg &msg );
97 bool CheckAreasForPortalSky( const pvsHandle_t handle, const idVec3 &origin );
103 bool * connectedAreas;
106 // current PVS for a specific source possibly taking portal states (open/closed) into account
107 mutable pvsCurrent_t currentPVS[MAX_CURRENT_PVS];
108 // used to create PVS
113 struct pvsPortal_s *pvsPortals;
114 struct pvsArea_s * pvsAreas;
117 int GetPortalCount( void ) const;
118 void CreatePVSData( void );
119 void DestroyPVSData( void );
120 void CopyPortalPVSToMightSee( void ) const;
121 void FloodFrontPortalPVS_r( struct pvsPortal_s *portal, int areaNum ) const;
122 void FrontPortalPVS( void ) const;
123 struct pvsStack_s * FloodPassagePVS_r( struct pvsPortal_s *source, const struct pvsPortal_s *portal, struct pvsStack_s *prevStack ) const;
124 void PassagePVS( void ) const;
125 void AddPassageBoundaries( const idWinding &source, const idWinding &pass, bool flipClip, idPlane *bounds, int &numBounds, int maxBounds ) const;
126 void CreatePassages( void ) const;
127 void DestroyPassages( void ) const;
128 int AreaPVSFromPortalPVS( void ) const;
129 void GetConnectedAreas( int srcArea, bool *connectedAreas ) const;
130 pvsHandle_t AllocCurrentPVS( unsigned int h ) const;
133 #endif /* !__GAME_PVS_H__ */