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

📄 ogrepaginglandscapescenemanager.cpp

📁 使用stl技术,(还没看,是听说的)
💻 CPP
📖 第 1 页 / 共 2 页
字号:
/***************************************************************************
	OgrePagingLandScapeSceneManager.cpp  -  description
	-------------------
	begin                : Mon May 12 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 <OgreCamera.h>
#include <OgreException.h>
#include <OgreStringConverter.h>
#include <OgreRenderSystem.h>
#include <fstream>
#include <OgreSDDataChunk.h>

#include <OgreOverlay.h>
#include <OgreGuiManager.h>
#include <OgreGuiElement.h>

#include "OgrePagingLandScapeSceneManager.h"
#include "OgrePagingLandScapeRenderable.h"
#include "OgrePagingLandScapeRenderableManager.h"
#include "OgrePagingLandScapeTile.h"
#include "OgrePagingLandScapeTileManager.h"
#include "OgrePagingLandScapeIntersectionSceneQuery.h"
#include "OgrePagingLandScapeRaySceneQuery.h"

namespace Ogre
{

//-----------------------------------------------------------------------
PagingLandScapeSceneManager::PagingLandScapeSceneManager() : SceneManager( )
{
//	showBoundingBoxes(true);
//	setDisplaySceneNodes(true);
	mCurrentCameraPageX = 0;
	mCurrentCameraPageZ = 0;
	mLastCameraPageState = PAGE_CHANGE;
	mTileManager = 0;
	mRenderableManager = 0;
	mNeedOptionsUpdate = false;
	mLastCameraPos = Vector3(-999999,9999999,-999999);
	//JEFF
	mWorldGeomIsSetup = false;
}

//-----------------------------------------------------------------------
PagingLandScapeSceneManager::~PagingLandScapeSceneManager()
{
	// JEFF
	// This gets done in clearScene
/*
	for ( int i = 0; i < mOptions.world_width; i++ )
	{
		for ( int j = 0; j < mOptions.world_height; j++ )
		{
			if ( mPages[ i ][ j ] != 0 )
			{
				delete mPages[ i ][ j ];
			}
		}
	}
*/
	clearScene();
}

//-----------------------------------------------------------------------
void PagingLandScapeSceneManager::setWorldGeometry( const String& filename )
{
	if ( mWorldGeomIsSetup == true )
	{
		clearScene();
	}
	// Load the config file
	mOptions.load( filename );
	mPause = 99;

	// Create the Tile and Renderable Manager
	mTileManager = new PagingLandScapeTileManager();
	mRenderableManager = new PagingLandScapeRenderableManager();

	int i, j;

	//setup the page array.
	for ( i = 0; i < mOptions.world_width; i++ )
	{
		mPages.push_back( PagingLandScapePageRow() );

		for ( j = 0; j < mOptions.world_height; j++ )
		{
			mPages[ i ].push_back( 0 );
		}
	}

	// populate the page array
	for ( j = 0; j < mOptions.world_height; j++ )
	{
		for ( i = 0; i < mOptions.world_width; i++ )
		{
			PagingLandScapePage *page = new PagingLandScapePage( i, j );

			mPages[ i ][ j ] = page;

		}
	}

	//setup the neighbor links.
	for ( j = 0; j < mOptions.world_height; j++ )
	{
		for ( i = 0; i < mOptions.world_width; i++ )
		{
			if ( j != mOptions.world_height - 1 )
			{
				mPages[ i ][ j ] -> setNeighbor( PagingLandScapeTile::EAST, mPages[ i ][ j + 1 ] );
				mPages[ i ][ j + 1 ] -> setNeighbor( PagingLandScapeTile::WEST, mPages[ i ][ j ] );
			}
			if ( i != mOptions.world_width - 1 )
			{
				mPages[ i ][ j ] -> setNeighbor( PagingLandScapeTile::SOUTH, mPages[ i + 1 ][ j ] );
				mPages[ i + 1 ][ j ] -> setNeighbor( PagingLandScapeTile::NORTH, mPages[ i ][ j ] );
			}
		}
	}
	mWorldGeomIsSetup = true;
}

//-----------------------------------------------------------------------
void PagingLandScapeSceneManager::clearScene(void)
{
	//JEFF let base class do this
/*
	if ( mSceneRoot != 0 )
	{
		// Unload the nodes
		mSceneRoot -> detachAllObjects();
		mSceneRoot -> removeAllChildren();

		getRootSceneNode() -> removeChild( mSceneRoot->getName() );
		delete mSceneRoot;

		mSceneRoot = 0;
	}
*/
	if ( mWorldGeomIsSetup == true )
	{
		mWorldGeomIsSetup = false;

		//TODO: check this, since this crash the plugin and will generate MemLeaks if not called.
		for ( int i = 0; i < mOptions.world_width; i++ )
		{
			for ( int j = 0; j < mOptions.world_height; j++ )
			{
				if ( mPages[ i ][ j ] != 0 )
				{
					delete mPages[ i ][ j ];
					//JEFF
					// set to NULL
					mPages[ i ][ j ] = 0;
				}
			}
		}
		mPages.clear();
		// Delete the Managers
		if ( mTileManager != 0 ) 
		{
			delete mTileManager;
			mTileManager = 0;
		}
		if ( mRenderableManager != 0 )
		{
			delete mRenderableManager;
			mRenderableManager = 0;
		}
	}
	//Call the default
	SceneManager::clearScene();
}

//-----------------------------------------------------------------------
bool PagingLandScapeSceneManager::setOption( const String& strKey, const void* pValue )
{
	mNeedOptionsUpdate = mOptions.setOption( strKey, pValue );
	return mNeedOptionsUpdate;
}

//-----------------------------------------------------------------------
bool PagingLandScapeSceneManager::getOption( const String& strKey, void* pDestValue )
{
	if ( strKey == "CurrentCameraPageX" )
	{
		* static_cast < int * > ( pDestValue ) = mCurrentCameraPageX;
		return true;
	}
	if ( strKey == "CurrentCameraPageZ" )
	{
		* static_cast < int * > ( pDestValue ) = mCurrentCameraPageZ;
		return true;
	}
	if ( strKey == "TileMerge" )
	{
		* static_cast < int * > ( pDestValue ) = mTileManager->numMerge();
		return true;
	}
	if ( strKey == "TileSplit" )
	{
		* static_cast < int * > ( pDestValue ) = mTileManager->numSplit();
		return true;
	}
	if ( strKey == "RenderableMorph" )
	{
		* static_cast < int * > ( pDestValue ) = mRenderableManager->numMorph();
		return true;
	}
	if ( strKey == "RenderableDeMorph" )
	{
		* static_cast < int * > ( pDestValue ) = mRenderableManager->numDeMorph();
		return true;
	}
	if ( strKey == "TileFree" )
	{
		* static_cast < int * > ( pDestValue ) = mTileManager->numFree();
		return true;
	}
	if ( strKey == "RenderableFree" )
	{
		* static_cast < int * > ( pDestValue ) = mRenderableManager->numFree();
		return true;
	}
	if ( strKey == "PagePreloadQueue" )
	{
		* static_cast < int * > ( pDestValue ) = mPagePreloadQueue.getSize();
		return true;
	}
	if ( strKey == "PageLoadQueue" )
	{
		* static_cast < int * > ( pDestValue ) = mPageLoadQueue.getSize();
		return true;
	}
	if ( strKey == "PageUnloadQueue" )
	{
		* static_cast < int * > ( pDestValue ) = mPageUnloadQueue.getSize();
		return true;
	}
	if ( strKey == "PagePostUnloadQueue" )
	{
		* static_cast < int * > ( pDestValue ) = mPagePostunloadQueue.getSize();
		return true;
	}
	return mOptions.getOption( strKey, pDestValue );
}

//-----------------------------------------------------------------------
bool PagingLandScapeSceneManager::hasOption( const String& strKey )
{
	if ( strKey == "CurrentCameraPageX" )
	{
		return true;
	}
	if ( strKey == "CurrentCameraPageZ" )
	{
		return true;
	}
	if ( strKey == "TileMerge" )
	{
		return true;
	}
	if ( strKey == "TileSplit" )
	{
		return true;
	}
	if ( strKey == "RenderableMorph" )
	{
		return true;
	}
	if ( strKey == "RenderableDeMorph" )
	{
		return true;
	}
	if ( strKey == "TileFree" )
	{
		return true;
	}
	if ( strKey == "RenderableFree" )
	{
		return true;
	}
	if ( strKey == "PagePreloadQueue" )
	{
		return true;
	}
	if ( strKey == "PageLoadQueue" )
	{
		return true;
	}
	if ( strKey == "PageUnloadQueue" )
	{
		return true;
	}
	if ( strKey == "PagePostUnloadQueue" )
	{
		return true;
	}
	return mOptions.hasOption( strKey );
}

//-----------------------------------------------------------------------
bool PagingLandScapeSceneManager::getOptionValues( const String& strKey, std::list<SDDataChunk>& refValueList )
{
	if ( strKey == "CurrentCameraPageX" )
	{
		refValueList.push_back(SDDataChunk());
		return true;
	}
	if ( strKey == "CurrentCameraPageZ" )
	{
		refValueList.push_back(SDDataChunk());
		return true;
	}
	if ( strKey == "TileMerge" )
	{
		refValueList.push_back(SDDataChunk());
		return true;
	}
	if ( strKey == "TileSplit" )
	{
		refValueList.push_back(SDDataChunk());
		return true;
	}
	if ( strKey == "RenderableMorph" )
	{
		refValueList.push_back(SDDataChunk());
		return true;
	}
	if ( strKey == "RenderableDeMorph" )
	{
		refValueList.push_back(SDDataChunk());
		return true;
	}
	if ( strKey == "TileFree" )
	{
		refValueList.push_back(SDDataChunk());
		return true;
	}
	if ( strKey == "RenderableFree" )
	{
		refValueList.push_back(SDDataChunk());
		return true;
	}
	if ( strKey == "PagePreloadQueue" )
	{
		refValueList.push_back(SDDataChunk());
		return true;
	}
	if ( strKey == "PageLoadQueue" )
	{
		refValueList.push_back(SDDataChunk());
		return true;
	}
	if ( strKey == "PageUnloadQueue" )
	{
		refValueList.push_back(SDDataChunk());
		return true;
	}
	if ( strKey == "PagePostUnloadQueue" )
	{
		refValueList.push_back(SDDataChunk());
		return true;
	}
	return mOptions.getOptionValues( strKey, refValueList );
}

//-----------------------------------------------------------------------
bool PagingLandScapeSceneManager::getOptionKeys( std::list<String>& refKeys )
{
	refKeys.clear();
	refKeys.push_back( "CurrentCameraPageX" );
	refKeys.push_back( "CurrentCameraPageZ" );

⌨️ 快捷键说明

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