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.

1150 lines
50 KiB

  1. //====== Copyright � 1996-2004, Valve Corporation, All rights reserved. =======
  2. //
  3. // Purpose:
  4. //
  5. //=============================================================================
  6. #ifndef DMELOG_H
  7. #define DMELOG_H
  8. #ifdef _WIN32
  9. #pragma once
  10. #endif
  11. #include <math.h>
  12. #include "datamodel/dmelement.h"
  13. #include "datamodel/dmattribute.h"
  14. #include "datamodel/dmattributevar.h"
  15. #include "datamodel/dmehandle.h"
  16. #include "datamodel/dmattributevar.h"
  17. #include "interpolatortypes.h"
  18. #include "movieobjects/dmetimeselectiontimes.h"
  19. #include "movieobjects/proceduralpresets.h"
  20. class IUniformRandomStream;
  21. template < class T > class CDmeTypedLog;
  22. enum
  23. {
  24. FILTER_SMOOTH = 0,
  25. FILTER_JITTER,
  26. FILTER_SHARPEN,
  27. FILTER_SOFTEN,
  28. FILTER_INOUT,
  29. NUM_FILTERS
  30. };
  31. enum RecordingMode_t
  32. {
  33. RECORD_PRESET = 0, // Preset/fader slider being dragged
  34. RECORD_ATTRIBUTESLIDER, // Single attribute slider being dragged
  35. };
  36. // Transform write mode types, specify how a transform is to apply to existing values.
  37. enum TransformWriteMode_t
  38. {
  39. TRANSFORM_WRITE_MODE_HOLD,
  40. TRANSFORM_WRITE_MODE_OFFSET,
  41. TRANSFORM_WRITE_MODE_OVERWRITE,
  42. TRANSFORM_WRITE_MODE_TRANSFORM
  43. };
  44. enum LogComponents_t
  45. {
  46. LOG_COMPONENTS_NONE = 0,
  47. LOG_COMPONENTS_X = ( 1 << 0 ),
  48. LOG_COMPONENTS_Y = ( 1 << 1 ),
  49. LOG_COMPONENTS_Z = ( 1 << 2 ),
  50. LOG_COMPONENTS_ALL = LOG_COMPONENTS_X | LOG_COMPONENTS_Y | LOG_COMPONENTS_Z,
  51. };
  52. DEFINE_ENUM_BITWISE_OPERATORS( LogComponents_t )
  53. enum SegmentInterpolation_t
  54. {
  55. SEGMENT_INTERPOLATE,
  56. SEGMENT_NOINTERPOLATE,
  57. };
  58. static const unsigned int LOG_MAX_COMPONENTS = 4;
  59. #define DMELOG_DEFAULT_THRESHHOLD 0.0001f
  60. class DmeLog_TimeSelection_t
  61. {
  62. public:
  63. DmeLog_TimeSelection_t() :
  64. m_flIntensity( 1.0f ),
  65. m_bAttachedMode( true ),
  66. m_bTimeAdvancing( false ),
  67. m_nResampleInterval( DmeTime_t( .05f ) ),// 50 msec sampling interval by default
  68. m_flThreshold( DMELOG_DEFAULT_THRESHHOLD ),
  69. m_pPresetValue( 0 ),
  70. m_pPresetTimes( 0 ),
  71. m_pOldHeadValue( 0 ),
  72. m_OldHeadValueIndex( -1 ),
  73. m_tHeadPosition( 0 ),
  74. m_TransformWriteMode( TRANSFORM_WRITE_MODE_OVERWRITE ),
  75. m_bManipulateInFalloff( false ),
  76. m_nComponentFlags( LOG_COMPONENTS_ALL ),
  77. m_RecordingMode( RECORD_PRESET )
  78. {
  79. m_nTimes[ TS_LEFT_FALLOFF ] = m_nTimes[ TS_LEFT_HOLD ] =
  80. m_nTimes[ TS_RIGHT_HOLD ] = m_nTimes[ TS_RIGHT_FALLOFF ] = DmeTime_t( 0 );
  81. m_nFalloffInterpolatorTypes[ 0 ] = m_nFalloffInterpolatorTypes[ 1 ] = INTERPOLATE_LINEAR_INTERP;
  82. m_bInfinite[ 0 ] = m_bInfinite[ 1 ] = false;
  83. }
  84. inline void ResetTimeAdvancing()
  85. {
  86. // Reset the time advancing flag
  87. m_bTimeAdvancing = false;
  88. }
  89. inline void StartTimeAdvancing()
  90. {
  91. m_bTimeAdvancing = true;
  92. }
  93. inline bool IsTimeAdvancing() const
  94. {
  95. return m_bTimeAdvancing;
  96. }
  97. inline RecordingMode_t GetRecordingMode() const
  98. {
  99. return m_RecordingMode;
  100. }
  101. void SetRecordingMode( RecordingMode_t mode )
  102. {
  103. m_RecordingMode = mode;
  104. }
  105. float GetAmountForTime( DmeTime_t curtime ) const;
  106. float AdjustFactorForInterpolatorType( float factor, int side ) const;
  107. // NOTE: See TimeSelectionTimes_t for return values, 0 means before, 1= left falloff, 2=hold, 3=right falloff, 4=after
  108. int ComputeRegionForTime( DmeTime_t curtime ) const;
  109. TimeSelection_t m_nTimes;
  110. int m_nFalloffInterpolatorTypes[ 2 ];
  111. DmeTime_t m_nResampleInterval;
  112. float m_flIntensity; // How much to drive values toward m_HeadValue (generally 1.0f)
  113. float m_flThreshold;
  114. const CDmAttribute* m_pPresetValue; // Pointer to the attribute storing the value to be used for presets
  115. const CDmAttribute* m_pPresetTimes; // Pointer to the attribute storing the times to be used for animated presets
  116. CDmAttribute* m_pOldHeadValue; // Pointer to the attribute storing the original head value
  117. int m_OldHeadValueIndex; // Array index of the original head value within the specified attribute
  118. DmeTime_t m_tHeadPosition; // Time position of the head
  119. TransformWriteMode_t m_TransformWriteMode; // Specification of how values are to be written into the log with respect to the existing values
  120. bool m_bAttachedMode : 1; // Is the current time "attached" to the head position
  121. bool m_bManipulateInFalloff : 1; // Should the rotation be applied as a transform to the position instead of interpolating
  122. LogComponents_t m_nComponentFlags; // Flag indicating which components of the log should be modified
  123. bool m_bInfinite[ 2 ];
  124. private:
  125. bool m_bTimeAdvancing : 1; // Has time ever been advancing
  126. RecordingMode_t m_RecordingMode;
  127. };
  128. class CDmeChannel;
  129. class CDmeChannelsClip;
  130. class CDmeClip;
  131. class CDmeFilmClip;
  132. class CDmeLog;
  133. class CDmeLogLayer;
  134. struct DmeClipStack_t;
  135. struct LayerSelectionData_t
  136. {
  137. LayerSelectionData_t();
  138. void Release();
  139. CDmeHandle< CDmeChannel > m_hChannel;
  140. CDmeHandle< CDmeChannelsClip > m_hOwner;
  141. CDmeHandle< CDmeFilmClip > m_hShot;
  142. CDmeHandle< CDmeLog > m_hLog;
  143. DmAttributeType_t m_DataType;
  144. DmeTime_t m_nTimes[ TS_TIME_COUNT ];
  145. // This is dynamic and needs to be released
  146. struct DataLayer_t
  147. {
  148. DataLayer_t( float frac, CDmeLogLayer *layer );
  149. float m_flStartFraction;
  150. CDmeHandle< CDmeLogLayer, HT_STRONG > m_hData;
  151. };
  152. CUtlVector< DataLayer_t > m_vecData;
  153. };
  154. struct DmeLogTransformParams_t
  155. {
  156. DmeLogTransformParams_t()
  157. : m_RotationLocal( quat_identity )
  158. , m_RotationParent( quat_identity )
  159. , m_Pivot( vec3_origin )
  160. , m_nProceduralType( PROCEDURAL_PRESET_NOT )
  161. , m_pRotationLog( NULL )
  162. {
  163. SetIdentityMatrix( m_Transform );
  164. }
  165. matrix3x4_t m_Transform;
  166. Quaternion m_RotationLocal;
  167. Quaternion m_RotationParent;
  168. Vector m_Pivot;
  169. int m_nProceduralType;
  170. CDmeTypedLog< Quaternion > *m_pRotationLog;
  171. };
  172. //-----------------------------------------------------------------------------
  173. // CDmeLogLayer - abstract base class
  174. //-----------------------------------------------------------------------------
  175. abstract_class CDmeLogLayer : public CDmElement
  176. {
  177. friend class CDmeLog;
  178. DEFINE_ELEMENT( CDmeLogLayer, CDmElement );
  179. public:
  180. virtual void CopyLayer( const CDmeLogLayer *src ) = 0;
  181. virtual void CopyPartialLayer( const CDmeLogLayer *src, DmeTime_t startTime, DmeTime_t endTime, bool bRebaseTimestamps ) = 0;
  182. virtual void ExplodeLayer( const CDmeLogLayer *src, DmeTime_t startTime, DmeTime_t endTime, bool bRebaseTimestamps, DmeTime_t tResampleInterval ) = 0;
  183. virtual void InsertKeyFromLayer( DmeTime_t keyTime, const CDmeLogLayer *src, DmeTime_t srcKeyTime ) = 0;
  184. DmeTime_t GetBeginTime( bool bAllowInfinite ) const;
  185. DmeTime_t GetEndTime( bool bAllowInfinite ) const;
  186. int GetKeyCount() const;
  187. void ScaleSampleTimes( float scale );
  188. // Returns the index of a key closest to this time, within tolerance
  189. // NOTE: Insertion or removal may change this index!
  190. // Returns -1 if the time isn't within tolerance.
  191. int FindKeyWithinTolerance( DmeTime_t time, DmeTime_t nTolerance );
  192. // Returns the type of attribute being logged
  193. virtual DmAttributeType_t GetDataType() const = 0;
  194. // Sets a key, removes all keys after this time
  195. virtual void SetKey( DmeTime_t time, const CDmAttribute *pAttr, uint index = 0, SegmentInterpolation_t interpSetting = SEGMENT_INTERPOLATE, int curveType = CURVE_DEFAULT ) = 0;
  196. virtual bool SetDuplicateKeyAtTime( DmeTime_t time ) = 0;
  197. // This inserts a key using the current values to construct the proper value for the time
  198. virtual int InsertKeyAtTime( DmeTime_t nTime, int curveType = CURVE_DEFAULT ) = 0;
  199. virtual void TrimKeys( DmeTime_t tStartTime, DmeTime_t tEndTime ) = 0;
  200. // Sets the interpolated value of the log at the specified time into the attribute
  201. virtual void GetValue( DmeTime_t time, CDmAttribute *pAttr, uint index = 0 ) const = 0;
  202. virtual float GetComponent( DmeTime_t time, int componentIndex ) const = 0;
  203. // Returns the time at which a particular key occurs
  204. DmeTime_t GetKeyTime( int nKeyIndex ) const;
  205. void SetKeyTime( int nKeyIndex, DmeTime_t keyTime );
  206. // Scale + bias key times
  207. void ScaleBiasKeyTimes( double flScale, DmeTime_t nBias );
  208. // Scale the keys within the source time selection to fill the destination time selection, keys outside the time selection will be shifted
  209. void RescaleSamplesInTimeSelection( const TimeSelection_t &srcTimeSeleciton, const TimeSelection_t &dstTimeSelection );
  210. // Removes a single key by index
  211. virtual void RemoveKey( int nKeyIndex, int nNumKeysToRemove = 1 ) = 0;
  212. // Removes all keys
  213. virtual void ClearKeys() = 0;
  214. virtual bool IsConstantValued() const = 0;
  215. virtual void RemoveRedundantKeys( bool bKeepEnds ) = 0;
  216. virtual void RemoveRedundantKeys( float threshold, bool bKeepEnds ) = 0;
  217. // resampling and filtering
  218. virtual void Resample( DmeFramerate_t samplerate ) = 0;
  219. virtual void Filter( int nSampleRadius ) = 0;
  220. virtual void Filter2( DmeTime_t sampleRadius ) = 0;
  221. virtual void SetOwnerLog( CDmeLog *owner ) = 0;
  222. CDmeLog *GetOwnerLog();
  223. const CDmeLog *GetOwnerLog() const;
  224. bool IsUsingCurveTypes() const;
  225. int GetDefaultCurveType() const;
  226. // Override curvetype for specific key
  227. void SetKeyCurveType( int nKeyIndex, int curveType );
  228. int GetKeyCurveType( int nKeyIndex ) const;
  229. // Layers may extend to infinity on the left or right, if so the start / end time will be min / max
  230. void SetInfinite( bool bLeftInfinite, bool bRightInfinite );
  231. bool IsLeftInfinite() { return m_bLeftInfinite; }
  232. bool IsRightInfinite() { return m_bRightInfinite; }
  233. // Validates that all keys are correctly sorted in time
  234. bool ValidateKeys() const;
  235. // Removes all keys outside the specified time range
  236. void RemoveKeysOutsideRange( DmeTime_t tStart, DmeTime_t tEnd );
  237. SegmentInterpolation_t GetSegmentInterpolationSetting( int nKeyIndex ) const;
  238. SegmentInterpolation_t GetSegmentInterpolationSetting( int nStartKeyIndex, int nEndKeyIndex ) const; //return SEGMENT_NOINTERPOLATE if any segment checked is non-interpolated
  239. SegmentInterpolation_t GetSegmentInterpolationSetting( DmeTime_t time ) const;
  240. SegmentInterpolation_t GetSegmentInterpolationSetting( DmeTime_t startTime, DmeTime_t endTime, bool bExcludeActualEndTimeKey ) const; //return SEGMENT_NOINTERPOLATE if any segment checked is non-interpolated
  241. // Masks all keys within the time range, returns true if keys were modified
  242. virtual bool MaskKeyRange( DmeTime_t tStartTime, DmeTime_t tEndTime, LogComponents_t nComponentFlags, bool bInfiniteLeft = false, bool bInfiniteRight = false ) = 0;
  243. virtual void MakeRoomForSamplesMaskedSubcomponents( CDmeLogLayer *pBaseLayer, DmeTime_t tStart, DmeTime_t tEnd, DmeTime_t tLeftShift, DmeTime_t tRightShift, LogComponents_t nComponents ) = 0;
  244. virtual void Compress() = 0;
  245. virtual void Decompress() = 0;
  246. virtual bool IsCompressed() const = 0;
  247. virtual size_t GetCompressedSize() const = 0;
  248. virtual size_t GetDataSize() const = 0;
  249. protected:
  250. int FindKey( DmeTime_t time ) const;
  251. void OnUsingCurveTypesChanged();
  252. CDmeLog *m_pOwnerLog;
  253. mutable int m_lastKey;
  254. bool m_bLeftInfinite;
  255. bool m_bRightInfinite;
  256. CDmaArray< DmeTime_t > m_times;
  257. CDmaArray< int > m_CurveTypes;
  258. CDmaArray< bool > m_NonInterpolatedSegments;
  259. };
  260. template< class T >
  261. CDmeLogLayer *CreateLayer( CDmeTypedLog< T > *ownerLog );
  262. //-----------------------------------------------------------------------------
  263. // CDmeLogLayer - abstract base class
  264. //-----------------------------------------------------------------------------
  265. abstract_class CDmeCurveInfo : public CDmElement
  266. {
  267. DEFINE_ELEMENT( CDmeCurveInfo, CDmElement );
  268. public:
  269. // Global override for all keys unless overriden by specific key
  270. void SetDefaultCurveType( int curveType );
  271. int GetDefaultCurveType() const;
  272. void SetMinValue( float val );
  273. float GetMinValue() const;
  274. void SetMaxValue( float val );
  275. float GetMaxValue() const;
  276. protected:
  277. CDmaVar< int > m_DefaultCurveType;
  278. CDmaVar< float > m_MinValue;
  279. CDmaVar< float > m_MaxValue;
  280. };
  281. template <class T > class CDmeTypedLogLayer;
  282. //-----------------------------------------------------------------------------
  283. // CDmeLog - abstract base class
  284. //-----------------------------------------------------------------------------
  285. abstract_class CDmeLog : public CDmElement
  286. {
  287. DEFINE_ELEMENT( CDmeLog, CDmElement );
  288. public:
  289. int FindLayerForTime( DmeTime_t time ) const;
  290. int FindLayerForTimeSkippingTopmost( DmeTime_t time ) const;
  291. int FindLayerForTimeBelowLayer( DmeTime_t time, int topLayerIndex ) const;
  292. void FindLayersForTime( DmeTime_t time, CUtlVector< int >& list ) const;
  293. virtual void FinishTimeSelection( DmeTime_t tHeadPosition, DmeLog_TimeSelection_t& params ) = 0; // in attached, time advancing mode, we need to blend out of the final sample over the fadeout interval
  294. virtual void StampKeyAtHead( DmeTime_t tHeadPosition, DmeTime_t tPreviousHeadPosition, const DmeLog_TimeSelection_t& params, const DmeLogTransformParams_t &transformParams, const CDmAttribute *pAttr, uint arrayIndex = 0, bool bTimeFilter = true, int layerIndex = -1 ) = 0;
  295. virtual void FilterUsingTimeSelection( IUniformRandomStream &random, float flScale, const DmeLog_TimeSelection_t& params, int filterType, bool bResample, bool bApplyFalloff, const CDmeLogLayer *baseLayer, CDmeLogLayer *writeLayer ) = 0;
  296. virtual void FilterUsingTimeSelection( IUniformRandomStream &random, const DmeLog_TimeSelection_t& params, int filterType, bool bResample, bool bApplyFalloff ) = 0;
  297. virtual void StaggerUsingTimeSelection( const DmeLog_TimeSelection_t& params, DmeTime_t tStaggerAmount, const CDmeLogLayer *baseLayer, CDmeLogLayer *writeLayer ) = 0;
  298. virtual void RevealUsingTimeSelection( const DmeLog_TimeSelection_t &params, const CDmeLogLayer *pTargetLayer ) = 0;
  299. virtual void RecaleAndRevealUsingTimeSelection( const DmeLog_TimeSelection_t &params, TimeSelection_t &sourceTimeSelection, const CDmeLogLayer *pTargetLayer ) = 0;
  300. virtual void GenerateSplineUsingTimeSelection( const DmeLog_TimeSelection_t& params, const CUtlVector< DmeTime_t > &sortedSplineKeyTimes, const CDmeLogLayer *baseLayer, CDmeLogLayer *writeLayer ) = 0;
  301. virtual void BlendLayersUsingTimeSelection( const DmeLog_TimeSelection_t &params, int baseLayer = 0 ) = 0;
  302. virtual void BlendLayersUsingTimeSelection( const CDmeLogLayer *firstLayer, const CDmeLogLayer *secondLayer, CDmeLogLayer *outputLayer, const DmeLog_TimeSelection_t &params, bool bUseBaseLayerSamples, bool bUseFalloff, bool bSelectionSamples, DmeTime_t tStartOffset ) = 0;
  303. virtual void BlendLayersUsingTimeSelection( const CDmeLogLayer *baseLayer, const CDmeLogLayer *firstLayer, const CDmeLogLayer *secondLayer, CDmeLogLayer *outputLayer, const DmeLog_TimeSelection_t &params, bool bUseBaseLayerSamples, DmeTime_t tStartOffset ) = 0;
  304. virtual void BlendTimesUsingTimeSelection( const CDmeLogLayer *firstLayer, const CDmeLogLayer *secondLayer, CDmeLogLayer *outputLayer, const DmeLog_TimeSelection_t &params, DmeTime_t tStartOffset, bool bFeatherBlendInFalloff ) = 0;
  305. virtual void PasteAndRescaleSamples( const CDmeLogLayer *src, const DmeLog_TimeSelection_t& srcParams, const DmeLog_TimeSelection_t& destParams, bool bBlendAreaInFalloffRegion, bool bReverse ) = 0;
  306. virtual void PasteAndRescaleSamples( const CDmeLogLayer *pBaseLayer, const CDmeLogLayer *pDataLayer, CDmeLogLayer *pOutputLayer, const DmeLog_TimeSelection_t& srcParams, const DmeLog_TimeSelection_t& destParams, bool bBlendAreaInFalloffRegion, bool bReverse ) = 0;
  307. virtual void BuildNormalizedLayer( int nChannels, CDmeTypedLogLayer< float > **pChannels, int nLayer ) = 0;
  308. virtual void BuildCorrespondingLayer( const CDmeLogLayer *pReferenceLayer, const CDmeLogLayer *pDataLayer, CDmeLogLayer *pOutputLayer ) = 0;
  309. virtual void HoldOrReleaseUsingTimeSelection( const DmeLog_TimeSelection_t& params, bool bHold, const CDmeLogLayer *pBaseLayer, CDmeLogLayer *pWriteLayer ) = 0;
  310. virtual void SteadyUsingTimeSelection( const DmeLog_TimeSelection_t& params, const CDmeLogLayer *pBaseLayer, CDmeLogLayer *pWriteLayer ) = 0;
  311. virtual void CopySamplesFromPreset( const DmeLog_TimeSelection_t& params, const CDmAttribute *pPresetValue, const CDmAttribute *pPresetTimes, DmeTime_t tLogTimeOffset, const CDmeChannelsClip *pChannelsClip, const CDmeLogLayer *pBaseLayer, CDmeLogLayer *pWriteLayer ) = 0; // preset samples are in shot time, not log time
  312. int GetTopmostLayer() const;
  313. int GetNumLayers() const;
  314. CDmeLogLayer *GetLayer( int index );
  315. const CDmeLogLayer *GetLayer( int index ) const;
  316. DmeTime_t GetBeginTime() const;
  317. DmeTime_t GetEndTime() const;
  318. int GetKeyCount() const;
  319. bool IsEmpty() const;
  320. void ScaleSampleTimes( float scale );
  321. virtual void ClearAndAddSampleAtTime( DmeTime_t time ) = 0;
  322. // Returns the index of a key closest to this time, within tolerance
  323. // NOTE: Insertion or removal may change this index!
  324. // Returns -1 if the time isn't within tolerance.
  325. virtual int FindKeyWithinTolerance( DmeTime_t time, DmeTime_t nTolerance ) = 0;
  326. // Returns the type of attribute being logged
  327. virtual DmAttributeType_t GetDataType() const = 0;
  328. // Sets a key, removes all keys after this time
  329. virtual void SetKey( DmeTime_t time, const CDmAttribute *pAttr, uint index = 0, SegmentInterpolation_t interpSetting = SEGMENT_INTERPOLATE, int curveType = CURVE_DEFAULT ) = 0;
  330. virtual bool SetDuplicateKeyAtTime( DmeTime_t time ) = 0;
  331. virtual int InsertKeyAtTime( DmeTime_t nTime, int curveType = CURVE_DEFAULT ) = 0;
  332. // Sets the interpolated value of the log at the specified time into the attribute
  333. virtual void GetValue( DmeTime_t time, CDmAttribute *pAttr, uint index = 0 ) const = 0;
  334. virtual void GetValueSkippingTopmostLayer( DmeTime_t time, CDmAttribute *pAttr, uint index = 0 ) const = 0;
  335. virtual float GetComponent( DmeTime_t time, int componentIndex ) const = 0;
  336. // Returns the time at which a particular key occurs
  337. virtual DmeTime_t GetKeyTime( int nKeyIndex ) const = 0;
  338. virtual void SetKeyTime( int nKeyIndex, DmeTime_t keyTime ) = 0;
  339. // Override curvetype for specific key
  340. void SetKeyCurveType( int nKeyIndex, int curveType );
  341. int GetKeyCurveType( int nKeyIndex ) const;
  342. // Removes a single key by index
  343. virtual void RemoveKey( int nKeyIndex, int nNumKeysToRemove = 1 ) = 0;
  344. // Removes all keys within the time range, returns true if keys were removed
  345. bool RemoveKeys( DmeTime_t tStartTime, DmeTime_t tEndTime );
  346. // Add keys at tStartTime and tEndTime, and remove all keys outside the range
  347. void TrimKeys( DmeTime_t tStartTime, DmeTime_t tEndTime );
  348. // Removes all keys
  349. virtual void ClearKeys() = 0;
  350. // Scale + bias key times
  351. void ScaleBiasKeyTimes( double flScale, DmeTime_t nBias );
  352. virtual bool IsConstantValued() const = 0;
  353. virtual void RemoveRedundantKeys( bool bKeepEnds ) = 0;
  354. virtual void RemoveRedundantKeys( float threshold, bool bKeepEnds ) = 0;
  355. // resampling and filtering
  356. virtual void Resample( DmeFramerate_t samplerate ) = 0;
  357. virtual void Filter( int nSampleRadius ) = 0;
  358. virtual void Filter2( DmeTime_t sampleRadius ) = 0;
  359. // Creates a log of a requested type
  360. static CDmeLog *CreateLog( DmAttributeType_t type, DmFileId_t fileid );
  361. virtual CDmeLogLayer *AddNewLayer() = 0;
  362. enum
  363. {
  364. FLATTEN_NODISCONTINUITY_FIXUP = (1<<0), // Don't add "helper" samples to preserve discontinuities. This occurs when the time selection is "detached" from the head position
  365. FLATTEN_SPEW = (1<<1),
  366. };
  367. virtual void FlattenLayers( float threshold, int flags, int baseLayer = 0 ) = 0;
  368. // Only used by undo system!!!
  369. virtual void AddLayerToTail( CDmeLogLayer *layer ) = 0;
  370. virtual CDmeLogLayer *RemoveLayerFromTail() = 0;
  371. virtual CDmeLogLayer *RemoveLayer( int iLayer ) = 0;
  372. // Resolve
  373. virtual void Resolve();
  374. // curve info helpers
  375. bool IsUsingCurveTypes() const;
  376. const CDmeCurveInfo *GetCurveInfo() const;
  377. CDmeCurveInfo *GetCurveInfo();
  378. virtual CDmeCurveInfo *GetOrCreateCurveInfo() = 0;
  379. virtual void SetCurveInfo( CDmeCurveInfo *pCurveInfo ) = 0;
  380. // accessors for CurveInfo data
  381. int GetDefaultCurveType() const;
  382. // FIXME - this should really be in the CurveInfo
  383. // but the animset editor currently asks for these, without having set a curveinfo...
  384. void SetMinValue( float val );
  385. void SetMaxValue( float val );
  386. float GetMinValue() const;
  387. float GetMaxValue() const;
  388. virtual bool HasDefaultValue() const = 0;
  389. // Bookmark functions
  390. virtual void InitalizeBookmarkArrays() = 0;
  391. virtual int GetNumBookmarkComponents() const = 0;
  392. int GetNumBookmarks( int nComponentIndex ) const;
  393. DmeTime_t GetBookmarkTime( int nBookmarkIndex, int nComponentIndex ) const;
  394. void AddBookmark( DmeTime_t time, int nComponentIndex );
  395. bool RemoveBookmark( DmeTime_t time, int nComponentIndex );
  396. void RemoveAllBookmarks( int nComponentIndex );
  397. void SetAllBookmarks( int nComponentIndex, const CUtlVector< DmeTime_t > &time );
  398. // Masks all keys within the time range, returns true if keys were modified
  399. virtual bool MaskKeyRange( DmeTime_t tStartTime, DmeTime_t tEndTime, LogComponents_t nComponentFlags, bool bInfiniteLeft = false, bool bInfiniteRight = false ) = 0;
  400. protected:
  401. // int FindKey( DmeTime_t time ) const;
  402. void OnUsingCurveTypesChanged();
  403. virtual void OnAttributeChanged( CDmAttribute *pAttribute );
  404. CDmaElementArray< CDmeLogLayer > m_Layers;
  405. CDmaElement< CDmeCurveInfo > m_CurveInfo;
  406. CDmaArray< DmeTime_t > m_BookmarkTimes[ LOG_MAX_COMPONENTS ];
  407. };
  408. //-----------------------------------------------------------------------------
  409. // CDmeTypedCurveInfo - implementation class for all logs
  410. //-----------------------------------------------------------------------------
  411. template< class T >
  412. class CDmeTypedCurveInfo : public CDmeCurveInfo
  413. {
  414. DEFINE_ELEMENT( CDmeTypedCurveInfo, CDmeCurveInfo );
  415. public:
  416. // For "faceposer" style left/right edges, this controls whether interpolators try to mimic faceposer left/right edge behavior
  417. void SetUseEdgeInfo( bool state );
  418. bool IsUsingEdgeInfo() const;
  419. void SetEdgeInfo( int edge, bool active, const T& val, int curveType );
  420. void GetEdgeInfo( int edge, bool& active, T& val, int& curveType ) const;
  421. void SetDefaultEdgeZeroValue( const T& val );
  422. const T& GetDefaultEdgeZeroValue() const;
  423. void SetRightEdgeTime( DmeTime_t time );
  424. DmeTime_t GetRightEdgeTime() const;
  425. bool IsEdgeActive( int edge ) const;
  426. void GetEdgeValue( int edge, T& value ) const;
  427. int GetEdgeCurveType( int edge ) const;
  428. void GetZeroValue( int side, T& val ) const;
  429. protected:
  430. CDmaVar< bool > m_bUseEdgeInfo;
  431. // Array of 2 for left/right edges...
  432. CDmaVar< bool > m_bEdgeActive[ 2 ];
  433. CDmaVar< T > m_EdgeValue[ 2 ];
  434. CDmaVar< int > m_EdgeCurveType[ 2 ];
  435. CDmaTime m_RightEdgeTime;
  436. CDmaVar< T > m_DefaultEdgeValue;
  437. };
  438. // forward declaration
  439. template< class T > class CDmeTypedLog;
  440. template< typename T >
  441. struct LogKeyValue_t
  442. {
  443. T value;
  444. DmeTime_t time;
  445. };
  446. //-----------------------------------------------------------------------------
  447. // CDmeTypedLogLayer - implementation class for all logs
  448. //-----------------------------------------------------------------------------
  449. template< class T >
  450. class CDmeTypedLogLayer : public CDmeLogLayer
  451. {
  452. DEFINE_ELEMENT( CDmeTypedLogLayer, CDmeLogLayer );
  453. public:
  454. virtual void CopyLayer( const CDmeLogLayer *src );
  455. virtual void CopyPartialLayer( const CDmeLogLayer *src, DmeTime_t startTime, DmeTime_t endTime, bool bRebaseTimestamps );
  456. virtual void ExplodeLayer( const CDmeLogLayer *src, DmeTime_t startTime, DmeTime_t endTime, bool bRebaseTimestamps, DmeTime_t tResampleInterval );
  457. virtual void InsertKeyFromLayer( DmeTime_t keyTime, const CDmeLogLayer *src, DmeTime_t srcKeyTime );
  458. // Finds a key within tolerance, or adds one. Unlike SetKey, this will *not* delete keys after the specified time
  459. int FindOrAddKey( DmeTime_t nTime, DmeTime_t nTolerance, const T& value, SegmentInterpolation_t interpSetting = SEGMENT_INTERPOLATE, int curveType = CURVE_DEFAULT );
  460. // Sets a key, removes all keys after this time
  461. void SetKey( DmeTime_t time, const T& value, SegmentInterpolation_t interpSetting = SEGMENT_INTERPOLATE, int curveType = CURVE_DEFAULT, bool removeRedundant = true );
  462. // Sets all of the keys on the layer from the provided array of times and values
  463. void SetAllKeys( const CUtlVector< DmeTime_t > &times, const CUtlVector< T > &values );
  464. // Copy all of the keys into the specified array
  465. void GetAllKeys( CUtlVector< DmeTime_t > &times, CUtlVector< T > &values ) const;
  466. // This inserts a key using the current values to construct the proper value for the time
  467. virtual int InsertKeyAtTime( DmeTime_t nTime, int curveType = CURVE_DEFAULT );
  468. // Add keys at tStartTime and tEndTime, and remove all keys outside the range
  469. virtual void TrimKeys( DmeTime_t tStartTime, DmeTime_t tEndTime );
  470. void SetKeyValue( int nKey, const T& value );
  471. const T& GetValue( DmeTime_t time ) const;
  472. const T& GetKeyValue( int nKeyIndex ) const;
  473. const T& GetValueSkippingKey( int nKeyToSkip ) const;
  474. // Returns the key time / value pair for the specified key
  475. void GetKeyValue( int keyIndex, LogKeyValue_t< T > &keyValue ) const;
  476. // This inserts a key. Unlike SetKey, this will *not* delete keys after the specified time
  477. int InsertKey( DmeTime_t nTime, const T& value, SegmentInterpolation_t interpSetting = SEGMENT_INTERPOLATE, int curveType = CURVE_DEFAULT, bool bIgnoreTolerance = false );
  478. // inherited from CDmeLog
  479. virtual void ClearKeys();
  480. virtual void SetKey( DmeTime_t time, const CDmAttribute *pAttr, uint index = 0, SegmentInterpolation_t interpSetting = SEGMENT_INTERPOLATE, int curveType = CURVE_DEFAULT );
  481. virtual bool SetDuplicateKeyAtTime( DmeTime_t time );
  482. virtual void GetValue( DmeTime_t time, CDmAttribute *pAttr, uint index = 0 ) const;
  483. virtual float GetComponent( DmeTime_t time, int componentIndex ) const;
  484. virtual DmAttributeType_t GetDataType() const;
  485. virtual bool IsConstantValued() const;
  486. virtual void RemoveRedundantKeys( bool bKeepEnds );
  487. virtual void RemoveRedundantKeys( float threshold, bool bKeepEnds );
  488. virtual void RemoveKey( int nKeyIndex, int nNumKeysToRemove = 1 );
  489. virtual void Resample( DmeFramerate_t samplerate );
  490. virtual void Filter( int nSampleRadius );
  491. virtual void Filter2( DmeTime_t sampleRadius );
  492. void RemoveKeys( DmeTime_t starttime );
  493. // curve info helpers
  494. const CDmeTypedCurveInfo< T > *GetTypedCurveInfo() const;
  495. CDmeTypedCurveInfo< T > *GetTypedCurveInfo();
  496. bool IsUsingEdgeInfo() const;
  497. void GetEdgeInfo( int edge, bool& active, T& val, int& curveType ) const;
  498. const T& GetDefaultEdgeZeroValue() const;
  499. DmeTime_t GetRightEdgeTime() const;
  500. void SetOwnerLog( CDmeLog *owner );
  501. CDmeTypedLog< T > *GetTypedOwnerLog();
  502. const CDmeTypedLog< T > *GetTypedOwnerLog() const;
  503. T MaskValue( DmeTime_t time, const T& value, LogComponents_t componentFlags ) const;
  504. // Masks all keys within the time range, returns true if keys were modified
  505. virtual bool MaskKeyRange( DmeTime_t tStartTime, DmeTime_t tEndTime, LogComponents_t nComponentFlags, bool bInfiniteLeft = false, bool bInfiniteRight = false );
  506. virtual void MakeRoomForSamplesMaskedSubcomponents( CDmeLogLayer *pBaseLayer, DmeTime_t tStart, DmeTime_t tEnd, DmeTime_t tLeftShift, DmeTime_t tRightShift, LogComponents_t nComponents );
  507. virtual void Compress();
  508. virtual void Decompress();
  509. virtual bool IsCompressed() const;
  510. virtual size_t GetCompressedSize() const;
  511. virtual size_t GetDataSize() const;
  512. protected:
  513. int GetEdgeCurveType( int edge ) const;
  514. void GetZeroValue( int side, T& val ) const;
  515. void GetValueUsingCurveInfo( DmeTime_t time, T& out ) const;
  516. void GetValueUsingCurveInfoSkippingKey( int nKeyToSkip, T& out ) const;
  517. void GetBoundedSample( int keyindex, DmeTime_t& time, T& val, int& curveType ) const;
  518. void CurveSimplify_R( float thresholdSqr, int startPoint, int endPoint, CDmeTypedLogLayer< T > *output );
  519. friend CDmeTypedLog< T >;
  520. void GetTwoKeyValues( int keyindex, T &v1, T &v2 ) const;
  521. void GetCompressedValue( int nKeyIndex, T &value ) const;
  522. void GetCompressedValues( int nKeyIndex, T &value1, T &value2 ) const;
  523. void CompressValues( CDmaArray< T > &stream, CUtlBinaryBlock &block, float flMaxError = 0.1f );
  524. protected:
  525. CDmaArray< T > m_values;
  526. // When compressed, m_values is empty and data is read from here
  527. CDmaVar< CUtlBinaryBlock > m_Compressed;
  528. };
  529. //-----------------------------------------------------------------------------
  530. // CDmeTypedLog - implementation class for all logs
  531. //-----------------------------------------------------------------------------
  532. template< class T >
  533. class CDmeTypedLog : public CDmeLog
  534. {
  535. DEFINE_ELEMENT( CDmeTypedLog, CDmeLog );
  536. public:
  537. virtual void OnAttributeArrayElementAdded( CDmAttribute *pAttribute, int nFirstElem, int nLastElem );
  538. CDmeTypedLogLayer< T > *GetLayer( int index );
  539. const CDmeTypedLogLayer< T > *GetLayer( int index ) const;
  540. void StampKeyAtHead( DmeTime_t tHeadPosition, DmeTime_t tPreviousHeadPosition, const DmeLog_TimeSelection_t& params, const DmeLogTransformParams_t &transformParams, const T& value, bool bTimeFilter = true, int layerIndex = -1 );
  541. void StampKeyAtHead( DmeTime_t tHeadPosition, DmeTime_t tPreviousHeadPosition, const DmeLog_TimeSelection_t& params, const DmeLogTransformParams_t &transformParams, const CDmAttribute *pAttr, uint arrayIndex = 0, bool bTimeFilter = true, int logLayer = -1 );
  542. void FinishTimeSelection( DmeTime_t tHeadPosition, DmeLog_TimeSelection_t& params ); // in attached, time advancing mode, we need to blend out of the final sample over the fadeout interval
  543. void FilterUsingTimeSelection( IUniformRandomStream &random, float flScale, const DmeLog_TimeSelection_t& params, int filterType, bool bResample, bool bApplyFalloff, const CDmeLogLayer *baseLayer, CDmeLogLayer *writeLayer );
  544. void FilterUsingTimeSelection( IUniformRandomStream &random, const DmeLog_TimeSelection_t& params, int filterType, bool bResample, bool bApplyFalloff );
  545. void StaggerUsingTimeSelection( const DmeLog_TimeSelection_t& params, DmeTime_t tStaggerAmount, const CDmeLogLayer *baseLayer, CDmeLogLayer *writeLayer );
  546. void RevealUsingTimeSelection( const DmeLog_TimeSelection_t &params, const CDmeLogLayer *pTargetLayer );
  547. void RecaleAndRevealUsingTimeSelection( const DmeLog_TimeSelection_t &params, TimeSelection_t &sourceTimeSelection, const CDmeLogLayer *pTargetLayer );
  548. void GenerateSplineUsingTimeSelection( const DmeLog_TimeSelection_t& params, const CUtlVector< DmeTime_t > &sortedSplineKeyTimes, const CDmeLogLayer *baseLayer, CDmeLogLayer *writeLayer );
  549. void BlendLayersUsingTimeSelection( const DmeLog_TimeSelection_t &params, int baseLayer = 0 );
  550. void BlendLayersUsingTimeSelection( const CDmeLogLayer *firstLayer, const CDmeLogLayer *secondLayer, CDmeLogLayer *outputLayer, const DmeLog_TimeSelection_t &params, bool bUseBaseLayerSamples, bool bUseFalloff, bool bSelectionSamples, DmeTime_t tStartOffset );
  551. void BlendLayersUsingTimeSelection( const CDmeLogLayer *baseLayer, const CDmeLogLayer *firstLayer, const CDmeLogLayer *secondLayer, CDmeLogLayer *outputLayer, const DmeLog_TimeSelection_t &params, bool bUseBaseLayerSamples, DmeTime_t tStartOffset );
  552. void BlendLayersUsingTimeSelection( const DmeLog_TimeSelection_t &params, const CDmeTypedLogLayer< T > *pBaseLayer, const CDmeTypedLogLayer< T > *pBlendLayer, CDmeTypedLogLayer< T > *pOutputLayer );
  553. void BlendTimesUsingTimeSelection( const CDmeLogLayer *firstLayer, const CDmeLogLayer *secondLayer, CDmeLogLayer *outputLayer, const DmeLog_TimeSelection_t &params, DmeTime_t tStartOffset, bool bFeatherBlendInFalloff );
  554. void HoldOrReleaseUsingTimeSelection( const DmeLog_TimeSelection_t& params, bool bHold, const CDmeLogLayer *pBaseLayer, CDmeLogLayer *pWriteLayer );
  555. void SteadyUsingTimeSelection( const DmeLog_TimeSelection_t& params, const CDmeLogLayer *pBaseLayer, CDmeLogLayer *pWriteLayer );
  556. void CopySamplesFromPreset( const DmeLog_TimeSelection_t& params, const CDmAttribute *pPresetValue, const CDmAttribute *pPresetTimes, DmeTime_t tLogTimeOffset, const CDmeChannelsClip *pChannelsClip, const CDmeLogLayer *pBaseLayer, CDmeLogLayer *pWriteLayer ); // preset samples are in shot time, not log time
  557. virtual void PasteAndRescaleSamples( const CDmeLogLayer *src, const DmeLog_TimeSelection_t& srcParams, const DmeLog_TimeSelection_t& destParams, bool bBlendAreaInFalloffRegion, bool bReverse );
  558. virtual void PasteAndRescaleSamples( const CDmeLogLayer *pBaseLayer, const CDmeLogLayer *pDataLayer, CDmeLogLayer *pOutputLayer, const DmeLog_TimeSelection_t& srcParams, const DmeLog_TimeSelection_t& destParams, bool bBlendAreaInFalloffRegion, bool bReverse );
  559. virtual void BuildCorrespondingLayer( const CDmeLogLayer *pReferenceLayer, const CDmeLogLayer *pDataLayer, CDmeLogLayer *pOutputLayer );
  560. virtual void BuildNormalizedLayer( int nChannels, CDmeTypedLogLayer< float > **pChannels, int nLayer );
  561. // Finds a key within tolerance, or adds one. Unlike SetKey, this will *not* delete keys after the specified time
  562. int FindOrAddKey( DmeTime_t nTime, DmeTime_t nTolerance, const T& value, SegmentInterpolation_t interpSetting = SEGMENT_INTERPOLATE, int curveType = CURVE_DEFAULT );
  563. // Sets a key, removes all keys after this time
  564. void SetKey( DmeTime_t time, const T& value, SegmentInterpolation_t interpSetting = SEGMENT_INTERPOLATE, int curveType = CURVE_DEFAULT );
  565. int InsertKeyAtTime( DmeTime_t nTime, int curveType = CURVE_DEFAULT );
  566. bool ValuesDiffer( const T& a, const T& b ) const;
  567. const T& GetValue( DmeTime_t time ) const;
  568. const T& GetValueSkippingTopmostLayer( DmeTime_t time ) const;
  569. const T& GetValueBelowLayer( DmeTime_t time, int nTopLayerIndex ) const;
  570. const T& GetKeyValue( int nKeyIndex ) const;
  571. // This inserts a key. Unlike SetKey, this will *not* delete keys after the specified time
  572. int InsertKey( DmeTime_t nTime, const T& value, SegmentInterpolation_t interpSetting = SEGMENT_INTERPOLATE, int curveType = CURVE_DEFAULT, bool bIgnoreTolerance = false );
  573. // inherited from CDmeLog
  574. virtual void ClearKeys();
  575. virtual void SetKey( DmeTime_t time, const CDmAttribute *pAttr, uint index = 0, SegmentInterpolation_t interpSetting = SEGMENT_INTERPOLATE, int curveType = CURVE_DEFAULT );
  576. virtual bool SetDuplicateKeyAtTime( DmeTime_t time );
  577. virtual void GetValue( DmeTime_t time, CDmAttribute *pAttr, uint index = 0 ) const;
  578. virtual void GetValueSkippingTopmostLayer( DmeTime_t time, CDmAttribute *pAttr, uint index = 0 ) const;
  579. virtual float GetComponent( DmeTime_t time, int componentIndex ) const;
  580. virtual DmAttributeType_t GetDataType() const;
  581. virtual bool IsConstantValued() const;
  582. virtual void RemoveRedundantKeys( bool bKeepEnds );
  583. virtual void RemoveRedundantKeys( float threshold, bool bKeepEnds );
  584. virtual void RemoveKey( int nKeyIndex, int nNumKeysToRemove = 1 );
  585. virtual void Resample( DmeFramerate_t samplerate );
  586. virtual void Filter( int nSampleRadius );
  587. virtual void Filter2( DmeTime_t sampleRadius );
  588. virtual int FindKeyWithinTolerance( DmeTime_t time, DmeTime_t nTolerance );
  589. virtual DmeTime_t GetKeyTime( int nKeyIndex ) const;
  590. virtual void SetKeyTime( int nKeyIndex, DmeTime_t keyTime );
  591. virtual void ClearAndAddSampleAtTime( DmeTime_t time );
  592. virtual CDmeLogLayer *AddNewLayer();
  593. virtual void FlattenLayers( float threshhold, int flags, int baseLayer = 0 );
  594. // Only used by undo system!!!
  595. virtual void AddLayerToTail( CDmeLogLayer *layer );
  596. virtual CDmeLogLayer *RemoveLayerFromTail();
  597. virtual CDmeLogLayer *RemoveLayer( int iLayer );
  598. // curve info helpers
  599. const CDmeTypedCurveInfo< T > *GetTypedCurveInfo() const;
  600. CDmeTypedCurveInfo< T > *GetTypedCurveInfo();
  601. virtual CDmeCurveInfo *GetOrCreateCurveInfo();
  602. virtual void SetCurveInfo( CDmeCurveInfo *pCurveInfo );
  603. // For "faceposer" style left/right edges, this controls whether interpolators try to mimic faceposer left/right edge behavior
  604. void SetUseEdgeInfo( bool state );
  605. bool IsUsingEdgeInfo() const;
  606. void SetEdgeInfo( int edge, bool active, const T& val, int curveType );
  607. void GetEdgeInfo( int edge, bool& active, T& val, int& curveType ) const;
  608. void SetDefaultEdgeZeroValue( const T& val );
  609. const T& GetDefaultEdgeZeroValue() const;
  610. void SetRightEdgeTime( DmeTime_t time );
  611. DmeTime_t GetRightEdgeTime() const;
  612. bool IsEdgeActive( int edge ) const;
  613. void GetEdgeValue( int edge, T& value ) const;
  614. int GetEdgeCurveType( int edge ) const;
  615. void GetZeroValue( int side, T& val ) const;
  616. T ClampValue( const T& value );
  617. T MaskValue( DmeTime_t time, const T& value, LogComponents_t componentFlags ) const;
  618. void SetDefaultValue( const T& value );
  619. const T& GetDefaultValue() const;
  620. bool HasDefaultValue() const;
  621. void ClearDefaultValue();
  622. static float s_threshold;
  623. static float GetValueThreshold() { return s_threshold; }
  624. static void SetValueThreshold( float s_threshold );
  625. // Bookmark functions
  626. virtual void InitalizeBookmarkArrays();
  627. virtual int GetNumBookmarkComponents() const;
  628. // Removes all keys within the time range, returns true if keys were removed
  629. virtual bool MaskKeyRange( DmeTime_t tStartTime, DmeTime_t tEndTime, LogComponents_t nComponentFlags, bool bInfiniteLeft = false, bool bInfiniteRight = false );
  630. void MaskAgainstLayer( CDmeTypedLogLayer< T > *pFinalLayer, const CDmeTypedLogLayer< T > *pReferenceLayer, LogComponents_t nComponentFlags );
  631. SegmentInterpolation_t GetSegmentInterpolationSetting( DmeTime_t time ) const;
  632. SegmentInterpolation_t GetSegmentInterpolationSetting_SkippingTopmostLayer( DmeTime_t time ) const;
  633. protected:
  634. void RemoveKeys( DmeTime_t starttime );
  635. void _StampKeyAtHeadResample( DmeTime_t tHeadPosition, const DmeLog_TimeSelection_t & params, const DmeLogTransformParams_t &transformParams, const T& value, bool bSkipToHead, bool bClearPreviousKeys, int layerIndex = -1 );
  636. void _StampKeyAtHead( DmeTime_t tHeadPosition, DmeTime_t tPreviousHeadPosition, const DmeLog_TimeSelection_t & params, const T& value, bool bFilteredByTimeSelection, int layerIndex = -1 );
  637. void _StampKeyAtTime( CDmeTypedLogLayer< T > *pWriteLayer, DmeTime_t t, const DmeLog_TimeSelection_t &params, const T& value, bool bFilterByTimeSelection, bool bForce = false );
  638. protected:
  639. CDmaVar< bool > m_UseDefaultValue;
  640. CDmaVar< T > m_DefaultValue;
  641. };
  642. //-----------------------------------------------------------------------------
  643. // Template methods
  644. //-----------------------------------------------------------------------------
  645. template< class T >
  646. DmAttributeType_t CDmeTypedLogLayer<T>::GetDataType() const
  647. {
  648. return CDmAttributeInfo< T >::AttributeType();
  649. }
  650. template< class T >
  651. bool CDmeTypedLogLayer<T>::IsConstantValued() const
  652. {
  653. if ( m_values.Count() < 2 )
  654. return true;
  655. if ( m_values.Count() == 2 && !GetTypedOwnerLog()->ValuesDiffer( m_values[ 0 ], m_values[ 1 ] ) )
  656. return true;
  657. // we're throwing away duplicate values during recording, so this is generally correct
  658. // although there are paths to set keys that don't use the duplicate test, so it's not 100%
  659. return false;
  660. }
  661. //-----------------------------------------------------------------------------
  662. // Template methods
  663. //-----------------------------------------------------------------------------
  664. template< class T >
  665. DmAttributeType_t CDmeTypedLog<T>::GetDataType() const
  666. {
  667. return CDmAttributeInfo< T >::AttributeType();
  668. }
  669. template< class T >
  670. void CDmeTypedLog<T>::SetValueThreshold( float thresh )
  671. {
  672. s_threshold = thresh;
  673. }
  674. template< class T >
  675. bool CDmeTypedLog<T>::IsConstantValued() const
  676. {
  677. int c = m_Layers.Count();
  678. for ( int i = 0; i < c; ++i )
  679. {
  680. if ( !GetLayer( i )->IsConstantValued() )
  681. return false;
  682. }
  683. return true;
  684. }
  685. template< class T >
  686. void CDmeTypedLog<T>::RemoveRedundantKeys( bool bKeepEnds )
  687. {
  688. int bestLayer = GetTopmostLayer();
  689. if ( bestLayer < 0 )
  690. return;
  691. GetLayer( bestLayer )->RemoveRedundantKeys( bKeepEnds );
  692. }
  693. template< class T >
  694. inline T MaskValue( const T& newValue, const T &currentValue, LogComponents_t componentFlags )
  695. {
  696. return newValue;
  697. }
  698. template<>
  699. inline Vector MaskValue( const Vector& value, const Vector &curValue, LogComponents_t componentFlags )
  700. {
  701. Vector writeValue;
  702. writeValue.x = ( componentFlags & LOG_COMPONENTS_X ) ? value.x : curValue.x;
  703. writeValue.y = ( componentFlags & LOG_COMPONENTS_Y ) ? value.y : curValue.y;
  704. writeValue.z = ( componentFlags & LOG_COMPONENTS_Z ) ? value.z : curValue.z;
  705. return writeValue;
  706. }
  707. template<>
  708. inline Quaternion MaskValue( const Quaternion& value, const Quaternion &curQuat, LogComponents_t componentFlags )
  709. {
  710. Quaternion writeValue;
  711. // Convert to euler
  712. QAngle curQA;
  713. QuaternionAngles( curQuat, curQA );
  714. QAngle valueQA;
  715. QuaternionAngles( value, valueQA );
  716. // Mask euler
  717. valueQA.x = ( componentFlags & LOG_COMPONENTS_X ) ? valueQA.x : curQA.x;
  718. valueQA.y = ( componentFlags & LOG_COMPONENTS_Y ) ? valueQA.y : curQA.y;
  719. valueQA.z = ( componentFlags & LOG_COMPONENTS_Z ) ? valueQA.z : curQA.z;
  720. // convert back to Quaternion for output
  721. AngleQuaternion( valueQA, writeValue );
  722. return writeValue;
  723. }
  724. template< class T >
  725. inline float Normalize( const T& val )
  726. {
  727. Assert( 0 );
  728. return 0.5f;
  729. }
  730. // AT_INT
  731. // AT_FLOAT
  732. // AT_VECTOR*
  733. template<>
  734. inline float Normalize( const bool& val )
  735. {
  736. return val ? 1.0f : 0.0f;
  737. }
  738. template<>
  739. inline float Normalize( const Color& val )
  740. {
  741. float sum = 0.0f;
  742. for ( int i = 0 ; i < 4; ++i )
  743. {
  744. sum += val[ i ];
  745. }
  746. sum /= 4.0f;
  747. return clamp( sum / 255.0f, 0.0f, 1.0f );
  748. }
  749. template<>
  750. inline float Normalize( const QAngle& val )
  751. {
  752. float sum = 0.0f;
  753. for ( int i = 0 ; i < 3; ++i )
  754. {
  755. float ang = val[ i ];
  756. if ( ang < 0.0f )
  757. {
  758. ang += 360.0f;
  759. }
  760. sum += ang;
  761. }
  762. return clamp( ( sum / 3.0f ) / 360.0f, 0.0f, 1.0f );
  763. }
  764. template<>
  765. inline float Normalize( const Quaternion& val )
  766. {
  767. float flAngle = 2.0f * acos( fabs( val.w ) );
  768. return flAngle / M_PI;
  769. // QAngle angle;
  770. // QuaternionAngles( val, angle );
  771. // return Normalize( angle );
  772. }
  773. template< class T >
  774. inline void CDmeTypedLog< T >::BuildNormalizedLayer( int nChannels, CDmeTypedLogLayer< float > **pChannels, int nLayer )
  775. {
  776. VPROF_BUDGET( "CDmeTypedLog< T >::BuildNormalizedLayer", "SFM" );
  777. Assert( pChannels );
  778. Assert( GetDataType() != AT_FLOAT );
  779. CDmeTypedLogLayer< T > *pBaseLayer = static_cast< CDmeTypedLogLayer< T > * >( GetLayer( nLayer ) );
  780. if ( !pBaseLayer )
  781. return;
  782. int kc = pBaseLayer->GetKeyCount();
  783. for ( int i = 0; i < kc; ++i )
  784. {
  785. DmeTime_t tKeyTime = pBaseLayer->GetKeyTime( i );
  786. T keyValue = pBaseLayer->GetKeyValue( i );
  787. float flNormalized = Normalize( keyValue );
  788. pChannels[ 0 ]->InsertKey( tKeyTime, flNormalized, pBaseLayer->GetSegmentInterpolationSetting( i ) );
  789. }
  790. if ( HasDefaultValue() )
  791. {
  792. pChannels[ 0 ]->GetTypedOwnerLog()->SetDefaultValue( Normalize( GetDefaultValue() ) );
  793. }
  794. }
  795. // Generic implementations all stubbed
  796. // Forward declare specific typed instantiations for float types
  797. template< class T > T CDmeTypedLog< T >::ClampValue( const T& value ) { return value; }
  798. template<> float CDmeTypedLog< float >::ClampValue( const float& value );
  799. template< class T > void CDmeTypedCurveInfo< T >::GetZeroValue( int side, T& val ) const{ Assert( 0 ); }
  800. template< class T > bool CDmeTypedCurveInfo< T >::IsEdgeActive( int edge ) const{ Assert( 0 ); return false; }
  801. template< class T > void CDmeTypedCurveInfo< T >::GetEdgeValue( int edge, T &value ) const{ Assert( 0 ); }
  802. template<> void CDmeTypedCurveInfo< float >::GetZeroValue( int side, float& val ) const;
  803. template<> bool CDmeTypedCurveInfo< float >::IsEdgeActive( int edge ) const;
  804. template<> void CDmeTypedCurveInfo< float >::GetEdgeValue( int edge, float &value ) const;
  805. template<> void CDmeTypedCurveInfo< Vector >::GetZeroValue( int side, Vector& val ) const;
  806. template<> void CDmeTypedCurveInfo< Quaternion >::GetZeroValue( int side, Quaternion& val ) const;
  807. template< class T > void CDmeTypedLogLayer< T >::GetValueUsingCurveInfo( DmeTime_t time, T& out ) const { Assert( 0 ); }
  808. template< class T > void CDmeTypedLogLayer< T >::GetValueUsingCurveInfoSkippingKey( int nKeyToSkip, T& out ) const { Assert( 0 ); }
  809. template<> void CDmeTypedLogLayer< float >::GetValueUsingCurveInfo( DmeTime_t time, float& out ) const;
  810. template<> void CDmeTypedLogLayer< float >::GetValueUsingCurveInfoSkippingKey( int nKeyToSkip, float& out ) const;
  811. template<> void CDmeTypedLogLayer< Vector >::GetValueUsingCurveInfo( DmeTime_t time, Vector& out ) const;
  812. template<> void CDmeTypedLogLayer< Vector >::GetValueUsingCurveInfoSkippingKey( int nKeyToSkip, Vector& out ) const;
  813. template<> void CDmeTypedLogLayer< Quaternion >::GetValueUsingCurveInfo( DmeTime_t time, Quaternion& out ) const;
  814. template<> void CDmeTypedLogLayer< Quaternion >::GetValueUsingCurveInfoSkippingKey( int nKeyToSkip, Quaternion& out ) const;
  815. template<class T> void CDmeTypedLogLayer< T >::CurveSimplify_R( float thresholdSqr, int startPoint, int endPoint, CDmeTypedLogLayer< T > *output );
  816. template<> void CDmeTypedLogLayer< bool >::CurveSimplify_R( float thresholdSqr, int startPoint, int endPoint, CDmeTypedLogLayer< bool > *output );
  817. template<> void CDmeTypedLogLayer< int >::CurveSimplify_R( float thresholdSqr, int startPoint, int endPoint, CDmeTypedLogLayer< int > *output );
  818. template<> void CDmeTypedLogLayer< Color >::CurveSimplify_R( float thresholdSqr, int startPoint, int endPoint, CDmeTypedLogLayer< Color > *output );
  819. template<> void CDmeTypedLogLayer< Quaternion >::CurveSimplify_R( float thresholdSqr, int startPoint, int endPoint, CDmeTypedLogLayer< Quaternion > *output );
  820. template<> void CDmeTypedLogLayer< VMatrix >::CurveSimplify_R( float thresholdSqr, int startPoint, int endPoint, CDmeTypedLogLayer< VMatrix > *output );
  821. template<> void CDmeTypedLog< Vector >::BuildNormalizedLayer( int nChannels, CDmeTypedLogLayer< float > **pChannels, int nLayer );
  822. template<> void CDmeTypedLog< Vector2D >::BuildNormalizedLayer( int nChannels, CDmeTypedLogLayer< float > **pChannels, int nLayer );
  823. template<> void CDmeTypedLog< Vector4D >::BuildNormalizedLayer( int nChannels, CDmeTypedLogLayer< float > **pChannels, int nLayer );
  824. template<> void CDmeTypedLog< float >::BuildNormalizedLayer( int nChannels, CDmeTypedLogLayer< float > **pChannels, int nLayer );
  825. template<> void CDmeTypedLog< int >::BuildNormalizedLayer( int nChannels, CDmeTypedLogLayer< float > **pChannels, int nLayer );
  826. template<> void CDmeTypedLog< DmeTime_t >::BuildNormalizedLayer( int nChannels, CDmeTypedLogLayer< float > **pChannels, int nLayer );
  827. template<> void CDmeTypedLog< Quaternion >::BuildNormalizedLayer( int nChannels, CDmeTypedLogLayer< float > **pChannels, int nLayer );
  828. template< class T >int CDmeTypedLog< T >::GetNumBookmarkComponents() const;
  829. template<> int CDmeTypedLog< Vector >::GetNumBookmarkComponents() const;
  830. template<> int CDmeTypedLog< Vector2D >::GetNumBookmarkComponents() const;
  831. template<> int CDmeTypedLog< Vector4D >::GetNumBookmarkComponents() const;
  832. template<> int CDmeTypedLog< Quaternion >::GetNumBookmarkComponents() const;
  833. template< class T > void CDmeTypedLog< T >::InitalizeBookmarkArrays();
  834. template<> void CDmeTypedLog< Vector >::InitalizeBookmarkArrays();
  835. template<> void CDmeTypedLog< Vector2D >::InitalizeBookmarkArrays();
  836. template<> void CDmeTypedLog< Vector4D >::InitalizeBookmarkArrays();
  837. template<> void CDmeTypedLog< Quaternion >::InitalizeBookmarkArrays();
  838. //template<> void CDmeTypedLog< float >::FinishTimeSelection( DmeTime_t tHeadPosition, DmeLog_TimeSelection_t& params );
  839. //template<> void CDmeTypedLog< bool >::_StampKeyAtHeadResample( const DmeLog_TimeSelection_t& params, const bool& value ) { Assert( 0 ); }
  840. //-----------------------------------------------------------------------------
  841. // typedefs for convenience (and so the user-supplied names match the programmer names)
  842. //-----------------------------------------------------------------------------
  843. typedef CDmeTypedLog<int> CDmeIntLog;
  844. typedef CDmeTypedLog<float> CDmeFloatLog;
  845. typedef CDmeTypedLog<bool> CDmeBoolLog;
  846. typedef CDmeTypedLog<Color> CDmeColorLog;
  847. typedef CDmeTypedLog<Vector2D> CDmeVector2Log;
  848. typedef CDmeTypedLog<Vector> CDmeVector3Log;
  849. typedef CDmeTypedLog<Vector4D> CDmeVector4Log;
  850. typedef CDmeTypedLog<QAngle> CDmeQAngleLog;
  851. typedef CDmeTypedLog<Quaternion> CDmeQuaternionLog;
  852. typedef CDmeTypedLog<VMatrix> CDmeVMatrixLog;
  853. typedef CDmeTypedLog<CUtlSymbolLarge> CDmeStringLog;
  854. typedef CDmeTypedLog<DmeTime_t> CDmeTimeLog;
  855. //-----------------------------------------------------------------------------
  856. // typedefs for convenience (and so the user-supplied names match the programmer names)
  857. //-----------------------------------------------------------------------------
  858. typedef CDmeTypedLogLayer<int> CDmeIntLogLayer;
  859. typedef CDmeTypedLogLayer<float> CDmeFloatLogLayer;
  860. typedef CDmeTypedLogLayer<bool> CDmeBoolLogLayer;
  861. typedef CDmeTypedLogLayer<Color> CDmeColorLogLayer;
  862. typedef CDmeTypedLogLayer<Vector2D> CDmeVector2LogLayer;
  863. typedef CDmeTypedLogLayer<Vector> CDmeVector3LogLayer;
  864. typedef CDmeTypedLogLayer<Vector4D> CDmeVector4LogLayer;
  865. typedef CDmeTypedLogLayer<QAngle> CDmeQAngleLogLayer;
  866. typedef CDmeTypedLogLayer<Quaternion> CDmeQuaternionLogLayer;
  867. typedef CDmeTypedLogLayer<VMatrix> CDmeVMatrixLogLayer;
  868. typedef CDmeTypedLogLayer<CUtlSymbolLarge> CDmeStringLogLayer;
  869. typedef CDmeTypedLogLayer<DmeTime_t> CDmeTimeLogLayer;
  870. //-----------------------------------------------------------------------------
  871. // typedefs for convenience (and so the user-supplied names match the programmer names)
  872. //-----------------------------------------------------------------------------
  873. typedef CDmeTypedCurveInfo<int> CDmeIntCurveInfo;
  874. typedef CDmeTypedCurveInfo<float> CDmeFloatCurveInfo;
  875. typedef CDmeTypedCurveInfo<bool> CDmeBoolCurveInfo;
  876. typedef CDmeTypedCurveInfo<Color> CDmeColorCurveInfo;
  877. typedef CDmeTypedCurveInfo<Vector2D> CDmeVector2CurveInfo;
  878. typedef CDmeTypedCurveInfo<Vector> CDmeVector3CurveInfo;
  879. typedef CDmeTypedCurveInfo<Vector4D> CDmeVector4CurveInfo;
  880. typedef CDmeTypedCurveInfo<QAngle> CDmeQAngleCurveInfo;
  881. typedef CDmeTypedCurveInfo<Quaternion> CDmeQuaternionCurveInfo;
  882. typedef CDmeTypedCurveInfo<VMatrix> CDmeVMatrixCurveInfo;
  883. typedef CDmeTypedCurveInfo<CUtlSymbolLarge> CDmeStringCurveInfo;
  884. typedef CDmeTypedCurveInfo<DmeTime_t> CDmeTimeCurveInfo;
  885. // the following types are not supported
  886. // AT_ELEMENT,
  887. // AT_VOID,
  888. // <all array types>
  889. //-----------------------------------------------------------------------------
  890. // Helpers for particular types of log layers
  891. //-----------------------------------------------------------------------------
  892. void GenerateRotationLog( CDmeQuaternionLogLayer *pLayer, const Vector &vecAxis, DmeTime_t pTime[4], float pRevolutionsPerSec[4] );
  893. // rotates a position log
  894. void RotatePositionLog( CDmeVector3LogLayer *pPositionLog, const matrix3x4_t& matrix );
  895. // rotates an orientation log
  896. void RotateOrientationLog( CDmeQuaternionLogLayer *pOrientationLog, const matrix3x4_t& matrix, bool bPreMultiply );
  897. float ComputeInterpolationFactor( float flFactor, int nInterpolatorType );
  898. float GetAmountForTime( DmeTime_t dmetime, const TimeSelection_t &times, const int nInterpolationTypes[ 2 ] );
  899. #endif // DMELOG_H