Esempio n. 1
0
float CActionScope::CalculateFragmentDuration(const CFragment &fragment) const
{
    IAnimationSet *pAnimSet = m_scopeContext.charInst ? m_scopeContext.charInst->GetIAnimationSet() : NULL;

    float ret = 0.0f;
    if (pAnimSet)
    {
        if (fragment.m_animLayers.size() > 0)
        {
            const TAnimClipSequence &animClipSeq = fragment.m_animLayers[0];

            uint32 numClips = animClipSeq.size();
            float lastDuration = 0.0f;
            for (uint32 i=0; i<numClips; i++)
            {
                const SAnimClip &animClip = animClipSeq[0];

                if (i > 0)
                {
                    if (animClip.blend.exitTime >= 0.0f)
                    {
                        ret += animClip.blend.exitTime;
                    }
                    else
                    {
                        ret += lastDuration;
                    }
                }
                lastDuration = 0.0f;
                if (!animClip.animation.IsEmpty() && !(animClip.animation.flags & CA_LOOP_ANIMATION) && (animClip.animation.playbackSpeed > 0.0f))
                {
                    int animID = pAnimSet->GetAnimIDByCRC(animClip.animation.animRef.crc);
                    if (animID >= 0)
                    {
                        lastDuration = (pAnimSet->GetDuration_sec(animID) / animClip.animation.playbackSpeed);
                    }
                }
            }

            ret += lastDuration;
        }
    }

    return ret;
}
//------------------------------------------------------------------------
bool CReplayActor::GetAdjustedLayerTime(ICharacterInstance* pCharacterInstance, int animId, const CryCharAnimationParams& params, float speedMultiplier, float animTime, float &adjustedLayerTime)
{
	ISkeletonAnim* pSkeletonAnim = pCharacterInstance->GetISkeletonAnim();
	IAnimationSet* pAnimationSet = pCharacterInstance->GetIAnimationSet();
	float duration = pAnimationSet->GetDuration_sec(animId);
	animTime *= params.m_fPlaybackSpeed * speedMultiplier;
	CRY_ASSERT_MESSAGE(animTime >= 0, "Animation time shouldn't be less than 0");

	if (duration > 0.0f)
	{
		if (params.m_nFlags & CA_LOOP_ANIMATION)
		{
			animTime = fmod(animTime, duration);
		}
		else if (params.m_nFlags & CA_REPEAT_LAST_KEY)
		{
			animTime = min(animTime, duration);
		}
		else if (animTime >= duration)
		{
			// Animation has finished don't bother playing it...
			return false;
		}

		adjustedLayerTime = animTime / duration;
	}
	else
	{
		if (!(params.m_nFlags & (CA_LOOP_ANIMATION|CA_REPEAT_LAST_KEY)))
		{
			return false;
		}
		else
		{
			adjustedLayerTime = 0.0f;
		}
	}

	return true;
}