diff --git a/source/graphics/GameView.cpp b/source/graphics/GameView.cpp index 4292b0fa87..9fc6a1b785 100644 --- a/source/graphics/GameView.cpp +++ b/source/graphics/GameView.cpp @@ -305,6 +305,8 @@ void CGameView::EnumerateObjects(const CFrustum& frustum, SceneCollector* c) PROFILE_START( "submit terrain" ); CTerrain* pTerrain = m->Game->GetWorld()->GetTerrain(); u32 patchesPerSide = pTerrain->GetPatchesPerSide(); + + // findout, which patches will be drawn for (uint j=0; jGetPatch(i,j); @@ -317,7 +319,22 @@ void CGameView::EnumerateObjects(const CFrustum& frustum, SceneCollector* c) } if (!m->Culling || frustum.IsBoxVisible (CVector3D(0,0,0), bounds)) { + //c->Submit(patch); + patch->setDrawState(); + } + } + } + + // draw the patches + for (uint j=0; jGetPatch(i,j); + if(patch->getDrawState() == true) + { c->Submit(patch); + patch->resetDrawState(); } } } diff --git a/source/graphics/Patch.cpp b/source/graphics/Patch.cpp index 7f7a8663bb..4474ef898c 100644 --- a/source/graphics/Patch.cpp +++ b/source/graphics/Patch.cpp @@ -3,6 +3,7 @@ // Name: ModelDef.cpp // Author: Rich Cross // Contact: rich@wildfiregames.com +// Modified by: 30. April 2007 - Christian Heubach // /////////////////////////////////////////////////////////////////////////////// @@ -16,12 +17,14 @@ // CPatch constructor CPatch::CPatch() : m_Parent(0) { + this->m_bWillBeDrawn = false; } /////////////////////////////////////////////////////////////////////////////// // CPatch destructor CPatch::~CPatch() { + } /////////////////////////////////////////////////////////////////////////////// @@ -43,6 +46,24 @@ void CPatch::Initialize(CTerrain* parent,u32 x,u32 z) } InvalidateBounds(); + + // get the neightbors + this->m_Neightbors[CPATCH_NEIGHTBOR_LEFT_TOP] = + this->m_Parent->GetPatch(x-1,z-1); + this->m_Neightbors[CPATCH_NEIGHTBOR_TOP] = + this->m_Parent->GetPatch(x,z-1); + this->m_Neightbors[CPATCH_NEIGHTBOR_RIGHT_TOP] = + this->m_Parent->GetPatch(x+1,z-1); + this->m_Neightbors[CPATCH_NEIGHTBOR_LEFT] = + this->m_Parent->GetPatch(x-1,z); + this->m_Neightbors[CPATCH_NEIGHTBOR_RIGHT] = + this->m_Parent->GetPatch(x+1,z); + this->m_Neightbors[CPATCH_NEIGHTBOR_LEFT_BOTTOM] = + this->m_Parent->GetPatch(x-1,z+1); + this->m_Neightbors[CPATCH_NEIGHTBOR_BOTTOM] = + this->m_Parent->GetPatch(x,z+1); + this->m_Neightbors[CPATCH_NEIGHTBOR_RIGHT_BOTTOM] = + this->m_Parent->GetPatch(x+1,z+1); } /////////////////////////////////////////////////////////////////////////////// diff --git a/source/graphics/Patch.h b/source/graphics/Patch.h index 0524c96c41..4b90c99b35 100644 --- a/source/graphics/Patch.h +++ b/source/graphics/Patch.h @@ -3,6 +3,7 @@ // Name: Patch.h // Author: Rich Cross // Contact: rich@wildfiregames.com +// Modified by: 30. April 2007 - Christian Heubach // /////////////////////////////////////////////////////////////////////////////// @@ -20,6 +21,18 @@ class CTerrain; // PATCH_SIZE: number of tiles in each patch const int PATCH_SIZE = 16; +/////////////////////////////////////////////////////////////////////////////// +// CPatchNeightbors: neightbor - IDs for CPatch + +#define CPATCH_NEIGHTBOR_LEFT_TOP 0 +#define CPATCH_NEIGHTBOR_TOP 1 +#define CPATCH_NEIGHTBOR_RIGHT_TOP 2 +#define CPATCH_NEIGHTBOR_LEFT 3 +#define CPATCH_NEIGHTBOR_RIGHT 4 +#define CPATCH_NEIGHTBOR_LEFT_BOTTOM 5 +#define CPATCH_NEIGHTBOR_BOTTOM 6 +#define CPATCH_NEIGHTBOR_RIGHT_BOTTOM 7 + /////////////////////////////////////////////////////////////////////////////// // CPatch: a single terrain patch, PATCH_SIZE tiles square class CPatch : public CRenderableObject @@ -35,6 +48,12 @@ public: // calculate and store bounds of this patch void CalcBounds(); + // neightbors of this patch + CPatch *m_Neightbors[8]; + + // is alread in the DrawList + bool m_bWillBeDrawn; + public: // minipatches (tiles) making up the patch CMiniPatch m_MiniPatches[PATCH_SIZE][PATCH_SIZE]; @@ -42,7 +61,20 @@ public: u32 m_X,m_Z; // parent terrain CTerrain* m_Parent; + // draw state... + void resetDrawState() { this->m_bWillBeDrawn = false; } + void setDrawState() + { + for(int i=0;i<8;i++) + { + if(m_Neightbors[i]) + m_Neightbors[i]->m_bWillBeDrawn = true; + } + m_bWillBeDrawn = true; + } + bool getDrawState() { return this->m_bWillBeDrawn; } }; #endif +