⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 ogrepaginglandscapetilemanager.cpp

📁 使用stl技术,(还没看,是听说的)
💻 CPP
字号:
/***************************************************************************
	OgrePagingLandScapeTileManager.cpp  -  description
	-------------------
	begin                : Mon Jun 16 2003
	copyright            : (C) 2003 by Jose A. Milan
	email                : spoke2@supercable.es
***************************************************************************/

/***************************************************************************
*                                                                         *
*   This program is free software; you can redistribute it and/or modify  *
*   it under the terms of the GNU Lesser General Public License as        *
*   published by the Free Software Foundation; either version 2 of the    *
*   License, or (at your option) any later version.                       *
*                                                                         *
***************************************************************************/

#include "OgrePagingLandScapeTileManager.h"

#include "OgrePagingLandScapeOptions.h"

namespace Ogre
{

//-----------------------------------------------------------------------
template<> PagingLandScapeTileManager* Singleton<PagingLandScapeTileManager>::ms_Singleton = 0;

//-----------------------------------------------------------------------
PagingLandScapeTileManager::PagingLandScapeTileManager( )
{	
	NumTiles = PagingLandScapeOptions::getSingleton().num_tiles;
	updateCache();
	for ( int i = 0; i < NumTiles; i++ )
	{
		PagingLandScapeTile* tile = new PagingLandScapeTile( );
		mTiles.push_back( tile );
		mQueue.push( tile );
	}
}
//-----------------------------------------------------------------------
PagingLandScapeTileManager::~PagingLandScapeTileManager( )
{
	for ( int i = 0; i < NumTiles ; i++ )
	{
		delete mTiles[ i ];
		mTiles[ i ] = 0;
	}

	// destroy de renderables
	mTiles.clear();
}

//-----------------------------------------------------------------------
void PagingLandScapeTileManager::updateCache( void )
{
	NumTilesMergeProcess = PagingLandScapeOptions::getSingleton().num_tiles_merge_process;
	NumTilesSplitProcess = PagingLandScapeOptions::getSingleton().num_tiles_split_process;
}

//-----------------------------------------------------------------------
PagingLandScapeTile *PagingLandScapeTileManager::getTile( )
{
	if ( mQueue.getSize() == 0 )
	{
		if ( mMergeQueue.getSize() > 0 )
		{
			Merge();
		}
	}
	return mQueue.pop( );
}

//-----------------------------------------------------------------------
void PagingLandScapeTileManager::freeTile( PagingLandScapeTile *tile )
{
	mQueue.push( tile );
}

//-----------------------------------------------------------------------
void PagingLandScapeTileManager::Merge( )
{
	int j = (int)mMergeQueue.getSize();
	if ( j > NumTilesMergeProcess )
	{
		j = NumTilesMergeProcess;
	}
	for ( int i = 0; i < j ; i++ )
	{
		PagingLandScapeTile *tile = mMergeQueue.pop( );
		if ( tile != 0 )
		{
			tile -> Merge( );
		}
	}
}

//-----------------------------------------------------------------------
void PagingLandScapeTileManager::needMerge( PagingLandScapeTile *tile )
{
	mMergeQueue.push( tile );
}

//-----------------------------------------------------------------------
void PagingLandScapeTileManager::Split( )
{
	int j = (int)mSplitQueue.getSize();
	if ( j > NumTilesSplitProcess )
	{
		j = NumTilesSplitProcess;
	}
	for ( int i = 0; i < j ; i++ )
	{
		PagingLandScapeTile *tile = mSplitQueue.pop( );
		if ( tile != 0 )
		{
			tile -> Split( );
		}
	}
}

//-----------------------------------------------------------------------
void PagingLandScapeTileManager::needSplit( PagingLandScapeTile *tile )
{
	mSplitQueue.push( tile );
}

//-----------------------------------------------------------------------
PagingLandScapeTileManager& PagingLandScapeTileManager::getSingleton(void)
{
	return Singleton<PagingLandScapeTileManager>::getSingleton();
}

//-----------------------------------------------------------------------
int PagingLandScapeTileManager::numFree( ) const
{
	return mQueue.getSize( );
}

//-----------------------------------------------------------------------
int PagingLandScapeTileManager::numMerge( ) const
{
	return mMergeQueue.getSize( );
}

//-----------------------------------------------------------------------
int PagingLandScapeTileManager::numSplit( ) const
{
	return mSplitQueue.getSize( );
}

} //namespace

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -