2007-05-07 18:33:24 +02:00
|
|
|
/**
|
|
|
|
* =========================================================================
|
|
|
|
* File : Patch.cpp
|
|
|
|
* Project : 0 A.D.
|
|
|
|
* Description : A patch of terrain holding NxN MiniPatch tiles
|
|
|
|
* =========================================================================
|
|
|
|
*/
|
2004-05-29 22:56:24 +02:00
|
|
|
|
2004-06-03 20:38:14 +02:00
|
|
|
#include "precompiled.h"
|
|
|
|
|
2004-05-29 22:56:24 +02:00
|
|
|
#include "Patch.h"
|
|
|
|
#include "Terrain.h"
|
|
|
|
|
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
// CPatch constructor
|
2007-05-10 22:47:17 +02:00
|
|
|
CPatch::CPatch()
|
|
|
|
: m_Parent(0), m_bWillBeDrawn(false)
|
2004-05-29 22:56:24 +02:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
// CPatch destructor
|
|
|
|
CPatch::~CPatch()
|
|
|
|
{
|
2007-05-06 09:58:16 +02:00
|
|
|
|
2004-05-29 22:56:24 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
// Initialize: setup patch data
|
|
|
|
void CPatch::Initialize(CTerrain* parent,u32 x,u32 z)
|
|
|
|
{
|
|
|
|
delete m_RenderData;
|
|
|
|
m_RenderData=0;
|
|
|
|
|
|
|
|
m_Parent=parent;
|
|
|
|
m_X=x;
|
|
|
|
m_Z=z;
|
|
|
|
|
|
|
|
// set parent of each patch
|
2007-05-10 22:47:17 +02:00
|
|
|
for (int j=0;j<PATCH_SIZE;j++)
|
|
|
|
{
|
|
|
|
for (int i=0;i<PATCH_SIZE;i++)
|
|
|
|
{
|
2004-05-29 22:56:24 +02:00
|
|
|
m_MiniPatches[j][i].m_Parent=this;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-02-10 00:19:48 +01:00
|
|
|
InvalidateBounds();
|
2004-05-29 22:56:24 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
// CalcBounds: calculating the bounds of this patch
|
|
|
|
void CPatch::CalcBounds()
|
|
|
|
{
|
|
|
|
m_Bounds.SetEmpty();
|
|
|
|
|
2007-05-10 22:47:17 +02:00
|
|
|
for (int j=0;j<PATCH_SIZE+1;j++)
|
|
|
|
{
|
|
|
|
for (int i=0;i<PATCH_SIZE+1;i++)
|
|
|
|
{
|
2004-05-29 22:56:24 +02:00
|
|
|
CVector3D pos;
|
|
|
|
m_Parent->CalcPosition(m_X*PATCH_SIZE+i,m_Z*PATCH_SIZE+j,pos);
|
|
|
|
m_Bounds+=pos;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|