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.

186 lines
6.5 KiB

  1. //====== Copyright � 1996-2004, Valve Corporation, All rights reserved. =======
  2. //
  3. // Purpose:
  4. //
  5. //=============================================================================
  6. #include "movieobjects/dmeoperator.h"
  7. #include "movieobjects/dmeattributereference.h"
  8. #include "datamodel/dmelementfactoryhelper.h"
  9. // memdbgon must be the last include file in a .cpp file!!!
  10. #include "tier0/memdbgon.h"
  11. //-----------------------------------------------------------------------------
  12. // Expose this class to the scene database
  13. //-----------------------------------------------------------------------------
  14. IMPLEMENT_ABSTRACT_ELEMENT( DmeOperator, CDmeOperator );
  15. //-----------------------------------------------------------------------------
  16. // Purpose:
  17. //-----------------------------------------------------------------------------
  18. void CDmeOperator::OnConstruction()
  19. {
  20. m_nSortKey = -1;
  21. }
  22. void CDmeOperator::OnDestruction()
  23. {
  24. }
  25. //-----------------------------------------------------------------------------
  26. // IsDirty - ie needs to operate
  27. //-----------------------------------------------------------------------------
  28. bool CDmeOperator::IsDirty()
  29. {
  30. return BaseClass::IsDirty();
  31. }
  32. //-----------------------------------------------------------------------------
  33. // Purpose : get a list of all of the operators whose evaluation affects the
  34. // result of this operator's evaluation.
  35. //-----------------------------------------------------------------------------
  36. void CDmeOperator::GatherInputOperators( CUtlVector< CDmeOperator * > &operatorList )
  37. {
  38. // Another operator will only affect this operator if one or more of its output attributes is
  39. // an input attribute of this operator. So to find all of the input operators we first find all
  40. // of the input attributes of this operator, then find the elements which own those attributes
  41. // and find all of the operators referencing those elements. Finally we check to see if any of
  42. // the output attributes of the operators match any of the input attributes of this operator.
  43. // Find the input attributes of this operator.
  44. CUtlVector< CDmAttribute* > inputAttributes( 0, 32 );
  45. GetInputAttributes( inputAttributes );
  46. // Build a list of all the operators which are referencing any of the elements which own an input
  47. // attribute of this operator, these are all the operators which can possibly be input operators.
  48. int nInputAttributes = inputAttributes.Count();
  49. CUtlVector< CDmeOperator* > connectedOperators( 0, nInputAttributes );
  50. CUtlVector< CDmElement* > inputOwnerList( 0, nInputAttributes );
  51. for ( int iAttr = 0; iAttr < nInputAttributes; ++iAttr )
  52. {
  53. CDmAttribute *pInputAttr = inputAttributes[ iAttr ];
  54. if ( pInputAttr == NULL )
  55. continue;
  56. CDmElement *pInputOwner = pInputAttr->GetOwner();
  57. // If the owner of the input is another operator, add it directly to the connected operator list.
  58. if ( ( pInputOwner != this ) && ( pInputOwner->IsA( CDmeOperator::GetStaticTypeSymbol() ) ) )
  59. {
  60. connectedOperators.AddToTail( CastElement< CDmeOperator >( pInputOwner ) );
  61. continue;
  62. }
  63. // If the owner of the input is not an operator, check to see if it has any operators referring
  64. // to it. A list of these elements is kept so that the check is only done once per element.
  65. if ( inputOwnerList.Find( pInputOwner ) != inputOwnerList.InvalidIndex() )
  66. continue;
  67. inputOwnerList.AddToTail( pInputOwner );
  68. for ( DmAttributeReferenceIterator_t it = g_pDataModel->FirstAttributeReferencingElement( pInputOwner->GetHandle() );
  69. it != DMATTRIBUTE_REFERENCE_ITERATOR_INVALID;
  70. it = g_pDataModel->NextAttributeReferencingElement( it ) )
  71. {
  72. CDmAttribute *pAttr = g_pDataModel->GetAttribute( it );
  73. if ( pAttr == NULL )
  74. continue;
  75. CDmElement *pElement = pAttr->GetOwner();
  76. CDmeOperator *pOperator = CastElement< CDmeOperator >( pElement );
  77. if ( pOperator == NULL )
  78. {
  79. pOperator = FindAncestorReferencingElement< CDmeOperator >( pElement );
  80. }
  81. if ( pOperator != NULL )
  82. {
  83. if ( connectedOperators.Find( pOperator ) == connectedOperators.InvalidIndex() )
  84. {
  85. connectedOperators.AddToTail( pOperator );
  86. }
  87. }
  88. }
  89. }
  90. // Now check each of the connected operators to determine if any of its output attributes is one
  91. // of this operator's input attributes. If so add it to the list of output operators if it is not
  92. // already there. Note, as soon as one attribute match is found there is no need to check the rest.
  93. CUtlVector< CDmAttribute* > outputAttributes( 0, 32 );
  94. int nConnectedOperators = connectedOperators.Count();
  95. for ( int iOper = 0; iOper < nConnectedOperators; ++iOper )
  96. {
  97. CDmeOperator *pOperator = connectedOperators[ iOper ];
  98. outputAttributes.RemoveAll();
  99. pOperator->GetOutputAttributes( outputAttributes );
  100. int nOutputAttributes = outputAttributes.Count();
  101. for ( int iAttr = 0; iAttr < nOutputAttributes; ++iAttr )
  102. {
  103. CDmAttribute *pOuputAttr = outputAttributes[ iAttr ];
  104. if ( inputAttributes.Find( pOuputAttr ) != inputAttributes.InvalidIndex() )
  105. {
  106. if ( operatorList.Find( pOperator ) == operatorList.InvalidIndex() )
  107. {
  108. pOperator->GatherInputOperators( operatorList );
  109. operatorList.AddToTail( pOperator );
  110. }
  111. break;
  112. }
  113. }
  114. }
  115. }
  116. void CDmeOperator::SetSortKey( int key )
  117. {
  118. m_nSortKey = key;
  119. }
  120. int CDmeOperator::GetSortKey() const
  121. {
  122. return m_nSortKey;
  123. }
  124. //-----------------------------------------------------------------------------
  125. // Purpose : Gather a list of all of the operators referencing this element and
  126. // all of the operators that they depend on.
  127. //-----------------------------------------------------------------------------
  128. void GatherOperatorsForElement( CDmElement *pRootElement, CUtlVector< CDmeOperator * > &operatorList )
  129. {
  130. for ( DmAttributeReferenceIterator_t it = g_pDataModel->FirstAttributeReferencingElement( pRootElement->GetHandle() );
  131. it != DMATTRIBUTE_REFERENCE_ITERATOR_INVALID;
  132. it = g_pDataModel->NextAttributeReferencingElement( it ) )
  133. {
  134. CDmAttribute *pAttr = g_pDataModel->GetAttribute( it );
  135. CDmElement *pOwnerElement = pAttr->GetOwner();
  136. if ( !g_pDataModel->GetElement( pOwnerElement->GetHandle() ) )
  137. continue;
  138. CDmeOperator *pOperator = CastElement< CDmeOperator >( pOwnerElement );
  139. if ( pOwnerElement->IsA( CDmeAttributeReference::GetStaticTypeSymbol() ) )
  140. {
  141. pOperator = FindAncestorReferencingElement< CDmeOperator >( pOwnerElement );
  142. }
  143. if ( pOperator == NULL )
  144. continue;
  145. if ( operatorList.Find( pOperator ) == operatorList.InvalidIndex() )
  146. {
  147. pOperator->GatherInputOperators( operatorList );
  148. operatorList.AddToTail( pOperator );
  149. }
  150. }
  151. }