LCOV - code coverage report
Current view: top level - source/graphics - Patch.cpp (source / functions) Hit Total Coverage
Test: 0 A.D. test coverage report Lines: 35 35 100.0 %
Date: 2023-01-19 00:18:29 Functions: 7 8 87.5 %

          Line data    Source code
       1             : /* Copyright (C) 2010 Wildfire Games.
       2             :  * This file is part of 0 A.D.
       3             :  *
       4             :  * 0 A.D. is free software: you can redistribute it and/or modify
       5             :  * it under the terms of the GNU General Public License as published by
       6             :  * the Free Software Foundation, either version 2 of the License, or
       7             :  * (at your option) any later version.
       8             :  *
       9             :  * 0 A.D. is distributed in the hope that it will be useful,
      10             :  * but WITHOUT ANY WARRANTY; without even the implied warranty of
      11             :  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
      12             :  * GNU General Public License for more details.
      13             :  *
      14             :  * You should have received a copy of the GNU General Public License
      15             :  * along with 0 A.D.  If not, see <http://www.gnu.org/licenses/>.
      16             :  */
      17             : 
      18             : /*
      19             :  * A patch of terrain holding NxN MiniPatch tiles
      20             :  */
      21             : 
      22             : #include "precompiled.h"
      23             : 
      24             : #include "Patch.h"
      25             : #include "Terrain.h"
      26             : 
      27             : 
      28             : ///////////////////////////////////////////////////////////////////////////////
      29             : // CPatch constructor
      30         269 : CPatch::CPatch()
      31         269 : : m_Parent(0)
      32             : {
      33         269 : }
      34             : 
      35             : ///////////////////////////////////////////////////////////////////////////////
      36             : // CPatch destructor
      37         269 : CPatch::~CPatch()
      38             : {
      39             : 
      40         269 : }
      41             : 
      42             : ///////////////////////////////////////////////////////////////////////////////
      43             : // Initialize: setup patch data
      44         269 : void CPatch::Initialize(CTerrain* parent,ssize_t x,ssize_t z)
      45             : {
      46         269 :     delete m_RenderData;
      47         269 :     m_RenderData=0;
      48             : 
      49         269 :     m_Parent=parent;
      50         269 :     m_X=x;
      51         269 :     m_Z=z;
      52             : 
      53         269 :     InvalidateBounds();
      54         269 : }
      55             : 
      56             : ///////////////////////////////////////////////////////////////////////////////
      57             : // CalcBounds: calculating the bounds of this patch
      58        1024 : void CPatch::CalcBounds()
      59             : {
      60        1024 :     m_WorldBounds.SetEmpty();
      61             : 
      62       18432 :     for (ssize_t j=0;j<PATCH_SIZE+1;j++)
      63             :     {
      64      313344 :         for (ssize_t i=0;i<PATCH_SIZE+1;i++)
      65             :         {
      66      295936 :             CVector3D pos;
      67      295936 :             m_Parent->CalcPosition(m_X*PATCH_SIZE+i,m_Z*PATCH_SIZE+j,pos);
      68      295936 :             m_WorldBounds+=pos;
      69             :         }
      70             :     }
      71             : 
      72             :     // If this a side patch, the sides go down to height 0, so add them
      73             :     // into the bounds
      74        1024 :     if (GetSideFlags())
      75         768 :         m_WorldBounds[0].Y = std::min(m_WorldBounds[0].Y, 0.f);
      76        1024 : }
      77             : 
      78        1024 : int CPatch::GetSideFlags()
      79             : {
      80        1024 :     int flags = 0;
      81        1024 :     if (m_X == 0)
      82         256 :         flags |= CPATCH_SIDE_NEGX;
      83        1024 :     if (m_Z == 0)
      84         256 :         flags |= CPATCH_SIDE_NEGZ;
      85        1024 :     if (m_X == m_Parent->GetPatchesPerSide()-1)
      86         256 :         flags |= CPATCH_SIDE_POSX;
      87        1024 :     if (m_Z == m_Parent->GetPatchesPerSide()-1)
      88         256 :         flags |= CPATCH_SIDE_POSZ;
      89        1024 :     return flags;
      90           3 : }

Generated by: LCOV version 1.13