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.

141 lines
3.5 KiB

  1. //========= Copyright � 1996-2005, 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 float GetDuration() = 0;
  62. virtual bool CurveHasEndTime() = 0; // only matters for events
  63. virtual int GetDefaultCurveType() = 0;
  64. };
  65. //-----------------------------------------------------------------------------
  66. // Purpose: The generic curve data
  67. //-----------------------------------------------------------------------------
  68. class CCurveData
  69. {
  70. public:
  71. int GetCount( void );
  72. CExpressionSample *Get( int index );
  73. CExpressionSample *Add( float time, float value, bool selected );
  74. void Delete( int index );
  75. void Clear( void );
  76. void Resort( ICurveDataAccessor *data );
  77. EdgeInfo_t *GetEdgeInfo( int idx );
  78. void SetEdgeInfo( bool leftEdge, int curveType, float zero );
  79. void GetEdgeInfo( bool leftEdge, int& curveType, float& zero ) const;
  80. void SetEdgeActive( bool leftEdge, bool state );
  81. bool IsEdgeActive( bool leftEdge ) const;
  82. int GetEdgeCurveType( bool leftEdge ) const;
  83. float GetEdgeZeroValue( bool leftEdge ) const;
  84. void RemoveOutOfRangeSamples( ICurveDataAccessor *data );
  85. void SaveToBuffer( CUtlBuffer& buf, IChoreoStringPool *pStringPool );
  86. bool RestoreFromBuffer( CUtlBuffer& buf, IChoreoStringPool *pStringPool );
  87. void Parse( ISceneTokenProcessor *tokenizer, ICurveDataAccessor *data );
  88. void FileSave( CUtlBuffer& buf, int level, const char *name );
  89. float GetIntensity( ICurveDataAccessor *data, float time );
  90. CExpressionSample *GetBoundedSample( ICurveDataAccessor *data, int number, bool& bClamped );
  91. CCurveData & operator = (const CCurveData &src)
  92. {
  93. // Copy ramp over
  94. m_Ramp.RemoveAll();
  95. int i;
  96. for ( i = 0; i < src.m_Ramp.Count(); i++ )
  97. {
  98. CExpressionSample sample = src.m_Ramp[ i ];
  99. CExpressionSample *newSample = Add( sample.time, sample.value, sample.selected );
  100. newSample->SetCurveType( sample.GetCurveType() );
  101. }
  102. m_RampEdgeInfo[ 0 ] = src.m_RampEdgeInfo[ 0 ];
  103. m_RampEdgeInfo[ 1 ] = src.m_RampEdgeInfo[ 1 ];
  104. return *this;
  105. };
  106. private:
  107. CUtlVector< CExpressionSample > m_Ramp;
  108. EdgeInfo_t m_RampEdgeInfo[ 2 ];
  109. public:
  110. float GetIntensityArea( ICurveDataAccessor *data, float time );
  111. private:
  112. void UpdateIntensityArea( ICurveDataAccessor *data );
  113. CUtlVector< float > m_RampAccumulator;
  114. };
  115. #endif // EXPRESSIONSAMPLE_H