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.

200 lines
5.4 KiB

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