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: 34 34 100.0 %
Date: 2026-12-03 01:19:39 Functions: 4 6 66.7 %

          Line data    Source code
       1             : /* Copyright (C) 2025 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             : 
      26             : #include "graphics/RenderableObject.h"
      27             : #include "graphics/Terrain.h"
      28             : #include "maths/BoundingBoxAligned.h"
      29             : #include "maths/Vector3D.h"
      30             : 
      31             : #include <algorithm>
      32             : 
      33             : ///////////////////////////////////////////////////////////////////////////////
      34             : // CPatch constructor
      35         717 : CPatch::CPatch()
      36      195741 : : m_Parent(0)
      37             : {
      38         717 : }
      39             : 
      40             : ///////////////////////////////////////////////////////////////////////////////
      41             : // CPatch destructor
      42         717 : CPatch::~CPatch()
      43             : {
      44             : 
      45         717 : }
      46             : 
      47             : ///////////////////////////////////////////////////////////////////////////////
      48             : // Initialize: setup patch data
      49         717 : void CPatch::Initialize(CTerrain* parent,ssize_t x,ssize_t z)
      50             : {
      51         717 :     delete m_RenderData;
      52         717 :     m_RenderData=0;
      53             : 
      54         717 :     m_Parent=parent;
      55         717 :     m_X=x;
      56         717 :     m_Z=z;
      57             : 
      58         717 :     InvalidateBounds();
      59         717 : }
      60             : 
      61             : ///////////////////////////////////////////////////////////////////////////////
      62             : // CalcBounds: calculating the bounds of this patch
      63        1456 : void CPatch::CalcBounds()
      64             : {
      65        1456 :     m_WorldBounds.SetEmpty();
      66             : 
      67       26208 :     for (ssize_t j=0;j<PATCH_SIZE+1;j++)
      68             :     {
      69      445536 :         for (ssize_t i=0;i<PATCH_SIZE+1;i++)
      70             :         {
      71      420784 :             CVector3D pos;
      72      420784 :             m_Parent->CalcPosition(m_X*PATCH_SIZE+i,m_Z*PATCH_SIZE+j,pos);
      73      420784 :             m_WorldBounds+=pos;
      74             :         }
      75             :     }
      76             : 
      77             :     // If this a side patch, the sides go down to height 0, so add them
      78             :     // into the bounds
      79        3520 :     if (GetSideFlags())
      80         900 :         m_WorldBounds[0].Y = std::min(m_WorldBounds[0].Y, 0.f);
      81        1456 : }
      82             : 
      83        1456 : int CPatch::GetSideFlags()
      84             : {
      85        1456 :     int flags = 0;
      86        1456 :     if (m_X == 0)
      87         292 :         flags |= CPATCH_SIDE_NEGX;
      88        1456 :     if (m_Z == 0)
      89         292 :         flags |= CPATCH_SIDE_NEGZ;
      90        1456 :     if (m_X == m_Parent->GetPatchesPerSide()-1)
      91         292 :         flags |= CPATCH_SIDE_POSX;
      92        1456 :     if (m_Z == m_Parent->GetPatchesPerSide()-1)
      93         900 :         flags |= CPATCH_SIDE_POSZ;
      94        1164 :     return flags;
      95             : }

Generated by: LCOV version 1.16