[692] | 1 | /*
|
---|
| 2 | -----------------------------------------------------------------------------
|
---|
| 3 | This source file is part of OGRE
|
---|
| 4 | (Object-oriented Graphics Rendering Engine)
|
---|
| 5 | For the latest info, see http://ogre.sourceforge.net/
|
---|
| 6 |
|
---|
| 7 | Copyright (c) 2000-2005 The OGRE Team
|
---|
| 8 | Also see acknowledgements in Readme.html
|
---|
| 9 |
|
---|
| 10 | This program is free software; you can redistribute it and/or modify it under
|
---|
| 11 | the terms of the GNU Lesser General Public License as published by the Free Software
|
---|
| 12 | Foundation; either version 2 of the License, or (at your option) any later
|
---|
| 13 | version.
|
---|
| 14 |
|
---|
| 15 | This program is distributed in the hope that it will be useful, but WITHOUT
|
---|
| 16 | ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
---|
| 17 | FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
|
---|
| 18 |
|
---|
| 19 | You should have received a copy of the GNU Lesser General Public License along with
|
---|
| 20 | this program; if not, write to the Free Software Foundation, Inc., 59 Temple
|
---|
| 21 | Place - Suite 330, Boston, MA 02111-1307, USA, or go to
|
---|
| 22 | http://www.gnu.org/copyleft/lesser.txt.
|
---|
| 23 | -----------------------------------------------------------------------------
|
---|
| 24 | */
|
---|
| 25 | // Ogre includes
|
---|
| 26 | #include "OgreStableHeaders.h"
|
---|
| 27 |
|
---|
| 28 | #include "OgreRoot.h"
|
---|
| 29 |
|
---|
| 30 | #include "OgreRenderSystem.h"
|
---|
| 31 | #include "OgreRenderWindow.h"
|
---|
| 32 | #include "OgreException.h"
|
---|
| 33 | #include "OgreControllerManager.h"
|
---|
| 34 | #include "OgreLogManager.h"
|
---|
| 35 | #include "OgreMath.h"
|
---|
| 36 | #include "OgreDynLibManager.h"
|
---|
| 37 | #include "OgreDynLib.h"
|
---|
| 38 | #include "OgreConfigFile.h"
|
---|
| 39 | #include "OgreMaterialManager.h"
|
---|
| 40 | #include "OgreMeshManager.h"
|
---|
| 41 | #include "OgreTextureManager.h"
|
---|
| 42 | #include "OgreParticleSystemManager.h"
|
---|
| 43 | #include "OgreSkeletonManager.h"
|
---|
| 44 | #include "OgreOverlayElementFactory.h"
|
---|
| 45 | #include "OgreOverlayManager.h"
|
---|
| 46 | #include "OgreProfiler.h"
|
---|
| 47 | #include "OgreErrorDialog.h"
|
---|
| 48 | #include "OgreConfigDialog.h"
|
---|
| 49 | #include "OgreStringConverter.h"
|
---|
| 50 | #include "OgrePlatformManager.h"
|
---|
| 51 | #include "OgreArchiveManager.h"
|
---|
| 52 | #include "OgreZip.h"
|
---|
| 53 | #include "OgreFileSystem.h"
|
---|
| 54 | #include "OgreShadowVolumeExtrudeProgram.h"
|
---|
| 55 | #include "OgreResourceBackgroundQueue.h"
|
---|
| 56 | #include "OgreEntity.h"
|
---|
| 57 | #include "OgreBillboardSet.h"
|
---|
| 58 | #include "OgreBillboardChain.h"
|
---|
| 59 | #include "OgreRibbonTrail.h"
|
---|
| 60 | #include "OgreLight.h"
|
---|
| 61 | #include "OgreManualObject.h"
|
---|
| 62 | #include "OgreRenderQueueInvocation.h"
|
---|
| 63 |
|
---|
| 64 | #if OGRE_NO_DEVIL == 0
|
---|
| 65 | #include "OgreILCodecs.h"
|
---|
| 66 | #endif
|
---|
| 67 |
|
---|
| 68 | #include "OgreFontManager.h"
|
---|
| 69 | #include "OgreHardwareBufferManager.h"
|
---|
| 70 |
|
---|
| 71 | #include "OgreOverlay.h"
|
---|
| 72 | #include "OgreHighLevelGpuProgramManager.h"
|
---|
| 73 |
|
---|
| 74 | #include "OgreExternalTextureSourceManager.h"
|
---|
| 75 | #include "OgreCompositorManager.h"
|
---|
| 76 |
|
---|
| 77 | namespace Ogre {
|
---|
| 78 | //-----------------------------------------------------------------------
|
---|
| 79 | template<> Root* Singleton<Root>::ms_Singleton = 0;
|
---|
| 80 | Root* Root::getSingletonPtr(void)
|
---|
| 81 | {
|
---|
| 82 | return ms_Singleton;
|
---|
| 83 | }
|
---|
| 84 | Root& Root::getSingleton(void)
|
---|
| 85 | {
|
---|
| 86 | assert( ms_Singleton ); return ( *ms_Singleton );
|
---|
| 87 | }
|
---|
| 88 |
|
---|
| 89 | typedef void (*DLL_START_PLUGIN)(void);
|
---|
| 90 | typedef void (*DLL_INIT_PLUGIN)(void);
|
---|
| 91 | typedef void (*DLL_STOP_PLUGIN)(void);
|
---|
| 92 |
|
---|
| 93 |
|
---|
| 94 | //-----------------------------------------------------------------------
|
---|
| 95 | // Termination handler
|
---|
| 96 | extern "C" _OgreExport void handleTerminate(void)
|
---|
| 97 | {
|
---|
| 98 | LogManager::getSingleton().logMessage("Termination handler: uncaught exception!", LML_CRITICAL);
|
---|
| 99 |
|
---|
| 100 | Root::getSingleton().shutdown();
|
---|
| 101 |
|
---|
| 102 | ErrorDialog* dlg = PlatformManager::getSingleton().createErrorDialog();
|
---|
| 103 |
|
---|
| 104 | Exception* e = Exception::getLastException();
|
---|
| 105 |
|
---|
| 106 | if (e)
|
---|
| 107 | dlg->display(e->getFullDescription());
|
---|
| 108 | else
|
---|
| 109 | dlg->display("Unknown");
|
---|
| 110 |
|
---|
| 111 | // Abort
|
---|
| 112 | exit(-1);
|
---|
| 113 |
|
---|
| 114 | }
|
---|
| 115 |
|
---|
| 116 | void Root::termHandler()
|
---|
| 117 | {
|
---|
| 118 | handleTerminate();
|
---|
| 119 | }
|
---|
| 120 |
|
---|
| 121 |
|
---|
| 122 | //-----------------------------------------------------------------------
|
---|
| 123 | Root::Root(const String& pluginFileName, const String& configFileName, const String& logFileName)
|
---|
| 124 | : mLogManager(0), mCurrentFrame(0), mFrameSmoothingTime(0.0f),
|
---|
| 125 | mNextMovableObjectTypeFlag(1), mIsInitialised(false)
|
---|
| 126 | {
|
---|
| 127 | // First create new exception handler
|
---|
| 128 | SET_TERM_HANDLER;
|
---|
| 129 |
|
---|
| 130 | // superclass will do singleton checking
|
---|
| 131 | String msg;
|
---|
| 132 |
|
---|
| 133 | // Init
|
---|
| 134 | mActiveRenderer = 0;
|
---|
| 135 | mVersion = StringConverter::toString(OGRE_VERSION_MAJOR) + "." +
|
---|
| 136 | StringConverter::toString(OGRE_VERSION_MINOR) + "." +
|
---|
| 137 | StringConverter::toString(OGRE_VERSION_PATCH) + " " +
|
---|
| 138 | "(" + OGRE_VERSION_NAME + ")";
|
---|
| 139 | mConfigFileName = configFileName;
|
---|
| 140 |
|
---|
| 141 | // Create log manager and default log file if there is no log manager yet
|
---|
| 142 | if(LogManager::getSingletonPtr() == 0)
|
---|
| 143 | {
|
---|
| 144 | mLogManager = new LogManager();
|
---|
| 145 | mLogManager->createLog(logFileName, true, true);
|
---|
| 146 | }
|
---|
| 147 |
|
---|
| 148 | // Dynamic library manager
|
---|
| 149 | mDynLibManager = new DynLibManager();
|
---|
| 150 |
|
---|
| 151 | mArchiveManager = new ArchiveManager();
|
---|
| 152 |
|
---|
| 153 | // ResourceGroupManager
|
---|
| 154 | mResourceGroupManager = new ResourceGroupManager();
|
---|
| 155 |
|
---|
| 156 | // ResourceBackgroundQueue
|
---|
| 157 | mResourceBackgroundQueue = new ResourceBackgroundQueue();
|
---|
| 158 |
|
---|
| 159 | // Create SceneManager enumerator (note - will be managed by singleton)
|
---|
| 160 | mSceneManagerEnum = new SceneManagerEnumerator();
|
---|
| 161 | mCurrentSceneManager = NULL;
|
---|
| 162 |
|
---|
| 163 | // ..material manager
|
---|
| 164 | mMaterialManager = new MaterialManager();
|
---|
| 165 |
|
---|
| 166 | // Mesh manager
|
---|
| 167 | mMeshManager = new MeshManager();
|
---|
| 168 |
|
---|
| 169 | // Skeleton manager
|
---|
| 170 | mSkeletonManager = new SkeletonManager();
|
---|
| 171 |
|
---|
| 172 | // ..particle system manager
|
---|
| 173 | mParticleManager = new ParticleSystemManager();
|
---|
| 174 |
|
---|
| 175 | // Platform manager
|
---|
| 176 | mPlatformManager = new PlatformManager();
|
---|
| 177 |
|
---|
| 178 | // Timer
|
---|
| 179 | mTimer = mPlatformManager->createTimer();
|
---|
| 180 |
|
---|
| 181 | // Overlay manager
|
---|
| 182 | mOverlayManager = new OverlayManager();
|
---|
| 183 |
|
---|
| 184 | mPanelFactory = new PanelOverlayElementFactory();
|
---|
| 185 | mOverlayManager->addOverlayElementFactory(mPanelFactory);
|
---|
| 186 |
|
---|
| 187 | mBorderPanelFactory = new BorderPanelOverlayElementFactory();
|
---|
| 188 | mOverlayManager->addOverlayElementFactory(mBorderPanelFactory);
|
---|
| 189 |
|
---|
| 190 | mTextAreaFactory = new TextAreaOverlayElementFactory();
|
---|
| 191 | mOverlayManager->addOverlayElementFactory(mTextAreaFactory);
|
---|
| 192 | // Font manager
|
---|
| 193 | mFontManager = new FontManager();
|
---|
| 194 |
|
---|
| 195 | #if OGRE_PROFILING
|
---|
| 196 | // Profiler
|
---|
| 197 | mProfiler = new Profiler();
|
---|
| 198 | Profiler::getSingleton().setTimer(mTimer);
|
---|
| 199 | #endif
|
---|
| 200 | mFileSystemArchiveFactory = new FileSystemArchiveFactory();
|
---|
| 201 | ArchiveManager::getSingleton().addArchiveFactory( mFileSystemArchiveFactory );
|
---|
| 202 | mZipArchiveFactory = new ZipArchiveFactory();
|
---|
| 203 | ArchiveManager::getSingleton().addArchiveFactory( mZipArchiveFactory );
|
---|
| 204 | #if OGRE_NO_DEVIL == 0
|
---|
| 205 | // Register image codecs
|
---|
| 206 | ILCodecs::registerCodecs();
|
---|
| 207 | #endif
|
---|
| 208 |
|
---|
| 209 | mHighLevelGpuProgramManager = new HighLevelGpuProgramManager();
|
---|
| 210 |
|
---|
| 211 | mExternalTextureSourceManager = new ExternalTextureSourceManager();
|
---|
| 212 | mCompositorManager = new CompositorManager();
|
---|
| 213 |
|
---|
| 214 | // Auto window
|
---|
| 215 | mAutoWindow = 0;
|
---|
| 216 |
|
---|
| 217 | // instantiate and register base movable factories
|
---|
| 218 | mEntityFactory = new EntityFactory();
|
---|
| 219 | addMovableObjectFactory(mEntityFactory);
|
---|
| 220 | mLightFactory = new LightFactory();
|
---|
| 221 | addMovableObjectFactory(mLightFactory);
|
---|
| 222 | mBillboardSetFactory = new BillboardSetFactory();
|
---|
| 223 | addMovableObjectFactory(mBillboardSetFactory);
|
---|
| 224 | mManualObjectFactory = new ManualObjectFactory();
|
---|
| 225 | addMovableObjectFactory(mManualObjectFactory);
|
---|
| 226 | mBillboardChainFactory = new BillboardChainFactory();
|
---|
| 227 | addMovableObjectFactory(mBillboardChainFactory);
|
---|
| 228 | mRibbonTrailFactory = new RibbonTrailFactory();
|
---|
| 229 | addMovableObjectFactory(mRibbonTrailFactory);
|
---|
| 230 |
|
---|
| 231 | // Load plugins
|
---|
| 232 | if (!pluginFileName.empty())
|
---|
| 233 | loadPlugins(pluginFileName);
|
---|
| 234 |
|
---|
| 235 | LogManager::getSingleton().logMessage("*-*-* OGRE Initialising");
|
---|
| 236 | msg = "*-*-* Version " + mVersion;
|
---|
| 237 | LogManager::getSingleton().logMessage(msg);
|
---|
| 238 |
|
---|
| 239 | // Can't create managers until initialised
|
---|
| 240 | mControllerManager = 0;
|
---|
| 241 |
|
---|
| 242 | mFirstTimePostWindowInit = false;
|
---|
| 243 |
|
---|
| 244 | }
|
---|
| 245 |
|
---|
| 246 | //-----------------------------------------------------------------------
|
---|
| 247 | Root::~Root()
|
---|
| 248 | {
|
---|
| 249 | shutdown();
|
---|
| 250 | delete mSceneManagerEnum;
|
---|
| 251 |
|
---|
| 252 | destroyAllRenderQueueInvocationSequences();
|
---|
| 253 | delete mCompositorManager;
|
---|
| 254 | delete mExternalTextureSourceManager;
|
---|
| 255 | #if OGRE_NO_DEVIL == 0
|
---|
| 256 | ILCodecs::deleteCodecs();
|
---|
| 257 | #endif
|
---|
| 258 | #if OGRE_PROFILING
|
---|
| 259 | delete mProfiler;
|
---|
| 260 | #endif
|
---|
| 261 | delete mOverlayManager;
|
---|
| 262 | delete mFontManager;
|
---|
| 263 | delete mArchiveManager;
|
---|
| 264 | delete mZipArchiveFactory;
|
---|
| 265 | delete mFileSystemArchiveFactory;
|
---|
| 266 | delete mSkeletonManager;
|
---|
| 267 | delete mMeshManager;
|
---|
| 268 | delete mParticleManager;
|
---|
| 269 |
|
---|
| 270 | if( mControllerManager )
|
---|
| 271 | delete mControllerManager;
|
---|
| 272 | if (mHighLevelGpuProgramManager)
|
---|
| 273 | delete mHighLevelGpuProgramManager;
|
---|
| 274 |
|
---|
| 275 | delete mTextAreaFactory;
|
---|
| 276 | delete mBorderPanelFactory;
|
---|
| 277 | delete mPanelFactory;
|
---|
| 278 |
|
---|
| 279 | unloadPlugins();
|
---|
| 280 | delete mMaterialManager;
|
---|
| 281 | Pass::processPendingPassUpdates(); // make sure passes are cleaned
|
---|
| 282 | delete mResourceBackgroundQueue;
|
---|
| 283 | delete mResourceGroupManager;
|
---|
| 284 |
|
---|
| 285 | delete mEntityFactory;
|
---|
| 286 | delete mLightFactory;
|
---|
| 287 | delete mBillboardSetFactory;
|
---|
| 288 | delete mManualObjectFactory;
|
---|
| 289 | delete mBillboardChainFactory;
|
---|
| 290 | delete mRibbonTrailFactory;
|
---|
| 291 |
|
---|
| 292 |
|
---|
| 293 | mPlatformManager->destroyTimer(mTimer);
|
---|
| 294 | delete mPlatformManager;
|
---|
| 295 | delete mDynLibManager;
|
---|
| 296 | delete mLogManager;
|
---|
| 297 |
|
---|
| 298 |
|
---|
| 299 | StringInterface::cleanupDictionary ();
|
---|
| 300 | }
|
---|
| 301 |
|
---|
| 302 | //-----------------------------------------------------------------------
|
---|
| 303 | void Root::saveConfig(void)
|
---|
| 304 | {
|
---|
| 305 | std::ofstream of(mConfigFileName.c_str());
|
---|
| 306 |
|
---|
| 307 | if (!of)
|
---|
| 308 | OGRE_EXCEPT(Exception::ERR_CANNOT_WRITE_TO_FILE, "Cannot create settings file.",
|
---|
| 309 | "Root::saveConfig");
|
---|
| 310 |
|
---|
| 311 | if (mActiveRenderer)
|
---|
| 312 | {
|
---|
| 313 | of << "Render System=" << mActiveRenderer->getName() << std::endl;
|
---|
| 314 | }
|
---|
| 315 | else
|
---|
| 316 | {
|
---|
| 317 | of << "Render System=" << std::endl;
|
---|
| 318 | }
|
---|
| 319 |
|
---|
| 320 | for (RenderSystemList::const_iterator pRend = getAvailableRenderers()->begin(); pRend != getAvailableRenderers()->end(); ++pRend)
|
---|
| 321 | {
|
---|
| 322 | RenderSystem* rs = *pRend;
|
---|
| 323 | of << std::endl;
|
---|
| 324 | of << "[" << rs->getName() << "]" << std::endl;
|
---|
| 325 | const ConfigOptionMap& opts = rs->getConfigOptions();
|
---|
| 326 | for (ConfigOptionMap::const_iterator pOpt = opts.begin(); pOpt != opts.end(); ++pOpt)
|
---|
| 327 | {
|
---|
| 328 | of << pOpt->first << "=" << pOpt->second.currentValue << std::endl;
|
---|
| 329 | }
|
---|
| 330 | }
|
---|
| 331 |
|
---|
| 332 | of.close();
|
---|
| 333 |
|
---|
| 334 | }
|
---|
| 335 | //-----------------------------------------------------------------------
|
---|
| 336 | bool Root::restoreConfig(void)
|
---|
| 337 | {
|
---|
| 338 | // Restores configuration from saved state
|
---|
| 339 | // Returns true if a valid saved configuration is
|
---|
| 340 | // available, and false if no saved config is
|
---|
| 341 | // stored, or if there has been a problem
|
---|
| 342 | ConfigFile cfg;
|
---|
| 343 | //RenderSystemList::iterator pRend;
|
---|
| 344 |
|
---|
| 345 | try {
|
---|
| 346 | // Don't trim whitespace
|
---|
| 347 | cfg.load(mConfigFileName, "\t:=", false);
|
---|
| 348 | }
|
---|
| 349 | catch (Exception& e)
|
---|
| 350 | {
|
---|
| 351 | if (e.getNumber() == Exception::ERR_FILE_NOT_FOUND)
|
---|
| 352 | {
|
---|
| 353 | return false;
|
---|
| 354 | }
|
---|
| 355 | else
|
---|
| 356 | {
|
---|
| 357 | throw;
|
---|
| 358 | }
|
---|
| 359 | }
|
---|
| 360 |
|
---|
| 361 | ConfigFile::SectionIterator iSection = cfg.getSectionIterator();
|
---|
| 362 | while (iSection.hasMoreElements())
|
---|
| 363 | {
|
---|
| 364 | const String& renderSystem = iSection.peekNextKey();
|
---|
| 365 | const ConfigFile::SettingsMultiMap& settings = *iSection.getNext();
|
---|
| 366 |
|
---|
| 367 | RenderSystem* rs = getRenderSystemByName(renderSystem);
|
---|
| 368 | if (!rs)
|
---|
| 369 | {
|
---|
| 370 | // Unrecognised render system
|
---|
| 371 | continue;
|
---|
| 372 | }
|
---|
| 373 |
|
---|
| 374 | ConfigFile::SettingsMultiMap::const_iterator i;
|
---|
| 375 | for (i = settings.begin(); i != settings.end(); ++i)
|
---|
| 376 | {
|
---|
| 377 | rs->setConfigOption(i->first, i->second);
|
---|
| 378 | }
|
---|
| 379 | }
|
---|
| 380 |
|
---|
| 381 | RenderSystem* rs = getRenderSystemByName(cfg.getSetting("Render System"));
|
---|
| 382 | if (!rs)
|
---|
| 383 | {
|
---|
| 384 | // Unrecognised render system
|
---|
| 385 | return false;
|
---|
| 386 | }
|
---|
| 387 |
|
---|
| 388 | setRenderSystem(rs);
|
---|
| 389 |
|
---|
| 390 | // Successful load
|
---|
| 391 | return true;
|
---|
| 392 |
|
---|
| 393 | }
|
---|
| 394 |
|
---|
| 395 | //-----------------------------------------------------------------------
|
---|
| 396 | bool Root::showConfigDialog(void)
|
---|
| 397 | {
|
---|
| 398 | // Displays the standard config dialog
|
---|
| 399 | // Will use stored defaults if available
|
---|
| 400 | ConfigDialog* dlg;
|
---|
| 401 | bool isOk;
|
---|
| 402 |
|
---|
| 403 | dlg = mPlatformManager->createConfigDialog();
|
---|
| 404 |
|
---|
| 405 | isOk = dlg->display();
|
---|
| 406 |
|
---|
| 407 | mPlatformManager->destroyConfigDialog(dlg);
|
---|
| 408 |
|
---|
| 409 | return isOk;
|
---|
| 410 |
|
---|
| 411 | }
|
---|
| 412 |
|
---|
| 413 | //-----------------------------------------------------------------------
|
---|
| 414 | RenderSystemList* Root::getAvailableRenderers(void)
|
---|
| 415 | {
|
---|
| 416 | // Returns a vector of renders
|
---|
| 417 |
|
---|
| 418 | return &mRenderers;
|
---|
| 419 |
|
---|
| 420 | }
|
---|
| 421 |
|
---|
| 422 | //-----------------------------------------------------------------------
|
---|
| 423 | RenderSystem* Root::getRenderSystemByName(const String& name)
|
---|
| 424 | {
|
---|
| 425 | if (name.empty())
|
---|
| 426 | {
|
---|
| 427 | // No render system
|
---|
| 428 | return NULL;
|
---|
| 429 | }
|
---|
| 430 |
|
---|
| 431 | RenderSystemList::const_iterator pRend;
|
---|
| 432 | for (pRend = getAvailableRenderers()->begin(); pRend != getAvailableRenderers()->end(); ++pRend)
|
---|
| 433 | {
|
---|
| 434 | RenderSystem* rs = *pRend;
|
---|
| 435 | if (rs->getName() == name)
|
---|
| 436 | return rs;
|
---|
| 437 | }
|
---|
| 438 |
|
---|
| 439 | // Unrecognised render system
|
---|
| 440 | return NULL;
|
---|
| 441 | }
|
---|
| 442 |
|
---|
| 443 | //-----------------------------------------------------------------------
|
---|
| 444 | void Root::setRenderSystem(RenderSystem* system)
|
---|
| 445 | {
|
---|
| 446 | // Sets the active rendering system
|
---|
| 447 | // Can be called direct or will be called by
|
---|
| 448 | // standard config dialog
|
---|
| 449 |
|
---|
| 450 | // Is there already an active renderer?
|
---|
| 451 | // If so, disable it and init the new one
|
---|
| 452 | if( mActiveRenderer && mActiveRenderer != system )
|
---|
| 453 | {
|
---|
| 454 | mActiveRenderer->shutdown();
|
---|
| 455 | }
|
---|
| 456 |
|
---|
| 457 | mActiveRenderer = system;
|
---|
| 458 | // Tell scene managers
|
---|
| 459 | SceneManagerEnumerator::getSingleton().setRenderSystem(system);
|
---|
| 460 |
|
---|
| 461 | }
|
---|
| 462 | //-----------------------------------------------------------------------
|
---|
| 463 | void Root::addRenderSystem(RenderSystem *newRend)
|
---|
| 464 | {
|
---|
| 465 | mRenderers.push_back(newRend);
|
---|
| 466 | }
|
---|
| 467 | //-----------------------------------------------------------------------
|
---|
| 468 | void Root::_setCurrentSceneManager(SceneManager* sm)
|
---|
| 469 | {
|
---|
| 470 | mCurrentSceneManager = sm;
|
---|
| 471 | }
|
---|
| 472 | //-----------------------------------------------------------------------
|
---|
| 473 | RenderSystem* Root::getRenderSystem(void)
|
---|
| 474 | {
|
---|
| 475 | // Gets the currently active renderer
|
---|
| 476 | return mActiveRenderer;
|
---|
| 477 |
|
---|
| 478 | }
|
---|
| 479 |
|
---|
| 480 | //-----------------------------------------------------------------------
|
---|
| 481 | RenderWindow* Root::initialise(bool autoCreateWindow, const String& windowTitle)
|
---|
| 482 | {
|
---|
| 483 | if (!mActiveRenderer)
|
---|
| 484 | OGRE_EXCEPT(Exception::ERR_NO_RENDERSYSTEM_SELECTED,
|
---|
| 485 | "Cannot initialise - no render "
|
---|
| 486 | "system has been selected.", "Root::initialise");
|
---|
| 487 |
|
---|
| 488 | if (!mControllerManager)
|
---|
| 489 | mControllerManager = new ControllerManager();
|
---|
| 490 |
|
---|
| 491 | mAutoWindow = mActiveRenderer->initialise(autoCreateWindow, windowTitle);
|
---|
| 492 |
|
---|
| 493 | mResourceBackgroundQueue->initialise();
|
---|
| 494 |
|
---|
| 495 | if (autoCreateWindow && !mFirstTimePostWindowInit)
|
---|
| 496 | {
|
---|
| 497 | oneTimePostWindowInit();
|
---|
| 498 | mAutoWindow->_setPrimary();
|
---|
| 499 | }
|
---|
| 500 |
|
---|
| 501 | // Initialise timer
|
---|
| 502 | mTimer->reset();
|
---|
| 503 |
|
---|
| 504 | // Init plugins
|
---|
| 505 | initialisePlugins();
|
---|
| 506 |
|
---|
| 507 | mIsInitialised = true;
|
---|
| 508 |
|
---|
| 509 | return mAutoWindow;
|
---|
| 510 |
|
---|
| 511 | }
|
---|
| 512 | //-----------------------------------------------------------------------
|
---|
| 513 | String Root::getErrorDescription(long errorNumber)
|
---|
| 514 | {
|
---|
| 515 |
|
---|
| 516 | // Pass to render system
|
---|
| 517 | if (mActiveRenderer)
|
---|
| 518 | return mActiveRenderer->getErrorDescription(errorNumber);
|
---|
| 519 | else
|
---|
| 520 | return "";
|
---|
| 521 |
|
---|
| 522 | }
|
---|
| 523 | //-----------------------------------------------------------------------
|
---|
| 524 | void Root::addSceneManagerFactory(SceneManagerFactory* fact)
|
---|
| 525 | {
|
---|
| 526 | mSceneManagerEnum->addFactory(fact);
|
---|
| 527 | }
|
---|
| 528 | //-----------------------------------------------------------------------
|
---|
| 529 | void Root::removeSceneManagerFactory(SceneManagerFactory* fact)
|
---|
| 530 | {
|
---|
| 531 | mSceneManagerEnum->removeFactory(fact);
|
---|
| 532 | }
|
---|
| 533 | //-----------------------------------------------------------------------
|
---|
| 534 | const SceneManagerMetaData* Root::getSceneManagerMetaData(const String& typeName) const
|
---|
| 535 | {
|
---|
| 536 | return mSceneManagerEnum->getMetaData(typeName);
|
---|
| 537 | }
|
---|
| 538 | //-----------------------------------------------------------------------
|
---|
| 539 | SceneManagerEnumerator::MetaDataIterator
|
---|
| 540 | Root::getSceneManagerMetaDataIterator(void) const
|
---|
| 541 | {
|
---|
| 542 | return mSceneManagerEnum->getMetaDataIterator();
|
---|
| 543 |
|
---|
| 544 | }
|
---|
| 545 | //-----------------------------------------------------------------------
|
---|
| 546 | SceneManager* Root::createSceneManager(const String& typeName,
|
---|
| 547 | const String& instanceName)
|
---|
| 548 | {
|
---|
| 549 | return mSceneManagerEnum->createSceneManager(typeName, instanceName);
|
---|
| 550 | }
|
---|
| 551 | //-----------------------------------------------------------------------
|
---|
| 552 | SceneManager* Root::createSceneManager(SceneTypeMask typeMask,
|
---|
| 553 | const String& instanceName)
|
---|
| 554 | {
|
---|
| 555 | return mSceneManagerEnum->createSceneManager(typeMask, instanceName);
|
---|
| 556 | }
|
---|
| 557 | //-----------------------------------------------------------------------
|
---|
| 558 | void Root::destroySceneManager(SceneManager* sm)
|
---|
| 559 | {
|
---|
| 560 | mSceneManagerEnum->destroySceneManager(sm);
|
---|
| 561 | }
|
---|
| 562 | //-----------------------------------------------------------------------
|
---|
| 563 | SceneManager* Root::getSceneManager(const String& instanceName) const
|
---|
| 564 | {
|
---|
| 565 | return mSceneManagerEnum->getSceneManager(instanceName);
|
---|
| 566 | }
|
---|
| 567 | //-----------------------------------------------------------------------
|
---|
| 568 | SceneManagerEnumerator::SceneManagerIterator Root::getSceneManagerIterator(void)
|
---|
| 569 | {
|
---|
| 570 | return mSceneManagerEnum->getSceneManagerIterator();
|
---|
| 571 | }
|
---|
| 572 | //-----------------------------------------------------------------------
|
---|
| 573 | TextureManager* Root::getTextureManager(void)
|
---|
| 574 | {
|
---|
| 575 | return &TextureManager::getSingleton();
|
---|
| 576 | }
|
---|
| 577 | //-----------------------------------------------------------------------
|
---|
| 578 | MeshManager* Root::getMeshManager(void)
|
---|
| 579 | {
|
---|
| 580 | return &MeshManager::getSingleton();
|
---|
| 581 | }
|
---|
| 582 | //-----------------------------------------------------------------------
|
---|
| 583 | void Root::addFrameListener(FrameListener* newListener)
|
---|
| 584 | {
|
---|
| 585 | // Insert, unique only (set)
|
---|
| 586 | mFrameListeners.insert(newListener);
|
---|
| 587 |
|
---|
| 588 | }
|
---|
| 589 |
|
---|
| 590 | //-----------------------------------------------------------------------
|
---|
| 591 | void Root::removeFrameListener(FrameListener* oldListener)
|
---|
| 592 | {
|
---|
| 593 | // Remove, 1 only (set)
|
---|
| 594 | mRemovedFrameListeners.insert(oldListener);
|
---|
| 595 | }
|
---|
| 596 | //-----------------------------------------------------------------------
|
---|
| 597 | bool Root::_fireFrameStarted(FrameEvent& evt)
|
---|
| 598 | {
|
---|
| 599 | // Increment frame number
|
---|
| 600 | ++mCurrentFrame;
|
---|
| 601 |
|
---|
| 602 | // Remove all marked listeners
|
---|
| 603 | std::set<FrameListener*>::iterator i;
|
---|
| 604 | for (i = mRemovedFrameListeners.begin();
|
---|
| 605 | i != mRemovedFrameListeners.end(); i++)
|
---|
| 606 | {
|
---|
| 607 | mFrameListeners.erase(*i);
|
---|
| 608 | }
|
---|
| 609 | mRemovedFrameListeners.clear();
|
---|
| 610 |
|
---|
| 611 | // Tell all listeners
|
---|
| 612 | for (i= mFrameListeners.begin(); i != mFrameListeners.end(); ++i)
|
---|
| 613 | {
|
---|
| 614 | if (!(*i)->frameStarted(evt))
|
---|
| 615 | return false;
|
---|
| 616 | }
|
---|
| 617 |
|
---|
| 618 | return true;
|
---|
| 619 |
|
---|
| 620 | }
|
---|
| 621 | //-----------------------------------------------------------------------
|
---|
| 622 | bool Root::_fireFrameEnded(FrameEvent& evt)
|
---|
| 623 | {
|
---|
| 624 | // Remove all marked listeners
|
---|
| 625 | std::set<FrameListener*>::iterator i;
|
---|
| 626 | for (i = mRemovedFrameListeners.begin();
|
---|
| 627 | i != mRemovedFrameListeners.end(); i++)
|
---|
| 628 | {
|
---|
| 629 | mFrameListeners.erase(*i);
|
---|
| 630 | }
|
---|
| 631 | mRemovedFrameListeners.clear();
|
---|
| 632 |
|
---|
| 633 | // Tell all listeners
|
---|
| 634 | bool ret = true;
|
---|
| 635 | for (i= mFrameListeners.begin(); i != mFrameListeners.end(); ++i)
|
---|
| 636 | {
|
---|
| 637 | if (!(*i)->frameEnded(evt))
|
---|
| 638 | {
|
---|
| 639 | ret = false;
|
---|
| 640 | break;
|
---|
| 641 | }
|
---|
| 642 | }
|
---|
| 643 |
|
---|
| 644 | // Tell buffer manager to free temp buffers used this frame
|
---|
| 645 | if (HardwareBufferManager::getSingletonPtr())
|
---|
| 646 | HardwareBufferManager::getSingleton()._releaseBufferCopies();
|
---|
| 647 |
|
---|
| 648 | return ret;
|
---|
| 649 | }
|
---|
| 650 | //-----------------------------------------------------------------------
|
---|
| 651 | bool Root::_fireFrameStarted()
|
---|
| 652 | {
|
---|
| 653 | unsigned long now = mTimer->getMilliseconds();
|
---|
| 654 | FrameEvent evt;
|
---|
| 655 | evt.timeSinceLastEvent = calculateEventTime(now, FETT_ANY);
|
---|
| 656 | evt.timeSinceLastFrame = calculateEventTime(now, FETT_STARTED);
|
---|
| 657 |
|
---|
| 658 | return _fireFrameStarted(evt);
|
---|
| 659 | }
|
---|
| 660 | //-----------------------------------------------------------------------
|
---|
| 661 | bool Root::_fireFrameEnded()
|
---|
| 662 | {
|
---|
| 663 | unsigned long now = mTimer->getMilliseconds();
|
---|
| 664 | FrameEvent evt;
|
---|
| 665 | evt.timeSinceLastEvent = calculateEventTime(now, FETT_ANY);
|
---|
| 666 | evt.timeSinceLastFrame = calculateEventTime(now, FETT_ENDED);
|
---|
| 667 |
|
---|
| 668 | return _fireFrameEnded(evt);
|
---|
| 669 | }
|
---|
| 670 | //-----------------------------------------------------------------------
|
---|
| 671 | Real Root::calculateEventTime(unsigned long now, FrameEventTimeType type)
|
---|
| 672 | {
|
---|
| 673 | // Calculate the average time passed between events of the given type
|
---|
| 674 | // during the last mFrameSmoothingTime seconds.
|
---|
| 675 |
|
---|
| 676 | std::deque<unsigned long>& times = mEventTimes[type];
|
---|
| 677 | times.push_back(now);
|
---|
| 678 |
|
---|
| 679 | if(times.size() == 1)
|
---|
| 680 | return 0;
|
---|
| 681 |
|
---|
| 682 | // Times up to mFrameSmoothingTime seconds old should be kept
|
---|
| 683 | unsigned long discardThreshold =
|
---|
| 684 | static_cast<unsigned long>(mFrameSmoothingTime * 1000.0f);
|
---|
| 685 |
|
---|
| 686 | // Find the oldest time to keep
|
---|
| 687 | std::deque<unsigned long>::iterator it = times.begin(),
|
---|
| 688 | end = times.end()-2; // We need at least two times
|
---|
| 689 | while(it != end)
|
---|
| 690 | {
|
---|
| 691 | if (now - *it > discardThreshold)
|
---|
| 692 | ++it;
|
---|
| 693 | else
|
---|
| 694 | break;
|
---|
| 695 | }
|
---|
| 696 |
|
---|
| 697 | // Remove old times
|
---|
| 698 | times.erase(times.begin(), it);
|
---|
| 699 |
|
---|
| 700 | return Real(times.back() - times.front()) / ((times.size()-1) * 1000);
|
---|
| 701 | }
|
---|
| 702 | //-----------------------------------------------------------------------
|
---|
| 703 | void Root::queueEndRendering(void)
|
---|
| 704 | {
|
---|
| 705 | mQueuedEnd = true;
|
---|
| 706 | }
|
---|
| 707 | //-----------------------------------------------------------------------
|
---|
| 708 | void Root::startRendering(void)
|
---|
| 709 | {
|
---|
| 710 | assert(mActiveRenderer != 0);
|
---|
| 711 |
|
---|
| 712 | mActiveRenderer->_initRenderTargets();
|
---|
| 713 |
|
---|
| 714 | // Clear event times
|
---|
| 715 | for(int i=0; i!=3; ++i)
|
---|
| 716 | mEventTimes[i].clear();
|
---|
| 717 |
|
---|
| 718 | // Infinite loop, until broken out of by frame listeners
|
---|
| 719 | // or break out by calling queueEndRendering()
|
---|
| 720 | mQueuedEnd = false;
|
---|
| 721 |
|
---|
| 722 | while( !mQueuedEnd )
|
---|
| 723 | {
|
---|
| 724 | //Allow platform to pump/create/etc messages/events once per frame
|
---|
| 725 | mPlatformManager->messagePump(mAutoWindow);
|
---|
| 726 |
|
---|
| 727 | if (!renderOneFrame())
|
---|
| 728 | break;
|
---|
| 729 | }
|
---|
| 730 | }
|
---|
| 731 | //-----------------------------------------------------------------------
|
---|
| 732 | bool Root::renderOneFrame(void)
|
---|
| 733 | {
|
---|
| 734 | if(!_fireFrameStarted())
|
---|
| 735 | return false;
|
---|
| 736 |
|
---|
| 737 | _updateAllRenderTargets();
|
---|
| 738 |
|
---|
| 739 | return _fireFrameEnded();
|
---|
| 740 | }
|
---|
| 741 | //-----------------------------------------------------------------------
|
---|
| 742 | void Root::shutdown(void)
|
---|
| 743 | {
|
---|
| 744 | SceneManagerEnumerator::getSingleton().shutdownAll();
|
---|
| 745 | shutdownPlugins();
|
---|
| 746 |
|
---|
| 747 | ShadowVolumeExtrudeProgram::shutdown();
|
---|
| 748 | mResourceBackgroundQueue->shutdown();
|
---|
| 749 | ResourceGroupManager::getSingleton().shutdownAll();
|
---|
| 750 |
|
---|
| 751 | mIsInitialised = false;
|
---|
| 752 |
|
---|
| 753 | LogManager::getSingleton().logMessage("*-*-* OGRE Shutdown");
|
---|
| 754 | }
|
---|
| 755 | //-----------------------------------------------------------------------
|
---|
| 756 | void Root::loadPlugins( const String& pluginsfile )
|
---|
| 757 | {
|
---|
| 758 | StringVector pluginList;
|
---|
| 759 | String pluginDir;
|
---|
| 760 | ConfigFile cfg;
|
---|
| 761 |
|
---|
| 762 | try {
|
---|
| 763 | cfg.load( pluginsfile );
|
---|
| 764 | }
|
---|
| 765 | catch (Exception)
|
---|
| 766 | {
|
---|
| 767 | LogManager::getSingleton().logMessage(pluginsfile + " not found, automatic plugin loading disabled.");
|
---|
| 768 | return;
|
---|
| 769 | }
|
---|
| 770 |
|
---|
| 771 | pluginDir = cfg.getSetting("PluginFolder"); // Ignored on Mac OS X, uses Resources/ directory
|
---|
| 772 | pluginList = cfg.getMultiSetting("Plugin");
|
---|
| 773 |
|
---|
| 774 | char last_char = pluginDir[pluginDir.length()-1];
|
---|
| 775 | if (last_char != '/' && last_char != '\\')
|
---|
| 776 | {
|
---|
| 777 | #if OGRE_PLATFORM == OGRE_PLATFORM_WIN32
|
---|
| 778 | pluginDir += "\\";
|
---|
| 779 | #elif OGRE_PLATFORM == OGRE_PLATFORM_LINUX
|
---|
| 780 | pluginDir += "/";
|
---|
| 781 | #endif
|
---|
| 782 | }
|
---|
| 783 |
|
---|
| 784 | for( StringVector::iterator it = pluginList.begin(); it != pluginList.end(); ++it )
|
---|
| 785 | {
|
---|
| 786 | loadPlugin(pluginDir + (*it));
|
---|
| 787 | }
|
---|
| 788 |
|
---|
| 789 | }
|
---|
| 790 | //-----------------------------------------------------------------------
|
---|
| 791 | void Root::shutdownPlugins(void)
|
---|
| 792 | {
|
---|
| 793 | std::vector<DynLib*>::reverse_iterator i;
|
---|
| 794 |
|
---|
| 795 | // NB Shutdown plugins in reverse order to enforce dependencies
|
---|
| 796 | for (i = mPluginLibs.rbegin(); i != mPluginLibs.rend(); ++i)
|
---|
| 797 | {
|
---|
| 798 | // Call plugin shutdown (optional)
|
---|
| 799 | DLL_STOP_PLUGIN pFunc = (DLL_STOP_PLUGIN)(*i)->getSymbol("dllShutdownPlugin");
|
---|
| 800 | if (pFunc)
|
---|
| 801 | {
|
---|
| 802 | pFunc();
|
---|
| 803 | }
|
---|
| 804 |
|
---|
| 805 | }
|
---|
| 806 | }
|
---|
| 807 | //-----------------------------------------------------------------------
|
---|
| 808 | void Root::initialisePlugins(void)
|
---|
| 809 | {
|
---|
| 810 | std::vector<DynLib*>::iterator i;
|
---|
| 811 |
|
---|
| 812 | for (i = mPluginLibs.begin(); i != mPluginLibs.end(); ++i)
|
---|
| 813 | {
|
---|
| 814 | // Call plugin initialise (optional)
|
---|
| 815 | DLL_INIT_PLUGIN pFunc = (DLL_INIT_PLUGIN)(*i)->getSymbol("dllInitialisePlugin");
|
---|
| 816 | if (pFunc)
|
---|
| 817 | {
|
---|
| 818 | pFunc();
|
---|
| 819 | }
|
---|
| 820 |
|
---|
| 821 | }
|
---|
| 822 | }
|
---|
| 823 | //-----------------------------------------------------------------------
|
---|
| 824 | void Root::unloadPlugins(void)
|
---|
| 825 | {
|
---|
| 826 | std::vector<DynLib*>::reverse_iterator i;
|
---|
| 827 |
|
---|
| 828 | // NB Unload plugins in reverse order to enforce dependencies
|
---|
| 829 | for (i = mPluginLibs.rbegin(); i != mPluginLibs.rend(); ++i)
|
---|
| 830 | {
|
---|
| 831 | // Call plugin shutdown
|
---|
| 832 | DLL_STOP_PLUGIN pFunc = (DLL_STOP_PLUGIN)(*i)->getSymbol("dllStopPlugin");
|
---|
| 833 | pFunc();
|
---|
| 834 | // Unload library & destroy
|
---|
| 835 | DynLibManager::getSingleton().unload(*i);
|
---|
| 836 |
|
---|
| 837 | }
|
---|
| 838 |
|
---|
| 839 | mPluginLibs.clear();
|
---|
| 840 |
|
---|
| 841 | }
|
---|
| 842 | //-----------------------------------------------------------------------
|
---|
| 843 | void Root::addResourceLocation(const String& name, const String& locType,
|
---|
| 844 | const String& groupName, bool recursive)
|
---|
| 845 | {
|
---|
| 846 | ResourceGroupManager::getSingleton().addResourceLocation(
|
---|
| 847 | name, locType, groupName, recursive);
|
---|
| 848 | }
|
---|
| 849 | //-----------------------------------------------------------------------
|
---|
| 850 | void Root::removeResourceLocation(const String& name, const String& groupName)
|
---|
| 851 | {
|
---|
| 852 | ResourceGroupManager::getSingleton().removeResourceLocation(
|
---|
| 853 | name, groupName);
|
---|
| 854 | }
|
---|
| 855 | //-----------------------------------------------------------------------
|
---|
| 856 | void Root::convertColourValue(const ColourValue& colour, uint32* pDest)
|
---|
| 857 | {
|
---|
| 858 | assert(mActiveRenderer != 0);
|
---|
| 859 | mActiveRenderer->convertColourValue(colour, pDest);
|
---|
| 860 | }
|
---|
| 861 | //-----------------------------------------------------------------------
|
---|
| 862 | RenderWindow* Root::getAutoCreatedWindow(void)
|
---|
| 863 | {
|
---|
| 864 | return mAutoWindow;
|
---|
| 865 | }
|
---|
| 866 | //-----------------------------------------------------------------------
|
---|
| 867 | RenderWindow* Root::createRenderWindow(const String &name, unsigned int width, unsigned int height,
|
---|
| 868 | bool fullScreen, const NameValuePairList *miscParams)
|
---|
| 869 | {
|
---|
| 870 | if (!mActiveRenderer)
|
---|
| 871 | {
|
---|
| 872 | OGRE_EXCEPT(Exception::ERR_NO_RENDERSYSTEM_SELECTED,
|
---|
| 873 | "Cannot create window - no render "
|
---|
| 874 | "system has been selected.", "Root::createRenderWindow");
|
---|
| 875 | }
|
---|
| 876 | RenderWindow* ret;
|
---|
| 877 | ret = mActiveRenderer->createRenderWindow(name, width, height, fullScreen, miscParams);
|
---|
| 878 |
|
---|
| 879 | // Initialisation for classes dependent on first window created
|
---|
| 880 | if(!mFirstTimePostWindowInit)
|
---|
| 881 | {
|
---|
| 882 | oneTimePostWindowInit();
|
---|
| 883 | ret->_setPrimary();
|
---|
| 884 | }
|
---|
| 885 |
|
---|
| 886 | return ret;
|
---|
| 887 |
|
---|
| 888 | }
|
---|
| 889 | //-----------------------------------------------------------------------
|
---|
| 890 | void Root::detachRenderTarget(RenderTarget* target)
|
---|
| 891 | {
|
---|
| 892 | if (!mActiveRenderer)
|
---|
| 893 | {
|
---|
| 894 | OGRE_EXCEPT(Exception::ERR_NO_RENDERSYSTEM_SELECTED,
|
---|
| 895 | "Cannot create window - no render "
|
---|
| 896 | "system has been selected.", "Root::destroyRenderWindow");
|
---|
| 897 | }
|
---|
| 898 |
|
---|
| 899 | mActiveRenderer->detachRenderTarget( target->getName() );
|
---|
| 900 | }
|
---|
| 901 | //-----------------------------------------------------------------------
|
---|
| 902 | void Root::detachRenderTarget(const String &name)
|
---|
| 903 | {
|
---|
| 904 | if (!mActiveRenderer)
|
---|
| 905 | {
|
---|
| 906 | OGRE_EXCEPT(Exception::ERR_NO_RENDERSYSTEM_SELECTED,
|
---|
| 907 | "Cannot create window - no render "
|
---|
| 908 | "system has been selected.", "Root::destroyRenderWindow");
|
---|
| 909 | }
|
---|
| 910 |
|
---|
| 911 | mActiveRenderer->detachRenderTarget( name );
|
---|
| 912 | }
|
---|
| 913 | //-----------------------------------------------------------------------
|
---|
| 914 | RenderTarget* Root::getRenderTarget(const String &name)
|
---|
| 915 | {
|
---|
| 916 | if (!mActiveRenderer)
|
---|
| 917 | {
|
---|
| 918 | OGRE_EXCEPT(Exception::ERR_NO_RENDERSYSTEM_SELECTED,
|
---|
| 919 | "Cannot create window - no render "
|
---|
| 920 | "system has been selected.", "Root::getRenderWindow");
|
---|
| 921 | }
|
---|
| 922 |
|
---|
| 923 | return mActiveRenderer->getRenderTarget(name);
|
---|
| 924 | }
|
---|
| 925 | //-----------------------------------------------------------------------
|
---|
| 926 | void Root::loadPlugin(const String& pluginName)
|
---|
| 927 | {
|
---|
| 928 | // Load plugin library
|
---|
| 929 | DynLib* lib = DynLibManager::getSingleton().load( pluginName );
|
---|
| 930 | // Store for later unload
|
---|
| 931 | mPluginLibs.push_back(lib);
|
---|
| 932 |
|
---|
| 933 | // Call startup function
|
---|
| 934 | DLL_START_PLUGIN pFunc = (DLL_START_PLUGIN)lib->getSymbol("dllStartPlugin");
|
---|
| 935 |
|
---|
| 936 | if (!pFunc)
|
---|
| 937 | OGRE_EXCEPT(Exception::ERR_ITEM_NOT_FOUND, "Cannot find symbol dllStartPlugin in library " + pluginName,
|
---|
| 938 | "Root::loadPlugins");
|
---|
| 939 | pFunc();
|
---|
| 940 |
|
---|
| 941 | if (mIsInitialised)
|
---|
| 942 | {
|
---|
| 943 | // initialise too
|
---|
| 944 | DLL_INIT_PLUGIN pFunc = (DLL_INIT_PLUGIN)lib->getSymbol("dllInitialisePlugin");
|
---|
| 945 | if (pFunc)
|
---|
| 946 | {
|
---|
| 947 | pFunc();
|
---|
| 948 | }
|
---|
| 949 | }
|
---|
| 950 | }
|
---|
| 951 | //-----------------------------------------------------------------------
|
---|
| 952 | void Root::unloadPlugin(const String& pluginName)
|
---|
| 953 | {
|
---|
| 954 | std::vector<DynLib*>::iterator i;
|
---|
| 955 |
|
---|
| 956 | for (i = mPluginLibs.begin(); i != mPluginLibs.end(); ++i)
|
---|
| 957 | {
|
---|
| 958 | if ((*i)->getName() == pluginName)
|
---|
| 959 | {
|
---|
| 960 | // Call plugin shutdown
|
---|
| 961 | DLL_STOP_PLUGIN pFunc = (DLL_STOP_PLUGIN)(*i)->getSymbol("dllStopPlugin");
|
---|
| 962 | pFunc();
|
---|
| 963 | // Unload library (destroyed by DynLibManager)
|
---|
| 964 | DynLibManager::getSingleton().unload(*i);
|
---|
| 965 | mPluginLibs.erase(i);
|
---|
| 966 | return;
|
---|
| 967 | }
|
---|
| 968 |
|
---|
| 969 | }
|
---|
| 970 | }
|
---|
| 971 | //-----------------------------------------------------------------------
|
---|
| 972 | Timer* Root::getTimer(void)
|
---|
| 973 | {
|
---|
| 974 | return mTimer;
|
---|
| 975 | }
|
---|
| 976 | //-----------------------------------------------------------------------
|
---|
| 977 | void Root::oneTimePostWindowInit(void)
|
---|
| 978 | {
|
---|
| 979 | if (!mFirstTimePostWindowInit)
|
---|
| 980 | {
|
---|
| 981 | // Initialise material manager
|
---|
| 982 | mMaterialManager->initialise();
|
---|
| 983 | // Init particle systems manager
|
---|
| 984 | mParticleManager->_initialise();
|
---|
| 985 | // Init mesh manager
|
---|
| 986 | MeshManager::getSingleton()._initialise();
|
---|
| 987 | mFirstTimePostWindowInit = true;
|
---|
| 988 | }
|
---|
| 989 |
|
---|
| 990 | }
|
---|
| 991 | //-----------------------------------------------------------------------
|
---|
| 992 | void Root::_updateAllRenderTargets(void)
|
---|
| 993 | {
|
---|
| 994 | // delegate
|
---|
| 995 | mActiveRenderer->_updateAllRenderTargets();
|
---|
| 996 | }
|
---|
| 997 | //-----------------------------------------------------------------------
|
---|
| 998 | void Root::clearEventTimes(void)
|
---|
| 999 | {
|
---|
| 1000 | // Clear event times
|
---|
| 1001 | for(int i=0; i<3; ++i)
|
---|
| 1002 | mEventTimes[i].clear();
|
---|
| 1003 | }
|
---|
| 1004 | //---------------------------------------------------------------------
|
---|
| 1005 | void Root::addMovableObjectFactory(MovableObjectFactory* fact,
|
---|
| 1006 | bool overrideExisting)
|
---|
| 1007 | {
|
---|
| 1008 | MovableObjectFactoryMap::iterator facti = mMovableObjectFactoryMap.find(
|
---|
| 1009 | fact->getType());
|
---|
| 1010 | if (!overrideExisting && facti != mMovableObjectFactoryMap.end())
|
---|
| 1011 | {
|
---|
| 1012 | OGRE_EXCEPT(Exception::ERR_DUPLICATE_ITEM,
|
---|
| 1013 | "A factory of type '" + fact->getType() + "' already exists.",
|
---|
| 1014 | "Root::addMovableObjectFactory");
|
---|
| 1015 | }
|
---|
| 1016 |
|
---|
| 1017 | if (fact->requestTypeFlags())
|
---|
| 1018 | {
|
---|
| 1019 | if (facti != mMovableObjectFactoryMap.end() && facti->second->requestTypeFlags())
|
---|
| 1020 | {
|
---|
| 1021 | // Copy type flags from the factory we're replacing
|
---|
| 1022 | fact->_notifyTypeFlags(facti->second->getTypeFlags());
|
---|
| 1023 | }
|
---|
| 1024 | else
|
---|
| 1025 | {
|
---|
| 1026 | // Allocate new
|
---|
| 1027 | fact->_notifyTypeFlags(_allocateNextMovableObjectTypeFlag());
|
---|
| 1028 | }
|
---|
| 1029 | }
|
---|
| 1030 |
|
---|
| 1031 | // Save
|
---|
| 1032 | mMovableObjectFactoryMap[fact->getType()] = fact;
|
---|
| 1033 |
|
---|
| 1034 | LogManager::getSingleton().logMessage("MovableObjectFactory for type '" +
|
---|
| 1035 | fact->getType() + "' registered.");
|
---|
| 1036 |
|
---|
| 1037 | }
|
---|
| 1038 | //---------------------------------------------------------------------
|
---|
| 1039 | bool Root::hasMovableObjectFactory(const String& typeName) const
|
---|
| 1040 | {
|
---|
| 1041 | return !(mMovableObjectFactoryMap.find(typeName) == mMovableObjectFactoryMap.end());
|
---|
| 1042 | }
|
---|
| 1043 | //---------------------------------------------------------------------
|
---|
| 1044 | MovableObjectFactory* Root::getMovableObjectFactory(const String& typeName)
|
---|
| 1045 | {
|
---|
| 1046 | MovableObjectFactoryMap::iterator i =
|
---|
| 1047 | mMovableObjectFactoryMap.find(typeName);
|
---|
| 1048 | if (i == mMovableObjectFactoryMap.end())
|
---|
| 1049 | {
|
---|
| 1050 | OGRE_EXCEPT(Exception::ERR_ITEM_NOT_FOUND,
|
---|
| 1051 | "MovableObjectFactory of type " + typeName + " does not exist",
|
---|
| 1052 | "Root::getMovableObjectFactory");
|
---|
| 1053 | }
|
---|
| 1054 | return i->second;
|
---|
| 1055 | }
|
---|
| 1056 | //---------------------------------------------------------------------
|
---|
| 1057 | uint32 Root::_allocateNextMovableObjectTypeFlag(void)
|
---|
| 1058 | {
|
---|
| 1059 | if (mNextMovableObjectTypeFlag == SceneManager::USER_TYPE_MASK_LIMIT)
|
---|
| 1060 | {
|
---|
| 1061 | OGRE_EXCEPT(Exception::ERR_DUPLICATE_ITEM,
|
---|
| 1062 | "Cannot allocate a type flag since "
|
---|
| 1063 | "all the available flags have been used.",
|
---|
| 1064 | "Root::_allocateNextMovableObjectTypeFlag");
|
---|
| 1065 |
|
---|
| 1066 | }
|
---|
| 1067 | uint32 ret = mNextMovableObjectTypeFlag;
|
---|
| 1068 | mNextMovableObjectTypeFlag <<= 1;
|
---|
| 1069 | return ret;
|
---|
| 1070 |
|
---|
| 1071 | }
|
---|
| 1072 | //---------------------------------------------------------------------
|
---|
| 1073 | void Root::removeMovableObjectFactory(MovableObjectFactory* fact)
|
---|
| 1074 | {
|
---|
| 1075 | MovableObjectFactoryMap::iterator i = mMovableObjectFactoryMap.find(
|
---|
| 1076 | fact->getType());
|
---|
| 1077 | if (i != mMovableObjectFactoryMap.end())
|
---|
| 1078 | {
|
---|
| 1079 | mMovableObjectFactoryMap.erase(i);
|
---|
| 1080 | }
|
---|
| 1081 |
|
---|
| 1082 | }
|
---|
| 1083 | //---------------------------------------------------------------------
|
---|
| 1084 | Root::MovableObjectFactoryIterator
|
---|
| 1085 | Root::getMovableObjectFactoryIterator(void) const
|
---|
| 1086 | {
|
---|
| 1087 | return MovableObjectFactoryIterator(mMovableObjectFactoryMap.begin(),
|
---|
| 1088 | mMovableObjectFactoryMap.end());
|
---|
| 1089 |
|
---|
| 1090 | }
|
---|
| 1091 | //---------------------------------------------------------------------
|
---|
| 1092 | RenderQueueInvocationSequence* Root::createRenderQueueInvocationSequence(
|
---|
| 1093 | const String& name)
|
---|
| 1094 | {
|
---|
| 1095 | RenderQueueInvocationSequenceMap::iterator i =
|
---|
| 1096 | mRQSequenceMap.find(name);
|
---|
| 1097 | if (i != mRQSequenceMap.end())
|
---|
| 1098 | {
|
---|
| 1099 | OGRE_EXCEPT(Exception::ERR_DUPLICATE_ITEM,
|
---|
| 1100 | "RenderQueueInvocationSequence with the name " + name +
|
---|
| 1101 | " already exists.",
|
---|
| 1102 | "Root::createRenderQueueInvocationSequence");
|
---|
| 1103 | }
|
---|
| 1104 | RenderQueueInvocationSequence* ret = new RenderQueueInvocationSequence(name);
|
---|
| 1105 | mRQSequenceMap[name] = ret;
|
---|
| 1106 | return ret;
|
---|
| 1107 | }
|
---|
| 1108 | //---------------------------------------------------------------------
|
---|
| 1109 | RenderQueueInvocationSequence* Root::getRenderQueueInvocationSequence(
|
---|
| 1110 | const String& name)
|
---|
| 1111 | {
|
---|
| 1112 | RenderQueueInvocationSequenceMap::iterator i =
|
---|
| 1113 | mRQSequenceMap.find(name);
|
---|
| 1114 | if (i == mRQSequenceMap.end())
|
---|
| 1115 | {
|
---|
| 1116 | OGRE_EXCEPT(Exception::ERR_ITEM_NOT_FOUND,
|
---|
| 1117 | "RenderQueueInvocationSequence with the name " + name +
|
---|
| 1118 | " not found.",
|
---|
| 1119 | "Root::getRenderQueueInvocationSequence");
|
---|
| 1120 | }
|
---|
| 1121 | return i->second;
|
---|
| 1122 | }
|
---|
| 1123 | //---------------------------------------------------------------------
|
---|
| 1124 | void Root::destroyRenderQueueInvocationSequence(
|
---|
| 1125 | const String& name)
|
---|
| 1126 | {
|
---|
| 1127 | RenderQueueInvocationSequenceMap::iterator i =
|
---|
| 1128 | mRQSequenceMap.find(name);
|
---|
| 1129 | if (i != mRQSequenceMap.end())
|
---|
| 1130 | {
|
---|
| 1131 | delete i->second;
|
---|
| 1132 | mRQSequenceMap.erase(i);
|
---|
| 1133 | }
|
---|
| 1134 | }
|
---|
| 1135 | //---------------------------------------------------------------------
|
---|
| 1136 | void Root::destroyAllRenderQueueInvocationSequences(void)
|
---|
| 1137 | {
|
---|
| 1138 | for (RenderQueueInvocationSequenceMap::iterator i = mRQSequenceMap.begin();
|
---|
| 1139 | i != mRQSequenceMap.end(); ++i)
|
---|
| 1140 | {
|
---|
| 1141 | delete i->second;
|
---|
| 1142 | }
|
---|
| 1143 | mRQSequenceMap.clear();
|
---|
| 1144 | }
|
---|
| 1145 | //---------------------------------------------------------------------
|
---|
| 1146 |
|
---|
| 1147 |
|
---|
| 1148 |
|
---|
| 1149 | }
|
---|