doom3-gpl
Doom 3 GPL source release
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Pvs.h
Go to the documentation of this file.
1 /*
2 ===========================================================================
3 
4 Doom 3 GPL Source Code
5 Copyright (C) 1999-2011 id Software LLC, a ZeniMax Media company.
6 
7 This file is part of the Doom 3 GPL Source Code (?Doom 3 Source Code?).
8 
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.
13 
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.
18 
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/>.
21 
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.
23 
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.
25 
26 ===========================================================================
27 */
28 
29 #ifndef __GAME_PVS_H__
30 #define __GAME_PVS_H__
31 
32 /*
33 ===================================================================================
34 
35  PVS
36 
37  Note: mirrors and other special view portals are not taken into account
38 
39 ===================================================================================
40 */
41 
42 
43 typedef struct pvsHandle_s {
44  int i; // index to current pvs
45  unsigned int h; // handle for current pvs
46 } pvsHandle_t;
47 
48 
49 typedef struct pvsCurrent_s {
50  pvsHandle_t handle; // current pvs handle
51  byte * pvs; // current pvs bit string
52 } pvsCurrent_t;
53 
54 #define MAX_CURRENT_PVS 8 // must be a power of 2
55 
56 typedef enum {
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
60 } pvsType_t;
61 
62 
63 class idPVS {
64 public:
65  idPVS( void );
66  ~idPVS( void );
67  // setup for the current map
68  void Init( void );
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
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;
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;
90 
91 #if ASYNC_WRITE_PVS
92  void WritePVS( const pvsHandle_t handle, idBitMsg &msg );
93  void ReadPVS( const pvsHandle_t handle, const idBitMsg &msg );
94 #endif
95 
96 #ifdef _D3XP
97  bool CheckAreasForPortalSky( const pvsHandle_t handle, const idVec3 &origin );
98 #endif
99 
100 private:
101  int numAreas;
104  int * areaQueue;
106  // current PVS for a specific source possibly taking portal states (open/closed) into account
108  // used to create PVS
114  struct pvsArea_s * pvsAreas;
115 
116 private:
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;
131 };
132 
133 #endif /* !__GAME_PVS_H__ */
int GetPortalCount(void) const
Definition: Pvs.cpp:106
void FreeCurrentPVS(pvsHandle_t handle) const
Definition: Pvs.cpp:1127
void DrawCurrentPVS(const pvsHandle_t handle, const idVec3 &source) const
Definition: Pvs.cpp:1338
Definition: Vector.h:316
int * areaQueue
Definition: Pvs.h:104
int GetPVSAreas(const idBounds &bounds, int *areas, int maxAreas) const
Definition: Pvs.cpp:939
void DrawPVS(const idVec3 &source, const pvsType_t type=PVS_NORMAL) const
Definition: Pvs.cpp:1227
pvsType_t
Definition: Pvs.h:56
void Init(void)
Definition: Pvs.cpp:796
pvsHandle_t MergeCurrentPVS(pvsHandle_t pvs1, pvsHandle_t pvs2) const
Definition: Pvs.cpp:1075
GLuint GLuint GLsizei GLenum type
Definition: glext.h:2845
struct pvsStack_s * FloodPassagePVS_r(struct pvsPortal_s *source, const struct pvsPortal_s *portal, struct pvsStack_s *prevStack) const
Definition: Pvs.cpp:326
byte * areaPVS
Definition: Pvs.h:105
byte * pvs
Definition: Pvs.h:51
bool * connectedAreas
Definition: Pvs.h:103
unsigned int h
Definition: Pvs.h:45
struct pvsHandle_s pvsHandle_t
int i
Definition: Pvs.h:44
void FloodFrontPortalPVS_r(struct pvsPortal_s *portal, int areaNum) const
Definition: Pvs.cpp:211
pvsHandle_t SetupCurrentPVS(const idVec3 &source, const pvsType_t type=PVS_NORMAL) const
Definition: Pvs.cpp:948
GLsizei GLsizei GLcharARB * source
Definition: glext.h:3633
int portalVisLongs
Definition: Pvs.h:110
void DestroyPassages(void) const
Definition: Pvs.cpp:694
bool InCurrentPVS(const pvsHandle_t handle, const idVec3 &target) const
Definition: Pvs.cpp:1139
int numPortals
Definition: Pvs.h:102
struct pvsPortal_s * pvsPortals
Definition: Pvs.h:113
Definition: Plane.h:71
struct pvsArea_s * pvsAreas
Definition: Pvs.h:114
void GetConnectedAreas(int srcArea, bool *connectedAreas) const
Definition: Pvs.cpp:889
Definition: Pvs.h:63
void CreatePassages(void) const
Definition: Pvs.cpp:571
idPVS(void)
Definition: Pvs.cpp:72
int areaVisLongs
Definition: Pvs.h:112
int portalVisBytes
Definition: Pvs.h:109
void AddPassageBoundaries(const idWinding &source, const idWinding &pass, bool flipClip, idPlane *bounds, int &numBounds, int maxBounds) const
Definition: Pvs.cpp:451
void CopyPortalPVSToMightSee(void) const
Definition: Pvs.cpp:716
pvsCurrent_t currentPVS[MAX_CURRENT_PVS]
Definition: Pvs.h:107
void Shutdown(void)
Definition: Pvs.cpp:861
unsigned char byte
Definition: Lib.h:75
int areaVisBytes
Definition: Pvs.h:111
int AreaPVSFromPortalPVS(void) const
Definition: Pvs.cpp:731
pvsHandle_t handle
Definition: Pvs.h:50
void PassagePVS(void) const
Definition: Pvs.cpp:414
void CreatePVSData(void)
Definition: Pvs.cpp:122
Definition: Pvs.h:57
void FrontPortalPVS(void) const
Definition: Pvs.cpp:241
~idPVS(void)
Definition: Pvs.cpp:97
void DestroyPVSData(void)
Definition: Pvs.cpp:180
pvsHandle_t AllocCurrentPVS(unsigned int h) const
Definition: Pvs.cpp:1103
#define MAX_CURRENT_PVS
Definition: Pvs.h:54
struct pvsCurrent_s pvsCurrent_t
int GetPVSArea(const idVec3 &point) const
Definition: Pvs.cpp:930
int numAreas
Definition: Pvs.h:101