📄 ogrepaginglandscapepage.cpp
字号:
void PagingLandScapePage::unload( )
{
if ( mIsLoaded == true )
{
mIsLoaded = false;
// Unload the pages
int size = ( int ) mTiles.size();
//Boundaries links
//NORTH
if ( mNeighbors[PagingLandScapeTile::NORTH] != 0 )
{
if ( mNeighbors[PagingLandScapeTile::NORTH]->isLoaded() == true )
{
for ( int j = 0; j < size; j++ )
{
mTiles[ 0 ][ j ]->setNeighbor( PagingLandScapeTile::NORTH, 0 );
mNeighbors[PagingLandScapeTile::NORTH]->mTiles[ size - 1 ][ j ]->setNeighbor( PagingLandScapeTile::SOUTH, 0 );
}
}
}
//SOUTH
if ( mNeighbors[PagingLandScapeTile::SOUTH] != 0 )
{
if ( mNeighbors[PagingLandScapeTile::SOUTH]->isLoaded() == true )
{
for ( int j = 0; j < size; j++ )
{
mTiles[ size - 1 ][ j ]->setNeighbor( PagingLandScapeTile::SOUTH, 0 );
mNeighbors[PagingLandScapeTile::SOUTH]->mTiles[ 0 ][ j ]->setNeighbor( PagingLandScapeTile::NORTH, 0 );
}
}
}
//EAST
if ( mNeighbors[PagingLandScapeTile::EAST] != 0 )
{
if ( mNeighbors[PagingLandScapeTile::EAST]->isLoaded() == true )
{
for ( int i = 0; i < size; i++ )
{
mTiles[ i ][ size - 1 ]->setNeighbor( PagingLandScapeTile::EAST, 0 );
mNeighbors[PagingLandScapeTile::EAST]->mTiles[ i ][ 0 ]->setNeighbor( PagingLandScapeTile::WEST, 0 );
}
}
}
//EAST
if ( mNeighbors[PagingLandScapeTile::WEST] != 0 )
{
if ( mNeighbors[PagingLandScapeTile::WEST]->isLoaded() == true )
{
for ( int i = 0; i < size; i++ )
{
mTiles[ i ][ 0 ]->setNeighbor( PagingLandScapeTile::WEST, 0 );
mNeighbors[PagingLandScapeTile::WEST]->mTiles[ i ][ size - 1 ]->setNeighbor( PagingLandScapeTile::EAST, 0 );
}
}
}
if ( mPageNode != 0 )
{
// Unload the nodes
mPageNode -> detachAllObjects();
mPageNode -> removeAndDestroyAllChildren();
//mPageNode -> getParent() -> removeChild( mPageNode->getName() );
//delete mPageNode;
static_cast<SceneNode*>( mPageNode -> getParent() )->removeAndDestroyChild( mPageNode->getName() );
mPageNode = 0;
}
// Internal Links
for ( int i = 0; i < size; i++ )
{
for ( int j = 0; j < size; j++ )
{
if ( i != size - 1 )
{
if ( mTiles[ i ][ j]->getNeighbor( PagingLandScapeTile::SOUTH ) != 0 )
{
mTiles[ i ][ j ]->getNeighbor( PagingLandScapeTile::SOUTH )->setNeighbor( PagingLandScapeTile::NORTH, 0 );
mTiles[ i ][ j ]->setNeighbor( PagingLandScapeTile::SOUTH, 0 );
}
}
if ( j != size - 1 )
{
if ( mTiles[ i ][ j]->getNeighbor( PagingLandScapeTile::EAST ) != 0 )
{
mTiles[ i ][ j ]->getNeighbor( PagingLandScapeTile::EAST )->setNeighbor( PagingLandScapeTile::WEST, 0 );
mTiles[ i ][ j ]->setNeighbor( PagingLandScapeTile::EAST, 0 );
}
}
mTiles[ i ][ j ] -> release();
mTiles[ i ][ j ] = 0;
}
}
// destroy de pages
mTiles.clear();
}
}
//-----------------------------------------------------------------------
bool PagingLandScapePage::isLoaded()
{
return mIsLoaded;
}
//-----------------------------------------------------------------------
void PagingLandScapePage::preload( )
{
if ( mIsPreLoaded == true )
{
return;
}
if ( mData->isLoaded() == false )
{
mData->load( mX, mZ );
}
if ( mLandScapeMaterial->getName() == "BaseWhite" )
{
// JEFF - all material settings configured through material script
Material * Tmp = reinterpret_cast<Material *>(MaterialManager::getSingleton().getByName("PagingLandScape." + StringConverter::toString( mZ ) + "." + StringConverter::toString( mX )));
if ( Tmp != 0 )
{
mLandScapeMaterial = Tmp;
}
mLandScapeMaterial->load();
}
else
{
mLandScapeMaterial->load();
}
mLandScapeMaterial -> setLightingEnabled( mOptions->lit );
mIsPreLoaded = true;
}
//-----------------------------------------------------------------------
void PagingLandScapePage::postUnload( )
{
if ( mIsLoaded == true )
{
return;
}
if ( mIsPreLoaded == true )
{
mIsPreLoaded = false;
mData->unload();
if ( mLandScapeMaterial != 0 )
{
mLandScapeMaterial -> unload();
// We can磘 destroy de material here.
//mLandScapeMaterial -> destroy();
//delete mLandScapeMaterial;
//mLandScapeMaterial = 0;
}
}
}
//-----------------------------------------------------------------------
bool PagingLandScapePage::isPreLoaded( )
{
return mIsPreLoaded;
}
//-----------------------------------------------------------------------
int PagingLandScapePage::isCameraIn( const Vector3 & pos )
{
//TODO: Optimize this, we are lossing about 20 FPS with this.
//if ( ( ( pos.x >= mIniX ) && ( pos.x <= mEndX ) ) && ( ( pos.z >= mIniZ ) && ( pos.z <= mEndZ ) ) )
if ( mBoundsExt.intersects( pos ) == true )
//if ( (mBoundsExt.getMinimum() < pos && mBoundsExt.getMaximum() > pos) )
{
//if ( ( pos.x > mZoneIniX ) && ( pos.x < mZoneEndX ) || ( pos.z > mZoneIniZ ) && ( pos.z < mZoneEndZ ) )
if ( mBoundsInt.intersects( pos ) == true )
//if ( !(mBoundsExt.getMinimum() > pos || mBoundsExt.getMaximum() < pos) )
{
// Full into this page
return PAGE_INSIDE;
}
else
{
// Over the change zone
return PAGE_CHANGE;
}
}
else
{
// Not in this page
return PAGE_OUTSIDE;
}
}
//-----------------------------------------------------------------------
//JEFF
float PagingLandScapePage::getRealWorldHeight( float x, float z )
{
// only continue if the page is preloaded otherwise don't have access to heightfield data
if(mIsPreLoaded != true)
{
return -1.0;
}
int tilesize = pow( 2, mOptions->InitLOD );
// if page is loaded then tiles will exist and request can be passed onto the tile instead since it might be split too
if(mIsLoaded == true)
{
// figure out which tile to deal with : # tiles is PageSize / tile_step
// Tile 0 corasponds to quadrant 0,0: Tile 1 is 1,0: last tile is n,n
// need to get the indices for the tile to be used
int i = (int)(x / tilesize);
// make sure index does not exceed page size max index
if (x >= mOptions->PageSize - 1)
{
i--;
}
int j = (int)(z / tilesize);
if (z >= mOptions->PageSize - 1)
{
j--;
}
// make x and z relative to the tile position
x -= (float)(i * tilesize);
z -= (float)(j * tilesize);
return mTiles[ i ][ j ] -> getRealWorldHeight( x , z );
}
else // page is only preloaded with textures but we can get direct acces to the height field map
{
// get static method of renderable class to find the height and return it
// have to pass coordinates that are relative to the tile but in this case the tile is the page
// must scale the result to the real world
return PagingLandScapeRenderable::getRealWorldHeight(mData, x, z, tilesize) * mOptions->scale.y;
}
}
//-----------------------------------------------------------------------
void PagingLandScapePage::getPagingLandScapeRenderOpsInBox(const AxisAlignedBox& box, std::list<RenderOperation>& opList)
{
if ( box.intersects( mBoundsExt ) )
{
int size = ( int ) mTiles.size();
for ( int i = 0; i < size; i++ )
{
for ( int j = 0; j < size; j++ )
{
mTiles[ i ][ j]->getPagingLandScapeRenderOpsInBox( box, opList );
}
}
}
}
//-----------------------------------------------------------------------
void PagingLandScapePage::_notify( const Vector3 & pos, const bool needOptionsUpdate )
{
if ( mIsLoaded == true )
{
int size = (int)mTiles.size();
for ( int i = 0; i < size; i++ )
{
for ( int j = 0; j < size; j++ )
{
mTiles[ i ][ j ] -> _notify( pos, needOptionsUpdate );
}
}
}
}
} //namespace
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -