Beispiel #1
0
//------------------------------------------------------------------------
void CItem::PlayAnimationEx(const char* animationName, int slot, int layer, bool loop, float blend, float speed, uint32 flags)
{
	bool start=true;

	ICharacterInstance *pCharacter = GetEntity()->GetCharacter(slot);

	if (!pCharacter && slot==eIGS_FirstPerson && ((m_stats.viewmode&eIVM_FirstPerson)==0))
	{
		start=false;

		int idx = 0;
		if (m_stats.hand == eIH_Right)
			idx = 1;
		else if (m_stats.hand == eIH_Left)
			idx = 2;
		if (m_fpgeometry[idx].name.empty())
			idx = 0;

		pCharacter = m_pItemSystem->GetCachedCharacter(m_fpgeometry[idx].name.c_str());
	}

	if (pCharacter && animationName)
	{
		ISkeletonAnim* pSkeletonAnim = pCharacter->GetISkeletonAnim();

		if (flags&eIPAF_CleanBlending)
		{
			while(pSkeletonAnim->GetNumAnimsInFIFO(layer)>1)
			{
				if (!pSkeletonAnim->RemoveAnimFromFIFO(layer, pSkeletonAnim->GetNumAnimsInFIFO(layer)-1))
					break;
			}
		}

		if (flags&eIPAF_NoBlend)
			blend = 0.0f;

		if (start)
		{
			CryCharAnimationParams params;
			params.m_fTransTime = blend;
			params.m_nLayerID = layer;
			params.m_nFlags = (loop?CA_LOOP_ANIMATION:0)|(flags&eIPAF_RestartAnimation?CA_ALLOW_ANIM_RESTART:0)|(flags&eIPAF_RepeatLastFrame?CA_REPEAT_LAST_KEY:0);
			pSkeletonAnim->StartAnimation(animationName,  params);
			pSkeletonAnim->SetLayerUpdateMultiplier(layer, speed);

			//pCharacter->GetISkeleton()->SetDebugging( true );
		}

		float duration=0.0f;
		int animationId = pCharacter->GetIAnimationSet()->GetAnimIDByName(animationName);
		if (animationId>=0)
			duration = pCharacter->GetIAnimationSet()->GetDuration_sec(animationId);
		
		m_animationTime[slot] = (uint32)(duration*1000.0f/speed);
		m_animationEnd[slot] = (uint32)(gEnv->pTimer->GetCurrTime()*1000.0f)+m_animationTime[slot];
		m_animationSpeed[slot] = speed;
	}
}
void CLipSyncProvider_TransitionQueue::FindMatchingAnim(const AudioControlId audioTriggerId, const ELipSyncMethod lipSyncMethod, ICharacterInstance &character, int* pAnimIdOut, CryCharAnimationParams* pAnimParamsOut) const
{
	CRY_ASSERT(audioTriggerId != INVALID_AUDIO_CONTROL_ID);
	CRY_ASSERT(pAnimIdOut != NULL);
	CRY_ASSERT(pAnimParamsOut != NULL);

	const char* szSoundName = ::GetSoundName(audioTriggerId);
	CRY_ASSERT(szSoundName);

	// Look for an animation matching the sound name exactly

	string               matchingAnimationName = PathUtil::GetFileName(szSoundName);
	const IAnimationSet* pAnimSet              = character.GetIAnimationSet();
	int                  nAnimId               = pAnimSet->GetAnimIDByName(matchingAnimationName.c_str());

	if (nAnimId < 0)
	{
		// First fallback: look for an animation matching the sound name without the index at the end

		int index = static_cast<int>(matchingAnimationName.length()) - 1;
		while ((index >= 0) && isdigit((unsigned char)matchingAnimationName[index]))
		{
			--index;
		}

		if ((index > 0) && (matchingAnimationName[index] == '_'))
		{
			matchingAnimationName = matchingAnimationName.Left(index);

			nAnimId = pAnimSet->GetAnimIDByName(matchingAnimationName.c_str());
		}
	}

	bool isDefaultAnim = false;

	if (nAnimId < 0)
	{
		// Second fallback: when requested use a default lip movement animation

		if (lipSyncMethod == eLSM_MatchAnimationToSoundName)
		{
			nAnimId = pAnimSet->GetAnimIDByName(m_sDefaultAnimName.c_str());
			if (nAnimId < 0)
			{
				CryWarning(VALIDATOR_MODULE_GAME, VALIDATOR_WARNING, "No '%s' default animation found for face '%s'. Automatic lip movement will not work.", m_sDefaultAnimName.c_str(), character.GetFilePath());
			}
			isDefaultAnim = true;
		}
	}

	*pAnimIdOut = nAnimId;
	FillCharAnimationParams(isDefaultAnim, pAnimParamsOut);
}
void CMountedGunController::OnEnter(EntityId mountedGunId)
{
    CRY_ASSERT_MESSAGE(m_pControlledPlayer, "Controlled player not initialized");

    ICharacterInstance* pCharacter = m_pControlledPlayer->IsThirdPerson() ? m_pControlledPlayer->GetEntity()->GetCharacter(0) : m_pControlledPlayer->GetShadowCharacter();
    if (pCharacter)
        {
            CItem* pWeapon = static_cast<CItem*>(g_pGame->GetIGameFramework()->GetIItemSystem()->GetItem(mountedGunId));
            assert(pWeapon);

            IActionController* pActionController = m_pControlledPlayer->GetAnimatedCharacter()->GetActionController();
            if (pActionController && m_pMannequinParams)
                {
                    SAFE_RELEASE(m_pMovementAction);

                    m_pMovementAction = new TPlayerAction(PP_PlayerAction, m_pMannequinParams->fragmentIDs.MotionMounted);
                    m_pMovementAction->AddRef();
                    pActionController->Queue(m_pMovementAction);
                }

            //////////////////////////////////////////////////////////////////////////
            // NOTE: This should go through mannequin
            CRecordingSystem* pRecordingSystem = g_pGame->GetRecordingSystem();
            if (pRecordingSystem)
                {
                    const SParams& pWeaponParams = pWeapon->GetParams();

                    IAnimationSet* pAnimationSet = pCharacter->GetIAnimationSet();
                    const int upAnimId = pAnimationSet->GetAnimIDByName(pWeaponParams.mountedTPAimAnims[MountedTPAimAnim::Up].c_str());
                    const int downAnimId = pAnimationSet->GetAnimIDByName(pWeaponParams.mountedTPAimAnims[MountedTPAimAnim::Down].c_str());

                    pRecordingSystem->OnMountedGunEnter(m_pControlledPlayer, upAnimId, downAnimId);
                }

            //////////////////////////////////////////////////////////////////////////

            IAnimatedCharacter* pAnimatedCharacter = m_pControlledPlayer->GetAnimatedCharacter();
            CRY_ASSERT(pAnimatedCharacter);

            pAnimatedCharacter->RequestPhysicalColliderMode(eColliderMode_Disabled, eColliderModeLayer_Game, "CMountedGunController::OnEnter");
            pAnimatedCharacter->SetNoMovementOverride(true);

            if (gEnv->bMultiplayer)
                pAnimatedCharacter->EnableRigidCollider(0.5f);
            else if (m_pControlledPlayer->IsPlayer())
                pAnimatedCharacter->EnableRigidCollider(1.5f);

            pAnimatedCharacter->GetGroundAlignmentParams().SetFlag(eGA_AllowWithNoCollision, true);

            BATTLECHATTER(BC_WatchMyBack, m_pControlledPlayer->GetEntityId());
        }
}
bool CAnimationProxyDualCharacter::StartAnimationById(IEntity *entity, int animId, const CryCharAnimationParams& Params, float speedMultiplier)
{
    ICharacterInstance* pICharacter = entity->GetCharacter(m_characterMain);
    if (pICharacter)
        {
            ISkeletonAnim* pISkeletonAnim = pICharacter->GetISkeletonAnim();
            ICharacterInstance* pIShadowCharacter = m_firstPersonMode ? entity->GetCharacter(m_characterShadow) : NULL;
            IAnimationSet* pAnimSet = pICharacter->GetIAnimationSet();

            SPlayParams playParams;
            GetPlayParams(animId, speedMultiplier, pAnimSet, playParams);

            bool shadowLocomotion = !(((Params.m_nFlags & CA_DISABLE_MULTILAYER) || (Params.m_nLayerID != 0)) || !m_killMixInFirst);
            bool bAnimStarted = false;
            bool bShouldPlayShadow = true;
            CryCharAnimationParams localParams = Params;
            if (!m_firstPersonMode || !shadowLocomotion)
                {
                    localParams.m_fPlaybackSpeed *= m_firstPersonMode ? playParams.speedFP : playParams.speedTP;
                    bAnimStarted = pISkeletonAnim->StartAnimationById(m_firstPersonMode ? playParams.animIDFP : playParams.animIDTP, localParams);
                    if (bAnimStarted)
                        {
                            pISkeletonAnim->SetLayerBlendWeight(Params.m_nLayerID, 1.0f);
                        }
                    else
                        bShouldPlayShadow = false;
                }

            if (bShouldPlayShadow && pIShadowCharacter != NULL)
                {
                    ISkeletonAnim* pIShadowSkeletonAnim = pIShadowCharacter->GetISkeletonAnim();
                    localParams.m_fPlaybackSpeed = Params.m_fPlaybackSpeed * playParams.speedTP;
                    if (pIShadowSkeletonAnim->StartAnimationById(playParams.animIDTP, localParams))
                        {
                            bAnimStarted = true;

                            pIShadowSkeletonAnim->SetLayerBlendWeight(Params.m_nLayerID, 1.0f);
                        }
                }

            if (bAnimStarted && (Params.m_nLayerID == 0))
                {
                    m_allowsMix = (Params.m_nFlags & CA_DISABLE_MULTILAYER) == 0;
                }

            return bAnimStarted;
        }

    return false;
}
bool CAnimationProxyDualCharacterUpper::StartAnimationById(IEntity *entity, int animId, const CryCharAnimationParams& Params, float speedMultiplier)
{
    ICharacterInstance* pICharacter = entity->GetCharacter(m_characterMain);
    if (pICharacter)
        {
            ISkeletonAnim* pISkeletonAnim = pICharacter->GetISkeletonAnim();
            ICharacterInstance* pIShadowCharacter = m_firstPersonMode ? entity->GetCharacter(m_characterShadow) : NULL;
            IAnimationSet* pAnimSet = pICharacter->GetIAnimationSet();

            SPlayParams playParams;
            GetPlayParams(animId, speedMultiplier, pAnimSet, playParams);

            CryCharAnimationParams localParams = Params;

            bool startedMain = false;
            if (m_firstPersonMode)
                {
                    localParams.m_fPlaybackSpeed *= playParams.speedFP;
                    startedMain = pISkeletonAnim->StartAnimationById(playParams.animIDFP, localParams);
                }
            else
                {
                    localParams.m_fPlaybackSpeed *= playParams.speedTP;
                    startedMain = pISkeletonAnim->StartAnimationById(playParams.animIDTP, localParams);
                }

            if (startedMain)
                {
                    pISkeletonAnim->SetLayerBlendWeight(Params.m_nLayerID, 1.0f);
                }

            if (pIShadowCharacter != NULL && (Params.m_nLayerID != 0))
                {
                    ISkeletonAnim* pIShadowSkeletonAnim = pIShadowCharacter->GetISkeletonAnim();

                    localParams.m_fPlaybackSpeed = Params.m_fPlaybackSpeed * playParams.speedTP;

                    if (pIShadowSkeletonAnim->StartAnimationById(playParams.animIDTP, localParams))
                        {
                            pIShadowSkeletonAnim->SetLayerBlendWeight(Params.m_nLayerID, 1.0f);
                        }
                }

            return startedMain;
        }

    return false;
}
bool CAnimationProxyDualCharacterBase::StartAnimation(IEntity *entity, const char* szAnimName, const CryCharAnimationParams& Params, float speedMultiplier)
{
    ICharacterInstance* pICharacter = entity->GetCharacter(m_characterMain);
    if (pICharacter)
        {
            int animID = pICharacter->GetIAnimationSet()->GetAnimIDByName(szAnimName);

#if !defined(_RELEASE)
            if (g_pGameCVars->g_animatorDebug)
                {
                    static const ColorF col (1.0f, 0.0f, 0.0f, 1.0f);
                    if (animID < 0)
                        {
                            g_pGame->GetIGameFramework()->GetIPersistantDebug()->Add2DText(string().Format("Missing %s", szAnimName).c_str(), 1.0f, col, 10.0f);
                        }
                }
#endif //!defined(_RELEASE)

            return StartAnimationById(entity, animID, Params, speedMultiplier);
        }

    return false;
}