DOOM-3-BFG

DOOM 3 BFG Edition
Log | Files | Refs

Pvs.h (5571B)


      1 /*
      2 ===========================================================================
      3 
      4 Doom 3 BFG Edition GPL Source Code
      5 Copyright (C) 1993-2012 id Software LLC, a ZeniMax Media company. 
      6 
      7 This file is part of the Doom 3 BFG Edition GPL Source Code ("Doom 3 BFG Edition Source Code").  
      8 
      9 Doom 3 BFG Edition 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 BFG Edition 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 BFG Edition Source Code.  If not, see <http://www.gnu.org/licenses/>.
     21 
     22 In addition, the Doom 3 BFG Edition 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 BFG Edition 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		64		// 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();
     66 						~idPVS();
     67 						// setup for the current map
     68 	void				Init();
     69 	void				Shutdown();
     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;
     90 
     91 	bool				CheckAreasForPortalSky( const pvsHandle_t handle, const idVec3 &origin );
     92 
     93 private:
     94 	int					numAreas;
     95 	int					numPortals;
     96 	bool *				connectedAreas;
     97 	int *				areaQueue;
     98 	byte *				areaPVS;
     99 						// current PVS for a specific source possibly taking portal states (open/closed) into account
    100 	mutable pvsCurrent_t currentPVS[MAX_CURRENT_PVS];
    101 						// used to create PVS
    102 	int					portalVisBytes;
    103 	int					portalVisLongs;
    104 	int					areaVisBytes;
    105 	int					areaVisLongs;
    106 	struct pvsPortal_s *pvsPortals;
    107 	struct pvsArea_s *	pvsAreas;
    108 
    109 private:
    110 	int					GetPortalCount() const;
    111 	void				CreatePVSData();
    112 	void				DestroyPVSData();
    113 	void				CopyPortalPVSToMightSee() const;
    114 	void				FloodFrontPortalPVS_r( struct pvsPortal_s *portal, int areaNum ) const;
    115 	void				FrontPortalPVS() const;
    116 	struct pvsStack_s *	FloodPassagePVS_r( struct pvsPortal_s *source, const struct pvsPortal_s *portal, struct pvsStack_s *prevStack ) const;
    117 	void				PassagePVS() const;
    118 	void				AddPassageBoundaries( const idWinding &source, const idWinding &pass, bool flipClip, idPlane *bounds, int &numBounds, int maxBounds ) const;
    119 	void				CreatePassages() const;
    120 	void				DestroyPassages() const;
    121 	int					AreaPVSFromPortalPVS() const;
    122 	void				GetConnectedAreas( int srcArea, bool *connectedAreas ) const;
    123 	pvsHandle_t			AllocCurrentPVS( unsigned int h ) const;
    124 };
    125 
    126 #endif /* !__GAME_PVS_H__ */