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.

135 lines
3.6 KiB

  1. //========= Copyright � 1996-2005, 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. #include "studio.h"
  11. // -----------------------------------------------------------------------------
  12. // CSequenceTransitioner implementation.
  13. // -----------------------------------------------------------------------------
  14. void CSequenceTransitioner::CheckForSequenceChange(
  15. CStudioHdr *hdr,
  16. int nCurSequence,
  17. bool bForceNewSequence,
  18. bool bInterpolate )
  19. {
  20. // sequence may be set before model is initialized
  21. if ( hdr == NULL)
  22. return;
  23. // FIXME?: this should detect that what's been asked to be drawn isn't what was expected
  24. // due to not only sequence change, by frame index, rate, or whatever. When that happens,
  25. // it should insert the previous rules.
  26. if (m_animationQueue.Count() == 0)
  27. {
  28. m_animationQueue.AddToTail();
  29. #ifdef CLIENT_DLL
  30. m_animationQueue[0].SetOwner( NULL );
  31. #endif
  32. }
  33. CAnimationLayer *currentblend = &m_animationQueue[m_animationQueue.Count()-1];
  34. if (currentblend->m_flLayerAnimtime &&
  35. (currentblend->GetSequence() != nCurSequence || bForceNewSequence ))
  36. {
  37. if ( nCurSequence < 0 || nCurSequence >= hdr->GetNumSeq() )
  38. {
  39. // remove all entries
  40. m_animationQueue.RemoveAll();
  41. }
  42. else
  43. {
  44. mstudioseqdesc_t &seqdesc = hdr->pSeqdesc( nCurSequence );
  45. // sequence changed
  46. if ((seqdesc.flags & STUDIO_SNAP) || !bInterpolate )
  47. {
  48. // remove all entries
  49. m_animationQueue.RemoveAll();
  50. }
  51. else
  52. {
  53. mstudioseqdesc_t &prevseqdesc = hdr->pSeqdesc( currentblend->GetSequence() );
  54. currentblend->m_flLayerFadeOuttime = MIN( prevseqdesc.fadeouttime, seqdesc.fadeintime );
  55. /*
  56. // clip blends to time remaining
  57. if ( !IsSequenceLooping(hdr, currentblend->GetSequence()) )
  58. {
  59. float length = Studio_Duration( hdr, currentblend->GetSequence(), flPoseParameter ) / currentblend->GetPlaybackRate();
  60. float timeLeft = (1.0 - currentblend->GetCycle()) * length;
  61. if (timeLeft < currentblend->m_flLayerFadeOuttime)
  62. currentblend->m_flLayerFadeOuttime = timeLeft;
  63. }
  64. */
  65. }
  66. if ( m_animationQueue.Count() > 2 )
  67. m_animationQueue.RemoveMultipleFromHead( 1 );
  68. }
  69. // push previously set sequence
  70. m_animationQueue.AddToTail();
  71. currentblend = &m_animationQueue[m_animationQueue.Count()-1];
  72. #ifdef CLIENT_DLL
  73. currentblend->SetOwner( NULL );
  74. #endif
  75. }
  76. currentblend->SetSequence( -1 );
  77. currentblend->m_flLayerAnimtime = 0.0;
  78. currentblend->m_flLayerFadeOuttime = 0.0;
  79. }
  80. void CSequenceTransitioner::UpdateCurrent(
  81. CStudioHdr *hdr,
  82. int nCurSequence,
  83. float flCurCycle,
  84. float flCurPlaybackRate,
  85. float flCurTime )
  86. {
  87. // sequence may be set before model is initialized
  88. if ( hdr == NULL)
  89. return;
  90. if (m_animationQueue.Count() == 0)
  91. {
  92. m_animationQueue.AddToTail();
  93. #ifdef CLIENT_DLL
  94. m_animationQueue[0].SetOwner( NULL );
  95. #endif
  96. }
  97. CAnimationLayer *currentblend = &m_animationQueue[m_animationQueue.Count()-1];
  98. // keep track of current sequence
  99. currentblend->SetSequence( nCurSequence );
  100. currentblend->m_flLayerAnimtime = flCurTime;
  101. currentblend->SetCycle( flCurCycle );
  102. currentblend->SetPlaybackRate( flCurPlaybackRate );
  103. // calc blending weights for previous sequences
  104. int i;
  105. for (i = 0; i < m_animationQueue.Count() - 1;)
  106. {
  107. float s = m_animationQueue[i].GetFadeout( flCurTime );
  108. if (s > 0)
  109. {
  110. m_animationQueue[i].SetWeight( s );
  111. i++;
  112. }
  113. else
  114. {
  115. m_animationQueue.Remove( i );
  116. }
  117. }
  118. }