BVB Source Codes

CRYENGINE Show ObjectsTree.h Source code

Return Download CRYENGINE: download ObjectsTree.h Source code - Download CRYENGINE Source code - Type:.h
  1. // Copyright 2001-2016 Crytek GmbH / Crytek Group. All rights reserved.
  2.  
  3. #ifndef __INCLUDE_CRY3DENGINE_OBJECTTREE_H
  4. #define __INCLUDE_CRY3DENGINE_OBJECTTREE_H
  5.  
  6. #pragma once
  7.  
  8. #define OCTREENODE_RENDER_FLAG_OBJECTS               1
  9. #define OCTREENODE_RENDER_FLAG_OCCLUDERS             2
  10. #define OCTREENODE_RENDER_FLAG_CASTERS               4
  11. #define OCTREENODE_RENDER_FLAG_OBJECTS_ONLY_ENTITIES 8
  12.  
  13. #define OCTREENODE_CHUNK_VERSION                     5
  14.  
  15. enum ELoadObjectsMode { LOM_LOAD_ALL, LOM_LOAD_ONLY_NON_STREAMABLE, LOM_LOAD_ONLY_STREAMABLE };
  16.  
  17. class CBrush;
  18. class COctreeNode;
  19. template<class T, size_t overAllocBytes> class PodArray;
  20. struct CLightEntity;
  21. struct ILightSource;
  22. struct IParticleEmitter;
  23.  
  24. ///////////////////////////////////////////////////////////////////////////////
  25. // data to be pushed to occlusion culler
  26. struct CRY_ALIGN(16) SCheckOcclusionJobData
  27. {
  28.         enum JobTypeT { QUIT, OCTREE_NODE, TERRAIN_NODE };
  29.  
  30.         SCheckOcclusionJobData()
  31.         {
  32.         }
  33.  
  34.         static SCheckOcclusionJobData CreateQuitJobData();
  35.         static SCheckOcclusionJobData CreateOctreeJobData(COctreeNode * pOctTreeNode, int nRenderMask, const Vec3 &rAmbColor, const SRenderingPassInfo &passInfo);
  36.         static SCheckOcclusionJobData CreateTerrainJobData(CTerrainNode * pTerrainNode, const AABB &rAABB, float fDistance);
  37.  
  38.         JobTypeT type; // type to indicate with which data the union is filled
  39.         union
  40.         {
  41.                 // data for octree nodes
  42.                 struct
  43.                 {
  44.                         COctreeNode* pOctTreeNode;
  45.                         int          nRenderMask;
  46.                         float        vAmbColor[3];
  47.                 } octTreeData;
  48.  
  49.                 // data for terrain nodes
  50.                 struct
  51.                 {
  52.                         CTerrainNode* pTerrainNode;
  53.                         float         vAABBMin[3];
  54.                         float         vAABBMax[3];
  55.                         float         fDistance;
  56.                 } terrainData;
  57.         };
  58.         // common data
  59.         SRendItemSorter rendItemSorter; // ensure order octree traversal oder even with parallel execution
  60.         const CCamera* pCam;            // store camera to handle vis areas correctly
  61. };
  62.  
  63. ///////////////////////////////////////////////////////////////////////////////
  64. inline SCheckOcclusionJobData SCheckOcclusionJobData::CreateQuitJobData()
  65. {
  66.         SCheckOcclusionJobData jobData;
  67.         jobData.type = QUIT;
  68.         return jobData;
  69. }
  70.  
  71. ///////////////////////////////////////////////////////////////////////////////
  72. inline SCheckOcclusionJobData SCheckOcclusionJobData::CreateOctreeJobData(COctreeNode* pOctTreeNode, int nRenderMask, const Vec3& rAmbColor, const SRenderingPassInfo& passInfo)
  73. {
  74.         SCheckOcclusionJobData jobData;
  75.         jobData.type = OCTREE_NODE;
  76.         jobData.octTreeData.pOctTreeNode = pOctTreeNode;
  77.         jobData.octTreeData.nRenderMask = nRenderMask;
  78.         jobData.octTreeData.vAmbColor[0] = rAmbColor.x;
  79.         jobData.octTreeData.vAmbColor[1] = rAmbColor.y;
  80.         jobData.octTreeData.vAmbColor[2] = rAmbColor.z;
  81.         jobData.rendItemSorter = passInfo.GetRendItemSorter();
  82.         jobData.pCam = &passInfo.GetCamera();
  83.         return jobData;
  84. }
  85.  
  86. ///////////////////////////////////////////////////////////////////////////////
  87. inline SCheckOcclusionJobData SCheckOcclusionJobData::CreateTerrainJobData(CTerrainNode* pTerrainNode, const AABB& rAABB, float fDistance)
  88. {
  89.         SCheckOcclusionJobData jobData;
  90.         jobData.type = TERRAIN_NODE;
  91.         jobData.terrainData.pTerrainNode = pTerrainNode;
  92.         jobData.terrainData.vAABBMin[0] = rAABB.min.x;
  93.         jobData.terrainData.vAABBMin[1] = rAABB.min.y;
  94.         jobData.terrainData.vAABBMin[2] = rAABB.min.z;
  95.         jobData.terrainData.vAABBMax[0] = rAABB.max.x;
  96.         jobData.terrainData.vAABBMax[1] = rAABB.max.y;
  97.         jobData.terrainData.vAABBMax[2] = rAABB.max.z;
  98.         jobData.terrainData.fDistance = fDistance;
  99.         return jobData;
  100. }
  101.  
  102. ///////////////////////////////////////////////////////////////////////////////
  103. // data written by occlusion culler jobs, to control main thread 3dengine side rendering
  104. struct CRY_ALIGN(16) SCheckOcclusionOutput
  105. {
  106.         enum JobTypeT { ROAD_DECALS, COMMON, TERRAIN, DEFORMABLE_BRUSH };
  107.  
  108.         static SCheckOcclusionOutput CreateDecalsAndRoadsOutput(IRenderNode * pObj, PodArray<CDLight*>* pAffectingLights, const Vec3 &rAmbColor, const AABB &rObjBox, float fEntDistance, bool bSunOnly, bool bCheckPerObjectOcclusion, const SRenderingPassInfo &passInfo);
  109.         static SCheckOcclusionOutput CreateCommonObjectOutput(IRenderNode * pObj, PodArray<CDLight*>* pAffectingLights, const Vec3 &rAmbColor, const AABB &rObjBox, float fEntDistance, bool bSunOnly, SSectorTextureSet * pTerrainTexInfo, const SRenderingPassInfo &passInfo);
  110.         static SCheckOcclusionOutput CreateTerrainOutput(CTerrainNode * pTerrainNode, const SRenderingPassInfo &passInfo);
  111.         static SCheckOcclusionOutput CreateDeformableBrushOutput(CBrush * pBrush, CRenderObject * pObj, int nLod, const SRenderingPassInfo &passInfo);
  112.  
  113.         JobTypeT type;
  114.         union
  115.         {
  116.                 //VEGETATION,ROAD_DECALS,COMMON Data
  117.                 struct
  118.                 {
  119.                         IRenderNode*        pObj;
  120.                         PodArray<CDLight*>* pAffectingLights;
  121.                         SSectorTextureSet*  pTerrainTexInfo;
  122.                         float               fEntDistance;
  123.                         bool                bSunOnly;
  124.                         bool                bCheckPerObjectOcclusion;
  125.                 } common;
  126.  
  127.                 //TERRAIN Data
  128.                 struct
  129.                 {
  130.                         CTerrainNode* pTerrainNode;
  131.                 } terrain;
  132.  
  133.                 //DEFORMABLE_BRUSH Data
  134.                 struct
  135.                 {
  136.                         CBrush*        pBrush;
  137.                         CRenderObject* pRenderObject;
  138.                         int            nLod;
  139.                 } deformable_brush;
  140.  
  141.                 //BRUSH Data
  142.                 struct
  143.                 {
  144.                         CBrush*        pBrush;
  145.                         CRenderObject* pRenderObject;
  146.                         int16          nLodA;
  147.                         int16          nLodB;
  148.                         uint8          nDissolveRef;
  149.                 } brush;
  150.         };
  151.  
  152.         Vec3 vAmbColor;
  153.         AABB objBox;
  154.         SRendItemSorter rendItemSorter;
  155. };
  156.  
  157. ///////////////////////////////////////////////////////////////////////////////
  158. inline SCheckOcclusionOutput SCheckOcclusionOutput::CreateDecalsAndRoadsOutput(IRenderNode* pObj, PodArray<CDLight*>* pAffectingLights, const Vec3& rAmbColor, const AABB& rObjBox, float fEntDistance, bool bSunOnly, bool bCheckPerObjectOcclusion, const SRenderingPassInfo& passInfo)
  159. {
  160.         SCheckOcclusionOutput outputData;
  161.         outputData.type = ROAD_DECALS;
  162.         outputData.rendItemSorter = passInfo.GetRendItemSorter();
  163.         outputData.vAmbColor = rAmbColor;
  164.         outputData.objBox = rObjBox;
  165.  
  166.         outputData.common.pObj = pObj;
  167.         outputData.common.pAffectingLights = pAffectingLights;
  168.         outputData.common.pTerrainTexInfo = NULL;
  169.         outputData.common.fEntDistance = fEntDistance;
  170.         outputData.common.bSunOnly = bSunOnly;
  171.         outputData.common.bCheckPerObjectOcclusion = bCheckPerObjectOcclusion;
  172.  
  173.         return outputData;
  174. }
  175.  
  176. ///////////////////////////////////////////////////////////////////////////////
  177. inline SCheckOcclusionOutput SCheckOcclusionOutput::CreateCommonObjectOutput(IRenderNode* pObj, PodArray<CDLight*>* pAffectingLights, const Vec3& rAmbColor, const AABB& rObjBox, float fEntDistance, bool bSunOnly, SSectorTextureSet* pTerrainTexInfo, const SRenderingPassInfo& passInfo)
  178. {
  179.         SCheckOcclusionOutput outputData;
  180.         outputData.type = COMMON;
  181.         outputData.rendItemSorter = passInfo.GetRendItemSorter();
  182.         outputData.vAmbColor = rAmbColor;
  183.         outputData.objBox = rObjBox;
  184.  
  185.         outputData.common.pObj = pObj;
  186.         outputData.common.pAffectingLights = pAffectingLights;
  187.         outputData.common.fEntDistance = fEntDistance;
  188.         outputData.common.bSunOnly = bSunOnly;
  189.         outputData.common.pTerrainTexInfo = pTerrainTexInfo;
  190.  
  191.         return outputData;
  192. }
  193.  
  194. ///////////////////////////////////////////////////////////////////////////////
  195. inline SCheckOcclusionOutput SCheckOcclusionOutput::CreateTerrainOutput(CTerrainNode* pTerrainNode, const SRenderingPassInfo& passInfo)
  196. {
  197.         SCheckOcclusionOutput outputData;
  198.         outputData.type = TERRAIN;
  199.         outputData.rendItemSorter = passInfo.GetRendItemSorter();
  200.  
  201.         outputData.terrain.pTerrainNode = pTerrainNode;
  202.  
  203.         return outputData;
  204. }
  205.  
  206. ///////////////////////////////////////////////////////////////////////////////
  207. inline SCheckOcclusionOutput SCheckOcclusionOutput::CreateDeformableBrushOutput(CBrush* pBrush, CRenderObject* pRenderObject, int nLod, const SRenderingPassInfo& passInfo)
  208. {
  209.         SCheckOcclusionOutput outputData;
  210.         outputData.type = DEFORMABLE_BRUSH;
  211.         outputData.rendItemSorter = passInfo.GetRendItemSorter();
  212.  
  213.         outputData.deformable_brush.pBrush = pBrush;
  214.         outputData.deformable_brush.nLod = nLod;
  215.         outputData.deformable_brush.pRenderObject = pRenderObject;
  216.  
  217.         return outputData;
  218. }
  219.  
  220. ///////////////////////////////////////////////////////////////////////////////
  221. enum EOcTeeNodeListType
  222. {
  223.         eMain,
  224.         eCasters,
  225.         eSprites,
  226.         eLights,
  227. };
  228.  
  229. template<class T> struct TDoublyLinkedList
  230. {
  231.         T* m_pFirstNode, * m_pLastNode;
  232.  
  233.         TDoublyLinkedList()
  234.         {
  235.                 m_pFirstNode = m_pLastNode = NULL;
  236.         }
  237.  
  238.         ~TDoublyLinkedList()
  239.         {
  240.                 assert(!m_pFirstNode && !m_pLastNode);
  241.         }
  242.  
  243.         void insertAfter(T* pAfter, T* pObj)
  244.         {
  245.                 pObj->m_pPrev = pAfter;
  246.                 pObj->m_pNext = pAfter->m_pNext;
  247.                 if (pAfter->m_pNext == NULL)
  248.                         m_pLastNode = pObj;
  249.                 else
  250.                         pAfter->m_pNext->m_pPrev = pObj;
  251.                 pAfter->m_pNext = pObj;
  252.         }
  253.  
  254.         void insertBefore(T* pBefore, T* pObj)
  255.         {
  256.                 pObj->m_pPrev = pBefore->m_pPrev;
  257.                 pObj->m_pNext = pBefore;
  258.                 if (pBefore->m_pPrev == NULL)
  259.                         m_pFirstNode = pObj;
  260.                 else
  261.                         pBefore->m_pPrev->m_pNext = pObj;
  262.                 pBefore->m_pPrev = pObj;
  263.         }
  264.  
  265.         void insertBeginning(T* pObj)
  266.         {
  267.                 if (m_pFirstNode == NULL)
  268.                 {
  269.                         m_pFirstNode = pObj;
  270.                         m_pLastNode = pObj;
  271.                         pObj->m_pPrev = NULL;
  272.                         pObj->m_pNext = NULL;
  273.                 }
  274.                 else
  275.                         insertBefore(m_pFirstNode, pObj);
  276.         }
  277.  
  278.         void insertEnd(T* pObj)
  279.         {
  280.                 if (m_pLastNode == NULL)
  281.                         insertBeginning(pObj);
  282.                 else
  283.                         insertAfter(m_pLastNode, pObj);
  284.         }
  285.  
  286.         void remove(T* pObj)
  287.         {
  288.                 if (pObj->m_pPrev == NULL)
  289.                         m_pFirstNode = pObj->m_pNext;
  290.                 else
  291.                         pObj->m_pPrev->m_pNext = pObj->m_pNext;
  292.  
  293.                 if (pObj->m_pNext == NULL)
  294.                         m_pLastNode = pObj->m_pPrev;
  295.                 else
  296.                         pObj->m_pNext->m_pPrev = pObj->m_pPrev;
  297.  
  298.                 pObj->m_pPrev = pObj->m_pNext = NULL;
  299.         }
  300.  
  301.         bool empty() const { return m_pFirstNode == NULL; }
  302. };
  303.  
  304. struct SInstancingInfo
  305. {
  306.         SInstancingInfo() { pStatInstGroup = 0; aabb.Reset(); fMinSpriteDistance = 10000.f; bInstancingInUse = 0; }
  307.         StatInstGroup*                                        pStatInstGroup;
  308.         DynArray<CVegetation*>                                arrInstances;
  309.         stl::aligned_vector<CRenderObject::SInstanceInfo, 16> arrMats;
  310.         stl::aligned_vector<SVegetationSpriteInfo, 16>        arrSprites;
  311.         AABB  aabb;
  312.         float fMinSpriteDistance;
  313.         bool  bInstancingInUse;
  314. };
  315.  
  316. struct SLayerVisibility
  317. {
  318.         const uint8*  pLayerVisibilityMask;
  319.         const uint16* pLayerIdTranslation;
  320. };
  321.  
  322. struct SOctreeLoadObjectsData
  323. {
  324.         COctreeNode*             pNode;
  325.         ptrdiff_t                offset;
  326.         size_t                   size;
  327.         _smart_ptr<IMemoryBlock> pMemBlock;
  328.         byte*                    pObjPtr;
  329.         byte*                    pEndObjPtr;
  330. };
  331.  
  332. class COctreeNode : public IOctreeNode, Cry3DEngineBase, IStreamCallback
  333. {
  334. public:
  335.  
  336.         struct ShadowMapFrustumParams
  337.         {
  338.                 CDLight*                  pLight;
  339.                 struct ShadowMapFrustum*  pFr;
  340.                 PodArray<SPlaneObject>*   pShadowHull;
  341.                 const SRenderingPassInfo* passInfo;
  342.                 Vec3                      vCamPos;
  343.                 uint32                    nRenderNodeFlags;
  344.                 bool                      bSun;
  345.         };
  346.  
  347.         ~COctreeNode();
  348.         void                ResetStaticInstancing();
  349.         bool                HasChildNodes();
  350.         int                 CountChildNodes();
  351.         void                InsertObject(IRenderNode* pObj, const AABB& objBox, const float fObjRadiusSqr, const Vec3& vObjCenter);
  352.         bool                DeleteObject(IRenderNode* pObj);
  353.         void                Render_Object_Nodes(bool bNodeCompletelyInFrustum, int nRenderMask, const Vec3& vAmbColor, const SRenderingPassInfo& passInfo);
  354.         void                CheckUpdateStaticInstancing();
  355.         void                RenderDebug();
  356.         static void         DeallocateRenderContentQueue();
  357.         void                RenderContent(int nRenderMask, const Vec3& vAmbColor, const SRenderingPassInfo& passInfo);
  358.         void                RenderContentJobEntry(int nRenderMask, Vec3 vAmbColor, SRenderingPassInfo passInfo);
  359.         void                RenderVegetations(TDoublyLinkedList<IRenderNode>* lstObjects, int nRenderMask, bool bNodeCompletelyInFrustum, PodArray<CDLight*>* pAffectingLights, bool bSunOnly, SSectorTextureSet* pTerrainTexInfo, const SRenderingPassInfo& passInfo);
  360.         void                RenderCommonObjects(TDoublyLinkedList<IRenderNode>* lstObjects, int nRenderMask, const Vec3& vAmbColor, bool bNodeCompletelyInFrustum, PodArray<CDLight*>* pAffectingLights, bool bSunOnly, SSectorTextureSet* pTerrainTexInfo, const SRenderingPassInfo& passInfo);
  361.         void                RenderDecalsAndRoads(TDoublyLinkedList<IRenderNode>* lstObjects, int nRenderMask, const Vec3& vAmbColor, bool bNodeCompletelyInFrustum, PodArray<CDLight*>* pAffectingLights, bool bSunOnly, const SRenderingPassInfo& passInfo);
  362.         void                RenderBrushes(TDoublyLinkedList<IRenderNode>* lstObjects, bool bNodeCompletelyInFrustum, PodArray<CDLight*>* pAffectingLights, bool bSunOnly, SSectorTextureSet* pTerrainTexInfo, const SRenderingPassInfo& passInfo);
  363.         PodArray<CDLight*>* GetAffectingLights(const SRenderingPassInfo& passInfo);
  364.         void                AddLightSource(CDLight* pSource, const SRenderingPassInfo& passInfo);
  365.         void                CheckInitAffectingLights(const SRenderingPassInfo& passInfo);
  366.         void                FillShadowCastersList(bool bNodeCompletellyInFrustum, CDLight* pLight, struct ShadowMapFrustum* pFr, PodArray<SPlaneObject>* pShadowHull, uint32 nRenderNodeFlags, const SRenderingPassInfo& passInfo);
  367.         void                FillShadowMapCastersList(const ShadowMapFrustumParams& params, bool bNodeCompletellyInFrustum);
  368.         void                ActivateObjectsLayer(uint16 nLayerId, bool bActivate, bool bPhys, IGeneralMemoryHeap* pHeap, const AABB& layerBox);
  369.         void                GetLayerMemoryUsage(uint16 nLayerId, ICrySizer* pSizer, int* pNumBrushes, int* pNumDecals);
  370.  
  371.         void                MarkAsUncompiled(const IRenderNode* pRenderNode = NULL);
  372.         COctreeNode*        FindNodeContainingBox(const AABB& objBox);
  373.         void                MoveObjectsIntoList(PodArray<SRNInfo>* plstResultEntities, const AABB* pAreaBox, bool bRemoveObjects = false, bool bSkipDecals = false, bool bSkip_ERF_NO_DECALNODE_DECALS = false, bool bSkipDynamicObjects = false, EERType eRNType = eERType_TypesNum);
  374.         int                 PhysicalizeInBox(const AABB& bbox);
  375.         int                 DephysicalizeInBox(const AABB& bbox);
  376.         int                 PhysicalizeOfType(ERNListType listType, bool bInstant);
  377.         int                 DePhysicalizeOfType(ERNListType listType, bool bInstant);
  378.  
  379. #if ENGINE_ENABLE_COMPILATION
  380.         int GetData(byte*& pData, int& nDataSize, std::vector<IStatObj*>* pStatObjTable, std::vector<IMaterial*>* pMatTable, std::vector<IStatInstGroup*>* pStatInstGroupTable, EEndian eEndian, SHotUpdateInfo* pExportInfo, const Vec3& segmentOffset);
  381. #endif
  382.  
  383.         const AABB&  GetObjectsBBox() { return m_objectsBox; }
  384.         AABB         GetShadowCastersBox(const AABB* pBBox, const Matrix34* pShadowSpaceTransform);
  385.         void         DeleteObjectsByFlag(int nRndFlag);
  386.         void         UnregisterEngineObjectsInArea(const SHotUpdateInfo* pExportInfo, PodArray<IRenderNode*>& arrUnregisteredObjects, bool bOnlyEngineObjects);
  387.         uint32       GetLastVisFrameId() { return m_nLastVisFrameId; }
  388.         void         GetObjectsByType(PodArray<IRenderNode*>& lstObjects, EERType objType, const AABB* pBBox, bool* pInstStreamCheckReady = NULL, uint64 dwFlags = ~0);
  389.         void         GetObjectsByFlags(uint dwFlags, PodArray<IRenderNode*>& lstObjects);
  390.  
  391.         void         GetNearestCubeProbe(float& fMinDistance, int& nMaxPriority, CLightEntity*& pNearestLight, const AABB* pBBox);
  392.         void         GetObjects(PodArray<IRenderNode*>& lstObjects, const AABB* pBBox);
  393.         bool         GetShadowCastersTimeSliced(IRenderNode* pIgnoreNode, ShadowMapFrustum* pFrustum, const PodArray<struct SPlaneObject>* pShadowHull, int renderNodeExcludeFlags, int& totalRemainingNodes, int nCurLevel, const SRenderingPassInfo& passInfo);
  394.         bool         IsObjectTypeInTheBox(EERType objType, const AABB& WSBBox);
  395.         bool         CleanUpTree();
  396.         int          GetObjectsCount(EOcTeeNodeListType eListType);
  397.         static int32 SaveObjects_CompareRenderNodes(const void* v1, const void* v2);
  398.         int SaveObjects(class CMemoryBlock* pMemBlock, std::vector<IStatObj*>* pStatObjTable, std::vector<IMaterial*>* pMatTable, std::vector<IStatInstGroup*>* pStatInstGroupTable, EEndian eEndian, const SHotUpdateInfo * pExportInfo, const Vec3 &segmentOffest);
  399.         int          LoadObjects(byte* pPtr, byte* pEndPtr, std::vector<IStatObj*>* pStatObjTable, std::vector<IMaterial*>* pMatTable, EEndian eEndian, int nChunkVersion, const SLayerVisibility* pLayerVisibility, const Vec3& segmentOffest, ELoadObjectsMode eLoadMode);
  400.         static int   GetSingleObjectFileDataSize(IRenderNode* pObj, const SHotUpdateInfo* pExportInfo);
  401.         static void  SaveSingleObject(byte*& pPtr, int& nDatanSize, IRenderNode* pObj, std::vector<IStatObj*>* pStatObjTable, std::vector<IMaterial*>* pMatTable, std::vector<IStatInstGroup*>* pStatInstGroupTable, EEndian eEndian, const SHotUpdateInfo* pExportInfo, const Vec3& segmentOffset);
  402.         static void  LoadSingleObject(byte*& pPtr, std::vector<IStatObj*>* pStatObjTable, std::vector<IMaterial*>* pMatTable, EEndian eEndian, int nChunkVersion, const SLayerVisibility* pLayerVisibility, int nSID, const Vec3& segmentOffset, ELoadObjectsMode eLoadMode, IRenderNode*& pRN);
  403.         static bool  IsObjectStreamable(EERType eType, uint64 dwRndFlags);
  404.         static bool  CheckSkipLoadObject(EERType eType, uint64 dwRndFlags, ELoadObjectsMode eLoadMode);
  405.         bool         IsRightNode(const AABB& objBox, const float fObjRadius, float fObjMaxViewDist);
  406.         void         GetMemoryUsage(ICrySizer* pSizer) const;
  407.         void         UpdateTerrainNodes(CTerrainNode* pParentNode = 0);
  408.  
  409.         template<class T>
  410.         int         Load_T(T*& f, int& nDataSize, std::vector<IStatObj*>* pStatObjTable, std::vector<IMaterial*>* pMatTable, EEndian eEndian, AABB* pBox, const SLayerVisibility* pLayerVisibility, const Vec3& segmentOffset);
  411.         int         Load(FILE*& f, int& nDataSize, std::vector<IStatObj*>* pStatObjTable, std::vector<IMaterial*>* pMatTable, EEndian eEndian, AABB* pBox, const SLayerVisibility* pLayerVisibility, const Vec3& segmentOffset);
  412.         int         Load(uint8*& f, int& nDataSize, std::vector<IStatObj*>* pStatObjTable, std::vector<IMaterial*>* pMatTable, EEndian eEndian, AABB* pBox, const SLayerVisibility* pLayerVisibility, const Vec3& segmentOffset);
  413.         bool        StreamLoad(uint8* pData, int nDataSize, std::vector<IStatObj*>* pStatObjTable, std::vector<IMaterial*>* pMatTable, EEndian eEndian, AABB* pBox);
  414.  
  415.         static void FreeLoadingCache();
  416.         void        GenerateStatObjAndMatTables(std::vector<IStatObj*>* pStatObjTable, std::vector<IMaterial*>* pMatTable, std::vector<IStatInstGroup*>* pStatInstGroupTable, SHotUpdateInfo* pExportInfo);
  417.         static void ReleaseEmptyNodes();
  418.         static void StaticReset();
  419.         bool        IsEmpty();
  420.         bool        HasObjects();
  421.  
  422.         // used for streaming
  423.         bool                   UpdateStreamingPriority(PodArray<COctreeNode*>& arrRecursion, float fMinDist, float fMaxDist, bool bFullUpdate, const SObjManPrecacheCamera* pPrecacheCams, size_t nPrecacheCams, const SRenderingPassInfo& passInfo);
  424.         float                  GetNodeStreamingDistance(const SObjManPrecacheCamera* pPrecacheCams, AABB objectsBox, size_t nPrecacheCams, const SRenderingPassInfo& passInfo);
  425.         void                   ReleaseStreamableContent();
  426.         bool                   CheckStartStreaming(bool bFullUpdate);
  427.         virtual void           StreamOnComplete(IReadStream* pStream, unsigned nError);
  428.         template<class T> void StreamOnCompleteReadObjects(T* f, int nDataSize);
  429.         void                   StartStreaming(bool bFinishNow, IReadStream_AutoPtr* ppStream);
  430.         template<class T> int  ReadObjects(T*& f, int& nDataSize, EEndian eEndian, std::vector<IStatObj*>* pStatObjTable, std::vector<IMaterial*>* pMatTable, const SLayerVisibility* pLayerVisibilityMask, const Vec3& segmentOffset, SOcTreeNodeChunk& chunk, ELoadObjectsMode eLoadMode);
  431.         void                   ReleaseObjects(bool bReleaseOnlyStreamable = false);
  432.         void                   GetStreamedInNodesNum(int& nAllStreamable, int& nReady);
  433.         static int             GetStreamingTasksNum()  { return m_nInstStreamTasksInProgress; }
  434.         static int             GetStreamedInNodesNum() { return m_arrStreamedInNodes.Count(); }
  435.         static void            StreamingCheckUnload(const SRenderingPassInfo& passInfo, PodArray<SObjManPrecacheCamera>& rStreamPreCacheCameras);
  436.  
  437.         void                   CheckManageVegetationSprites(float fNodeDistance, int nMaxFrames, const SRenderingPassInfo& passInfo);
  438.         AABB                   GetNodeBox() const
  439.         {
  440.                 return AABB(
  441.                   m_vNodeCenter - m_vNodeAxisRadius,
  442.                   m_vNodeCenter + m_vNodeAxisRadius);
  443.         }
  444.  
  445.         void OffsetObjects(const Vec3& offset);
  446.         void SetVisArea(CVisArea* pVisArea);
  447.         void UpdateVisAreaSID(CVisArea* pVisArea, int nSID)
  448.         {
  449.                 assert(pVisArea);
  450.                 m_nSID = nSID;
  451.         }
  452.  
  453.         static COctreeNode* Create(int nSID, const AABB& box, struct CVisArea* pVisArea, COctreeNode* pParent = NULL);
  454.  
  455. protected:
  456.         AABB  GetChildBBox(int nChildId);
  457.         void  CompileObjects();
  458.         void  UpdateStaticInstancing();
  459.         void  UpdateObjects(IRenderNode* pObj);
  460.         void  CompileCharacter(ICharacterInstance* pChar, uint32& nInternalFlags);
  461.         void  CompileObjectsBrightness();
  462.         float GetNodeObjectsMaxViewDistance();
  463.  
  464.         // Check if min spec specified in render node passes current server config spec.
  465.         static bool CheckRenderFlagsMinSpec(uint32 dwRndFlags);
  466.  
  467.         void        LinkObject(IRenderNode* pObj, EERType eERType, bool bPushFront = true);
  468.         void        UnlinkObject(IRenderNode* pObj);
  469.  
  470.         static int  Cmp_OctreeNodeSize(const void* v1, const void* v2);
  471.  
  472. private:
  473.         COctreeNode(int nSID, const AABB& box, struct CVisArea* pVisArea, COctreeNode* pParent);
  474.  
  475.         float        GetNodeRadius2() const { return m_vNodeAxisRadius.Dot(m_vNodeAxisRadius); }
  476.         COctreeNode* FindChildFor(IRenderNode* pObj, const AABB& objBox, const float fObjRadius, const Vec3& vObjCenter);
  477.         bool         HasAnyRenderableCandidates(const SRenderingPassInfo& passInfo) const;
  478.         void         BuildLoadingDatas(PodArray<SOctreeLoadObjectsData>* pQueue, byte* pOrigData, byte*& pData, int& nDataSize, EEndian eEndian);
  479.         PodArray<SOctreeLoadObjectsData> m_loadingDatas;
  480.  
  481.         static const float               fMinShadowCasterViewDist;
  482.  
  483.         bool                             m_streamComplete;
  484.  
  485.         uint32                           m_nOccludedFrameId;
  486.         uint32                           m_renderFlags;
  487.         uint32                           m_errTypesBitField;
  488.         AABB                             m_objectsBox;
  489.         float                            m_fObjectsMaxViewDist;
  490.         uint32                           m_nLastVisFrameId;
  491.  
  492.         COctreeNode*                     m_arrChilds[8];
  493.         TDoublyLinkedList<IRenderNode>   m_arrObjects[eRNListType_ListsNum];
  494.         PodArray<SCasterInfo>            m_lstCasters;
  495.         Vec3                             m_vNodeCenter;
  496.         Vec3                             m_vNodeAxisRadius;
  497.         PodArray<CDLight*>               m_lstAffectingLights;
  498.         uint32                           m_nLightMaskFrameId;
  499.         COctreeNode*                     m_pParent;
  500.         uint32                           nFillShadowCastersSkipFrameId;
  501.         float                            m_fNodeDistance;
  502.         int                              m_nManageVegetationsFrameId;
  503.         int                              m_nSID;
  504.  
  505.         OcclusionTestClient              m_occlusionTestClient;
  506.  
  507.         uint32                           m_bHasLights               : 1;
  508.         uint32                           m_bHasRoads                : 1;
  509.         uint32                           m_bNodeCompletelyInFrustum : 1;
  510.         uint32                           m_fpSunDirX                : 7;
  511.         uint32                           m_fpSunDirZ                : 7;
  512.         uint32                           m_fpSunDirYs               : 1;
  513.  
  514.         // used for streaming
  515.         int                           m_nFileDataOffset; // TODO: make it 64bit
  516.         int                           m_nFileDataSize;
  517.         EFileStreamingStatus          m_eStreamingStatus;
  518.         IReadStreamPtr                m_pReadStream;
  519.         int                           m_nUpdateStreamingPrioriryRoundId;
  520.         static int                    m_nInstStreamTasksInProgress;
  521.         static FILE*                  m_pFileForSyncRead;
  522.         static PodArray<COctreeNode*> m_arrStreamedInNodes;
  523.         uint32                        m_bStaticInstancingIsDirty : 1;
  524.  
  525.         struct SNodeInstancingInfo
  526.         {
  527.                 SNodeInstancingInfo() { pRNode = 0; nodeMatrix.IsIdentity(); }
  528.                 Matrix34           nodeMatrix;
  529.                 class CVegetation* pRNode;
  530.         };
  531.         std::map<std::pair<IStatObj*, IMaterial*>, PodArray<SNodeInstancingInfo>*>* m_pStaticInstancingInfo;
  532.  
  533.         float                         m_fPrevTerrainTexScale; // used to detect terrain texturing change and refresh info in object instances
  534.  
  535.         static void*                  m_pRenderContentJobQueue;
  536. public:
  537.         static PodArray<COctreeNode*> m_arrEmptyNodes;
  538.         static int                    m_nNodesCounterAll;
  539.         static int                    m_nNodesCounterStreamable;
  540.         static int                    m_nInstCounterLoaded;
  541.  
  542.         volatile int                  m_updateStaticInstancingLock;
  543. };
  544.  
  545. #endif
  546.  
downloadObjectsTree.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