diff options
| author | FluorescentCIAAfricanAmerican <[email protected]> | 2020-04-22 12:56:21 -0400 |
|---|---|---|
| committer | FluorescentCIAAfricanAmerican <[email protected]> | 2020-04-22 12:56:21 -0400 |
| commit | 3bf9df6b2785fa6d951086978a3e66f49427166a (patch) | |
| tree | 2c0f1f0c63c4832882bc93814ebd2c2b1c6224e5 /movieobjects/dmebalancetostereocalculatoroperator.cpp | |
| download | archived-source-engine-2018-hl2-src-master.tar.xz archived-source-engine-2018-hl2-src-master.zip | |
Diffstat (limited to 'movieobjects/dmebalancetostereocalculatoroperator.cpp')
| -rw-r--r-- | movieobjects/dmebalancetostereocalculatoroperator.cpp | 105 |
1 files changed, 105 insertions, 0 deletions
diff --git a/movieobjects/dmebalancetostereocalculatoroperator.cpp b/movieobjects/dmebalancetostereocalculatoroperator.cpp new file mode 100644 index 0000000..a8fc482 --- /dev/null +++ b/movieobjects/dmebalancetostereocalculatoroperator.cpp @@ -0,0 +1,105 @@ +//========= Copyright Valve Corporation, All rights reserved. ============// +// +// The expression operator class - scalar math calculator +// for a good list of operators and simple functions, see: +// \\fileserver\user\MarcS\boxweb\aliveDistLite\v4.2.0\doc\alive\functions.txt +// (although we'll want to implement elerp as the standard 3x^2 - 2x^3 with rescale) +// +//============================================================================= +#include "movieobjects/dmebalancetostereocalculatoroperator.h" +#include "movieobjects/dmechannel.h" +#include "movieobjects_interfaces.h" +#include "datamodel/dmelementfactoryhelper.h" +#include "datamodel/dmattribute.h" + +// memdbgon must be the last include file in a .cpp file!!! +#include "tier0/memdbgon.h" + +//----------------------------------------------------------------------------- +// Expose this class to the scene database +//----------------------------------------------------------------------------- +IMPLEMENT_ELEMENT_FACTORY( DmeBalanceToStereoCalculatorOperator, CDmeBalanceToStereoCalculatorOperator ); + + +//----------------------------------------------------------------------------- +// Purpose: +//----------------------------------------------------------------------------- +void CDmeBalanceToStereoCalculatorOperator::OnConstruction() +{ + m_result_left.Init( this, "result_left" ); + m_result_right.Init( this, "result_right" ); + m_result_multi.Init( this, "result_multi" ); + + m_value.Init( this, "value" ); + m_balance.InitAndSet( this, "balance", 0.5f ); + m_multilevel.InitAndSet( this, "multilevel", 0.5f ); + + m_bSpewResult.Init( this, "spewresult" ); + + m_flDefaultValue = FLT_MAX; +} + +void CDmeBalanceToStereoCalculatorOperator::OnDestruction() +{ +} + +void CDmeBalanceToStereoCalculatorOperator::GetInputAttributes ( CUtlVector< CDmAttribute * > &attrs ) +{ + attrs.AddToTail( m_value.GetAttribute() ); + attrs.AddToTail( m_balance.GetAttribute() ); + attrs.AddToTail( m_multilevel.GetAttribute() ); +} + +void CDmeBalanceToStereoCalculatorOperator::GetOutputAttributes( CUtlVector< CDmAttribute * > &attrs ) +{ + attrs.AddToTail( m_result_left.GetAttribute() ); + attrs.AddToTail( m_result_right.GetAttribute() ); + attrs.AddToTail( m_result_multi.GetAttribute() ); +} + +float CDmeBalanceToStereoCalculatorOperator::ComputeDefaultValue() +{ + // NOTE: This is a total hack, which we expect to remove soon, when the balance work is done. + const static UtlSymId_t symToElement = g_pDataModel->GetSymbol( "toElement" ); + CDmeChannel *pChannel = FindReferringElement<CDmeChannel>( this, symToElement ); + if ( !pChannel ) + return 0.0f; + + CDmElement *pControl = pChannel->GetFromElement(); + if ( !pControl ) + return 0.0f; + + return pControl->GetValue<float>( "defaultValue" ); +} + +void CDmeBalanceToStereoCalculatorOperator::Operate() +{ + if ( m_flDefaultValue == FLT_MAX ) + { + m_flDefaultValue = ComputeDefaultValue(); + } + + float flValue = m_value - m_flDefaultValue; + if ( m_balance > 0.5f ) + { + m_result_right = m_value; + m_result_left = ( ( 1.0f - m_balance ) / 0.5f ) * flValue + m_flDefaultValue; + } + else + { + m_result_right = ( m_balance / 0.5f ) * flValue + m_flDefaultValue; + m_result_left = m_value; + } + + m_result_multi = m_multilevel; + + if ( m_bSpewResult ) + { + Msg( "%s = l('%f') r('%f') m('%f')\n", GetName(), (float)m_result_left, (float)m_result_right, (float)m_result_multi ); + } +} + +void CDmeBalanceToStereoCalculatorOperator::SetSpewResult( bool state ) +{ + m_bSpewResult = state; +} |