BVB Source Codes

CRYENGINE Show AttachmentManager.h Source code

Return Download CRYENGINE: download AttachmentManager.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 "Vertex/VertexData.h"
  6. #include "Vertex/VertexAnimation.h"
  7. #include "ModelSkin.h"
  8. #include "Skeleton.h"
  9. #include "AttachmentFace.h"
  10. #include "AttachmentBone.h"
  11. #include "AttachmentSkin.h"
  12. #include "AttachmentProxy.h"
  13. #include "AttachmentMerged.h"
  14. #include <CryMath/GeomQuery.h>
  15.  
  16. struct CharacterAttachment;
  17. namespace Command {
  18. class CBuffer;
  19. }
  20.  
  21. class CAttachmentManager : public IAttachmentManager
  22. {
  23.         friend class CAttachmentBONE;
  24.         friend class CAttachmentFACE;
  25.         friend class CAttachmentSKIN;
  26.  
  27. public:
  28.         CAttachmentManager()
  29.         {
  30.                 m_pSkelInstance = NULL;
  31.                 m_nHaveEntityAttachments = 0;
  32.                 m_numRedirectionWithAttachment = 0;
  33.                 m_fZoomDistanceSq = 0;
  34.                 m_arrAttachments.reserve(0x20);
  35.                 m_TypeSortingRequired = 0;
  36.                 m_attachmentMergingRequired = 0;
  37.                 m_nDrawProxies = 0;
  38.                 memset(&m_sortedRanges, 0, sizeof(m_sortedRanges));
  39.                 m_fTurbulenceGlobal = 0;
  40.                 m_fTurbulenceLocal = 0;
  41.                 m_physAttachIds = 1;
  42.         };
  43.  
  44.         uint32        LoadAttachmentList(const char* pathname);
  45.         static uint32 ParseXMLAttachmentList(CharacterAttachment* parrAttachments, uint32 numAttachments, XmlNodeRef nodeAttachements);
  46.         void          InitAttachmentList(const CharacterAttachment* parrAttachments, uint32 numAttachments, const string pathname, uint32 nLoadingFlags, int nKeepModelInMemory);
  47.  
  48.         IAttachment*  CreateAttachment(const char* szName, uint32 type, const char* szJointName = 0, bool bCallProject = true);
  49.  
  50.         void          MergeCharacterAttachments();
  51.         void          RequestMergeCharacterAttachments() { ++m_attachmentMergingRequired; }
  52.  
  53.         int32         GetAttachmentCount() const         { return m_arrAttachments.size(); };
  54.         int32         GetExtraBonesCount() const         { return m_extraBones.size(); }
  55.  
  56.         int32         AddExtraBone(IAttachment* pAttachment);
  57.         void          RemoveExtraBone(IAttachment* pAttachment);
  58.         int32         FindExtraBone(IAttachment* pAttachment);
  59.  
  60.         void          UpdateBindings();
  61.  
  62.         IAttachment*  GetInterfaceByIndex(uint32 c) const;
  63.         IAttachment*  GetInterfaceByName(const char* szName) const;
  64.         IAttachment*  GetInterfaceByNameCRC(uint32 nameCRC) const;
  65.         IAttachment*  GetInterfaceByPhysId(int id) const;
  66.  
  67.         int32         GetIndexByName(const char* szName) const;
  68.         int32         GetIndexByNameCRC(uint32 nameCRC) const;
  69.  
  70.         void          AddEntityAttachment()
  71.         {
  72.                 m_nHaveEntityAttachments++;
  73.         }
  74.         void RemoveEntityAttachment()
  75.         {
  76.                 if (m_nHaveEntityAttachments > 0)
  77.                 {
  78.                         m_nHaveEntityAttachments--;
  79.                 }
  80. #ifndef _RELEASE
  81.                 else
  82.                 {
  83.                         CRY_ASSERT_MESSAGE(0, "Removing too many entity attachments");
  84.                 }
  85. #endif
  86.         }
  87.  
  88.         bool NeedsHierarchicalUpdate();
  89. #ifdef EDITOR_PCDEBUGCODE
  90.         void Verification();
  91. #endif
  92.  
  93.         void UpdateAllRemapTables();
  94.         void PrepareAllRedirectedTransformations(Skeleton::CPoseData& pPoseData);
  95.         void GenerateProxyModelRelativeTransformations(Skeleton::CPoseData& pPoseData);
  96.  
  97.         // Updates all attachment objects except for those labeled "execute".
  98.         // They all are safe to update in the animation job.
  99.         // These updates get skipped if the character is not visible (as a performance optimization).
  100.         void UpdateLocationsExceptExecute(Skeleton::CPoseData& pPoseData);
  101.  
  102.         // for attachment objects labeled "execute", we have to distinguish between attachment
  103.         // objects which are safe to update in the animation job and those who are not (e. g. entities)
  104.         // Updates only "execute" attachment objects which are safe to update in the animation job
  105.         // "execute" attachment objects are always updated (regardless of visibility)
  106.         void           UpdateLocationsExecute(Skeleton::CPoseData& pPoseData);
  107.         // Updates only "execute" attachments which are unsafe to update in the animation job
  108.         void           UpdateLocationsExecuteUnsafe(Skeleton::CPoseData& pPoseData);
  109.  
  110.         void           ProcessAllAttachedObjectsFast();
  111.  
  112.         void           DrawAttachments(SRendParams& rRendParams, const Matrix34& m, const SRenderingPassInfo& passInfo, const f32 fZoomFactor, const f32 fZoomDistanceSq);
  113.         void           DrawMergedAttachments(SRendParams& rRendParams, const Matrix34& m, const SRenderingPassInfo& passInfo, const f32 fZoomFactor, const f32 fZoomDistanceSq);
  114.  
  115.         virtual int32  RemoveAttachmentByInterface(const IAttachment* pAttachment, uint32 loadingFlags = 0);
  116.         virtual int32  RemoveAttachmentByName(const char* szName, uint32 loadingFlags = 0);
  117.         virtual int32  RemoveAttachmentByNameCRC(uint32 nameCrc, uint32 loadingFlags = 0);
  118.         virtual uint32 ProjectAllAttachment();
  119.  
  120.         void           RemoveAttachmentByIndex(uint32 index, uint32 loadingFlags = 0);
  121.         uint32         RemoveAllAttachments();
  122.  
  123.         void           CreateCommands(Command::CBuffer& buffer);
  124.  
  125.         // Attachment Object Binding
  126.         virtual void                ClearAttachmentObject(SAttachmentBase* pAttachment, uint32 nLoadingFlags);
  127.         virtual void                AddAttachmentObject(SAttachmentBase* pAttachment, IAttachmentObject* pModel, ISkin* pISkin = 0, uint32 nLoadingFlags = 0);
  128.         virtual void                SwapAttachmentObject(SAttachmentBase* pAttachment, IAttachment* pNewAttachment);
  129.  
  130.         void                        PhysicalizeAttachment(int idx, int nLod, IPhysicalEntity* pent, const Vec3& offset);
  131.         int                         UpdatePhysicalizedAttachment(int idx, IPhysicalEntity* pent, const QuatT& offset);
  132.         int                         UpdatePhysAttachmentHideState(int idx, IPhysicalEntity* pent, const Vec3& offset);
  133.  
  134.         virtual void                PhysicalizeAttachment(int idx, IPhysicalEntity* pent = 0, int nLod = 0);
  135.         virtual void                DephysicalizeAttachment(int idx, IPhysicalEntity* pent = 0);
  136.  
  137.         void                        OnHideAttachment(const IAttachment* pAttachment, uint32 nHideType, bool bHide);
  138.         void                        Serialize(TSerialize ser);
  139.  
  140.         virtual ICharacterInstance* GetSkelInstance() const;
  141.         ILINE bool                  IsFastUpdateType(IAttachmentObject::EType eAttachmentType) const
  142.         {
  143.                 if (eAttachmentType == IAttachmentObject::eAttachment_Entity)
  144.                         return true;
  145.                 if (eAttachmentType == IAttachmentObject::eAttachment_Effect)
  146.                         return true;
  147.                 return false;
  148.         }
  149.  
  150.         virtual IProxy*     CreateProxy(const char* szName, const char* szJointName);
  151.         virtual int32       GetProxyCount() const { return m_arrProxies.size(); }
  152.  
  153.         virtual IProxy*     GetProxyInterfaceByIndex(uint32 c) const;
  154.         virtual IProxy*     GetProxyInterfaceByName(const char* szName) const;
  155.         virtual IProxy*     GetProxyInterfaceByCRC(uint32 nameCRC) const;
  156.  
  157.         virtual int32       GetProxyIndexByName(const char* szName) const;
  158.         virtual int32       GetProxyIndexByCRC(uint32 nameCRC) const;
  159.  
  160.         virtual int32       RemoveProxyByInterface(const IProxy* ptr);
  161.         virtual int32       RemoveProxyByName(const char* szName);
  162.         virtual int32       RemoveProxyByNameCRC(uint32 nameCRC);
  163.         void                RemoveProxyByIndex(uint32 n);
  164.         virtual void        DrawProxies(uint32 enable) { (enable & 0x80) ? m_nDrawProxies &= enable : m_nDrawProxies |= enable; }
  165.         void                VerifyProxyLinks();
  166.  
  167.         virtual uint32      GetProcFunctionCount() const { return 5; }
  168.         virtual const char* GetProcFunctionName(uint32 idx) const;
  169.         const char*         ExecProcFunction(uint32 nCRC32, Skeleton::CPoseData* pPoseData, const char* pstrFunction = 0) const;
  170.  
  171.         float               GetExtent(EGeomForm eForm);
  172.         void                GetRandomPos(PosNorm& ran, CRndGen& seed, EGeomForm eForm) const;
  173. #if !defined(_RELEASE)
  174.         float               DebugDrawAttachment(IAttachment* pAttachment, ISkin* pSkin, Vec3 drawLoc, IMaterial* pMaterial, float drawScale);
  175. #endif
  176.  
  177. public:
  178.         uint32 m_TypeSortingRequired;
  179.         void         SortByType();
  180.         size_t       SizeOfAllAttachments() const;
  181.         void         GetMemoryUsage(ICrySizer* pSizer) const;
  182.         ILINE uint32 GetMinJointAttachments() const  { return m_sortedRanges[eRange_BoneStatic].begin; }
  183.         ILINE uint32 GetMaxJointAttachments() const  { return m_sortedRanges[eRange_BoneExecute].end; }
  184.         ILINE uint32 GetRedirectedJointCount() const { return m_sortedRanges[eRange_BoneRedirect].GetNumElements(); }
  185.  
  186.         // Generates a context in the Character Manager for each attached instance
  187.         // and returns the number of instance contexts generated
  188.         int GenerateAttachedInstanceContexts();
  189.  
  190.         CGeomExtents                            m_Extents;
  191.         CCharInstance*                          m_pSkelInstance;
  192.         DynArray<_smart_ptr<SAttachmentBase>>   m_arrAttachments;
  193.         DynArray<_smart_ptr<CAttachmentMerged>> m_mergedAttachments;
  194.         DynArray<IAttachment*>                  m_extraBones;
  195.         DynArray<CProxy>                        m_arrProxies;
  196.         uint32 m_nDrawProxies;
  197.         f32    m_fTurbulenceGlobal, m_fTurbulenceLocal;
  198. private:
  199.         class CModificationCommand
  200.         {
  201.         public:
  202.                 CModificationCommand(SAttachmentBase* pAttachment) : m_pAttachment(pAttachment) {}
  203.                 virtual ~CModificationCommand() {}
  204.                 virtual void Execute() = 0;
  205.         protected:
  206.                 _smart_ptr<SAttachmentBase> m_pAttachment;
  207.         };
  208.  
  209.         class CModificationCommandBuffer
  210.         {
  211.         public:
  212.                 static const uint32 kMaxOffsets = 4096;
  213.                 static const uint32 kMaxMemory = 4096;
  214.  
  215.                 CModificationCommandBuffer() { Clear(); }
  216.                 ~CModificationCommandBuffer();
  217.                 void  Execute();
  218.                 template<class T>
  219.                 T*    Alloc() { return static_cast<T*>(Alloc(sizeof(T), alignof(T))); }
  220.         private:
  221.                 void* Alloc(size_t size, size_t align);
  222.                 void  Clear();
  223.                 stl::aligned_vector<char, 32> m_memory;
  224.                 std::vector<uint32>           m_commandOffsets;
  225.         };
  226.  
  227. #define CMD_BUF_PUSH_COMMAND(buf, command, ...) \
  228.   new((buf).Alloc<command>())command(__VA_ARGS__)
  229.  
  230.         f32    m_fZoomDistanceSq;
  231.         uint32 m_nHaveEntityAttachments;
  232.         uint32 m_numRedirectionWithAttachment;
  233.         uint32 m_physAttachIds; // bitmask for used physicalized attachment ids
  234.         uint32 m_attachmentMergingRequired;
  235.  
  236.         struct SRange
  237.         {
  238.                 uint16 begin;
  239.                 uint16 end;
  240.                 uint32 GetNumElements() const { return end - begin; };
  241.         };
  242.  
  243.         // The eRange_BoneExecute and eRange_BoneExecuteUnsafe need to stay next
  244.         // to each other.
  245.         // Generally, the algorithms make some assumptions on the order of
  246.         // the ranges, so it is best not to touch them, currently.
  247.         enum ERange
  248.         {
  249.                 eRange_BoneRedirect,
  250.                 eRange_BoneEmpty,
  251.                 eRange_BoneStatic,
  252.                 eRange_BoneExecute,
  253.                 eRange_BoneExecuteUnsafe,
  254.                 eRange_FaceEmpty,
  255.                 eRange_FaceStatic,
  256.                 eRange_FaceExecute,
  257.                 eRange_FaceExecuteUnsafe,
  258.                 eRange_SkinMesh,
  259.                 eRange_VertexClothOrPendulumRow,
  260.  
  261.                 eRange_COUNT
  262.         };
  263.  
  264.         SRange                     m_sortedRanges[eRange_COUNT];
  265.  
  266.         CModificationCommandBuffer m_modificationCommandBuffer;
  267. };
  268.  
downloadAttachmentManager.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