source-engine/game/shared/sequence_Transitioner.cpp

134 lines
3.5 KiB
C++
Raw Normal View History

2023-10-03 14:23:56 +00:00
//========= Copyright <20> 1996-2005, Valve Corporation, All rights reserved. ============//
2020-04-22 16:56:21 +00:00
//
// Purpose:
//
//=============================================================================//
#include "cbase.h"
2023-10-03 14:23:56 +00:00
#include "sequence_transitioner.h"
2020-04-22 16:56:21 +00:00
// memdbgon must be the last include file in a .cpp file!!!
#include "tier0/memdbgon.h"
2023-10-03 14:23:56 +00:00
#include "studio.h"
2020-04-22 16:56:21 +00:00
// -----------------------------------------------------------------------------
// CSequenceTransitioner implementation.
// -----------------------------------------------------------------------------
void CSequenceTransitioner::CheckForSequenceChange(
CStudioHdr *hdr,
int nCurSequence,
bool bForceNewSequence,
bool bInterpolate )
{
// sequence may be set before model is initialized
if ( hdr == NULL)
return;
// FIXME?: this should detect that what's been asked to be drawn isn't what was expected
// due to not only sequence change, by frame index, rate, or whatever. When that happens,
// it should insert the previous rules.
if (m_animationQueue.Count() == 0)
{
m_animationQueue.AddToTail();
2023-10-03 14:23:56 +00:00
#ifdef CLIENT_DLL
m_animationQueue[0].SetOwner( NULL );
#endif
2020-04-22 16:56:21 +00:00
}
CAnimationLayer *currentblend = &m_animationQueue[m_animationQueue.Count()-1];
if (currentblend->m_flLayerAnimtime &&
2023-10-03 14:23:56 +00:00
(currentblend->GetSequence() != nCurSequence || bForceNewSequence ))
2020-04-22 16:56:21 +00:00
{
2023-10-03 14:23:56 +00:00
if ( nCurSequence < 0 || nCurSequence >= hdr->GetNumSeq() )
2020-04-22 16:56:21 +00:00
{
// remove all entries
m_animationQueue.RemoveAll();
}
else
{
2023-10-03 14:23:56 +00:00
mstudioseqdesc_t &seqdesc = hdr->pSeqdesc( nCurSequence );
// sequence changed
if ((seqdesc.flags & STUDIO_SNAP) || !bInterpolate )
{
// remove all entries
m_animationQueue.RemoveAll();
}
else
2020-04-22 16:56:21 +00:00
{
2023-10-03 14:23:56 +00:00
mstudioseqdesc_t &prevseqdesc = hdr->pSeqdesc( currentblend->GetSequence() );
currentblend->m_flLayerFadeOuttime = MIN( prevseqdesc.fadeouttime, seqdesc.fadeintime );
/*
// clip blends to time remaining
if ( !IsSequenceLooping(hdr, currentblend->GetSequence()) )
{
float length = Studio_Duration( hdr, currentblend->GetSequence(), flPoseParameter ) / currentblend->GetPlaybackRate();
float timeLeft = (1.0 - currentblend->GetCycle()) * length;
if (timeLeft < currentblend->m_flLayerFadeOuttime)
currentblend->m_flLayerFadeOuttime = timeLeft;
}
*/
2020-04-22 16:56:21 +00:00
}
}
// push previously set sequence
m_animationQueue.AddToTail();
currentblend = &m_animationQueue[m_animationQueue.Count()-1];
2023-10-03 14:23:56 +00:00
#ifdef CLIENT_DLL
currentblend->SetOwner( NULL );
#endif
2020-04-22 16:56:21 +00:00
}
2023-10-03 14:23:56 +00:00
currentblend->SetSequence( -1 );
2020-04-22 16:56:21 +00:00
currentblend->m_flLayerAnimtime = 0.0;
currentblend->m_flLayerFadeOuttime = 0.0;
}
void CSequenceTransitioner::UpdateCurrent(
CStudioHdr *hdr,
int nCurSequence,
float flCurCycle,
float flCurPlaybackRate,
float flCurTime )
{
// sequence may be set before model is initialized
if ( hdr == NULL)
return;
if (m_animationQueue.Count() == 0)
{
m_animationQueue.AddToTail();
2023-10-03 14:23:56 +00:00
#ifdef CLIENT_DLL
m_animationQueue[0].SetOwner( NULL );
#endif
2020-04-22 16:56:21 +00:00
}
CAnimationLayer *currentblend = &m_animationQueue[m_animationQueue.Count()-1];
// keep track of current sequence
2023-10-03 14:23:56 +00:00
currentblend->SetSequence( nCurSequence );
2020-04-22 16:56:21 +00:00
currentblend->m_flLayerAnimtime = flCurTime;
2023-10-03 14:23:56 +00:00
currentblend->SetCycle( flCurCycle );
currentblend->SetPlaybackRate( flCurPlaybackRate );
2020-04-22 16:56:21 +00:00
// calc blending weights for previous sequences
int i;
for (i = 0; i < m_animationQueue.Count() - 1;)
{
float s = m_animationQueue[i].GetFadeout( flCurTime );
if (s > 0)
{
2023-10-03 14:23:56 +00:00
m_animationQueue[i].SetWeight( s );
2020-04-22 16:56:21 +00:00
i++;
}
else
{
m_animationQueue.Remove( i );
}
}
}