示例#1
0
void CActionScope::Resume(float forcedBlendTime, uint32 resumeFlags)
{
	if (!m_scopeContext.pCharInst)
	{
		return;
	}

	IAnimationSet* pAnimSet = m_scopeContext.pCharInst->GetIAnimationSet();
	if (!pAnimSet)
	{
		return;
	}

	ISkeletonAnim &skeletonAnimation = *m_scopeContext.pCharInst->GetISkeletonAnim();

	const bool useDefaultBlendTime = (forcedBlendTime < 0);

	for (int i = 0; i < m_numLayers; ++i)
	{
		SSequencer &sequencer = m_layerSequencers[i];

		const int   animationLayer = m_layer + i;
		const float blendTime      = useDefaultBlendTime ? sequencer.blend.duration : forcedBlendTime;

		if (sequencer.savedAnimNormalisedTime < 0)
		{
			skeletonAnimation.StopAnimationInLayer(animationLayer, blendTime);
		}
		else
		{
			const uint32 pos = sequencer.pos - 1;
			if (pos < sequencer.sequence.size())
			{
				SAnimClip &clip   = sequencer.sequence[pos];
				const int  animID = pAnimSet->GetAnimIDByCRC(clip.animation.animRef.crc);
				if (0 <= animID)
				{
					CryCharAnimationParams params;
					InitAnimationParams(clip.animation, i, clip.blend, params);
					const bool installAnimationSuccess = InstallAnimation(animID, params);
					if (installAnimationSuccess)
					{
						const int animationsInLayer = skeletonAnimation.GetNumAnimsInFIFO(animationLayer);
						CRY_ASSERT(1 <= animationsInLayer);

						const bool   loopingAnimation                = ((clip.animation.flags & CA_LOOP_ANIMATION) != 0);
						const uint32 restoreAnimationTimeFlagToCheck = loopingAnimation ? IActionController::ERF_RestoreLoopingAnimationTime : IActionController::ERF_RestoreNonLoopingAnimationTime;
						const bool   restoreAnimationTime            = ((restoreAnimationTimeFlagToCheck & resumeFlags) != 0);
						if (restoreAnimationTime)
						{
							const int   lastAnimationIndex = animationsInLayer - 1;
							CAnimation &animation          = skeletonAnimation.GetAnimFromFIFO(animationLayer, lastAnimationIndex);
							skeletonAnimation.SetAnimationNormalizedTime(&animation, sequencer.savedAnimNormalisedTime);
						}
					}
				}
			}
		}
	}
}
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());
        }
}
示例#3
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;
}
void CAnimActionBlendFromRagdoll::GenerateAnimIDs()
{
	SFragTagState fragTagStateMatch;
	SFragTagState fragTagStateQuery( m_rootScope->GetContext().state.GetMask(), m_fragTagsTarget );
	int32 numOptions = m_rootScope->GetDatabase().FindBestMatchingTag(m_fragmentID, fragTagStateQuery, &fragTagStateMatch);

	IAnimationSet* piAnimSet = m_rootScope->GetEntity().GetCharacter(0)->GetIAnimationSet();

	m_animIds.reserve( numOptions );
	for (int32 i=0; i<numOptions; i++)
	{
		const CFragment *fragment = m_rootScope->GetDatabase().GetEntry(m_fragmentID, fragTagStateMatch, i);

		if( !fragment->m_animLayers.empty() && !fragment->m_animLayers[0].empty() )
		{
			const SAnimClip& animClip = fragment->m_animLayers[0][0];
			const uint animID = piAnimSet->GetAnimIDByCRC(animClip.animation.animRef.crc);
			m_animIds.push_back( animID );
		}
	}
}
//------------------------------------------------------------------------
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;
}
void CAnimationProxyDualCharacterBase::Generate1P3PPairFile()
{
    const int MAX_MODELS = 128;
    ICharacterModel *pCharacterModels[MAX_MODELS];
    int numModels;
    gEnv->pCharacterManager->GetLoadedModels(NULL, numModels);
    numModels = min(numModels, MAX_MODELS);

    gEnv->pCharacterManager->GetLoadedModels(pCharacterModels, numModels);

    s_animCrCHashMap.clear();

    for (uint32 i=0; i<numModels; ++i)
        {
            if (pCharacterModels[i]->GetNumInstances() > 0)
                {
                    IAnimationSet *animSet = pCharacterModels[i]->GetICharInstanceFromModel(0)->GetIAnimationSet();
                    uint32 numAnims = animSet->GetAnimationCount();

                    for (uint32 anm = 0; anm < numAnims; anm++)
                        {
                            uint32 animCRC = animSet->GetCRCByAnimID(anm);
                            if (s_animCrCHashMap.find(animCRC) == s_animCrCHashMap.end())
                                {
                                    int animID3P = -1;
                                    const char *name = animSet->GetNameByAnimID(anm);
                                    if (strlen(name) >= 255)
                                        {
                                            CRY_ASSERT_MESSAGE(0, string().Format("[CAnimationProxyDualCharacterBase::Generate1P3PPairFiles] Animname %s overruns buffer", name));
                                            CryLogAlways("[CAnimationProxyDualCharacterBase::Generate1P3PPairFiles] Animname %s overruns buffer", name);
                                            continue;
                                        }
                                    const char *pos = CryStringUtils::stristr(name, "_1p");
                                    if (pos)
                                        {
                                            char name3P[256];
                                            strcpy(name3P, name);
                                            name3P[(int)(TRUNCATE_PTR)pos + 1 - (int)(TRUNCATE_PTR)name] = '3';
                                            animID3P = animSet->GetAnimIDByName(name3P);

                                            if (animID3P >= 0)
                                                {
                                                    uint32 animCRCTP = animSet->GetCRCByAnimID(animID3P);
                                                    s_animCrCHashMap[animCRC] = animCRCTP;
                                                }
                                        }
                                }
                        }
                }
        }


    //--- Save the file
    CryFixedStringT<256> animCrC;
    XmlNodeRef nodePairList	= gEnv->pSystem->CreateXmlNode( "Pairs" );
    for (NameHashMap::iterator iter = s_animCrCHashMap.begin(); iter != s_animCrCHashMap.end(); ++iter)
        {
            XmlNodeRef nodePair = nodePairList->newChild( "Pair" );
            animCrC.Format("%u", iter->first);
            nodePair->setAttr( "FP", animCrC.c_str());
            animCrC.Format("%u", iter->second);
            nodePair->setAttr( "TP", animCrC.c_str());
        }
    nodePairList->saveToFile(ANIMPAIR_PATHNAME);

    s_animCrCHashMap.clear();
    Load1P3PPairFile();
}