BVB Source Codes

CRYENGINE Show CharacterInstanceProcessing.h Source code

Return Download CRYENGINE: download CharacterInstanceProcessing.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 "SkeletonAnim.h"
  7. #include "CharacterInstance.h"
  8.  
  9. class CAttachmentBONE;
  10. class CAttachmentManager;
  11. namespace Memory {
  12. class CPoolFrameLocal;
  13. };
  14.  
  15. namespace CharacterInstanceProcessing
  16. {
  17. static const int kMaxNumberOfCharacterInstanceProcessingContexts = 8192;
  18.  
  19. class CJob
  20. {
  21. public:
  22.         CJob(SContext* pCtx) : m_pCtx(pCtx) {}
  23. public:
  24.  
  25.         void Begin(bool bImmediate);
  26.         void Wait() const;
  27.  
  28.         void Job_Execute();
  29.         void Execute(bool bImmediate);
  30. private:
  31.         SContext*                     m_pCtx;
  32.         mutable JobManager::SJobState m_jobState;
  33. };
  34.  
  35. struct SContext
  36. {
  37.         SContext()
  38.                 : pInstance(nullptr)
  39.                 , pBone(nullptr)
  40.                 , pParent(nullptr)
  41.                 , numChildren(0)
  42.                 , slot(-1)
  43.                 , pCommandBuffer(nullptr)
  44.                 , job(nullptr)
  45.                 , state(EState::Unstarted)
  46.         {
  47.         }
  48.  
  49.         void Initialize(CCharInstance* pInst, const CAttachmentBONE* pBone, const CCharInstance* pParent, int numChildren);
  50.  
  51.         //! Checks if computation of this processing context is currently in progress.
  52.         //! \return True if computation is still in progress. False if computation did not yet start or already finished for the current frame.
  53.         bool IsInProgress() const;
  54.  
  55.         _smart_ptr<CCharInstance> pInstance;
  56.         const CAttachmentBONE*    pBone;
  57.         const CCharInstance*      pParent;
  58.  
  59.         int                       numChildren;
  60.         int                       slot;
  61.  
  62.         Command::CBuffer*         pCommandBuffer;
  63.         CJob                      job;
  64.  
  65.         enum class EState
  66.         {
  67.                 Unstarted,
  68.                 StartAnimationProcessed,
  69.                 JobExecuted,
  70.                 JobSkipped,
  71.                 Finished,
  72.                 Failure
  73.         };
  74.  
  75.         EState state;
  76. };
  77.  
  78. class CContextQueue
  79. {
  80. public:
  81.         CContextQueue() : m_numContexts(0) { ClearContexts(); }
  82.         template<class Function>
  83.         void ExecuteForDirectChildren(int parentIndex, Function f)
  84.         {
  85.                 const int start = parentIndex + 1;
  86.                 const int end = start + m_contexts[parentIndex].numChildren;
  87.                 for (int i = start; i < end; ++i)
  88.                 {
  89.                         auto& ctx = m_contexts[i];
  90.                         ctx.state = f(ctx);
  91.                         i += ctx.numChildren;
  92.                 }
  93.         }
  94.         template<class Function>
  95.         void ExecuteForDirectChildrenWithoutStateChange(int parentIndex, Function f)
  96.         {
  97.                 const int start = parentIndex + 1;
  98.                 const int end = start + m_contexts[parentIndex].numChildren;
  99.                 for (int i = start; i < end; ++i)
  100.                 {
  101.                         auto& ctx = m_contexts[i];
  102.                         f(ctx);
  103.                         i += ctx.numChildren;
  104.                 }
  105.         }
  106.         template<class Function>
  107.         void ExecuteForContextAndAllChildrenRecursively(int parentIndex, Function f)
  108.         {
  109.                 const int start = parentIndex;
  110.                 const int end = start + m_contexts[parentIndex].numChildren + 1;
  111.                 for (int i = start; i < end; ++i)
  112.                 {
  113.                         auto& ctx = m_contexts[i];
  114.                         ctx.state = f(ctx);
  115.                 }
  116.         }
  117.         template<class Function>
  118.         void ExecuteForContext(int index, Function f)
  119.         {
  120.                 auto& ctx = m_contexts[index];
  121.                 ctx.state = f(ctx);
  122.         }
  123.         template<class Function>
  124.         void ExecuteForAll(Function f)
  125.         {
  126.                 const int num = m_numContexts;
  127.                 for (int i = 0; i < num; ++i)
  128.                 {
  129.                         auto& ctx = m_contexts[i];
  130.                         ctx.state = f(ctx);
  131.                 }
  132.         }
  133.         SContext& AppendContext();
  134.         void      ClearContexts();
  135.         int       GetNumberOfContexts() const { return m_numContexts; };
  136.  
  137.         SContext& GetContext(int i)           { return m_contexts[i]; }
  138. private:
  139.         CContextQueue(const CContextQueue& other);      // non construction-copyable
  140.         CContextQueue& operator=(const CContextQueue&); // non copyable
  141.  
  142.         StaticArray<SContext, kMaxNumberOfCharacterInstanceProcessingContexts> m_contexts;
  143.  
  144.         int m_numContexts;
  145. };
  146.  
  147. //////////////////////////////////////////////////////////////////////////////////////////////////
  148. // In the following, these are the different update phases of the character instance processing //
  149. //////////////////////////////////////////////////////////////////////////////////////////////////
  150.  
  151. struct SStartAnimationProcessing
  152. {
  153.         SStartAnimationProcessing() : m_pParams(nullptr) {}
  154.         SStartAnimationProcessing(const SAnimationProcessParams& params) : m_pParams(&params) {}
  155.         SContext::EState operator()(const SContext& ctx);
  156.  
  157. private:
  158.         const SAnimationProcessParams* m_pParams;
  159. };
  160.  
  161. struct SExecuteJob
  162. {
  163.         SContext::EState operator()(const SContext& ctx);
  164. };
  165.  
  166. struct SFinishAnimationComputations
  167. {
  168.         SContext::EState operator()(const SContext& ctx);
  169. };
  170.  
  171. bool                     InitializeMemoryPool();
  172. Memory::CPoolFrameLocal* GetMemoryPool();
  173. }
  174.  
downloadCharacterInstanceProcessing.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