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.

179 lines
6.4 KiB

  1. //========= Copyright Valve Corporation, All rights reserved. ============//
  2. //
  3. // A class used to build flex animation controls for an animation set
  4. //
  5. //=============================================================================
  6. #ifndef FLEXCONTROLBUILDER_H
  7. #define FLEXCONTROLBUILDER_H
  8. #ifdef _WIN32
  9. #pragma once
  10. #endif
  11. #include "movieobjects/timeutils.h"
  12. #include "tier1/utlvector.h"
  13. #include "movieobjects/dmelog.h"
  14. //-----------------------------------------------------------------------------
  15. // Forward declarations
  16. //-----------------------------------------------------------------------------
  17. class CDmeAnimationSet;
  18. class CDmeGameModel;
  19. class CDmeFilmClip;
  20. class CDmeChannelsClip;
  21. class CDmElement;
  22. class CDmeChannel;
  23. class CDmeBalanceToStereoCalculatorOperator;
  24. class CDmeGlobalFlexControllerOperator;
  25. //-----------------------------------------------------------------------------
  26. //
  27. // Utility class for dealing with the complex task of building flex controls
  28. //
  29. //-----------------------------------------------------------------------------
  30. class CFlexControlBuilder
  31. {
  32. public:
  33. // Main entry point for creating flex animation set controls
  34. void CreateAnimationSetControls( CDmeFilmClip *pMovie, CDmeAnimationSet *pAnimationSet,
  35. CDmeGameModel *pGameModel, CDmeFilmClip *pSourceClip, CDmeChannelsClip *pDestClip, bool bUseExistingLogs );
  36. private:
  37. enum ControlField_t
  38. {
  39. CONTROL_VALUE = 0,
  40. CONTROL_BALANCE,
  41. CONTROL_MULTILEVEL,
  42. CONTROL_FIELD_COUNT,
  43. };
  44. enum OutputField_t
  45. {
  46. OUTPUT_MONO = 0,
  47. OUTPUT_RIGHT = 0,
  48. OUTPUT_LEFT,
  49. OUTPUT_MULTILEVEL,
  50. OUTPUT_FIELD_COUNT,
  51. };
  52. struct FlexControllerInfo_t
  53. {
  54. char m_pFlexControlName[256];
  55. float m_flDefaultValue;
  56. int m_nGlobalIndex;
  57. };
  58. struct ExistingLogInfo_t
  59. {
  60. CDmeFloatLog *m_pLog;
  61. DmeTime_t m_GlobalOffset;
  62. double m_flGlobalScale;
  63. };
  64. struct ControlInfo_t
  65. {
  66. char m_pControlName[256];
  67. bool m_bIsStereo : 1;
  68. bool m_bIsMulti : 1;
  69. CDmElement *m_pControl;
  70. int m_pControllerIndex[OUTPUT_FIELD_COUNT];
  71. CDmeChannel *m_ppControlChannel[CONTROL_FIELD_COUNT];
  72. float m_pDefaultValue[CONTROL_FIELD_COUNT];
  73. ExistingLogInfo_t m_pExistingLog[CONTROL_FIELD_COUNT];
  74. };
  75. // Removes a channel from the channels clip referring to it.
  76. void RemoveChannelFromClips( CDmeChannel *pChannel );
  77. // Removes a stereo operator from the animation set referring to it
  78. void RemoveStereoOpFromSet( CDmeBalanceToStereoCalculatorOperator *pChannel );
  79. // Builds the list of flex controls (outputs) in the current game model
  80. void BuildDesiredFlexControlList( CDmeGameModel *pGameModel );
  81. // This builds a list of the desired input controls we need to have controls for
  82. // by the time we're all done with this enormous process.
  83. void BuildDesiredControlList( CDmeGameModel *pGameModel );
  84. // finds controls whose channels don't point to anything anymore, and deletes both the channels and the control
  85. void RemoveUnusedControlsAndChannels( CDmeAnimationSet *pAnimationSet, CDmeChannelsClip *pChannelsClip );
  86. // I'll bet you can guess what this does
  87. void RemoveUnusedExistingFlexControllers( CDmeGameModel *pGameModel );
  88. // Fixup list of existing flex controller logs
  89. // - reattach flex controls that were removed from the gamemodel's list
  90. void FixupExistingFlexControlLogList( CDmeFilmClip *pCurrentClip, CDmeGameModel *pGameModel );
  91. // Converts existing logs to balance/value if necessary while building the list
  92. // Also deletes existing infrastructure (balance ops, channels, flex controller ops).
  93. void BuildExistingFlexControlLogList( CDmeFilmClip *pCurrentClip, CDmeGameModel *pGameModel );
  94. // Finds a desired flex controller index in the m_FlexControllerInfo array
  95. int FindDesiredFlexController( const char *pFlexControllerName ) const;
  96. // Blows away the various elements trying to control a flex controller op
  97. void CleanupExistingFlexController( CDmeGameModel *pGameModel, CDmeGlobalFlexControllerOperator *pOp );
  98. // Finds a channels clip containing a particular channel
  99. CDmeChannelsClip* FindChannelsClipContainingChannel( CDmeFilmClip *pClip, CDmeChannel *pSearch );
  100. // Returns an existing mono log
  101. void GetExistingMonoLog( ExistingLogInfo_t *pLog, CDmeFilmClip *pClip, CDmeGlobalFlexControllerOperator *pMonoOp );
  102. // Returns an existing stereo log, performing conversion if necessary
  103. void GetExistingStereoLog( ExistingLogInfo_t *pLogs, CDmeFilmClip *pClip,
  104. CDmeGlobalFlexControllerOperator *pRightOp, CDmeGlobalFlexControllerOperator *pLeftOp );
  105. // Returns an existing value/balance log
  106. void GetExistingVBLog( ExistingLogInfo_t *pLogs, CDmeFilmClip *pClip, CDmeBalanceToStereoCalculatorOperator *pStereoOp );
  107. // Converts an existing left/right log into a value/balance log
  108. void ConvertExistingLRLogs( ExistingLogInfo_t *pLogs, CDmeFilmClip *pClip, CDmeChannel *pLeftChannel, CDmeChannel *pRightChannel );
  109. // Computes a global offset and scale to convert from log time to global time
  110. void ComputeChannelTimeTransform( DmeTime_t *pOffset, double *pScale, CDmeChannelsClip *pChannelsClip );
  111. bool ComputeChannelTimeTransform( DmeTime_t *pOffset, double *pScale, CDmeFilmClip* pClip, CDmeChannel* pChannel );
  112. // Initializes the fields of a flex control
  113. void InitializeFlexControl( ControlInfo_t &info );
  114. // Creates all controls for flexes
  115. void CreateFlexControls( CDmeAnimationSet *pAnimationSet );
  116. // Build the infrastructure of the ops that connect that control to the dmegamemodel
  117. void AttachControlsToGameModel( CDmeAnimationSet *pAnimationSet, CDmeGameModel *pGameModel, CDmeChannelsClip *pChannelsClip );
  118. // Connects a mono control to a single flex controller op
  119. void BuildFlexControllerOps( CDmeGameModel *pGameModel, CDmeChannelsClip *pChannelsClip, ControlInfo_t &info, ControlField_t field );
  120. // Connects a stereo control to a two flex controller ops
  121. void BuildStereoFlexControllerOps( CDmeAnimationSet *pAnimationSet, CDmeGameModel *pGameModel, CDmeChannelsClip *pChannelsClip, ControlInfo_t &info );
  122. // Attaches existing logs and sets default values for logs
  123. void SetupLogs( CDmeChannelsClip *pChannelsClip, bool bUseExistingLogs );
  124. // Destination flex controllers
  125. CUtlVector< FlexControllerInfo_t > m_FlexControllerInfo;
  126. // Destination controls
  127. CUtlVector< ControlInfo_t > m_ControlInfo;
  128. CDmeFilmClip *m_pMovie;
  129. };
  130. //-----------------------------------------------------------------------------
  131. // Initialize default global flex controller
  132. //-----------------------------------------------------------------------------
  133. void SetupDefaultFlexController();
  134. #endif // FLEXCONTROLBUILDER_H