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.

153 lines
3.8 KiB

  1. //====== Copyright � 1996-2004, Valve Corporation, All rights reserved. =======
  2. //
  3. // Purpose:
  4. //
  5. //=============================================================================
  6. #ifndef DMETIMEFRAME_H
  7. #define DMETIMEFRAME_H
  8. #ifdef _WIN32
  9. #pragma once
  10. #endif
  11. #include "datamodel/dmelement.h"
  12. #include "datamodel/dmattributevar.h"
  13. //-----------------------------------------------------------------------------
  14. // Time classes used to help disambiguate between local + parent time
  15. //-----------------------------------------------------------------------------
  16. typedef int LocalTime_t;
  17. typedef int ParentTime_t;
  18. class CDmeTimeFrame : public CDmElement
  19. {
  20. DEFINE_ELEMENT( CDmeTimeFrame, CDmElement );
  21. public:
  22. // Methods of IDmElement
  23. virtual void OnAttributeChanged( CDmAttribute *pAttribute );
  24. DmeTime_t ToChildMediaTime( DmeTime_t t, bool bClamp = true ) const;
  25. DmeTime_t FromChildMediaTime( DmeTime_t t, bool bClamp = true ) const;
  26. DmeTime_t ToChildMediaDuration( DmeTime_t dt ) const;
  27. DmeTime_t FromChildMediaDuration( DmeTime_t dt ) const;
  28. DmeTime_t GetStartTime() const;
  29. DmeTime_t GetDuration() const;
  30. DmeTime_t GetTimeOffset() const;
  31. float GetTimeScale() const;
  32. DmeTime_t GetStartInChildMediaTime() const;
  33. DmeTime_t GetEndInChildMediaTime() const;
  34. void SetStartTime( DmeTime_t startTime );
  35. void SetDuration( DmeTime_t duration );
  36. void SetTimeOffset( DmeTime_t offset );
  37. void SetTimeScale( float flScale );
  38. void SetEndTime( DmeTime_t endTime, bool bChangeDuration );
  39. void SetTimeScale( float flScale, DmeTime_t scaleCenter, bool bChangeDuration );
  40. private:
  41. CDmaTime m_Start;
  42. CDmaTime m_Duration;
  43. CDmaTime m_Offset;
  44. CDmaVar< float > m_Scale;
  45. };
  46. //-----------------------------------------------------------------------------
  47. // inline methods
  48. //-----------------------------------------------------------------------------
  49. inline DmeTime_t CDmeTimeFrame::GetStartTime() const
  50. {
  51. return m_Start;
  52. }
  53. inline DmeTime_t CDmeTimeFrame::GetDuration() const
  54. {
  55. return m_Duration;
  56. }
  57. inline DmeTime_t CDmeTimeFrame::GetTimeOffset() const
  58. {
  59. return m_Offset;
  60. }
  61. inline float CDmeTimeFrame::GetTimeScale() const
  62. {
  63. return m_Scale;
  64. }
  65. inline void CDmeTimeFrame::SetStartTime( DmeTime_t startTime )
  66. {
  67. m_Start = startTime;
  68. }
  69. inline void CDmeTimeFrame::SetDuration( DmeTime_t duration )
  70. {
  71. Assert( duration >= DMETIME_ZERO ); // if you want a reversed clip, set the timescale negative
  72. m_Duration = MAX( DMETIME_ZERO, duration );
  73. }
  74. inline void CDmeTimeFrame::SetTimeOffset( DmeTime_t offset )
  75. {
  76. m_Offset = offset;
  77. }
  78. inline void CDmeTimeFrame::SetTimeScale( float flScale )
  79. {
  80. m_Scale = flScale;
  81. }
  82. //-----------------------------------------------------------------------------
  83. // Convert back + forth between my media time and child media time
  84. //-----------------------------------------------------------------------------
  85. inline DmeTime_t CDmeTimeFrame::ToChildMediaTime( DmeTime_t t, bool bClamp ) const
  86. {
  87. t -= m_Start;
  88. if ( bClamp )
  89. {
  90. t.Clamp( DMETIME_ZERO, m_Duration );
  91. }
  92. return ( t + m_Offset ) * m_Scale;
  93. }
  94. inline DmeTime_t CDmeTimeFrame::FromChildMediaTime( DmeTime_t t, bool bClamp ) const
  95. {
  96. t = t / m_Scale - m_Offset;
  97. if ( bClamp )
  98. {
  99. t.Clamp( DMETIME_ZERO, m_Duration );
  100. }
  101. return t + m_Start;
  102. }
  103. inline DmeTime_t CDmeTimeFrame::ToChildMediaDuration( DmeTime_t dt ) const
  104. {
  105. return dt * m_Scale;
  106. }
  107. inline DmeTime_t CDmeTimeFrame::FromChildMediaDuration( DmeTime_t dt ) const
  108. {
  109. return dt / m_Scale;
  110. }
  111. inline DmeTime_t CDmeTimeFrame::GetStartInChildMediaTime() const
  112. {
  113. DmeTime_t time = m_Offset.Get() * m_Scale;
  114. Assert( time == ToChildMediaTime( GetStartTime() ) );
  115. return time;
  116. }
  117. inline DmeTime_t CDmeTimeFrame::GetEndInChildMediaTime() const
  118. {
  119. DmeTime_t time = ( m_Offset.Get() + m_Duration.Get() ) * m_Scale;
  120. Assert( time == ToChildMediaTime( GetStartTime() + GetDuration() ) );
  121. return time;
  122. }
  123. #endif // DMETIMEFRAME_H