RenderWorld_local.h 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263
  1. /*
  2. ===========================================================================
  3. Doom 3 GPL Source Code
  4. Copyright (C) 1999-2011 id Software LLC, a ZeniMax Media company.
  5. This file is part of the Doom 3 GPL Source Code (?Doom 3 Source Code?).
  6. Doom 3 Source Code is free software: you can redistribute it and/or modify
  7. it under the terms of the GNU General Public License as published by
  8. the Free Software Foundation, either version 3 of the License, or
  9. (at your option) any later version.
  10. Doom 3 Source Code is distributed in the hope that it will be useful,
  11. but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. GNU General Public License for more details.
  14. You should have received a copy of the GNU General Public License
  15. along with Doom 3 Source Code. If not, see <http://www.gnu.org/licenses/>.
  16. 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.
  17. 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.
  18. ===========================================================================
  19. */
  20. #ifndef __RENDERWORLDLOCAL_H__
  21. #define __RENDERWORLDLOCAL_H__
  22. // assume any lightDef or entityDef index above this is an internal error
  23. const int LUDICROUS_INDEX = 10000;
  24. typedef struct portal_s {
  25. int intoArea; // area this portal leads to
  26. idWinding * w; // winding points have counter clockwise ordering seen this area
  27. idPlane plane; // view must be on the positive side of the plane to cross
  28. struct portal_s * next; // next portal of the area
  29. struct doublePortal_s * doublePortal;
  30. } portal_t;
  31. typedef struct doublePortal_s {
  32. struct portal_s * portals[2];
  33. int blockingBits; // PS_BLOCK_VIEW, PS_BLOCK_AIR, etc, set by doors that shut them off
  34. // A portal will be considered closed if it is past the
  35. // fog-out point in a fog volume. We only support a single
  36. // fog volume over each portal.
  37. idRenderLightLocal * fogLight;
  38. struct doublePortal_s * nextFoggedPortal;
  39. } doublePortal_t;
  40. typedef struct portalArea_s {
  41. int areaNum;
  42. int connectedAreaNum[NUM_PORTAL_ATTRIBUTES]; // if two areas have matching connectedAreaNum, they are
  43. // not separated by a portal with the apropriate PS_BLOCK_* blockingBits
  44. int viewCount; // set by R_FindViewLightsAndEntities
  45. portal_t * portals; // never changes after load
  46. areaReference_t entityRefs; // head/tail of doubly linked list, may change
  47. areaReference_t lightRefs; // head/tail of doubly linked list, may change
  48. } portalArea_t;
  49. static const int CHILDREN_HAVE_MULTIPLE_AREAS = -2;
  50. static const int AREANUM_SOLID = -1;
  51. typedef struct {
  52. idPlane plane;
  53. int children[2]; // negative numbers are (-1 - areaNumber), 0 = solid
  54. int commonChildrenArea; // if all children are either solid or a single area,
  55. // this is the area number, else CHILDREN_HAVE_MULTIPLE_AREAS
  56. } areaNode_t;
  57. class idRenderWorldLocal : public idRenderWorld {
  58. public:
  59. idRenderWorldLocal();
  60. virtual ~idRenderWorldLocal();
  61. virtual qhandle_t AddEntityDef( const renderEntity_t *re );
  62. virtual void UpdateEntityDef( qhandle_t entityHandle, const renderEntity_t *re );
  63. virtual void FreeEntityDef( qhandle_t entityHandle );
  64. virtual const renderEntity_t *GetRenderEntity( qhandle_t entityHandle ) const;
  65. virtual qhandle_t AddLightDef( const renderLight_t *rlight );
  66. virtual void UpdateLightDef( qhandle_t lightHandle, const renderLight_t *rlight );
  67. virtual void FreeLightDef( qhandle_t lightHandle );
  68. virtual const renderLight_t *GetRenderLight( qhandle_t lightHandle ) const;
  69. virtual bool CheckAreaForPortalSky( int areaNum );
  70. virtual void GenerateAllInteractions();
  71. virtual void RegenerateWorld();
  72. virtual void ProjectDecalOntoWorld( const idFixedWinding &winding, const idVec3 &projectionOrigin, const bool parallel, const float fadeDepth, const idMaterial *material, const int startTime );
  73. virtual void ProjectDecal( qhandle_t entityHandle, const idFixedWinding &winding, const idVec3 &projectionOrigin, const bool parallel, const float fadeDepth, const idMaterial *material, const int startTime );
  74. virtual void ProjectOverlay( qhandle_t entityHandle, const idPlane localTextureAxis[2], const idMaterial *material );
  75. virtual void RemoveDecals( qhandle_t entityHandle );
  76. virtual void SetRenderView( const renderView_t *renderView );
  77. virtual void RenderScene( const renderView_t *renderView );
  78. virtual int NumAreas( void ) const;
  79. virtual int PointInArea( const idVec3 &point ) const;
  80. virtual int BoundsInAreas( const idBounds &bounds, int *areas, int maxAreas ) const;
  81. virtual int NumPortalsInArea( int areaNum );
  82. virtual exitPortal_t GetPortal( int areaNum, int portalNum );
  83. virtual guiPoint_t GuiTrace( qhandle_t entityHandle, const idVec3 start, const idVec3 end ) const;
  84. virtual bool ModelTrace( modelTrace_t &trace, qhandle_t entityHandle, const idVec3 &start, const idVec3 &end, const float radius ) const;
  85. virtual bool Trace( modelTrace_t &trace, const idVec3 &start, const idVec3 &end, const float radius, bool skipDynamic = true, bool skipPlayer = false ) const;
  86. virtual bool FastWorldTrace( modelTrace_t &trace, const idVec3 &start, const idVec3 &end ) const;
  87. virtual void DebugClearLines( int time );
  88. virtual void DebugLine( const idVec4 &color, const idVec3 &start, const idVec3 &end, const int lifetime = 0, const bool depthTest = false );
  89. virtual void DebugArrow( const idVec4 &color, const idVec3 &start, const idVec3 &end, int size, const int lifetime = 0 );
  90. virtual void DebugWinding( const idVec4 &color, const idWinding &w, const idVec3 &origin, const idMat3 &axis, const int lifetime = 0, const bool depthTest = false );
  91. 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 );
  92. virtual void DebugSphere( const idVec4 &color, const idSphere &sphere, const int lifetime = 0, bool depthTest = false );
  93. virtual void DebugBounds( const idVec4 &color, const idBounds &bounds, const idVec3 &org = vec3_origin, const int lifetime = 0 );
  94. virtual void DebugBox( const idVec4 &color, const idBox &box, const int lifetime = 0 );
  95. virtual void DebugFrustum( const idVec4 &color, const idFrustum &frustum, const bool showFromOrigin = false, const int lifetime = 0 );
  96. virtual void DebugCone( const idVec4 &color, const idVec3 &apex, const idVec3 &dir, float radius1, float radius2, const int lifetime = 0 );
  97. virtual void DebugScreenRect( const idVec4 &color, const idScreenRect &rect, const viewDef_t *viewDef, const int lifetime = 0 );
  98. virtual void DebugAxis( const idVec3 &origin, const idMat3 &axis );
  99. virtual void DebugClearPolygons( int time );
  100. virtual void DebugPolygon( const idVec4 &color, const idWinding &winding, const int lifeTime = 0, const bool depthTest = false );
  101. 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 );
  102. //-----------------------
  103. idStr mapName; // ie: maps/tim_dm2.proc, written to demoFile
  104. ID_TIME_T mapTimeStamp; // for fast reloads of the same level
  105. areaNode_t * areaNodes;
  106. int numAreaNodes;
  107. portalArea_t * portalAreas;
  108. int numPortalAreas;
  109. int connectedAreaNum; // incremented every time a door portal state changes
  110. idScreenRect * areaScreenRect;
  111. doublePortal_t * doublePortals;
  112. int numInterAreaPortals;
  113. idList<idRenderModel *> localModels;
  114. idList<idRenderEntityLocal*> entityDefs;
  115. idList<idRenderLightLocal*> lightDefs;
  116. idBlockAlloc<areaReference_t, 1024> areaReferenceAllocator;
  117. idBlockAlloc<idInteraction, 256> interactionAllocator;
  118. idBlockAlloc<areaNumRef_t, 1024> areaNumRefAllocator;
  119. // all light / entity interactions are referenced here for fast lookup without
  120. // having to crawl the doubly linked lists. EnntityDefs are sequential for better
  121. // cache access, because the table is accessed by light in idRenderWorldLocal::CreateLightDefInteractions()
  122. // Growing this table is time consuming, so we add a pad value to the number
  123. // of entityDefs and lightDefs
  124. idInteraction ** interactionTable;
  125. int interactionTableWidth; // entityDefs
  126. int interactionTableHeight; // lightDefs
  127. bool generateAllInteractionsCalled;
  128. //-----------------------
  129. // RenderWorld_load.cpp
  130. idRenderModel * ParseModel( idLexer *src );
  131. idRenderModel * ParseShadowModel( idLexer *src );
  132. void SetupAreaRefs();
  133. void ParseInterAreaPortals( idLexer *src );
  134. void ParseNodes( idLexer *src );
  135. int CommonChildrenArea_r( areaNode_t *node );
  136. void FreeWorld();
  137. void ClearWorld();
  138. void FreeDefs();
  139. void TouchWorldModels( void );
  140. void AddWorldModelEntities();
  141. void ClearPortalStates();
  142. virtual bool InitFromMap( const char *mapName );
  143. //--------------------------
  144. // RenderWorld_portals.cpp
  145. idScreenRect ScreenRectFromWinding( const idWinding *w, viewEntity_t *space );
  146. bool PortalIsFoggedOut( const portal_t *p );
  147. void FloodViewThroughArea_r( const idVec3 origin, int areaNum, const struct portalStack_s *ps );
  148. void FlowViewThroughPortals( const idVec3 origin, int numPlanes, const idPlane *planes );
  149. void FloodLightThroughArea_r( idRenderLightLocal *light, int areaNum, const struct portalStack_s *ps );
  150. void FlowLightThroughPortals( idRenderLightLocal *light );
  151. areaNumRef_t * FloodFrustumAreas_r( const idFrustum &frustum, const int areaNum, const idBounds &bounds, areaNumRef_t *areas );
  152. areaNumRef_t * FloodFrustumAreas( const idFrustum &frustum, areaNumRef_t *areas );
  153. bool CullEntityByPortals( const idRenderEntityLocal *entity, const struct portalStack_s *ps );
  154. void AddAreaEntityRefs( int areaNum, const struct portalStack_s *ps );
  155. bool CullLightByPortals( const idRenderLightLocal *light, const struct portalStack_s *ps );
  156. void AddAreaLightRefs( int areaNum, const struct portalStack_s *ps );
  157. void AddAreaRefs( int areaNum, const struct portalStack_s *ps );
  158. void BuildConnectedAreas_r( int areaNum );
  159. void BuildConnectedAreas( void );
  160. void FindViewLightsAndEntities( void );
  161. int NumPortals( void ) const;
  162. qhandle_t FindPortal( const idBounds &b ) const;
  163. void SetPortalState( qhandle_t portal, int blockingBits );
  164. int GetPortalState( qhandle_t portal );
  165. bool AreasAreConnected( int areaNum1, int areaNum2, portalConnection_t connection );
  166. void FloodConnectedAreas( portalArea_t *area, int portalAttributeIndex );
  167. idScreenRect & GetAreaScreenRect( int areaNum ) const { return areaScreenRect[areaNum]; }
  168. void ShowPortals();
  169. //--------------------------
  170. // RenderWorld_demo.cpp
  171. void StartWritingDemo( idDemoFile *demo );
  172. void StopWritingDemo();
  173. bool ProcessDemoCommand( idDemoFile *readDemo, renderView_t *demoRenderView, int *demoTimeOffset );
  174. void WriteLoadMap();
  175. void WriteRenderView( const renderView_t *renderView );
  176. void WriteVisibleDefs( const viewDef_t *viewDef );
  177. void WriteFreeLight( qhandle_t handle );
  178. void WriteFreeEntity( qhandle_t handle );
  179. void WriteRenderLight( qhandle_t handle, const renderLight_t *light );
  180. void WriteRenderEntity( qhandle_t handle, const renderEntity_t *ent );
  181. void ReadRenderEntity();
  182. void ReadRenderLight();
  183. //--------------------------
  184. // RenderWorld.cpp
  185. void ResizeInteractionTable();
  186. void AddEntityRefToArea( idRenderEntityLocal *def, portalArea_t *area );
  187. void AddLightRefToArea( idRenderLightLocal *light, portalArea_t *area );
  188. void RecurseProcBSP_r( modelTrace_t *results, int parentNodeNum, int nodeNum, float p1f, float p2f, const idVec3 &p1, const idVec3 &p2 ) const;
  189. void BoundsInAreas_r( int nodeNum, const idBounds &bounds, int *areas, int *numAreas, int maxAreas ) const;
  190. float DrawTextLength( const char *text, float scale, int len = 0 );
  191. void FreeInteractions();
  192. void PushVolumeIntoTree_r( idRenderEntityLocal *def, idRenderLightLocal *light, const idSphere *sphere, int numPoints, const idVec3 (*points), int nodeNum );
  193. void PushVolumeIntoTree( idRenderEntityLocal *def, idRenderLightLocal *light, int numPoints, const idVec3 (*points) );
  194. //-------------------------------
  195. // tr_light.c
  196. void CreateLightDefInteractions( idRenderLightLocal *ldef );
  197. };
  198. #endif /* !__RENDERWORLDLOCAL_H__ */