예제 #1
0
    void LoadingScreen::changeWallpaper ()
    {
        if (mResources.isNull ())
        {
            mResources = Ogre::StringVectorPtr (new Ogre::StringVector);

            Ogre::StringVectorPtr resources = Ogre::ResourceGroupManager::getSingleton ().listResourceNames ("General", false);
            for (Ogre::StringVector::const_iterator it = resources->begin(); it != resources->end(); ++it)
            {
                if (it->size() < 6)
                    continue;
                std::string start = it->substr(0, 6);
                boost::to_lower(start);

                if (start == "splash")
                    mResources->push_back (*it);
            }
        }

        if (mResources->size())
        {
            std::string randomSplash = mResources->at (rand() % mResources->size());

            Ogre::TexturePtr tex = Ogre::TextureManager::getSingleton ().load (randomSplash, "General");
            mBackgroundImage->setImageTexture (randomSplash);
        }
        else
            std::cerr << "No loading screens found!" << std::endl;
    }
예제 #2
0
void MainWindow::updateLevels()
{
    try
    {
        ClientPluginManager& pluginManager = EditorGlobals::mGrid->getActiveServer().getPluginManager();
        LevelManager& levelManager = pluginManager.getPlugin<LevelManager>();
        ResourceManager& resourceManager = pluginManager.getPlugin<ResourceManager>();
        Ogre::StringVectorPtr levels = levelManager.list();

        int numListLevels = qMin( levels->size(), (std::size_t)cMaxLevels );

        for( int i = 0; i < numListLevels; ++i ) 
        {
            Path filePath = resourceManager.getResourcePath() / levels->at( i );
            QString file = QString( filePath.string().c_str() );
            QString text = tr( "&%1 %2" ).arg( i + 1 ).arg( strippedName( file ) );
            mLevelActions[i]->setText( text );
            mLevelActions[i]->setData( file );
            mLevelActions[i]->setVisible( true );
        }

        for( int i = numListLevels; i < cMaxLevels; ++i )
            mLevelActions[i]->setVisible( false );
    }
    catch( Exception e )
    {
        // Ignore error	
    }
}
예제 #3
0
    void SoundManager::startRandomTitle()
    {
        Ogre::StringVector filelist;
        if (mMusicFiles.find(mCurrentPlaylist) == mMusicFiles.end())
        {
            Ogre::StringVector groups = Ogre::ResourceGroupManager::getSingleton().getResourceGroups ();
            for (Ogre::StringVector::iterator it = groups.begin(); it != groups.end(); ++it)
            {
                Ogre::StringVectorPtr resourcesInThisGroup = mResourceMgr.findResourceNames(*it,
                                                                                            "Music/"+mCurrentPlaylist+"/*");
                filelist.insert(filelist.end(), resourcesInThisGroup->begin(), resourcesInThisGroup->end());
            }
            mMusicFiles[mCurrentPlaylist] = filelist;
        }
        else
            filelist = mMusicFiles[mCurrentPlaylist];

        if(!filelist.size())
            return;

        int i = rand()%filelist.size();

        // Don't play the same music track twice in a row
        if (filelist[i] == mLastPlayedMusic)
        {
            i = (i+1) % filelist.size();
        }

        streamMusicFull(filelist[i]);
    }
const std::vector<std::string> ModelDefinitionManager::getAllMeshes() const
{
	std::vector<std::string> meshes;
	Ogre::StringVectorPtr meshesVector = Ogre::ResourceGroupManager::getSingleton().findResourceNames("General", "*.mesh");
	for (Ogre::StringVector::iterator I = meshesVector->begin(); I != meshesVector->end(); ++I) {
		meshes.push_back(std::string(*I));
	}
	meshesVector.setNull();
	return meshes;
}
예제 #5
0
void loadAllMaterialControlFiles(MaterialControlsContainer& controlsContainer)
{
    Ogre::StringVectorPtr fileStringVector = Ogre::ResourceGroupManager::getSingleton().findResourceNames( "Popular", "*.controls");
	Ogre::StringVector::iterator controlsFileNameIterator = fileStringVector->begin();

    while ( controlsFileNameIterator != fileStringVector->end() )
	{
        loadMaterialControlsFile(controlsContainer, *controlsFileNameIterator);
        ++controlsFileNameIterator;
	}
}
예제 #6
0
    void SoundManager::startRandomTitle()
    {
        Ogre::StringVectorPtr filelist;
        filelist = mResourceMgr.findResourceNames(Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME,
                                                  "Music/"+mCurrentPlaylist+"/*");
        if(!filelist->size())
            return;

        int i = rand()%filelist->size();
        streamMusicFull((*filelist)[i]);
    }
예제 #7
0
 void FontLoader::loadAllFonts(bool exportToFile)
 {
     Ogre::StringVector groups = Ogre::ResourceGroupManager::getSingleton().getResourceGroups ();
     for (Ogre::StringVector::iterator it = groups.begin(); it != groups.end(); ++it)
     {
         Ogre::StringVectorPtr resourcesInThisGroup = Ogre::ResourceGroupManager::getSingleton ().findResourceNames (*it, "*.fnt");
         for (Ogre::StringVector::iterator resource = resourcesInThisGroup->begin(); resource != resourcesInThisGroup->end(); ++resource)
         {
             loadFont(*resource, exportToFile);
         }
     }
 }
예제 #8
0
ResourceList ResourceManager::list()
{
    ResourceList resourceList;

    Ogre::StringVectorPtr resources = mRGM.findResourceNames( mGroup, "*" );
    
    for( Ogre::StringVector::const_iterator i = resources->begin(); i != resources->end(); ++i )
    {
        resourceList.push_back( Path( *i ) );
    }

    return resourceList;
}
예제 #9
0
CSMWorld::Resources::Resources (const std::string& baseDirectory, UniversalId::Type type,
    const char * const *extensions)
: mBaseDirectory (baseDirectory), mType (type)
{
    int baseSize = mBaseDirectory.size();

    Ogre::StringVector resourcesGroups =
        Ogre::ResourceGroupManager::getSingleton().getResourceGroups();

    for (Ogre::StringVector::iterator iter (resourcesGroups.begin());
        iter!=resourcesGroups.end(); ++iter)
    {
        if (*iter=="General" || *iter=="Internal" || *iter=="Autodetect")
            continue;

        Ogre::StringVectorPtr resources =
            Ogre::ResourceGroupManager::getSingleton().listResourceNames (*iter);

        for (Ogre::StringVector::const_iterator iter (resources->begin());
            iter!=resources->end(); ++iter)
        {
            if (static_cast<int> (iter->size())<baseSize+1 ||
                iter->substr (0, baseSize)!=mBaseDirectory ||
                ((*iter)[baseSize]!='/' && (*iter)[baseSize]!='\\'))
                continue;

            if (extensions)
            {
                std::string::size_type index = iter->find_last_of ('.');

                if (index==std::string::npos)
                    continue;

                std::string extension = iter->substr (index+1);

                int i = 0;

                for (; extensions[i]; ++i)
                    if (extensions[i]==extension)
                        break;

                if (!extensions[i])
                    continue;
            }

            std::string file = iter->substr (baseSize+1);
            mFiles.push_back (file);
            mIndex.insert (std::make_pair (file, static_cast<int> (mFiles.size())-1));
        }
    }
}
예제 #10
0
파일: MainFrm.cpp 프로젝트: mavaL/MiniCraft
bool CMainFrame::_CreateMeshPanel( CImageList& imageList, Ogre::StringVectorPtr& meshNames )
{
	if (!m_resourceSelector.Create(WS_CHILD|WS_VISIBLE, CRect(200,100,400,300), this, IDS_ResourceSelector))
		return false;

	m_resourceSelector.SetOwner(this);
	m_resourceSelector.SetIconSize(CSize(MESH_ICON_SIZE, MESH_ICON_SIZE));
	CXTPTaskPanelGroup* pGroup = m_resourceSelector.AddGroup(IDS_ResourceSelector_Mesh);

	int itemCount = imageList.GetImageCount();
 	m_resourceSelector.GetImageManager()->SetImageList(imageList.Detach(), 0);
	
	for (int i=0; i<itemCount; ++i)
	{
		std::wstring meshname(Utility::EngineToUnicode(meshNames->at(i)));
		meshname.erase(meshname.length()-5);
		// Add folder entries
		CXTPTaskPanelGroupItem* pItem = pGroup->AddLinkItem(i, 0);
		pItem->SetIconIndex(i);
		pItem->SetCaption(meshname.c_str());
	}
					
	m_resourceSelector.SetBehaviour(xtpTaskPanelBehaviourList);
	m_resourceSelector.SetSelectItemOnFocus(TRUE);
	m_resourceSelector.SetMultiColumn(TRUE);
	m_resourceSelector.SetColumnWidth(RES_SELECTOR_COLUMN_WIDTH);
	m_resourceSelector.GetAt(0)->SetExpanded(TRUE);
	//拖拽支持
	m_resourceSelector.AllowDrag(xtpTaskItemAllowDragCopyOutsideControl);

	return true;
}
예제 #11
0
    void SoundManager::startRandomTitle()
    {
        Ogre::StringVector filelist;

        Ogre::StringVector groups = Ogre::ResourceGroupManager::getSingleton().getResourceGroups ();
        for (Ogre::StringVector::iterator it = groups.begin(); it != groups.end(); ++it)
        {
            Ogre::StringVectorPtr resourcesInThisGroup = mResourceMgr.findResourceNames(*it,
                                                                                        "Music/"+mCurrentPlaylist+"/*");
            filelist.insert(filelist.end(), resourcesInThisGroup->begin(), resourcesInThisGroup->end());
        }

        if(!filelist.size())
            return;

        int i = rand()%filelist.size();
        streamMusicFull(filelist[i]);
    }
예제 #12
0
//-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
void
ResourceService::getResourceNames(I_ResourceNameVisitor& _visitor, 
                                  const std::string& _group,
                                  const std::string& _pattern) const
{
    _visitor.begin();

    Ogre::StringVectorPtr pStringVector = 
        m_groupManager.findResourceNames(_group, _pattern);

    Ogre::StringVector::iterator iter = pStringVector->begin();
    while (iter != pStringVector->end())
    {
        _visitor.visit(*iter);
        iter++;
    }

    _visitor.end();
}
예제 #13
0
    void LoadingScreen::changeWallpaper ()
    {
        std::vector<std::string> splash;

        Ogre::StringVectorPtr resources = Ogre::ResourceGroupManager::getSingleton ().listResourceNames ("General", false);
        for (Ogre::StringVector::const_iterator it = resources->begin(); it != resources->end(); ++it)
        {
            if (it->size() < 6)
                continue;
            std::string start = it->substr(0, 6);
            boost::to_lower(start);

            if (start == "splash")
                splash.push_back (*it);
        }
        std::string randomSplash = splash[rand() % splash.size()];

        Ogre::TexturePtr tex = Ogre::TextureManager::getSingleton ().load (randomSplash, "General");
        mBackgroundImage->setImageTexture (randomSplash);
    }
예제 #14
0
 void ResourceManager::DestroyAssetGroup(const String& GroupName)
 {
     for( std::vector<String>::iterator it = ResourceGroups.begin() ; it != ResourceGroups.end() ; it++ )
     {
         if(GroupName == (*it))
         {
             ResourceGroups.erase(it);
             break;
         }
     }
     /// @todo This is a bit of a hack, but needs to be here until we can upgrade our resource system.
     Ogre::StringVectorPtr ResourceNames = this->OgreResource->listResourceNames(GroupName,false);
     for( Whole X = 0 ; X < ResourceNames->size() ; ++X )
     {
         if(ResourceNames->at(X).find(".mesh"))
         {
             MeshManager::GetSingletonPtr()->UnloadMesh(ResourceNames->at(X));
         }
     }
     this->OgreResource->destroyResourceGroup(GroupName);
 }
//----------------------------------------------------------------------------//
size_t OgreResourceProvider::getResourceGroupFileNames(
    std::vector<String>& out_vec, const String& file_pattern,
    const String& resource_group)
{
    // get list of files in the group that match the pattern.
    Ogre::StringVectorPtr vp =
        Ogre::ResourceGroupManager::getSingleton().findResourceNames(
            (resource_group.empty() ?
                d_defaultResourceGroup.c_str() :
                resource_group.c_str()),
            file_pattern.c_str());

    size_t entries = 0;
    Ogre::StringVector::iterator i = vp->begin();
    for (; i != vp->end(); ++i)
    {
        out_vec.push_back(i->c_str());
        ++entries;
    }

    return entries;
}
void aiBehaviorTreeTemplateManager::LoadAll()
{
	Ogre::StringVectorPtr loc = Ogre::ResourceGroupManager::getSingleton().findResourceLocation("BehaviorTemplate", "*Behaviors");
	const STRING filename = loc->at(0) + "\\Script\\";

	//加载全局黑板xml
	Ogre::DataStreamPtr stream = Ogre::ResourceGroupManager::getSingleton().openResource("RaceGlobal.xml", "BehaviorTemplate");
	char* szData = strdup(stream->getAsString().c_str());

	rapidxml::xml_document<> XMLDoc;
	XMLDoc.parse<0>(szData);
	rapidxml::xml_node<>* pNode = XMLDoc.first_node("Root")->first_node("BlackBoard");

	while(pNode)
	{
		const STRING raceName = pNode->first_attribute("race")->value();
		rapidxml::xml_node<>* pVarNode = pNode->first_node("Variable");

		eGameRace race;
		if(raceName == "Terran") race = eGameRace_Terran;
		else if(raceName == "Zerg") race = eGameRace_Zerg;
		else assert(0);

		aiBlackBoard* bb = new aiBlackBoard;
		bb->LoadParams(pVarNode);
		m_globalBBs.insert(std::make_pair(race, bb));

		//脚本
		const char* szFilename = XMLDoc.first_node("Root")->first_node("Script")->first_attribute("filename")->value();
		const STRING filepath = filename + szFilename;
		SCRIPTNAMAGER.DoFile(filepath);

		pNode = pNode->next_sibling("BlackBoard");
	}

	free(szData);
	XMLDoc.clear();

	//加载各单位行为树xml
	Ogre::StringVectorPtr files = Ogre::ResourceGroupManager::getSingleton().findResourceNames("BehaviorTemplate", "*.xml");
	auto iter = std::find(files->begin(), files->end(), "RaceGlobal.xml");
	files->erase(iter);
	for (auto iter=files->begin(); iter!=files->end(); ++iter)
	{
		aiBehaviorTreeTemplate* pTmpl = new aiBehaviorTreeTemplate;
		const STRING name = pTmpl->Load(*iter);
		m_bts.insert(std::make_pair(name, pTmpl));
	}
}
예제 #17
0
    void LoadingScreen::changeWallpaper ()
    {
        if (mResources.empty())
        {
            Ogre::StringVector groups = Ogre::ResourceGroupManager::getSingleton().getResourceGroups ();
            for (Ogre::StringVector::iterator it = groups.begin(); it != groups.end(); ++it)
            {
                Ogre::StringVectorPtr resourcesInThisGroup = Ogre::ResourceGroupManager::getSingleton ().findResourceNames (*it, "Splash_*.tga");
                mResources.insert(mResources.end(), resourcesInThisGroup->begin(), resourcesInThisGroup->end());
            }
        }

        if (!mResources.empty())
        {
            std::string const & randomSplash = mResources.at (rand() % mResources.size());

            Ogre::TexturePtr tex = Ogre::TextureManager::getSingleton ().load (randomSplash, Ogre::ResourceGroupManager::AUTODETECT_RESOURCE_GROUP_NAME);

            mBackgroundImage->setImageTexture (randomSplash);
        }
        else
            std::cerr << "No loading screens found!" << std::endl;
    }
예제 #18
0
// 初始化
VOID CEngineInterface::Initial(VOID* pParam)
{
#if (_MSC_VER >= 1400)
	setlocale( LC_CTYPE, "" );
#endif

	//---------------------------------------------------------
	//取得渲染窗口句柄
	KLAssert(pParam);
	HWND hMainWnd = *((HWND*)pParam);
	g_hMainWnd = hMainWnd;

	g_pVaribleSys = (tVariableSystem*)g_theKernel.GetNode("bin\\var");
	KLAssert(g_pVaribleSys);

	g_pEventSys = (tEventSystem*)g_theKernel.GetNode("bin\\event");
	KLAssert(g_pEventSys);

	//---------------------------------------------------------

	// 改变加载方式
	// 屏掉下边这句了by czg 200911-30
	// CFairyScriptResGet::EnableResDynamicLoad(false);
	// 影响场景效果Z
	Ogre::SystemSetting::forcePixelShader(false);

	// 初始化KylinSystem
	m_pFairySystem->init("Resources.cfg", "", "", "Engine.log");	// Resources

	//---------------------------------------------------------
	// 加载OGRE插件
	g_pDebuger = (tDebuger*)g_theKernel.GetNode("bin\\debuger");

	g_pSoundSystem = (tSoundSystem*)g_theKernel.GetNode("bin\\snd");
	KLAssert(g_pSoundSystem);

	g_pWorldSystem = (tWorldSystem*)g_theKernel.GetNode("bin\\worldman");
	KLAssert(g_pWorldSystem);

	g_pTimeSystem = (tTimeSystem*)g_theKernel.GetNode("bin\\time");
	KLAssert(g_pTimeSystem);

	g_pResourceProvider = (tResourceProvider*)g_theKernel.GetNode("bin\\resprovider");
	KLAssert(g_pResourceProvider);
	g_pDataBase = (tDataBaseSystem*)g_theKernel.GetNode("bin\\dbc");
	KLAssert(g_pDataBase);

	STRING str = g_pVaribleSys->GetAs_String("Gfx_API");
	Ogre::Root* pTheRoot = &(Ogre::Root::getSingleton());
	// 选择渲染系统
	if(str == "Direct3D")
	{
#ifdef  USEOGRELIB
		Ogre::InstallD3D9Plugin();
#else
		pTheRoot->loadPlugin("RenderSystem_Direct3D9.dll");
		pTheRoot->setRenderSystem(pTheRoot->getRenderSystemByName("Direct3D9 Rendering Subsystem"));
#endif
	
	}
	else if(str == "OpenGL")
	{
#ifdef  USEOGRELIB
	
#else
		pTheRoot->loadPlugin("RenderSystem_GL.dll");
		pTheRoot->setRenderSystem(pTheRoot->getRenderSystemByName("OpenGL Rendering Subsystem"));
#endif
	}
	else 
		KLThrow("UnKnown RenderSystem!");
	// 加载其他插件
#ifdef  USEOGRELIB
	Ogre::InstallParticleFXPlugin();
	Ogre::InstallParticleFX2Plugin();
	Ogre::InstallOctreeScenePlugin();
	Ogre::InstallCgProgramManagerPlugin();
#else
	pTheRoot->loadPlugin("Plugin_ParticleFX.dll");
	pTheRoot->loadPlugin("Plugin_ParticleFX2.dll");
	pTheRoot->loadPlugin("Plugin_OctreeSceneManager.dll");
	pTheRoot->loadPlugin("Plugin_CgProgramManager.dll");
#endif
	

	// 分析资源
	ScriptParsingListener listener;
	try 
	{
		// 传入渲染窗口句柄
		Ogre::NameValuePairList ViewSetting;
		INT nFSAA = g_pVaribleSys->GetAs_Int(szFSAAVar);
		INT nVsync = g_pVaribleSys->GetAs_Int(szvsyncVar);

		switch(nFSAA)
		{
		case 0:
			ViewSetting["FSAA"]  = Ogre::StringConverter::toString(0);
			break;
		case 1:
			ViewSetting["FSAA"]  = Ogre::StringConverter::toString(2);
			break;
		case 2:
			ViewSetting["FSAA"]  = Ogre::StringConverter::toString(4);
			break;
		default:
			ViewSetting["FSAA"]  = Ogre::StringConverter::toString(0);
			break;
		}

		if(nVsync == 1)
			ViewSetting["vsync"] = "true";
		else
			ViewSetting["vsync"] = "false";

		m_pFairySystem->setup((Fairy::ulong)(UINT_PTR)g_hMainWnd, &ViewSetting);

		// 关闭OGRE图标
		m_pFairySystem->getFrameStatsListener()->showLogoPanel(FALSE);
		
		// 状态板
		m_pFairySystem->getFrameStatsListener()->showStatPanel(FALSE);

		// 创建射线交集
		m_pRaySceneQuery = m_pFairySystem->getSceneManager()->createRayQuery(Ogre::Ray());
        m_pRaySceneQuery->setSortByDistance(TRUE);

		//---------------------------------------------------------
		// 设置DebugPanel
		m_pDebugPanel = new CDebugPanel(Ogre::OverlayManager::getSingleton().getByName("WXSJ/DebugOverlay"),		// CJSH
										Ogre::OverlayManager::getSingleton().getOverlayElement("WXSJ/StatPanel"), 
										Ogre::OverlayManager::getSingleton().getOverlayElement("WXSJ/HitObjPanel"), 
										Ogre::OverlayManager::getSingleton().getOverlayElement("WXSJ/HitObjText"), 
										m_pFairySystem->getRenderWindow());

		//---------------------------------------------------------
		// 创建摄像机
		{
			// 设置摄像机
			// 取得环境变量
		
			BOOL bHave;
			FLOAT fCamera_MinDistance = g_pVaribleSys->GetAs_Float("Camera_MinDistance", &bHave);
			if(bHave) 
				CCamera_Scene::MIN_DISTANCE = fCamera_MinDistance;

			FLOAT fCamera_MaxDistance = g_pVaribleSys->GetAs_Float("Camera_MaxDistance", &bHave);
			if(bHave)
				CCamera_Scene::MAX_DISTANCE = fCamera_MaxDistance;

			FLOAT fCamera_Pitch = g_pVaribleSys->GetAs_Float("Camera_Pitch", &bHave);
			if(bHave) 
				CCamera_Scene::STATIC_PITCH = -fCamera_Pitch * KLU_PI / 180.0f;

			FLOAT fCamera_PitchApproch = g_pVaribleSys->GetAs_Float("Camera_PitchApproch", &bHave);
			if(bHave) 
				CCamera_Scene::APPROCH_PITCH = -fCamera_PitchApproch * KLU_PI / 180.0f;

/*
			// 摄象机偏移量
			INT fCamera_Offset = g_pVaribleSys->GetAs_Float("Camera_Varible_Offset", &bHave);
			if( bHave )
//				Camera_SetOffset( 0.0f, m_fVerticalOffset );
				m_fVerticalOffset = fCamera_Offset;
*/

/*
			fCamera_Offset = g_pVaribleSys->GetAs_Float("Camera_Parallel_Offset", &bHave);
			if( bHave )
				m_fSaveParallelOffset = fCamera_Offset;
*/
		}

		m_pCamera_CharView = new CCamera_CharSel(m_pFairySystem->getCamera());
		m_pCamera_Scene = new CCamera_Scene(m_pFairySystem->getCamera());
		m_pCamera_Scene->SetDistance(CCamera_Scene::MAX_DISTANCE);

		m_pCamera_Current = m_pCamera_CharView;

		//--------------------------------------------
		// 初始化PostFilter系统
		m_pPostFilterManager = m_pFairySystem->getPostFilterManager();
		// 注册所有全局渲染器
		Fairy::registerAllPostFilterFactories(m_pPostFilterManager);
		m_pPostFilterManager->createPostFilter("Floodlighting", m_pFairySystem->getViewport());
		m_pPostFilterManager->createPostFilter("Bloom", m_pFairySystem->getViewport());
		m_pPostFilterManager->createPostFilter("HeatVision", m_pFairySystem->getViewport());
		m_pPostFilterManager->createPostFilter("Fade", m_pFairySystem->getViewport());
		m_pPostFilterManager->createPostFilter("MotionBlur", m_pFairySystem->getViewport());

		//--------------------------------------------
		// 设置特效系统的声音播放函数
		Fairy::LogicModel::SetPlaySoundFuncton((OnPlaySound)(g_pSoundSystem->GetPlaySoundFunc()));
		Fairy::LogicModel::SetStopSoundFunction((OnStopSound)(g_pSoundSystem->GetStopSoundFunc()));
		Fairy::BulletSystem::SetPlaySoundFuncton((OnPlaySound)(g_pSoundSystem->GetPlaySoundFunc()));
		Fairy::BulletSystem::SetStopSoundFunction((OnStopSound)(g_pSoundSystem->GetStopSoundFunc()));
		Fairy::LogicModel::SetGetHeightInWorldListener((GetHeightInWorld)(g_pWorldSystem->GetTerrainHeightFunc()));

		// 初始化 fake obeject manager
		m_pFakeObjectManager = new CFakeObjectEntityManager;
		m_pFakeObjectManager->Initial();

//		Fairy::Effect::setDefaultIterativeInterval(0.01f);
		Ogre::ParticleSystem::setDefaultIterationInterval(0.033f);

		// 系统设置接口挂接变量控制系统
		g_pEventSys->RegisterEventHandle("VARIABLE_CHANGED",_OnVariableChangedEvent);

		// 恢复上次颜色设置
		g_pEventSys->PushEvent(GE_VARIABLE_CHANGED, sz32BitTexturesVar, g_pVaribleSys->GetAs_String(sz32BitTexturesVar).c_str());


//		Ogre::TextureManager::getSingleton().setDefaultNumMipmaps( 1 );


		// 加载人物阴影配置
		BOOL bHave;
		INT nHumanLightmap = g_pVaribleSys->GetAs_Float(szShadowTechniqueVar, &bHave );
		if( bHave )
			Scene_SetShadowTechnique( (BOOL)nHumanLightmap );

		// 加载全局泛光配置
		INT nFullScreenLight = g_pVaribleSys->GetAs_Float( szPostFilterEnabledVar, &bHave );
		if( bHave )
			Scene_SetPostFilterEnabled( (BOOL)nFullScreenLight );

		//初始化小地图探灯功能
		m_pMapLight = new CUIMapLight;
		m_pMapLight->Initial();

	} 
	catch(const Ogre::Exception& e)
	{
        BOOL rethrow = TRUE;

        if (e.getNumber() == Ogre::Exception::ERR_DUPLICATE_ITEM)
        {
            if (e.getSource() == "ResourceManager::add")
            {
                if (Ogre::StringUtil::endsWith(listener._scriptName, ".material", TRUE))
                {
                    char materialName[256];
                    if (sscanf(e.getDescription().c_str(), "Resource with the name %255s already exists.", materialName) == 1)
                    {
                        Ogre::MaterialPtr material = Ogre::MaterialManager::getSingleton().getByName(materialName);
                        if (!material.isNull())
                        {
                            char message[1024];

                            Ogre::StringVectorPtr currentNames = Fairy::findResourceFilenames(listener._groupName, listener._scriptName);
                            const Ogre::String& currentName = currentNames.isNull() || currentNames->empty() ? listener._scriptName : currentNames->front();
                            if (material->getOrigin().empty())
                            {
								_snprintf(message, 1024,
										("Predefined material \"%s\" duplicated in file \"%s\", the application will exit."),
                                        material->getName().c_str(), currentName.c_str());
                            }
                            else
                            {
                                Ogre::StringVectorPtr originNames = Fairy::findResourceFilenames(material->getGroup(), material->getOrigin());
                                const Ogre::String& originName = originNames.isNull() || originNames->empty() ? material->getOrigin() : originNames->front();
                                if (currentName == originName)
                                {
									_snprintf(message, 1024,
												("The material \"%s\" occuring in the file \"%s\" more than once, the application will exit."),
			                                    material->getName().c_str(), currentName.c_str());
                                }
                                else
                                {
									_snprintf(message, 1024,
											("Duplicate material \"%s\" in files \"%s\" and \"%s\", the application will exit."),
                                            material->getName().c_str(), currentName.c_str(), originName.c_str());
                                }
                            }

							KLThrow("Ogre::%s", message);
                        }
                    }
                }
            }
		}
		
		throw;
	}
}
예제 #19
0
//初始化
VOID CRenderSystem::Initial(VOID* pParam)
{
#if (_MSC_VER >= 1400)
//	std::locale langLocale("");
//	std::locale::global(langLocale);
	setlocale( LC_CTYPE, "" );
#endif
	//---------------------------------------------------------
	//取得渲染窗口句柄
	TDAssert(pParam);
	HWND hMainWnd = *((HWND*)pParam);
	g_hMainWnd = hMainWnd;

	g_pVaribleSys = (tVariableSystem*)g_pKernel->GetNode("bin\\var");
	TDAssert(g_pVaribleSys);

	g_pEventSys = (tEventSystem*)g_pKernel->GetNode("bin\\event");
	TDAssert(g_pEventSys);

	//---------------------------------------------------------
	//初始化RenderSystem
	m_pRenderSystem->init("WXResources.cfg", "", "", "WXRender.log");

	//---------------------------------------------------------
	//加载OGRE插件
	g_pDebuger = (tDebuger*)g_pKernel->GetNode("bin\\debuger");

	g_pSoundSystem = (tSoundSystem*)g_pKernel->GetNode("bin\\snd");
	TDAssert(g_pSoundSystem);

	g_pWorldSystem = (tWorldSystem*)g_pKernel->GetNode("bin\\worldman");
	TDAssert(g_pWorldSystem);

	g_pTimeSystem = (tTimeSystem*)g_pKernel->GetNode("bin\\time");
	TDAssert(g_pTimeSystem);

	g_pResourceProvider = (CResourceProvider*)g_pKernel->GetNode("bin\\resprovider");
	TDAssert(g_pResourceProvider);

	//STRING str = g_pVaribleSys->GetAs_String("Gfx_API");
	Ogre::Root* pTheRoot = &(Ogre::Root::getSingleton());

	//选择渲染系统
	//if(stricmp(g_pVaribleSys->GetAs_String("Gfx_API").c_str(), "Direct3D") == 0)
	//{
	//	pTheRoot->loadPlugin("RenderSystem_Direct3D9.dll");
	//	pTheRoot->setRenderSystem(pTheRoot->getRenderSystemByName("Direct3D9 Rendering Subsystem"));
	//}
	//else if(stricmp(g_pVaribleSys->GetAs_String("Gfx_API").c_str(), "OpenGL") == 0)
	//{
	//	TDThrow("Don't Support GL RenderSystem!");
	//	//pTheRoot->loadPlugin("RenderSystem_GL.dll");
	//	//pTheRoot->setRenderSystem(pTheRoot->getRenderSystemByName("OpenGL Rendering Subsystem"));
	//}
	//else 
	//	TDThrow("UnKnown RenderSystem!");


	//使用D3D渲染
	pTheRoot->loadRenderPlugins_D3D9();
	//加载其他插件
	pTheRoot->loadInnerPlugins();
	//pTheRoot->loadPlugin("Plugin_ParticleFX.dll");
	//pTheRoot->loadPlugin("Plugin_ParticleFX2.dll");
	//pTheRoot->loadPlugin("Plugin_OctreeSceneManager.dll");
	//pTheRoot->loadPlugin("Plugin_CgProgramManager.dll");

	//分析资源
	ScriptParsingListener listener;
	try 
	{
		//传入渲染窗口句柄
		WX::System::NameValuePairList ViewSetting;
		INT nFSAA = g_pVaribleSys->GetAs_Int(szFSAAVar);
		INT nVsync = g_pVaribleSys->GetAs_Int(szvsyncVar);

		switch(nFSAA)
		{
		case 0:
			ViewSetting["FSAA"]  = Ogre::StringConverter::toString(0);
			break;
		case 1:
			ViewSetting["FSAA"]  = Ogre::StringConverter::toString(2);
			break;
		case 2:
			ViewSetting["FSAA"]  = Ogre::StringConverter::toString(4);
			break;
		default:
			ViewSetting["FSAA"]  = Ogre::StringConverter::toString(0);
			break;
		}

		if(nVsync == 1)
			ViewSetting["vsync"] = "true";
		else
			ViewSetting["vsync"] = "false";

		m_pRenderSystem->setup((WX::ulong)(UINT_PTR)g_hMainWnd, &ViewSetting);

		//关闭OGRE图标
		m_pRenderSystem->getFrameStatsListener()->showLogoPanel(FALSE);
		
		//状态板
		m_pRenderSystem->getFrameStatsListener()->showStatPanel(FALSE);

		//创建射线交集
		m_pRaySceneQuery = m_pRenderSystem->getSceneManager()->createRayQuery(Ogre::Ray());
        m_pRaySceneQuery->setSortByDistance(TRUE);

		//---------------------------------------------------------
		//设置DebugPanel
		m_pDebugPanel = new CDebugPanel(
								Ogre::OverlayManager::getSingleton().getByName("WX/DebugOverlay"),
								Ogre::OverlayManager::getSingleton().getOverlayElement("WX/StatPanel"), 
								Ogre::OverlayManager::getSingleton().getOverlayElement("WX/HitObjPanel"), 
								Ogre::OverlayManager::getSingleton().getOverlayElement("WX/HitObjText"), 
								m_pRenderSystem->getRenderWindow());

		//---------------------------------------------------------
		//创建摄像机
		{
			//设置摄像机
			//取得环境变量
		
			BOOL bHave;
			FLOAT fCamera_MinDistance = g_pVaribleSys->GetAs_Float("Camera_MinDistance", &bHave);
			if(bHave) CCamera_Scene::MIN_DISTANCE = fCamera_MinDistance;

			FLOAT fCamera_MaxDistance = g_pVaribleSys->GetAs_Float("Camera_MaxDistance", &bHave);
			if(bHave) CCamera_Scene::MAX_DISTANCE = fCamera_MaxDistance;

			FLOAT fCamera_Pitch = g_pVaribleSys->GetAs_Float("Camera_Pitch", &bHave);
			if(bHave) CCamera_Scene::STATIC_PITCH = -fCamera_Pitch*TDU_PI/180.0f;
		}

		m_pCamera_CharView = new CCamera_CharSel(m_pRenderSystem->getCamera());
		m_pCamera_Scene = new CCamera_Scene(m_pRenderSystem->getCamera());
		m_pCamera_Scene->SetDistance(CCamera_Scene::MAX_DISTANCE);

		m_pCamera_Current = m_pCamera_CharView;

		//--------------------------------------------
		//初始化PostFilter系统
		m_pPostFilterManager = m_pRenderSystem->getPostFilterManager();
		//注册所有全局渲染器
		WX::registerAllPostFilterFactories(m_pPostFilterManager);
		m_pPostFilterManager->createPostFilter("Floodlighting", m_pRenderSystem->getViewport());
//		m_pPostFilterManager->createPostFilter("Bloom", m_pRenderSystem->getViewport());
//		m_pPostFilterManager->createPostFilter("HeatVision", m_pRenderSystem->getViewport());
		m_pPostFilterManager->createPostFilter("Fade", m_pRenderSystem->getViewport());

		//--------------------------------------------
		//设置特效系统的声音播放函数
		WX::LogicModel::SetPlaySoundFuncton((OnPlaySound)(g_pSoundSystem->GetPlaySoundFunc()));
		WX::LogicModel::SetStopSoundFunction((OnStopSound)(g_pSoundSystem->GetStopSoundFunc()));
		WX::LogicModel::SetGetHeightInWorldListener((GetHeightInWorld)(g_pWorldSystem->GetTerrainHeightFunc()));

		// 初始化 fake obeject manager
		m_pFakeObjectManager = new CFakeObjectManager;
		m_pFakeObjectManager->Initial();

//		WX::Effect::setDefaultIterativeInterval(0.01f);
		Ogre::ParticleSystem::setDefaultIterationInterval(0.033f);

		//系统设置接口挂接变量控制系统
		g_pEventSys->RegisterEventHandle("VARIABLE_CHANGED",_OnVariableChangedEvent);

		//恢复上次颜色设置
		g_pEventSys->PushEvent(
            GE_VARIABLE_CHANGED, 
			sz32BitTexturesVar, 
			g_pVaribleSys->GetAs_String(sz32BitTexturesVar).c_str());

	} 
	catch(const Ogre::Exception& e)
	{
        BOOL rethrow = TRUE;

        if (e.getNumber() == Ogre::Exception::ERR_DUPLICATE_ITEM)
        {
            if (e.getSource() == "ResourceManager::add")
            {
                if (Ogre::StringUtil::endsWith(listener._scriptName, ".material", TRUE))
                {
                    char materialName[256];
                    if (sscanf(e.getDescription().c_str(), "Resource with the name %255s already exists.", materialName) == 1)
                    {
                        Ogre::MaterialPtr material = Ogre::MaterialManager::getSingleton().getByName(materialName);
                        if (!material.isNull())
                        {
                            char message[1024];

                            Ogre::StringVectorPtr currentNames = WX::findResourceFilenames(listener._groupName, listener._scriptName);
                            const Ogre::String& currentName = currentNames.isNull() || currentNames->empty() ? listener._scriptName : currentNames->front();
                            if (material->getOrigin().empty())
                            {
								_snprintf(message, 1024,
										("Predefined material \"%s\" duplicated in file \"%s\", the application will exit."),
                                        material->getName().c_str(), currentName.c_str());
                            }
                            else
                            {
                                Ogre::StringVectorPtr originNames = WX::findResourceFilenames(material->getGroup(), material->getOrigin());
                                const Ogre::String& originName = originNames.isNull() || originNames->empty() ? material->getOrigin() : originNames->front();
                                if (currentName == originName)
                                {
									_snprintf(message, 1024,
												("The material \"%s\" occuring in the file \"%s\" more than once, the application will exit."),
			                                    material->getName().c_str(), currentName.c_str());
                                }
                                else
                                {
									_snprintf(message, 1024,
											("Duplicate material \"%s\" in files \"%s\" and \"%s\", the application will exit."),
                                            material->getName().c_str(), currentName.c_str(), originName.c_str());
                                }
                            }

							TDThrow("Ogre::%s", message);
                        }
                    }
                }
            }
		}
		
		throw;
	}
}