// 初始化 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; } }
//初始化 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; } }