BVB Source Codes

CRYENGINE Show terrain_load.cpp Source code

Return Download CRYENGINE: download terrain_load.cpp Source code - Download CRYENGINE Source code - Type:.cpp
  1. // Copyright 2001-2016 Crytek GmbH / Crytek Group. All rights reserved.
  2.  
  3. // -------------------------------------------------------------------------
  4. //  File name:   terrain_load.cpp
  5. //  Version:     v1.00
  6. //  Created:     28/5/2001 by Vladimir Kajalin
  7. //  Compilers:   Visual Studio.NET
  8. //  Description: terrain loading
  9. // -------------------------------------------------------------------------
  10. //  History:
  11. //
  12. ////////////////////////////////////////////////////////////////////////////
  13.  
  14. #include "StdAfx.h"
  15. #include "terrain.h"
  16. #include "terrain_sector.h"
  17. #include "ObjMan.h"
  18. #include "terrain_water.h"
  19. #include "3dEngine.h"
  20. #include "Vegetation.h"
  21.  
  22. CTerrain::CTerrain(const STerrainInfo& TerrainInfo)
  23. {
  24.         m_bProcVegetationInUse = false;
  25.         m_nLoadedSectors = 0;
  26.         m_bOceanIsVisible = 0;
  27.         m_fDistanceToSectorWithWater = 0;
  28.         //      m_nDiffTexIndexTableSize = 0;
  29.         //      m_nDiffTexTreeLevelOffset = 0;
  30.         //      ZeroStruct(m_hdrDiffTexInfo);
  31.         //      ZeroStruct(m_TerrainTextureLayer);
  32.         //      m_ucpDiffTexTmpBuffer = 0;
  33.         m_pTerrainEf = 0;
  34.         //      ZeroStruct(m_SSurfaceType); // staic
  35.         m_pOcean = 0;
  36.         m_eEndianOfTexture = eLittleEndian;
  37.  
  38.         // load default textures
  39.         m_nWhiteTexId = Get3DEngine()->GetWhiteTexID();
  40.         m_nBlackTexId = Get3DEngine()->GetBlackTexID();
  41.  
  42.         // set params
  43.         m_nUnitSize = TerrainInfo.nUnitSize_InMeters;
  44.         m_fInvUnitSize = 1.f / TerrainInfo.nUnitSize_InMeters;
  45.         m_nTerrainSize = TerrainInfo.nHeightMapSize_InUnits * TerrainInfo.nUnitSize_InMeters;
  46.         m_nSectorSize = TerrainInfo.nSectorSize_InMeters;
  47. #ifndef SEG_WORLD
  48.         m_nSectorsTableSize = TerrainInfo.nSectorsTableSize_InSectors;
  49. #endif
  50.         m_fHeightmapZRatio = TerrainInfo.fHeightmapZRatio;
  51.         m_fOceanWaterLevel = TerrainInfo.fOceanWaterLevel;
  52.  
  53.         m_nUnitsToSectorBitShift = 0;
  54.         while (m_nSectorSize >> m_nUnitsToSectorBitShift > m_nUnitSize)
  55.                 m_nUnitsToSectorBitShift++;
  56.  
  57.         // make flat 0 level heightmap
  58.         //      m_arrusHightMapData.Allocate(TerrainInfo.nHeightMapSize_InUnits+1);
  59.         //      m_arrHightMapRangeInfo.Allocate((TerrainInfo.nHeightMapSize_InUnits>>m_nRangeBitShift)+1);
  60.  
  61. #ifndef SEG_WORLD
  62.         assert(m_nSectorsTableSize == m_nTerrainSize / m_nSectorSize);
  63. #endif
  64.  
  65.         m_nBitShift = 0;
  66.         while ((128 >> m_nBitShift) != 128 / CTerrain::GetHeightMapUnitSize())
  67.                 m_nBitShift++;
  68.  
  69.         m_nTerrainSizeDiv = (m_nTerrainSize >> m_nBitShift) - 1;
  70.  
  71.         m_lstSectors.reserve(512); // based on inspection in MemReplay
  72.  
  73.         // create default segment
  74.         ISegmentsManager* pSM = Get3DEngine()->m_pSegmentsManager;
  75.         if (!pSM || !pSM->CreateSegments(this))
  76.         {
  77.                 float f = (float) GetTerrainSize();
  78.                 CreateSegment(Vec3(f, f, f));
  79.         }
  80.         InitHeightfieldPhysics(0);
  81.  
  82.         if (GetRenderer())
  83.         {
  84.                 SInputShaderResourcesPtr pIsr = GetRenderer()->EF_CreateInputShaderResource();
  85.                 pIsr->m_LMaterial.m_Opacity = 1.0f;
  86.                 m_pTerrainEf = MakeSystemMaterialFromShader("Terrain", pIsr);
  87.         }
  88.  
  89.         m_pImposterEf = MakeSystemMaterialFromShader("Common.Imposter");
  90.  
  91.         //      memset(m_arrImposters,0,sizeof(m_arrImposters));
  92.         //      memset(m_arrImpostersTopBottom,0,sizeof(m_arrImpostersTopBottom));
  93.  
  94.         m_StoredModifications.SetTerrain(*this);
  95.  
  96.         assert(m_SSurfaceType[0].GetDataSize() < SRangeInfo::e_max_surface_types * 1000);
  97.  
  98.         m_pTerrainUpdateDispatcher = GetRenderer() ? new CTerrainUpdateDispatcher() : nullptr;
  99.  
  100. #if defined(FEATURE_SVO_GI)
  101.         m_pTerrainRgbLowResSystemCopy = 0;
  102. #endif
  103. }
  104.  
  105. void CTerrain::CloseTerrainTextureFile(int nSID)
  106. {
  107.         if (nSID < 0)
  108.         {
  109.                 int nEndSID = GetMaxSegmentsCount();
  110.                 for (nSID = 0; nSID < nEndSID; ++nSID)
  111.                 {
  112.                         AABB aabb;
  113.                         if (!GetSegmentBounds(nSID, aabb))
  114.                                 continue;
  115.                         CloseTerrainTextureFile(nSID);
  116.                 }
  117.                 return;
  118.         }
  119.  
  120.         m_arrBaseTexInfos[nSID].m_nDiffTexIndexTableSize = 0;
  121.  
  122.         for (int i = m_lstActiveTextureNodes.size() - 1; i >= 0; --i)
  123.         {
  124. #ifdef SEG_WORLD
  125.                 if (m_lstActiveTextureNodes[i]->m_nSID == nSID)
  126. #endif
  127.                 {
  128.                         m_lstActiveTextureNodes[i]->UnloadNodeTexture(false);
  129.                         m_lstActiveTextureNodes.Delete(i);
  130.                 }
  131.         }
  132.  
  133.         for (int i = m_lstActiveProcObjNodes.size() - 1; i >= 0; --i)
  134.         {
  135. #ifdef SEG_WORLD
  136.                 if (m_lstActiveProcObjNodes[i]->m_nSID == nSID)
  137. #endif
  138.                 {
  139.                         m_lstActiveProcObjNodes[i]->RemoveProcObjects(false);
  140.                         m_lstActiveProcObjNodes.Delete(i);
  141.                 }
  142.         }
  143.  
  144.         if (GetParentNode(nSID))
  145.                 GetParentNode(nSID)->UnloadNodeTexture(true);
  146.  
  147.         m_bOpenTerrainTextureFileNoLog = false;
  148. }
  149.  
  150. CTerrain::~CTerrain()
  151. {
  152.         INDENT_LOG_DURING_SCOPE(true, "Destroying terrain");
  153.  
  154.         SAFE_DELETE(m_pOcean);
  155.         SAFE_DELETE(m_pTerrainUpdateDispatcher);
  156.  
  157. #if defined(FEATURE_SVO_GI)
  158.         SAFE_DELETE(m_pTerrainRgbLowResSystemCopy);
  159. #endif
  160.  
  161.         for (int nSID = 0; nSID < m_SSurfaceType.Count(); nSID++)
  162.                 DeleteSegment(nSID, true);
  163.  
  164.         CTerrainNode::ResetStaticData();
  165. }
  166.  
  167. void CTerrain::InitHeightfieldPhysics(int nSID)
  168. {
  169.         // for phys engine
  170.         primitives::heightfield hf;
  171.         hf.Basis.SetIdentity();
  172.         hf.origin.zero();
  173.         hf.step.x = hf.step.y = (float)CTerrain::GetHeightMapUnitSize();
  174.         hf.size.x = hf.size.y = CTerrain::GetTerrainSize() / CTerrain::GetHeightMapUnitSize();
  175.         hf.stride.set(hf.size.y + 1, 1);
  176.         hf.heightscale = 1.0f;//m_fHeightmapZRatio;
  177.         hf.typemask = SRangeInfo::e_hole | SRangeInfo::e_undefined;
  178.         hf.typehole = SRangeInfo::e_hole;
  179.         hf.heightmask = ~SRangeInfo::e_index_hole; // hf.heightmask does not appear to be used anywhere. What is it for?
  180.  
  181.         hf.fpGetHeightCallback = GetHeightFromUnits_Callback;
  182.         hf.fpGetSurfTypeCallback = GetSurfaceTypeFromUnits_Callback;
  183.  
  184.         int arrMatMapping[SRangeInfo::e_max_surface_types];
  185.         memset(arrMatMapping, 0, sizeof(arrMatMapping));
  186.         for (int i = 0; i < SRangeInfo::e_max_surface_types; i++)
  187.                 if (IMaterial* pMat = m_SSurfaceType[nSID][i].pLayerMat)
  188.                 {
  189.                         if (pMat->GetSubMtlCount() > 2)
  190.                                 pMat = pMat->GetSubMtl(2);
  191.                         arrMatMapping[i] = pMat->GetSurfaceTypeId();
  192.                 }
  193.  
  194.         // KLUDGE: The 3rd parameter in the following call (nMats) cannot be 128 because it gets assigned to an unsigned:7!
  195.         IPhysicalEntity* pPhysTerrain = GetPhysicalWorld()->SetHeightfieldData(&hf, arrMatMapping, SRangeInfo::e_undefined);
  196.         pe_params_foreign_data pfd;
  197.         pfd.iForeignData = PHYS_FOREIGN_ID_TERRAIN;
  198.         pPhysTerrain->SetParams(&pfd);
  199. }
  200.  
  201. void CTerrain::SetMaterialMapping(int nSID)
  202. {
  203.         int arrMatMapping[SRangeInfo::e_max_surface_types];
  204.         memset(arrMatMapping, 0, sizeof(arrMatMapping));
  205.         for (int i = 0; i < SRangeInfo::e_max_surface_types; i++)
  206.                 if (IMaterial* pMat = m_SSurfaceType[nSID][i].pLayerMat)
  207.                 {
  208.                         if (pMat->GetSubMtlCount() > 2)
  209.                                 pMat = pMat->GetSubMtl(2);
  210.                         arrMatMapping[i] = pMat->GetSurfaceTypeId();
  211.                 }
  212.  
  213.         GetPhysicalWorld()->SetHeightfieldMatMapping(arrMatMapping, SRangeInfo::e_undefined);
  214. }
  215. /*
  216.    int __cdecl CTerrain__Cmp_CVegetationForLoading_Size(const void* v1, const void* v2)
  217.    {
  218.    CVegetationForLoading * p1 = ((CVegetationForLoading*)v1);
  219.    CVegetationForLoading * p2 = ((CVegetationForLoading*)v2);
  220.  
  221.    PodArray<StatInstGroup> & lstStaticTypes = CStatObj::GetObjManager()->m_lstStaticTypes;
  222.  
  223.    CStatObj * pStatObj1 = (p1->GetID()<lstStaticTypes.Count()) ? lstStaticTypes[p1->GetID()].GetStatObj() : 0;
  224.    CStatObj * pStatObj2 = (p2->GetID()<lstStaticTypes.Count()) ? lstStaticTypes[p2->GetID()].GetStatObj() : 0;
  225.  
  226.    if(!pStatObj1)
  227.     return 1;
  228.    if(!pStatObj2)
  229.     return -1;
  230.  
  231.    int nSecId1 = 0;
  232.    {  // get pos
  233.     Vec3 vCenter = Vec3(p1->GetX(),p1->GetY(),p1->GetZ()) + (pStatObj1->GetBoxMin()+pStatObj1->GetBoxMax())*0.5f*p1->GetScale();
  234.     // get sector ids
  235.     int x = (int)(((vCenter.x)/CTerrain::GetSectorSize()));
  236.     int y = (int)(((vCenter.y)/CTerrain::GetSectorSize()));
  237.     // get obj bbox
  238.     Vec3 vBMin = pStatObj1->GetBoxMin()*p1->GetScale();
  239.     Vec3 vBMax = pStatObj1->GetBoxMax()*p1->GetScale();
  240.     // if outside of the map, or too big - register in sector (0,0)
  241.    //    if( x<0 || x>=CTerrain::GetSectorsTableSize() || y<0 || y>=CTerrain::GetSectorsTableSize() ||
  242.    //    (vBMax.x - vBMin.x)>TERRAIN_SECTORS_MAX_OVERLAPPING*2 || (vBMax.y - vBMin.y)>TERRAIN_SECTORS_MAX_OVERLAPPING*2)
  243.     //  x = y = 0;
  244.  
  245.     // get sector id
  246.     nSecId1 = (x)*CTerrain::GetSectorsTableSize() + (y);
  247.    }
  248.  
  249.    int nSecId2 = 0;
  250.    {  // get pos
  251.     Vec3 vCenter = Vec3(p2->GetX(),p2->GetY(),p2->GetZ()) + (pStatObj2->GetBoxMin()+pStatObj2->GetBoxMax())*0.5f*p2->GetScale();
  252.     // get sector ids
  253.     int x = (int)(((vCenter.x)/CTerrain::GetSectorSize()));
  254.     int y = (int)(((vCenter.y)/CTerrain::GetSectorSize()));
  255.     // get obj bbox
  256.     Vec3 vBMin = pStatObj2->GetBoxMin()*p2->GetScale();
  257.     Vec3 vBMax = pStatObj2->GetBoxMax()*p2->GetScale();
  258.     // if outside of the map, or too big - register in sector (0,0)
  259.    //    if( x<0 || x>=CTerrain::GetSectorsTableSize() || y<0 || y>=CTerrain::GetSectorsTableSize() ||
  260.    //    (vBMax.x - vBMin.x)>TERRAIN_SECTORS_MAX_OVERLAPPING*2 || (vBMax.y - vBMin.y)>TERRAIN_SECTORS_MAX_OVERLAPPING*2)
  261.     //  x = y = 0;
  262.  
  263.     // get sector id
  264.     nSecId2 = (x)*CTerrain::GetSectorsTableSize() + (y);
  265.    }
  266.  
  267.    if(nSecId1 > nSecId2)
  268.     return -1;
  269.    if(nSecId1 < nSecId2)
  270.     return 1;
  271.  
  272.    if(p1->GetScale()*pStatObj1->GetRadius() > p2->GetScale()*pStatObj2->GetRadius())
  273.     return 1;
  274.    if(p1->GetScale()*pStatObj1->GetRadius() < p2->GetScale()*pStatObj2->GetRadius())
  275.     return -1;
  276.  
  277.    return 0;
  278.    }
  279.  
  280.    int __cdecl CTerrain__Cmp_Int(const void* v1, const void* v2)
  281.    {
  282.    if(*(uint32*)v1 > *(uint32*)v2)
  283.     return 1;
  284.    if(*(uint32*)v1 < *(uint32*)v2)
  285.     return -1;
  286.  
  287.    return 0;
  288.    }
  289.  
  290.    void CTerrain::LoadVegetationances()
  291.    {
  292.    assert(this); if(!this) return;
  293.  
  294.    PrintMessage("Loading static object positions ...");
  295.  
  296.  
  297.    for( int x=0; x<CTerrain::GetSectorsTableSize(); x++)
  298.    for( int y=0; y<CTerrain::GetSectorsTableSize(); y++)
  299.     assert(!m_arrSecInfoPyramid[nSID][0][x][y]->m_lstEntities[STATIC_OBJECTS].Count());
  300.  
  301.  
  302.    // load static object positions list
  303.    PodArray<CVegetationForLoading> static_objects;
  304.    static_objects.Load(Get3DEngine()->GetLevelFilePath("objects.lst"), gEnv->pCryPak);
  305.  
  306.    // todo: sorting in not correct for hierarchical system
  307.    qsort(static_objects.GetElements(), static_objects.Count(),
  308.     sizeof(static_objects[0]), CTerrain__Cmp_CVegetationForLoading_Size);
  309.  
  310.    // put objects into sectors depending on object position and fill lstUsedCGFs
  311.    PodArray<CStatObj*> lstUsedCGFs;
  312.    for(int i=0; i<static_objects.Count(); i++)
  313.    {
  314.     float x       = static_objects[i].GetX();
  315.     float y       = static_objects[i].GetY();
  316.     float z       = static_objects[i].GetZ()>0 ? static_objects[i].GetZ() : GetZApr(x,y);
  317.     int  nId      = static_objects[i].GetID();
  318.     uint8 ucBr    = static_objects[i].GetBrightness();
  319.     uint8 ucAngle = static_objects[i].GetAngle();
  320.     float fScale  = static_objects[i].GetScale();
  321.  
  322.     if( nId>=0 && nId<GetObjManager()->m_lstStaticTypes.Count() &&
  323.         fScale>0 &&
  324.         x>=0 && x<CTerrain::GetTerrainSize() && y>=0 && y<CTerrain::GetTerrainSize() &&
  325.         GetObjManager()->m_lstStaticTypes[nId].GetStatObj() )
  326.     {
  327.       if(GetObjManager()->m_lstStaticTypes[nId].GetStatObj()->GetRadius()*fScale < GetCVars()->e_VegetationMinSize)
  328.         continue; // skip creation of very small objects
  329.  
  330.       if(lstUsedCGFs.Find(GetObjManager()->m_lstStaticTypes[nId].GetStatObj())<0)
  331.         lstUsedCGFs.Add(GetObjManager()->m_lstStaticTypes[nId].GetStatObj());
  332.  
  333.       CVegetation * pEnt = (CVegetation*)Get3DEngine()->CreateRenderNode( eERType_Vegetation );
  334.       pEnt->m_fScale = fScale;
  335.       pEnt->m_vPos = Vec3(x,y,z);
  336.       pEnt->SetStatObjGroupId(nId);
  337.       pEnt->m_ucBright = ucBr;
  338.       pEnt->CalcBBox();
  339.       pEnt->Physicalize( );
  340.     }
  341.    }
  342.  
  343.    // release not used CGF's
  344.    int nGroupsReleased=0;
  345.    for(int i=0; i<GetObjManager()->m_lstStaticTypes.Count(); i++)
  346.    {
  347.     CStatObj * pStatObj = GetObjManager()->m_lstStaticTypes[i].GetStatObj();
  348.     if(pStatObj && lstUsedCGFs.Find(pStatObj)<0)
  349.     {
  350.       Get3DEngine()->ReleaseObject(pStatObj);
  351.       GetObjManager()->m_lstStaticTypes[i].pStatObj = NULL;
  352.       nGroupsReleased++;
  353.     }
  354.    }
  355.  
  356.    PrintMessagePlus(" %d objects created", static_objects.Count());
  357.    }
  358.  
  359.    void CTerrain::CompileObjects()
  360.    {
  361.    // set max view distance and sort by size
  362.    for(int nTreeLevel=0; nTreeLevel<TERRAIN_NODE_TREE_DEPTH; nTreeLevel++)
  363.    for( int x=0; x<m_arrSecInfoPyramid[nSID][nTreeLevel].GetSize(); x++)
  364.    for( int y=0; y<m_arrSecInfoPyramid[nSID][nTreeLevel].GetSize(); y++)
  365.     m_arrSecInfoPyramid[nSID][nTreeLevel][x][y]->CompileObjects(STATIC_OBJECTS);
  366.    }*/
  367.  
  368. void CTerrain::GetStreamingStatus(int& nLoadedSectors, int& nTotalSectors)
  369. {
  370.         nLoadedSectors = m_nLoadedSectors;
  371.         nTotalSectors = 0;
  372.         int nSegs = GetMaxSegmentsCount();
  373.         for (int nSID = 0; nSID < nSegs; ++nSID)
  374.         {
  375.                 if (!m_pParentNodes[nSID])
  376.                         continue;
  377.                 int nSectors = CTerrain::GetSectorsTableSize(nSID);
  378.                 nTotalSectors = nSectors * nSectors;
  379.         }
  380. }
  381.  
  382. bool CTerrain::m_bOpenTerrainTextureFileNoLog = false;
  383.  
  384. bool CTerrain::OpenTerrainTextureFile(SCommonFileHeader& hdrDiffTexHdr, STerrainTextureFileHeader& hdrDiffTexInfo, const char* szFileName, uint8*& ucpDiffTexTmpBuffer, int& nDiffTexIndexTableSize, int nSID)
  385. {
  386.         if (!GetRenderer())
  387.                 return false;
  388.  
  389.         FUNCTION_PROFILER_3DENGINE;
  390.         assert(nSID >= 0);
  391.  
  392.         m_arrBaseTexInfos[nSID].m_nDiffTexIndexTableSize = 0;
  393.  
  394.         if (GetParentNode(nSID))
  395.                 GetParentNode(nSID)->UnloadNodeTexture(true);
  396.         else
  397.                 return false;
  398.  
  399.         bool bNoLog = m_bOpenTerrainTextureFileNoLog;
  400.         m_bOpenTerrainTextureFileNoLog = true;
  401.  
  402.         if (!bNoLog)
  403.                 PrintMessage("Opening %s ...", szFileName);
  404.  
  405.         // rbx open flags, x is a hint to not cache whole file in memory.
  406.         FILE* fpDiffTexFile = gEnv->pCryPak->FOpen(Get3DEngine()->GetLevelFilePath(szFileName), "rbx");
  407.  
  408.         if (!fpDiffTexFile)
  409.         {
  410.                 if (!bNoLog)
  411.                         PrintMessage("Error opening terrain texture file: file not found (you might need to regenerate the surface texture)");
  412.                 return false;
  413.         }
  414.  
  415.         if (!gEnv->pCryPak->FRead(&hdrDiffTexHdr, 1, fpDiffTexFile, false))
  416.         {
  417.                 gEnv->pCryPak->FClose(fpDiffTexFile);
  418.                 fpDiffTexFile = 0;
  419.                 CloseTerrainTextureFile(nSID);
  420.                 if (!bNoLog)
  421.                         PrintMessage("Error opening terrain texture file: header not found (file is broken)");
  422.                 return false;
  423.         }
  424.  
  425.         m_eEndianOfTexture = (hdrDiffTexHdr.flags & SERIALIZATION_FLAG_BIG_ENDIAN) ? eBigEndian : eLittleEndian;
  426.  
  427.         SwapEndian(hdrDiffTexHdr, m_eEndianOfTexture);
  428.  
  429.         if (strcmp(hdrDiffTexHdr.signature, "CRY") || hdrDiffTexHdr.file_type != eTerrainTextureFile)
  430.         {
  431.                 gEnv->pCryPak->FClose(fpDiffTexFile);
  432.                 fpDiffTexFile = 0;
  433.                 CloseTerrainTextureFile(nSID);
  434.                 PrintMessage("Error opening terrain texture file: invalid signature");
  435.                 return false;
  436.         }
  437.  
  438.         if (hdrDiffTexHdr.version != FILEVERSION_TERRAIN_TEXTURE_FILE)
  439.         {
  440.                 gEnv->pCryPak->FClose(fpDiffTexFile);
  441.                 fpDiffTexFile = 0;
  442.                 CloseTerrainTextureFile(nSID);
  443.                 if (!bNoLog)
  444.                         Error("Error opening terrain texture file: version error (you might need to regenerate the surface texture)");
  445.                 return false;
  446.         }
  447.  
  448.         gEnv->pCryPak->FRead(&hdrDiffTexInfo, 1, fpDiffTexFile, m_eEndianOfTexture != GetPlatformEndian());
  449.  
  450.         memset(m_arrBaseTexInfos[nSID].m_TerrainTextureLayer, 0, sizeof(m_arrBaseTexInfos[nSID].m_TerrainTextureLayer));
  451.  
  452.         // layers
  453.         for (uint32 dwI = 0; dwI < hdrDiffTexInfo.nLayerCount; ++dwI)
  454.         {
  455.                 assert(dwI <= 2);
  456.                 if (dwI > 2) break;                     // too many layers
  457.  
  458.                 gEnv->pCryPak->FRead(&m_arrBaseTexInfos[nSID].m_TerrainTextureLayer[dwI], 1, fpDiffTexFile, m_eEndianOfTexture != GetPlatformEndian());
  459.  
  460.                 PrintMessage("  TerrainLayer %d: TexFormat: %s, SectorTextureSize: %dx%d, SectorTextureDataSizeBytes: %d",
  461.                              dwI, GetRenderer()->GetTextureFormatName(m_arrBaseTexInfos[nSID].m_TerrainTextureLayer[dwI].eTexFormat),
  462.                              m_arrBaseTexInfos[nSID].m_TerrainTextureLayer[dwI].nSectorSizePixels, m_arrBaseTexInfos[nSID].m_TerrainTextureLayer[dwI].nSectorSizePixels,
  463.                              m_arrBaseTexInfos[nSID].m_TerrainTextureLayer[dwI].nSectorSizeBytes);
  464.         }
  465.  
  466.         // unlock all nodes
  467.         for (int nTreeLevel = 0; nTreeLevel < TERRAIN_NODE_TREE_DEPTH; nTreeLevel++)
  468.                 for (int x = 0; x < m_arrSecInfoPyramid[nSID][nTreeLevel].GetSize(); x++)
  469.                         for (int y = 0; y < m_arrSecInfoPyramid[nSID][nTreeLevel].GetSize(); y++)
  470.                         {
  471. #ifndef _RELEASE
  472.                                 m_arrSecInfoPyramid[nSID][nTreeLevel][x][y]->m_eTextureEditingState = eTES_SectorIsUnmodified;
  473.                                 m_arrSecInfoPyramid[nSID][nTreeLevel][x][y]->m_eElevTexEditingState = eTES_SectorIsUnmodified;
  474. #endif // _RELEASE
  475.  
  476.                                 m_arrSecInfoPyramid[nSID][nTreeLevel][x][y]->m_nNodeTextureOffset = -1;
  477.                                 m_arrSecInfoPyramid[nSID][nTreeLevel][x][y]->m_bMergeNotAllowed = false;
  478.                         }
  479.  
  480.         // index block
  481.         {
  482.                 std::vector<int16> IndexBlock;    // for explanation - see saving code
  483.  
  484.                 uint16 wSize;
  485.                 gEnv->pCryPak->FRead(&wSize, 1, fpDiffTexFile, m_eEndianOfTexture != GetPlatformEndian());
  486.  
  487.                 IndexBlock.resize(wSize);
  488.  
  489.                 for (uint16 wI = 0; wI < wSize; ++wI)
  490.                         gEnv->pCryPak->FRead(&IndexBlock[wI], 1, fpDiffTexFile, m_eEndianOfTexture != GetPlatformEndian());
  491.  
  492.                 PrintMessage("  RGB multiplier: %.f, Texture indices: %d", 1.f / hdrDiffTexInfo.fBrMultiplier, wSize);
  493.  
  494.                 int16* pIndices = &IndexBlock[0];
  495.                 int16 nElementsLeft = wSize;
  496.  
  497.                 if (wSize > 0 && pIndices[0] >= 0)
  498.                 {
  499.                         CTerrainNode* const p = GetParentNode(nSID);
  500.                         if (p)
  501.                         {
  502.                                 p->AssignTextureFileOffset(pIndices, nElementsLeft);
  503.                                 assert(nElementsLeft == 0);
  504.                         }
  505.                 }
  506.  
  507.                 nDiffTexIndexTableSize = wSize * sizeof(uint16) + sizeof(uint16);
  508.  
  509.                 if (!m_bEditor)
  510.                 {
  511.                         FRAME_PROFILER("CTerrain::OpenTerrainTextureFile: ReleaseHoleNodes & UpdateTerrainNodes", GetSystem(), PROFILE_3DENGINE);
  512.  
  513.                         int nNodesCounterBefore = CTerrainNode::m_nNodesCounter;
  514.                         GetParentNode(nSID)->ReleaseHoleNodes();
  515.                         PrintMessage("  %d out of %d nodes cleaned", nNodesCounterBefore - CTerrainNode::m_nNodesCounter, nNodesCounterBefore);
  516.  
  517.                         if (Get3DEngine()->m_pObjectsTree[nSID])
  518.                                 Get3DEngine()->m_pObjectsTree[nSID]->UpdateTerrainNodes();
  519.                 }
  520.         }
  521.  
  522.         int nSectorHeightMapTextureDim = m_arrBaseTexInfos[nSID].m_TerrainTextureLayer[1].nSectorSizePixels;
  523.  
  524.         delete[] ucpDiffTexTmpBuffer;
  525.         ucpDiffTexTmpBuffer = new uint8[m_arrBaseTexInfos[nSID].m_TerrainTextureLayer[0].nSectorSizeBytes + m_arrBaseTexInfos[nSID].m_TerrainTextureLayer[1].nSectorSizeBytes + sizeof(float)*nSectorHeightMapTextureDim*nSectorHeightMapTextureDim];
  526.  
  527.         gEnv->pCryPak->FClose(fpDiffTexFile);
  528.         fpDiffTexFile = 0;
  529.  
  530.         // init texture pools
  531.         m_texCache[0].InitPool(0, m_arrBaseTexInfos[nSID].m_TerrainTextureLayer[0].nSectorSizePixels, m_arrBaseTexInfos[nSID].m_TerrainTextureLayer[0].eTexFormat);
  532.         m_texCache[1].InitPool(0, m_arrBaseTexInfos[nSID].m_TerrainTextureLayer[1].nSectorSizePixels, m_arrBaseTexInfos[nSID].m_TerrainTextureLayer[1].eTexFormat);
  533.         m_texCache[2].InitPool(0, nSectorHeightMapTextureDim, eTF_R32F);
  534.  
  535.         return true;
  536. }
  537.  
downloadterrain_load.cpp 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