BVB Source Codes

CRYENGINE Show GeomCacheRenderNode.h Source code

Return Download CRYENGINE: download GeomCacheRenderNode.h Source code - Download CRYENGINE Source code - Type:.h
  1. // Copyright 2001-2016 Crytek GmbH / Crytek Group. All rights reserved.
  2.  
  3. // ------------------------------------------------------------------------
  4. //  File name:   GeomCacheRenderNode.h
  5. //  Created:     19/7/2012 by Axel Gneiting
  6. //  Description: Draws geometry caches
  7. // -------------------------------------------------------------------------
  8. //
  9. ////////////////////////////////////////////////////////////////////////////
  10.  
  11. #ifndef _GEOMCACHE_RENDERNODE_
  12. #define _GEOMCACHE_RENDERNODE_
  13.  
  14. #pragma once
  15.  
  16. #if defined(USE_GEOM_CACHES)
  17.  
  18.         #include "GeomCache.h"
  19.         #include "GeomCacheDecoder.h"
  20.  
  21. struct SGeomCacheRenderMeshUpdateContext
  22. {
  23.         SGeomCacheRenderMeshUpdateContext() : m_meshId(0), m_pRenderMesh(NULL),
  24.                 m_pUpdateState(NULL), m_pIndices(NULL) {}
  25.  
  26.         // Information needed to create the render mesh each frame
  27.         uint m_meshId;
  28.  
  29.         // The render mesh
  30.         _smart_ptr<IRenderMesh> m_pRenderMesh;
  31.  
  32.         // Locks the render mesh from rendering until it was filled
  33.         volatile int* m_pUpdateState;
  34.  
  35.         // Previous positions for motion blur
  36.         stl::aligned_vector<Vec3, 16> m_prevPositions;
  37.  
  38.         // Data pointers for updating
  39.         vtx_idx*                      m_pIndices;
  40.         strided_pointer<Vec3>         m_pPositions;
  41.         strided_pointer<UCol>         m_pColors;
  42.         strided_pointer<Vec2>         m_pTexcoords;
  43.         strided_pointer<SPipTangents> m_pTangents;
  44.         strided_pointer<Vec3>         m_pVelocities;
  45. };
  46.  
  47. struct SGeomCacheRenderElementData
  48. {
  49.         CREGeomCache*                            m_pRenderElement;
  50.         volatile int*                            m_pUpdateState;
  51.         int                                      m_threadId;
  52.         DynArray<CREGeomCache::SMeshRenderData>* m_pCurrentFillData;
  53. };
  54.  
  55. class CGeomCacheRenderNode : public IGeomCacheRenderNode, public IGeomCacheListener, public Cry3DEngineBase
  56. {
  57. public:
  58.         CGeomCacheRenderNode();
  59.         virtual ~CGeomCacheRenderNode();
  60.  
  61.         virtual const char* GetName() const final;
  62.         virtual const char* GetEntityClassName() const final;
  63.         virtual EERType     GetRenderNodeType() final { return eERType_GeomCache; }
  64.  
  65.         virtual Vec3        GetPos(bool bWorldOnly) const final;
  66.         virtual void        SetBBox(const AABB& WSBBox) final;
  67.         virtual const AABB  GetBBox() const final;
  68.         virtual void        GetLocalBounds(AABB& bbox) final;
  69.         virtual void        OffsetPosition(const Vec3& delta) final;
  70.  
  71.         // Called before rendering to update to current frame bbox
  72.         void                            UpdateBBox();
  73.  
  74.         virtual void                    Render(const struct SRendParams& entDrawParams, const SRenderingPassInfo& passInfo) final;
  75.  
  76.         void                            SetMatrix(const Matrix34& matrix);
  77.         const Matrix34&                 GetMatrix() const                         { return m_matrix; }
  78.  
  79.         virtual struct IPhysicalEntity* GetPhysics() const final                  { return NULL; }
  80.         virtual void                    SetPhysics(IPhysicalEntity* pPhys)  final {}
  81.  
  82.         virtual void                    SetMaterial(IMaterial* pMat) final;
  83.         virtual IMaterial*              GetMaterial(Vec3* pHitPos) const final;
  84.         virtual IMaterial*              GetMaterialOverride()  final { return m_pMaterial; }
  85.  
  86.         virtual float                   GetMaxViewDist() final;
  87.  
  88.         virtual void                    GetMemoryUsage(ICrySizer* pSizer) const final;
  89.  
  90.         virtual void                    UpdateStreamingPriority(const SUpdateStreamingPriorityContext& streamingContext) final;
  91.  
  92.         // Streaming
  93.         float GetStreamingTime() const { return std::max(m_streamingTime, m_playbackTime); }
  94.  
  95.         // Called for starting the update job in CGeomCacheManager
  96.         void StartAsyncUpdate();
  97.  
  98.         // Called by fill job if it didn't call FillFrameAsync because data wasn't available
  99.         void SkipFrameFill();
  100.  
  101.         // Called from the update job in CGeomCacheManager
  102.         bool FillFrameAsync(const char* const pFloorFrameData, const char* const pCeilFrameData, const float lerpFactor);
  103.  
  104.         // Called from FillFrameAsync
  105.         void UpdateMesh_JobEntry(SGeomCacheRenderMeshUpdateContext* pUpdateContext, SGeomCacheStaticMeshData* pStaticMeshData,
  106.                                  const char* pFloorMeshData, const char* pCeilMeshData, float lerpFactor);
  107.  
  108.         // Called from CGeomCacheManager when playback stops
  109.         void ClearFillData();
  110.  
  111.         // Called from CObjManager to update streaming
  112.         void UpdateStreamableComponents(float fImportance, float fDistance, bool bFullUpdate, int nLod, const float fInvScale, bool bDrawNear);
  113.  
  114.         // IGeomCacheRenderNode
  115.         virtual bool        LoadGeomCache(const char* sGeomCacheFileName) final;
  116.  
  117.         virtual void        SetPlaybackTime(const float time) final;
  118.         virtual float       GetPlaybackTime() const final { return m_playbackTime; }
  119.  
  120.         virtual bool        IsStreaming() const final;
  121.         virtual void        StartStreaming(const float time) final;
  122.         virtual void        StopStreaming() final;
  123.         virtual bool        IsLooping() const final;
  124.         virtual void        SetLooping(const bool bEnable) final;
  125.         virtual float       GetPrecachedTime() const final;
  126.  
  127.         virtual IGeomCache* GetGeomCache() const final { return m_pGeomCache; }
  128.  
  129.         virtual bool        DidBoundsChange() final;
  130.  
  131.         virtual void        SetDrawing(bool bDrawing) final { m_bDrawing = bDrawing; }
  132.  
  133.         // Set stand in CGFs and distance
  134.         virtual void SetStandIn(const char* pFilePath, const char* pMaterial) final;
  135.         virtual void SetFirstFrameStandIn(const char* pFilePath, const char* pMaterial) final;
  136.         virtual void SetLastFrameStandIn(const char* pFilePath, const char* pMaterial) final;
  137.         virtual void SetStandInDistance(const float distance) final;
  138.  
  139.         // Set distance at which cache will start streaming automatically (0 means no auto streaming)
  140.         virtual void SetStreamInDistance(const float distance) final;
  141.  
  142.         virtual void DebugDraw(const SGeometryDebugDrawInfo& info, uint nodeIndex) const final;
  143.         virtual bool RayIntersection(SRayHitInfo& hitInfo, IMaterial* pCustomMtl, uint* pHitNodeIndex) const final;
  144.  
  145.         // Get node information
  146.         virtual uint        GetNodeCount() const final;
  147.         virtual Matrix34    GetNodeTransform(const uint nodeIndex) const final;
  148.         virtual const char* GetNodeName(const uint nodeIndex) const final;
  149.         virtual uint32      GetNodeNameHash(const uint nodeIndex) const final;
  150.         virtual bool        IsNodeDataValid(const uint nodeIndex) const final;
  151.  
  152.         // Physics
  153.         virtual void InitPhysicalEntity(IPhysicalEntity* pPhysicalEntity, const pe_articgeomparams& params) final;
  154.  
  155.         #ifndef _RELEASE
  156.         void DebugRender();
  157.         #endif
  158.  
  159. private:
  160.         void                    CalcBBox();
  161.  
  162.         void                    FillRenderObject(const SRendParams& rendParams, const SRenderingPassInfo& passInfo, IMaterial* pMaterial, CRenderObject* pRenderObject);
  163.  
  164.         bool                    Initialize();
  165.         bool                    InitializeRenderMeshes();
  166.         _smart_ptr<IRenderMesh> SetupDynamicRenderMesh(SGeomCacheRenderMeshUpdateContext& updateContext);
  167.  
  168.         void                    Clear(bool bWaitForStreamingJobs);
  169.  
  170.         void                    InitTransformsRec(uint& currentNodeIndex, const std::vector<SGeomCacheStaticNodeData>& staticNodeData, const QuatTNS& currentTransform);
  171.  
  172.         void                    UpdateTransformsRec(uint& currentNodeIndex, uint& currentMeshIndex, const std::vector<SGeomCacheStaticNodeData>& staticNodeData,
  173.                                                     const std::vector<SGeomCacheStaticMeshData>& staticMeshData, uint& currentNodeDataOffset, const char* const pFloorNodeData,
  174.                                                     const char* const pCeilNodeData, const QuatTNS& currentTransform, const float lerpFactor);
  175.  
  176.         // IGeomCacheListener
  177.         virtual void OnGeomCacheStaticDataLoaded();
  178.         virtual void OnGeomCacheStaticDataUnloaded();
  179.  
  180.         void         DebugDrawRec(const SGeometryDebugDrawInfo& info,
  181.                                   uint& currentNodeIndex, const std::vector<SGeomCacheStaticNodeData>& staticNodeData) const;
  182.         bool         RayIntersectionRec(SRayHitInfo& hitInfo, IMaterial* pCustomMtl, uint* pHitNodeIndex,
  183.                                         uint& currentNodeIndex, const std::vector<SGeomCacheStaticNodeData>& staticNodeData,
  184.                                         SRayHitInfo& hitOut, float& fMinDistance) const;
  185.  
  186.         #ifndef _RELEASE
  187.         void InstancingDebugDrawRec(uint& currentNodeIndex, const std::vector<SGeomCacheStaticNodeData>& staticNodeData);
  188.         #endif
  189.  
  190.         enum EStandInType
  191.         {
  192.                 eStandInType_None,
  193.                 eStandInType_Default,
  194.                 eStandInType_FirstFrame,
  195.                 eStandInType_LastFrame
  196.         };
  197.  
  198.         EStandInType SelectStandIn() const;
  199.         IStatObj*    GetStandIn(const EStandInType type) const;
  200.  
  201.         void         PrecacheStandIn(IStatObj* pStandIn, float fImportance, float fDistance, bool bFullUpdate, int nLod, const float fInvScale, bool bDrawNear);
  202.  
  203.         void         UpdatePhysicalEntity(const pe_articgeomparams* pParams);
  204.         void         UpdatePhysicalMaterials();
  205.  
  206.         // Material ID -> render element data + update state pointer
  207.         typedef std::unordered_map<uint32, SGeomCacheRenderElementData> TRenderElementMap;
  208.         TRenderElementMap m_pRenderElements;
  209.  
  210.         // Saved node transforms for motion blur and attachments
  211.         std::vector<Matrix34> m_nodeMatrices;
  212.  
  213.         // All render meshes
  214.         std::vector<_smart_ptr<IRenderMesh>> m_renderMeshes;
  215.  
  216.         // Update contexts for render meshes
  217.         std::vector<SGeomCacheRenderMeshUpdateContext> m_renderMeshUpdateContexts;
  218.  
  219.         // Override material
  220.         _smart_ptr<IMaterial> m_pMaterial;
  221.  
  222.         // The rendered cache
  223.         _smart_ptr<CGeomCache> m_pGeomCache;
  224.  
  225.         // World space matrix
  226.         Matrix34 m_matrix;
  227.  
  228.         // Playback
  229.         volatile float m_playbackTime;
  230.  
  231.         // Streaming flag
  232.         volatile float m_streamingTime;
  233.  
  234.         // Misc
  235.         IPhysicalEntity* m_pPhysicalEntity;
  236.         float            m_maxViewDist;
  237.  
  238.         // World space bounding box
  239.         AABB m_bBox;
  240.  
  241.         // AABB of current displayed frame and render buffer
  242.         AABB m_currentAABB;
  243.         AABB m_currentDisplayAABB;
  244.  
  245.         // Used for editor debug rendering & ray intersection
  246.         mutable CryCriticalSection m_fillCS;
  247.  
  248.         // Transform ready sync
  249.         mutable CryMutex             m_bTransformsReadyCS;
  250.         mutable CryConditionVariable m_bTransformReadyCV;
  251.  
  252.         // Stand in stat objects
  253.         EStandInType         m_standInVisible;
  254.         _smart_ptr<IStatObj> m_pStandIn;
  255.         _smart_ptr<IStatObj> m_pFirstFrameStandIn;
  256.         _smart_ptr<IStatObj> m_pLastFrameStandIn;
  257.         float                m_standInDistance;
  258.  
  259.         // Distance at which render node will automatically start streaming
  260.         float m_streamInDistance;
  261.  
  262.         // Flags
  263.         volatile bool m_bInitialized;
  264.         bool          m_bLooping;
  265.         volatile bool m_bIsStreaming;
  266.         bool          m_bFilledFrameOnce;
  267.         bool          m_bBoundsChanged;
  268.         bool          m_bDrawing;
  269.         bool          m_bTransformReady;
  270. };
  271.  
  272. #endif
  273. #endif
  274.  
downloadGeomCacheRenderNode.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