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

📄 ogrepaginglandscapescenemanager.cpp

📁 使用stl技术,(还没看,是听说的)
💻 CPP
📖 第 1 页 / 共 2 页
字号:
	refKeys.push_back( "TileMerge" );
	refKeys.push_back( "TileSplit" );
	refKeys.push_back( "RenderableMorph" );
	refKeys.push_back( "RenderableDeMorph" );
	refKeys.push_back( "TileFree" );
	refKeys.push_back( "RenderableFree" );
	refKeys.push_back( "PagePreloadQueue" );
	refKeys.push_back( "PageLoadQueue" );
	refKeys.push_back( "PageUnloadQueue" );
	refKeys.push_back( "PagePostUnloadQueue" );
	return mOptions.getOptionKeys( refKeys );
}

//-----------------------------------------------------------------------
void PagingLandScapeSceneManager::_updateSceneGraph( Camera * cam )
{
	bool bNeedUpdate = false;
	int i, j, iniX, iniZ, finX, finZ;
	int preIniX, preIniZ, preFinX, preFinZ;

	// entry into here could come before setWorldGeometry got called which could be disasterous
	// so check for init

	if(mWorldGeomIsSetup)
	{
		// Here we have to look if we have to load, unload any of the LandScape Pages
		//Vector3 pos = cam->getPosition();
		// Fix from Praetor, so the camera used gives you "world-relative" coordinates
		Vector3 pos = cam->getDerivedPosition();

		//updateStats( pos );

		// Update only if the camera was moved
		if ( PagingLandScapeOptions::getSingleton().cameraThreshold <= (mLastCameraPos - pos).squaredLength() )
		{

			// make sure in the bounding box of landscape
			float camy = pos.y;
			pos.y = 127;
			// Check for the camera position in the LandScape Pages list, we check if we are in the inside the security zone
			//  if not, launch the chage routine and update the camera position mCurrentCameraX, mCurrentCameraY.
			if ( mPages[ mCurrentCameraPageX ][ mCurrentCameraPageZ ] -> isCameraIn( pos ) != PAGE_INSIDE )
			{
				// JEFF
				// convert camera pos to page index
				getPageIndices(pos, i, j);
				if ( mPages[ i ][ j ] -> isCameraIn ( pos ) == PAGE_INSIDE )
				{
					if ( ( mCurrentCameraPageX != i ) || ( mCurrentCameraPageZ != j ) )
					{
						// We must load the next visible landscape pages, and unload the last visibles
						iniX = i - mOptions.max_adjacent_pages;
						iniZ = j - mOptions.max_adjacent_pages;
						finX = i + mOptions.max_adjacent_pages;
						finZ = j + mOptions.max_adjacent_pages;
						preIniX = i - mOptions.max_preload_pages;
						preIniZ = j - mOptions.max_preload_pages;
						preFinX = i + mOptions.max_preload_pages;
						preFinZ = j + mOptions.max_preload_pages;
						bNeedUpdate = true;
						// update the camera page position
						mCurrentCameraPageX = i;
						mCurrentCameraPageZ = j;
					}
				}
			}
			// restore camera height so that tiling is affected by height
			pos.y = camy;
			// Update the last camera position
			mLastCameraPos = pos;
		}
		if ( bNeedUpdate == true )
		{
			// check the landscape boundaries
			if ( iniX < 0 )
			{
				iniX = 0;
			}
			if ( iniZ < 0 )
			{
				iniZ = 0;
			}
			if ( finX >= mOptions.world_width )
			{
				finX = mOptions.world_width - 1;
			}
			if ( finZ >= mOptions.world_height )
			{
				finZ = mOptions.world_height - 1;
			}
			// Check the preload boundaries
			if ( preIniX < 0 )
			{
				preIniX = 0;
			}
			if ( preIniZ < 0 )
			{
				preIniZ = 0;
			}
			if ( preFinX >= mOptions.world_width )
			{
				preFinX = mOptions.world_width - 1;
			}
			if ( preFinZ >= mOptions.world_height )
			{
				preFinZ = mOptions.world_height - 1;
			}

			// Have the current page be loaded now
			if ( mPages[ mCurrentCameraPageX ][ mCurrentCameraPageZ ]->isPreLoaded() == false )
			{
				mPages[ mCurrentCameraPageX ][ mCurrentCameraPageZ ]->preload();
			}
			if ( mPages[ mCurrentCameraPageX ][ mCurrentCameraPageZ ]->isLoaded() == false )
			{
				mPages[ mCurrentCameraPageX ][ mCurrentCameraPageZ ]->load( * mSceneRoot );
			}
			// Queue the rest
			for ( j = 0; j < mOptions.world_height; j++ )
			{
				for ( i = 0; i < mOptions.world_width; i++ )
				{
					// Loading and unloading must be done one by one to avoid FPS drop, so they are queue.
					// No need to queue for preload since _ProcessLoading will do it in Load if required.								
					if ( ( ( j < preIniZ ) || ( j > preFinZ ) ) || ( ( i < preIniX ) || ( i > preFinX ) ) )
					{
						// post unload as required
						mPagePostunloadQueue.push( mPages[ i ][ j ] );
					}
					else
					{			
						if ( ( ( j < iniZ ) || ( j > finZ ) ) || ( ( i < iniX ) || ( i > finX ) ) )
						{
							// unload as required
							mPageUnloadQueue.push( mPages[ i ][ j ] );
						}
						else
						{
							// load as required
							mPageLoadQueue.push( mPages[ i ][ j ] );
						}
					}
				}
			}
		}
		// Preload, load, unload and postunload as required
		_ProcessLoading();

		_ProcessMergeSplit( pos );
	}
	// Call the default
	SceneManager::_updateSceneGraph( cam );
}

//-----------------------------------------------------------------------
void PagingLandScapeSceneManager::_ProcessLoading( void )
{
	// Preload, load, unload and postunload 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() == true )
					{
						// If we are not postunloaded the queue again
						mPagePostunloadQueue.push( e );
					}										
				}
			}
		}
	}
}

//-----------------------------------------------------------------------
void PagingLandScapeSceneManager::_ProcessMergeSplit( const Vector3 & pos )
{
	mPause++;
	if ( mPause >= 16 )
	{
		//Check the Merge and Split
		for ( int i = 0; i < mOptions.world_width; i++ )
		{
			for ( int j = 0; j < mOptions.world_height; j ++ )
			{
				mPages[ i ][ j ] -> _notify( pos, mNeedOptionsUpdate );
			}
		}
		mPause = 0;
	}

	if ( mNeedOptionsUpdate )
	{
		mTileManager->updateCache();
		mRenderableManager->updateCache();
		mNeedOptionsUpdate = false;
	}

	mTileManager->Merge();
	mTileManager->Split();
	mRenderableManager->Morph();
	mRenderableManager->DeMorph();	
}

//-----------------------------------------------------------------------
void PagingLandScapeSceneManager::_renderVisibleObjects( void )
{

	SceneManager::_renderVisibleObjects();
	// Reset the traingle count
	PagingLandScapeRenderable::mRenderedTris = 0;

}

//-----------------------------------------------------------------------
void PagingLandScapeSceneManager::_findVisibleObjects ( Camera * cam )
{
	SceneManager::_findVisibleObjects( cam, false );
}

//----------------------------------------------------------------------------
IntersectionSceneQuery* PagingLandScapeSceneManager::createIntersectionQuery(unsigned long mask)
{
	PagingLandScapeIntersectionSceneQuery* q = new PagingLandScapeIntersectionSceneQuery(this);
	q->setQueryMask(mask);
	return q;
}

//----------------------------------------------------------------------------
RaySceneQuery* PagingLandScapeSceneManager::createRayQuery(const Ray& ray, unsigned long mask)
{
	PagingLandScapeRaySceneQuery* q = new PagingLandScapeRaySceneQuery(this);
	q->setRay(ray);
	q->setQueryMask(mask);
	return q;
}

// JEFF
//----------------------------------------------------------------------------
float PagingLandScapeSceneManager::getRealWorldHeight(float x, float z)
{
	int i, j;
	// figure out which page the point is on
	getPageIndices(Vector3(x, 0, z), i, j);

	// scale position from world to page scale
	x /= mOptions.scale.x;
	z /= mOptions.scale.z;

	// adjust x and z to be local to page
	x -= (float)(i + i - mOptions.world_width) / 2.0 * (mOptions.PageSize - 1);
	z -= (float)(j + j - mOptions.world_height) / 2.0 * (mOptions.PageSize - 1);

	// make sure x and z do not go outside the world boundries
	if (x < 0)
	{
		x = 0;
	}
	else if (x > (mOptions.PageSize - 1)) 
	{
		x = mOptions.PageSize - 1;
	}

	if (z < 0)
	{
		z = 0;
	}
	else if (z > (mOptions.PageSize - 1))
	{
		z = mOptions.PageSize - 1;
	}

	// get the page node to return the real world height
	return mPages[ i ][ j ] -> getRealWorldHeight( x, z );
}

// JEFF
//----------------------------------------------------------------------------
/// methad takes an UP vector and determines the indexes for the page the UP vector would be in
void PagingLandScapeSceneManager::getPageIndices(const Vector3& pos, int& x, int& z)
{
	x = (int)(pos.x / mOptions.scale.x / (mOptions.PageSize - 1.0) + mOptions.world_width / 2.0);
	z = (int)(pos.z / mOptions.scale.z / (mOptions.PageSize - 1.0) + mOptions.world_height / 2.0);

	// make sure indices are not negative or outside range of number of pages
	if (x < 0)
	{
		x = 0;
	}
	else if (x >= mOptions.world_width) 
	{
		x = mOptions.world_width - 1;
	}

	if (z < 0)
	{
		z = 0;
	}
	else if (z >= mOptions.world_height) 
	{
		z = mOptions.world_height - 1;
	}
}

/*
//----------------------------------------------------------------------------
void PagingLandScapeSceneManager::updateStats( const Vector3 & pos )
{
	static String Aux1 = "Page (X, Z): (";
	static String Aux2 = "Queue (Merges, Splits, Morphs, DeMorphs): (";
	static String Aux3 = "Tiles (Used, Free): (";
	static String Aux4 = "Renderables (Used, Free): (";
	static String Aux5 = "Player (X, Y, Z): (";
	static String Aux6 = "Queues (PreLoad, Load, Unload, PostUnload): (";
	//Debug Overlay
	if ( this->getOverlay( "PagingLandScape/DebugOverlay" ) -> isVisible() == true )
	{
		// Debug Text
		GuiManager::getSingleton().getGuiElement("PagingLandScape/Page")->setCaption( Aux1 + 
			StringConverter::toString(mCurrentCameraPageX) + ", " + 
			StringConverter::toString(mCurrentCameraPageZ) + ")" );
		GuiManager::getSingleton().getGuiElement("PagingLandScape/Queue")->setCaption( Aux2 + 
			StringConverter::toString(mTileManager->numMerge()) + ", " + 
			StringConverter::toString(mTileManager->numSplit()) + ", " +
			StringConverter::toString(mRenderableManager->numMorph()) + ", " +
			StringConverter::toString(mRenderableManager->numDeMorph()) + ")" );
		int i = mTileManager->numFree();
		GuiManager::getSingleton().getGuiElement("PagingLandScape/FreeTiles")->setCaption( Aux3 + 
			StringConverter::toString(mOptions.num_tiles - i) + ", " + 
			StringConverter::toString(i) + ")" );
		i = mRenderableManager->numFree();
		GuiManager::getSingleton().getGuiElement("PagingLandScape/FreeRenderables")->setCaption( Aux4 + 
			StringConverter::toString(mOptions.num_renderables - i) + ", " + 
			StringConverter::toString(i) + ")" );
		GuiManager::getSingleton().getGuiElement("PagingLandScape/Player")->setCaption( Aux5 + 
			StringConverter::toString(pos.x) + ", " + 
			StringConverter::toString(pos.y) + ", " +
			StringConverter::toString(pos.z) + ")" );
		GuiManager::getSingleton().getGuiElement("PagingLandScape/MainQueue")->setCaption( Aux6 + 
			StringConverter::toString(mPagePreloadQueue.getSize()) + ", " + 
			StringConverter::toString(mPageLoadQueue.getSize()) + ", " +
			StringConverter::toString(mPageUnloadQueue.getSize()) + ", " +
			StringConverter::toString(mPagePostunloadQueue.getSize()) + ")" );
	}
}
*/

} //namespace

⌨️ 快捷键说明

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