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.

92 lines
2.5 KiB

  1. //====== Copyright � 1996-2004, 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, "start", DMETIME_ZERO, FATTRIB_HAS_CALLBACK );
  21. m_Duration.InitAndSet( this, "duration", DMETIME_ZERO, FATTRIB_HAS_CALLBACK );
  22. m_Offset .InitAndSet( this, "offset", DMETIME_ZERO );
  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 - m_Start;
  42. }
  43. else
  44. {
  45. m_Start = endTime - 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. DmeTime_t t = scaleCenter - m_Start;
  55. if ( bChangeDuration )
  56. {
  57. DmeTime_t newDuration = m_Duration.Get() * ratio;
  58. if ( scaleCenter != m_Start )
  59. {
  60. DmeTime_t newStart = ( m_Start.Get() - scaleCenter ) * ratio + scaleCenter;
  61. SetStartTime( newStart );
  62. }
  63. SetTimeOffset( ( t + m_Offset.Get() ) * ratio + m_Start.Get() - scaleCenter );
  64. SetDuration( newDuration );
  65. }
  66. else
  67. {
  68. SetTimeOffset( ( t + m_Offset.Get() ) * ratio - t );
  69. }
  70. SetTimeScale( flScale );
  71. #ifdef _DEBUG
  72. DmeTime_t postCenterTime = ToChildMediaTime( scaleCenter, false );
  73. Assert( abs( preCenterTime - postCenterTime ) <= DMETIME_MINDELTA );
  74. #endif
  75. }