Main Page Namespace List Class Hierarchy Alphabetical List Compound List File List Namespace Members Compound Members File Members Related Pages

# OgreRoot.cpp

Go to the documentation of this file.

    00001 /*
    00002 -----------------------------------------------------------------------------
    00003 This source file is part of OGRE
    00004 (Object-oriented Graphics Rendering Engine)
    00005 For the latest info, see http://ogre.sourceforge.net/
    00006
    00007 Copyright © 2000-2002 The OGRE Team
    00008 Also see acknowledgements in Readme.html
    00009
    00010 This program is free software; you can redistribute it and/or modify it under
    00011 the terms of the GNU Lesser General Public License as published by the Free Software
    00012 Foundation; either version 2 of the License, or (at your option) any later
    00013 version.
    00014
    00015 This program is distributed in the hope that it will be useful, but WITHOUT
    00016 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
    00017 FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
    00018
    00019 You should have received a copy of the GNU Lesser General Public License along with
    00020 this program; if not, write to the Free Software Foundation, Inc., 59 Temple
    00021 Place - Suite 330, Boston, MA 02111-1307, USA, or go to
    00022 http://www.gnu.org/copyleft/lesser.txt.
    00023 -----------------------------------------------------------------------------
    00024 */
    00025 // Ogre includes
    00026 #include "OgreStableHeaders.h"
    00027
    00028 #include "OgreRoot.h"
    00029
    00030 #include "OgreRenderSystem.h"
    00031 #include "OgreException.h"
    00032 #include "OgreControllerManager.h"
    00033 #include "OgreLogManager.h"
    00034 #include "OgreMath.h"
    00035 #include "OgreDynLibManager.h"
    00036 #include "OgreDynLib.h"
    00037 #include "OgreConfigFile.h"
    00038 #include "OgreMaterialManager.h"
    00039 #include "OgreResourceManager.h"
    00040 #include "OgreMeshManager.h"
    00041 #include "OgreTextureManager.h"
    00042 #include "OgreParticleSystemManager.h"
    00043 #include "OgreSkeletonManager.h"
    00044 #include "OgreGuiManager.h"
    00045 #include "OgreOverlayManager.h"
    00046 #include "OgreZipArchiveFactory.h"
    00047 #include "OgreProfiler.h"
    00048 #include "OgreErrorDialog.h"
    00049 #include "OgreConfigDialog.h"
    00050 #include "OgreStringConverter.h"
    00051
    00052 #include "OgreILCodecs.h"
    00053
    00054 #include "OgreFontManager.h"
    00055 #include "OgreHardwareBufferManager.h"
    00056
    00057 #include "OgreOverlay.h"
    00058 #include "OgreHighLevelGpuProgramManager.h"
    00059
    00060 #include "OgreExternalTextureSourceManager.h"
    00061
    00062 #if OGRE_PLATFORM == PLATFORM_WIN32
    00063
    00064 #   define WIN32_LEAN_AND_MEAN
    00065 #   include <direct.h>
    00066 #   include <windows.h>
    00067
    00068 #endif
    00069
    00070
    00071 namespace Ogre {
    00072     //-----------------------------------------------------------------------
    00073     template<> Root* Singleton<Root>::ms_Singleton = 0;
    00074     Root* Root::getSingletonPtr(void)
    00075     {
    00076         return ms_Singleton;
    00077     }
    00078     Root& Root::getSingleton(void)
    00079     {
    00080         assert( ms_Singleton );  return ( *ms_Singleton );
    00081     }
    00082
    00083     typedef void (*DLL_START_PLUGIN)(void);
    00084     typedef void (*DLL_STOP_PLUGIN)(void);
    00085
    00086
    00087     //-----------------------------------------------------------------------
    00088     // Termination handler
    00089     extern "C" _OgreExport void handleTerminate(void)
    00090     {
    00091         LogManager::getSingleton().logMessage(LML_CRITICAL, "Termination handler: uncaught exception!");
    00092
    00093         Root::getSingleton().shutdown();
    00094
    00095         ErrorDialog* dlg = PlatformManager::getSingleton().createErrorDialog();
    00096
    00097         Exception* e = Exception::getLastException();
    00098
    00099         if (e)
    00100             dlg->display(e->getFullDescription());
    00101         else
    00102             dlg->display("Unknown");
    00103
    00104         // Abort
    00105         exit(-1);
    00106
    00107     }
    00108
    00109     void Root::termHandler()
    00110     {
    00111         handleTerminate();
    00112     }
    00113
    00114
    00115     //-----------------------------------------------------------------------
    00116     Root::Root(const String& pluginFileName, const String& configFileName, const String& logFileName)
    00117       : mCurrentFrame(0)
    00118     {
    00119         // First create new exception handler
    00120         SET_TERM_HANDLER;
    00121
    00122         // superclass will do singleton checking
    00123         String msg;
    00124
    00125         // Init
    00126         mActiveRenderer = 0;
    00127         mVersion = StringConverter::toString(OGRE_VERSION_MAJOR) + "." +
    00128             StringConverter::toString(OGRE_VERSION_MINOR) + "." +
    00129             StringConverter::toString(OGRE_VERSION_PATCH) + " " +
    00130             "(" + OGRE_VERSION_NAME + ")";
    00131         mConfigFileName = configFileName;
    00132
    00133         // Create log manager and default log file
    00134         mLogManager = new LogManager();
    00135         mLogManager->createLog(logFileName, true, true);
    00136
    00137         // Dynamic library manager
    00138         mDynLibManager = new DynLibManager();
    00139
    00140         mArchiveManager = new ArchiveManager();
    00141
    00142         // Create SceneManager enumerator (note - will be managed by singleton)
    00143         mSceneManagerEnum = new SceneManagerEnumerator();
    00144         mCurrentSceneManager = NULL;
    00145
    00146         // ..material manager
    00147         mMaterialManager = new MaterialManager();
    00148
    00149         // Mesh manager
    00150         mMeshManager = new MeshManager();
    00151
    00152         // Skeleton manager
    00153         mSkeletonManager = new SkeletonManager();
    00154
    00155         // ..particle system manager
    00156         mParticleManager = new ParticleSystemManager();
    00157
    00158         // Platform manager
    00159         mPlatformManager = new PlatformManager();
    00160
    00161         // Timer
    00162         mTimer = mPlatformManager->createTimer();
    00163
    00164         // Overlay manager
    00165         mOverlayManager = new OverlayManager();
    00166         // Gui Manager
    00167         mGuiManager = new GuiManager();
    00168         // Font manager
    00169         mFontManager = new FontManager();
    00170
    00171 #if OGRE_PROFILING
    00172         // Profiler
    00173         mProfiler = new Profiler();
    00174         Profiler::getSingleton().setTimer(mTimer);
    00175 #endif
    00176         mZipArchiveFactory = new ZipArchiveFactory();
    00177         ArchiveManager::getSingleton().addArchiveFactory( mZipArchiveFactory );
    00178
    00179         // Register image codecs
    00180         ILCodecs::registerCodecs();
    00181
    00182         mHighLevelGpuProgramManager = new HighLevelGpuProgramManager();
    00183
    00184         mExternalTextureSourceManager = new ExternalTextureSourceManager();
    00185
    00186         // Auto window
    00187         mAutoWindow = 0;
    00188
    00189         // Load plugins
    00190         if (!pluginFileName.empty())
    00191             loadPlugins(pluginFileName);
    00192
    00193         mLogManager->logMessage("*-*-* OGRE Initialising");
    00194         msg = "*-*-* Version " + mVersion;
    00195         mLogManager->logMessage(msg);
    00196
    00197         // Can't create managers until initialised
    00198         mControllerManager = 0;
    00199
    00200
    00201         // Seed random number generator for future use
    00202         srand((unsigned)time(0));
    00203
    00204         mFirstTimePostWindowInit = false;
    00205
    00206     }
    00207
    00208     //-----------------------------------------------------------------------
    00209     Root::~Root()
    00210     {
    00211         shutdown();
    00212         delete mSceneManagerEnum;
    00213
    00214         delete mExternalTextureSourceManager;
    00215
    00216         ILCodecs::deleteCodecs();
    00217         delete mZipArchiveFactory;
    00218 #if OGRE_PROFILING
    00219         delete mProfiler;
    00220 #endif
    00221         delete mGuiManager;
    00222         delete mOverlayManager;
    00223         delete mFontManager;
    00224         delete mArchiveManager;
    00225         delete mSkeletonManager;
    00226         delete mMeshManager;
    00227         delete mMaterialManager;
    00228         Pass::processPendingPassUpdates(); // make sure passes are cleaned
    00229         delete mParticleManager;
    00230
    00231         if( mControllerManager )
    00232             delete mControllerManager;
    00233         if (mHighLevelGpuProgramManager)
    00234             delete mHighLevelGpuProgramManager;
    00235
    00236
    00237         unloadPlugins();
    00238
    00239
    00240
    00241         mPlatformManager->destroyTimer(mTimer);
    00242         delete mPlatformManager;
    00243         delete mDynLibManager;
    00244         delete mLogManager;
    00245
    00246         ResourceManager::cleanupCommonArchive () ;
    00247
    00248         StringInterface::cleanupDictionary ();
    00249     }
    00250
    00251     //-----------------------------------------------------------------------
    00252     void Root::saveConfig(void)
    00253     {
    00254         ::FILE *fp;
    00255         char rec[100];
    00256
    00257         fp = fopen(mConfigFileName.c_str(), "w");
    00258         if (!fp)
    00259             Except(Exception::ERR_CANNOT_WRITE_TO_FILE, "Cannot create settings file.",
    00260             "Root::saveConfig");
    00261
    00262         if (mActiveRenderer)
    00263         {
    00264             sprintf(rec, "Render System\t%s\n", mActiveRenderer->getName().c_str());
    00265             fputs(rec, fp);
    00266
    00267             ConfigOptionMap& opts = mActiveRenderer->getConfigOptions();
    00268             for(  ConfigOptionMap::iterator pOpt = opts.begin(); pOpt != opts.end(); ++pOpt )
    00269             {
    00270                 sprintf(rec, "%s\t%s\n", pOpt->first.c_str(),
    00271                     pOpt->second.currentValue.c_str());
    00272                 fputs(rec, fp);
    00273             }
    00274         }
    00275         else
    00276         {
    00277             strcpy(rec, "Render System\t ");
    00278             fputs(rec, fp);
    00279         }
    00280
    00281         fclose(fp);
    00282
    00283     }
    00284     //-----------------------------------------------------------------------
    00285     bool Root::restoreConfig(void)
    00286     {
    00287         // Restores configuration from saved state
    00288         // Returns true if a valid saved configuration is
    00289         //   available, and false if no saved config is
    00290         //   stored, or if there has been a problem
    00291         ConfigFile cfg;
    00292         String renderSystem;
    00293         RenderSystemList::iterator pRend;
    00294
    00295         try {
    00296             // Don't trim whitespace
    00297             cfg.load(mConfigFileName, "\t:=", false);
    00298         }
    00299         catch (Exception& e)
    00300         {
    00301             if (e.getNumber() == Exception::ERR_FILE_NOT_FOUND)
    00302             {
    00303                 return false;
    00304             }
    00305             else
    00306             {
    00307                 throw;
    00308             }
    00309         }
    00310
    00311         renderSystem = cfg.getSetting("Render System");
    00312         if(renderSystem.empty())
    00313         {
    00314             // No render system entry - error
    00315             return false;
    00316         }
    00317
    00318         pRend = getAvailableRenderers()->begin();
    00319         while (pRend != getAvailableRenderers()->end())
    00320         {
    00321             String rName = (*pRend)->getName();
    00322             if (rName == renderSystem)
    00323                 break;
    00324             pRend++;
    00325         }
    00326
    00327         if (pRend == getAvailableRenderers()->end())
    00328         {
    00329             // Unrecognised render system
    00330             return false;
    00331         }
    00332
    00333         setRenderSystem(*pRend);
    00334
    00335         ConfigFile::SettingsIterator i = cfg.getSettingsIterator();
    00336
    00337         String optName, optVal;
    00338         while (i.hasMoreElements())
    00339         {
    00340             optName = i.peekNextKey();
    00341             optVal = i.getNext();
    00342             if(optName != "Render System")
    00343             {
    00344                 mActiveRenderer->setConfigOption(optName, optVal);
    00345             }
    00346         }
    00347
    00348         // Successful load
    00349         return true;
    00350
    00351     }
    00352
    00353     //-----------------------------------------------------------------------
    00354     bool Root::showConfigDialog(void)
    00355     {
    00356         // Displays the standard config dialog
    00357         // Will use stored defaults if available
    00358         ConfigDialog* dlg;
    00359         bool isOk;
    00360
    00361         dlg = mPlatformManager->createConfigDialog();
    00362
    00363         isOk = dlg->display();
    00364
    00365         mPlatformManager->destroyConfigDialog(dlg);
    00366
    00367         return isOk;
    00368
    00369     }
    00370
    00371     //-----------------------------------------------------------------------
    00372     RenderSystemList* Root::getAvailableRenderers(void)
    00373     {
    00374         // Returns a vector of renders
    00375
    00376         return &mRenderers;
    00377
    00378     }
    00379
    00380     //-----------------------------------------------------------------------
    00381     void Root::setRenderSystem(RenderSystem* system)
    00382     {
    00383         // Sets the active rendering system
    00384         // Can be called direct or will be called by
    00385         //   standard config dialog
    00386
    00387         // Is there already an active renderer?
    00388         // If so, disable it and init the new one
    00389         if( mActiveRenderer && mActiveRenderer != system )
    00390         {
    00391             mActiveRenderer->shutdown();
    00392         }
    00393
    00394         mActiveRenderer = system;
    00395         // Tell scene managers
    00396         SceneManagerEnumerator::getSingleton().setRenderSystem(system);
    00397
    00398     }
    00399     //-----------------------------------------------------------------------
    00400     void Root::addRenderSystem(RenderSystem *newRend)
    00401     {
    00402         mRenderers.push_back(newRend);
    00403     }
    00404     //-----------------------------------------------------------------------
    00405     void Root::setSceneManager(SceneType sType, SceneManager *sm)
    00406     {
    00407         SceneManagerEnumerator::getSingleton().setSceneManager(sType, sm);
    00408     }
    00409
    00410     //-----------------------------------------------------------------------
    00411     RenderSystem* Root::getRenderSystem(void)
    00412     {
    00413         // Gets the currently active renderer
    00414         return mActiveRenderer;
    00415
    00416     }
    00417
    00418     //-----------------------------------------------------------------------
    00419     RenderWindow* Root::initialise(bool autoCreateWindow, const String& windowTitle)
    00420     {
    00421         if (!mActiveRenderer)
    00422             Except(Exception::ERR_NO_RENDERSYSTEM_SELECTED,
    00423             "Cannot initialise - no render "
    00424             "system has been selected.", "Root::initialise");
    00425
    00426         mControllerManager = new ControllerManager();
    00427
    00428         mAutoWindow =  mActiveRenderer->initialise(autoCreateWindow, windowTitle);
    00429
    00430         if (autoCreateWindow)
    00431         {
    00432             oneTimePostWindowInit();
    00433         }
    00434
    00435         // Initialise timer
    00436         mTimer->reset();
    00437         return mAutoWindow;
    00438
    00439     }
    00440     //-----------------------------------------------------------------------
    00441     String Root::getErrorDescription(long errorNumber)
    00442     {
    00443
    00444         // Pass to render system
    00445         if (mActiveRenderer)
    00446             return mActiveRenderer->getErrorDescription(errorNumber);
    00447         else
    00448             return "";
    00449
    00450     }
    00451     //-----------------------------------------------------------------------
    00452     SceneManager* Root::getSceneManager(SceneType sceneType)
    00453     {
    00454         // Delegate
    00455         return mSceneManagerEnum->getSceneManager(sceneType);
    00456     }
    00457     //-----------------------------------------------------------------------
    00458     TextureManager* Root::getTextureManager(void)
    00459     {
    00460         return &TextureManager::getSingleton();
    00461     }
    00462     //-----------------------------------------------------------------------
    00463     MeshManager* Root::getMeshManager(void)
    00464     {
    00465         return &MeshManager::getSingleton();
    00466     }
    00467     //-----------------------------------------------------------------------
    00468     void Root::addFrameListener(FrameListener* newListener)
    00469     {
    00470         // Insert, unique only (set)
    00471         mFrameListeners.insert(newListener);
    00472
    00473     }
    00474
    00475     //-----------------------------------------------------------------------
    00476     void Root::removeFrameListener(FrameListener* oldListener)
    00477     {
    00478         // Remove, 1 only (set)
    00479         mFrameListeners.erase(oldListener);
    00480     }
    00481     //-----------------------------------------------------------------------
    00482     bool Root::_fireFrameStarted(FrameEvent& evt)
    00483     {
    00484         // Increment frame number
    00485         ++mCurrentFrame;
    00486
    00487         // Tell all listeners
    00488         std::set<FrameListener*>::iterator i;
    00489         for (i= mFrameListeners.begin(); i != mFrameListeners.end(); ++i)
    00490         {
    00491             if (!(*i)->frameStarted(evt))
    00492                 return false;
    00493         }
    00494
    00495         return true;
    00496
    00497     }
    00498     //-----------------------------------------------------------------------
    00499     bool Root::_fireFrameEnded(FrameEvent& evt)
    00500     {
    00501         // Tell all listeners
    00502         std::set<FrameListener*>::iterator i;
    00503         for (i= mFrameListeners.begin(); i != mFrameListeners.end(); ++i)
    00504         {
    00505             if (!(*i)->frameEnded(evt))
    00506                 return false;
    00507         }
    00508
    00509         // Tell buffer manager to free temp buffers used this frame
    00510         if (HardwareBufferManager::getSingletonPtr())
    00511             HardwareBufferManager::getSingleton()._releaseBufferCopies();
    00512
    00513         return true;
    00514     }
    00515     //-----------------------------------------------------------------------
    00516     bool Root::_fireFrameStarted()
    00517     {
    00518         unsigned long now = mTimer->getMilliseconds();
    00519         FrameEvent evt;
    00520         evt.timeSinceLastEvent = calculateEventTime(now, FETT_ANY);
    00521         evt.timeSinceLastFrame = calculateEventTime(now, FETT_STARTED);
    00522
    00523         return _fireFrameStarted(evt);
    00524     }
    00525     //-----------------------------------------------------------------------
    00526     bool Root::_fireFrameEnded()
    00527     {
    00528         unsigned long now = mTimer->getMilliseconds();
    00529         FrameEvent evt;
    00530         evt.timeSinceLastEvent = calculateEventTime(now, FETT_ANY);
    00531         evt.timeSinceLastFrame = calculateEventTime(now, FETT_ENDED);
    00532
    00533         return _fireFrameEnded(evt);
    00534     }
    00535     //-----------------------------------------------------------------------
    00536     Real Root::calculateEventTime(unsigned long now, FrameEventTimeType type)
    00537     {
    00538         // Calculate the average time passed between events of the given type
    00539         // during the last 0.5 seconds.
    00540
    00541         std::deque<unsigned long>& times = mEventTimes[type];
    00542         times.push_back(now);
    00543
    00544         if(times.size() == 1)
    00545             return 0;
    00546
    00547         // Times up to 0.5 seconds old should be kept
    00548         unsigned long discardLimit = now - 500;
    00549
    00550         // Find the oldest time to keep
    00551         std::deque<unsigned long>::iterator it = times.begin(),
    00552             end = times.end()-2; // We need at least two times
    00553         while(it != end)
    00554         {
    00555             if(*it < discardLimit)
    00556                 ++it;
    00557             else
    00558                 break;
    00559         }
    00560
    00561         // Remove old times
    00562         times.erase(times.begin(), it);
    00563
    00564         return Real(times.back() - times.front()) / ((times.size()-1) * 1000);
    00565     }
    00566     //-----------------------------------------------------------------------
    00567     void Root::queueEndRendering(void)
    00568     {
    00569         mQueuedEnd = true;
    00570     }
    00571     //-----------------------------------------------------------------------
    00572     void Root::startRendering(void)
    00573     {
    00574         assert(mActiveRenderer != 0);
    00575
    00576         mActiveRenderer->_initRenderTargets();
    00577
    00578         // Clear event times
    00579         for(int i=0; i!=3; ++i)
    00580             mEventTimes[i].clear();
    00581
    00582         // Infinite loop, until broken out of by frame listeners
    00583         // or break out by calling queueEndRendering()
    00584         mQueuedEnd = false;
    00585         while( !mQueuedEnd )
    00586         {
    00587 #if OGRE_PLATFORM == PLATFORM_WIN32
    00588             // Pump events on Win32
    00589             MSG  msg;
    00590             while( PeekMessage( &msg, NULL, 0U, 0U, PM_REMOVE ) )
    00591             {
    00592                 TranslateMessage( &msg );
    00593                 DispatchMessage( &msg );
    00594             }
    00595 #endif
    00596
    00597             if (!renderOneFrame())
    00598                 break;
    00599         }
    00600
    00601
    00602     }
    00603     //-----------------------------------------------------------------------
    00604     bool Root::renderOneFrame(void)
    00605     {
    00606         if(!_fireFrameStarted())
    00607             return false;
    00608
    00609         _updateAllRenderTargets();
    00610
    00611         return _fireFrameEnded();
    00612     }
    00613     //-----------------------------------------------------------------------
    00614     void Root::shutdown(void)
    00615     {
    00616         SceneManagerEnumerator::getSingleton().shutdownAll();
    00617
    00618         mLogManager->logMessage("*-*-* OGRE Shutdown");
    00619     }
    00620     //-----------------------------------------------------------------------
    00621     void Root::loadPlugins( const String& pluginsfile )
    00622     {
    00623         StringVector pluginList;
    00624         String pluginDir;
    00625         ConfigFile cfg;
    00626
    00627         try {
    00628             cfg.load( pluginsfile );
    00629         }
    00630         catch (Exception)
    00631         {
    00632             LogManager::getSingleton().logMessage(pluginsfile + " not found, automatic plugin loading disabled.");
    00633             return;
    00634         }
    00635
    00636         pluginDir = cfg.getSetting("PluginFolder"); // Ignored on Mac OS X, uses Resources/ directory
    00637         pluginList = cfg.getMultiSetting("Plugin");
    00638
    00639         char last_char = pluginDir[pluginDir.length()-1];
    00640         if (last_char != '/' && last_char != '\\')
    00641         {
    00642 #if OGRE_PLATFORM == PLATFORM_WIN32
    00643             pluginDir += "\\";
    00644 #elif OGRE_PLATFORM == PLATFORM_LINUX
    00645             pluginDir += "/";
    00646 #endif
    00647         }
    00648
    00649         for( StringVector::iterator it = pluginList.begin(); it != pluginList.end(); ++it )
    00650         {
    00651             loadPlugin(pluginDir + (*it));
    00652         }
    00653
    00654     }
    00655     //-----------------------------------------------------------------------
    00656     void Root::unloadPlugins(void)
    00657     {
    00658         std::vector<DynLib*>::reverse_iterator i;
    00659
    00660         // NB Unload plugins in reverse order to enforce dependencies
    00661         for (i = mPluginLibs.rbegin(); i != mPluginLibs.rend(); ++i)
    00662         {
    00663             // Call plugin shutdown
    00664             DLL_STOP_PLUGIN pFunc = (DLL_STOP_PLUGIN)(*i)->getSymbol("dllStopPlugin");
    00665             pFunc();
    00666             // Unload library & destroy
    00667             DynLibManager::getSingleton().unload((Resource*)*i);
    00668             delete *i;
    00669
    00670         }
    00671
    00672         mPluginLibs.clear();
    00673
    00674     }
    00675     //-----------------------------------------------------------------------
    00676     void Root::addResourceLocation(const String& name, const String& locType, ResourceType resType)
    00677     {
    00678         switch(resType)
    00679         {
    00680         case RESTYPE_ALL:
    00681             ResourceManager::addCommonArchiveEx(name, locType);
    00682             break;
    00683         case RESTYPE_TEXTURES:
    00684             TextureManager::getSingleton().addArchiveEx(name, locType);
    00685             break;
    00686         case RESTYPE_MODELS:
    00687             MeshManager::getSingleton().addArchiveEx(name, locType);
    00688             break;
    00689
    00690         }
    00691     }
    00692     //-----------------------------------------------------------------------
    00693     void Root::convertColourValue(const ColourValue& colour, unsigned long* pDest)
    00694     {
    00695         assert(mActiveRenderer != 0);
    00696         mActiveRenderer->convertColourValue(colour, pDest);
    00697     }
    00698     //-----------------------------------------------------------------------
    00699     RenderWindow* Root::getAutoCreatedWindow(void)
    00700     {
    00701         return mAutoWindow;
    00702     }
    00703     //-----------------------------------------------------------------------
    00704     RenderWindow* Root::createRenderWindow(const String &name, unsigned int width, unsigned int height, unsigned int colourDepth,
    00705                 bool fullScreen, int left, int top, bool depthBuffer,RenderWindow* parentWindowHandle)
    00706     {
    00707         if (!mActiveRenderer)
    00708         {
    00709             Except(Exception::ERR_NO_RENDERSYSTEM_SELECTED,
    00710             "Cannot create window - no render "
    00711             "system has been selected.", "Root::createRenderWindow");
    00712         }
    00713         RenderWindow* ret;
    00714         ret = mActiveRenderer->createRenderWindow(name, width, height, colourDepth, fullScreen, left, top,
    00715             depthBuffer, parentWindowHandle);
    00716
    00717         // Initialisation for classes dependent on first window created
    00718         oneTimePostWindowInit();
    00719
    00720         return ret;
    00721
    00722     }
    00723     //-----------------------------------------------------------------------
    00724     void Root::detachRenderTarget(RenderTarget* target)
    00725     {
    00726         if (!mActiveRenderer)
    00727         {
    00728             Except(Exception::ERR_NO_RENDERSYSTEM_SELECTED,
    00729             "Cannot create window - no render "
    00730             "system has been selected.", "Root::destroyRenderWindow");
    00731         }
    00732
    00733         mActiveRenderer->detachRenderTarget( target->getName() );
    00734     }
    00735     //-----------------------------------------------------------------------
    00736     void Root::detachRenderTarget(const String &name)
    00737     {
    00738         if (!mActiveRenderer)
    00739         {
    00740             Except(Exception::ERR_NO_RENDERSYSTEM_SELECTED,
    00741             "Cannot create window - no render "
    00742             "system has been selected.", "Root::destroyRenderWindow");
    00743         }
    00744
    00745         mActiveRenderer->detachRenderTarget( name );
    00746     }
    00747     //-----------------------------------------------------------------------
    00748     RenderTarget* Root::getRenderTarget(const String &name)
    00749     {
    00750         if (!mActiveRenderer)
    00751         {
    00752             Except(Exception::ERR_NO_RENDERSYSTEM_SELECTED,
    00753             "Cannot create window - no render "
    00754             "system has been selected.", "Root::getRenderWindow");
    00755         }
    00756
    00757         return mActiveRenderer->getRenderTarget(name);
    00758     }
    00759     //-----------------------------------------------------------------------
    00760     /*
    00761     void Root::showDebugOverlay(bool show)
    00762     {
    00763         Overlay* o = (Overlay*)OverlayManager::getSingleton().getByName("Core/DebugOverlay");
    00764         if (!o)
    00765             Except( Exception::ERR_ITEM_NOT_FOUND, "Could not find overlay Core/DebugOverlay",
    00766                 "Root::showDebugOverlay" );
    00767         if (show)
    00768         {
    00769             o->show();
    00770         }
    00771         else
    00772         {
    00773             o->hide();
    00774         }
    00775
    00776     }
    00777     */
    00778     //-----------------------------------------------------------------------
    00779     void Root::loadPlugin(const String& pluginName)
    00780     {
    00781         // Load plugin library
    00782         DynLib* lib = DynLibManager::getSingleton().load( pluginName );
    00783         // Store for later unload
    00784         mPluginLibs.push_back(lib);
    00785
    00786         // Call startup function
    00787         DLL_START_PLUGIN pFunc = (DLL_START_PLUGIN)lib->getSymbol("dllStartPlugin");
    00788
    00789         if (!pFunc)
    00790             Except(Exception::ERR_ITEM_NOT_FOUND, "Cannot find symbol dllStartPlugin in library " + pluginName,
    00791                 "Root::loadPlugins");
    00792         pFunc();
    00793     }
    00794     //-----------------------------------------------------------------------
    00795     void Root::unloadPlugin(const String& pluginName)
    00796     {
    00797         std::vector<DynLib*>::iterator i;
    00798
    00799         for (i = mPluginLibs.begin(); i != mPluginLibs.end(); ++i)
    00800         {
    00801             if ((*i)->getName() == pluginName)
    00802             {
    00803                 // Call plugin shutdown
    00804                 DLL_STOP_PLUGIN pFunc = (DLL_STOP_PLUGIN)(*i)->getSymbol("dllStopPlugin");
    00805                 pFunc();
    00806                 // Unload library & destroy
    00807                 DynLibManager::getSingleton().unload((Resource*)*i);
    00808                 delete *i;
    00809                 mPluginLibs.erase(i);
    00810                 return;
    00811             }
    00812
    00813         }
    00814     }
    00815     //-----------------------------------------------------------------------
    00816     Timer* Root::getTimer(void)
    00817     {
    00818         return mTimer;
    00819     }
    00820     //-----------------------------------------------------------------------
    00821     void Root::oneTimePostWindowInit(void)
    00822     {
    00823         if (!mFirstTimePostWindowInit)
    00824         {
    00825             // Initialise material manager
    00826             mMaterialManager->initialise();
    00827             // Init particle systems manager
    00828             mParticleManager->_initialise();
    00829             // parse all font scripts
    00830             mFontManager->parseAllSources();
    00831             // init overlays
    00832             mOverlayManager->parseAllSources();
    00833             // Init mesh manager
    00834             MeshManager::getSingleton()._initialise();
    00835             mFirstTimePostWindowInit = true;
    00836         }
    00837
    00838     }
    00839     //-----------------------------------------------------------------------
    00840     void Root::_updateAllRenderTargets(void)
    00841     {
    00842         // delegate
    00843         mActiveRenderer->_updateAllRenderTargets();
    00844     }
    00845 }

Copyright © 2002-2003 by The OGRE Team
Last modified Sun Nov 28 19:48:43 2004