BVB Source Codes

CRYENGINE Show CharacterManager.h Source code

Return Download CRYENGINE: download CharacterManager.h Source code - Download CRYENGINE Source code - Type:.h
  1. // Copyright 2001-2016 Crytek GmbH / Crytek Group. All rights reserved.
  2.  
  3. #pragma once
  4.  
  5. #include <CryAnimation/ICryAnimation.h>
  6. #include "ParamLoader.h"
  7. #include "AttachmentVCloth.h"
  8. #include "CharacterInstanceProcessing.h"
  9.  
  10. class CSkin;              //default skinning
  11. class CAttachmentSKIN;    //skin-instance
  12. class CAttachmentVCLOTH;  //cloth-instance
  13. class CDefaultSkeleton;   //default skeleton
  14. class CCharInstance;      //skel-instance
  15. class CAttachmentManager; //skel-instance
  16. class CClothManager;
  17. class CAttachmentMerger;
  18. class CFacialAnimation;
  19. struct IAnimationSet;
  20. class CPoseModifierSetup;
  21.  
  22. DECLARE_SHARED_POINTERS(CPoseModifierSetup);
  23.  
  24. extern float g_YLine;
  25.  
  26. struct DebugInstances
  27. {
  28.         _smart_ptr<ICharacterInstance> m_pInst;
  29.         QuatTS                         m_GridLocation;
  30.         f32                            m_fExtrapolation;
  31.         ColorF                         m_AmbientColor;
  32. };
  33.  
  34. struct CDefaultSkeletonReferences
  35. {
  36.         CDefaultSkeleton*        m_pDefaultSkeleton;
  37.         DynArray<CCharInstance*> m_RefByInstances;
  38.         CDefaultSkeletonReferences()
  39.         {
  40.                 m_pDefaultSkeleton = 0;
  41.                 m_RefByInstances.reserve(0x10);
  42.         }
  43.         void GetMemoryUsage(ICrySizer* pSizer) const {}
  44. };
  45. struct CDefaultSkinningReferences
  46. {
  47.         CSkin*                       m_pDefaultSkinning;
  48.         DynArray<CAttachmentSKIN*>   m_RefByInstances;
  49.         DynArray<CAttachmentVCLOTH*> m_RefByInstancesVCloth;
  50.         CDefaultSkinningReferences()
  51.         {
  52.                 m_pDefaultSkinning = 0;
  53.                 m_RefByInstances.reserve(0x10);
  54.         }
  55.         void GetMemoryUsage(ICrySizer* pSizer) const {}
  56. };
  57.  
  58. struct CharacterAttachment
  59. {
  60.         CharacterAttachment()
  61.                 : m_relRotation(false)
  62.                 , m_relPosition(false)
  63.                 , m_RelativeDefault(IDENTITY)
  64.                 , m_AbsoluteDefault(IDENTITY)
  65.                 , m_Type(0xDeadBeef)
  66.                 , m_AttFlags(0)
  67.                 , m_ProxyParams(0, 0, 0, 0)
  68.                 , m_ProxyPurpose(0)
  69.         {
  70.                 memset(&m_AttPhysInfo, 0, sizeof(m_AttPhysInfo));
  71.         }
  72.  
  73.         void GetMemoryUsage(ICrySizer* pSizer) const
  74.         {
  75.                 pSizer->AddObject(m_strAttachmentName);
  76.                 pSizer->AddObject(m_strJointName);
  77.                 pSizer->AddObject(m_strBindingPath);
  78.                 pSizer->AddObject(m_pMaterial);
  79.                 pSizer->AddObject(m_parrMaterial);
  80.                 pSizer->AddObject(m_pStaticObject);
  81.         }
  82.  
  83.         string                m_strAttachmentName;
  84.         uint32                m_Type;
  85.         uint32                m_AttFlags;
  86.         string                m_strJointName;
  87.         bool                  m_relRotation;
  88.         bool                  m_relPosition;
  89.         QuatT                 m_RelativeDefault;
  90.         QuatT                 m_AbsoluteDefault;
  91.         Vec4                  m_ProxyParams;
  92.         uint32                m_ProxyPurpose;
  93.  
  94.         SimulationParams      ap;
  95.  
  96.         string                m_strRowJointName;
  97.         RowSimulationParams   rowap;
  98.  
  99.         SVClothParams         clothParams;
  100.  
  101.         string                m_strBindingPath;
  102.         string                m_strSimBindingPath;
  103.         _smart_ptr<IMaterial> m_pMaterial;                         //this is the shared material for all LODs
  104.         _smart_ptr<IMaterial> m_parrMaterial[g_nMaxGeomLodLevels]; //some LODs can have an individual material
  105.         _smart_ptr<IStatObj>  m_pStaticObject;
  106.  
  107.         CryBonePhysics        m_AttPhysInfo[2];
  108. };
  109.  
  110. struct CharacterDefinition
  111. {
  112.         virtual ~CharacterDefinition(){}
  113.         CharacterDefinition()
  114.         {
  115.                 m_nRefCounter = 0;
  116.                 m_nKeepInMemory = 0;
  117.                 m_nKeepModelsInMemory = -1;
  118.         }
  119.  
  120.         virtual void AddRef()
  121.         {
  122.                 ++m_nRefCounter;
  123.         }
  124.  
  125.         void GetMemoryUsage(ICrySizer* pSizer) const
  126.         {
  127.                 pSizer->AddObject(m_strFilePath);
  128.                 pSizer->AddObject(m_strBaseModelFilePath);
  129.                 pSizer->AddObject(m_pBaseModelMaterial);
  130.                 pSizer->AddObject(m_arrAttachments);
  131.         }
  132.  
  133.         string                        m_strFilePath;
  134.         string                        m_strBaseModelFilePath;
  135.         _smart_ptr<IMaterial>         m_pBaseModelMaterial;
  136.         int                           m_nKeepModelsInMemory; // Reference count.
  137.         int                           m_nRefCounter;         // Reference count.
  138.         int                           m_nKeepInMemory;
  139.         DynArray<CharacterAttachment> m_arrAttachments;
  140.         CPoseModifierSetupPtr         m_pPoseModifierSetup;
  141. };
  142.  
  143. //////////////////////////////////////////////////////////////////////
  144. // This class contains a list of character bodies and list of character instances.
  145. // On attempt to create same character second time only new instance will be created.
  146. // Only this class can create actual characters.
  147. class CharacterManager : public ICharacterManager
  148. {
  149. public:
  150.         static bool   s_bPaused;
  151.         static uint32 s_renderFrameIdLocal;
  152.         static uint32 GetRendererThreadId();
  153.         static uint32 GetRendererMainThreadId();
  154.  
  155.         friend class CAnimationManager;
  156.         friend class CAttachmentManager;
  157.         friend class CAttachmentMerger;
  158.         friend class CAttachmentSKIN;
  159.         friend class CAttachmentVCLOTH;
  160.         friend class CClothPiece;
  161.         friend class CCharInstance;
  162.         friend class CDefaultSkeleton;
  163.         friend class CSkin;
  164.         friend class CParamLoader;
  165. #if BLENDSPACE_VISUALIZATION
  166.         friend class CSkeletonAnim;
  167.         friend struct SParametricSamplerInternal;
  168. #endif
  169.  
  170.         CharacterManager();
  171.         ~CharacterManager();
  172.         virtual void Release(); // Deletes itself
  173.  
  174.         virtual void PostInit();
  175.  
  176.         virtual void SyncAllAnimations();
  177.  
  178.         void         ClearPoseModifiersFromSynchQueue();
  179.         void         StopAnimationsOnAllInstances();
  180.  
  181.         /**
  182.          * Stop animations on all instances using the specified animation set.
  183.          */
  184.         void                                        StopAnimationsOnAllInstances(const IAnimationSet& animationSet);
  185.  
  186.         CharacterInstanceProcessing::CContextQueue& GetContextSyncQueue() { return m_ContextSyncQueue; };
  187.  
  188.         void                                        UpdateRendererFrame();
  189.  
  190.         // should be called every frame
  191.         void           Update(bool bPause);
  192.         void           UpdateStreaming(int nFullUpdateRoundId, int nFastUpdateRoundId);
  193.         void           DatabaseUnloading();
  194.  
  195.         CAnimationSet* GetAnimationSetUsedInCharEdit();
  196.  
  197.         void           DummyUpdate(); // can be called instead of Update() for UI purposes (such as in preview viewports, etc).
  198.  
  199.         //////////////////////////////////////////////////////////////////////////
  200.         IFacialAnimation*        GetIFacialAnimation();
  201.         const IFacialAnimation*  GetIFacialAnimation() const;
  202.  
  203.         IAnimEvents*             GetIAnimEvents()            { return &g_AnimationManager; };
  204.         const IAnimEvents*       GetIAnimEvents() const      { return &g_AnimationManager; };
  205.  
  206.         CAnimationManager&       GetAnimationManager()       { return m_AnimationManager; };
  207.         const CAnimationManager& GetAnimationManager() const { return m_AnimationManager; };
  208.  
  209.         CParamLoader&            GetParamLoader()            { return m_ParamLoader; };
  210.  
  211.         CFacialAnimation*        GetFacialAnimation()        { return m_pFacialAnimation; }
  212.         const CFacialAnimation*  GetFacialAnimation() const  { return m_pFacialAnimation; }
  213.  
  214.         const IAttachmentMerger& GetIAttachmentMerger() const;
  215.  
  216.         //a list with model-names that use "ForceSkeletonUpdates"
  217.         std::vector<string>          m_arrSkeletonUpdates;
  218.         std::vector<uint32>          m_arrAnimPlaying;
  219.         std::vector<uint32>          m_arrForceSkeletonUpdates;
  220.         std::vector<uint32>          m_arrVisible;
  221.         uint32                       m_nUpdateCounter;
  222.         uint32                       m_AllowStartOfAnimation;
  223.         uint32                       g_SkeletonUpdates;
  224.         uint32                       g_AnimationUpdates;
  225.  
  226.         IAnimationStreamingListener* m_pStreamingListener;
  227.  
  228.         //methods to handle animation assets
  229.         void SetAnimMemoryTracker(const SAnimMemoryTracker& amt)
  230.         {
  231.                 g_AnimationManager.m_AnimMemoryTracker.m_nMemTracker = amt.m_nMemTracker;
  232.                 g_AnimationManager.m_AnimMemoryTracker.m_nAnimsCurrent = amt.m_nAnimsCurrent;
  233.                 g_AnimationManager.m_AnimMemoryTracker.m_nAnimsMax = amt.m_nAnimsMax;
  234.                 g_AnimationManager.m_AnimMemoryTracker.m_nAnimsAdd = amt.m_nAnimsAdd;
  235.                 g_AnimationManager.m_AnimMemoryTracker.m_nAnimsCounter = amt.m_nAnimsCounter;
  236.         }
  237.         SAnimMemoryTracker GetAnimMemoryTracker() const
  238.         {
  239.                 return g_AnimationManager.m_AnimMemoryTracker;
  240.         }
  241.  
  242.         bool             DBA_PreLoad(const char* filepath, ICharacterManager::EStreamingDBAPriority priority);
  243.         bool             DBA_LockStatus(const char* filepath, uint32 status, ICharacterManager::EStreamingDBAPriority priority);
  244.         bool             DBA_Unload(const char* filepath);
  245.         bool             DBA_Unload_All();
  246.  
  247.         virtual bool     CAF_AddRef(uint32 filePathCRC);
  248.         virtual bool     CAF_IsLoaded(uint32 filePathCRC) const;
  249.         virtual bool     CAF_Release(uint32 filePathCRC);
  250.         virtual bool     CAF_LoadSynchronously(uint32 filePathCRC);
  251.         virtual bool     LMG_LoadSynchronously(uint32 filePathCRC, const IAnimationSet* pAnimationSet);
  252.  
  253.         virtual bool     CAF_AddRefByGlobalId(int globalID);
  254.         virtual bool     CAF_ReleaseByGlobalId(int globalID);
  255.  
  256.         EReloadCAFResult ReloadCAF(const char* szFilePathCAF)
  257.         {
  258.                 return g_AnimationManager.ReloadCAF(szFilePathCAF);
  259.         };
  260.         int ReloadLMG(const char* szFilePathLMG)
  261.         {
  262.                 return g_AnimationManager.ReloadLMG(szFilePathLMG);
  263.         };
  264.  
  265.         CDefaultSkeleton* GetModelByAimPoseID(uint32 nGlobalIDAimPose);
  266.         const char*       GetDBAFilePathByGlobalID(int32 globalID) const;
  267.         virtual void      SetStreamingListener(IAnimationStreamingListener* pListener) { m_pStreamingListener = pListener; };
  268.  
  269.         // light profiler functions
  270.         virtual void                AddFrameTicks(uint64 nTicks)     { m_nFrameTicks += nTicks; }
  271.         virtual void                AddFrameSyncTicks(uint64 nTicks) { m_nFrameSyncTicks += nTicks; }
  272.         virtual void                ResetFrameTicks()                { m_nFrameTicks = 0; m_nFrameSyncTicks = 0; }
  273.         virtual uint64              NumFrameTicks() const            { return m_nFrameTicks; }
  274.         virtual uint64              NumFrameSyncTicks() const        { return m_nFrameSyncTicks; }
  275.         virtual uint32              NumCharacters() const            { return m_nActiveCharactersLastFrame; }
  276.  
  277.         void                        UpdateDatabaseUnloadTimeStamp();
  278.         uint32                      GetDatabaseUnloadTimeDelta() const;
  279.  
  280.         ICharacterInstance*         LoadCharacterDefinition(const string pathname, uint32 nLoadingFlags = 0);
  281.         int32                       LoadCDF(const char* pathname);
  282.         int32                       LoadCDFFromXML(XmlNodeRef root, const char* pathname);
  283.         void                        ReleaseCDF(const char* pathname);
  284.         uint32                      GetCDFId(const string& pathname);
  285.         uint32                      GetOrLoadCDFId(const string& pathname);
  286.         bool                        StreamKeepCDFResident(const char* szFilePath, int nLod, int nRefAdj, bool bUrgent);
  287.         CDefaultSkinningReferences* GetDefaultSkinningReferences(CSkin* pDefaultSkinning);
  288.  
  289. private:
  290.         void UpdateInstances(bool bPause);
  291.  
  292.         uint32 m_StartGAH_Iterator;
  293.         void   LoadAnimationImageFile(const char* filenameCAF, const char* filenameAIM);
  294.         bool   LoadAnimationImageFileCAF(const char* filenameCAF);
  295.         bool   LoadAnimationImageFileAIM(const char* filenameAIM);
  296.         uint32 IsInitializedByIMG() { return m_InitializedByIMG;  };
  297.         uint32 m_InitializedByIMG;
  298.  
  299.         void DumpAssetStatistics();
  300.         f32  GetAverageFrameTime(f32 sec, f32 FrameTime, f32 TimeScale, f32 LastAverageFrameTime);
  301.  
  302.         //methods to manage instances
  303.         virtual ICharacterInstance* CreateInstance(const char* szFilePath, uint32 nLoadingFlags = 0);
  304.         ICharacterInstance*         CreateCGAInstance(const char* szFilePath, uint32 nLoadingFlags = 0);
  305.         ICharacterInstance*         CreateSKELInstance(const char* szFilePath, uint32 nLoadingFlags);
  306.         void                        RegisterInstanceSkel(CDefaultSkeleton* pDefaultSkeleton, CCharInstance* pInstance);
  307.         void                        UnregisterInstanceSkel(CDefaultSkeleton* pDefaultSkeleton, CCharInstance* pInstance);
  308.         void                        RegisterInstanceSkin(CSkin* pDefaultSkinning, CAttachmentSKIN* pInstance);
  309.         void                        UnregisterInstanceSkin(CSkin* pDefaultSkinning, CAttachmentSKIN* pInstance);
  310.         void                        RegisterInstanceVCloth(CSkin* pDefaultSkinning, CAttachmentVCLOTH* pInstance);
  311.         void                        UnregisterInstanceVCloth(CSkin* pDefaultSkinning, CAttachmentVCLOTH* pInstance);
  312.         virtual uint32              GetNumInstancesPerModel(const IDefaultSkeleton& rIDefaultSkeleton) const;
  313.         virtual ICharacterInstance* GetICharInstanceFromModel(const IDefaultSkeleton& rIDefaultSkeleton, uint32 num) const;
  314.         void GetCharacterInstancesSize(class ICrySizer* pSizer) const;
  315.  
  316.         //methods to manage skels and skins
  317.         virtual IDefaultSkeleton* LoadModelSKEL(const char* szFilePath, uint32 nLoadingFlags);
  318.         virtual ISkin*            LoadModelSKIN(const char* szFilePath, uint32 nLoadingFlags);
  319.         CDefaultSkeleton*         FetchModelSKEL(const char* szFilePath, uint32 nLoadingFlags);
  320.         CDefaultSkeleton*         FetchModelSKELForGCA(const char* szFilePath, uint32 nLoadingFlags);
  321.         CSkin*                    FetchModelSKIN(const char* szFilePath, uint32 nLoadingFlags);
  322.         void                      PreloadModelsCDF();
  323.         void                      PreloadModelsCHR();
  324.         void                      PreloadModelsCGA();
  325.         void                      RegisterModelSKEL(CDefaultSkeleton* pModelSKEL, uint32 nLoadingFlags);
  326.         void                      RegisterModelSKIN(CSkin* pModelSKIN, uint32 nLoadingFlags);
  327.         void                      UnregisterModelSKEL(CDefaultSkeleton* pModelSKEL);
  328.         void                      UnregisterModelSKIN(CSkin* pModelSKIN);
  329.         void                      SkelExtension(CCharInstance* pCharInstance, const char* pFilepathSKEL, const uint32 cdfId, const uint32 nLoadingFlags);
  330.         uint32                    CompatibilityTest(CDefaultSkeleton* pDefaultSkeleton, CSkin* pCSkin);
  331.         CDefaultSkeleton*         CheckIfModelSKELLoaded(const string& strFileName, uint32 nLoadingFlags);
  332.         CDefaultSkeleton*         CreateExtendedSkel(CCharInstance* pCharInstance, CDefaultSkeleton* pDefaultSkeleton, uint64 nExtendedCRC64, const std::vector<const char*>& mismatchingSkins, const uint32 nLoadingFlags);
  333. #ifdef EDITOR_PCDEBUGCODE
  334.         virtual void              ClearAllKeepInMemFlags();
  335. #endif
  336.  
  337.         CSkin*            CheckIfModelSKINLoaded(const string& strFileName, uint32 nLoadingFlags);
  338.         CDefaultSkeleton* CheckIfModelExtSKELCreated(const uint64 nCRC64, uint32 nLoadingFlags);
  339.         void              UpdateStreaming_SKEL(std::vector<CDefaultSkeletonReferences>& skels, uint32 nRenderFrameId, const uint32* nRoundIds);
  340.         void              UpdateStreaming_SKIN(std::vector<CDefaultSkinningReferences>& skins, uint32 nRenderFrameId, const uint32* nRoundIds);
  341.  
  342.         virtual bool      LoadAndLockResources(const char* szFilePath, uint32 nLoadingFlags);
  343.         virtual void      StreamKeepCharacterResourcesResident(const char* szFilePath, int nLod, bool bKeep, bool bUrgent = false);
  344.         virtual bool      StreamHasCharacterResources(const char* szFilePath, int nLod);
  345.         virtual void      GetLoadedModels(IDefaultSkeleton** pIDefaultSkeleton, uint32& nCount) const;
  346.         virtual void      ReloadAllModels();
  347.         virtual void      ReloadAllCHRPARAMS();
  348.         virtual void      PreloadLevelModels();
  349.  
  350.         void              GetModelCacheSize() const;
  351.         void              DebugModelCache(uint32 printtxt, std::vector<CDefaultSkeletonReferences>& parrModelCache, std::vector<CDefaultSkinningReferences>& parrModelCacheSKIN);
  352.         virtual void      ClearResources(bool bForceCleanup);      //! Cleans up all resources - currently deletes all bodies and characters (even if there are references on them)
  353.         void              CleanupModelCache(bool bForceCleanup);   // deletes all registered bodies; the character instances got deleted even if they're still referenced
  354.         void              GetStatistics(Statistics& rStats) const; // returns statistics about this instance of character animation manager don't call this too frequently
  355.         void              GetMemoryUsage(ICrySizer* pSizer) const; //puts the size of the whole subsystem into this sizer object, classified, according to the flags set in the sizer
  356.         void              TrackMemoryOfModels();
  357.         std::vector<CDefaultSkeletonReferences> m_arrModelCacheSKEL;
  358.         std::vector<CDefaultSkinningReferences> m_arrModelCacheSKIN;
  359.  
  360. #if BLENDSPACE_VISUALIZATION
  361.         void CreateDebugInstances(const char* szCharacterFileName);
  362.         void DeleteDebugInstances();
  363.         void RenderDebugInstances(const SRenderingPassInfo& passInfo);
  364.         void RenderBlendSpace(const SRenderingPassInfo& passInfo, ICharacterInstance* pCharacterInstance, float fCharacterScale, unsigned int flags);
  365.         bool HasAnyDebugInstancesCreated() const;
  366.         bool HasDebugInstancesCreated(const char* szCharacterFileName) const;
  367.         DynArray<DebugInstances> m_arrCharacterBase;
  368. #endif
  369. #ifdef EDITOR_PCDEBUGCODE
  370.         virtual void GetMotionParameterDetails(SMotionParameterDetails& outDetails, EMotionParamID paramId) const;
  371.         virtual bool InjectCDF(const char* pathname, const char* content, size_t contentLength);
  372.         virtual void ClearCDFCache() { m_arrCacheForCDF.clear(); }  //deactivate the cache in Editor-Mode, or we can't load the same CDF after we changed & saved it
  373.         virtual void InjectCHRPARAMS(const char* pathname, const char* content, size_t contentLength);
  374.         virtual void ClearCHRPARAMSCache();
  375.         virtual void InjectBSPACE(const char* pathname, const char* content, size_t contentLength);
  376.         virtual void ClearBSPACECache();
  377.         std::vector<CDefaultSkeletonReferences> m_arrModelCacheSKEL_CharEdit;
  378.         std::vector<CDefaultSkinningReferences> m_arrModelCacheSKIN_CharEdit;
  379. #endif
  380.  
  381.         /**
  382.          * Stop animations on all instances using the specified animation set.
  383.          * Stop animations on all instances if nullptr is passed.
  384.          */
  385.         void InternalStopAnimationsOnAllInstances(const IAnimationSet* pAnimationSet);
  386.  
  387.         CAnimationManager                          m_AnimationManager;
  388.  
  389.         CFacialAnimation*                          m_pFacialAnimation;
  390.  
  391.         CParamLoader                               m_ParamLoader;
  392.  
  393.         std::vector<f32>                           m_arrFrameTimes;
  394.  
  395.         std::vector<CharacterDefinition>           m_arrCacheForCDF;
  396.  
  397.         CharacterInstanceProcessing::CContextQueue m_ContextSyncQueue;  // queue to remember all animations which were started and need a sync
  398.  
  399.         uint64 m_nFrameTicks;                 // number of ticks spend in animations function during the last frame
  400.         uint64 m_nFrameSyncTicks;             // number of ticks spend in animations sync function during the last frame
  401.         uint32 m_nActiveCharactersLastFrame;  // number of characters for which ForwardKinematics was called
  402.  
  403.         uint32 m_nStreamUpdateRoundId[MAX_STREAM_PREDICTION_ZONES];
  404.  
  405.         uint32 m_lastDatabaseUnloadTimeStamp;
  406.  
  407.         // geometry data cache for VCloth
  408.         SClothGeometry* LoadVClothGeometry(const CAttachmentVCLOTH& pRendAtt, _smart_ptr<IRenderMesh> pRenderMeshes[]);
  409.         typedef std::map<uint64, SClothGeometry> TClothGeomCache;
  410.         TClothGeomCache m_clothGeometries;
  411. };
  412.  
downloadCharacterManager.h Source code - Download CRYENGINE Source code
Related Source Codes/Software:
postal - 2017-06-11
reactide - Reactide is the first dedicated IDE for React web ... 2017-06-11
rkt - rkt is a pod-native container engine for Linux. It... 2017-06-11
uWebSockets - Tiny WebSockets https://for... 2017-06-11
realworld - TodoMVC for the RealWorld - Exemplary fullstack Me... 2017-06-11
CRYENGINE - CRYENGINE is a powerful real-time game development... 2017-06-11
goreplay - GoReplay is an open-source tool for capturing and ... 2017-06-10
pyenv - Simple Python version management 2017-06-10
redux-saga - An alternative side effect model for Redux apps ... 2017-06-10
angular-starter - 2017-06-10

 Back to top