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 | #ifdef GAMETOOLS_ILLUMINATION_MODULE
|
---|
612 | {
|
---|
613 | std::set<FrameListener*, FrameListenerComparer>::iterator i;
|
---|
614 | for (i= mFrameListeners.begin(); i != mFrameListeners.end(); ++i)
|
---|
615 | {
|
---|
616 | if (!(*i)->frameStarted(evt))
|
---|
617 | return false;
|
---|
618 | }
|
---|
619 | }
|
---|
620 | #else
|
---|
621 | // Tell all listeners
|
---|
622 | for (i= mFrameListeners.begin(); i != mFrameListeners.end(); ++i)
|
---|
623 | {
|
---|
624 | if (!(*i)->frameStarted(evt))
|
---|
625 | return false;
|
---|
626 | }
|
---|
627 | #endif
|
---|
628 |
|
---|
629 | return true;
|
---|
630 |
|
---|
631 | }
|
---|
632 | //-----------------------------------------------------------------------
|
---|
633 | bool Root::_fireFrameEnded(FrameEvent& evt)
|
---|
634 | {
|
---|
635 | // Remove all marked listeners
|
---|
636 | std::set<FrameListener*>::iterator i;
|
---|
637 | for (i = mRemovedFrameListeners.begin();
|
---|
638 | i != mRemovedFrameListeners.end(); i++)
|
---|
639 | {
|
---|
640 | mFrameListeners.erase(*i);
|
---|
641 | }
|
---|
642 | mRemovedFrameListeners.clear();
|
---|
643 |
|
---|
644 | // Tell all listeners
|
---|
645 | bool ret = true;
|
---|
646 |
|
---|
647 | #ifdef GAMETOOLS_ILLUMINATION_MODULE
|
---|
648 | {
|
---|
649 | std::set<FrameListener*, FrameListenerComparer>::iterator i;
|
---|
650 | for (i= mFrameListeners.begin(); i != mFrameListeners.end(); ++i)
|
---|
651 | {
|
---|
652 | if (!(*i)->frameEnded(evt))
|
---|
653 | {
|
---|
654 | ret = false;
|
---|
655 | break;
|
---|
656 | }
|
---|
657 | }
|
---|
658 | }
|
---|
659 | #else
|
---|
660 | for (i= mFrameListeners.begin(); i != mFrameListeners.end(); ++i)
|
---|
661 | {
|
---|
662 | if (!(*i)->frameEnded(evt))
|
---|
663 | {
|
---|
664 | ret = false;
|
---|
665 | break;
|
---|
666 | }
|
---|
667 | }
|
---|
668 | #endif
|
---|
669 |
|
---|
670 | // Tell buffer manager to free temp buffers used this frame
|
---|
671 | if (HardwareBufferManager::getSingletonPtr())
|
---|
672 | HardwareBufferManager::getSingleton()._releaseBufferCopies();
|
---|
673 |
|
---|
674 | return ret;
|
---|
675 | }
|
---|
676 | //-----------------------------------------------------------------------
|
---|
677 | bool Root::_fireFrameStarted()
|
---|
678 | {
|
---|
679 | unsigned long now = mTimer->getMilliseconds();
|
---|
680 | FrameEvent evt;
|
---|
681 | evt.timeSinceLastEvent = calculateEventTime(now, FETT_ANY);
|
---|
682 | evt.timeSinceLastFrame = calculateEventTime(now, FETT_STARTED);
|
---|
683 |
|
---|
684 | return _fireFrameStarted(evt);
|
---|
685 | }
|
---|
686 | //-----------------------------------------------------------------------
|
---|
687 | bool Root::_fireFrameEnded()
|
---|
688 | {
|
---|
689 | unsigned long now = mTimer->getMilliseconds();
|
---|
690 | FrameEvent evt;
|
---|
691 | evt.timeSinceLastEvent = calculateEventTime(now, FETT_ANY);
|
---|
692 | evt.timeSinceLastFrame = calculateEventTime(now, FETT_ENDED);
|
---|
693 |
|
---|
694 | return _fireFrameEnded(evt);
|
---|
695 | }
|
---|
696 | //-----------------------------------------------------------------------
|
---|
697 | Real Root::calculateEventTime(unsigned long now, FrameEventTimeType type)
|
---|
698 | {
|
---|
699 | // Calculate the average time passed between events of the given type
|
---|
700 | // during the last mFrameSmoothingTime seconds.
|
---|
701 |
|
---|
702 | std::deque<unsigned long>& times = mEventTimes[type];
|
---|
703 | times.push_back(now);
|
---|
704 |
|
---|
705 | if(times.size() == 1)
|
---|
706 | return 0;
|
---|
707 |
|
---|
708 | // Times up to mFrameSmoothingTime seconds old should be kept
|
---|
709 | unsigned long discardThreshold =
|
---|
710 | static_cast<unsigned long>(mFrameSmoothingTime * 1000.0f);
|
---|
711 |
|
---|
712 | // Find the oldest time to keep
|
---|
713 | std::deque<unsigned long>::iterator it = times.begin(),
|
---|
714 | end = times.end()-2; // We need at least two times
|
---|
715 | while(it != end)
|
---|
716 | {
|
---|
717 | if (now - *it > discardThreshold)
|
---|
718 | ++it;
|
---|
719 | else
|
---|
720 | break;
|
---|
721 | }
|
---|
722 |
|
---|
723 | // Remove old times
|
---|
724 | times.erase(times.begin(), it);
|
---|
725 |
|
---|
726 | return Real(times.back() - times.front()) / ((times.size()-1) * 1000);
|
---|
727 | }
|
---|
728 | //-----------------------------------------------------------------------
|
---|
729 | void Root::queueEndRendering(void)
|
---|
730 | {
|
---|
731 | mQueuedEnd = true;
|
---|
732 | }
|
---|
733 | //-----------------------------------------------------------------------
|
---|
734 | void Root::startRendering(void)
|
---|
735 | {
|
---|
736 | assert(mActiveRenderer != 0);
|
---|
737 |
|
---|
738 | mActiveRenderer->_initRenderTargets();
|
---|
739 |
|
---|
740 | // Clear event times
|
---|
741 | for(int i=0; i!=3; ++i)
|
---|
742 | mEventTimes[i].clear();
|
---|
743 |
|
---|
744 | // Infinite loop, until broken out of by frame listeners
|
---|
745 | // or break out by calling queueEndRendering()
|
---|
746 | mQueuedEnd = false;
|
---|
747 |
|
---|
748 | while( !mQueuedEnd )
|
---|
749 | {
|
---|
750 | //Allow platform to pump/create/etc messages/events once per frame
|
---|
751 | mPlatformManager->messagePump(mAutoWindow);
|
---|
752 |
|
---|
753 | if (!renderOneFrame())
|
---|
754 | break;
|
---|
755 | }
|
---|
756 | }
|
---|
757 | //-----------------------------------------------------------------------
|
---|
758 | bool Root::renderOneFrame(void)
|
---|
759 | {
|
---|
760 | if(!_fireFrameStarted())
|
---|
761 | return false;
|
---|
762 |
|
---|
763 | _updateAllRenderTargets();
|
---|
764 |
|
---|
765 | return _fireFrameEnded();
|
---|
766 | }
|
---|
767 | //-----------------------------------------------------------------------
|
---|
768 | void Root::shutdown(void)
|
---|
769 | {
|
---|
770 | SceneManagerEnumerator::getSingleton().shutdownAll();
|
---|
771 | shutdownPlugins();
|
---|
772 |
|
---|
773 | ShadowVolumeExtrudeProgram::shutdown();
|
---|
774 | mResourceBackgroundQueue->shutdown();
|
---|
775 | ResourceGroupManager::getSingleton().shutdownAll();
|
---|
776 |
|
---|
777 | mIsInitialised = false;
|
---|
778 |
|
---|
779 | LogManager::getSingleton().logMessage("*-*-* OGRE Shutdown");
|
---|
780 | }
|
---|
781 | //-----------------------------------------------------------------------
|
---|
782 | void Root::loadPlugins( const String& pluginsfile )
|
---|
783 | {
|
---|
784 | StringVector pluginList;
|
---|
785 | String pluginDir;
|
---|
786 | ConfigFile cfg;
|
---|
787 |
|
---|
788 | try {
|
---|
789 | cfg.load( pluginsfile );
|
---|
790 | }
|
---|
791 | catch (Exception)
|
---|
792 | {
|
---|
793 | LogManager::getSingleton().logMessage(pluginsfile + " not found, automatic plugin loading disabled.");
|
---|
794 | return;
|
---|
795 | }
|
---|
796 |
|
---|
797 | pluginDir = cfg.getSetting("PluginFolder"); // Ignored on Mac OS X, uses Resources/ directory
|
---|
798 | pluginList = cfg.getMultiSetting("Plugin");
|
---|
799 |
|
---|
800 | char last_char = pluginDir[pluginDir.length()-1];
|
---|
801 | if (last_char != '/' && last_char != '\\')
|
---|
802 | {
|
---|
803 | #if OGRE_PLATFORM == OGRE_PLATFORM_WIN32
|
---|
804 | pluginDir += "\\";
|
---|
805 | #elif OGRE_PLATFORM == OGRE_PLATFORM_LINUX
|
---|
806 | pluginDir += "/";
|
---|
807 | #endif
|
---|
808 | }
|
---|
809 |
|
---|
810 | for( StringVector::iterator it = pluginList.begin(); it != pluginList.end(); ++it )
|
---|
811 | {
|
---|
812 | loadPlugin(pluginDir + (*it));
|
---|
813 | }
|
---|
814 |
|
---|
815 | }
|
---|
816 | //-----------------------------------------------------------------------
|
---|
817 | void Root::shutdownPlugins(void)
|
---|
818 | {
|
---|
819 | std::vector<DynLib*>::reverse_iterator i;
|
---|
820 |
|
---|
821 | // NB Shutdown plugins in reverse order to enforce dependencies
|
---|
822 | for (i = mPluginLibs.rbegin(); i != mPluginLibs.rend(); ++i)
|
---|
823 | {
|
---|
824 | // Call plugin shutdown (optional)
|
---|
825 | DLL_STOP_PLUGIN pFunc = (DLL_STOP_PLUGIN)(*i)->getSymbol("dllShutdownPlugin");
|
---|
826 | if (pFunc)
|
---|
827 | {
|
---|
828 | pFunc();
|
---|
829 | }
|
---|
830 |
|
---|
831 | }
|
---|
832 | }
|
---|
833 | //-----------------------------------------------------------------------
|
---|
834 | void Root::initialisePlugins(void)
|
---|
835 | {
|
---|
836 | std::vector<DynLib*>::iterator i;
|
---|
837 |
|
---|
838 | for (i = mPluginLibs.begin(); i != mPluginLibs.end(); ++i)
|
---|
839 | {
|
---|
840 | // Call plugin initialise (optional)
|
---|
841 | DLL_INIT_PLUGIN pFunc = (DLL_INIT_PLUGIN)(*i)->getSymbol("dllInitialisePlugin");
|
---|
842 | if (pFunc)
|
---|
843 | {
|
---|
844 | pFunc();
|
---|
845 | }
|
---|
846 |
|
---|
847 | }
|
---|
848 | }
|
---|
849 | //-----------------------------------------------------------------------
|
---|
850 | void Root::unloadPlugins(void)
|
---|
851 | {
|
---|
852 | std::vector<DynLib*>::reverse_iterator i;
|
---|
853 |
|
---|
854 | // NB Unload plugins in reverse order to enforce dependencies
|
---|
855 | for (i = mPluginLibs.rbegin(); i != mPluginLibs.rend(); ++i)
|
---|
856 | {
|
---|
857 | // Call plugin shutdown
|
---|
858 | DLL_STOP_PLUGIN pFunc = (DLL_STOP_PLUGIN)(*i)->getSymbol("dllStopPlugin");
|
---|
859 | pFunc();
|
---|
860 | // Unload library & destroy
|
---|
861 | DynLibManager::getSingleton().unload(*i);
|
---|
862 |
|
---|
863 | }
|
---|
864 |
|
---|
865 | mPluginLibs.clear();
|
---|
866 |
|
---|
867 | }
|
---|
868 | //-----------------------------------------------------------------------
|
---|
869 | void Root::addResourceLocation(const String& name, const String& locType,
|
---|
870 | const String& groupName, bool recursive)
|
---|
871 | {
|
---|
872 | ResourceGroupManager::getSingleton().addResourceLocation(
|
---|
873 | name, locType, groupName, recursive);
|
---|
874 | }
|
---|
875 | //-----------------------------------------------------------------------
|
---|
876 | void Root::removeResourceLocation(const String& name, const String& groupName)
|
---|
877 | {
|
---|
878 | ResourceGroupManager::getSingleton().removeResourceLocation(
|
---|
879 | name, groupName);
|
---|
880 | }
|
---|
881 | //-----------------------------------------------------------------------
|
---|
882 | void Root::convertColourValue(const ColourValue& colour, uint32* pDest)
|
---|
883 | {
|
---|
884 | assert(mActiveRenderer != 0);
|
---|
885 | mActiveRenderer->convertColourValue(colour, pDest);
|
---|
886 | }
|
---|
887 | //-----------------------------------------------------------------------
|
---|
888 | RenderWindow* Root::getAutoCreatedWindow(void)
|
---|
889 | {
|
---|
890 | return mAutoWindow;
|
---|
891 | }
|
---|
892 | //-----------------------------------------------------------------------
|
---|
893 | RenderWindow* Root::createRenderWindow(const String &name, unsigned int width, unsigned int height,
|
---|
894 | bool fullScreen, const NameValuePairList *miscParams)
|
---|
895 | {
|
---|
896 | if (!mActiveRenderer)
|
---|
897 | {
|
---|
898 | OGRE_EXCEPT(Exception::ERR_NO_RENDERSYSTEM_SELECTED,
|
---|
899 | "Cannot create window - no render "
|
---|
900 | "system has been selected.", "Root::createRenderWindow");
|
---|
901 | }
|
---|
902 | RenderWindow* ret;
|
---|
903 | ret = mActiveRenderer->createRenderWindow(name, width, height, fullScreen, miscParams);
|
---|
904 |
|
---|
905 | // Initialisation for classes dependent on first window created
|
---|
906 | if(!mFirstTimePostWindowInit)
|
---|
907 | {
|
---|
908 | oneTimePostWindowInit();
|
---|
909 | ret->_setPrimary();
|
---|
910 | }
|
---|
911 |
|
---|
912 | return ret;
|
---|
913 |
|
---|
914 | }
|
---|
915 | //-----------------------------------------------------------------------
|
---|
916 | void Root::detachRenderTarget(RenderTarget* target)
|
---|
917 | {
|
---|
918 | if (!mActiveRenderer)
|
---|
919 | {
|
---|
920 | OGRE_EXCEPT(Exception::ERR_NO_RENDERSYSTEM_SELECTED,
|
---|
921 | "Cannot create window - no render "
|
---|
922 | "system has been selected.", "Root::destroyRenderWindow");
|
---|
923 | }
|
---|
924 |
|
---|
925 | mActiveRenderer->detachRenderTarget( target->getName() );
|
---|
926 | }
|
---|
927 | //-----------------------------------------------------------------------
|
---|
928 | void Root::detachRenderTarget(const String &name)
|
---|
929 | {
|
---|
930 | if (!mActiveRenderer)
|
---|
931 | {
|
---|
932 | OGRE_EXCEPT(Exception::ERR_NO_RENDERSYSTEM_SELECTED,
|
---|
933 | "Cannot create window - no render "
|
---|
934 | "system has been selected.", "Root::destroyRenderWindow");
|
---|
935 | }
|
---|
936 |
|
---|
937 | mActiveRenderer->detachRenderTarget( name );
|
---|
938 | }
|
---|
939 | //-----------------------------------------------------------------------
|
---|
940 | RenderTarget* Root::getRenderTarget(const String &name)
|
---|
941 | {
|
---|
942 | if (!mActiveRenderer)
|
---|
943 | {
|
---|
944 | OGRE_EXCEPT(Exception::ERR_NO_RENDERSYSTEM_SELECTED,
|
---|
945 | "Cannot create window - no render "
|
---|
946 | "system has been selected.", "Root::getRenderWindow");
|
---|
947 | }
|
---|
948 |
|
---|
949 | return mActiveRenderer->getRenderTarget(name);
|
---|
950 | }
|
---|
951 | //-----------------------------------------------------------------------
|
---|
952 | void Root::loadPlugin(const String& pluginName)
|
---|
953 | {
|
---|
954 | // Load plugin library
|
---|
955 | DynLib* lib = DynLibManager::getSingleton().load( pluginName );
|
---|
956 | // Store for later unload
|
---|
957 | mPluginLibs.push_back(lib);
|
---|
958 |
|
---|
959 | // Call startup function
|
---|
960 | DLL_START_PLUGIN pFunc = (DLL_START_PLUGIN)lib->getSymbol("dllStartPlugin");
|
---|
961 |
|
---|
962 | if (!pFunc)
|
---|
963 | OGRE_EXCEPT(Exception::ERR_ITEM_NOT_FOUND, "Cannot find symbol dllStartPlugin in library " + pluginName,
|
---|
964 | "Root::loadPlugins");
|
---|
965 | pFunc();
|
---|
966 |
|
---|
967 | if (mIsInitialised)
|
---|
968 | {
|
---|
969 | // initialise too
|
---|
970 | DLL_INIT_PLUGIN pFunc = (DLL_INIT_PLUGIN)lib->getSymbol("dllInitialisePlugin");
|
---|
971 | if (pFunc)
|
---|
972 | {
|
---|
973 | pFunc();
|
---|
974 | }
|
---|
975 | }
|
---|
976 | }
|
---|
977 | //-----------------------------------------------------------------------
|
---|
978 | void Root::unloadPlugin(const String& pluginName)
|
---|
979 | {
|
---|
980 | std::vector<DynLib*>::iterator i;
|
---|
981 |
|
---|
982 | for (i = mPluginLibs.begin(); i != mPluginLibs.end(); ++i)
|
---|
983 | {
|
---|
984 | if ((*i)->getName() == pluginName)
|
---|
985 | {
|
---|
986 | // Call plugin shutdown
|
---|
987 | DLL_STOP_PLUGIN pFunc = (DLL_STOP_PLUGIN)(*i)->getSymbol("dllStopPlugin");
|
---|
988 | pFunc();
|
---|
989 | // Unload library (destroyed by DynLibManager)
|
---|
990 | DynLibManager::getSingleton().unload(*i);
|
---|
991 | mPluginLibs.erase(i);
|
---|
992 | return;
|
---|
993 | }
|
---|
994 |
|
---|
995 | }
|
---|
996 | }
|
---|
997 | //-----------------------------------------------------------------------
|
---|
998 | Timer* Root::getTimer(void)
|
---|
999 | {
|
---|
1000 | return mTimer;
|
---|
1001 | }
|
---|
1002 | //-----------------------------------------------------------------------
|
---|
1003 | void Root::oneTimePostWindowInit(void)
|
---|
1004 | {
|
---|
1005 | if (!mFirstTimePostWindowInit)
|
---|
1006 | {
|
---|
1007 | // Initialise material manager
|
---|
1008 | mMaterialManager->initialise();
|
---|
1009 | // Init particle systems manager
|
---|
1010 | mParticleManager->_initialise();
|
---|
1011 | // Init mesh manager
|
---|
1012 | MeshManager::getSingleton()._initialise();
|
---|
1013 | mFirstTimePostWindowInit = true;
|
---|
1014 | }
|
---|
1015 |
|
---|
1016 | }
|
---|
1017 | //-----------------------------------------------------------------------
|
---|
1018 | void Root::_updateAllRenderTargets(void)
|
---|
1019 | {
|
---|
1020 | // delegate
|
---|
1021 | mActiveRenderer->_updateAllRenderTargets();
|
---|
1022 | }
|
---|
1023 | //-----------------------------------------------------------------------
|
---|
1024 | void Root::clearEventTimes(void)
|
---|
1025 | {
|
---|
1026 | // Clear event times
|
---|
1027 | for(int i=0; i<3; ++i)
|
---|
1028 | mEventTimes[i].clear();
|
---|
1029 | }
|
---|
1030 | //---------------------------------------------------------------------
|
---|
1031 | void Root::addMovableObjectFactory(MovableObjectFactory* fact,
|
---|
1032 | bool overrideExisting)
|
---|
1033 | {
|
---|
1034 | MovableObjectFactoryMap::iterator facti = mMovableObjectFactoryMap.find(
|
---|
1035 | fact->getType());
|
---|
1036 | if (!overrideExisting && facti != mMovableObjectFactoryMap.end())
|
---|
1037 | {
|
---|
1038 | OGRE_EXCEPT(Exception::ERR_DUPLICATE_ITEM,
|
---|
1039 | "A factory of type '" + fact->getType() + "' already exists.",
|
---|
1040 | "Root::addMovableObjectFactory");
|
---|
1041 | }
|
---|
1042 |
|
---|
1043 | if (fact->requestTypeFlags())
|
---|
1044 | {
|
---|
1045 | if (facti != mMovableObjectFactoryMap.end() && facti->second->requestTypeFlags())
|
---|
1046 | {
|
---|
1047 | // Copy type flags from the factory we're replacing
|
---|
1048 | fact->_notifyTypeFlags(facti->second->getTypeFlags());
|
---|
1049 | }
|
---|
1050 | else
|
---|
1051 | {
|
---|
1052 | // Allocate new
|
---|
1053 | fact->_notifyTypeFlags(_allocateNextMovableObjectTypeFlag());
|
---|
1054 | }
|
---|
1055 | }
|
---|
1056 |
|
---|
1057 | // Save
|
---|
1058 | mMovableObjectFactoryMap[fact->getType()] = fact;
|
---|
1059 |
|
---|
1060 | LogManager::getSingleton().logMessage("MovableObjectFactory for type '" +
|
---|
1061 | fact->getType() + "' registered.");
|
---|
1062 |
|
---|
1063 | }
|
---|
1064 | //---------------------------------------------------------------------
|
---|
1065 | bool Root::hasMovableObjectFactory(const String& typeName) const
|
---|
1066 | {
|
---|
1067 | return !(mMovableObjectFactoryMap.find(typeName) == mMovableObjectFactoryMap.end());
|
---|
1068 | }
|
---|
1069 | //---------------------------------------------------------------------
|
---|
1070 | MovableObjectFactory* Root::getMovableObjectFactory(const String& typeName)
|
---|
1071 | {
|
---|
1072 | MovableObjectFactoryMap::iterator i =
|
---|
1073 | mMovableObjectFactoryMap.find(typeName);
|
---|
1074 | if (i == mMovableObjectFactoryMap.end())
|
---|
1075 | {
|
---|
1076 | OGRE_EXCEPT(Exception::ERR_ITEM_NOT_FOUND,
|
---|
1077 | "MovableObjectFactory of type " + typeName + " does not exist",
|
---|
1078 | "Root::getMovableObjectFactory");
|
---|
1079 | }
|
---|
1080 | return i->second;
|
---|
1081 | }
|
---|
1082 | //---------------------------------------------------------------------
|
---|
1083 | uint32 Root::_allocateNextMovableObjectTypeFlag(void)
|
---|
1084 | {
|
---|
1085 | if (mNextMovableObjectTypeFlag == SceneManager::USER_TYPE_MASK_LIMIT)
|
---|
1086 | {
|
---|
1087 | OGRE_EXCEPT(Exception::ERR_DUPLICATE_ITEM,
|
---|
1088 | "Cannot allocate a type flag since "
|
---|
1089 | "all the available flags have been used.",
|
---|
1090 | "Root::_allocateNextMovableObjectTypeFlag");
|
---|
1091 |
|
---|
1092 | }
|
---|
1093 | uint32 ret = mNextMovableObjectTypeFlag;
|
---|
1094 | mNextMovableObjectTypeFlag <<= 1;
|
---|
1095 | return ret;
|
---|
1096 |
|
---|
1097 | }
|
---|
1098 | //---------------------------------------------------------------------
|
---|
1099 | void Root::removeMovableObjectFactory(MovableObjectFactory* fact)
|
---|
1100 | {
|
---|
1101 | MovableObjectFactoryMap::iterator i = mMovableObjectFactoryMap.find(
|
---|
1102 | fact->getType());
|
---|
1103 | if (i != mMovableObjectFactoryMap.end())
|
---|
1104 | {
|
---|
1105 | mMovableObjectFactoryMap.erase(i);
|
---|
1106 | }
|
---|
1107 |
|
---|
1108 | }
|
---|
1109 | //---------------------------------------------------------------------
|
---|
1110 | Root::MovableObjectFactoryIterator
|
---|
1111 | Root::getMovableObjectFactoryIterator(void) const
|
---|
1112 | {
|
---|
1113 | return MovableObjectFactoryIterator(mMovableObjectFactoryMap.begin(),
|
---|
1114 | mMovableObjectFactoryMap.end());
|
---|
1115 |
|
---|
1116 | }
|
---|
1117 | //---------------------------------------------------------------------
|
---|
1118 | RenderQueueInvocationSequence* Root::createRenderQueueInvocationSequence(
|
---|
1119 | const String& name)
|
---|
1120 | {
|
---|
1121 | RenderQueueInvocationSequenceMap::iterator i =
|
---|
1122 | mRQSequenceMap.find(name);
|
---|
1123 | if (i != mRQSequenceMap.end())
|
---|
1124 | {
|
---|
1125 | OGRE_EXCEPT(Exception::ERR_DUPLICATE_ITEM,
|
---|
1126 | "RenderQueueInvocationSequence with the name " + name +
|
---|
1127 | " already exists.",
|
---|
1128 | "Root::createRenderQueueInvocationSequence");
|
---|
1129 | }
|
---|
1130 | RenderQueueInvocationSequence* ret = new RenderQueueInvocationSequence(name);
|
---|
1131 | mRQSequenceMap[name] = ret;
|
---|
1132 | return ret;
|
---|
1133 | }
|
---|
1134 | //---------------------------------------------------------------------
|
---|
1135 | RenderQueueInvocationSequence* Root::getRenderQueueInvocationSequence(
|
---|
1136 | const String& name)
|
---|
1137 | {
|
---|
1138 | RenderQueueInvocationSequenceMap::iterator i =
|
---|
1139 | mRQSequenceMap.find(name);
|
---|
1140 | if (i == mRQSequenceMap.end())
|
---|
1141 | {
|
---|
1142 | OGRE_EXCEPT(Exception::ERR_ITEM_NOT_FOUND,
|
---|
1143 | "RenderQueueInvocationSequence with the name " + name +
|
---|
1144 | " not found.",
|
---|
1145 | "Root::getRenderQueueInvocationSequence");
|
---|
1146 | }
|
---|
1147 | return i->second;
|
---|
1148 | }
|
---|
1149 | //---------------------------------------------------------------------
|
---|
1150 | void Root::destroyRenderQueueInvocationSequence(
|
---|
1151 | const String& name)
|
---|
1152 | {
|
---|
1153 | RenderQueueInvocationSequenceMap::iterator i =
|
---|
1154 | mRQSequenceMap.find(name);
|
---|
1155 | if (i != mRQSequenceMap.end())
|
---|
1156 | {
|
---|
1157 | delete i->second;
|
---|
1158 | mRQSequenceMap.erase(i);
|
---|
1159 | }
|
---|
1160 | }
|
---|
1161 | //---------------------------------------------------------------------
|
---|
1162 | void Root::destroyAllRenderQueueInvocationSequences(void)
|
---|
1163 | {
|
---|
1164 | for (RenderQueueInvocationSequenceMap::iterator i = mRQSequenceMap.begin();
|
---|
1165 | i != mRQSequenceMap.end(); ++i)
|
---|
1166 | {
|
---|
1167 | delete i->second;
|
---|
1168 | }
|
---|
1169 | mRQSequenceMap.clear();
|
---|
1170 | }
|
---|
1171 | //---------------------------------------------------------------------
|
---|
1172 |
|
---|
1173 |
|
---|
1174 |
|
---|
1175 | }
|
---|