void CMPTrackViewManager::Client_SynchAnimationTimes(const CGameRules::STrackViewParameters& params)
{
	IMovieSystem *pMovieSystem = gEnv->pMovieSystem;

	int numTrackViews = params.m_NumberOfTrackViews + params.m_NumberOfFinishedTrackViews;
	CryLog("CMPTrackViewManager::Client_SynchAnimationTimes() numTrackViews=%d; numFinishedTrackViews=%d", params.m_NumberOfTrackViews, params.m_NumberOfFinishedTrackViews);

	for(int i = 0; i < numTrackViews; ++i)
	{
		int trackviewHashId = params.m_Ids[i];

		if(trackviewHashId == 0)
			continue;

		for(int k = 0; k < pMovieSystem->GetNumSequences(); ++k)
		{
			IAnimSequence* pSequence = pMovieSystem->GetSequence(k); 
			CryHashStringId id(pSequence->GetName());
			if(id == trackviewHashId)
			{
				float timeValue = params.m_Times[i]; // even finished sequences include their time now, to handle aborted sequences
				float currentTimeValue = pMovieSystem->GetPlayingTime(pSequence);
				
				CryLog("CMPTrackViewManager::Client_SynchAnimationTimes() Sequence %d %s at time %f", i, pSequence->GetName(), timeValue);
				if(pMovieSystem->IsPlaying(pSequence))
				{
					// always update finished anims
					if( i>=params.m_NumberOfTrackViews || fabs(currentTimeValue - timeValue) >  s_TrackViewMinTimeDifferenceForSynch) //If we are close enough don't update - avoid unnecessary jerking
					{
						pMovieSystem->SetPlayingTime(pSequence, timeValue);
					}
				}
				else
				{
					pMovieSystem->PlaySequence(pSequence, NULL, true, false, timeValue);

					if(params.m_bInitialData && i>=params.m_NumberOfTrackViews && m_FinishedTrackViewCount < CGameRules::STrackViewParameters::sMaxTrackViews)
					{
						m_FinishedTrackViews[m_FinishedTrackViewCount++] = id.id;
					}
				}

				if (i>=params.m_NumberOfTrackViews)
				{
					// this is a finished trackview, so having setup the correct playtime above, lets actually stop it like it should be
					CryLog("CMPTrackViewManager::Client_SynchAnimationTimes() Sequence %d %s is a finished trackview, stopping it", i, pSequence->GetName());
					pMovieSystem->StopSequence(pSequence);
				}
			}
		}
	}
}
IAnimSequence* CMPTrackViewManager::FindTrackviewSequence(int trackviewId)
{
	IMovieSystem *pMovieSystem = gEnv->pMovieSystem;

	for(int i = 0; i < pMovieSystem->GetNumSequences(); ++i)
	{
		IAnimSequence* pSequence = pMovieSystem->GetSequence(i); 
		CryHashStringId id(pSequence->GetName());
		if(id == trackviewId)
		{
			return pSequence;
		}
	}

	return NULL;
}
void CMPTrackViewManager::Update()
{
#ifndef _RELEASE
	if (g_pGameCVars->g_mptrackview_debug)
	{
		IMovieSystem *pMovieSystem = gEnv->pMovieSystem;

		int numSequences=pMovieSystem->GetNumSequences();

		CryWatch("num finished trackviews=%d", m_FinishedTrackViewCount);
		for (int i=0; i<m_FinishedTrackViewCount; i++)
		{
			const char *foundName="NOT FOUND";

			// SLOW
			IAnimSequence *foundSequence = FindTrackviewSequence(m_FinishedTrackViews[i]);
			if (foundSequence)
			{
				foundName = foundSequence->GetName();
			}

			CryWatch("finished[%d] hash=%x; time=%f; foundName=%s", i, m_FinishedTrackViews[i], m_FinishedTrackViewTimes[i], foundName);
		}

		int numPlaying=pMovieSystem->GetNumPlayingSequences();
		for(int i = 0; i < numPlaying; ++i)
		{
			IAnimSequence* pSequence = pMovieSystem->GetPlayingSequence(i);

			if( pSequence )
			{
				const char *name=pSequence->GetName();
				if (!name)
				{
					name = "[NULL]";
				}
				CryHashStringId hash_id(pSequence->GetName());
				float timeValue = pMovieSystem->GetPlayingTime(pSequence);

				CryWatch("Seq[%d]: name=%s; time=%f; hash=%x", i, name, timeValue, hash_id.id);
			}
		}
	}
#endif
}