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.

215 lines
5.9 KiB

  1. //========= Copyright � 1996-2005, Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose: This module defines the CPowerInfo class, which contains a
  4. // whole bunch of precalculated data for each displacement power.
  5. // It holds data that indicates how to tesselate, how to access
  6. // neighbor displacements, etc.
  7. //
  8. // $NoKeywords: $
  9. //=============================================================================//
  10. #ifndef DISP_POWERINFO_H
  11. #define DISP_POWERINFO_H
  12. #ifdef _WIN32
  13. #pragma once
  14. #endif
  15. #include "disp_vertindex.h"
  16. #include "bspfile.h"
  17. #define NUM_POWERINFOS (MAX_MAP_DISP_POWER+1)
  18. struct DispNodeInfo_t
  19. {
  20. enum
  21. {
  22. // Indicates if any children at all have triangles
  23. CHILDREN_HAVE_TRIANGLES = 0x1
  24. };
  25. // Indicates which tesselation indices are associated with a node
  26. unsigned short m_FirstTesselationIndex;
  27. unsigned char m_Count;
  28. unsigned char m_Flags;
  29. Vector m_mins; // AABB for node triangles
  30. Vector m_maxs;
  31. };
  32. // ------------------------------------------------------------------------ //
  33. // CTesselateWindings are used to tell what order a node needs to visit
  34. // vertices while tesselating.
  35. // ------------------------------------------------------------------------ //
  36. class CTesselateVert
  37. {
  38. public:
  39. CTesselateVert( CVertIndex const &index, int iNode );
  40. CVertIndex m_Index;
  41. short m_iNode; // Which node this vert is a part of (-1 on left, right, up, and down).
  42. };
  43. class CTesselateWinding
  44. {
  45. public:
  46. CTesselateVert *m_Verts;
  47. short m_nVerts; // (includes the last vert)
  48. };
  49. class CVertDependency
  50. {
  51. public:
  52. // Returns false if there is no dependency stored here.
  53. bool IsValid() { return m_iVert.x != -1; }
  54. public:
  55. // The vert index is in the same power as the source displacement.
  56. // It is also wrapped, so for example, on the middle of the right edge
  57. // of a 3x3, it will have a dependency on the 3x3's root node (1,1), and it
  58. // will have another (1,1) entry that references a neighbor.
  59. CVertIndex m_iVert;
  60. // This is -1 if the vert exists inside the source displacement.
  61. // It is one of the NEIGHBOREDGE_ codes above if it reaches into a neighbor.
  62. short m_iNeighbor;
  63. };
  64. // Precalculated data about displacement vertices.
  65. class CVertInfo
  66. {
  67. public:
  68. CVertInfo();
  69. // These are the vertices that this vertex depends on (vertices that must be
  70. // active for this vert to exist).
  71. CVertDependency m_Dependencies[2];
  72. // These are the vertices that have this vert in their m_Dependencies.
  73. enum { NUM_REVERSE_DEPENDENCIES=4 };
  74. CVertDependency m_ReverseDependencies[NUM_REVERSE_DEPENDENCIES];
  75. short m_iNodeLevel; // -1 if this is not a node. Otherwise, the recursion level
  76. // of this node (root node = 1).
  77. CVertIndex m_iParent; // x=-1 if this is a not a node or if it's the root node.
  78. };
  79. class CTwoUShorts
  80. {
  81. public:
  82. unsigned short m_Values[2];
  83. };
  84. class CFourVerts
  85. {
  86. public:
  87. CVertIndex m_Verts[4];
  88. };
  89. // Used for referencing triangles in the fully-tesselated displacement by index.
  90. class CTriInfo
  91. {
  92. public:
  93. unsigned short m_Indices[3];
  94. };
  95. // Precalculated data for displacements of a certain power.
  96. class CPowerInfo
  97. {
  98. public:
  99. CPowerInfo(
  100. CVertInfo *pVertInfo,
  101. CFourVerts *pSideVerts,
  102. CFourVerts *pChildVerts,
  103. CFourVerts *pSideVertCorners,
  104. CTwoUShorts *pErrorEdges,
  105. CTriInfo *pTriInfos );
  106. int GetPower() const { return m_Power; }
  107. int GetSideLength() const { return m_SideLength; }
  108. const CVertIndex& GetRootNode() const { return m_RootNode; }
  109. int GetMidPoint() const { return m_MidPoint; } // Half the edge length.
  110. // Get at the tri list.
  111. int GetNumTriInfos() const { return m_nTriInfos; }
  112. const CTriInfo* GetTriInfo( int i ) const { return &m_pTriInfos[i]; }
  113. // Get the number of vertices in a displacement of this power.
  114. int GetNumVerts() const { return m_MaxVerts; }
  115. // Return a corner point index. Indexed by the CORNER_ defines.
  116. const CVertIndex& GetCornerPointIndex( int iCorner ) const;
  117. public:
  118. CVertInfo *m_pVertInfo;
  119. CFourVerts *m_pSideVerts; // The 4 side verts for each node.
  120. CFourVerts *m_pChildVerts; // The 4 children for each node.
  121. CFourVerts *m_pSideVertCorners;
  122. CTwoUShorts *m_pErrorEdges; // These are the edges
  123. // that are used to measure the screenspace
  124. // error with respect to each vert.
  125. CTriInfo *m_pTriInfos;
  126. int m_nTriInfos;
  127. int m_Power;
  128. CVertIndex m_RootNode;
  129. int m_SideLength;
  130. int m_SideLengthM1; // Side length minus 1.
  131. int m_MidPoint; // Side length / 2.
  132. int m_MaxVerts; // m_SideLength * m_SideLength
  133. int m_NodeCount; // total # of nodes, including children
  134. // Precalculated increments if you're using a bit vector to represent nodes.
  135. // Starting at level 0 of the tree, this stores the increment between the nodes at this
  136. // level. Vectors holding node data are stored in preorder traversal, and these
  137. // increments tell the number of elements between nodes at each level.
  138. int m_NodeIndexIncrements[MAX_MAP_DISP_POWER];
  139. CVertIndex m_EdgeStartVerts[4];
  140. CVertIndex m_EdgeIncrements[4];
  141. CVertIndex m_NeighborStartVerts[4][4]; // [side][orientation]
  142. CVertIndex m_NeighborIncrements[4][4]; // [side][orientation]
  143. private:
  144. friend void InitPowerInfo( CPowerInfo *pInfo, int iMaxPower );
  145. CVertIndex m_CornerPointIndices[4];
  146. };
  147. // ----------------------------------------------------------------------------- //
  148. // Globals.
  149. // ----------------------------------------------------------------------------- //
  150. // Indexed by the TWINDING_ enums.
  151. extern CTesselateWinding g_TWinding;
  152. // ----------------------------------------------------------------------------- //
  153. // Functions.
  154. // ----------------------------------------------------------------------------- //
  155. // Valid indices are MIN_MAP_DISP_POWER through (and including) MAX_MAP_DISP_POWER.
  156. const CPowerInfo* GetPowerInfo( int iPower );
  157. #endif // DISP_POWERINFO_H