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.

95 lines
2.7 KiB

  1. //========= Copyright Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose:
  4. //
  5. //=============================================================================
  6. #include "movieobjects/dmetimeframe.h"
  7. #include "tier0/dbg.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. // Class factory
  13. //-----------------------------------------------------------------------------
  14. IMPLEMENT_ELEMENT_FACTORY( DmeTimeFrame, CDmeTimeFrame );
  15. //-----------------------------------------------------------------------------
  16. // Constructor, destructor
  17. //-----------------------------------------------------------------------------
  18. void CDmeTimeFrame::OnConstruction()
  19. {
  20. m_Start .InitAndSet( this, "startTime", 0, FATTRIB_HAS_CALLBACK );
  21. m_Duration.InitAndSet( this, "durationTime", 0, FATTRIB_HAS_CALLBACK );
  22. m_Offset .InitAndSet( this, "offsetTime", 0 );
  23. m_Scale .InitAndSet( this, "scale", 1.0f );
  24. }
  25. void CDmeTimeFrame::OnDestruction()
  26. {
  27. }
  28. void CDmeTimeFrame::OnAttributeChanged( CDmAttribute *pAttribute )
  29. {
  30. BaseClass::OnAttributeChanged( pAttribute );
  31. // notify parent clip that the time has changed
  32. if ( pAttribute == m_Start.GetAttribute() || pAttribute == m_Duration.GetAttribute() )
  33. {
  34. InvokeOnAttributeChangedOnReferrers( GetHandle(), pAttribute );
  35. }
  36. }
  37. void CDmeTimeFrame::SetEndTime( DmeTime_t endTime, bool bChangeDuration )
  38. {
  39. if ( bChangeDuration )
  40. {
  41. m_Duration = endTime.GetTenthsOfMS() - m_Start;
  42. }
  43. else
  44. {
  45. m_Start = endTime.GetTenthsOfMS() - m_Duration;
  46. }
  47. }
  48. void CDmeTimeFrame::SetTimeScale( float flScale, DmeTime_t scaleCenter, bool bChangeDuration )
  49. {
  50. #ifdef _DEBUG
  51. DmeTime_t preCenterTime = ToChildMediaTime( scaleCenter, false );
  52. #endif
  53. float ratio = m_Scale / flScale;
  54. int t = scaleCenter.GetTenthsOfMS() - m_Start;
  55. if ( bChangeDuration )
  56. {
  57. int newDuration = int( m_Duration * ratio );
  58. if ( scaleCenter.GetTenthsOfMS() != m_Start )
  59. {
  60. int newStart = int( ( m_Start - scaleCenter.GetTenthsOfMS() ) * ratio + scaleCenter.GetTenthsOfMS() );
  61. SetStartTime( DmeTime_t( newStart ) );
  62. }
  63. int newStart = m_Start;
  64. int newOffset = int( ( t + m_Offset ) * ratio + newStart - scaleCenter.GetTenthsOfMS() );
  65. SetTimeOffset( DmeTime_t( newOffset ) );
  66. SetDuration( DmeTime_t( newDuration ) );
  67. }
  68. else
  69. {
  70. int newOffset = int( ( t + m_Offset ) * ratio - t );
  71. SetTimeOffset( DmeTime_t( newOffset ) );
  72. }
  73. SetTimeScale( flScale );
  74. #ifdef _DEBUG
  75. DmeTime_t postCenterTime = ToChildMediaTime( scaleCenter, false );
  76. Assert( abs( preCenterTime - postCenterTime ) <= DMETIME_MINDELTA );
  77. #endif
  78. }