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.

142 lines
3.5 KiB

  1. //========= Copyright Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose:
  4. //
  5. // $NoKeywords: $
  6. //=============================================================================//
  7. #ifndef EXPRESSIONSAMPLE_H
  8. #define EXPRESSIONSAMPLE_H
  9. #ifdef _WIN32
  10. #pragma once
  11. #endif
  12. #include "interpolatortypes.h"
  13. class CUtlBuffer;
  14. class ISceneTokenProcessor;
  15. class IChoreoStringPool;
  16. #pragma pack(1)
  17. struct EdgeInfo_t
  18. {
  19. EdgeInfo_t() :
  20. m_bActive( false ),
  21. m_CurveType( CURVE_DEFAULT ),
  22. m_flZeroPos( 0.0f )
  23. {
  24. }
  25. bool m_bActive;
  26. unsigned short m_CurveType;
  27. float m_flZeroPos;
  28. };
  29. struct CExpressionSample
  30. {
  31. CExpressionSample() :
  32. value( 0.0f ),
  33. time( 0.0f )
  34. {
  35. selected = 0;
  36. m_curvetype = CURVE_DEFAULT;
  37. }
  38. void SetCurveType( int curveType )
  39. {
  40. m_curvetype = curveType;
  41. }
  42. int GetCurveType() const
  43. {
  44. return m_curvetype;
  45. }
  46. // Height
  47. float value;
  48. // time from start of event
  49. float time;
  50. unsigned short selected : 1;
  51. private:
  52. unsigned short m_curvetype : 15;
  53. };
  54. #pragma pack()
  55. //-----------------------------------------------------------------------------
  56. // Purpose: Provides generic access to scene or event ramp data
  57. //-----------------------------------------------------------------------------
  58. class ICurveDataAccessor
  59. {
  60. public:
  61. virtual ~ICurveDataAccessor(){}
  62. virtual float GetDuration() = 0;
  63. virtual bool CurveHasEndTime() = 0; // only matters for events
  64. virtual int GetDefaultCurveType() = 0;
  65. };
  66. //-----------------------------------------------------------------------------
  67. // Purpose: The generic curve data
  68. //-----------------------------------------------------------------------------
  69. class CCurveData
  70. {
  71. public:
  72. int GetCount( void );
  73. CExpressionSample *Get( int index );
  74. CExpressionSample *Add( float time, float value, bool selected );
  75. void Delete( int index );
  76. void Clear( void );
  77. void Resort( ICurveDataAccessor *data );
  78. EdgeInfo_t *GetEdgeInfo( int idx );
  79. void SetEdgeInfo( bool leftEdge, int curveType, float zero );
  80. void GetEdgeInfo( bool leftEdge, int& curveType, float& zero ) const;
  81. void SetEdgeActive( bool leftEdge, bool state );
  82. bool IsEdgeActive( bool leftEdge ) const;
  83. int GetEdgeCurveType( bool leftEdge ) const;
  84. float GetEdgeZeroValue( bool leftEdge ) const;
  85. void RemoveOutOfRangeSamples( ICurveDataAccessor *data );
  86. void SaveToBuffer( CUtlBuffer& buf, IChoreoStringPool *pStringPool );
  87. bool RestoreFromBuffer( CUtlBuffer& buf, IChoreoStringPool *pStringPool );
  88. void Parse( ISceneTokenProcessor *tokenizer, ICurveDataAccessor *data );
  89. void FileSave( CUtlBuffer& buf, int level, const char *name );
  90. float GetIntensity( ICurveDataAccessor *data, float time );
  91. CExpressionSample *GetBoundedSample( ICurveDataAccessor *data, int number, bool& bClamped );
  92. CCurveData & operator = (const CCurveData &src)
  93. {
  94. // Copy ramp over
  95. m_Ramp.RemoveAll();
  96. int i;
  97. for ( i = 0; i < src.m_Ramp.Count(); i++ )
  98. {
  99. CExpressionSample sample = src.m_Ramp[ i ];
  100. CExpressionSample *newSample = Add( sample.time, sample.value, sample.selected );
  101. newSample->SetCurveType( sample.GetCurveType() );
  102. }
  103. m_RampEdgeInfo[ 0 ] = src.m_RampEdgeInfo[ 0 ];
  104. m_RampEdgeInfo[ 1 ] = src.m_RampEdgeInfo[ 1 ];
  105. return *this;
  106. };
  107. private:
  108. CUtlVector< CExpressionSample > m_Ramp;
  109. EdgeInfo_t m_RampEdgeInfo[ 2 ];
  110. public:
  111. float GetIntensityArea( ICurveDataAccessor *data, float time );
  112. private:
  113. void UpdateIntensityArea( ICurveDataAccessor *data );
  114. CUtlVector< float > m_RampAccumulator;
  115. };
  116. #endif // EXPRESSIONSAMPLE_H