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.

213 lines
5.8 KiB

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