doom3-gpl
Doom 3 GPL source release
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
RenderWorld_local.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 __RENDERWORLDLOCAL_H__
30 #define __RENDERWORLDLOCAL_H__
31 
32 // assume any lightDef or entityDef index above this is an internal error
33 const int LUDICROUS_INDEX = 10000;
34 
35 
36 typedef struct portal_s {
37  int intoArea; // area this portal leads to
38  idWinding * w; // winding points have counter clockwise ordering seen this area
39  idPlane plane; // view must be on the positive side of the plane to cross
40  struct portal_s * next; // next portal of the area
42 } portal_t;
43 
44 
45 typedef struct doublePortal_s {
46  struct portal_s * portals[2];
47  int blockingBits; // PS_BLOCK_VIEW, PS_BLOCK_AIR, etc, set by doors that shut them off
48 
49  // A portal will be considered closed if it is past the
50  // fog-out point in a fog volume. We only support a single
51  // fog volume over each portal.
55 
56 
57 typedef struct portalArea_s {
58  int areaNum;
59  int connectedAreaNum[NUM_PORTAL_ATTRIBUTES]; // if two areas have matching connectedAreaNum, they are
60  // not separated by a portal with the apropriate PS_BLOCK_* blockingBits
61  int viewCount; // set by R_FindViewLightsAndEntities
62  portal_t * portals; // never changes after load
63  areaReference_t entityRefs; // head/tail of doubly linked list, may change
64  areaReference_t lightRefs; // head/tail of doubly linked list, may change
65 } portalArea_t;
66 
67 
68 static const int CHILDREN_HAVE_MULTIPLE_AREAS = -2;
69 static const int AREANUM_SOLID = -1;
70 typedef struct {
72  int children[2]; // negative numbers are (-1 - areaNumber), 0 = solid
73  int commonChildrenArea; // if all children are either solid or a single area,
74  // this is the area number, else CHILDREN_HAVE_MULTIPLE_AREAS
75 } areaNode_t;
76 
77 
79 public:
81  virtual ~idRenderWorldLocal();
82 
83  virtual qhandle_t AddEntityDef( const renderEntity_t *re );
84  virtual void UpdateEntityDef( qhandle_t entityHandle, const renderEntity_t *re );
85  virtual void FreeEntityDef( qhandle_t entityHandle );
86  virtual const renderEntity_t *GetRenderEntity( qhandle_t entityHandle ) const;
87 
88  virtual qhandle_t AddLightDef( const renderLight_t *rlight );
89  virtual void UpdateLightDef( qhandle_t lightHandle, const renderLight_t *rlight );
90  virtual void FreeLightDef( qhandle_t lightHandle );
91  virtual const renderLight_t *GetRenderLight( qhandle_t lightHandle ) const;
92 
93  virtual bool CheckAreaForPortalSky( int areaNum );
94 
95  virtual void GenerateAllInteractions();
96  virtual void RegenerateWorld();
97 
98  virtual void ProjectDecalOntoWorld( const idFixedWinding &winding, const idVec3 &projectionOrigin, const bool parallel, const float fadeDepth, const idMaterial *material, const int startTime );
99  virtual void ProjectDecal( qhandle_t entityHandle, const idFixedWinding &winding, const idVec3 &projectionOrigin, const bool parallel, const float fadeDepth, const idMaterial *material, const int startTime );
100  virtual void ProjectOverlay( qhandle_t entityHandle, const idPlane localTextureAxis[2], const idMaterial *material );
101  virtual void RemoveDecals( qhandle_t entityHandle );
102 
103  virtual void SetRenderView( const renderView_t *renderView );
104  virtual void RenderScene( const renderView_t *renderView );
105 
106  virtual int NumAreas( void ) const;
107  virtual int PointInArea( const idVec3 &point ) const;
108  virtual int BoundsInAreas( const idBounds &bounds, int *areas, int maxAreas ) const;
109  virtual int NumPortalsInArea( int areaNum );
110  virtual exitPortal_t GetPortal( int areaNum, int portalNum );
111 
112  virtual guiPoint_t GuiTrace( qhandle_t entityHandle, const idVec3 start, const idVec3 end ) const;
113  virtual bool ModelTrace( modelTrace_t &trace, qhandle_t entityHandle, const idVec3 &start, const idVec3 &end, const float radius ) const;
114  virtual bool Trace( modelTrace_t &trace, const idVec3 &start, const idVec3 &end, const float radius, bool skipDynamic = true, bool skipPlayer = false ) const;
115  virtual bool FastWorldTrace( modelTrace_t &trace, const idVec3 &start, const idVec3 &end ) const;
116 
117  virtual void DebugClearLines( int time );
118  virtual void DebugLine( const idVec4 &color, const idVec3 &start, const idVec3 &end, const int lifetime = 0, const bool depthTest = false );
119  virtual void DebugArrow( const idVec4 &color, const idVec3 &start, const idVec3 &end, int size, const int lifetime = 0 );
120  virtual void DebugWinding( const idVec4 &color, const idWinding &w, const idVec3 &origin, const idMat3 &axis, const int lifetime = 0, const bool depthTest = false );
121  virtual void DebugCircle( const idVec4 &color, const idVec3 &origin, const idVec3 &dir, const float radius, const int numSteps, const int lifetime = 0, const bool depthTest = false );
122  virtual void DebugSphere( const idVec4 &color, const idSphere &sphere, const int lifetime = 0, bool depthTest = false );
123  virtual void DebugBounds( const idVec4 &color, const idBounds &bounds, const idVec3 &org = vec3_origin, const int lifetime = 0 );
124  virtual void DebugBox( const idVec4 &color, const idBox &box, const int lifetime = 0 );
125  virtual void DebugFrustum( const idVec4 &color, const idFrustum &frustum, const bool showFromOrigin = false, const int lifetime = 0 );
126  virtual void DebugCone( const idVec4 &color, const idVec3 &apex, const idVec3 &dir, float radius1, float radius2, const int lifetime = 0 );
127  virtual void DebugScreenRect( const idVec4 &color, const idScreenRect &rect, const viewDef_t *viewDef, const int lifetime = 0 );
128  virtual void DebugAxis( const idVec3 &origin, const idMat3 &axis );
129 
130  virtual void DebugClearPolygons( int time );
131  virtual void DebugPolygon( const idVec4 &color, const idWinding &winding, const int lifeTime = 0, const bool depthTest = false );
132 
133  virtual void DrawText( const char *text, const idVec3 &origin, float scale, const idVec4 &color, const idMat3 &viewAxis, const int align = 1, const int lifetime = 0, bool depthTest = false );
134 
135  //-----------------------
136 
137  idStr mapName; // ie: maps/tim_dm2.proc, written to demoFile
138  ID_TIME_T mapTimeStamp; // for fast reloads of the same level
139 
142 
145  int connectedAreaNum; // incremented every time a door portal state changes
146 
148 
151 
153 
156 
160 
161  // all light / entity interactions are referenced here for fast lookup without
162  // having to crawl the doubly linked lists. EnntityDefs are sequential for better
163  // cache access, because the table is accessed by light in idRenderWorldLocal::CreateLightDefInteractions()
164  // Growing this table is time consuming, so we add a pad value to the number
165  // of entityDefs and lightDefs
167  int interactionTableWidth; // entityDefs
168  int interactionTableHeight; // lightDefs
169 
170 
172 
173  //-----------------------
174  // RenderWorld_load.cpp
175 
178  void SetupAreaRefs();
180  void ParseNodes( idLexer *src );
181  int CommonChildrenArea_r( areaNode_t *node );
182  void FreeWorld();
183  void ClearWorld();
184  void FreeDefs();
185  void TouchWorldModels( void );
186  void AddWorldModelEntities();
187  void ClearPortalStates();
188  virtual bool InitFromMap( const char *mapName );
189 
190  //--------------------------
191  // RenderWorld_portals.cpp
192 
194  bool PortalIsFoggedOut( const portal_t *p );
195  void FloodViewThroughArea_r( const idVec3 origin, int areaNum, const struct portalStack_s *ps );
196  void FlowViewThroughPortals( const idVec3 origin, int numPlanes, const idPlane *planes );
197  void FloodLightThroughArea_r( idRenderLightLocal *light, int areaNum, const struct portalStack_s *ps );
199  areaNumRef_t * FloodFrustumAreas_r( const idFrustum &frustum, const int areaNum, const idBounds &bounds, areaNumRef_t *areas );
200  areaNumRef_t * FloodFrustumAreas( const idFrustum &frustum, areaNumRef_t *areas );
201  bool CullEntityByPortals( const idRenderEntityLocal *entity, const struct portalStack_s *ps );
202  void AddAreaEntityRefs( int areaNum, const struct portalStack_s *ps );
203  bool CullLightByPortals( const idRenderLightLocal *light, const struct portalStack_s *ps );
204  void AddAreaLightRefs( int areaNum, const struct portalStack_s *ps );
205  void AddAreaRefs( int areaNum, const struct portalStack_s *ps );
206  void BuildConnectedAreas_r( int areaNum );
207  void BuildConnectedAreas( void );
208  void FindViewLightsAndEntities( void );
209 
210  int NumPortals( void ) const;
211  qhandle_t FindPortal( const idBounds &b ) const;
212  void SetPortalState( qhandle_t portal, int blockingBits );
213  int GetPortalState( qhandle_t portal );
214  bool AreasAreConnected( int areaNum1, int areaNum2, portalConnection_t connection );
215  void FloodConnectedAreas( portalArea_t *area, int portalAttributeIndex );
216  idScreenRect & GetAreaScreenRect( int areaNum ) const { return areaScreenRect[areaNum]; }
217  void ShowPortals();
218 
219  //--------------------------
220  // RenderWorld_demo.cpp
221 
222  void StartWritingDemo( idDemoFile *demo );
223  void StopWritingDemo();
224  bool ProcessDemoCommand( idDemoFile *readDemo, renderView_t *demoRenderView, int *demoTimeOffset );
225 
226  void WriteLoadMap();
227  void WriteRenderView( const renderView_t *renderView );
228  void WriteVisibleDefs( const viewDef_t *viewDef );
229  void WriteFreeLight( qhandle_t handle );
230  void WriteFreeEntity( qhandle_t handle );
231  void WriteRenderLight( qhandle_t handle, const renderLight_t *light );
232  void WriteRenderEntity( qhandle_t handle, const renderEntity_t *ent );
233  void ReadRenderEntity();
234  void ReadRenderLight();
235 
236 
237  //--------------------------
238  // RenderWorld.cpp
239 
240  void ResizeInteractionTable();
241 
243  void AddLightRefToArea( idRenderLightLocal *light, portalArea_t *area );
244 
245  void RecurseProcBSP_r( modelTrace_t *results, int parentNodeNum, int nodeNum, float p1f, float p2f, const idVec3 &p1, const idVec3 &p2 ) const;
246 
247  void BoundsInAreas_r( int nodeNum, const idBounds &bounds, int *areas, int *numAreas, int maxAreas ) const;
248 
249  float DrawTextLength( const char *text, float scale, int len = 0 );
250 
251  void FreeInteractions();
252 
253  void PushVolumeIntoTree_r( idRenderEntityLocal *def, idRenderLightLocal *light, const idSphere *sphere, int numPoints, const idVec3 (*points), int nodeNum );
254 
255  void PushVolumeIntoTree( idRenderEntityLocal *def, idRenderLightLocal *light, int numPoints, const idVec3 (*points) );
256 
257  //-------------------------------
258  // tr_light.c
260 };
261 
262 #endif /* !__RENDERWORLDLOCAL_H__ */
bool ProcessDemoCommand(idDemoFile *readDemo, renderView_t *demoRenderView, int *demoTimeOffset)
void AddEntityRefToArea(idRenderEntityLocal *def, portalArea_t *area)
virtual qhandle_t AddEntityDef(const renderEntity_t *re)
byte color[4]
Definition: MegaTexture.cpp:54
virtual void RegenerateWorld()
GLsizei const GLfloat * points
Definition: glext.h:3884
virtual void DebugCircle(const idVec4 &color, const idVec3 &origin, const idVec3 &dir, const float radius, const int numSteps, const int lifetime=0, const bool depthTest=false)
void SetPortalState(qhandle_t portal, int blockingBits)
int qhandle_t
Definition: Lib.h:81
idList< idRenderModel * > localModels
virtual const renderLight_t * GetRenderLight(qhandle_t lightHandle) const
void FlowViewThroughPortals(const idVec3 origin, int numPlanes, const idPlane *planes)
virtual exitPortal_t GetPortal(int areaNum, int portalNum)
struct portalArea_s portalArea_t
areaReference_t lightRefs
virtual void DebugPolygon(const idVec4 &color, const idWinding &winding, const int lifeTime=0, const bool depthTest=false)
virtual void UpdateEntityDef(qhandle_t entityHandle, const renderEntity_t *re)
void FloodViewThroughArea_r(const idVec3 origin, int areaNum, const struct portalStack_s *ps)
portalConnection_t
Definition: RenderWorld.h:257
idRenderLightLocal * fogLight
virtual void RemoveDecals(qhandle_t entityHandle)
virtual qhandle_t AddLightDef(const renderLight_t *rlight)
virtual void UpdateLightDef(qhandle_t lightHandle, const renderLight_t *rlight)
idScreenRect & GetAreaScreenRect(int areaNum) const
GLenum GLenum GLenum GLenum GLenum scale
Definition: glext.h:4804
void WriteRenderEntity(qhandle_t handle, const renderEntity_t *ent)
void AddAreaEntityRefs(int areaNum, const struct portalStack_s *ps)
idList< idRenderEntityLocal * > entityDefs
virtual void DebugSphere(const idVec4 &color, const idSphere &sphere, const int lifetime=0, bool depthTest=false)
void FlowLightThroughPortals(idRenderLightLocal *light)
virtual void RenderScene(const renderView_t *renderView)
virtual void DebugClearPolygons(int time)
void FindViewLightsAndEntities(void)
virtual bool InitFromMap(const char *mapName)
bool CullLightByPortals(const idRenderLightLocal *light, const struct portalStack_s *ps)
Definition: Vector.h:316
struct portal_s portal_t
void WriteRenderLight(qhandle_t handle, const renderLight_t *light)
virtual void DebugArrow(const idVec4 &color, const idVec3 &start, const idVec3 &end, int size, const int lifetime=0)
void PushVolumeIntoTree_r(idRenderEntityLocal *def, idRenderLightLocal *light, const idSphere *sphere, int numPoints, const idVec3(*points), int nodeNum)
void AddAreaLightRefs(int areaNum, const struct portalStack_s *ps)
virtual void DebugBox(const idVec4 &color, const idBox &box, const int lifetime=0)
GLuint src
Definition: glext.h:5390
GLenum GLsizei len
Definition: glext.h:3472
virtual void DebugBounds(const idVec4 &color, const idBounds &bounds, const idVec3 &org=vec3_origin, const int lifetime=0)
virtual bool Trace(modelTrace_t &trace, const idVec3 &start, const idVec3 &end, const float radius, bool skipDynamic=true, bool skipPlayer=false) const
areaNumRef_t * FloodFrustumAreas(const idFrustum &frustum, areaNumRef_t *areas)
struct doublePortal_s doublePortal_t
void WriteFreeEntity(qhandle_t handle)
idList< idRenderLightLocal * > lightDefs
void WriteRenderView(const renderView_t *renderView)
void ResizeInteractionTable()
virtual void DebugLine(const idVec4 &color, const idVec3 &start, const idVec3 &end, const int lifetime=0, const bool depthTest=false)
struct doublePortal_s * nextFoggedPortal
qhandle_t FindPortal(const idBounds &b) const
int NumPortals(void) const
doublePortal_t * doublePortals
Definition: Lexer.h:137
idInteraction ** interactionTable
void StartWritingDemo(idDemoFile *demo)
virtual void DrawText(const char *text, const idVec3 &origin, float scale, const idVec4 &color, const idMat3 &viewAxis, const int align=1, const int lifetime=0, bool depthTest=false)
void WriteFreeLight(qhandle_t handle)
virtual void FreeLightDef(qhandle_t lightHandle)
virtual const renderEntity_t * GetRenderEntity(qhandle_t entityHandle) const
virtual bool FastWorldTrace(modelTrace_t &trace, const idVec3 &start, const idVec3 &end) const
GLubyte GLubyte GLubyte GLubyte w
Definition: glext.h:3454
Definition: Vector.h:808
const int LUDICROUS_INDEX
idVec3 vec3_origin(0.0f, 0.0f, 0.0f)
GLuint GLuint end
Definition: glext.h:2845
idRenderModel * ParseModel(idLexer *src)
virtual bool ModelTrace(modelTrace_t &trace, qhandle_t entityHandle, const idVec3 &start, const idVec3 &end, const float radius) const
struct portal_s * next
areaNumRef_t * FloodFrustumAreas_r(const idFrustum &frustum, const int areaNum, const idBounds &bounds, areaNumRef_t *areas)
Definition: Plane.h:71
virtual void DebugScreenRect(const idVec4 &color, const idScreenRect &rect, const viewDef_t *viewDef, const int lifetime=0)
bool PortalIsFoggedOut(const portal_t *p)
bool CullEntityByPortals(const idRenderEntityLocal *entity, const struct portalStack_s *ps)
idBlockAlloc< areaReference_t, 1024 > areaReferenceAllocator
virtual void ProjectDecalOntoWorld(const idFixedWinding &winding, const idVec3 &projectionOrigin, const bool parallel, const float fadeDepth, const idMaterial *material, const int startTime)
virtual ~idRenderWorldLocal()
void BoundsInAreas_r(int nodeNum, const idBounds &bounds, int *areas, int *numAreas, int maxAreas) const
bool AreasAreConnected(int areaNum1, int areaNum2, portalConnection_t connection)
struct portal_s * portals[2]
virtual void DebugWinding(const idVec4 &color, const idWinding &w, const idVec3 &origin, const idMat3 &axis, const int lifetime=0, const bool depthTest=false)
idBlockAlloc< areaNumRef_t, 1024 > areaNumRefAllocator
void RecurseProcBSP_r(modelTrace_t *results, int parentNodeNum, int nodeNum, float p1f, float p2f, const idVec3 &p1, const idVec3 &p2) const
virtual bool CheckAreaForPortalSky(int areaNum)
virtual int NumPortalsInArea(int areaNum)
int CommonChildrenArea_r(areaNode_t *node)
virtual int NumAreas(void) const
GLubyte GLubyte b
Definition: glext.h:4662
virtual void DebugClearLines(int time)
void FloodConnectedAreas(portalArea_t *area, int portalAttributeIndex)
virtual guiPoint_t GuiTrace(qhandle_t entityHandle, const idVec3 start, const idVec3 end) const
idWinding * w
virtual void GenerateAllInteractions()
float DrawTextLength(const char *text, float scale, int len=0)
Definition: Matrix.h:333
void CreateLightDefInteractions(idRenderLightLocal *ldef)
Definition: tr_light.cpp:541
virtual void SetRenderView(const renderView_t *renderView)
int connectedAreaNum[NUM_PORTAL_ATTRIBUTES]
portalArea_t * portalAreas
virtual void DebugCone(const idVec4 &color, const idVec3 &apex, const idVec3 &dir, float radius1, float radius2, const int lifetime=0)
void FloodLightThroughArea_r(idRenderLightLocal *light, int areaNum, const struct portalStack_s *ps)
idRenderModel * ParseShadowModel(idLexer *src)
GLsizeiptr size
Definition: glext.h:3112
virtual void DebugAxis(const idVec3 &origin, const idMat3 &axis)
virtual int PointInArea(const idVec3 &point) const
void BuildConnectedAreas_r(int areaNum)
idPlane plane
Definition: Str.h:116
int GetPortalState(qhandle_t portal)
portal_t * portals
areaReference_t entityRefs
idScreenRect ScreenRectFromWinding(const idWinding *w, viewEntity_t *space)
void AddLightRefToArea(idRenderLightLocal *light, portalArea_t *area)
void PushVolumeIntoTree(idRenderEntityLocal *def, idRenderLightLocal *light, int numPoints, const idVec3(*points))
struct doublePortal_s * doublePortal
void ParseInterAreaPortals(idLexer *src)
void WriteVisibleDefs(const viewDef_t *viewDef)
void ParseNodes(idLexer *src)
virtual void ProjectDecal(qhandle_t entityHandle, const idFixedWinding &winding, const idVec3 &projectionOrigin, const bool parallel, const float fadeDepth, const idMaterial *material, const int startTime)
GLfloat GLfloat p
Definition: glext.h:4674
virtual void ProjectOverlay(qhandle_t entityHandle, const idPlane localTextureAxis[2], const idMaterial *material)
void AddAreaRefs(int areaNum, const struct portalStack_s *ps)
idScreenRect * areaScreenRect
virtual void FreeEntityDef(qhandle_t entityHandle)
idBlockAlloc< idInteraction, 256 > interactionAllocator
Definition: Box.h:40
GLuint start
Definition: glext.h:2845
virtual void DebugFrustum(const idVec4 &color, const idFrustum &frustum, const bool showFromOrigin=false, const int lifetime=0)
virtual int BoundsInAreas(const idBounds &bounds, int *areas, int maxAreas) const