DOOM-3-BFG

DOOM 3 BFG Edition
Log | Files | Refs

Interaction.h (5670B)


      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 __INTERACTION_H__
     30 #define __INTERACTION_H__
     31 
     32 /*
     33 ===============================================================================
     34 
     35 	Interaction between static entityDef surfaces and a static lightDef.
     36 
     37 	Interactions with no lightTris and no shadowTris are still
     38 	valid, because they show that a given entityDef / lightDef
     39 	do not interact, even though they share one or more areas.
     40 
     41 ===============================================================================
     42 */
     43 
     44 #define LIGHT_CULL_ALL_FRONT		((byte *)-1)
     45 #define	LIGHT_CLIP_EPSILON			0.1f
     46 
     47 // enabling this define allows the precise inside shadow volume test
     48 // to be performed on interaction (static) shadow volumes
     49 #define KEEP_INTERACTION_CPU_DATA
     50 
     51 struct srfCullInfo_t {
     52 	// For each triangle a byte set to 1 if facing the light origin.
     53 	byte *					facing;
     54 
     55 	// For each vertex a byte with the bits [0-5] set if the
     56 	// vertex is at the back side of the corresponding clip plane.
     57 	// If the 'cullBits' pointer equals LIGHT_CULL_ALL_FRONT all
     58 	// vertices are at the front of all the clip planes.
     59 	byte *					cullBits;
     60 
     61 	// Clip planes in surface space used to calculate the cull bits.
     62 	idPlane					localClipPlanes[6];
     63 };
     64 
     65 
     66 // Pre-generated shadow volumes from dmap are not present in surfaceInteraction_t,
     67 // they are added separately.
     68 struct surfaceInteraction_t {
     69 	// The vertexes for light tris will always come from ambient triangles.
     70 	// For interactions created at load time, the indexes will be uniquely
     71 	// generated in static vertex memory.
     72 	int						numLightTrisIndexes;
     73 	vertCacheHandle_t		lightTrisIndexCache;
     74 
     75 	// shadow volume triangle surface
     76 	int						numShadowIndexes;
     77 	int						numShadowIndexesNoCaps;	// if the view is outside the shadow, this can be used
     78 	triIndex_t *			shadowIndexes;			// only != NULL if KEEP_INTERACTION_CPU_DATA is defined
     79 	vertCacheHandle_t		shadowIndexCache;
     80 };
     81 
     82 
     83 class idRenderEntityLocal;
     84 class idRenderLightLocal;
     85 
     86 class idInteraction {
     87 public:
     88 	// this may be 0 if the light and entity do not actually intersect
     89 	// -1 = an untested interaction
     90 	int						numSurfaces;
     91 
     92 	// if there is a whole-entity optimized shadow hull, it will
     93 	// be present as a surfaceInteraction_t with a NULL ambientTris, but
     94 	// possibly having a shader to specify the shadow sorting order
     95 	// (FIXME: actually try making shadow hulls?  we never did.)
     96 	surfaceInteraction_t *	surfaces;
     97 	
     98 	// get space from here, if NULL, it is a pre-generated shadow volume from dmap
     99 	idRenderEntityLocal *	entityDef;
    100 	idRenderLightLocal *	lightDef;
    101 
    102 	idInteraction *			lightNext;				// for lightDef chains
    103 	idInteraction *			lightPrev;
    104 	idInteraction *			entityNext;				// for entityDef chains
    105 	idInteraction *			entityPrev;
    106 
    107 	bool					staticInteraction;		// true if the interaction was created at map load time in static buffer space
    108 
    109 public:
    110 							idInteraction();
    111 
    112 	// because these are generated and freed each game tic for active elements all
    113 	// over the world, we use a custom pool allocater to avoid memory allocation overhead
    114 	// and fragmentation
    115 	static idInteraction *	AllocAndLink( idRenderEntityLocal *edef, idRenderLightLocal *ldef );
    116 
    117 	// unlinks from the entity and light, frees all surfaceInteractions,
    118 	// and puts it back on the free list
    119 	void					UnlinkAndFree();
    120 
    121 	// free the interaction surfaces
    122 	void					FreeSurfaces();
    123 
    124 	// makes the interaction empty for when the light and entity do not actually intersect
    125 	// all empty interactions are linked at the end of the light's and entity's interaction list
    126 	void					MakeEmpty();
    127 
    128 	// returns true if the interaction is empty
    129 	bool					IsEmpty() const { return ( numSurfaces == 0 ); }
    130 
    131 	// returns true if the interaction is not yet completely created
    132 	bool					IsDeferred() const { return ( numSurfaces == -1 ); }
    133 
    134 	// returns true if the interaction has shadows
    135 	bool					HasShadows() const;
    136 
    137 	// called by GenerateAllInteractions
    138 	void					CreateStaticInteraction();
    139 
    140 private:
    141 	// unlink from entity and light lists
    142 	void					Unlink();
    143 };
    144 
    145 void R_ShowInteractionMemory_f( const idCmdArgs &args );
    146 
    147 #endif /* !__INTERACTION_H__ */