doom3-gpl
Doom 3 GPL source release
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Interaction.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 __INTERACTION_H__
30 #define __INTERACTION_H__
31 
32 /*
33 ===============================================================================
34 
35  Interaction between entityDef surfaces and a 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_TRIS_DEFERRED ((srfTriangles_t *)-1)
45 #define LIGHT_CULL_ALL_FRONT ((byte *)-1)
46 #define LIGHT_CLIP_EPSILON 0.1f
47 
48 
49 typedef struct {
50  // For each triangle a byte set to 1 if facing the light origin.
52 
53  // For each vertex a byte with the bits [0-5] set if the
54  // vertex is at the back side of the corresponding clip plane.
55  // If the 'cullBits' pointer equals LIGHT_CULL_ALL_FRONT all
56  // vertices are at the front of all the clip planes.
58 
59  // Clip planes in surface space used to calculate the cull bits.
60  idPlane localClipPlanes[6];
62 
63 
64 typedef struct {
65  // if lightTris == LIGHT_TRIS_DEFERRED, then the calculation of the
66  // lightTris has been deferred, and must be done if ambientTris is visible
68 
69  // shadow volume triangle surface
71 
72  // so we can check ambientViewCount before adding lightTris, and get
73  // at the shared vertex and possibly shadowVertex caches
75 
76  const idMaterial * shader;
77 
78  int expCulled; // only for the experimental shadow buffer renderer
79 
82 
83 
84 typedef struct areaNumRef_s {
85  struct areaNumRef_s * next;
86  int areaNum;
87 } areaNumRef_t;
88 
89 
91 class idRenderLightLocal;
92 
94 public:
95  // this may be 0 if the light and entity do not actually intersect
96  // -1 = an untested interaction
98 
99  // if there is a whole-entity optimized shadow hull, it will
100  // be present as a surfaceInteraction_t with a NULL ambientTris, but
101  // possibly having a shader to specify the shadow sorting order
103 
104  // get space from here, if NULL, it is a pre-generated shadow volume from dmap
107 
108  idInteraction * lightNext; // for lightDef chains
110  idInteraction * entityNext; // for entityDef chains
112 
113 public:
114  idInteraction( void );
115 
116  // because these are generated and freed each game tic for active elements all
117  // over the world, we use a custom pool allocater to avoid memory allocation overhead
118  // and fragmentation
120 
121  // unlinks from the entity and light, frees all surfaceInteractions,
122  // and puts it back on the free list
123  void UnlinkAndFree( void );
124 
125  // free the interaction surfaces
126  void FreeSurfaces( void );
127 
128  // makes the interaction empty for when the light and entity do not actually intersect
129  // all empty interactions are linked at the end of the light's and entity's interaction list
130  void MakeEmpty( void );
131 
132  // returns true if the interaction is empty
133  bool IsEmpty( void ) const { return ( numSurfaces == 0 ); }
134 
135  // returns true if the interaction is not yet completely created
136  bool IsDeferred( void ) const { return ( numSurfaces == -1 ); }
137 
138  // returns true if the interaction has shadows
139  bool HasShadows( void ) const;
140 
141  // counts up the memory used by all the surfaceInteractions, which
142  // will be used to determine when we need to start purging old interactions
143  int MemoryUsed( void );
144 
145  // makes sure all necessary light surfaces and shadow surfaces are created, and
146  // calls R_LinkLightSurf() for each one
147  void AddActiveInteraction( void );
148 
149 private:
150  enum {
155  } frustumState;
156  idFrustum frustum; // frustum which contains the interaction
157  areaNumRef_t * frustumAreas; // numbers of the areas the frustum touches
158 
159  int dynamicModelFrameCount; // so we can tell if a callback model animated
160 
161 private:
162  // actually create the interaction
163  void CreateInteraction( const idRenderModel *model );
164 
165  // unlink from entity and light lists
166  void Unlink( void );
167 
168  // try to determine if the entire interaction, including shadows, is guaranteed
169  // to be outside the view frustum
170  bool CullInteractionByViewFrustum( const idFrustum &viewFrustum );
171 
172  // determine the minimum scissor rect that will include the interaction shadows
173  // projected to the bounds of the light
175 };
176 
177 
178 void R_CalcInteractionFacing( const idRenderEntityLocal *ent, const srfTriangles_t *tri, const idRenderLightLocal *light, srfCullInfo_t &cullInfo );
179 void R_CalcInteractionCullBits( const idRenderEntityLocal *ent, const srfTriangles_t *tri, const idRenderLightLocal *light, srfCullInfo_t &cullInfo );
180 void R_FreeInteractionCullInfo( srfCullInfo_t &cullInfo );
181 
182 void R_ShowInteractionMemory_f( const idCmdArgs &args );
183 
184 #endif /* !__INTERACTION_H__ */
const idMaterial * shader
Definition: Interaction.h:76
areaNumRef_t * frustumAreas
Definition: Interaction.h:157
void UnlinkAndFree(void)
byte * facing
Definition: Interaction.h:51
idInteraction * entityPrev
Definition: Interaction.h:111
idFrustum frustum
Definition: Interaction.h:156
idInteraction * lightNext
Definition: Interaction.h:108
bool HasShadows(void) const
bool IsDeferred(void) const
Definition: Interaction.h:136
srfCullInfo_t cullInfo
Definition: Interaction.h:80
idRenderLightLocal * lightDef
Definition: Interaction.h:106
static idInteraction * AllocAndLink(idRenderEntityLocal *edef, idRenderLightLocal *ldef)
idInteraction * lightPrev
Definition: Interaction.h:109
void R_FreeInteractionCullInfo(srfCullInfo_t &cullInfo)
byte * cullBits
Definition: Interaction.h:57
void Unlink(void)
struct areaNumRef_s * next
Definition: Interaction.h:85
srfTriangles_t * lightTris
Definition: Interaction.h:67
struct areaNumRef_s areaNumRef_t
bool IsEmpty(void) const
Definition: Interaction.h:133
Definition: Plane.h:71
void AddActiveInteraction(void)
void R_CalcInteractionCullBits(const idRenderEntityLocal *ent, const srfTriangles_t *tri, const idRenderLightLocal *light, srfCullInfo_t &cullInfo)
Definition: Interaction.cpp:92
void MakeEmpty(void)
void R_CalcInteractionFacing(const idRenderEntityLocal *ent, const srfTriangles_t *tri, const idRenderLightLocal *light, srfCullInfo_t &cullInfo)
Definition: Interaction.cpp:55
enum idInteraction::@87 frustumState
int dynamicModelFrameCount
Definition: Interaction.h:159
surfaceInteraction_t * surfaces
Definition: Interaction.h:102
idScreenRect CalcInteractionScissorRectangle(const idFrustum &viewFrustum)
unsigned char byte
Definition: Lib.h:75
bool CullInteractionByViewFrustum(const idFrustum &viewFrustum)
int MemoryUsed(void)
idInteraction * entityNext
Definition: Interaction.h:110
srfTriangles_t * ambientTris
Definition: Interaction.h:74
srfTriangles_t * shadowTris
Definition: Interaction.h:70
void FreeSurfaces(void)
void R_ShowInteractionMemory_f(const idCmdArgs &args)
idRenderEntityLocal * entityDef
Definition: Interaction.h:105
void CreateInteraction(const idRenderModel *model)