ogrepaginglandscapepagemanager.cpp
来自「使用stl技术,(还没看,是听说的)」· C++ 代码 · 共 473 行 · 第 1/2 页
CPP
473 行
{
for ( i = iniX; i <= finX; i++ )
{
mPageLoadQueue.push( mPages[ i ][ j ] );
}
}
}
}
// Update the last camera position
mLastCameraPos = pos;
PagingLandScapeTile *t = getTile (pos, mCurrentCameraPageX, mCurrentCameraPageZ);
if (t)
{
PagingLandScapeTileInfo *CurrentTileInfo = t->getInfo ();
if (CurrentTileInfo)
{
mCurrentCameraTileX = CurrentTileInfo->tileX;
mCurrentCameraTileZ = CurrentTileInfo->tileZ;
}
}
}
// Check for visibility
PagingLandscapeCamera* plsmCam = static_cast<PagingLandscapeCamera*> (cam);
for ( uint j = 0; j < mHeigth; j++ )
{
for ( uint i = 0; i < mWidth; i++ )
{
mPages[ i ][ j ]->_Notify (pos, plsmCam);
}
}
// Preload, load, unload and post unload as required
_processLoading();
}
//-----------------------------------------------------------------------
uint PagingLandScapePageManager::getCurrentCameraPageX( void )
{
return mCurrentCameraPageX;
}
//-----------------------------------------------------------------------
uint PagingLandScapePageManager::getCurrentCameraPageZ( void )
{
return mCurrentCameraPageZ;
}
//-----------------------------------------------------------------------
uint PagingLandScapePageManager::getCurrentCameraTileX( void )
{
return mCurrentCameraTileX;
}
//-----------------------------------------------------------------------
uint PagingLandScapePageManager::getCurrentCameraTileZ( void )
{
return mCurrentCameraTileZ;
}
//-----------------------------------------------------------------------
int PagingLandScapePageManager::getPagePreloadQueueSize( void )
{
return mPagePreloadQueue.getSize();
}
//-----------------------------------------------------------------------
int PagingLandScapePageManager::getPageLoadQueueSize( void )
{
return mPageLoadQueue.getSize();
}
//-----------------------------------------------------------------------
int PagingLandScapePageManager::getPageUnloadQueueSize( void )
{
return mPageUnloadQueue.getSize();
}
//-----------------------------------------------------------------------
int PagingLandScapePageManager::getPagePostUnloadQueueSize( void )
{
return mPagePostunloadQueue.getSize();
}
//-----------------------------------------------------------------------
void PagingLandScapePageManager::_processLoading( void )
{
// Preload, load, unload and post unload as required
/* We try to PreLoad
If no preload is required, then try to Load
If no load is required, then try to UnLoad
If no unload is required, then try to PostUnLoad.
*/
PagingLandScapePage *e;
e = mPagePreloadQueue.pop();
if ( e != 0 )
{
e->preload();
}
else
{
e = mPageLoadQueue.pop();
if ( e != 0 )
{
e->load( * mSceneRoot );
if ( e->isLoaded() == false )
{
if ( e->isPreLoaded() == false )
{
// If we are not PreLoaded, then we must preload
mPagePreloadQueue.push( e );
}
// If we are not loaded then queue again, since maybe we are not preloaded.
mPageLoadQueue.push( e );
}
}
else
{
e = mPageUnloadQueue.pop();
if ( e != 0 )
{
e->unload();
}
else
{
e = mPagePostunloadQueue.pop();
if ( e != 0 )
{
e->postUnload();
if ( e->isPreLoaded())
{
// If we are not post unloaded the queue again
mPagePostunloadQueue.push( e );
}
}
}
}
}
// load some renderables
PagingLandScapeRenderableManager::getSingleton().executeRenderableLoading();
}
//-----------------------------------------------------------------------
PagingLandScapeTile *PagingLandScapePageManager::getTileUnscaled(const Vector3& pos)
{
int pSize = PagingLandScapeOptions::getSingleton().PageSize;
int w = int (PagingLandScapeOptions::getSingleton().world_width * 0.5f);
int h = int (PagingLandScapeOptions::getSingleton().world_height * 0.5f);
Vector3 TileRefPos = pos;
int pagex = (int) (TileRefPos.x / pSize + w);
int pagez = (int) (TileRefPos.z / pSize + h);
// make sure indices are not negative or outside range of number of pages
if (pagex < 0 || pagex >= w*2 || pagez >= h*2 || pagez < 0)
return 0;
else
{
int tSize = PagingLandScapeOptions::getSingleton().TileSize;
int tilex = (int) ((TileRefPos.x - ((pagex - w) * pSize)) / tSize);
int tilez = (int) ((TileRefPos.z - ((pagez - h) * pSize)) / tSize);
pSize = (pSize / tSize) - 1;
if (tilex > pSize)
tilex = pSize;
else if (tilex < 0)
tilex = 0;
if (tilez > pSize)
tilez = pSize;
else if (tilez < 0)
tilez = 0;
return mPages[pagex][pagez]->getTile (tilex, tilez);
}
}
//-----------------------------------------------------------------------
PagingLandScapeTile *PagingLandScapePageManager::getTile(const Vector3& pos)
{
int pSize = PagingLandScapeOptions::getSingleton().PageSize - 1;
Vector3 scale = PagingLandScapeOptions::getSingleton().scale;
int w = int (PagingLandScapeOptions::getSingleton().world_width * 0.5f);
int h = int (PagingLandScapeOptions::getSingleton().world_height * 0.5f);
Vector3 TileRefPos (pos.x / scale.x,
pos.y,
pos.z / scale.z);
int pagex = (int) (TileRefPos.x / pSize + w);
int pagez = (int) (TileRefPos.z / pSize + h );
// make sure indices are not negative or outside range of number of pages
if (pagex < 0 || pagex >= w*2 || pagez >= h*2 || pagez < 0)
return 0;
else
{
int tSize = PagingLandScapeOptions::getSingleton().TileSize;
int tilex = (int) ((TileRefPos.x - ((pagex - w) * pSize)) / tSize);
int tilez = (int) ((TileRefPos.z - ((pagez - h) * pSize)) / tSize);
pSize = (pSize / tSize) - 1;
if (tilex > pSize || tilex < 0 ||
tilez > pSize || tilez < 0)
return 0;
return mPages[pagex][pagez]->getTile (tilex, tilez);
}
}
//-----------------------------------------------------------------------
PagingLandScapeTile *PagingLandScapePageManager::getTile(const Vector3& pos, const uint &pagex, const uint &pagez)
{
Vector3 TileRefPos = pos;
TileRefPos.x = pos.x / PagingLandScapeOptions::getSingleton().scale.x;
TileRefPos.z = pos.z / PagingLandScapeOptions::getSingleton().scale.z;
int tSize = PagingLandScapeOptions::getSingleton().TileSize;
int pSize = PagingLandScapeOptions::getSingleton().PageSize - 1;
int tilex = (int) ((TileRefPos.x - ((pagex - PagingLandScapeOptions::getSingleton().world_width * 0.5f) * (pSize))) / tSize);
int tilez = (int) ((TileRefPos.z - ((pagez - PagingLandScapeOptions::getSingleton().world_height* 0.5f) * (pSize))) / tSize);
pSize = (pSize / tSize) - 1;
if (tilex > pSize || tilex < 0 ||
tilez > pSize || tilez < 0)
return 0;
return mPages[pagex][pagez]->getTile (tilex, tilez);
}
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?