BVB Source Codes

CRYENGINE Show AnimationDatabaseManager.h Source code

Return Download CRYENGINE: download AnimationDatabaseManager.h Source code - Download CRYENGINE Source code - Type:.h
  1. // Copyright 2001-2016 Crytek GmbH / Crytek Group. All rights reserved.
  2.  
  3. //
  4. ////////////////////////////////////////////////////////////////////////////
  5. #ifndef __ANIMATION_DATABASE_MANAGER_H__
  6. #define __ANIMATION_DATABASE_MANAGER_H__
  7.  
  8. #include "AnimationDatabase.h"
  9. #include "ICryMannequinEditor.h"
  10.  
  11. #include <CryCore/Containers/CryListenerSet.h>
  12. #include <CrySystem/File/IResourceManager.h>
  13.  
  14. class CAnimationDatabaseLibrary
  15. {
  16. public:
  17.         typedef const CAnimationDatabase* THandle;
  18.  
  19.         CAnimationDatabaseLibrary();
  20.         ~CAnimationDatabaseLibrary();
  21.  
  22.         void Insert(uint32 nCrc, CAnimationDatabase* pDb);
  23.  
  24. public:
  25.         THandle LoadResource(const char* name, uint32 nFlags);
  26.         THandle TryOpenResource(const char* name, uint32 nFlags);
  27.         void    CreateResource(THandle& hdlOut, const char* name, uint32 nFlags);
  28.         void    PublishResource(THandle& hdlOut);
  29.  
  30. protected:
  31.         typedef std::map<uint32, CAnimationDatabase*> TAnimDatabaseList;
  32.  
  33. protected:
  34.         bool LoadDatabase(const XmlNodeRef& xmlNode, CAnimationDatabase& animDB, bool recursive);
  35.         bool LoadDatabaseDefinitions(const XmlNodeRef& root, const char* filename, const CTagDefinition** ppFragDefs, const CTagDefinition** ppTagDefs);
  36.  
  37.         void LoadDatabaseData
  38.         (
  39.           CAnimationDatabase& animDB,
  40.           const XmlNodeRef root,
  41.           const CTagDefinition& fragIDs,
  42.           const CTagDefinition& tagIDs,
  43.           const TagState& adbFilter,
  44.           bool recursive,
  45.           CAnimationDatabase::SSubADB* subAnimDB = NULL
  46.         );
  47.  
  48.         void AnimEntryToXML(XmlNodeRef outNode, const SAnimationEntry& animEntry, const char* name) const;
  49.         bool XMLToAnimEntry(SAnimationEntry& animEntry, XmlNodeRef root) const;
  50.  
  51.         bool XMLToFragment(CFragment& fragment, XmlNodeRef root, bool transition) const;
  52.         void FragmentToXML(XmlNodeRef outNode, const CFragment* fragment, bool transition) const;
  53.  
  54.         void ProceduralToXml(XmlNodeRef pOutNode, const SProceduralEntry& proceduralEntry) const;
  55.         bool XmlToProcedural(XmlNodeRef pInNode, SProceduralEntry& outProceduralEntry) const;
  56.  
  57.         void XMLToBlend(SAnimBlend& animBlend, XmlNodeRef xmlBlend) const;
  58.         void BlendToXML(XmlNodeRef outNode, const SAnimBlend& animBlend, const char* name) const;
  59.  
  60. private:
  61.         CAnimationDatabaseLibrary(const CAnimationDatabaseLibrary&);
  62.         CAnimationDatabaseLibrary& operator=(const CAnimationDatabaseLibrary&);
  63.  
  64. protected:
  65.         TAnimDatabaseList m_databases;
  66.  
  67.         CTagDefinition    m_animFlags;
  68.         CTagDefinition    m_transitionFlags;
  69. };
  70.  
  71. class CAnimationTagDefLibrary
  72. {
  73. public:
  74.         typedef const CTagDefinition* THandle;
  75.  
  76.         CAnimationTagDefLibrary();
  77.         ~CAnimationTagDefLibrary();
  78.  
  79.         void Insert(uint32 nCrc, CTagDefinition* pDef);
  80.  
  81. public:
  82.         THandle LoadResource(const char* name, uint32 nFlags);
  83.         THandle TryOpenResource(const char* name, uint32 nFlags);
  84.         void    CreateResource(THandle& hdlOut, const char* name, uint32 nFlags);
  85.         void    PublishResource(THandle& hdlOut);
  86.  
  87. protected:
  88.         typedef std::map<uint32, CTagDefinition*> TTagDefList;
  89.  
  90. private:
  91.         CAnimationTagDefLibrary(const CAnimationTagDefLibrary&);
  92.         CAnimationTagDefLibrary& operator=(const CAnimationTagDefLibrary&);
  93.  
  94. protected:
  95.         TTagDefList m_tagDefs;
  96. };
  97.  
  98. class CAnimationControllerDefLibrary
  99. {
  100. public:
  101.         typedef const SControllerDef* THandle;
  102.  
  103.         CAnimationControllerDefLibrary();
  104.         ~CAnimationControllerDefLibrary();
  105.  
  106.         void Insert(uint32 nCrc32, SControllerDef* pDef);
  107.  
  108. public:
  109.         THandle LoadResource(const char* name, uint32 nFlags);
  110.         THandle TryOpenResource(const char* name, uint32 nFlags);
  111.         void    CreateResource(THandle& hdlOut, const char* name, uint32 nFlags);
  112.         void    PublishResource(THandle& hdlOut);
  113.  
  114. protected:
  115.         typedef std::map<uint32, SControllerDef*> TControllerDefList;
  116.  
  117. protected:
  118.         SControllerDef* LoadControllerDef(const XmlNodeRef& xmlNode, const char* context);
  119.  
  120. private:
  121.         CAnimationControllerDefLibrary(const CAnimationControllerDefLibrary&);
  122.         CAnimationControllerDefLibrary& operator=(const CAnimationControllerDefLibrary&);
  123.  
  124. protected:
  125.         TControllerDefList m_controllerDefs;
  126.         CTagDefinition     m_fragmentFlags;
  127. };
  128.  
  129. class CAnimationDatabaseManager
  130.         : public IAnimationDatabaseManager
  131.           , public IMannequinEditorManager
  132.           , protected CAnimationDatabaseLibrary
  133.           , protected CAnimationTagDefLibrary
  134.           , protected CAnimationControllerDefLibrary
  135. {
  136. public:
  137.         CAnimationDatabaseManager();
  138.         ~CAnimationDatabaseManager();
  139.  
  140.         virtual int GetTotalDatabases() const
  141.         {
  142.                 return m_databases.size();
  143.         }
  144.         virtual const IAnimationDatabase* GetDatabase(int idx) const
  145.         {
  146.                 for (TAnimDatabaseList::const_iterator iter = m_databases.begin(); iter != m_databases.end(); ++iter)
  147.                 {
  148.                         if (idx-- == 0)
  149.                         {
  150.                                 return iter->second;
  151.                         }
  152.                 }
  153.                 return NULL;
  154.         }
  155.  
  156.         const IAnimationDatabase* Load(const char* filename);
  157.         const SControllerDef*     LoadControllerDef(const char* filename);
  158.         const CTagDefinition*     LoadTagDefs(const char* filename, bool isTags);
  159.  
  160.         const IAnimationDatabase* FindDatabase(const uint32 crcFilename) const;
  161.  
  162.         const SControllerDef*     FindControllerDef(const uint32 crcFilename) const;
  163.         const SControllerDef*     FindControllerDef(const char* filename) const;
  164.  
  165.         const CTagDefinition*     FindTagDef(const uint32 crcFilename) const;
  166.         const CTagDefinition*     FindTagDef(const char* filename) const;
  167.  
  168.         IAnimationDatabase*       Create(const char* filename, const char* defFilename);
  169.         CTagDefinition*           CreateTagDefinition(const char* filename);
  170.  
  171.         void                      ReloadAll();
  172.         void                      UnloadAll();
  173.  
  174.         // IMannequinEditorManager
  175.         void                    GetAffectedFragmentsString(const CTagDefinition* pQueryTagDef, TagID tagID, char* buffer, int bufferSize);
  176.         void                    ApplyTagDefChanges(const CTagDefinition* pOriginal, CTagDefinition* pModified);
  177.         void                    RenameTag(const CTagDefinition* pOriginal, int32 tagCRC, const char* newName);
  178.         void                    RenameTagGroup(const CTagDefinition* pOriginal, int32 tagGroupCRC, const char* newName);
  179.         void                    GetIncludedTagDefs(const CTagDefinition* pQueriedTagDef, DynArray<CTagDefinition*>& tagDefs) const;
  180.  
  181.         EModifyFragmentIdResult CreateFragmentID(const CTagDefinition& fragmentIds, const char* szFragmentIdName);
  182.         EModifyFragmentIdResult RenameFragmentID(const CTagDefinition& fragmentIds, FragmentID fragmentID, const char* szFragmentIdName);
  183.         EModifyFragmentIdResult DeleteFragmentID(const CTagDefinition& fragmentIds, FragmentID fragmentID);
  184.  
  185.         bool                    SetFragmentTagDef(const CTagDefinition& fragmentIds, FragmentID fragmentID, const CTagDefinition* pFragTagDefs);
  186.  
  187.         void                    SetFragmentDef(const SControllerDef& controllerDef, FragmentID fragmentID, const SFragmentDef& fragmentDef);
  188.  
  189.         void                    SaveDatabasesSnapshot(SSnapshotCollection& snapshotCollection) const;
  190.         void                    LoadDatabasesSnapshot(const SSnapshotCollection& snapshotCollection);
  191.  
  192.         void                    GetLoadedTagDefs(DynArray<const CTagDefinition*>& tagDefs);
  193.         void                    GetLoadedDatabases(DynArray<const IAnimationDatabase*>& animDatabases) const;
  194.         void                    GetLoadedControllerDefs(DynArray<const SControllerDef*>& controllerDefs) const;
  195.  
  196.         void                    SaveAll(IMannequinWriter* pWriter) const;
  197.         void                    RevertDatabase(const char* szFilename);
  198.         void                    RevertControllerDef(const char* szFilename);
  199.         void                    RevertTagDef(const char* szFilename);
  200.  
  201.         bool                    DeleteFragmentEntry(IAnimationDatabase* pDatabase, FragmentID fragmentID, const SFragTagState& tagState, uint32 optionIdx, bool logWarning);
  202.         uint32                  AddFragmentEntry(IAnimationDatabase* pDatabase, FragmentID fragmentID, const SFragTagState& tagState, const CFragment& fragment);
  203.         void                    SetFragmentEntry(IAnimationDatabase* pDatabase, FragmentID fragmentID, const SFragTagState& tagState, uint32 optionIdx, const CFragment& fragment);
  204.  
  205.         bool                    IsFileUsedByControllerDef(const SControllerDef& controllerDef, const char* szFilename) const;
  206.  
  207.         void                    RegisterListener(IMannequinEditorListener* pListener);
  208.         void                    UnregisterListener(IMannequinEditorListener* pListener);
  209.  
  210.         void                    AddSubADBFragmentFilter(IAnimationDatabase* pDatabase, const char* szSubADBFilename, FragmentID fragmentID);
  211.         void                    RemoveSubADBFragmentFilter(IAnimationDatabase* pDatabase, const char* szSubADBFilename, FragmentID fragmentID);
  212.         uint32                  GetSubADBFragmentFilterCount(const IAnimationDatabase* pDatabase, const char* szSubADBFilename) const;
  213.         FragmentID              GetSubADBFragmentFilter(const IAnimationDatabase* pDatabase, const char* szSubADBFilename, uint32 index) const;
  214.  
  215.         void                    SetSubADBTagFilter(IAnimationDatabase* pDatabase, const char* szSubADBFilename, TagState tagState);
  216.         TagState                GetSubADBTagFilter(const IAnimationDatabase* pDatabase, const char* szSubADBFilename) const;
  217.  
  218.         void                    SetBlend(IAnimationDatabase* pDatabase, FragmentID fragmentIDFrom, FragmentID fragmentIDTo, const SFragTagState& tagFrom, const SFragTagState& tagTo, SFragmentBlendUid blendUid, const SFragmentBlend& fragBlend);
  219.         SFragmentBlendUid       AddBlend(IAnimationDatabase* pDatabase, FragmentID fragmentIDFrom, FragmentID fragmentIDTo, const SFragTagState& tagFrom, const SFragTagState& tagTo, const SFragmentBlend& fragBlend);
  220.         void                    DeleteBlend(IAnimationDatabase* pDatabase, FragmentID fragmentIDFrom, FragmentID fragmentIDTo, const SFragTagState& tagFrom, const SFragTagState& tagTo, SFragmentBlendUid blendUid);
  221.         void                    GetFragmentBlends(const IAnimationDatabase* pDatabase, SEditorFragmentBlendID::TEditorFragmentBlendIDArray& outBlendIDs) const;
  222.         void                    GetFragmentBlendVariants(const IAnimationDatabase* pDatabase, const FragmentID fragmentIDFrom, const FragmentID fragmentIDTo, SEditorFragmentBlendVariant::TEditorFragmentBlendVariantArray& outVariants) const;
  223.         void                    GetFragmentBlend(const IAnimationDatabase* pIDatabase, const FragmentID fragmentIDFrom, const FragmentID fragmentIDTo, const SFragTagState& tagFrom, const SFragTagState& tagTo, const SFragmentBlendUid& blendUid, SFragmentBlend& outFragmentBlend) const;
  224.         // ~IMannequinEditorManager
  225.  
  226. private:
  227.         CAnimationDatabaseManager(const CAnimationDatabaseManager&);
  228.         CAnimationDatabaseManager& operator=(const CAnimationDatabaseManager&);
  229.  
  230.         //--- used for saving
  231.         struct SSaveState
  232.         {
  233.                 string m_sFileName;
  234.                 bool   m_bSavedByTags;  // Otherwise saved by ID... tags is higher priority;
  235.  
  236.                 SSaveState() : m_sFileName(), m_bSavedByTags(false) {}
  237.         };
  238.         typedef std::vector<SSaveState> TSaveStateList;
  239.  
  240.         struct SFragmentSaveEntry
  241.         {
  242.                 TSaveStateList vSaveStates;
  243.         };
  244.         typedef std::vector<SFragmentSaveEntry> TFragmentSaveList;
  245.  
  246.         struct SFragmentBlendSaveEntry
  247.         {
  248.                 TSaveStateList vSaveStates;
  249.         };
  250.         typedef std::map<CAnimationDatabase::SFragmentBlendID, SFragmentBlendSaveEntry> TFragmentBlendSaveDatabase;
  251.  
  252.         void       Save(const IAnimationDatabase& iAnimDB, const char* databaseName) const;
  253.  
  254.         XmlNodeRef SaveDatabase
  255.         (
  256.           const CAnimationDatabase& animDB,
  257.           const CAnimationDatabase::SSubADB* subAnimDB,
  258.           const TFragmentSaveList& vFragSaveList,
  259.           const TFragmentBlendSaveDatabase& mBlendSaveDatabase,
  260.           bool flatten = false
  261.         ) const;
  262.  
  263.         void                             ReloadDatabase(IAnimationDatabase* pDatabase);
  264.         void                             RemoveDataFromParent(CAnimationDatabase* parentADB, const CAnimationDatabase::SSubADB* subADB);
  265.         void                             ClearDatabase(CAnimationDatabase* pDatabase);
  266.         void                             Compress(CAnimationDatabase& animDB);
  267.  
  268.         XmlNodeRef                       SaveControllerDef(const SControllerDef& controllerDef) const;
  269.         void                             ReloadControllerDef(SControllerDef* pControllerDef);
  270.         void                             ReloadTagDefinition(CTagDefinition* pTagDefinition);
  271.  
  272.         void                             FindRootSubADB(const CAnimationDatabase& animDB, const CAnimationDatabase::SSubADB* pSubADB, FragmentID fragID, TagState tagState, string& outRootADB) const;
  273.         std::vector<CAnimationDatabase*> FindImpactedDatabases(const CAnimationDatabase* pWorkingDatabase, FragmentID fragId, TagState globalTags) const;
  274.         bool                             HasAncestor(const CAnimationDatabase& database, const string& ancestorName) const;
  275.         bool                             HasAncestor(const CAnimationDatabase::SSubADB& database, const string& ancestorName) const;
  276.  
  277.         void                             PrepareSave(const CAnimationDatabase& animDB, const CAnimationDatabase::SSubADB* subAnimDB, TFragmentSaveList& vFragSaveList, TFragmentBlendSaveDatabase& mBlendSaveDatabase) const;
  278.  
  279.         bool                             FragmentMatches(uint32 fragCRC, const TagState& tagState, const CAnimationDatabase::SSubADB& subAnimDB, bool& bTagMatchFound) const;
  280.         bool                             TransitionMatches(uint32 fragCRCFrom, uint32 fragCRCTo, const TagState& tagStateFrom, const TagState& tagStateTo, const CTagDefinition& parentTagDefs, const CAnimationDatabase::SSubADB& subAnimDB, bool& bTagMatchFound) const;
  281.         bool                             CanSaveFragmentID(FragmentID fragID, const CAnimationDatabase& animDB, const CAnimationDatabase::SSubADB* subAnimDB) const;
  282.         bool                             ShouldSaveFragment(FragmentID fragID, const TagState& tagState, const CAnimationDatabase& animDB, const CAnimationDatabase::SSubADB* subAnimDB, bool& bTagMatchFound) const;
  283.         bool                             ShouldSaveTransition
  284.         (
  285.           FragmentID fragIDFrom,
  286.           FragmentID fragIDTo,
  287.           const TagState& tagStateFrom,
  288.           const TagState& tagStateTo,
  289.           const CAnimationDatabase& animDB,
  290.           const CAnimationDatabase::SSubADB* subAnimDB,
  291.           bool& bTagMatchFound
  292.         ) const;
  293.  
  294.         void RevertSubADB(const char* szFilename, CAnimationDatabase* animDB, const CAnimationDatabase::SSubADB& subADB);
  295.  
  296.         void SaveSubADB
  297.         (
  298.           IMannequinWriter* pWriter,
  299.           const CAnimationDatabase& animationDatabase,
  300.           const CAnimationDatabase::SSubADB& subADB,
  301.           const TFragmentSaveList& vFragSaveList,
  302.           const TFragmentBlendSaveDatabase& mBlendSaveDatabase
  303.         ) const;
  304.  
  305.         void SaveSubADB(const CAnimationDatabase& animDB, const CAnimationDatabase::SSubADB& subAnimDB, const TFragmentSaveList& vFragSaveList, const TFragmentBlendSaveDatabase& mBlendSaveDatabase) const;
  306.  
  307.         void SaveDatabase(IMannequinWriter* pWriter, const IAnimationDatabase* pAnimationDatabase) const;
  308.         void SaveControllerDef(IMannequinWriter* pWriter, const SControllerDef* pControllerDef) const;
  309.         void SaveTagDefinition(IMannequinWriter* pWriter, const CTagDefinition* pTagDefinition) const;
  310.  
  311.         void NotifyListenersTagDefinitionChanged(const CTagDefinition& tagDef);
  312.  
  313.         void ReconcileSubDatabases(const CAnimationDatabase* pSourceDatabase);
  314.         void ReconcileSubDatabase(const CAnimationDatabase* pSourceDatabase, CAnimationDatabase* pTargetSubDatabase);
  315.  
  316. private:
  317.  
  318.         static CAnimationDatabaseManager* s_Instance;
  319.  
  320.         typedef CListenerSet<IMannequinEditorListener*> TEditorListenerSet;
  321.         TEditorListenerSet m_editorListenerSet;
  322. };
  323.  
  324. #endif //__ANIMATION_DATABASE_MANAGER_H__
  325.  
downloadAnimationDatabaseManager.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