Counter Strike : Global Offensive Source Code
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.

183 lines
5.2 KiB

  1. //========= Copyright � 1996-2005, Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose:
  4. //
  5. // $NoKeywords: $
  6. //
  7. //===========================================================================//
  8. #ifndef C_FUNC_BREAKABLESURF_H
  9. #define C_FUNC_BREAKABLESURF_H
  10. #ifdef _WIN32
  11. #pragma once
  12. #endif
  13. #include "iviewrender.h"
  14. #include "proxyentity.h"
  15. #define MAX_NUM_PANELS 16
  16. #define NUM_EDGE_TYPES 4
  17. #define NUM_EDGE_STYLES 3
  18. extern IVDebugOverlay *debugoverlay;
  19. enum WinSide_t
  20. {
  21. WIN_SIDE_BOTTOM,
  22. WIN_SIDE_RIGHT,
  23. WIN_SIDE_TOP,
  24. WIN_SIDE_LEFT,
  25. };
  26. enum WinEdge_t
  27. {
  28. EDGE_NOT = -1, // No edge
  29. EDGE_NONE, /* No edge on both sides /##\ */
  30. EDGE_FULL, // Edge on both sides |##|
  31. EDGE_LEFT, /* Edge is on left only |##\ */
  32. EDGE_RIGHT, // Edge is on right only /##|
  33. };
  34. #define STYLE_HIGHLIGHT = -1;
  35. //-----------------------------------------------------------------------------
  36. // All the information associated with a particular handle
  37. //-----------------------------------------------------------------------------
  38. struct Panel_t
  39. {
  40. char m_nWidth;
  41. char m_nHeight;
  42. char m_nSide;
  43. char m_nEdgeType;
  44. char m_nStyle;
  45. };
  46. struct EdgeTexture_t
  47. {
  48. int m_nRenderIndex;
  49. int m_nStyle;
  50. CMaterialReference m_pMaterialEdge;
  51. CTextureReference m_pMaterialEdgeTexture;
  52. };
  53. class C_BreakableSurface : public C_BaseEntity, public IBrushRenderer
  54. {
  55. public:
  56. DECLARE_CLASS( C_BreakableSurface, C_BaseEntity );
  57. DECLARE_DATADESC();
  58. DECLARE_CLIENTCLASS();
  59. int m_nNumWide;
  60. int m_nNumHigh;
  61. float m_flPanelWidth;
  62. float m_flPanelHeight;
  63. Vector m_vNormal;
  64. Vector m_vCorner;
  65. bool m_bIsBroken;
  66. int m_nSurfaceType;
  67. // This is the texture we're going to use to multiply by the cracked base texture
  68. ITexture* m_pCurrentDetailTexture;
  69. // Stores linked list of edges to render
  70. CUtlLinkedList< Panel_t, unsigned short > m_RenderList;
  71. C_BreakableSurface();
  72. ~C_BreakableSurface();
  73. public:
  74. void InitMaterial(WinEdge_t nEdgeType, int nEdgeStyle, char const* pMaterialName);
  75. virtual void OnDataChanged( DataUpdateType_t updateType );
  76. virtual void OnPreDataChanged( DataUpdateType_t updateType );
  77. RenderableTranslucencyType_t ComputeTranslucencyType( void );
  78. bool HavePanel(int nWidth, int nHeight);
  79. bool RenderBrushModelSurface( IClientEntity* pBaseEntity, IBrushSurface* pBrushSurface );
  80. int DrawModel( int flags, const RenderableInstance_t &instance );
  81. void DrawSolidBlocks( IBrushSurface* pBrushSurface );
  82. virtual void OnRestore();
  83. virtual bool ShouldReceiveProjectedTextures( int flags );
  84. private:
  85. // One bit per pane
  86. CNetworkArray( bool, m_RawPanelBitVec, MAX_NUM_PANELS * MAX_NUM_PANELS );
  87. bool m_PrevRawPanelBitVec[ MAX_NUM_PANELS * MAX_NUM_PANELS ];
  88. // 2 bits of flags and 2 bits of edge type
  89. byte m_nPanelBits[MAX_NUM_PANELS][MAX_NUM_PANELS]; //UNDONE: allocate this dynamically?
  90. CMaterialReference m_pMaterialBox;
  91. EdgeTexture_t m_pSolid;
  92. EdgeTexture_t m_pEdge[NUM_EDGE_TYPES][NUM_EDGE_STYLES];
  93. inline bool InLegalRange(int nWidth, int nHeight);
  94. inline bool IsPanelSolid(int nWidth, int nHeight);
  95. inline bool IsPanelStale(int nWidth, int nHeight);
  96. inline void SetPanelSolid(int nWidth, int nHeight, bool value);
  97. inline void SetPanelStale(int nWidth, int nHeight, bool value);
  98. void DrawOneEdge( IBrushSurface* pBrushSurface, IMesh* pMesh,
  99. CMeshBuilder *pMeshBuilder, const Vector &vStartPos,
  100. const Vector &vWStep, const Vector &vHstep, WinSide_t nEdge);
  101. void DrawOneHighlight( IBrushSurface* pBrushSurface, IMesh* pMesh,
  102. CMeshBuilder *pMeshBuilder, const Vector &vStartPos,
  103. const Vector &vWStep, const Vector &vHstep, WinSide_t nEdge);
  104. void DrawOneBlock(IBrushSurface* pBrushSurface, IMesh* pMesh,
  105. CMeshBuilder *pMeshBuilder, const Vector &vPosition,
  106. const Vector &vWidth, const Vector &vHeight);
  107. void DrawRenderList( IBrushSurface* pBrushSurface);
  108. void DrawRenderListHighlights( IBrushSurface* pBrushSurface );
  109. int FindRenderPanel(int nWidth, int nHeight, WinSide_t nSide);
  110. void AddToRenderList(int nWidth, int nHeight, WinSide_t nSide, WinEdge_t nEdgeType, int forceStyle);
  111. int FindFirstRenderTexture(WinEdge_t nEdgeType, int nStyle);
  112. inline void SetStyleType( int w, int h, int type )
  113. {
  114. Assert( type < NUM_EDGE_STYLES );
  115. Assert( type >= 0 );
  116. // Clear old value
  117. m_nPanelBits[ w ][ h ] &= ( ~0x03 << 2 );
  118. // Insert new value
  119. m_nPanelBits[ w ][ h ] |= ( type << 2 );
  120. }
  121. inline int GetStyleType( int w, int h )
  122. {
  123. int value = m_nPanelBits[ w ][ h ];
  124. value = ( value >> 2 ) & 0x03;
  125. Assert( value < NUM_EDGE_STYLES );
  126. return value;
  127. }
  128. // Gets at the cracked version of the material
  129. void FindCrackedMaterial();
  130. CMaterialReference m_pCrackedMaterial;
  131. CTextureReference m_pMaterialBoxTexture;
  132. void UpdateEdgeType(int nWidth, int nHeight, int forceStyle = -1 );
  133. };
  134. class CBreakableSurfaceProxy : public CEntityMaterialProxy
  135. {
  136. public:
  137. CBreakableSurfaceProxy();
  138. virtual ~CBreakableSurfaceProxy();
  139. virtual bool Init( IMaterial *pMaterial, KeyValues *pKeyValues );
  140. virtual void OnBind( C_BaseEntity *pC_BaseEntity );
  141. virtual IMaterial *GetMaterial();
  142. private:
  143. // get at the material whose texture we're going to steal
  144. void AcquireSourceMaterial( C_BaseEntity* pEnt );
  145. IMaterialVar* m_BaseTextureVar;
  146. };
  147. #endif // C_FUNC_BREAKABLESURF_H