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.

105 lines
3.4 KiB

  1. //========= Copyright Valve Corporation, All rights reserved. ============//
  2. //
  3. // The expression operator class - scalar math calculator
  4. // for a good list of operators and simple functions, see:
  5. // \\fileserver\user\MarcS\boxweb\aliveDistLite\v4.2.0\doc\alive\functions.txt
  6. // (although we'll want to implement elerp as the standard 3x^2 - 2x^3 with rescale)
  7. //
  8. //=============================================================================
  9. #include "movieobjects/dmebalancetostereocalculatoroperator.h"
  10. #include "movieobjects/dmechannel.h"
  11. #include "movieobjects_interfaces.h"
  12. #include "datamodel/dmelementfactoryhelper.h"
  13. #include "datamodel/dmattribute.h"
  14. // memdbgon must be the last include file in a .cpp file!!!
  15. #include "tier0/memdbgon.h"
  16. //-----------------------------------------------------------------------------
  17. // Expose this class to the scene database
  18. //-----------------------------------------------------------------------------
  19. IMPLEMENT_ELEMENT_FACTORY( DmeBalanceToStereoCalculatorOperator, CDmeBalanceToStereoCalculatorOperator );
  20. //-----------------------------------------------------------------------------
  21. // Purpose:
  22. //-----------------------------------------------------------------------------
  23. void CDmeBalanceToStereoCalculatorOperator::OnConstruction()
  24. {
  25. m_result_left.Init( this, "result_left" );
  26. m_result_right.Init( this, "result_right" );
  27. m_result_multi.Init( this, "result_multi" );
  28. m_value.Init( this, "value" );
  29. m_balance.InitAndSet( this, "balance", 0.5f );
  30. m_multilevel.InitAndSet( this, "multilevel", 0.5f );
  31. m_bSpewResult.Init( this, "spewresult" );
  32. m_flDefaultValue = FLT_MAX;
  33. }
  34. void CDmeBalanceToStereoCalculatorOperator::OnDestruction()
  35. {
  36. }
  37. void CDmeBalanceToStereoCalculatorOperator::GetInputAttributes ( CUtlVector< CDmAttribute * > &attrs )
  38. {
  39. attrs.AddToTail( m_value.GetAttribute() );
  40. attrs.AddToTail( m_balance.GetAttribute() );
  41. attrs.AddToTail( m_multilevel.GetAttribute() );
  42. }
  43. void CDmeBalanceToStereoCalculatorOperator::GetOutputAttributes( CUtlVector< CDmAttribute * > &attrs )
  44. {
  45. attrs.AddToTail( m_result_left.GetAttribute() );
  46. attrs.AddToTail( m_result_right.GetAttribute() );
  47. attrs.AddToTail( m_result_multi.GetAttribute() );
  48. }
  49. float CDmeBalanceToStereoCalculatorOperator::ComputeDefaultValue()
  50. {
  51. // NOTE: This is a total hack, which we expect to remove soon, when the balance work is done.
  52. const static UtlSymId_t symToElement = g_pDataModel->GetSymbol( "toElement" );
  53. CDmeChannel *pChannel = FindReferringElement<CDmeChannel>( this, symToElement );
  54. if ( !pChannel )
  55. return 0.0f;
  56. CDmElement *pControl = pChannel->GetFromElement();
  57. if ( !pControl )
  58. return 0.0f;
  59. return pControl->GetValue<float>( "defaultValue" );
  60. }
  61. void CDmeBalanceToStereoCalculatorOperator::Operate()
  62. {
  63. if ( m_flDefaultValue == FLT_MAX )
  64. {
  65. m_flDefaultValue = ComputeDefaultValue();
  66. }
  67. float flValue = m_value - m_flDefaultValue;
  68. if ( m_balance > 0.5f )
  69. {
  70. m_result_right = m_value;
  71. m_result_left = ( ( 1.0f - m_balance ) / 0.5f ) * flValue + m_flDefaultValue;
  72. }
  73. else
  74. {
  75. m_result_right = ( m_balance / 0.5f ) * flValue + m_flDefaultValue;
  76. m_result_left = m_value;
  77. }
  78. m_result_multi = m_multilevel;
  79. if ( m_bSpewResult )
  80. {
  81. Msg( "%s = l('%f') r('%f') m('%f')\n", GetName(), (float)m_result_left, (float)m_result_right, (float)m_result_multi );
  82. }
  83. }
  84. void CDmeBalanceToStereoCalculatorOperator::SetSpewResult( bool state )
  85. {
  86. m_bSpewResult = state;
  87. }