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.

199 lines
5.4 KiB

  1. //========= Copyright Valve Corporation, All rights reserved. ============//
  2. //
  3. // A class representing a subselection of something like a mesh
  4. //
  5. //=============================================================================
  6. #ifndef DMECOMPONENT_H
  7. #define DMECOMPONENT_H
  8. #ifdef _WIN32
  9. #pragma once
  10. #endif
  11. #include "datamodel/dmelement.h"
  12. //-----------------------------------------------------------------------------
  13. //
  14. //
  15. //
  16. //-----------------------------------------------------------------------------
  17. class CDmeComponent : public CDmElement
  18. {
  19. DEFINE_ELEMENT( CDmeComponent, CDmElement );
  20. public:
  21. enum Component_t
  22. {
  23. COMP_INVALID = -1,
  24. COMP_VTX,
  25. COMP_FACE,
  26. STANDARD_COMP_COUNT
  27. };
  28. // resolve internal data from changed attributes
  29. virtual void Resolve();
  30. // What type of component is this
  31. Component_t Type() const;
  32. // How many pieces are in this component
  33. virtual int Count() const;
  34. // Are there no pieces in this component
  35. bool IsEmpty() const;
  36. // Are all possible pieces in this component
  37. bool IsComplete() const;
  38. // Is this an equivalent component to another component
  39. virtual bool IsEqual( const CDmeComponent *pRhs ) const;
  40. // Reset to an empty selection
  41. virtual void Clear();
  42. protected:
  43. CDmaVar< int > m_Type;
  44. CDmaVar< bool > m_bComplete;
  45. };
  46. //-----------------------------------------------------------------------------
  47. // The default type is invalid
  48. //-----------------------------------------------------------------------------
  49. inline CDmeComponent::Component_t CDmeComponent::Type() const
  50. {
  51. const int type( m_Type.Get() );
  52. if ( type < 0 || type >= STANDARD_COMP_COUNT )
  53. return COMP_INVALID;
  54. return static_cast< Component_t >( type );
  55. }
  56. //-----------------------------------------------------------------------------
  57. // Are there no pieces in this component
  58. //-----------------------------------------------------------------------------
  59. inline int CDmeComponent::Count() const
  60. {
  61. Assert( 0 );
  62. return 0;
  63. }
  64. //-----------------------------------------------------------------------------
  65. // Are there no pieces in this component
  66. //-----------------------------------------------------------------------------
  67. inline bool CDmeComponent::IsEmpty() const
  68. {
  69. return Count() == 0;
  70. }
  71. //-----------------------------------------------------------------------------
  72. // Are all possible pieces in this component
  73. //-----------------------------------------------------------------------------
  74. inline bool CDmeComponent::IsEqual( const CDmeComponent *pRhs ) const
  75. {
  76. return Type() == pRhs->Type() && Count() == pRhs->Count() && IsComplete() == pRhs->IsComplete();
  77. }
  78. //-----------------------------------------------------------------------------
  79. // Are all possible pieces in this component
  80. //-----------------------------------------------------------------------------
  81. inline bool CDmeComponent::IsComplete() const
  82. {
  83. return m_bComplete.Get();
  84. }
  85. //-----------------------------------------------------------------------------
  86. // Reset to an empty selection
  87. //-----------------------------------------------------------------------------
  88. inline void CDmeComponent::Clear()
  89. {
  90. m_bComplete.Set( false );
  91. }
  92. //-----------------------------------------------------------------------------
  93. //
  94. //
  95. //
  96. //-----------------------------------------------------------------------------
  97. class CDmeSingleIndexedComponent : public CDmeComponent
  98. {
  99. DEFINE_ELEMENT( CDmeSingleIndexedComponent, CDmeComponent );
  100. public:
  101. // resolve internal data from changed attributes
  102. virtual void Resolve();
  103. // From CDmeComponent
  104. virtual int Count() const;
  105. bool SetType( Component_t type );
  106. void AddComponent( int component, float weight = 1.0f );
  107. void AddComponents( const CUtlVector< int > &components );
  108. void AddComponents( const CUtlVector< int > &components, const CUtlVector< float > &weights );
  109. void RemoveComponent( int component );
  110. bool GetComponent( int index, int &component, float &weight ) const;
  111. bool GetWeight( int component, float &weight ) const;
  112. void GetComponents( CUtlVector< int > &components ) const;
  113. void GetComponents( CUtlVector< int > &components, CUtlVector< float > &weights ) const;
  114. void SetComplete( int nComplete );
  115. int GetComplete() const;
  116. bool HasComponent( int component ) const;
  117. virtual void Clear();
  118. void Add( const CDmeSingleIndexedComponent &rhs );
  119. void Add( const CDmeSingleIndexedComponent *pRhs ) { Assert( pRhs ); Add( *pRhs ); }
  120. void Union( const CDmeSingleIndexedComponent &rhs ) { Add( rhs ); }
  121. void Union( const CDmeSingleIndexedComponent *pRhs ) { Assert( pRhs ); Add( *pRhs ); }
  122. CDmeSingleIndexedComponent &operator+=( const CDmeSingleIndexedComponent &rhs ) { Add( rhs ); return *this; }
  123. void Subtract( const CDmeSingleIndexedComponent &rhs );
  124. void Subtract( const CDmeSingleIndexedComponent *pRhs ) { Assert( pRhs ); Subtract( *pRhs ); }
  125. void Complement( const CDmeSingleIndexedComponent &rhs ) { Subtract( rhs ); }
  126. void Complement( const CDmeSingleIndexedComponent *pRhs ) { Assert( pRhs ); Subtract( *pRhs ); }
  127. CDmeSingleIndexedComponent &operator-=( const CDmeSingleIndexedComponent &rhs ) { Subtract( rhs ); return *this; }
  128. void Intersection( const CDmeSingleIndexedComponent &rhs );
  129. void Intersection( const CDmeSingleIndexedComponent *pRhs ) { Assert( pRhs ); Intersection( *pRhs ); }
  130. protected:
  131. int BinarySearch( int component ) const;
  132. CDmaVar< int > m_CompleteCount;
  133. CDmaArray< int > m_Components;
  134. CDmaArray< float > m_Weights;
  135. };
  136. #endif // DMECOMPONENT_H