Pyrogenesis  13997
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Patch.cpp
Go to the documentation of this file.
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
31 : m_Parent(0), m_bWillBeDrawn(false)
32 {
33 }
34 
35 ///////////////////////////////////////////////////////////////////////////////
36 // CPatch destructor
38 {
39 
40 }
41 
42 ///////////////////////////////////////////////////////////////////////////////
43 // Initialize: setup patch data
45 {
46  delete m_RenderData;
47  m_RenderData=0;
48 
49  m_Parent=parent;
50  m_X=x;
51  m_Z=z;
52 
54 }
55 
56 ///////////////////////////////////////////////////////////////////////////////
57 // CalcBounds: calculating the bounds of this patch
59 {
61 
62  for (ssize_t j=0;j<PATCH_SIZE+1;j++)
63  {
64  for (ssize_t i=0;i<PATCH_SIZE+1;i++)
65  {
66  CVector3D pos;
67  m_Parent->CalcPosition(m_X*PATCH_SIZE+i,m_Z*PATCH_SIZE+j,pos);
68  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  if (GetSideFlags())
75  m_WorldBounds[0].Y = std::min(m_WorldBounds[0].Y, 0.f);
76 }
77 
79 {
80  int flags = 0;
81  if (m_X == 0)
82  flags |= CPATCH_SIDE_NEGX;
83  if (m_Z == 0)
84  flags |= CPATCH_SIDE_NEGZ;
85  if (m_X == m_Parent->GetPatchesPerSide()-1)
86  flags |= CPATCH_SIDE_POSX;
87  if (m_Z == m_Parent->GetPatchesPerSide()-1)
88  flags |= CPATCH_SIDE_POSZ;
89  return flags;
90 }
CRenderData * m_RenderData
Definition: Decompose.h:22
void CalcPosition(ssize_t i, ssize_t j, CVector3D &pos) const
Definition: Terrain.cpp:118
CPatch()
Definition: Patch.cpp:30
CBoundingBoxAligned m_WorldBounds
World-space bounds of this object.
~CPatch()
Definition: Patch.cpp:37
int m_X
Definition: Patch.h:68
intptr_t ssize_t
Definition: wposix_types.h:82
int GetSideFlags()
Definition: Patch.cpp:78
CTerrain * m_Parent
Definition: Patch.h:70
int m_Z
Definition: Patch.h:68
void Initialize(CTerrain *parent, ssize_t x, ssize_t z)
Definition: Patch.cpp:44
ssize_t GetPatchesPerSide() const
Definition: Terrain.h:69
const ssize_t PATCH_SIZE
Definition: Patch.h:34
void CalcBounds()
(Re)calculates and stores any bounds or bound-dependent data for this object.
Definition: Patch.cpp:58
virtual void InvalidateBounds()
Marks the bounds as invalid.