00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00034 #include "SO3Root.h"
00035 #include "SO3Window.h"
00036 #include "SO3WidgetManager.h"
00037 #include "SO3KeyboardHook.h"
00038 #include "SO3FlashWidgetFactory.h"
00039 #include "SO3BitmapWidgetFactory.h"
00040 #include "SO3ObjWindowWidgetFactory.h"
00041 #include "../SO3Material/SO3Compositor.h"
00042 #include "../SO3Material/SO3Material.h"
00043 #include "../SO3SceneGraph/SO3Scene.h"
00044 #include "../SO3Utils/SO3ScolFileSystem.h"
00045 #include "../SO3Utils/SO3ScolUrl.h"
00046 #include "../SO3Utils/SO3ConversionTools.h"
00047 #include "../SO3Utils/SO3PluginManager.h"
00048 #include "../SO3Utils/SO3BaseMeshsTools.h"
00049 #include "../SCOLPack/SO3SCOL.h"
00050 #include "SO3LogListener.h"
00051
00052
00053 #include <scol.h>
00054
00055 extern int SO3_LOGS_MSG;
00056
00057 namespace Ogre
00058 {
00059 template<> SRoot* Ogre::Singleton<SRoot>::ms_Singleton = 0;
00060 }
00061
00062 namespace SO3
00063 {
00064
00065 SRoot* SRoot::getSingletonPtr()
00066 {
00067 return ms_Singleton;
00068 }
00069
00070 SRoot& SRoot::getSingleton()
00071 {
00072 assert(ms_Singleton);
00073 return (*ms_Singleton);
00074 }
00075
00076 SRoot::SRoot(WindowHandle windowHandle)
00077 {
00078
00079 rootWindowHandle = windowHandle;
00080
00081
00082 renderSystem = SO3_NONE_RENDER_SYSTEM;
00083 fullScreenWindow = 0;
00084 debugPanelInitialized = false;
00085 dummyWindow = 0;
00086
00087
00088 staticPluginStereo = 0;
00089 staticPluginOctree = 0;
00090 staticPluginCG = 0;
00091 staticPluginParticleFX = 0;
00092
00093
00094 #ifdef SO3_DEVELOPPER_BUILD
00095 staticPluginD3D9 = 0;
00096
00097
00098 staticPluginOpenGL = 0;
00099 # if SO3_PLUGIN_WEB_MANAGER_BUILD == 1
00100 staticWebNavigatorPlugin = 0;
00101 # endif
00102 #endif
00103
00104
00105 #if SO3_DEBUG
00106
00107 O3Root = OGRE_NEW Ogre::Root();
00108 #else
00109 O3Root = OGRE_NEW Ogre::Root("", "", "");
00110 #endif
00111
00112
00113 pluginManager = new SPluginManager();
00114
00115
00116 widgetManager = new SWidgetManager();
00117
00118
00119 flashWidgetFactory = new SFlashWidgetFactory();
00120 widgetManager->AddWidgetFactory(flashWidgetFactory);
00121
00122
00123 bitmapWidgetFactory = new SBitmapWidgetFactory();
00124 widgetManager->AddWidgetFactory(bitmapWidgetFactory);
00125
00126
00127 objWindowWidgetFactory = new SObjWindowWidgetFactory();
00128 widgetManager->AddWidgetFactory(objWindowWidgetFactory);
00129
00130 keyboardHook = new SKeyboardHook();
00131
00132 LoadOgrePlugins();
00133
00134
00135 LoadSO3Plugins();
00136
00137 mLogEnable = false;
00138 Ogre::LogManager::getSingleton().getDefaultLog()->addListener((Ogre::LogListener*)this);
00139 }
00140
00141 WindowHandle SRoot::GetRootWindowHandle()
00142 {
00143 return rootWindowHandle;
00144 }
00145
00146 Ogre::Root* SRoot::GetOgreRootPointer()
00147 {
00148 return O3Root;
00149 }
00150
00151 void SRoot::messageLogged(const Ogre::String& message, Ogre::LogMessageLevel lml, bool maskDebug, const Ogre::String &logName, bool& skipMessage)
00152 {
00153 if (mLogEnable)
00154 {
00155 LogListenerList::iterator iLogListenerList = logListenerList.begin();
00156 while(iLogListenerList != logListenerList.end())
00157 {
00158 (*iLogListenerList)->messageLogged(message);
00159 iLogListenerList++;
00160 }
00161 }
00162 }
00163
00164 void SRoot::AddLogListener(SLogListener* newLogListener)
00165 {
00166 if(logListenerList.count(newLogListener))
00167 OGRE_EXCEPT(Ogre::Exception::ERR_DUPLICATE_ITEM, "Cannot add this listener, it already exists in the listener list!", "SRoot::AddLogListener");
00168
00169 logListenerList.insert(newLogListener);
00170 }
00171
00172 void SRoot::RemoveLogListener(SLogListener* existingLogListener)
00173 {
00174 if(!logListenerList.count(existingLogListener))
00175 OGRE_EXCEPT(Ogre::Exception::ERR_DUPLICATE_ITEM, "Cannot remove listener, this listener does not exists in the listener list!", "SRoot::RemoveLogListener");
00176
00177 logListenerList.erase(existingLogListener);
00178 }
00179
00180 void SRoot::SetLogEnable(bool state)
00181 {
00182 mLogEnable = state;
00183 }
00184
00185 bool SRoot::GetLogEnable()
00186 {
00187 return mLogEnable;
00188 }
00189
00190 void SRoot::SetLogMask(Ogre::LoggingLevel level)
00191 {
00192 Ogre::LogManager::getSingleton().getDefaultLog()->setLogDetail(level);
00193 }
00194
00195 bool SRoot::checkFSAA(Ogre::String val)
00196 {
00197 bool finded = false;
00198 if(val.find("[Quality]") != string::npos)
00199 val = val.substr(0, val.find("[Quality]")-2);
00200
00201 Ogre::ConfigOptionMap& m_system_caps = this->O3Root->getRenderSystem()->getConfigOptions();
00202 Ogre::ConfigOptionMap::iterator itr = m_system_caps.begin();
00203 while(itr != m_system_caps.end()&&!finded)
00204 {
00205 if(itr->first == "FSAA" )
00206 {
00207 Ogre::StringVector possible_values = (itr)->second.possibleValues;
00208 Ogre::StringVector::iterator pv_itr = possible_values.begin();
00209 while(pv_itr != possible_values.end() && !finded)
00210 {
00211 if(!strcmp(val.c_str(),pv_itr->c_str()))
00212 finded = true;
00213 pv_itr++;
00214 }
00215 }
00216 itr ++;
00217 }
00218 return finded;
00219 }
00220
00221 SRoot::~SRoot()
00222 {
00223 SAFE_DELETE(keyboardHook);
00224
00225 if (!SO3DebugFont.isNull())
00226 Ogre::FontManager::getSingleton().remove(SO3DebugFont);
00227 SO3DebugFont.setNull();
00228
00229
00230 UnloadSO3Plugins();
00231
00232
00233 SAFE_DELETE(pluginManager);
00234
00235
00236 SAFE_DELETE(widgetManager);
00237
00238
00239 SAFE_DELETE(objWindowWidgetFactory);
00240
00241
00242 SAFE_DELETE(flashWidgetFactory);
00243
00244
00245 SAFE_DELETE(bitmapWidgetFactory);
00246
00247 Ogre::LogManager::getSingleton().getDefaultLog()->removeListener((Ogre::LogListener*)this);
00248
00249
00250 if (dummyWindow)
00251 {
00252 dummyWindow->destroy();
00253 dummyWindow = 0;
00254 }
00255
00256
00257 SAFE_DELETE(O3Root);
00258
00259
00260 UnloadOgrePlugins();
00261 }
00262
00263 SScene* SRoot::CreateScene(std::string newSceneName, const int scolChannel)
00264 {
00265 SScene* newScene = new SScene(this, newSceneName, scolChannel);
00266 AddScene(newScene);
00267 return newScene;
00268 }
00269
00270 void SRoot::DeleteScene(SScene* existingScene)
00271 {
00272 RemoveScene(existingScene);
00273 SAFE_DELETE(existingScene);
00274 }
00275
00276 SScene* SRoot::GetScene(std::string sceneName)
00277 {
00278 SSceneMap::iterator iSceneSearched = sceneList.find(sceneName);
00279 if(iSceneSearched != sceneList.end())
00280 return iSceneSearched->second;
00281 else
00282 return 0;
00283 }
00284
00285 const SSceneMap& SRoot::GetSceneList() const
00286 {
00287 return sceneList;
00288 }
00289
00290 void SRoot::AddScene(SScene* existingScene)
00291 {
00292 string sceneName = existingScene->GetName();
00293 SSceneMap::iterator iSceneSearched = sceneList.find(sceneName);
00294 if(iSceneSearched == sceneList.end())
00295 {
00296 sceneList.insert(SSceneMap::value_type(sceneName, existingScene));
00297 }
00298 else
00299 {
00300
00301 OGRE_EXCEPT(Ogre::Exception::ERR_DUPLICATE_ITEM, "Can not add Scene named \""+ sceneName +"\", an element with the same name already exist!", "SRoot::AddScene");
00302 }
00303 }
00304
00305 void SRoot::RemoveScene(SScene* existingScene)
00306 {
00307 RemoveScene(existingScene->GetName());
00308 }
00309
00310 void SRoot::RemoveScene(std::string sceneName)
00311 {
00312 SSceneMap::iterator iSceneSearched = sceneList.find(sceneName);
00313 if(iSceneSearched != sceneList.end())
00314 {
00315 sceneList.erase(iSceneSearched);
00316 }
00317 else
00318 {
00319
00320 OGRE_EXCEPT(Ogre::Exception::ERR_ITEM_NOT_FOUND, "Can not remove Scene named \""+ sceneName +"\", element not found!", "SRoot::RemoveScene");
00321 }
00322 }
00323
00324 SWindow* SRoot::CreateRenderWindow(WindowHandle windowHandle, std::string windowName, int width, int height, std::string fsaa)
00325 {
00326 SWindow* newWindow = new SWindow(this, windowHandle, windowName, width, height, fsaa);
00327 AddRenderWindow(newWindow);
00328
00329 if (!dummyWindow)
00330 dummyWindow = const_cast<Ogre::RenderWindow*>(newWindow->GetOgreRenderWindowPointer());
00331
00332
00333 SO3DebugFont->reload();
00334 return newWindow;
00335 }
00336
00337 void SRoot::DeleteRenderWindow(SWindow* existingWindow)
00338 {
00339 if (fullScreenWindow == existingWindow)
00340 fullScreenWindow = 0;
00341
00342 RemoveRenderWindow(existingWindow);
00343 SAFE_DELETE(existingWindow);
00344 }
00345
00346 SWindow* SRoot::GetRenderWindow(WindowHandle hwnd)
00347 {
00348 SWindow* winfound = 0;
00349 const SWindowMap lWin = windowList;
00350 SWindowMap::const_iterator iWindowSearched = lWin.begin();
00351
00352 while((iWindowSearched != lWin.end()) && (winfound == 0))
00353 {
00354 if (iWindowSearched->second->GetWindowHandle() == hwnd)
00355 winfound = iWindowSearched->second;
00356 iWindowSearched++;
00357 }
00358
00359 return winfound;
00360 }
00361
00362 SWindow* SRoot::GetRenderWindow(std::string windowName)
00363 {
00364 SWindowMap::iterator iWindowSearched = windowList.find(windowName);
00365 if(iWindowSearched != windowList.end())
00366 return iWindowSearched->second;
00367 else
00368 return 0;
00369 }
00370
00371 const SWindowMap& SRoot::GetRenderWindowList() const
00372 {
00373 return windowList;
00374 }
00375
00376 void SRoot::AddRenderWindow(SWindow* existingWindow)
00377 {
00378 string windowName = existingWindow->GetName();
00379 SWindowMap::iterator iWindowSearched = windowList.find(windowName);
00380 if(iWindowSearched == windowList.end())
00381 {
00382 windowList.insert(SWindowMap::value_type(windowName, existingWindow));
00383 }
00384 else
00385 {
00386
00387 OGRE_EXCEPT(Ogre::Exception::ERR_DUPLICATE_ITEM, "Can not add Window named \""+ windowName +"\", an element with the same name already exist!", "SRoot::AddWindow");
00388 }
00389 }
00390
00391 void SRoot::RemoveRenderWindow(SWindow* existingWindow)
00392 {
00393 RemoveRenderWindow(existingWindow->GetName());
00394 }
00395
00396 void SRoot::RemoveRenderWindow(std::string windowName)
00397 {
00398 SWindowMap::iterator iWindowSearched = windowList.find(windowName);
00399 if(iWindowSearched != windowList.end())
00400 {
00401 windowList.erase(iWindowSearched);
00402 }
00403 else
00404 {
00405
00406 OGRE_EXCEPT(Ogre::Exception::ERR_ITEM_NOT_FOUND, "Can not remove Window named \""+ windowName +"\", element not found!", "SRoot::RemoveWindow");
00407 }
00408 }
00409
00410 SRoot::RenderSystem SRoot::GetRenderSystem()
00411 {
00412 return renderSystem;
00413 }
00414
00415 void SRoot::SetRenderSystem(RenderSystem selectedRenderSystem)
00416 {
00417 if (selectedRenderSystem == SO3_NONE_RENDER_SYSTEM)
00418 OGRE_EXCEPT(Ogre::Exception::ERR_INVALIDPARAMS, "Cannot set render system to \"none\", invalid render system.", "SRoot::SetRenderSystem");
00419
00420 if (renderSystem != SO3_NONE_RENDER_SYSTEM)
00421 OGRE_EXCEPT(Ogre::Exception::ERR_INVALIDPARAMS, "Render system is still setted, cannot change render system while running.", "SRoot::SetRenderSystem");
00422
00423
00424 #if OGRE_VERSION < ((1 << 16) | (7 << 8) | 0)
00425 Ogre::RenderSystemList* renderSystemList = O3Root->getAvailableRenderers();
00426 if(renderSystemList == NULL)
00427 #else
00428 const Ogre::RenderSystemList renderSystemList = O3Root->getAvailableRenderers();
00429 if(renderSystemList.empty())
00430 #endif
00431 OGRE_EXCEPT(Ogre::Exception::ERR_INTERNAL_ERROR, "No supported render system found!", "SRoot::SetRenderSystem");
00432
00433
00434 switch(selectedRenderSystem)
00435 {
00436 case SO3_DIRECTX9_RENDERER:
00437 O3Render = O3Root->getRenderSystemByName("Direct3D9 Rendering Subsystem");
00438
00439
00440 break;
00441
00442
00443
00444 case SO3_OPENGL_RENDERER:
00445 O3Render = O3Root->getRenderSystemByName("OpenGL Rendering Subsystem");
00446 break;
00447 }
00448 renderSystem = selectedRenderSystem;
00449 O3Root->setRenderSystem(O3Render);
00450 O3Root->getSingleton().initialise(false);
00451 }
00452
00453 std::vector<std::string> SRoot::GetMultisamplingMode(RenderSystem wishedRenderSystem)
00454 {
00455 if (wishedRenderSystem == SO3_NONE_RENDER_SYSTEM)
00456 OGRE_EXCEPT(Ogre::Exception::ERR_INVALIDPARAMS, "Cannot get render system multisampling information for \"none\", invalid render system.", "SRoot::GetMultisamplingMode");
00457
00458 Ogre::RenderSystem* selectedRenderSystem = 0;
00459 std::vector<std::string> multisamplingModes;
00460 switch(wishedRenderSystem)
00461 {
00462 case SO3_DIRECTX9_RENDERER:
00463 selectedRenderSystem = O3Root->getRenderSystemByName("Direct3D9 Rendering Subsystem");
00464 break;
00465
00466
00467
00468 case SO3_OPENGL_RENDERER:
00469 selectedRenderSystem = O3Root->getRenderSystemByName("OpenGL Rendering Subsystem");
00470 break;
00471 }
00472
00473 if (selectedRenderSystem != 0)
00474 {
00475 Ogre::ConfigOptionMap& m_system_caps = selectedRenderSystem->getConfigOptions();
00476 Ogre::ConfigOptionMap::iterator itr = m_system_caps.find("FSAA");
00477 if (itr == m_system_caps.end())
00478 itr = m_system_caps.find("Anti aliasing");
00479
00480 if (itr != m_system_caps.end())
00481 {
00482 Ogre::StringVector possible_values = itr->second.possibleValues;
00483 Ogre::StringVector::iterator pv_itr = possible_values.begin();
00484 while (pv_itr != possible_values.end())
00485 {
00486 multisamplingModes.push_back(*pv_itr);
00487 pv_itr++;
00488 }
00489 }
00490 }
00491
00492 return multisamplingModes;
00493 }
00494
00495 bool SRoot::CheckDirectxVersion()
00496 {
00497 bool directxOk = false;
00498 DWORD dwVersion;
00499 DWORD dwRevision;
00500 if(DirectXSetupGetVersion(&dwVersion, &dwRevision))
00501 {
00502 int a = (int)HIWORD(dwVersion);
00503 int b = (int)LOWORD(dwVersion);
00504 int c = (int)HIWORD(dwRevision);
00505 int d = (int)LOWORD(dwRevision);
00506
00507 if(b == 9 && d>= 904)
00508 directxOk = true;
00509 }
00510 return directxOk;
00511 }
00512
00513 bool SRoot::LoadOgrePlugins()
00514 {
00515 # ifdef SO3_DEVELOPPER_BUILD
00516
00517 staticPluginD3D9 = OGRE_NEW Ogre::D3D9Plugin();
00518 Ogre::Root::getSingleton().installPlugin(staticPluginD3D9);
00519
00520
00521
00522
00523 staticPluginOpenGL = OGRE_NEW Ogre::GLPlugin();
00524 Ogre::Root::getSingleton().installPlugin(staticPluginOpenGL);
00525 # else
00526
00527 # ifdef SO3_DEBUG
00528 Ogre::Root::getSingleton().loadPlugin("plugins/SO3_RenderSystem_GL_d.dll");
00529 if(CheckDirectxVersion())
00530 Ogre::Root::getSingleton().loadPlugin("plugins/SO3_RenderSystem_Direct3D9_d.dll");
00531 # else
00532 Ogre::Root::getSingleton().loadPlugin("plugins/SO3_RenderSystem_GL.dll");
00533 if(CheckDirectxVersion())
00534 Ogre::Root::getSingleton().loadPlugin("plugins/SO3_RenderSystem_Direct3D9.dll");
00535 # endif
00536 # endif
00537
00538
00539 staticPluginParticleFX = OGRE_NEW Ogre::ParticleFXPlugin();
00540 Ogre::Root::getSingleton().installPlugin(staticPluginParticleFX);
00541 staticPluginCG = OGRE_NEW Ogre::CgPlugin();
00542 Ogre::Root::getSingleton().installPlugin(staticPluginCG);
00543 staticPluginOctree = OGRE_NEW Ogre::OctreePlugin();
00544 Ogre::Root::getSingleton().installPlugin(staticPluginOctree);
00545 staticPluginStereo = OGRE_NEW Ogre::StereoPlugin();
00546 Ogre::Root::getSingleton().installPlugin(staticPluginStereo);
00547
00548
00549 scolFileSystemArchiveFactory = OGRE_NEW SO3ScolFileSystemArchiveFactory();
00550 Ogre::ArchiveManager::getSingleton().addArchiveFactory(scolFileSystemArchiveFactory);
00551
00552
00553 scolUrlArchiveFactory = OGRE_NEW SO3ScolUrlArchiveFactory();
00554 Ogre::ArchiveManager::getSingleton().addArchiveFactory(scolUrlArchiveFactory);
00555
00556
00557 return true;
00558 }
00559
00560 bool SRoot::UnloadOgrePlugins()
00561 {
00562 OGRE_DELETE scolFileSystemArchiveFactory;
00563 OGRE_DELETE scolUrlArchiveFactory;
00564 OGRE_DELETE staticPluginStereo;
00565 OGRE_DELETE staticPluginOctree;
00566 OGRE_DELETE staticPluginCG;
00567 OGRE_DELETE staticPluginParticleFX;
00568
00569 # ifdef SO3_DEVELOPPER_BUILD
00570 OGRE_DELETE staticPluginD3D9;
00571
00572
00573 OGRE_DELETE staticPluginOpenGL;
00574 # endif
00575
00576 return true;
00577 }
00578
00579 void SRoot::InitRenderer()
00580 {
00581
00582 if (!debugPanelInitialized)
00583 {
00584 if (renderSystem == SO3_OPENGL_RENDERER)
00585 {
00586
00587 Ogre::NameValuePairList viewConfig;
00588 viewConfig["hidden"] = "Yes";
00589
00590
00591 viewConfig["monitorIndex"] = "0";
00592 viewConfig["vsync"] = "Yes";
00593
00594
00595 dummyWindow = Ogre::Root::getSingleton().createRenderWindow("OgreDummyWindow", 1, 1, false, &viewConfig);
00596 dummyWindow->setAutoUpdated(false);
00597 dummyWindow->setDeactivateOnFocusChange(false);
00598 }
00599
00600 try
00601 {
00602
00603
00604 #if OGRE_VERSION < ((1 << 16) | (7 << 8) | 0)
00605 Ogre::ResourceGroupManager::getSingleton().createResourceGroup(SO3_INTERNAL_RESOURCE_GROUP);
00606 Ogre::ResourceGroupManager::getSingleton().createResourceGroup(SO3_INTERNAL_DYNAMIC_RESOURCE_GROUP);
00607 Ogre::ResourceGroupManager::getSingleton().createResourceGroup(SO3_INTERNAL_DYNAMIC_READABLE_RESOURCE_GROUP);
00608 Ogre::ResourceGroupManager::getSingleton().createResourceGroup(SO3_INTERNAL_HYDRAX_RESOURCE_GROUP);
00609 Ogre::ResourceGroupManager::getSingleton().createResourceGroup(SO3_INTERNAL_SKYX_RESOURCE_GROUP);
00610 #else
00611 Ogre::ResourceGroupManager::getSingleton().createResourceGroup(SO3_INTERNAL_RESOURCE_GROUP, false);
00612 Ogre::ResourceGroupManager::getSingleton().createResourceGroup(SO3_INTERNAL_DYNAMIC_RESOURCE_GROUP, false);
00613 Ogre::ResourceGroupManager::getSingleton().createResourceGroup(SO3_INTERNAL_DYNAMIC_READABLE_RESOURCE_GROUP, true);
00614 Ogre::ResourceGroupManager::getSingleton().createResourceGroup(SO3_INTERNAL_HYDRAX_RESOURCE_GROUP, true);
00615 Ogre::ResourceGroupManager::getSingleton().createResourceGroup(SO3_INTERNAL_SKYX_RESOURCE_GROUP, true);
00616 #endif
00617
00618 #ifdef SO3_DEBUG
00619
00620 Ogre::Root::getSingleton().addResourceLocation("Plugins/Ogre_Redist/OgreCore", "FileSystem", SO3_INTERNAL_RESOURCE_GROUP, true);
00621 Ogre::Root::getSingleton().addResourceLocation("Plugins/Ogre_Redist/Hydrax", "FileSystem", SO3_INTERNAL_HYDRAX_RESOURCE_GROUP, true);
00622 Ogre::Root::getSingleton().addResourceLocation("Plugins/Ogre_Redist/Skyx", "FileSystem", SO3_INTERNAL_SKYX_RESOURCE_GROUP, true);
00623 #else
00624 Ogre::Root::getSingleton().addResourceLocation("Plugins/Ogre_Redist/OgreCore.zip", "Zip", SO3_INTERNAL_RESOURCE_GROUP, true);
00625 Ogre::Root::getSingleton().addResourceLocation("Plugins/Ogre_Redist/Hydrax.zip", "Zip", SO3_INTERNAL_HYDRAX_RESOURCE_GROUP, true);
00626 Ogre::Root::getSingleton().addResourceLocation("Plugins/Ogre_Redist/Skyx.zip", "Zip", SO3_INTERNAL_SKYX_RESOURCE_GROUP, true);
00627 #endif
00628
00629 Ogre::ResourceGroupManager::getSingleton().initialiseResourceGroup(SO3_INTERNAL_RESOURCE_GROUP);
00630 Ogre::ResourceGroupManager::getSingleton().initialiseResourceGroup(SO3_INTERNAL_HYDRAX_RESOURCE_GROUP);
00631 Ogre::ResourceGroupManager::getSingleton().initialiseResourceGroup(SO3_INTERNAL_SKYX_RESOURCE_GROUP);
00632
00633
00634 SO3DebugOverlay = Ogre::OverlayManager::getSingleton().create("SO3DebugOverlayName");
00635 SO3DebugPanel = static_cast<Ogre::OverlayContainer*>(Ogre::OverlayManager::getSingleton().createOverlayElement("Panel", "SO3DebugPanelName"));
00636 SO3DebugTextArea = static_cast<Ogre::TextAreaOverlayElement*>(Ogre::OverlayManager::getSingleton().createOverlayElement("TextArea","SO3DebugTextAreaName"));
00637 SO3DebugOverlay->add2D(SO3DebugPanel);
00638 SO3DebugPanel->addChild(SO3DebugTextArea);
00639 SO3DebugFont.setNull();
00640 SO3DebugFont = Ogre::FontManager::getSingleton().create("SO3DebugFont", SO3_INTERNAL_RESOURCE_GROUP);
00641 SO3DebugFont->setParameter("type", "truetype");
00642 SO3DebugFont->setParameter("source", "bluehigh.ttf");
00643 SO3DebugFont->setParameter("size", "16");
00644 SO3DebugFont->setParameter("resolution", "128");
00645 SO3DebugFont->load();
00646 SO3DebugTextArea->setFontName(SO3DebugFont->getName());
00647 debugPanelInitialized = true;
00648
00649
00650 CreateBoneHelperMesh();
00651
00652
00653 if (dummyWindow)
00654 dummyWindow->update();
00655 }
00656 catch(Ogre::Exception &e)
00657 {
00658 Ogre::LogManager::getSingleton().getDefaultLog()->logMessage("An exception has occurred: "+ e.getDescription());
00659 }
00660 }
00661 }
00662
00663 bool SRoot::SetFullScreenState(SWindow* window, bool state, int width, int height)
00664 {
00665
00666 if (state && (fullScreenWindow == 0))
00667 {
00668 if (renderSystem != SO3_OPENGL_RENDERER)
00669 {
00670 try
00671 {
00672 const_cast <Ogre::RenderWindow*> (window->GetOgreRenderWindowPointer())->update();
00673 }
00674 catch (Ogre::Exception &e)
00675 {
00676 Ogre::LogManager::getSingleton().getDefaultLog()->logMessage("An exception has occurred: "+ e.getDescription());
00677 }
00678 }
00679
00680 try
00681 {
00682 const_cast <Ogre::RenderWindow*> (window->GetOgreRenderWindowPointer())->setFullscreen(state, width, height);
00683 }
00684 catch (Ogre::Exception &e)
00685 {
00686 Ogre::LogManager::getSingleton().getDefaultLog()->logMessage("An exception has occurred: "+ e.getDescription());
00687 return false;
00688 }
00689
00690 fullScreenWindow = window;
00691
00692
00693 if (renderSystem != SO3_OPENGL_RENDERER)
00694 {
00695 try
00696 {
00697 const_cast <Ogre::RenderWindow*> (window->GetOgreRenderWindowPointer())->update();
00698 }
00699 catch (Ogre::Exception &e)
00700 {
00701 Ogre::LogManager::getSingleton().getDefaultLog()->logMessage("An exception has occurred: "+ e.getDescription());
00702 }
00703 }
00704 return true;
00705 }
00706 else if (!state && (fullScreenWindow == window))
00707 {
00708 try
00709 {
00710 const_cast <Ogre::RenderWindow*> (fullScreenWindow->GetOgreRenderWindowPointer())->setFullscreen(state, width, height);
00711 }
00712 catch (Ogre::Exception &e)
00713 {
00714 Ogre::LogManager::getSingleton().getDefaultLog()->logMessage("An exception has occurred: "+ e.getDescription());
00715 return false;
00716 }
00717
00718 if (renderSystem != SO3_OPENGL_RENDERER)
00719 {
00720 try
00721 {
00722 const_cast <Ogre::RenderWindow*> (fullScreenWindow->GetOgreRenderWindowPointer())->update();
00723 }
00724 catch (Ogre::Exception &e)
00725 {
00726 Ogre::LogManager::getSingleton().getDefaultLog()->logMessage("An exception has occurred: "+ e.getDescription());
00727 }
00728 }
00729
00730 fullScreenWindow = 0;
00731 return true;
00732 }
00733
00734 return false;
00735 }
00736
00737 bool SRoot::LoadSO3Plugins()
00738 {
00739 # ifdef SO3_DEVELOPPER_BUILD
00740 # if SO3_PLUGIN_WEB_MANAGER_BUILD == 1
00741 staticWebNavigatorPlugin = new SWebNavigatorPlugin();
00742 # endif
00743 # else
00744 pluginManager->Load("./Plugins/SO3_Plugins/Plugin_WebNavigator.dll");
00745 # endif
00746 return true;
00747 }
00748
00749 bool SRoot::UnloadSO3Plugins()
00750 {
00751 # ifdef SO3_DEVELOPPER_BUILD
00752 # if SO3_PLUGIN_WEB_MANAGER_BUILD == 1
00753 SAFE_DELETE(staticWebNavigatorPlugin)
00754 # endif
00755 # endif
00756 return true;
00757 }
00758
00759 void SRoot::SetDebugEnable(bool enable)
00760 {
00761 if (debugPanelInitialized)
00762 {
00763 if (enable)
00764 SO3DebugOverlay->show();
00765 else
00766 SO3DebugOverlay->hide();
00767 }
00768 }
00769
00770 bool SRoot::GetDebugEnable()
00771 {
00772 if (debugPanelInitialized)
00773 return SO3DebugOverlay->isVisible();
00774 else
00775 return false;
00776 }
00777
00778 void SRoot::SetDebugDisplay(SMaterial* material, int color, int posx, int posy, int width, int height, int charHeight)
00779 {
00780 if (debugPanelInitialized)
00781 {
00782 SO3DebugPanel->setMetricsMode(Ogre::GMM_PIXELS);
00783 SO3DebugPanel->setDimensions(Ogre::Real(width),Ogre::Real(height));
00784 SO3DebugPanel->setPosition(Ogre::Real(posx), Ogre::Real(posy));
00785
00786 if(material!=0)
00787 SO3DebugPanel->setMaterialName(material->getOgreMaterialPointer()->getName());
00788
00789 SO3DebugPanel->_update();
00790 SO3DebugTextArea->setMetricsMode(Ogre::GMM_PIXELS);
00791 SO3DebugTextArea->setPosition(0.0, 0.0);
00792 SO3DebugTextArea->setDimensions(Ogre::Real(width),Ogre::Real(height));
00793 SO3DebugTextArea->setCharHeight(Ogre::Real(charHeight));
00794 SO3DebugTextArea->setColour(ConversionTools::ScolToOgreColorRGBA(color));
00795 SO3DebugTextArea->setColourBottom(ConversionTools::ScolToOgreColorRGBA(color));
00796 SO3DebugTextArea->setColourTop(ConversionTools::ScolToOgreColorRGBA(color));
00797 SO3DebugOverlay->show();
00798 }
00799 }
00800
00801 void SRoot::SetDebugText(std::string text)
00802 {
00803 if (debugPanelInitialized)
00804 {
00805 SO3DebugTextArea->setCaption(text);
00806 SO3DebugTextArea->_update();
00807 SO3DebugPanel->_update();
00808 }
00809 }
00810
00811 void SRoot::CreateBoneHelperMesh()
00812 {
00813 SBaseMeshsTools::CreateOctahedron("SO3/Bone/Helper/Mesh", .2f, .1f, 1.0f, SO3_INTERNAL_RESOURCE_GROUP);
00814 Ogre::MaterialPtr material = Ogre::MaterialManager::getSingleton().create("SO3/Bone/Helper/Material", SO3_INTERNAL_RESOURCE_GROUP);
00815 material->setReceiveShadows(false);
00816 material->getTechnique(0)->getPass(0)->setLightingEnabled(true);
00817 material->getTechnique(0)->getPass(0)->setAmbient(1, 0, 0);
00818 material->getTechnique(0)->getPass(0)->setDiffuse(1, 0, 0, 1);
00819 material->getTechnique(0)->getPass(0)->setSelfIllumination(1, 0, 0);
00820 material->getTechnique(0)->getPass(0)->setDepthCheckEnabled(false);
00821 }
00822
00823 bool SRoot::Update()
00824 {
00825 bool ret = false;
00826 try
00827 {
00828 ret = Ogre::Root::getSingleton().renderOneFrame();
00829 }
00830 catch (Ogre::Exception &e)
00831 {
00832 Ogre::LogManager::getSingleton().getDefaultLog()->logMessage("An exception has occurred: "+ e.getDescription());
00833 }
00834 return ret;
00835 }
00836
00837 }