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.

115 lines
3.1 KiB

  1. //========= Copyright Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose:
  4. //
  5. //=============================================================================//
  6. #include "cbase.h"
  7. #include "sequence_Transitioner.h"
  8. // memdbgon must be the last include file in a .cpp file!!!
  9. #include "tier0/memdbgon.h"
  10. // -----------------------------------------------------------------------------
  11. // CSequenceTransitioner implementation.
  12. // -----------------------------------------------------------------------------
  13. void CSequenceTransitioner::CheckForSequenceChange(
  14. CStudioHdr *hdr,
  15. int nCurSequence,
  16. bool bForceNewSequence,
  17. bool bInterpolate )
  18. {
  19. // sequence may be set before model is initialized
  20. if ( hdr == NULL)
  21. return;
  22. // FIXME?: this should detect that what's been asked to be drawn isn't what was expected
  23. // due to not only sequence change, by frame index, rate, or whatever. When that happens,
  24. // it should insert the previous rules.
  25. if (m_animationQueue.Count() == 0)
  26. {
  27. m_animationQueue.AddToTail();
  28. }
  29. CAnimationLayer *currentblend = &m_animationQueue[m_animationQueue.Count()-1];
  30. if (currentblend->m_flLayerAnimtime &&
  31. (currentblend->m_nSequence != nCurSequence || bForceNewSequence ))
  32. {
  33. mstudioseqdesc_t &seqdesc = hdr->pSeqdesc( nCurSequence );
  34. // sequence changed
  35. if ((seqdesc.flags & STUDIO_SNAP) || !bInterpolate )
  36. {
  37. // remove all entries
  38. m_animationQueue.RemoveAll();
  39. }
  40. else
  41. {
  42. mstudioseqdesc_t &prevseqdesc = hdr->pSeqdesc( currentblend->m_nSequence );
  43. currentblend->m_flLayerFadeOuttime = MIN( prevseqdesc.fadeouttime, seqdesc.fadeintime );
  44. /*
  45. // clip blends to time remaining
  46. if ( !IsSequenceLooping(hdr, currentblend->m_nSequence) )
  47. {
  48. float length = Studio_Duration( hdr, currentblend->m_nSequence, flPoseParameter ) / currentblend->m_flPlaybackRate;
  49. float timeLeft = (1.0 - currentblend->m_flCycle) * length;
  50. if (timeLeft < currentblend->m_flLayerFadeOuttime)
  51. currentblend->m_flLayerFadeOuttime = timeLeft;
  52. }
  53. */
  54. }
  55. // push previously set sequence
  56. m_animationQueue.AddToTail();
  57. currentblend = &m_animationQueue[m_animationQueue.Count()-1];
  58. }
  59. currentblend->m_nSequence = -1;
  60. currentblend->m_flLayerAnimtime = 0.0;
  61. currentblend->m_flLayerFadeOuttime = 0.0;
  62. }
  63. void CSequenceTransitioner::UpdateCurrent(
  64. CStudioHdr *hdr,
  65. int nCurSequence,
  66. float flCurCycle,
  67. float flCurPlaybackRate,
  68. float flCurTime )
  69. {
  70. // sequence may be set before model is initialized
  71. if ( hdr == NULL)
  72. return;
  73. if (m_animationQueue.Count() == 0)
  74. {
  75. m_animationQueue.AddToTail();
  76. }
  77. CAnimationLayer *currentblend = &m_animationQueue[m_animationQueue.Count()-1];
  78. // keep track of current sequence
  79. currentblend->m_nSequence = nCurSequence;
  80. currentblend->m_flLayerAnimtime = flCurTime;
  81. currentblend->m_flCycle = flCurCycle;
  82. currentblend->m_flPlaybackRate = flCurPlaybackRate;
  83. // calc blending weights for previous sequences
  84. int i;
  85. for (i = 0; i < m_animationQueue.Count() - 1;)
  86. {
  87. float s = m_animationQueue[i].GetFadeout( flCurTime );
  88. if (s > 0)
  89. {
  90. m_animationQueue[i].m_flWeight = s;
  91. i++;
  92. }
  93. else
  94. {
  95. m_animationQueue.Remove( i );
  96. }
  97. }
  98. }