Team Fortress 2 Source Code as on 22/4/2020
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

217 lines
7.4 KiB

  1. //========= Copyright Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose:
  4. //
  5. // $Revision: $
  6. // $NoKeywords: $
  7. //
  8. // This file contains code to allow us to associate client data with bsp leaves.
  9. //
  10. //===========================================================================//
  11. #if !defined( CLIENTLEAFSYSTEM_H )
  12. #define CLIENTLEAFSYSTEM_H
  13. #ifdef _WIN32
  14. #pragma once
  15. #endif
  16. #include "igamesystem.h"
  17. #include "engine/IClientLeafSystem.h"
  18. #include "cdll_int.h"
  19. #include "ivrenderview.h"
  20. #include "tier1/mempool.h"
  21. #include "tier1/refcount.h"
  22. //-----------------------------------------------------------------------------
  23. // Forward declarations
  24. //-----------------------------------------------------------------------------
  25. struct WorldListInfo_t;
  26. class IClientRenderable;
  27. class Vector;
  28. class CGameTrace;
  29. typedef CGameTrace trace_t;
  30. struct Ray_t;
  31. class Vector2D;
  32. class CStaticProp;
  33. //-----------------------------------------------------------------------------
  34. // Handle to an renderables in the client leaf system
  35. //-----------------------------------------------------------------------------
  36. enum
  37. {
  38. DETAIL_PROP_RENDER_HANDLE = (ClientRenderHandle_t)0xfffe
  39. };
  40. class CClientRenderablesList : public CRefCounted<>
  41. {
  42. DECLARE_FIXEDSIZE_ALLOCATOR( CClientRenderablesList );
  43. public:
  44. enum
  45. {
  46. MAX_GROUP_ENTITIES = 4096
  47. };
  48. struct CEntry
  49. {
  50. IClientRenderable *m_pRenderable;
  51. unsigned short m_iWorldListInfoLeaf; // NOTE: this indexes WorldListInfo_t's leaf list.
  52. unsigned short m_TwoPass;
  53. ClientRenderHandle_t m_RenderHandle;
  54. };
  55. // The leaves for the entries are in the order of the leaves you call CollateRenderablesInLeaf in.
  56. CEntry m_RenderGroups[RENDER_GROUP_COUNT][MAX_GROUP_ENTITIES];
  57. int m_RenderGroupCounts[RENDER_GROUP_COUNT];
  58. };
  59. //-----------------------------------------------------------------------------
  60. // Used by CollateRenderablesInLeaf
  61. //-----------------------------------------------------------------------------
  62. struct SetupRenderInfo_t
  63. {
  64. WorldListInfo_t *m_pWorldListInfo;
  65. CClientRenderablesList *m_pRenderList;
  66. Vector m_vecRenderOrigin;
  67. Vector m_vecRenderForward;
  68. int m_nRenderFrame;
  69. int m_nDetailBuildFrame; // The "render frame" for detail objects
  70. float m_flRenderDistSq;
  71. bool m_bDrawDetailObjects : 1;
  72. bool m_bDrawTranslucentObjects : 1;
  73. SetupRenderInfo_t()
  74. {
  75. m_bDrawDetailObjects = true;
  76. m_bDrawTranslucentObjects = true;
  77. }
  78. };
  79. //-----------------------------------------------------------------------------
  80. // A handle associated with shadows managed by the client leaf system
  81. //-----------------------------------------------------------------------------
  82. typedef unsigned short ClientLeafShadowHandle_t;
  83. enum
  84. {
  85. CLIENT_LEAF_SHADOW_INVALID_HANDLE = (ClientLeafShadowHandle_t)~0
  86. };
  87. //-----------------------------------------------------------------------------
  88. // The client leaf system
  89. //-----------------------------------------------------------------------------
  90. abstract_class IClientLeafShadowEnum
  91. {
  92. public:
  93. // The user ID is the id passed into CreateShadow
  94. virtual void EnumShadow( ClientShadowHandle_t userId ) = 0;
  95. };
  96. // subclassed by things which wish to add per-leaf data managed by the client leafsystem
  97. class CClientLeafSubSystemData
  98. {
  99. public:
  100. virtual ~CClientLeafSubSystemData( void )
  101. {
  102. }
  103. };
  104. // defines for subsystem ids. each subsystem id uses up one pointer in each leaf
  105. #define CLSUBSYSTEM_DETAILOBJECTS 0
  106. #define N_CLSUBSYSTEMS 1
  107. //-----------------------------------------------------------------------------
  108. // The client leaf system
  109. //-----------------------------------------------------------------------------
  110. abstract_class IClientLeafSystem : public IClientLeafSystemEngine, public IGameSystemPerFrame
  111. {
  112. public:
  113. // Adds and removes renderables from the leaf lists
  114. virtual void AddRenderable( IClientRenderable* pRenderable, RenderGroup_t group ) = 0;
  115. // This tells if the renderable is in the current PVS. It assumes you've updated the renderable
  116. // with RenderableChanged() calls
  117. virtual bool IsRenderableInPVS( IClientRenderable *pRenderable ) = 0;
  118. virtual void SetSubSystemDataInLeaf( int leaf, int nSubSystemIdx, CClientLeafSubSystemData *pData ) =0;
  119. virtual CClientLeafSubSystemData *GetSubSystemDataInLeaf( int leaf, int nSubSystemIdx ) =0;
  120. virtual void SetDetailObjectsInLeaf( int leaf, int firstDetailObject, int detailObjectCount ) = 0;
  121. virtual void GetDetailObjectsInLeaf( int leaf, int& firstDetailObject, int& detailObjectCount ) = 0;
  122. // Indicates which leaves detail objects should be rendered from, returns the detais objects in the leaf
  123. virtual void DrawDetailObjectsInLeaf( int leaf, int frameNumber, int& firstDetailObject, int& detailObjectCount ) = 0;
  124. // Should we draw detail objects (sprites or models) in this leaf (because it's close enough to the view)
  125. // *and* are there any objects in the leaf?
  126. virtual bool ShouldDrawDetailObjectsInLeaf( int leaf, int frameNumber ) = 0;
  127. // Call this when a renderable origin/angles/bbox parameters has changed
  128. virtual void RenderableChanged( ClientRenderHandle_t handle ) = 0;
  129. // Set a render group
  130. virtual void SetRenderGroup( ClientRenderHandle_t handle, RenderGroup_t group ) = 0;
  131. // Computes which leaf translucent objects should be rendered in
  132. virtual void ComputeTranslucentRenderLeaf( int count, const LeafIndex_t *pLeafList, const LeafFogVolume_t *pLeafFogVolumeList, int frameNumber, int viewID ) = 0;
  133. // Put renderables into their appropriate lists.
  134. virtual void BuildRenderablesList( const SetupRenderInfo_t &info ) = 0;
  135. // Put renderables in the leaf into their appropriate lists.
  136. virtual void CollateViewModelRenderables( CUtlVector< IClientRenderable * >& opaqueList, CUtlVector< IClientRenderable * >& translucentList ) = 0;
  137. // Call this to deactivate static prop rendering..
  138. virtual void DrawStaticProps( bool enable ) = 0;
  139. // Call this to deactivate small object rendering
  140. virtual void DrawSmallEntities( bool enable ) = 0;
  141. // The following methods are related to shadows...
  142. virtual ClientLeafShadowHandle_t AddShadow( ClientShadowHandle_t userId, unsigned short flags ) = 0;
  143. virtual void RemoveShadow( ClientLeafShadowHandle_t h ) = 0;
  144. // Project a shadow
  145. virtual void ProjectShadow( ClientLeafShadowHandle_t handle, int nLeafCount, const int *pLeafList ) = 0;
  146. // Project a projected texture spotlight
  147. virtual void ProjectFlashlight( ClientLeafShadowHandle_t handle, int nLeafCount, const int *pLeafList ) = 0;
  148. // Find all shadow casters in a set of leaves
  149. virtual void EnumerateShadowsInLeaves( int leafCount, LeafIndex_t* pLeaves, IClientLeafShadowEnum* pEnum ) = 0;
  150. // Fill in a list of the leaves this renderable is in.
  151. // Returns -1 if the handle is invalid.
  152. virtual int GetRenderableLeaves( ClientRenderHandle_t handle, int leaves[128] ) = 0;
  153. // Get leaves this renderable is in
  154. virtual bool GetRenderableLeaf ( ClientRenderHandle_t handle, int* pOutLeaf, const int* pInIterator = 0, int* pOutIterator = 0 ) = 0;
  155. // Use alternate translucent sorting algorithm (draw translucent objects in the furthest leaf they lie in)
  156. virtual void EnableAlternateSorting( ClientRenderHandle_t handle, bool bEnable ) = 0;
  157. };
  158. //-----------------------------------------------------------------------------
  159. // Singleton accessor
  160. //-----------------------------------------------------------------------------
  161. extern IClientLeafSystem *g_pClientLeafSystem;
  162. inline IClientLeafSystem* ClientLeafSystem()
  163. {
  164. return g_pClientLeafSystem;
  165. }
  166. #endif // CLIENTLEAFSYSTEM_H