IActionController

Main interface into an action controller, managing fragment playback on a specific entity. More...

#include

Public Types

enum EResumeFlags { ERF_RestartAnimations = BIT(0), ERF_RestoreLoopingAnimationTime = BIT(1), ERF_RestoreNonLoopingAnimationTime = BIT(2), ERF_Default = ERF_RestartAnimations | ERF_RestoreLoopingAnimationTime | ERF_RestoreNonLoopingAnimationTime }

Public Member Functions

virtual void OnEvent (const SGameObjectEvent &event)=0
virtual void OnAnimationEvent (ICharacterInstance *pCharacter, const AnimEventInstance &event)=0
virtual void Reset ()=0
virtual void Flush ()=0
virtual uint32 GetTotalScopes () const =0
virtual void SetScopeContext (uint32 scopeContextID, IEntity &entity, ICharacterInstance *pCharacter, const IAnimationDatabase *animDatabase)=0
virtual void ClearScopeContext (uint32 scopeContextID, bool flushAnimations=true)=0
virtual bool IsScopeActive (uint32 scopeID) const =0
virtual ActionScopes GetActiveScopeMask () const =0
virtual IEntity & GetEntity () const =0
virtual EntityId GetEntityId () const =0
virtual IScope * GetScope (uint32 scopeID)=0
virtual const IScope * GetScope (uint32 scopeID) const =0
virtual uint32 GetScopeID (const char *name) const =0
virtual FragmentID GetFragID (uint32 crc) const =0
virtual TagID GetGlobalTagID (uint32 crc) const =0
virtual TagID GetFragTagID (FragmentID fragID, uint32 crc) const =0
virtual const CTagDefinition * GetTagDefinition (FragmentID fragID) const =0
virtual void Queue (IAction &action, float time=-1.0f)=0
virtual void Requeue (IAction &action)=0
virtual void Update (float timePassed)=0
Updates the action controller, should be called by the user each frame for fragments to be played.
virtual SAnimationContext & GetContext ()=0
virtual const SAnimationContext & GetContext () const =0
virtual void Pause ()=0
virtual void Resume (uint32 resumeFlags=ERF_Default)=0
virtual void SetFlag (EActionControllerFlags flag, bool enable)=0
virtual void SetTimeScale (float timeScale)=0
virtual float GetTimeScale () const =0
virtual bool IsActionPending (uint32 userToken) const =0
virtual bool IsDifferent (const FragmentID fragID, const TagState &fragmentTags, const ActionScopes &scopeMask) const =0
virtual bool CanInstall (const IAction &action, const ActionScopes &scopeMask, float timeStep, float &timeTillInstall) const =0
virtual bool QueryDuration (IAction &action, float &fragmentDuration, float &transitionDuration) const =0
virtual void SetSlaveController (IActionController &target, uint32 targetContext, bool enslave, const IAnimationDatabase *piOptionTargetDatabase)=0
virtual void RegisterListener (IMannequinListener *listener)=0
virtual void UnregisterListener (IMannequinListener *listener)=0
virtual class IProceduralContext * FindOrCreateProceduralContext (const CryClassID &contextId)=0
virtual const class IProceduralContext * FindProceduralContext (const CryClassID &contextId) const =0
virtual class IProceduralContext * FindProceduralContext (const CryClassID &contextId)=0
virtual class IProceduralContext * CreateProceduralContext (const CryClassID &contextId)=0
virtual QuatT ExtractLocalAnimLocation (FragmentID fragID, TagState fragTags, uint32 scopeID, uint32 optionIdx)=0
virtual void Release ()=0
virtual const SMannParameter * GetParam (const char *paramName) const =0
virtual const SMannParameter * GetParam (uint32 paramNameCRC) const =0
virtual bool RemoveParam (const char *paramName)=0
virtual bool RemoveParam (uint32 paramNameCRC)=0
virtual void SetParam (const char *paramName, const SMannParameter &param)=0
virtual void SetParam (const SMannParameter &param)=0
virtual void ResetParams ()=0
template
bool GetParam (const char *paramName, PODTYPE &value) const
template
bool GetParam (uint32 paramNameCRC, PODTYPE &value) const
template
void SetParam (const char *paramName, const PODTYPE &value)
template
void SetParam (uint32 paramNameCRC, const PODTYPE &value)

Detailed Description

Main interface into an action controller, managing fragment playback on a specific entity.

Member Function Documentation

◆ OnAnimationEvent()

virtual void IActionController::OnAnimationEvent ( ICharacterInstance * pCharacter,
const AnimEventInstance & event
)
pure virtual

Should be called when the specified character encounters an animation event

#include 
#include 

#include 

class CAnimationEventsComponent final : public IEntityComponent
{
public:
    static void ReflectType(Schematyc::CTypeDesc& desc) { /* Reflect the component GUID in here. */ }

    // Override the ProcessEvent function to receive the callback whenever an animation event is triggered by any character
    virtual void ProcessEvent(const SEntityEvent& event) override
    {
        // Check if this is the animation event
        if (event.event == ENTITY_EVENT_ANIM_EVENT)
        {
            // Retrieve the animation event info from the first parameter
            const AnimEventInstance& animEvent = reinterpret_cast(event.nParam[0]);
            // Retrieve the character that this even occurred on
            ICharacterInstance* pCharacter = reinterpret_cast(event.nParam[1]);
            // Now forward the event to the action controller
            m_pActionController->OnAnimationEvent(pCharacter, animEvent);
        }
    }

    // Subscribe to animation events
    virtual uint64 GetEventMask() const override { return BIT64(ENTITY_EVENT_ANIM_EVENT); }

protected:
    // The action controller we want to forward events to
    IActionController* m_pActionController;
};

◆ Queue()

virtual void IActionController::Queue ( IAction & action,
float time = -1.0f
)
pure virtual

Queues the specified action / fragment for playback

#include 
#include 

// Creates a Mannequin action controller for the specified entity
void QueueFragment(IActionController& actionController, ICharacterInstance& character, IEntity& entity)
{
    // For the sake of this example, load the controller definition from /Animations/Mannequin/MyDatabase.adb
    const char* szAnimationDatabasePath = "Animations/Mannequin/MyDatabase.adb";
    // Assume that we have a scope context named "MyContext", created via the Mannequin Editor
    const char* szScopeContextName = "MyContext";
    // Automatically queue a fragment with name "Idle", assumed to have been created via the Mannequin Editor
    const char* szFragmentName = "Idle";

    // Query the Mannequin interface from the game framework
    IMannequin &mannequin = gEnv->pGameFramework->GetMannequinInterface();
    IAnimationDatabaseManager& databaseManager = mannequin.GetAnimationDatabaseManager();
    const SControllerDef& controllerDefinition = actionController.GetContext().controllerDef;

    // Load the animation database from disk
    const IAnimationDatabase *pAnimationDatabase = databaseManager.Load(szAnimationDatabasePath);

    // Activate the specified context for this entity, and assign it to the specified character instance
    const TagID contextId = controllerDefinition.m_scopeContexts.Find(szScopeContextName);
    actionController.SetScopeContext(contextId, entity, &character, pAnimationDatabase);

    // Query the specified fragment from the controller definition
    const TagID fragmentId = controllerDefinition.m_fragmentIDs.Find(szFragmentName);
    // Create the action with the specified fragment id
    // Note that this should be stored, since _smart_ptr will destroy the action at the end of the scope
    // Ideally this should be destroyed just before the action controller.
    _smart_ptr pFragment = new TAction(0, fragmentId);

    // Queue the fragment to start playing immediately on next update
    actionController.Queue(*pFragment.get());
}